PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/admin/dict.php

https://bitbucket.org/speedealing/speedealing
PHP | 1288 lines | 1109 code | 90 blank | 89 comment | 369 complexity | d67fa4015f7eeec7dddafbee76d4ddf9 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

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

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