From 5f74b86b18d3a27b78726c5e214a3ca3004398e7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Ferry?= <jfefe@aternatik.fr>
Date: Sun, 23 Mar 2014 19:21:58 +0100
Subject: [PATCH] Add dictionary to define type of resources

---
 htdocs/admin/dict.php                          | 12 +++++++++++-
 htdocs/install/mysql/migration/3.5.0-3.6.0.sql | 10 ++++++++++
 htdocs/langs/en_US/resource.lang               |  4 +++-
 htdocs/resource/class/resource.class.php       |  6 +++---
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php
index 51d9ca2bced..16f9aed618f 100644
--- a/htdocs/admin/dict.php
+++ b/htdocs/admin/dict.php
@@ -70,7 +70,7 @@ $hookmanager->initHooks(array('admin'));
 // Put here declaration of dictionaries properties
 
 // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
-$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,25,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,23);
+$taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,25,12,13,0,14,0,7,17,0,22,20,18,21,0,15,0,24,23,0,26);
 
 // Name of SQL tables of dictionaries
 $tabname=array();
@@ -99,6 +99,7 @@ $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
 $tabname[23]= MAIN_DB_PREFIX."accountingaccount";
 $tabname[24]= MAIN_DB_PREFIX."accounting_system";
 $tabname[25]= MAIN_DB_PREFIX."c_revenuestamp";
+$tabname[26]= MAIN_DB_PREFIX."c_type_resource";
 
 // Dictionary labels
 $tablib=array();
@@ -127,6 +128,7 @@ $tablib[22]= "DictionarySource";
 $tablib[23]= "DictionaryAccountancyplan";
 $tablib[24]= "DictionaryAccountancysystem";
 $tablib[25]= "DictionaryRevenueStamp";
+$tablib[26]= "DictionaryResourceType";
 
 // Requete pour extraction des donnees des dictionnaires
 $tabsql=array();
@@ -155,6 +157,7 @@ $tabsql[22]= "SELECT rowid   as rowid, code, label, active FROM ".MAIN_DB_PREFIX
 $tabsql[23]= "SELECT rowid   as rowid, fk_pcg_version, pcg_type, pcg_subtype, account_number as accountancy_code, account_parent, label, active FROM ".MAIN_DB_PREFIX."accountingaccount";
 $tabsql[24]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as country_id, p.code as country_code, p.libelle as pays, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_pays as p WHERE s.fk_pays=p.rowid and p.active=1";
 $tabsql[25]= "SELECT t.rowid, t.taux, p.libelle as country, p.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_pays as p WHERE t.fk_pays=p.rowid";
+$tabsql[26]= "SELECT rowid   as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
 
 // Critere de tri du dictionnaire
 $tabsqlsort=array();
@@ -183,6 +186,7 @@ $tabsqlsort[22]="code ASC, label ASC";
 $tabsqlsort[23]="fk_pcg_version ASC, accountancy_code ASC";
 $tabsqlsort[24]="pcg_version ASC";
 $tabsqlsort[25]="country ASC, taux ASC";
+$tabsqlsort[26]="code ASC,label ASC";
 
 // Nom des champs en resultat de select pour affichage du dictionnaire
 $tabfield=array();
@@ -211,6 +215,7 @@ $tabfield[22]= "code,label";
 $tabfield[23]= "fk_pcg_version,accountancy_code,account_parent,pcg_type,pcg_subtype,label";
 $tabfield[24]= "pcg_version,country_id,country,label";
 $tabfield[25]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
+$tabfield[26]= "code,label";
 
 // Nom des champs d'edition pour modification d'un enregistrement
 $tabfieldvalue=array();
@@ -239,6 +244,7 @@ $tabfieldvalue[22]= "code,label";
 $tabfieldvalue[23]= "fk_pcg_version,accountancy_code,account_parent,pcg_type,pcg_subtype,label";
 $tabfieldvalue[24]= "pcg_version,country,label";
 $tabfieldvalue[25]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
+$tabfieldvalue[26]= "code,label";
 
 // Nom des champs dans la table pour insertion d'un enregistrement
 $tabfieldinsert=array();
@@ -267,6 +273,7 @@ $tabfieldinsert[22]= "code,label";
 $tabfieldinsert[23]= "fk_pcg_version,account_number,account_parent,pcg_type,pcg_subtype,label";
 $tabfieldinsert[24]= "pcg_version,fk_pays,label";
 $tabfieldinsert[25]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
+$tabfieldinsert[26]= "code,label";
 
 // Nom du rowid si le champ n'est pas de type autoincrement
 // Example: "" if id field is "rowid" and has autoincrement on
@@ -297,6 +304,7 @@ $tabrowid[22]= "rowid";
 $tabrowid[23]= "";
 $tabrowid[24]= "";
 $tabrowid[25]= "";
+$tabrowid[25]= "";
 
 // Condition to show dictionary in setup page
 $tabcond=array();
@@ -325,6 +333,7 @@ $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabl
 $tabcond[23]= (! empty($conf->global->ACCOUNTING_USEDICTTOEDIT) && ! empty($conf->accounting->enabled));	// The accountancy plan should be edited with specific pages. You can set ACCOUNTING_USEDICTTOEDIT to 1 if you want to use dictionary editor.
 $tabcond[24]= (! empty($conf->global->ACCOUNTING_USEDICTTOEDIT) && ! empty($conf->accounting->enabled));	// The accountancy system should be edited with specific pages. You can set ACCOUNTING_USEDICTTOEDIT to 1 if you want to use dictionary editor.
 $tabcond[25]= true;
+$tabcond[26]= ! empty($conf->resource->enabled);
 
 // List of help for fields
 $tabhelp=array();
@@ -353,6 +362,7 @@ $tabhelp[22] = array();
 $tabhelp[23] = array();
 $tabhelp[24] = array();
 $tabhelp[25] = array();
+$tabhelp[26] = array();
 
 // Complete all arrays with entries found into modules
 complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp);
diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
index 400d26af2b2..7cccaa7b00a 100644
--- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
+++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
@@ -1187,3 +1187,13 @@ CREATE TABLE llx_element_resources
 ALTER TABLE llx_element_resources ADD UNIQUE INDEX idx_element_resources_idx1 (resource_id, resource_type, element_id, element_type);
 ALTER TABLE llx_element_resources ADD INDEX idx_element_element_element_id (element_id);
 -- Pas de contraite sur resource_id et element_id car pointe sur differentes tables
+
+create table llx_c_type_resource
+(
+  rowid      	integer     PRIMARY KEY,
+  code          varchar(32) NOT NULL,
+  label 	    varchar(64)	NOT NULL,
+  active  	    tinyint DEFAULT 1  NOT NULL
+)ENGINE=innodb;
+
+ALTER TABLE llx_c_type_resource ADD UNIQUE INDEX uk_c_type_resource_id (label, code);
diff --git a/htdocs/langs/en_US/resource.lang b/htdocs/langs/en_US/resource.lang
index eb3250183b9..f1712db18c7 100755
--- a/htdocs/langs/en_US/resource.lang
+++ b/htdocs/langs/en_US/resource.lang
@@ -29,4 +29,6 @@ TitleResourceCard=Resource card
 ResourceSingular=Resource
 
 ResourceName=Resource name
-ResourceType=Resource type
\ No newline at end of file
+ResourceType=Type of resource
+
+DictionaryResourceType=Type of resources
\ No newline at end of file
diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/resource.class.php
index 51faf8d7b59..4f56fcce0b5 100644
--- a/htdocs/resource/class/resource.class.php
+++ b/htdocs/resource/class/resource.class.php
@@ -677,7 +677,7 @@ class Resource extends CommonObject
     
     	if (count($this->cache_code_type_resource)) return 0;    // Cache deja charge
     
-    	$sql = "SELECT rowid, code, libelle, active";
+    	$sql = "SELECT rowid, code, label, active";
     	$sql.= " FROM ".MAIN_DB_PREFIX."c_type_resource";
     	$sql.= " WHERE active > 0";
     	$sql.= " ORDER BY rowid";
@@ -691,9 +691,9 @@ class Resource extends CommonObject
     		{
     			$obj = $this->db->fetch_object($resql);
     			// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
-    			$label=($langs->trans("ResourceTypeShort".$obj->code)!=("ResourceTypeShort".$obj->code)?$langs->trans("ResourceTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:''));
+    			$label=($langs->trans("ResourceTypeShort".$obj->code)!=("ResourceTypeShort".$obj->code)?$langs->trans("ResourceTypeShort".$obj->code):($obj->label!='-'?$obj->label:''));
     			$this->cache_code_type_resource[$obj->rowid]['code'] =$obj->code;
-    			$this->cache_code_type_resource[$obj->rowid]['libelle']=$label;
+    			$this->cache_code_type_resource[$obj->rowid]['label']=$label;
     			$this->cache_code_type_resource[$obj->rowid]['active'] =$obj->active;
     			$i++;
     		}
-- 
GitLab