diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index c1b17f9afec..f5db96ef42a 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -124,11 +124,9 @@ class Categorie */ function create() { - global $langs; + global $conf,$langs; $langs->load('categories'); - if ($this->socid == -1) $this->socid = 0; - if ($this->already_exists ()) { $this->error=$langs->trans("ImpossibleAddCat"); @@ -136,9 +134,17 @@ class Categorie return -1; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description, fk_soc, visible, type) "; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label, description,"; + if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) + { + $sql.= "fk_soc,"; + } + $sql.= "visible, type) "; $sql.= "VALUES ('".addslashes($this->label)."', '".addslashes($this->description)."',"; - $sql.= ($this->socid?$this->socid:"null").","; + if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) + { + $sql.= ($this->socid != -1 ? $this->socid : 'null').","; + } $sql.= "'".$this->visible."',".$this->type.")"; @@ -186,7 +192,6 @@ class Categorie // Clean parameters $this->label=trim($this->label); $this->description=trim($this->description); - if ($this->socid == -1) $this->socid = 0; $this->db->begin(); @@ -223,7 +228,7 @@ class Categorie } if ($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { - $sql .= ", fk_soc = ".$this->socid; + $sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null'); } $sql .= ", visible = '".$this->visible."'"; $sql .= " WHERE rowid = ".$this->id; diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index a04558599af..8e27ca708a9 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -33,6 +33,8 @@ require "./pre.inc.php"; if (!$user->rights->categorie->lire) accessforbidden(); +$type=$_REQUEST['type']; + // If socid provided by ajax company selector if (! empty($_POST['socid_id'])) { @@ -71,7 +73,7 @@ if ($_POST["action"] == 'update' && $user->rights->categorie->creer) { if ($categorie->update($user) > 0) { - header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id); + header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type); exit; } else @@ -114,6 +116,7 @@ print "\n"; print '