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 <?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 * 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 * 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']) ...@@ -51,11 +51,11 @@ if((isset($_GET['action']) && ! empty($_GET['action'])) && (isset($_GET['name'])
{ {
if ($_GET['action'] == 'set') 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') 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 ...@@ -191,28 +191,19 @@ class Conf
$this->modules[]=$module; $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++; $i++;
} }
// Sharings between entities // Load shared elements between entities
if (! empty($this->multicompany->enabled) && ! empty($multicompany_sharing)) if (! empty($this->multicompany->enabled))
{ {
$ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php'); $ret = @dol_include_once('/multicompany/class/actions_multicompany.class.php');
if ($ret) if ($ret)
{ {
$mc = new ActionsMulticompany($db); $mc = new ActionsMulticompany($db);
$this->multicompany->entity = $mc->loadEntity();
foreach($multicompany_sharing as $key => $value) $this->entities = $mc->loadSharedElements();
{
$this->entities[$key]=$mc->check_entity($value);
}
} }
} }
} }
......
...@@ -463,7 +463,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not ...@@ -463,7 +463,7 @@ function dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $not
$sql = "DELETE FROM ".MAIN_DB_PREFIX."const"; $sql = "DELETE FROM ".MAIN_DB_PREFIX."const";
$sql.= " WHERE name = ".$db->encrypt($name,1); $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); dol_syslog("admin.lib::dolibarr_set_const sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql); $resql=$db->query($sql);
......
...@@ -218,13 +218,16 @@ function ajax_combobox($htmlname) ...@@ -218,13 +218,16 @@ function ajax_combobox($htmlname)
/** /**
* On/off button for constant * On/off button for constant
* *
* @param code Name of constant * @param string $code Name of constant
* @param input Input element * @param array $input Input element
* @param int $entity Entity to set
* TODO add different method for other input (show/hide, disable, ..) * 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; global $conf, $langs;
$entity = ((! empty($entity) && is_numeric($entity) && $entity > 0) || $entity == 0 ? $entity : $conf->entity);
$out= '<script type="text/javascript"> $out= '<script type="text/javascript">
$(function() { $(function() {
...@@ -234,7 +237,8 @@ function ajax_constantonoff($code,$input=array()) ...@@ -234,7 +237,8 @@ function ajax_constantonoff($code,$input=array())
$( "#set_'.$code.'" ).click(function() { $( "#set_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", { $.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
action: \'set\', action: \'set\',
name: \''.$code.'\' name: \''.$code.'\',
entity: \''.$entity.'\'
}, },
function() { function() {
$("#set_'.$code.'" ).hide(); $("#set_'.$code.'" ).hide();
...@@ -256,7 +260,8 @@ function ajax_constantonoff($code,$input=array()) ...@@ -256,7 +260,8 @@ function ajax_constantonoff($code,$input=array())
$( "#del_'.$code.'" ).click(function() { $( "#del_'.$code.'" ).click(function() {
$.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", { $.get( "'.DOL_URL_ROOT.'/core/ajax/constantonoff.php", {
action: \'del\', action: \'del\',
name: \''.$code.'\' name: \''.$code.'\',
entity: \''.$entity.'\'
}, },
function() { function() {
$("#del_'.$code.'" ).hide(); $("#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