From deb94493ddcca6cc43fc7215f4abcf61887376d6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 8 Oct 2008 08:03:28 +0000 Subject: [PATCH] Added ability to assign a category of product to a customer --- htdocs/categories/categorie.class.php | 19 ++++++++++++------- htdocs/categories/edit.php | 5 ++++- htdocs/categories/viewcat.php | 6 +++--- mysql/migration/2.4.0-2.5.0.sql | 2 +- mysql/tables/llx_categorie.sql | 2 +- 5 files changed, 21 insertions(+), 13 deletions(-) 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 '
'; print ''; print ''; +print ''; print ''; print ''; } @@ -161,7 +161,7 @@ print "
\n"; if ($user->rights->categorie->creer) { - print "".$langs->trans("Modify").""; + print "".$langs->trans("Modify").""; } if ($user->rights->categorie->supprimer) diff --git a/mysql/migration/2.4.0-2.5.0.sql b/mysql/migration/2.4.0-2.5.0.sql index bb4106fdfa9..fb74fd36329 100644 --- a/mysql/migration/2.4.0-2.5.0.sql +++ b/mysql/migration/2.4.0-2.5.0.sql @@ -34,7 +34,7 @@ alter table llx_rights_def modify column type varchar(1); ALTER TABLE `llx_commandedet` ADD column `date_start` DATETIME DEFAULT NULL, ADD `date_end` DATETIME DEFAULT NULL ; -alter table llx_categorie add column fk_soc integer DEFAULT 0 after description; +alter table llx_categorie add column fk_soc integer DEFAULT NULL after description; alter table llx_product drop column nbvente; diff --git a/mysql/tables/llx_categorie.sql b/mysql/tables/llx_categorie.sql index c4a07f3a058..93fac289eb6 100644 --- a/mysql/tables/llx_categorie.sql +++ b/mysql/tables/llx_categorie.sql @@ -25,7 +25,7 @@ create table llx_categorie rowid integer AUTO_INCREMENT PRIMARY KEY, label VARCHAR(255), -- category name description text, -- description of the category - fk_soc integer DEFAULT 0, -- attribution of the category has a company (for product only) + fk_soc integer DEFAULT NULL, -- attribution of the category has a company (for product only) visible tinyint DEFAULT 1 NOT NULL, -- determine if the products are visible or not type tinyint DEFAULT 1 NOT NULL -- category type (product, supplier, customer) )type=innodb;
'; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 213ff8faf86..63b4428234b 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -34,7 +34,7 @@ if ($_REQUEST['id'] == "") exit(); } -$type=$_GET['type']; +$type=$_REQUEST['type']; // Securite if (! $user->rights->categorie->lire) @@ -136,7 +136,7 @@ if ($type == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) else { print '
'; - print $langs->trans("InernalCategory").''; + print $langs->trans("InternalCategory").''; print ($c->visible ? $langs->trans("Visible") : $langs->trans("Invisible")); print '