From 2382a0a4ee32b12bf4721a144d34ceddd2761e57 Mon Sep 17 00:00:00 2001
From: KHELIFA <kkhelifa@open-dsi.fr>
Date: Fri, 19 May 2017 10:46:29 +0200
Subject: [PATCH] Core dictionaries: Adds the ability to change the color and
 position of the dictionary 'Types of agenda events'

---
 htdocs/admin/dict.php         | 42 ++++++++++++++++++++++++++---------
 htdocs/langs/en_US/admin.lang |  1 +
 htdocs/langs/fr_FR/admin.lang |  1 +
 3 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 46a8001b02a..2b422074f1b 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -431,7 +431,7 @@ $tabhelp[2]  = array('code'=>$langs->trans("EnterAnyCode"));
 $tabhelp[3]  = array('code'=>$langs->trans("EnterAnyCode"));
 $tabhelp[4]  = array('code'=>$langs->trans("EnterAnyCode"));
 $tabhelp[5]  = array('code'=>$langs->trans("EnterAnyCode"));
-$tabhelp[6]  = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
+$tabhelp[6]  = array('code'=>$langs->trans("EnterAnyCode"), 'color'=>$langs->trans("ColorFormat"), 'position'=>$langs->trans("PositionIntoComboList"));
 $tabhelp[7]  = array('code'=>$langs->trans("EnterAnyCode"));
 $tabhelp[8]  = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
 $tabhelp[9]  = array('code'=>$langs->trans("EnterAnyCode"), 'unicode'=>$langs->trans("UnicodeCurrency"));
@@ -581,6 +581,12 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
     $listfieldmodify=explode(',',$tabfieldinsert[$id]);
     $listfieldvalue=explode(',',$tabfieldvalue[$id]);
 
+    if (GETPOST('actionmodify') && $tabname[$id] == MAIN_DB_PREFIX . "c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
+        $listfield=explode(',','color,position');
+        $listfieldmodify=explode(',','color,position');
+        $listfieldvalue=explode(',','color,position');
+    }
+
     // Check that all fields are filled
     $ok=1;
     foreach ($listfield as $f => $value)
@@ -619,7 +625,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify'))
         }
     }
     // Other checks
-    if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
+    if (GETPOST('actionadd') && $tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
         $ok=0;
         setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
     }
@@ -1104,7 +1110,7 @@ if ($id)
 
         if (empty($reshook))
         {
-       		fieldList($fieldlist,$obj,$tabname[$id],'add');
+       		fieldList($fieldlist,$langs,$obj,$tabname[$id],'add');
         }
 
         if ($id == 4) print '<td></td>';
@@ -1304,7 +1310,13 @@ if ($id)
                     $error=$hookmanager->error; $errors=$hookmanager->errors;
 
                     // Show fields
-                    if (empty($reshook)) fieldList($fieldlist,$obj,$tabname[$id],'edit');
+                    if (empty($reshook)) {
+                        $fieldl = $fieldlist;
+                        if ($tabname[$id] == MAIN_DB_PREFIX . "c_actioncomm" && in_array($obj->type, array('system', 'systemauto'))) {
+                            $fieldl=array(array('code'),array('libelle'),array('type'),'color','position');
+                        }
+                        fieldList($fieldl, $langs, $obj, $tabname[$id], 'edit');
+                    }
 
                     print '<td colspan="3" align="center">';
                     print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
@@ -1512,6 +1524,7 @@ if ($id)
                     if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
                     $canbemodified=$iserasable;
                     if ($obj->code == 'RECEP') $canbemodified=1;
+                    if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm") $canbemodified=1;
 
                     // Url 
                     $rowidcol=$tabrowid[$id];
@@ -1643,15 +1656,16 @@ $db->close();
 /**
  *	Show fields in insert/edit mode
  *
- * 	@param		array	$fieldlist		Array of fields
- * 	@param		Object	$obj			If we show a particular record, obj is filled with record fields
- *  @param		string	$tabname		Name of SQL table
- *  @param		string	$context		'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered
+ * 	@param		array		$fieldlist		Array of fields
+ * 	@param		Translate	$langs			Translate class
+ * 	@param		Object		$obj			If we show a particular record, obj is filled with record fields
+ *  @param		string		$tabname		Name of SQL table
+ *  @param		string		$context		'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered
  *	@return		void
  */
-function fieldList($fieldlist, $obj='', $tabname='', $context='')
+function fieldList($fieldlist, $langs, $obj='', $tabname='', $context='')
 {
-	global $conf,$langs,$db;
+	global $conf,$db;
 	global $form;
 	global $region_id;
 	global $elementList,$sourceList,$localtax_typeList;
@@ -1809,6 +1823,14 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='')
 			}
 			print '</td>';
 		}
+        elseif (is_array($fieldlist[$field]))
+        {
+            $hidden = (! empty($obj->{$fieldlist[$field][0]})?$obj->{$fieldlist[$field][0]}:'');
+            print '<td>';
+            print '<input type="hidden" name="'.$fieldlist[$field][0].'" value="'.$hidden.'">';
+            print $langs->trans($hidden);
+            print '</td>';
+        }
 		else
 		{
 			$classtd=''; $class='';
diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang
index 1c9ac65e4b8..070b58d40c2 100644
--- a/htdocs/langs/en_US/admin.lang
+++ b/htdocs/langs/en_US/admin.lang
@@ -1632,6 +1632,7 @@ MinimumNoticePeriod=Minimum notice period (Your leave request must be done befor
 NbAddedAutomatically=Number of days added to counters of users (automatically) each month
 EnterAnyCode=This field contains a reference to identify line. Enter any value of your choice, but without special characters.
 UnicodeCurrency=Enter here between braces, list of byte number that represent the currency symbol. For exemple: for $, enter [36] - for brazil real R$ [82,36] - for €, enter [8364]
+ColorFormat=The RGB color is in HEX format, eg: FF0000
 PositionIntoComboList=Position of line into combo lists
 SellTaxRate=Sale tax rate
 RecuperableOnly=Yes for VAT "Non Perçue Récupérable" dedicated for some state in France. Keep value to "No" in all other cases.
diff --git a/htdocs/langs/fr_FR/admin.lang b/htdocs/langs/fr_FR/admin.lang
index bd3d6405843..4eac426571d 100644
--- a/htdocs/langs/fr_FR/admin.lang
+++ b/htdocs/langs/fr_FR/admin.lang
@@ -1600,6 +1600,7 @@ MinimumNoticePeriod=Période de préavis minimum (Votre demande de congé doit 
 NbAddedAutomatically=Nombre de jours ajoutés aux compteurs des utilisateurs (automatiquement) chaque mois
 EnterAnyCode=Ce champ contient une référence pour identifier le champ. Entrez une valeur de votre choix, mais sans caractères spéciaux.
 UnicodeCurrency=Saisissez ici entre accolades, la liste du numéro des octets qui représentent le symbole de la monnaie. Pour exemple: pour $, entrez [36] - pour le Real Brésilien R$ [82,36] - pour l'euro €, entrez [8364]
+ColorFormat=La couleur RVB est au format HEX, ex: FF0000
 PositionIntoComboList=Position de la ligne dans des listes déroulantes
 SellTaxRate=Taux de TVA
 RecuperableOnly=Oui pour une TVA "Perçue Non Récupérable" dédiée à certains pays comme la France. Gardez la valeur à "Non" dans tous les autres cas.
-- 
GitLab