From 250e3555c3cc8d6433c419bd25a8217556f46a78 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 7 Jul 2012 10:57:54 +0200 Subject: [PATCH] Fix: more bugs with multicompany --- htdocs/core/class/conf.class.php | 2 +- htdocs/core/class/html.form.class.php | 4 ++-- htdocs/main.inc.php | 4 ++-- htdocs/user/class/user.class.php | 2 +- htdocs/user/fiche.php | 22 +++++++++++++++------- htdocs/user/group/fiche.php | 20 +++++++++----------- 6 files changed, 30 insertions(+), 24 deletions(-) diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index a2c19812434..52352963ca4 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -199,7 +199,7 @@ class Conf { $modulename=strtolower($reg[1]); if ($modulename == 'propale') $modulename='propal'; - $this->$modulename=(object) array(); + if (! is_object($this->$modulename)) $this->$modulename=(object) array(); $this->$modulename->enabled=true; $this->modules[]=$modulename; // Add this module in list of enabled modules } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 294b12f80f6..29baedfc6b5 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -929,7 +929,7 @@ class Form * @param int $force_entity Possibility to force entity * @return void */ - function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) + function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=false) { print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity); } @@ -947,7 +947,7 @@ class Form * @param int $force_entity Possibility to force entity * @return string HTML select string */ - function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) + function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=false) { global $conf,$user,$langs; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 2fcae84a917..c2564cb2f17 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -358,7 +358,7 @@ if (! defined('NOLOGIN')) // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($db); - $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST('entity')); + $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST('entity','int',2)); if ($result < 0) { $error++; } @@ -742,7 +742,7 @@ $heightforframes=48; // Switch to another entity if (! empty($conf->multicompany->enabled) && GETPOST('action') == 'switchentity') { - if ($mc->switchEntity(GETPOST('entity','int')) > 0) + if ($mc->switchEntity(GETPOST('entity','int',2)) > 0) { Header("Location: ".DOL_URL_ROOT.'/'); exit; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index f2746ff50ea..45854bf284a 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1999,7 +1999,7 @@ class User extends CommonObject } else { - if ($all) $sql.= " WHERE entity = is not null"; + if ($all) $sql.= " WHERE entity IS NOT NULL"; // all users except superadmin else $sql.= " WHERE entity = ".$conf->entity; if ($limitTo == 'active') $sql.= " AND statut = 1"; } diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 1a9d2e2e803..66c26c6660e 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -203,18 +203,22 @@ if ($action == 'add' && $canadduser) $edituser->note = $_POST["note"]; $edituser->ldap_sid = $_POST["ldap_sid"]; // If multicompany is off, admin users must all be on entity 0. - if($conf->multicompany->enabled) + if ($conf->multicompany->enabled) { - if($conf->multicompany->transverse_mode || ! empty($_POST["superadmin"])) + if (! empty($_POST["superadmin"])) { - $edituser->entity=0; + $edituser->entity = 0; + } + else if ($conf->multicompany->transverse_mode) + { + $edituser->entity = 1; // all users in master entity } else { $edituser->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]); } } - else if(! empty($_POST["admin"])) + else if (! empty($_POST["admin"])) { $edituser->entity=0; } @@ -317,11 +321,15 @@ if ($action == 'update' && ! $_POST["cancel"]) $edituser->webcal_login = $_POST["webcal_login"]; $edituser->phenix_login = $_POST["phenix_login"]; $edituser->phenix_pass = $_POST["phenix_pass"]; - if($conf->multicompany->enabled) + if ($conf->multicompany->enabled) { - if($conf->multicompany->transverse_mode || ! empty($_POST["superadmin"])) + if (! empty($_POST["superadmin"])) { - $edituser->entity=0; + $edituser->entity = 0; + } + else if ($conf->multicompany->transverse_mode) + { + $edituser->entity = 1; // all users in master entity } else { diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index 9c26e7be32c..e7b7a99d932 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -51,7 +51,7 @@ $userid=GETPOST('user', 'int'); // Security check $result = restrictedArea($user, 'user', $id, 'usergroup&usergroup', 'user'); -if(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->multicompany->transverse_mode) +if (! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->multicompany->transverse_mode) { accessforbidden(); } @@ -83,7 +83,7 @@ if ($action == 'confirm_delete' && $confirm == "yes") */ if ($action == 'add') { - if($caneditperms) + if ($caneditperms) { $message=""; if (! $_POST["nom"]) @@ -96,8 +96,8 @@ if ($action == 'add') { $object->nom = trim($_POST["nom"]); $object->note = trim($_POST["note"]); - - if($conf->multicompany->enabled && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; + + if ($conf->multicompany->enabled && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; $db->begin(); @@ -108,7 +108,7 @@ if ($action == 'add') { $db->commit(); - Header("Location: fiche.php?id=".$object->id); + Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else @@ -145,7 +145,7 @@ if ($action == 'adduser' || $action =='removeuser') if ($result > 0) { - header("Location: fiche.php?id=".$object->id); + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else @@ -164,7 +164,7 @@ if ($action == 'adduser' || $action =='removeuser') if ($action == 'update') { - if($caneditperms) + if ($caneditperms) { $message=""; @@ -176,8 +176,8 @@ if ($action == 'update') $object->nom = trim($_POST["group"]); $object->note = dol_htmlcleanlastbr($_POST["note"]); - - if($conf->multicompany->enabled && !empty($conf->multicompany->transverse_mode)) $object->entity = 0; + + if ($conf->multicompany->enabled && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; $ret=$object->update(); @@ -504,7 +504,5 @@ else } llxFooter(); - $db->close(); - ?>