Browse Source

NEW Add color on categories

Laurent Destailleur 9 years ago
parent
commit
81b447dd0f

+ 22 - 8
htdocs/categories/class/categorie.class.php

@@ -116,6 +116,13 @@ class Categorie extends CommonObject
 	var $fk_parent;
 	var $label;
 	var $description;
+	/**
+	 * @var string     Color
+	 */
+	var $color;
+	/**
+	 * @var ???
+	 */
 	var $socid;
 	/**
 	 * @var int Category type
@@ -156,7 +163,7 @@ class Categorie extends CommonObject
 		// Check parameters
 		if (empty($id) && empty($label)) return -1;
 
-		$sql = "SELECT rowid, fk_parent, entity, label, description, fk_soc, visible, type";
+		$sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type";
 		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
 		if ($id)
 		{
@@ -180,6 +187,7 @@ class Categorie extends CommonObject
 				$this->fk_parent	= $res['fk_parent'];
 				$this->label		= $res['label'];
 				$this->description	= $res['description'];
+				$this->color    	= $res['color'];
 				$this->socid		= $res['fk_soc'];
 				$this->visible		= $res['visible'];
 				$this->type			= $res['type'];
@@ -225,6 +233,7 @@ class Categorie extends CommonObject
 		// Clean parameters
 		$this->label = trim($this->label);
 		$this->description = trim($this->description);
+		$this->color = trim($this->color);
 		$this->import_key = trim($this->import_key);
 		if (empty($this->visible)) $this->visible=0;
 		$this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
@@ -244,6 +253,7 @@ class Categorie extends CommonObject
 		$sql.= "fk_parent,";
 		$sql.= " label,";
 		$sql.= " description,";
+		$sql.= " color,";
 		if (! empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER))
 		{
 			$sql.= "fk_soc,";
@@ -256,6 +266,7 @@ class Categorie extends CommonObject
 		$sql.= $this->fk_parent.",";
 		$sql.= "'".$this->db->escape($this->label)."',";
 		$sql.= "'".$this->db->escape($this->description)."',";
+		$sql.= "'".$this->db->escape($this->color)."',";
 		if (! empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER))
 		{
 			$sql.= ($this->socid != -1 ? $this->socid : 'null').",";
@@ -358,6 +369,7 @@ class Categorie extends CommonObject
 		$sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
 		$sql.= " SET label = '".$this->db->escape($this->label)."',";
 		$sql.= " description = '".$this->db->escape($this->description)."'";
+		$sql.= " color = '".$this->db->escape($this->color)."'";
 		if (! empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER))
 		{
 			$sql .= ", fk_soc = ".($this->socid != -1 ? $this->socid : 'null');
@@ -562,14 +574,15 @@ class Categorie extends CommonObject
 		if ($this->id == -1) return -2;
 
 		// For backward compatibility
-		if ($type == 'societe') {
+		if ($type == 'societe') 
+		{
 			$type = 'customer';
-			dol_syslog( get_class( $this ) . "::add_type(): type 'societe' is deprecated, please use 'customer' instead",
-				LOG_WARNING );
-		} elseif ($type == 'fournisseur') {
+			dol_syslog(get_class($this) . "::add_type(): type 'societe' is deprecated, please use 'customer' instead",	LOG_WARNING);
+		}
+		elseif ($type == 'fournisseur') 
+		{
 			$type = 'supplier';
-			dol_syslog( get_class( $this ) . "::add_type(): type 'fournisseur' is deprecated, please use 'supplier' instead",
-				LOG_WARNING );
+			dol_syslog(get_class($this) . "::add_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
 		}
 
         $this->db->begin();
@@ -876,7 +889,7 @@ class Categorie extends CommonObject
 		$current_lang = $langs->getDefaultLang();
 
 		// Init $this->cats array
-		$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.fk_parent";	// Distinct reduce pb with old tables with duplicates
+		$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.color, c.fk_parent";	// Distinct reduce pb with old tables with duplicates
 		if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= ", t.label as label_trans, t.description as description_trans";
 		$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
 		if (! empty($conf->global->MAIN_MULTILANGS)) $sql.= " LEFT  JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$current_lang."'";
@@ -895,6 +908,7 @@ class Categorie extends CommonObject
 				$this->cats[$obj->rowid]['fk_parent'] = $obj->fk_parent;
 				$this->cats[$obj->rowid]['label'] = ! empty($obj->label_trans) ? $obj->label_trans : $obj->label;
 				$this->cats[$obj->rowid]['description'] = ! empty($obj->description_trans) ? $obj->description_trans : $obj->description;
+				$this->cats[$obj->rowid]['color'] = $obj->color;
 				$i++;
 			}
 		}

+ 9 - 0
htdocs/categories/edit.php

@@ -39,6 +39,7 @@ $confirm=GETPOST('confirm');
 $socid=GETPOST('socid','int');
 $label=GETPOST('label');
 $description=GETPOST('description');
+$color=GETPOST('color','alpha');
 $visible=GETPOST('visible');
 $parent=GETPOST('parent');
 
@@ -71,6 +72,7 @@ if ($action == 'update' && $user->rights->categorie->creer)
 
 	$categorie->label          = $label;
 	$categorie->description    = dol_htmlcleanlastbr($description);
+	$categorie->color          = $color;
 	$categorie->socid          = ($socid ? $socid : 'null');
 	$categorie->visible        = $visible;
 
@@ -152,6 +154,13 @@ $doleditor=new DolEditor('description',$object->description,'',200,'dolibarr_not
 $doleditor->Create();
 print '</td></tr>';
 
+// Color
+print '<tr>';
+print '<td class="fieldrequired" width="25%">'.$langs->trans("Color").'</td>';
+print '<td >';
+print $formother->select_color($color, 'color');
+print '</td></tr>';
+
 // Parent category
 print '<tr><td>'.$langs->trans("In").'</td><td>';
 print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);

+ 9 - 1
htdocs/categories/viewcat.php

@@ -29,6 +29,7 @@ require '../main.inc.php';
 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
 require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
 
 
 $langs->load("categories");
@@ -159,6 +160,7 @@ if ($type == Categorie::TYPE_PRODUCT && $elemid && $action == 'addintocategory'
  */
 
 $form = new Form($db);
+$formother = new FormOther($db);
 
 llxHeader("","",$langs->trans("Categories"));
 
@@ -197,11 +199,17 @@ foreach ($ways as $way)
 print '</td></tr>';
 
 // Description
-print '<tr><td width="20%" class="notopnoleft">';
+print '<tr><td class="notopnoleft">';
 print $langs->trans("Description").'</td><td>';
 print dol_htmlentitiesbr($object->description);
 print '</td></tr>';
 
+// Color
+print '<tr><td class="notopnoleft">';
+print $langs->trans("Color").'</td><td>';
+print $formother->showColor($object->color);
+print '</td></tr>';
+
 $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 if (empty($reshook) && ! empty($extrafields->attribute_label))
 {

+ 1 - 0
htdocs/install/mysql/migration/3.8.0-3.9.0.sql

@@ -32,6 +32,7 @@ ALTER TABLE llx_societe ADD COLUMN model_pdf varchar(255);
 
 ALTER TABLE llx_societe_commerciaux ADD COLUMN import_key varchar(14) AFTER fk_user;
 
+ALTER TABLE llx_categorie ADD COLUMN color varchar(8);
 
 create table llx_overwrite_trans
 (

+ 2 - 2
htdocs/install/mysql/tables/llx_categorie.sql

@@ -26,10 +26,10 @@ create table llx_categorie
 	label 		    varchar(255) NOT NULL,				-- category name
 	type	        tinyint DEFAULT 1 NOT NULL,			-- category type (product, supplier, customer, member)
 	description 	text,								-- description of the category
-	fk_soc          integer DEFAULT NULL,				-- attribution of the category has a company (for product only)
+    color           varchar(8),                         -- color
+	fk_soc          integer DEFAULT NULL,				-- not used by default. Used when option CATEGORY_ASSIGNED_TO_A_CUSTOMER is set.
 	visible         tinyint DEFAULT 1 NOT NULL,			-- determine if the products are visible or not
     import_key      varchar(14)							-- Import key
-    
 )ENGINE=innodb;
 
 --