Skip to content
Snippets Groups Projects
Commit 376759c1 authored by Regis Houssin's avatar Regis Houssin
Browse files

Fix: refactoring elements sharing management between entities

parent 4eb88be3
No related branches found
No related tags found
No related merge requests found
<?php
/* Copyright (C) 2011 Regis Houssin <regis@dolibarr.fr>
/* Copyright (C) 2011-2012 Regis Houssin <regis@dolibarr.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -51,11 +51,11 @@ if((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name'])
{
if ($_GET['action'] == 'set')
{
dolibarr_set_const($db, $_GET['name'], 1, 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, GETPOST('name','alpha'), 1, 'chaine', 0, '', GETPOST('entity','int'));
}
else if ($_GET['action'] == 'del')
{
dolibarr_del_const($db, $_GET['name'], $conf->entity);
dolibarr_del_const($db, GETPOST('name','alpha'), GETPOST('entity','int'));
}
}
}
......
......@@ -191,28 +191,19 @@ class Conf
$this->modules[]=$module;
}
}
// Sharings between entities
else if ($value && preg_match('/^MULTICOMPANY_([A-Z_]+)_SHARING$/',$key,$reg))
{
$module=strtolower($reg[1]);
$multicompany_sharing[$module]=$value;
}
}
$i++;
}
// Sharings between entities
if (! empty($this->multicompany->enabled) && ! empty($multicompany_sharing))
// Load shared elements between entities
if (! empty($this->multicompany->enabled))
{
$ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($ret)
{
$mc = new ActionsMulticompany($db);
foreach($multicompany_sharing as $key => $value)
{
$this->entities[$key]=$mc->check_entity($value);
}
$this->multicompany->entity = $mc->loadEntity();
$this->entities = $mc->loadSharedElements();
}
}
}
......
......@@ -463,7 +463,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE name = ".$db->encrypt($name,1);
if ($entity > 0) $sql.= " AND entity = ".$entity;
if ($entity >= 0) $sql.= " AND entity = ".$entity;
dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
......
......@@ -218,13 +218,16 @@ function ajax_combobox($htmlname)
/**
* On/off button for constant
*
* @param code Name of constant
* @param input Input element
* @param string $code Name of constant
* @param array $input Input element
* @param int $entity Entity to set
* TODO add different method for other input (show/hide, disable, ..)
*/
function ajax_constantonoff($code,$input=array())
function ajax_constantonoff($code,$input=array(),$entity=false)
{
global $conf, $langs;
$entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
$out= '<script type="text/javascript">
$(function() {
......@@ -234,7 +237,8 @@ function ajax_constantonoff($code,$input=array())
$( "#set_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
action: \'set\',
name: \''.$code.'\'
name: \''.$code.'\',
entity: \''.$entity.'\'
},
function() {
$("#set_'.$code.'" ).hide();
......@@ -256,7 +260,8 @@ function ajax_constantonoff($code,$input=array())
$( "#del_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
action: \'del\',
name: \''.$code.'\'
name: \''.$code.'\',
entity: \''.$entity.'\'
},
function() {
$("#del_'.$code.'" ).hide();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment