PageRenderTime 56ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/admin/dict.php

https://github.com/asterix14/dolibarr
PHP | 1067 lines | 871 code | 92 blank | 104 comment | 275 complexity | fea6528025057ad403f0a3f19511f528 MD5 | raw file
Possible License(s): LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
  6. * Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/dict.php
  25. * \ingroup setup
  26. * \brief Page to administer data tables
  27. */
  28. require("../main.inc.php");
  29. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formadmin.class.php");
  30. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formcompany.class.php");
  31. require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php");
  32. $langs->load("errors");
  33. $langs->load("admin");
  34. $langs->load("companies");
  35. $action=GETPOST('action')?GETPOST('action'):'view';
  36. if (!$user->admin) accessforbidden();
  37. $acts[0] = "activate";
  38. $acts[1] = "disable";
  39. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  40. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  41. $listoffset=GETPOST('listoffset');
  42. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  43. $active = 1;
  44. $sortfield = GETPOST("sortfield",'alpha');
  45. $sortorder = GETPOST("sortorder",'alpha');
  46. $page = GETPOST("page",'int');
  47. if ($page == -1) { $page = 0 ; }
  48. $offset = $listlimit * $page ;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  52. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  53. $hookmanager=new HookManager($db);
  54. $hookmanager->callHooks(array('admin'));
  55. // Thi page is a generic page to edit dictionnaries
  56. // Put here delacaration of dictionnaries properties
  57. // Sort order to show dictionnary (0 is space). All other dictionnaries (added by modules) will be at end of this.
  58. $taborder=array(9,0,4,3,2,0,1,8,19,16,0,5,11,0,6,0,10,12,13,0,14,0,7,17,0,22,20,18,21,0,15);
  59. // Name of SQL tables of dictionnaries
  60. $tabname[1] = MAIN_DB_PREFIX."c_forme_juridique";
  61. $tabname[2] = MAIN_DB_PREFIX."c_departements";
  62. $tabname[3] = MAIN_DB_PREFIX."c_regions";
  63. $tabname[4] = MAIN_DB_PREFIX."c_pays";
  64. $tabname[5] = MAIN_DB_PREFIX."c_civilite";
  65. $tabname[6] = MAIN_DB_PREFIX."c_actioncomm";
  66. $tabname[7] = MAIN_DB_PREFIX."c_chargesociales";
  67. $tabname[8] = MAIN_DB_PREFIX."c_typent";
  68. $tabname[9] = MAIN_DB_PREFIX."c_currencies";
  69. $tabname[10]= MAIN_DB_PREFIX."c_tva";
  70. $tabname[11]= MAIN_DB_PREFIX."c_type_contact";
  71. $tabname[12]= MAIN_DB_PREFIX."c_payment_term";
  72. $tabname[13]= MAIN_DB_PREFIX."c_paiement";
  73. $tabname[14]= MAIN_DB_PREFIX."c_ecotaxe";
  74. $tabname[15]= MAIN_DB_PREFIX."c_paper_format";
  75. $tabname[16]= MAIN_DB_PREFIX."c_prospectlevel";
  76. $tabname[17]= MAIN_DB_PREFIX."c_type_fees";
  77. $tabname[18]= MAIN_DB_PREFIX."c_shipment_mode";
  78. $tabname[19]= MAIN_DB_PREFIX."c_effectif";
  79. $tabname[20]= MAIN_DB_PREFIX."c_input_method";
  80. $tabname[21]= MAIN_DB_PREFIX."c_availability";
  81. $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
  82. // Dictionary labels
  83. $tablib[1] = "DictionnaryCompanyJuridicalType";
  84. $tablib[2] = "DictionnaryCanton";
  85. $tablib[3] = "DictionnaryRegion";
  86. $tablib[4] = "DictionnaryCountry";
  87. $tablib[5] = "DictionnaryCivility";
  88. $tablib[6] = "DictionnaryActions";
  89. $tablib[7] = "DictionnarySocialContributions";
  90. $tablib[8] = "DictionnaryCompanyType";
  91. $tablib[9] = "DictionnaryCurrency";
  92. $tablib[10]= "DictionnaryVAT";
  93. $tablib[11]= "DictionnaryTypeContact";
  94. $tablib[12]= "DictionnaryPaymentConditions";
  95. $tablib[13]= "DictionnaryPaymentModes";
  96. $tablib[14]= "DictionnaryEcotaxe";
  97. $tablib[15]= "DictionnaryPaperFormat";
  98. $tablib[16]= "DictionnaryProspectLevel";
  99. $tablib[17]= "DictionnaryFees";
  100. $tablib[18]= "DictionnarySendingMethods";
  101. $tablib[19]= "DictionnaryStaff";
  102. $tablib[20]= "DictionnaryOrderMethods";
  103. $tablib[21]= "DictionnaryAvailability";
  104. $tablib[22]= "DictionnarySource";
  105. // Requete pour extraction des donnees des dictionnaires
  106. $tabsql[1] = "SELECT f.rowid as rowid, f.code, f.libelle, p.code as pays_code, p.libelle as pays, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_pays as p WHERE f.fk_pays=p.rowid";
  107. $tabsql[2] = "SELECT d.rowid as rowid, d.code_departement as code, d.nom as libelle, d.fk_region as region_id, r.nom as region, p.code as pays_code, p.libelle as pays, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p WHERE d.fk_region=r.code_region and r.fk_pays=p.rowid and r.active=1 and p.active=1";
  108. $tabsql[3] = "SELECT r.rowid as rowid, code_region as code, nom as libelle, r.fk_pays as pays_id, p.code as pays_code, p.libelle as pays, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_pays as p WHERE r.fk_pays=p.rowid and p.active=1";
  109. $tabsql[4] = "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_pays";
  110. $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.civilite AS libelle, c.active FROM ".MAIN_DB_PREFIX."c_civilite AS c";
  111. $tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
  112. $tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.deductible, p.code as pays_code, p.libelle as pays, a.fk_pays as pays_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_pays as p WHERE a.fk_pays=p.rowid and p.active=1";
  113. $tabsql[8] = "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_typent";
  114. //$tabsql[9] = "SELECT code, code_iso, label as libelle, symbole, active FROM ".MAIN_DB_PREFIX."c_currencies";
  115. $tabsql[9] = "SELECT code, code_iso, label as libelle, active FROM ".MAIN_DB_PREFIX."c_currencies";
  116. $tabsql[10]= "SELECT t.rowid, t.taux, t.localtax1, t.localtax2, p.libelle as pays, p.code as pays_code, t.fk_pays as pays_id, t.recuperableonly, t.note, t.active, t.accountancy_code FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p WHERE t.fk_pays=p.rowid";
  117. $tabsql[11]= "SELECT t.rowid as rowid, element, source, code, libelle, active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
  118. $tabsql[12]= "SELECT c.rowid as rowid, code, sortorder, c.libelle, c.libelle_facture, nbjour, fdm, decalage, active FROM ".MAIN_DB_PREFIX.'c_payment_term AS c';
  119. $tabsql[13]= "SELECT id as rowid, code, c.libelle, type, active FROM ".MAIN_DB_PREFIX."c_paiement AS c";
  120. $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as pays_id, p.code as pays_code, p.libelle as pays, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_pays as p WHERE e.fk_pays=p.rowid and p.active=1";
  121. $tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
  122. $tabsql[16]= "SELECT code, label as libelle, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  123. $tabsql[17]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_type_fees";
  124. $tabsql[18]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
  125. $tabsql[19]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
  126. $tabsql[20]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
  127. $tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
  128. $tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
  129. // Critere de tri du dictionnaire
  130. $tabsqlsort[1] ="pays ASC, code ASC";
  131. $tabsqlsort[2] ="pays ASC, code ASC";
  132. $tabsqlsort[3] ="pays ASC, code ASC";
  133. $tabsqlsort[4] ="code ASC";
  134. $tabsqlsort[5] ="libelle ASC";
  135. $tabsqlsort[6] ="a.type ASC, a.module, a.position, a.code ASC";
  136. $tabsqlsort[7] ="pays ASC, code ASC, a.libelle ASC";
  137. $tabsqlsort[8] ="libelle ASC";
  138. $tabsqlsort[9] ="code ASC";
  139. $tabsqlsort[10]="pays ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
  140. $tabsqlsort[11]="element ASC, source ASC, code ASC";
  141. $tabsqlsort[12]="sortorder ASC, code ASC";
  142. $tabsqlsort[13]="code ASC";
  143. $tabsqlsort[14]="pays ASC, e.organization ASC, code ASC";
  144. $tabsqlsort[15]="rowid ASC";
  145. $tabsqlsort[16]="sortorder ASC";
  146. $tabsqlsort[17]="code ASC";
  147. $tabsqlsort[18]="code ASC, libelle ASC";
  148. $tabsqlsort[19]="id ASC";
  149. $tabsqlsort[20]="code ASC, libelle ASC";
  150. $tabsqlsort[21]="code ASC, label ASC";
  151. $tabsqlsort[22]="code ASC, label ASC";
  152. // Nom des champs en resultat de select pour affichage du dictionnaire
  153. $tabfield[1] = "code,libelle,pays";
  154. $tabfield[2] = "code,libelle,region_id,region,pays"; // "code,libelle,region,pays_code-pays"
  155. $tabfield[3] = "code,libelle,pays_id,pays";
  156. $tabfield[4] = "code,libelle";
  157. $tabfield[5] = "code,libelle";
  158. $tabfield[6] = "code,libelle,type,position";
  159. $tabfield[7] = "code,libelle,pays_id,pays,deductible";
  160. $tabfield[8] = "code,libelle";
  161. //$tabfield[9] = "code,code_iso,libelle,symbole";
  162. $tabfield[9] = "code,code_iso,libelle";
  163. $tabfield[10]= "pays_id,pays,taux,recuperableonly,localtax1,localtax2,accountancy_code,note";
  164. $tabfield[11]= "element,source,code,libelle";
  165. $tabfield[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage";
  166. $tabfield[13]= "code,libelle,type";
  167. $tabfield[14]= "code,libelle,price,organization,pays_id,pays";
  168. $tabfield[15]= "code,libelle,width,height,unit";
  169. $tabfield[16]= "code,libelle";
  170. $tabfield[17]= "code,libelle";
  171. $tabfield[18]= "code,libelle";
  172. $tabfield[19]= "code,libelle";
  173. $tabfield[20]= "code,libelle";
  174. $tabfield[21]= "code,label";
  175. $tabfield[22]= "code,label";
  176. // Nom des champs d'edition pour modification d'un enregistrement
  177. $tabfieldvalue[1] = "code,libelle,pays";
  178. $tabfieldvalue[2] = "code,libelle,region"; // "code,libelle,region"
  179. $tabfieldvalue[3] = "code,libelle,pays";
  180. $tabfieldvalue[4] = "code,libelle";
  181. $tabfieldvalue[5] = "code,libelle";
  182. $tabfieldvalue[6] = "code,libelle,type,position";
  183. $tabfieldvalue[7] = "code,libelle,pays,deductible";
  184. $tabfieldvalue[8] = "code,libelle";
  185. //$tabfieldvalue[9] = "code,code_iso,libelle,symbole";
  186. $tabfieldvalue[9] = "code,code_iso,libelle";
  187. $tabfieldvalue[10]= "pays,taux,recuperableonly,localtax1,localtax2,accountancy_code,note";
  188. $tabfieldvalue[11]= "element,source,code,libelle";
  189. $tabfieldvalue[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage";
  190. $tabfieldvalue[13]= "code,libelle,type";
  191. $tabfieldvalue[14]= "code,libelle,price,organization,pays";
  192. $tabfieldvalue[15]= "code,libelle,width,height,unit";
  193. $tabfieldvalue[16]= "code,libelle";
  194. $tabfieldvalue[17]= "code,libelle";
  195. $tabfieldvalue[18]= "code,libelle";
  196. $tabfieldvalue[19]= "code,libelle";
  197. $tabfieldvalue[20]= "code,libelle";
  198. $tabfieldvalue[21]= "code,label";
  199. $tabfieldvalue[22]= "code,label";
  200. // Nom des champs dans la table pour insertion d'un enregistrement
  201. $tabfieldinsert[1] = "code,libelle,fk_pays";
  202. $tabfieldinsert[2] = "code_departement,nom,fk_region";
  203. $tabfieldinsert[3] = "code_region,nom,fk_pays";
  204. $tabfieldinsert[4] = "code,libelle";
  205. $tabfieldinsert[5] = "code,civilite";
  206. $tabfieldinsert[6] = "code,libelle,type,position";
  207. $tabfieldinsert[7] = "code,libelle,fk_pays,deductible";
  208. $tabfieldinsert[8] = "code,libelle";
  209. //$tabfieldinsert[9] = "code,code_iso,label,symbole";
  210. $tabfieldinsert[9] = "code,code_iso,label";
  211. $tabfieldinsert[10]= "fk_pays,taux,recuperableonly,localtax1,localtax2,accountancy_code,note";
  212. $tabfieldinsert[11]= "element,source,code,libelle";
  213. $tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,fdm,decalage";
  214. $tabfieldinsert[13]= "code,libelle,type";
  215. $tabfieldinsert[14]= "code,libelle,price,organization,fk_pays";
  216. $tabfieldinsert[15]= "code,label,width,height,unit";
  217. $tabfieldinsert[16]= "code,label";
  218. $tabfieldinsert[17]= "code,libelle";
  219. $tabfieldinsert[18]= "code,libelle";
  220. $tabfieldinsert[19]= "code,libelle";
  221. $tabfieldinsert[20]= "code,libelle";
  222. $tabfieldinsert[21]= "code,label";
  223. $tabfieldinsert[22]= "code,label";
  224. // Nom du rowid si le champ n'est pas de type autoincrement
  225. // Example: "" if id field is "rowid" and has autoincrement on
  226. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  227. $tabrowid[1] = "";
  228. $tabrowid[2] = "";
  229. $tabrowid[3] = "";
  230. $tabrowid[4] = "rowid";
  231. $tabrowid[5] = "rowid";
  232. $tabrowid[6] = "id";
  233. $tabrowid[7] = "id";
  234. $tabrowid[8] = "id";
  235. $tabrowid[9] = "code";
  236. $tabrowid[10]= "";
  237. $tabrowid[11]= "rowid";
  238. $tabrowid[12]= "rowid";
  239. $tabrowid[13]= "id";
  240. $tabrowid[14]= "";
  241. $tabrowid[15]= "";
  242. $tabrowid[16]= "code";
  243. $tabrowid[17]= "id";
  244. $tabrowid[18]= "rowid";
  245. $tabrowid[19]= "id";
  246. $tabrowid[20]= "";
  247. $tabrowid[21]= "rowid";
  248. $tabrowid[22]= "rowid";
  249. // Condition to show dictionnary in setup page
  250. $tabcond[1] = true;
  251. $tabcond[2] = true;
  252. $tabcond[3] = true;
  253. $tabcond[4] = true;
  254. $tabcond[5] = $conf->societe->enabled||$conf->adherent->enabled;
  255. $tabcond[6] = $conf->agenda->enabled;
  256. $tabcond[7] = $conf->tax->enabled;
  257. $tabcond[8] = $conf->societe->enabled;
  258. $tabcond[9] = true;
  259. $tabcond[10]= true;
  260. $tabcond[11]= true;
  261. $tabcond[12]= $conf->commande->enabled||$conf->propale->enabled||$conf->facture->enabled||$conf->fournisseur->enabled;
  262. $tabcond[13]= $conf->commande->enabled||$conf->propale->enabled||$conf->facture->enabled||$conf->fournisseur->enabled;
  263. $tabcond[14]= $conf->product->enabled&&$conf->ecotax->enabled;
  264. $tabcond[15]= true;
  265. $tabcond[16]= $conf->societe->enabled && empty($conf->global->SOCIETE_DISABLE_PROSPECTS);
  266. $tabcond[17]= $conf->deplacement->enabled;
  267. $tabcond[18]= $conf->expedition->enabled;
  268. $tabcond[19]= $conf->societe->enabled;
  269. $tabcond[20]= $conf->fournisseur->enabled;
  270. $tabcond[21]= $conf->propale->enabled;
  271. $tabcond[22]= $conf->commande->enabled||$conf->propale->enabled;
  272. complete_dictionnary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond);
  273. // Define elementList and sourceList (used for dictionnary "type of contacts")
  274. $elementList = array();
  275. $sourceList=array();
  276. if (GETPOST("id") == 11)
  277. {
  278. $langs->load("orders");
  279. $langs->load("contracts");
  280. $langs->load("projects");
  281. $langs->load("propal");
  282. $langs->load("bills");
  283. $langs->load("interventions");
  284. $elementList = array("commande"=>$langs->trans("Order"),
  285. "order_supplier"=>$langs->trans("SupplierOrder"),
  286. "contrat"=>$langs->trans("Contract"),
  287. "project"=>$langs->trans("Project"),
  288. "project_task"=>$langs->trans("Task"),
  289. "propal"=>$langs->trans("Propal"),
  290. "facture"=>$langs->trans("Bill"),
  291. "facture_fourn"=>$langs->trans("SupplierBill"),
  292. "fichinter"=>$langs->trans("InterventionCard"));
  293. if ($conf->global->MAIN_SUPPORT_CONTACT_TYPE_FOR_THIRDPARTIES) $elementList["societe"]=$langs->trans("ThirdParty");
  294. $sourceList = array("internal"=>$langs->trans("Internal"),
  295. "external"=>$langs->trans("External"));
  296. }
  297. $msg='';
  298. /*
  299. * Actions ajout ou modification d'une entree dans un dictionnaire de donnee
  300. */
  301. if ($_POST["actionadd"] || $_POST["actionmodify"])
  302. {
  303. $listfield=explode(',',$tabfield[$_POST["id"]]);
  304. $listfieldinsert=explode(',',$tabfieldinsert[$_POST["id"]]);
  305. $listfieldmodify=explode(',',$tabfieldinsert[$_POST["id"]]);
  306. $listfieldvalue=explode(',',$tabfieldvalue[$_POST["id"]]);
  307. // Check that all fields are filled
  308. $ok=1;
  309. foreach ($listfield as $f => $value)
  310. {
  311. if ($value == 'pays')
  312. {
  313. if (in_array('region_id',$listfield)) { continue; } // For region page, we do not require the country input
  314. }
  315. if ((! isset($_POST[$value]) || $_POST[$value]=='')
  316. && $listfield[$f] != 'decalage' // Fields that are not mandatory
  317. && $listfield[$f] != 'module' // Fields that are not mandatory
  318. && $listfield[$f] != 'accountancy_code') // Fields that are not mandatory
  319. {
  320. $ok=0;
  321. $fieldnamekey=$listfield[$f];
  322. // We take translate key of field
  323. if ($fieldnamekey == 'libelle') $fieldnamekey='Label';
  324. if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
  325. if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
  326. if ($fieldnamekey == 'module') $fieldnamekey='Module';
  327. $msg.=$langs->trans("ErrorFieldRequired",$langs->transnoentities($fieldnamekey)).'<br>';
  328. }
  329. }
  330. // Autres verif
  331. if ($tabname[$_POST["id"]] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && $_POST["type"]=='system') {
  332. $ok=0;
  333. $msg.="Value 'system' for type is reserved. You can use 'user' as value to add your own record.<br>";
  334. }
  335. if (isset($_POST["code"]) && $_POST["code"]=='0') {
  336. $ok=0;
  337. $msg.="Code can't contains value 0<br>";
  338. }
  339. if (isset($_POST["pays"]) && $_POST["pays"]=='0') {
  340. $ok=0;
  341. $msg.=$langs->trans("ErrorFieldRequired",$langs->trans("Country")).'<br>';
  342. }
  343. // Si verif ok et action add, on ajoute la ligne
  344. if ($ok && $_POST["actionadd"])
  345. {
  346. if ($tabrowid[$_POST["id"]])
  347. {
  348. // Recupere id libre pour insertion
  349. $newid=0;
  350. $sql = "SELECT max(".$tabrowid[$_POST["id"]].") newid from ".$tabname[$_POST["id"]];
  351. $result = $db->query($sql);
  352. if ($result)
  353. {
  354. $obj = $db->fetch_object($result);
  355. $newid=($obj->newid + 1);
  356. } else {
  357. dol_print_error($db);
  358. }
  359. }
  360. // Add new entry
  361. $sql = "INSERT INTO ".$tabname[$_POST["id"]]." (";
  362. // List of fields
  363. if ($tabrowid[$_POST["id"]] &&
  364. ! in_array($tabrowid[$_POST["id"]],$listfieldinsert)) $sql.= $tabrowid[$_POST["id"]].",";
  365. $sql.= $tabfieldinsert[$_POST["id"]];
  366. $sql.=",active)";
  367. $sql.= " VALUES(";
  368. // List of values
  369. if ($tabrowid[$_POST["id"]] &&
  370. ! in_array($tabrowid[$_POST["id"]],$listfieldinsert)) $sql.= $newid.",";
  371. $i=0;
  372. foreach ($listfieldinsert as $f => $value)
  373. {
  374. if ($value == 'price') { $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); }
  375. if ($i) $sql.=",";
  376. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  377. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  378. $i++;
  379. }
  380. $sql.=",1)";
  381. dol_syslog("actionadd sql=".$sql);
  382. $result = $db->query($sql);
  383. if ($result) // Add is ok
  384. {
  385. $oldid=$_POST["id"];
  386. $_POST=array('id'=>$oldid); // Clean $_POST array, we keep only
  387. $_GET["id"]=$_POST["id"]; // Force affichage dictionnaire en cours d'edition
  388. }
  389. else
  390. {
  391. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  392. $msg=$langs->trans("ErrorRecordAlreadyExists").'<br>';
  393. }
  394. else {
  395. dol_print_error($db);
  396. }
  397. }
  398. }
  399. // Si verif ok et action modify, on modifie la ligne
  400. if ($ok && $_POST["actionmodify"])
  401. {
  402. if ($tabrowid[$_POST["id"]]) { $rowidcol=$tabrowid[$_POST["id"]]; }
  403. else { $rowidcol="rowid"; }
  404. // Modify entry
  405. $sql = "UPDATE ".$tabname[$_POST["id"]]." SET ";
  406. // Modifie valeur des champs
  407. if ($tabrowid[$_POST["id"]] && !in_array($tabrowid[$_POST["id"]],$listfieldmodify))
  408. {
  409. $sql.= $tabrowid[$_POST["id"]]."=";
  410. $sql.= "'".$db->escape($_POST["rowid"])."', ";
  411. }
  412. $i = 0;
  413. foreach ($listfieldmodify as $field)
  414. {
  415. if ($field == 'price') { $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU'); }
  416. if ($i) $sql.=",";
  417. $sql.= $field."=";
  418. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  419. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  420. $i++;
  421. }
  422. $sql.= " WHERE ".$rowidcol." = '".$_POST["rowid"]."'";
  423. dol_syslog("actionmodify sql=".$sql);
  424. //print $sql;
  425. $resql = $db->query($sql);
  426. if (! $resql)
  427. {
  428. $msg=$db->error();
  429. }
  430. }
  431. if ($msg) $msg='<div class="error">'.$msg.'</div>';
  432. $_GET["id"]=$_POST["id"]; // Force affichage dictionnaire en cours d'edition
  433. }
  434. if ($_POST["actioncancel"])
  435. {
  436. $_GET["id"]=$_POST["id"]; // Force affichage dictionnaire en cours d'edition
  437. }
  438. if ($_REQUEST['action'] == 'confirm_delete' && $_REQUEST['confirm'] == 'yes') // delete
  439. {
  440. if ($tabrowid[$_GET["id"]]) { $rowidcol=$tabrowid[$_GET["id"]]; }
  441. else { $rowidcol="rowid"; }
  442. $sql = "DELETE from ".$tabname[$_GET["id"]]." WHERE ".$rowidcol."='".$_GET["rowid"]."'";
  443. dol_syslog("delete sql=".$sql);
  444. $result = $db->query($sql);
  445. if (! $result)
  446. {
  447. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  448. {
  449. $msg='<div class="error">'.$langs->trans("ErrorRecordIsUsedByChild").'</div>';
  450. }
  451. else
  452. {
  453. dol_print_error($db);
  454. }
  455. }
  456. }
  457. if ($_GET["action"] == $acts[0]) // activate
  458. {
  459. if ($tabrowid[$_GET["id"]]) { $rowidcol=$tabrowid[$_GET["id"]]; }
  460. else { $rowidcol="rowid"; }
  461. if ($_GET["rowid"]) {
  462. $sql = "UPDATE ".$tabname[$_GET["id"]]." SET active = 1 WHERE ".$rowidcol."='".$_GET["rowid"]."'";
  463. }
  464. elseif ($_GET["code"]) {
  465. $sql = "UPDATE ".$tabname[$_GET["id"]]." SET active = 1 WHERE code='".$_GET["code"]."'";
  466. }
  467. $result = $db->query($sql);
  468. if (!$result)
  469. {
  470. dol_print_error($db);
  471. }
  472. }
  473. if ($_GET["action"] == $acts[1]) // disable
  474. {
  475. if ($tabrowid[$_GET["id"]]) { $rowidcol=$tabrowid[$_GET["id"]]; }
  476. else { $rowidcol="rowid"; }
  477. if ($_GET["rowid"]) {
  478. $sql = "UPDATE ".$tabname[$_GET["id"]]." SET active = 0 WHERE ".$rowidcol."='".$_GET["rowid"]."'";
  479. }
  480. elseif ($_GET["code"]) {
  481. $sql = "UPDATE ".$tabname[$_GET["id"]]." SET active = 0 WHERE code='".$_GET["code"]."'";
  482. }
  483. $result = $db->query($sql);
  484. if (!$result)
  485. {
  486. dol_print_error($db);
  487. }
  488. }
  489. /*
  490. * View
  491. */
  492. $form = new Form($db);
  493. $formadmin=new FormAdmin($db);
  494. llxHeader();
  495. $titre=$langs->trans("DictionnarySetup");
  496. $linkback='';
  497. if ($_GET["id"])
  498. {
  499. $titre.=' - '.$langs->trans($tablib[$_GET["id"]]);
  500. $linkback='<a href="'.DOL_URL_ROOT.'/admin/dict.php">'.$langs->trans("BackToDictionnaryList").'</a>';
  501. }
  502. print_fiche_titre($titre,$linkback,'setup');
  503. if (empty($_GET["id"]))
  504. {
  505. print $langs->trans("DictionnaryDesc");
  506. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  507. }
  508. print "<br>\n";
  509. /*
  510. * Confirmation de la suppression de la ligne
  511. */
  512. if ($_GET['action'] == 'delete')
  513. {
  514. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$_GET["rowid"].'&code='.$_GET["code"].'&id='.$_GET["id"], $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  515. if ($ret == 'html') print '<br>';
  516. }
  517. /*
  518. * Show a dictionnary
  519. */
  520. if ($_GET["id"])
  521. {
  522. dol_htmloutput_mesg($msg);
  523. // Complete requete recherche valeurs avec critere de tri
  524. $sql=$tabsql[$_GET["id"]];
  525. if ($_GET["sortfield"])
  526. {
  527. // If sort order is "pays", we use pays_code instead
  528. if ($_GET["sortfield"] == 'pays') $_GET["sortfield"]='pays_code';
  529. $sql.= " ORDER BY ".$_GET["sortfield"];
  530. if ($_GET["sortorder"])
  531. {
  532. $sql.=" ".strtoupper($_GET["sortorder"]);
  533. }
  534. $sql.=", ";
  535. // Remove from default sort order the choosed order
  536. $tabsqlsort[$_GET["id"]]=preg_replace('/'.$_GET["sortfield"].' '.$_GET["sortorder"].',/i','',$tabsqlsort[$_GET["id"]]);
  537. $tabsqlsort[$_GET["id"]]=preg_replace('/'.$_GET["sortfield"].',/i','',$tabsqlsort[$_GET["id"]]);
  538. }
  539. else {
  540. $sql.=" ORDER BY ";
  541. }
  542. $sql.=$tabsqlsort[$_GET["id"]];
  543. $sql.=$db->plimit($listlimit+1,$offset);
  544. //print $sql;
  545. $fieldlist=explode(',',$tabfield[$_GET["id"]]);
  546. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  547. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  548. print '<table class="noborder" width="100%">';
  549. // Form to add a new line
  550. if ($tabname[$_GET["id"]])
  551. {
  552. $alabelisused=0;
  553. $var=false;
  554. $fieldlist=explode(',',$tabfield[$_GET["id"]]);
  555. // print '<table class="noborder" width="100%">';
  556. // Line for title
  557. print '<tr class="liste_titre">';
  558. foreach ($fieldlist as $field => $value)
  559. {
  560. // Determine le nom du champ par rapport aux noms possibles
  561. // dans les dictionnaires de donnees
  562. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  563. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  564. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  565. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  566. if ($fieldlist[$field]=='taux') { $valuetoshow=$langs->trans("Rate"); }
  567. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  568. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  569. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  570. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  571. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label")."*"; }
  572. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  573. if ($fieldlist[$field]=='pays') {
  574. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  575. $valuetoshow=$langs->trans("Country"); }
  576. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=MAIN_LABEL_MENTION_NPR; }
  577. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  578. if ($fieldlist[$field]=='fdm') { $valuetoshow=$langs->trans("AtEndOfMonth"); }
  579. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  580. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  581. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  582. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  583. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='pays_id') { $valuetoshow=''; }
  584. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  585. if ($valuetoshow != '')
  586. {
  587. print '<td>';
  588. print $valuetoshow;
  589. print '</td>';
  590. }
  591. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  592. }
  593. print '<td colspan="3">';
  594. print '<input type="hidden" name="id" value="'.$_GET["id"].'">';
  595. print '&nbsp;</td>';
  596. print '</tr>';
  597. // Line to type new values
  598. print "<tr ".$bc[$var].">";
  599. $obj='';
  600. // If data was already input, we define them in obj to populate input fields.
  601. if ($_POST["actionadd"])
  602. {
  603. foreach ($fieldlist as $key=>$val)
  604. {
  605. if (! empty($_POST[$val])) $obj->$val=$_POST[$val];
  606. }
  607. }
  608. $tmpaction = 'create';
  609. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$_GET["id"]]);
  610. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  611. $error=$hookmanager->error; $errors=$hookmanager->errors;
  612. if (empty($reshook)) fieldList($fieldlist,$obj);
  613. print '<td colspan="3" align="right"><input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'"></td>';
  614. print "</tr>";
  615. if ($alabelisused) // Si un des champs est un libelle
  616. {
  617. print '<tr><td colspan="'.(count($fieldlist)+2).'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
  618. }
  619. print '<tr><td colspan="'.(count($fieldlist)+2).'">&nbsp;</td></tr>';
  620. }
  621. // List of available values in database
  622. dol_syslog("htdocs/admin/dict sql=".$sql, LOG_DEBUG);
  623. $resql=$db->query($sql);
  624. if ($resql)
  625. {
  626. $num = $db->num_rows($resql);
  627. $i = 0;
  628. $var=true;
  629. if ($num)
  630. {
  631. // There is several pages
  632. if ($num > $listlimit)
  633. {
  634. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  635. print_fleche_navigation($page,$_SERVER["PHP_SELF"],'&id='.GETPOST('id'),($num > $listlimit),$langs->trans("Page").' '.($page+1));
  636. print '</td></tr>';
  637. }
  638. // Title of lines
  639. print '<tr class="liste_titre">';
  640. foreach ($fieldlist as $field => $value)
  641. {
  642. // Determine le nom du champ par rapport aux noms possibles
  643. // dans les dictionnaires de donnees
  644. $showfield=1; // Par defaut
  645. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  646. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  647. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  648. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  649. if ($fieldlist[$field]=='taux') { $valuetoshow=$langs->trans("Rate"); }
  650. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  651. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  652. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  653. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  654. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label")."*"; }
  655. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  656. if ($fieldlist[$field]=='pays') { $valuetoshow=$langs->trans("Country"); }
  657. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=MAIN_LABEL_MENTION_NPR; }
  658. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  659. if ($fieldlist[$field]=='fdm') { $valuetoshow=$langs->trans("AtEndOfMonth"); }
  660. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  661. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  662. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  663. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  664. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='pays_id') { $showfield=0; }
  665. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  666. // Affiche nom du champ
  667. if ($showfield)
  668. {
  669. print_liste_field_titre($valuetoshow,"dict.php",$fieldlist[$field],($page?'page='.$page.'&':'').'&id='.GETPOST("id"),"","",$sortfield,$sortorder);
  670. }
  671. }
  672. print_liste_field_titre($langs->trans("Status"),"dict.php","active",($page?'page='.$page.'&':'').'&id='.GETPOST("id"),"",'align="center"',$sortfield,$sortorder);
  673. print '<td colspan="2" class="liste_titre">&nbsp;</td>';
  674. print '</tr>';
  675. // Lines with values
  676. while ($i < $num)
  677. {
  678. $obj = $db->fetch_object($resql);
  679. $var=!$var;
  680. //print_r($obj);
  681. print "<tr ".$bc[$var].">";
  682. if ($action == 'edit' && ($_GET["rowid"] == ($obj->rowid?$obj->rowid:$obj->code)))
  683. {
  684. print '<form action="dict.php" method="post">';
  685. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  686. print '<input type="hidden" name="id" value="'.GETPOST("id").'">';
  687. print '<input type="hidden" name="page" value="'.$page.'">';
  688. print '<input type="hidden" name="rowid" value="'.$_GET["rowid"].'">';
  689. $tmpaction='edit';
  690. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$_GET["id"]]);
  691. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  692. $error=$hookmanager->error; $errors=$hookmanager->errors;
  693. if (empty($reshook)) fieldList($fieldlist,$obj);
  694. print '<td colspan="3" align="right"><a name="'.($obj->rowid?$obj->rowid:$obj->code).'">&nbsp;</a><input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  695. print '&nbsp;<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
  696. }
  697. else
  698. {
  699. $tmpaction = 'view';
  700. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$_GET["id"]]);
  701. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  702. $error=$hookmanager->error; $errors=$hookmanager->errors;
  703. if (empty($reshook))
  704. {
  705. foreach ($fieldlist as $field => $value)
  706. {
  707. $showfield=1;
  708. $valuetoshow=$obj->$fieldlist[$field];
  709. if ($valuetoshow=='all') {
  710. $valuetoshow=$langs->trans('All');
  711. }
  712. else if ($fieldlist[$field]=='pays') {
  713. if (empty($obj->pays_code))
  714. {
  715. $valuetoshow='-';
  716. }
  717. else
  718. {
  719. $key=$langs->trans("Country".strtoupper($obj->pays_code));
  720. $valuetoshow=($key != "Country".strtoupper($obj->pays_code))?$obj->pays_code." - ".$key:$obj->pays;
  721. }
  722. }
  723. else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='fdm') {
  724. $valuetoshow=yn($valuetoshow);
  725. }
  726. else if ($fieldlist[$field]=='price') {
  727. $valuetoshow=price($valuetoshow);
  728. }
  729. else if ($fieldlist[$field]=='libelle_facture') {
  730. $langs->load("bills");
  731. $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
  732. $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  733. $valuetoshow=nl2br($valuetoshow);
  734. }
  735. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_pays') {
  736. $key=$langs->trans("Country".strtoupper($obj->code));
  737. $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  738. }
  739. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_availability') {
  740. $langs->load("propal");
  741. $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
  742. $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  743. }
  744. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_actioncomm') {
  745. $key=$langs->trans("Action".strtoupper($obj->code));
  746. $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  747. }
  748. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_currencies') {
  749. $key=$langs->trans("Currency".strtoupper($obj->code_iso));
  750. $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso))?$key:$obj->$fieldlist[$field];
  751. }
  752. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_typent') {
  753. $key=$langs->trans(strtoupper($obj->code));
  754. $valuetoshow=($key != strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  755. }
  756. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_prospectlevel') {
  757. $key=$langs->trans(strtoupper($obj->code));
  758. $valuetoshow=($key != strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  759. }
  760. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_civilite') {
  761. $key=$langs->trans("Civility".strtoupper($obj->code));
  762. $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  763. }
  764. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_type_contact') {
  765. $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  766. $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  767. }
  768. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_payment_term') {
  769. $langs->load("bills");
  770. $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
  771. $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  772. }
  773. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_paiement') {
  774. $langs->load("bills");
  775. $key=$langs->trans("PaymentType".strtoupper($obj->code));
  776. $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  777. }
  778. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_input_reason') {
  779. $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
  780. $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  781. }
  782. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_input_method') {
  783. $langs->load("orders");
  784. $key=$langs->trans($obj->code);
  785. $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->$fieldlist[$field];
  786. }
  787. else if ($fieldlist[$field]=='libelle' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_shipment_mode') {
  788. $langs->load("sendings");
  789. $key=$langs->trans("SendingMethod".strtoupper($obj->code));
  790. $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code))?$key:$obj->$fieldlist[$field];
  791. }
  792. else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='pays_id') {
  793. $showfield=0;
  794. }
  795. if ($showfield) print '<td>'.$valuetoshow.'</td>';
  796. }
  797. }
  798. print '<td align="center" nowrap="nowrap">';
  799. // Est-ce une entree du dictionnaire qui peut etre desactivee ?
  800. $iserasable=1; // Oui par defaut
  801. if (isset($obj->code) && ($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) $iserasable=0;
  802. if (isset($obj->code) && $obj->code == 'RECEP') $iserasable=0;
  803. if (isset($obj->code) && $obj->code == 'EF0') $iserasable=0;
  804. if ($obj->type && $obj->type == 'system') $iserasable=0;
  805. if ($iserasable) print '<a href="'.$_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.($obj->rowid?$obj->rowid:$obj->code).'&amp;code='.$obj->code.'&amp;id='.$_GET["id"].'&amp;action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  806. else print $langs->trans("AlwaysActive");
  807. print "</td>";
  808. // Modify link
  809. if ($iserasable) print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.($obj->rowid?$obj->rowid:$obj->code).'&amp;code='.$obj->code.'&amp;id='.$_GET["id"].'&amp;action=edit#'.($obj->rowid?$obj->rowid:$obj->code).'">'.img_edit().'</a></td>';
  810. else print '<td>&nbsp;</td>';
  811. // Delete link
  812. if ($iserasable) print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.($obj->rowid?$obj->rowid:$obj->code).'&amp;code='.$obj->code.'&amp;id='.$_GET["id"].'&amp;action=delete">'.img_delete().'</a></td>';
  813. else print '<td>&nbsp;</td>';
  814. print "</tr>\n";
  815. }
  816. $i++;
  817. }
  818. }
  819. }
  820. else {
  821. dol_print_error($db);
  822. }
  823. print '</table>';
  824. print '</form>';
  825. }
  826. else
  827. {
  828. /*
  829. * Show list of dictionnary to show
  830. */
  831. $var=true;
  832. $lastlineisempty=false;
  833. print '<table class="noborder" width="100%">';
  834. print '<tr class="liste_titre">';
  835. //print '<td>'.$langs->trans("Module").'</td>';
  836. print '<td colspan="2">'.$langs->trans("Dictionnary").'</td>';
  837. print '<td>'.$langs->trans("Table").'</td>';
  838. print '</tr>';
  839. foreach ($taborder as $i)
  840. {
  841. if ($tabname[$i] && empty($tabcond[$i])) continue;
  842. if ($i)
  843. {
  844. $var=!$var;
  845. $value=$tabname[$i];
  846. print '<tr '.$bc[$var].'><td width="30%">';
  847. if (! empty($tabcond[$i]))
  848. {
  849. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">'.$langs->trans($tablib[$i]).'</a>';
  850. }
  851. else
  852. {
  853. print $langs->trans($tablib[$i]);
  854. }
  855. print '</td>';
  856. print '<td>';
  857. /*if (empty($tabcond[$i]))
  858. {
  859. print info_admin($langs->trans("DictionnaryDisabledSinceNoModuleNeedIt"),1);
  860. }*/
  861. print '</td>';
  862. print '<td>'.$tabname[$i].'</td></tr>';
  863. $lastlineisempty=false;
  864. }
  865. else
  866. {
  867. if (! $lastlineisempty)
  868. {
  869. $var=!$var;
  870. print '<tr '.$bc[$var].'><td width="30%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  871. $lastlineisempty=true;
  872. }
  873. }
  874. }
  875. print '</table>';
  876. }
  877. print '<br>';
  878. $db->close();
  879. llxFooter();
  880. /**
  881. * Show field
  882. *
  883. * @param array $fieldlist Array of fields
  884. * @param Object $obj If we show a particular record, obj is filled with record fields
  885. * @return void
  886. */
  887. function fieldList($fieldlist,$obj='')
  888. {
  889. global $conf,$langs,$db;
  890. global $form;
  891. global $region_id;
  892. global $elementList,$sourceList;
  893. $formadmin = new FormAdmin($db);
  894. $formcompany = new FormCompany($db);
  895. foreach ($fieldlist as $field => $value)
  896. {
  897. if ($fieldlist[$field] == 'pays') {
  898. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  899. print '<td>';
  900. print $form->select_country(($obj->pays_code?$obj->pays_code:$obj->pays),'pays');
  901. print '</td>';
  902. }
  903. elseif ($fieldlist[$field] == 'pays_id') {
  904. $pays_id = (! empty($obj->$fieldlist[$field])) ? $obj->$fieldlist[$field] : 0;
  905. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$pays_id.'">';
  906. }
  907. elseif ($fieldlist[$field] == 'region') {
  908. print '<td>';
  909. $formcompany->select_region($region_id,'region');
  910. print '</td>';
  911. }
  912. elseif ($fieldlist[$field] == 'region_id') {
  913. $region_id = $obj->$fieldlist[$field]?$obj->$fieldlist[$field]:0;
  914. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
  915. }
  916. elseif ($fieldlist[$field] == 'lang') {
  917. print '<td>';
  918. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  919. print '</td>';
  920. }
  921. // Le type de l'element (pour les type de contact).'
  922. elseif ($fieldlist[$field] == 'element')
  923. {
  924. print '<td>';
  925. print $form->selectarray('element', $elementList,$obj->$fieldlist[$field]);
  926. print '</td>';
  927. }
  928. // La source de l'element (pour les type de contact).'
  929. elseif ($fieldlist[$field] == 'source')
  930. {
  931. print '<td>';
  932. print $form->selectarray('source', $sourceList,$obj->$fieldlist[$field]);
  933. print '</td>';
  934. }
  935. elseif ($fieldlist[$field] == 'type' && $tabname[$_GET["id"]] == MAIN_DB_PREFIX."c_actioncomm")
  936. {
  937. print '<td>';
  938. print 'user<input type="hidden" name="type" value="user">';
  939. print '</td>';
  940. }
  941. elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'fdm') {
  942. print '<td>';
  943. print $form->selectyesno($fieldlist[$field],$obj->$fieldlist[$field],1);
  944. print '</td>';
  945. }
  946. elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
  947. print '<td><input type="text" class="flat" value="'.$obj->$fieldlist[$field].'" size="3" name="'.$fieldlist[$field].'"></td>';
  948. }
  949. elseif ($fieldlist[$field] == 'libelle_facture') {
  950. print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.$obj->$fieldlist[$field].'</textarea></td>';
  951. }
  952. elseif ($fieldlist[$field] == 'price') {
  953. print '<td><input type="text" class="flat" value="'.price($obj->$fieldlist[$field]).'" size="8" name="'.$fieldlist[$field].'"></td>';
  954. }
  955. elseif ($fieldlist[$field] == 'code') {
  956. print '<td><input type="text" class="flat" value="'.$obj->$fieldlist[$field].'" size="10" name="'.$fieldlist[$field].'"></td>';
  957. }
  958. elseif ($fieldlist[$field]=='unit') {
  959. print '<td>';
  960. print $form->selectarray('unit',array('mm','cm','point','inch'),$obj->$fieldlist[$field],0,0,1);
  961. print '</td>';
  962. }
  963. else
  964. {
  965. print '<td>';
  966. print

Large files files are truncated, but you can click here to view the full file