dict.php 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
  9. * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
  11. * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  12. * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/admin/dict.php
  30. * \ingroup setup
  31. * \brief Page to administer data tables
  32. */
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  40. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  41. $langs->load("errors");
  42. $langs->load("admin");
  43. $langs->load("main");
  44. $langs->load("companies");
  45. $langs->load("resource");
  46. $langs->load("holiday");
  47. $langs->load("accountancy");
  48. $langs->load("hrm");
  49. $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
  50. $confirm=GETPOST('confirm','alpha');
  51. $id=GETPOST('id','int');
  52. $rowid=GETPOST('rowid','alpha');
  53. $allowed=$user->admin;
  54. if ($id == 7 && ! empty($user->rights->accounting->chartofaccount)) $allowed=1; // Tax page allowed to manager of chart account
  55. if ($id == 10 && ! empty($user->rights->accounting->chartofaccount)) $allowed=1; // Vat page allowed to manager of chart account
  56. if (! $allowed) accessforbidden();
  57. $acts[0] = "activate";
  58. $acts[1] = "disable";
  59. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  60. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  61. $listoffset=GETPOST('listoffset');
  62. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  63. $active = 1;
  64. $sortfield = GETPOST("sortfield",'alpha');
  65. $sortorder = GETPOST("sortorder",'alpha');
  66. $page = GETPOST("page",'int');
  67. if ($page == -1) { $page = 0 ; }
  68. $offset = $listlimit * $page ;
  69. $pageprev = $page - 1;
  70. $pagenext = $page + 1;
  71. $search_country_id = GETPOST('search_country_id','int');
  72. $search_code = GETPOST('search_code','alpha');
  73. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  74. $hookmanager->initHooks(array('admin'));
  75. // This page is a generic page to edit dictionaries
  76. // Put here declaration of dictionaries properties
  77. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  78. $taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,33,34,0,6,0,29,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,26,0);
  79. // Name of SQL tables of dictionaries
  80. $tabname=array();
  81. $tabname[1] = MAIN_DB_PREFIX."c_forme_juridique";
  82. $tabname[2] = MAIN_DB_PREFIX."c_departements";
  83. $tabname[3] = MAIN_DB_PREFIX."c_regions";
  84. $tabname[4] = MAIN_DB_PREFIX."c_country";
  85. $tabname[5] = MAIN_DB_PREFIX."c_civility";
  86. $tabname[6] = MAIN_DB_PREFIX."c_actioncomm";
  87. $tabname[7] = MAIN_DB_PREFIX."c_chargesociales";
  88. $tabname[8] = MAIN_DB_PREFIX."c_typent";
  89. $tabname[9] = MAIN_DB_PREFIX."c_currencies";
  90. $tabname[10]= MAIN_DB_PREFIX."c_tva";
  91. $tabname[11]= MAIN_DB_PREFIX."c_type_contact";
  92. $tabname[12]= MAIN_DB_PREFIX."c_payment_term";
  93. $tabname[13]= MAIN_DB_PREFIX."c_paiement";
  94. $tabname[14]= MAIN_DB_PREFIX."c_ecotaxe";
  95. $tabname[15]= MAIN_DB_PREFIX."c_paper_format";
  96. $tabname[16]= MAIN_DB_PREFIX."c_prospectlevel";
  97. $tabname[17]= MAIN_DB_PREFIX."c_type_fees";
  98. $tabname[18]= MAIN_DB_PREFIX."c_shipment_mode";
  99. $tabname[19]= MAIN_DB_PREFIX."c_effectif";
  100. $tabname[20]= MAIN_DB_PREFIX."c_input_method";
  101. $tabname[21]= MAIN_DB_PREFIX."c_availability";
  102. $tabname[22]= MAIN_DB_PREFIX."c_input_reason";
  103. $tabname[23]= MAIN_DB_PREFIX."c_revenuestamp";
  104. $tabname[24]= MAIN_DB_PREFIX."c_type_resource";
  105. //$tabname[25]= MAIN_DB_PREFIX."c_email_templates";
  106. $tabname[26]= MAIN_DB_PREFIX."c_units";
  107. $tabname[27]= MAIN_DB_PREFIX."c_stcomm";
  108. $tabname[28]= MAIN_DB_PREFIX."c_holiday_types";
  109. $tabname[29]= MAIN_DB_PREFIX."c_lead_status";
  110. $tabname[30]= MAIN_DB_PREFIX."c_format_cards";
  111. //$tabname[31]= MAIN_DB_PREFIX."accounting_system";
  112. //$tabname[32]= MAIN_DB_PREFIX."c_accounting_category";
  113. $tabname[33]= MAIN_DB_PREFIX."c_hrm_department";
  114. $tabname[34]= MAIN_DB_PREFIX."c_hrm_function";
  115. // Dictionary labels
  116. $tablib=array();
  117. $tablib[1] = "DictionaryCompanyJuridicalType";
  118. $tablib[2] = "DictionaryCanton";
  119. $tablib[3] = "DictionaryRegion";
  120. $tablib[4] = "DictionaryCountry";
  121. $tablib[5] = "DictionaryCivility";
  122. $tablib[6] = "DictionaryActions";
  123. $tablib[7] = "DictionarySocialContributions";
  124. $tablib[8] = "DictionaryCompanyType";
  125. $tablib[9] = "DictionaryCurrency";
  126. $tablib[10]= "DictionaryVAT";
  127. $tablib[11]= "DictionaryTypeContact";
  128. $tablib[12]= "DictionaryPaymentConditions";
  129. $tablib[13]= "DictionaryPaymentModes";
  130. $tablib[14]= "DictionaryEcotaxe";
  131. $tablib[15]= "DictionaryPaperFormat";
  132. $tablib[16]= "DictionaryProspectLevel";
  133. $tablib[17]= "DictionaryFees";
  134. $tablib[18]= "DictionarySendingMethods";
  135. $tablib[19]= "DictionaryStaff";
  136. $tablib[20]= "DictionaryOrderMethods";
  137. $tablib[21]= "DictionaryAvailability";
  138. $tablib[22]= "DictionarySource";
  139. $tablib[23]= "DictionaryRevenueStamp";
  140. $tablib[24]= "DictionaryResourceType";
  141. //$tablib[25]= "DictionaryEMailTemplates";
  142. $tablib[26]= "DictionaryUnits";
  143. $tablib[27]= "DictionaryProspectStatus";
  144. $tablib[28]= "DictionaryHolidayTypes";
  145. $tablib[29]= "DictionaryOpportunityStatus";
  146. $tablib[30]= "DictionaryFormatCards";
  147. //$tablib[31]= "DictionaryAccountancysystem";
  148. //$tablib[32]= "DictionaryAccountancyCategory";
  149. $tablib[33]= "DictionaryDepartment";
  150. $tablib[34]= "DictionaryFunction";
  151. // Requests to extract data
  152. $tabsql=array();
  153. $tabsql[1] = "SELECT f.rowid as rowid, f.code, f.libelle, c.code as country_code, c.label as country, f.active FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c WHERE f.fk_pays=c.rowid";
  154. $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, c.code as country_code, c.label as country, d.active FROM ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid and r.active=1 and c.active=1";
  155. $tabsql[3] = "SELECT r.rowid as rowid, r.code_region as code, r.nom as libelle, r.fk_pays as country_id, c.code as country_code, c.label as country, r.active FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c WHERE r.fk_pays=c.rowid and c.active=1";
  156. $tabsql[4] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite FROM ".MAIN_DB_PREFIX."c_country AS c";
  157. $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
  158. $tabsql[6] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.type, a.active, a.module, a.color, a.position FROM ".MAIN_DB_PREFIX."c_actioncomm AS a";
  159. $tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, a.deductible, c.code as country_code, c.label as country, a.fk_pays as country_id, a.active FROM ".MAIN_DB_PREFIX."c_chargesociales AS a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_pays=c.rowid and c.active=1";
  160. $tabsql[8] = "SELECT t.id as rowid, t.code as code, t.libelle, t.fk_country as country_id, c.code as country_code, c.label as country, t.position, t.active FROM ".MAIN_DB_PREFIX."c_typent as t LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON t.fk_country=c.rowid";
  161. $tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
  162. $tabsql[10]= "SELECT t.rowid, t.code, t.taux, t.localtax1_type, t.localtax1, t.localtax2_type, t.localtax2, c.label as country, c.code as country_code, t.fk_pays as country_id, t.recuperableonly, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
  163. $tabsql[11]= "SELECT t.rowid as rowid, t.element, t.source, t.code, t.libelle, t.position, t.active FROM ".MAIN_DB_PREFIX."c_type_contact AS t";
  164. $tabsql[12]= "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder FROM ".MAIN_DB_PREFIX.'c_payment_term AS c';
  165. $tabsql[13]= "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.accountancy_code FROM ".MAIN_DB_PREFIX."c_paiement AS c";
  166. $tabsql[14]= "SELECT e.rowid as rowid, e.code as code, e.libelle, e.price, e.organization, e.fk_pays as country_id, c.code as country_code, c.label as country, e.active FROM ".MAIN_DB_PREFIX."c_ecotaxe AS e, ".MAIN_DB_PREFIX."c_country as c WHERE e.fk_pays=c.rowid and c.active=1";
  167. $tabsql[15]= "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
  168. $tabsql[16]= "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  169. $tabsql[17]= "SELECT id as rowid, code, label, accountancy_code, active FROM ".MAIN_DB_PREFIX."c_type_fees";
  170. $tabsql[18]= "SELECT rowid as rowid, code, libelle, tracking, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
  171. $tabsql[19]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
  172. $tabsql[20]= "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
  173. $tabsql[21]= "SELECT c.rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_availability AS c";
  174. $tabsql[22]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
  175. $tabsql[23]= "SELECT t.rowid as rowid, t.taux, c.label as country, c.code as country_code, t.fk_pays as country_id, t.note, t.active, t.accountancy_code_sell, t.accountancy_code_buy FROM ".MAIN_DB_PREFIX."c_revenuestamp as t, ".MAIN_DB_PREFIX."c_country as c WHERE t.fk_pays=c.rowid";
  176. $tabsql[24]= "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
  177. //$tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content_lines, content, active FROM ".MAIN_DB_PREFIX."c_email_templates WHERE entity IN (".getEntity('email_template',1).")";
  178. $tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
  179. $tabsql[27]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_stcomm";
  180. $tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid";
  181. $tabsql[29]= "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status";
  182. $tabsql[30]= "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards";
  183. //$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s";
  184. //$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.sens, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
  185. $tabsql[33]= "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department";
  186. $tabsql[34]= "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function";
  187. // Criteria to sort dictionaries
  188. $tabsqlsort=array();
  189. $tabsqlsort[1] ="country ASC, code ASC";
  190. $tabsqlsort[2] ="country ASC, code ASC";
  191. $tabsqlsort[3] ="country ASC, code ASC";
  192. $tabsqlsort[4] ="code ASC";
  193. $tabsqlsort[5] ="label ASC";
  194. $tabsqlsort[6] ="a.type ASC, a.module ASC, a.position ASC, a.code ASC";
  195. $tabsqlsort[7] ="country ASC, code ASC, a.libelle ASC";
  196. $tabsqlsort[8] ="country DESC,".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?' t.position ASC,':'')." libelle ASC";
  197. $tabsqlsort[9] ="label ASC";
  198. $tabsqlsort[10]="country ASC, code ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
  199. $tabsqlsort[11]="t.element ASC, t.source ASC, t.position ASC, t.code ASC";
  200. $tabsqlsort[12]="sortorder ASC, code ASC";
  201. $tabsqlsort[13]="code ASC";
  202. $tabsqlsort[14]="country ASC, e.organization ASC, code ASC";
  203. $tabsqlsort[15]="rowid ASC";
  204. $tabsqlsort[16]="sortorder ASC";
  205. $tabsqlsort[17]="code ASC";
  206. $tabsqlsort[18]="code ASC, libelle ASC";
  207. $tabsqlsort[19]="id ASC";
  208. $tabsqlsort[20]="code ASC, libelle ASC";
  209. $tabsqlsort[21]="code ASC, label ASC";
  210. $tabsqlsort[22]="code ASC, label ASC";
  211. $tabsqlsort[23]="country ASC, taux ASC";
  212. $tabsqlsort[24]="code ASC,label ASC";
  213. //$tabsqlsort[25]="label ASC";
  214. $tabsqlsort[26]="code ASC";
  215. $tabsqlsort[27]="code ASC";
  216. $tabsqlsort[28]="country ASC, code ASC";
  217. $tabsqlsort[29]="position ASC";
  218. $tabsqlsort[30]="code ASC";
  219. //$tabsqlsort[31]="pcg_version ASC";
  220. //$tabsqlsort[32]="position ASC";
  221. $tabsqlsort[33]="code ASC";
  222. $tabsqlsort[34]="code ASC";
  223. // Nom des champs en resultat de select pour affichage du dictionnaire
  224. $tabfield=array();
  225. $tabfield[1] = "code,libelle,country";
  226. $tabfield[2] = "code,libelle,region_id,region,country"; // "code,libelle,region,country_code-country"
  227. $tabfield[3] = "code,libelle,country_id,country";
  228. $tabfield[4] = "code,label";
  229. $tabfield[5] = "code,label";
  230. $tabfield[6] = "code,libelle,type,color,position";
  231. $tabfield[7] = "code,libelle,country,accountancy_code,deductible";
  232. $tabfield[8] = "code,libelle,country_id,country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
  233. $tabfield[9] = "code,label,unicode";
  234. $tabfield[10]= "country_id,country,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
  235. $tabfield[11]= "element,source,code,libelle,position";
  236. $tabfield[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder";
  237. $tabfield[13]= "code,libelle,type,accountancy_code";
  238. $tabfield[14]= "code,libelle,price,organization,country_id,country";
  239. $tabfield[15]= "code,libelle,width,height,unit";
  240. $tabfield[16]= "code,libelle,sortorder";
  241. $tabfield[17]= "code,label,accountancy_code";
  242. $tabfield[18]= "code,libelle,tracking";
  243. $tabfield[19]= "code,libelle";
  244. $tabfield[20]= "code,libelle";
  245. $tabfield[21]= "code,label";
  246. $tabfield[22]= "code,label";
  247. $tabfield[23]= "country_id,country,taux,accountancy_code_sell,accountancy_code_buy,note";
  248. $tabfield[24]= "code,label";
  249. //$tabfield[25]= "label,type_template,private,position,topic,content_lines,content";
  250. $tabfield[26]= "code,label,short_label";
  251. $tabfield[27]= "code,libelle";
  252. $tabfield[28]= "code,label,affect,delay,newbymonth,country_id,country";
  253. $tabfield[29]= "code,label,percent,position";
  254. $tabfield[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  255. //$tabfield[31]= "pcg_version,label";
  256. //$tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country";
  257. $tabfield[33]= "code,label";
  258. $tabfield[34]= "code,label";
  259. // Nom des champs d'edition pour modification d'un enregistrement
  260. $tabfieldvalue=array();
  261. $tabfieldvalue[1] = "code,libelle,country";
  262. $tabfieldvalue[2] = "code,libelle,region"; // "code,libelle,region"
  263. $tabfieldvalue[3] = "code,libelle,country";
  264. $tabfieldvalue[4] = "code,label";
  265. $tabfieldvalue[5] = "code,label";
  266. $tabfieldvalue[6] = "code,libelle,type,color,position";
  267. $tabfieldvalue[7] = "code,libelle,country,accountancy_code,deductible";
  268. $tabfieldvalue[8] = "code,libelle,country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
  269. $tabfieldvalue[9] = "code,label,unicode";
  270. $tabfieldvalue[10]= "country,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
  271. $tabfieldvalue[11]= "element,source,code,libelle,position";
  272. $tabfieldvalue[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder";
  273. $tabfieldvalue[13]= "code,libelle,type,accountancy_code";
  274. $tabfieldvalue[14]= "code,libelle,price,organization,country";
  275. $tabfieldvalue[15]= "code,libelle,width,height,unit";
  276. $tabfieldvalue[16]= "code,libelle,sortorder";
  277. $tabfieldvalue[17]= "code,label,accountancy_code";
  278. $tabfieldvalue[18]= "code,libelle,tracking";
  279. $tabfieldvalue[19]= "code,libelle";
  280. $tabfieldvalue[20]= "code,libelle";
  281. $tabfieldvalue[21]= "code,label";
  282. $tabfieldvalue[22]= "code,label";
  283. $tabfieldvalue[23]= "country,taux,accountancy_code_sell,accountancy_code_buy,note";
  284. $tabfieldvalue[24]= "code,label";
  285. //$tabfieldvalue[25]= "label,type_template,private,position,topic,content_lines,content";
  286. $tabfieldvalue[26]= "code,label,short_label";
  287. $tabfieldvalue[27]= "code,libelle";
  288. $tabfieldvalue[28]= "code,label,affect,delay,newbymonth,country";
  289. $tabfieldvalue[29]= "code,label,percent,position";
  290. $tabfieldvalue[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  291. //$tabfieldvalue[31]= "pcg_version,label";
  292. //$tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country";
  293. $tabfieldvalue[33]= "code,label";
  294. $tabfieldvalue[34]= "code,label";
  295. // Nom des champs dans la table pour insertion d'un enregistrement
  296. $tabfieldinsert=array();
  297. $tabfieldinsert[1] = "code,libelle,fk_pays";
  298. $tabfieldinsert[2] = "code_departement,nom,fk_region";
  299. $tabfieldinsert[3] = "code_region,nom,fk_pays";
  300. $tabfieldinsert[4] = "code,label";
  301. $tabfieldinsert[5] = "code,label";
  302. $tabfieldinsert[6] = "code,libelle,type,color,position";
  303. $tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code,deductible";
  304. $tabfieldinsert[8] = "code,libelle,fk_country".(! empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?',position':'');
  305. $tabfieldinsert[9] = "code_iso,label,unicode";
  306. $tabfieldinsert[10]= "fk_pays,code,taux,recuperableonly,localtax1_type,localtax1,localtax2_type,localtax2,accountancy_code_sell,accountancy_code_buy,note";
  307. $tabfieldinsert[11]= "element,source,code,libelle,position";
  308. $tabfieldinsert[12]= "code,libelle,libelle_facture,nbjour,type_cdr,decalage,sortorder";
  309. $tabfieldinsert[13]= "code,libelle,type,accountancy_code";
  310. $tabfieldinsert[14]= "code,libelle,price,organization,fk_pays";
  311. $tabfieldinsert[15]= "code,label,width,height,unit";
  312. $tabfieldinsert[16]= "code,label,sortorder";
  313. $tabfieldinsert[17]= "code,label,accountancy_code";
  314. $tabfieldinsert[18]= "code,libelle,tracking";
  315. $tabfieldinsert[19]= "code,libelle";
  316. $tabfieldinsert[20]= "code,libelle";
  317. $tabfieldinsert[21]= "code,label";
  318. $tabfieldinsert[22]= "code,label";
  319. $tabfieldinsert[23]= "fk_pays,taux,accountancy_code_sell,accountancy_code_buy,note";
  320. $tabfieldinsert[24]= "code,label";
  321. //$tabfieldinsert[25]= "label,type_template,private,position,topic,content_lines,content,entity";
  322. $tabfieldinsert[26]= "code,label,short_label";
  323. $tabfieldinsert[27]= "code,libelle";
  324. $tabfieldinsert[28]= "code,label,affect,delay,newbymonth,fk_country";
  325. $tabfieldinsert[29]= "code,label,percent,position";
  326. $tabfieldinsert[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  327. //$tabfieldinsert[31]= "pcg_version,label";
  328. //$tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
  329. $tabfieldinsert[33]= "code,label";
  330. $tabfieldinsert[34]= "code,label";
  331. // Nom du rowid si le champ n'est pas de type autoincrement
  332. // Example: "" if id field is "rowid" and has autoincrement on
  333. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  334. $tabrowid=array();
  335. $tabrowid[1] = "";
  336. $tabrowid[2] = "";
  337. $tabrowid[3] = "";
  338. $tabrowid[4] = "rowid";
  339. $tabrowid[5] = "rowid";
  340. $tabrowid[6] = "id";
  341. $tabrowid[7] = "id";
  342. $tabrowid[8] = "id";
  343. $tabrowid[9] = "code_iso";
  344. $tabrowid[10]= "";
  345. $tabrowid[11]= "rowid";
  346. $tabrowid[12]= "rowid";
  347. $tabrowid[13]= "id";
  348. $tabrowid[14]= "";
  349. $tabrowid[15]= "";
  350. $tabrowid[16]= "code";
  351. $tabrowid[17]= "id";
  352. $tabrowid[18]= "rowid";
  353. $tabrowid[19]= "id";
  354. $tabrowid[20]= "";
  355. $tabrowid[21]= "rowid";
  356. $tabrowid[22]= "rowid";
  357. $tabrowid[23]= "";
  358. $tabrowid[24]= "";
  359. //$tabrowid[25]= "";
  360. $tabrowid[26]= "";
  361. $tabrowid[27]= "id";
  362. $tabrowid[28]= "";
  363. $tabrowid[29]= "";
  364. $tabrowid[30]= "";
  365. //$tabrowid[31]= "";
  366. //$tabrowid[32]= "";
  367. $tabrowid[33]= "rowid";
  368. $tabrowid[34]= "rowid";
  369. // Condition to show dictionary in setup page
  370. $tabcond=array();
  371. $tabcond[1] = (! empty($conf->societe->enabled));
  372. $tabcond[2] = true;
  373. $tabcond[3] = true;
  374. $tabcond[4] = true;
  375. $tabcond[5] = (! empty($conf->societe->enabled) || ! empty($conf->adherent->enabled));
  376. $tabcond[6] = ! empty($conf->agenda->enabled);
  377. $tabcond[7] = ! empty($conf->tax->enabled);
  378. $tabcond[8] = ! empty($conf->societe->enabled);
  379. $tabcond[9] = true;
  380. $tabcond[10]= true;
  381. $tabcond[11]= (! empty($conf->societe->enabled));
  382. $tabcond[12]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled));
  383. $tabcond[13]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled));
  384. $tabcond[14]= (! empty($conf->product->enabled) && ! empty($conf->ecotax->enabled));
  385. $tabcond[15]= true;
  386. $tabcond[16]= (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS));
  387. $tabcond[17]= (! empty($conf->deplacement->enabled) || ! empty($conf->expensereport->enabled));
  388. $tabcond[18]= ! empty($conf->expedition->enabled);
  389. $tabcond[19]= ! empty($conf->societe->enabled);
  390. $tabcond[20]= ! empty($conf->fournisseur->enabled);
  391. $tabcond[21]= ! empty($conf->propal->enabled);
  392. $tabcond[22]= (! empty($conf->commande->enabled) || ! empty($conf->propal->enabled));
  393. $tabcond[23]= true;
  394. $tabcond[24]= ! empty($conf->resource->enabled);
  395. //$tabcond[25]= true; // && ! empty($conf->global->MAIN_EMAIL_EDIT_TEMPLATE_FROM_DIC);
  396. $tabcond[26]= ! empty($conf->product->enabled);
  397. $tabcond[27]= ! empty($conf->societe->enabled);
  398. $tabcond[28]= ! empty($conf->holiday->enabled);
  399. $tabcond[29]= ! empty($conf->projet->enabled);
  400. $tabcond[30]= ! empty($conf->label->enabled);
  401. //$tabcond[31]= ! empty($conf->accounting->enabled);
  402. //$tabcond[32]= ! empty($conf->accounting->enabled);
  403. $tabcond[33]= ! empty($conf->hrm->enabled);
  404. $tabcond[34]= ! empty($conf->hrm->enabled);
  405. // List of help for fields
  406. $tabhelp=array();
  407. $tabhelp[1] = array('code'=>$langs->trans("EnterAnyCode"));
  408. $tabhelp[2] = array('code'=>$langs->trans("EnterAnyCode"));
  409. $tabhelp[3] = array('code'=>$langs->trans("EnterAnyCode"));
  410. $tabhelp[4] = array('code'=>$langs->trans("EnterAnyCode"));
  411. $tabhelp[5] = array('code'=>$langs->trans("EnterAnyCode"));
  412. $tabhelp[6] = array('code'=>$langs->trans("EnterAnyCode"), 'color'=>$langs->trans("ColorFormat"), 'position'=>$langs->trans("PositionIntoComboList"));
  413. $tabhelp[7] = array('code'=>$langs->trans("EnterAnyCode"));
  414. $tabhelp[8] = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
  415. $tabhelp[9] = array('code'=>$langs->trans("EnterAnyCode"), 'unicode'=>$langs->trans("UnicodeCurrency"));
  416. $tabhelp[10] = array('code'=>$langs->trans("EnterAnyCode"), 'taux'=>$langs->trans("SellTaxRate"), 'recuperableonly'=>$langs->trans("RecuperableOnly"), 'localtax1_type'=>$langs->trans("LocalTaxDesc"), 'localtax2_type'=>$langs->trans("LocalTaxDesc"));
  417. $tabhelp[11] = array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"));
  418. $tabhelp[12] = array('code'=>$langs->trans("EnterAnyCode"), 'type_cdr'=>$langs->trans("TypeCdr"));
  419. $tabhelp[13] = array('code'=>$langs->trans("EnterAnyCode"));
  420. $tabhelp[14] = array('code'=>$langs->trans("EnterAnyCode"));
  421. $tabhelp[15] = array('code'=>$langs->trans("EnterAnyCode"));
  422. $tabhelp[16] = array('code'=>$langs->trans("EnterAnyCode"));
  423. $tabhelp[17] = array('code'=>$langs->trans("EnterAnyCode"));
  424. $tabhelp[18] = array('code'=>$langs->trans("EnterAnyCode"), 'tracking'=>$langs->trans("UrlTrackingDesc"));
  425. $tabhelp[19] = array('code'=>$langs->trans("EnterAnyCode"));
  426. $tabhelp[20] = array('code'=>$langs->trans("EnterAnyCode"));
  427. $tabhelp[21] = array('code'=>$langs->trans("EnterAnyCode"));
  428. $tabhelp[22] = array('code'=>$langs->trans("EnterAnyCode"));
  429. $tabhelp[23] = array();
  430. $tabhelp[24] = array('code'=>$langs->trans("EnterAnyCode"));
  431. //$tabhelp[25] = array('topic'=>$langs->trans('SeeSubstitutionVars'),'content'=>$langs->trans('SeeSubstitutionVars'),'content_lines'=>$langs->trans('SeeSubstitutionVars'),'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
  432. $tabhelp[26] = array('code'=>$langs->trans("EnterAnyCode"));
  433. $tabhelp[27] = array('code'=>$langs->trans("EnterAnyCode"));
  434. $tabhelp[28] = array('affect'=>$langs->trans("FollowedByACounter"),'delay'=>$langs->trans("MinimumNoticePeriod"), 'newbymonth'=>$langs->trans("NbAddedAutomatically"));
  435. $tabhelp[29] = array('code'=>$langs->trans("EnterAnyCode"), 'percent'=>$langs->trans("OpportunityPercent"), 'position'=>$langs->trans("PositionIntoComboList"));
  436. $tabhelp[30] = array('code'=>$langs->trans("EnterAnyCode"), 'name'=>$langs->trans("LabelName"), 'paper_size'=>$langs->trans("LabelPaperSize"));
  437. //$tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
  438. //$tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"));
  439. $tabhelp[33] = array('code'=>$langs->trans("EnterAnyCode"));
  440. $tabhelp[34] = array('code'=>$langs->trans("EnterAnyCode"));
  441. // List of check for fields (NOT USED YET)
  442. $tabfieldcheck=array();
  443. $tabfieldcheck[1] = array();
  444. $tabfieldcheck[2] = array();
  445. $tabfieldcheck[3] = array();
  446. $tabfieldcheck[4] = array();
  447. $tabfieldcheck[5] = array();
  448. $tabfieldcheck[6] = array();
  449. $tabfieldcheck[7] = array();
  450. $tabfieldcheck[8] = array();
  451. $tabfieldcheck[9] = array();
  452. $tabfieldcheck[10] = array();
  453. $tabfieldcheck[11] = array();
  454. $tabfieldcheck[12] = array();
  455. $tabfieldcheck[13] = array();
  456. $tabfieldcheck[14] = array();
  457. $tabfieldcheck[15] = array();
  458. $tabfieldcheck[16] = array();
  459. $tabfieldcheck[17] = array();
  460. $tabfieldcheck[18] = array();
  461. $tabfieldcheck[19] = array();
  462. $tabfieldcheck[20] = array();
  463. $tabfieldcheck[21] = array();
  464. $tabfieldcheck[22] = array();
  465. $tabfieldcheck[23] = array();
  466. $tabfieldcheck[24] = array();
  467. //$tabfieldcheck[25] = array();
  468. $tabfieldcheck[26] = array();
  469. $tabfieldcheck[27] = array();
  470. $tabfieldcheck[28] = array();
  471. $tabfieldcheck[29] = array();
  472. $tabfieldcheck[30] = array();
  473. //$tabfieldcheck[31] = array();
  474. //$tabfieldcheck[32] = array();
  475. $tabfieldcheck[33] = array();
  476. $tabfieldcheck[34] = array();
  477. // Complete all arrays with entries found into modules
  478. complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
  479. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  480. $elementList = array();
  481. $sourceList=array();
  482. if ($id == 11)
  483. {
  484. $langs->load("orders");
  485. $langs->load("contracts");
  486. $langs->load("projects");
  487. $langs->load("propal");
  488. $langs->load("bills");
  489. $langs->load("interventions");
  490. $elementList = array(
  491. '' => '',
  492. 'societe' => $langs->trans('ThirdParty'),
  493. // 'proposal' => $langs->trans('Proposal'),
  494. // 'order' => $langs->trans('Order'),
  495. // 'invoice' => $langs->trans('Bill'),
  496. 'invoice_supplier' => $langs->trans('SupplierBill'),
  497. 'order_supplier' => $langs->trans('SupplierOrder'),
  498. // 'intervention' => $langs->trans('InterventionCard'),
  499. // 'contract' => $langs->trans('Contract'),
  500. 'project' => $langs->trans('Project'),
  501. 'project_task' => $langs->trans('Task'),
  502. 'agenda' => $langs->trans('Agenda'),
  503. // old deprecated
  504. 'contrat' => $langs->trans('Contract'),
  505. 'propal' => $langs->trans('Proposal'),
  506. 'commande' => $langs->trans('Order'),
  507. 'facture' => $langs->trans('Bill'),
  508. 'resource' => $langs->trans('Resource'),
  509. // 'facture_fourn' => $langs->trans('SupplierBill'),
  510. 'fichinter' => $langs->trans('InterventionCard')
  511. );
  512. if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) $elementList["societe"] = $langs->trans('ThirdParty');
  513. complete_elementList_with_modules($elementList);
  514. asort($elementList);
  515. $sourceList = array(
  516. 'internal' => $langs->trans('Internal'),
  517. 'external' => $langs->trans('External')
  518. );
  519. }
  520. // Define localtax_typeList (used for dictionary "llx_c_tva")
  521. $localtax_typeList = array();
  522. if ($id == 10)
  523. {
  524. $localtax_typeList = array(
  525. "0" => $langs->trans("No"),
  526. "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
  527. "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
  528. "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
  529. "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
  530. "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
  531. "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
  532. );
  533. }
  534. /*
  535. * Actions
  536. */
  537. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  538. {
  539. $search_country_id = '';
  540. $search_code = '';
  541. }
  542. // Actions add or modify an entry into a dictionary
  543. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  544. {
  545. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  546. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  547. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  548. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  549. // Check that all fields are filled
  550. $ok=1;
  551. foreach ($listfield as $f => $value)
  552. {
  553. if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancysystem','DictionaryAccountancyCategory'))) continue; // For some pages, country is not mandatory
  554. if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
  555. if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
  556. if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
  557. if ($value == 'color' && empty($_POST['color'])) continue;
  558. if ($value == 'formula' && empty($_POST['formula'])) continue;
  559. if ((! isset($_POST[$value]) || $_POST[$value]=='')
  560. && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
  561. && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
  562. )
  563. )
  564. {
  565. $ok=0;
  566. $fieldnamekey=$listfield[$f];
  567. // We take translate key of field
  568. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  569. if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
  570. if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
  571. if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
  572. if ($fieldnamekey == 'module') $fieldnamekey='Module';
  573. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  574. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  575. if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
  576. if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
  577. if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
  578. if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
  579. if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible';
  580. if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder';
  581. if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
  582. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  583. }
  584. }
  585. // Other checks
  586. if (GETPOST('actionadd') && $tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
  587. $ok=0;
  588. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  589. }
  590. if (isset($_POST["code"]))
  591. {
  592. if ($_POST["code"]=='0')
  593. {
  594. $ok=0;
  595. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  596. }
  597. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  598. {
  599. $ok = 0;
  600. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
  601. }*/
  602. }
  603. if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
  604. {
  605. if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
  606. {
  607. $_POST["country"]='';
  608. }
  609. else
  610. {
  611. $ok=0;
  612. setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
  613. }
  614. }
  615. if ($id == 3 && ! is_numeric($_POST["code"]))
  616. {
  617. $ok=0;
  618. setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric",$langs->transnoentities("Code")), null, 'errors');
  619. }
  620. // Clean some parameters
  621. if ((! empty($_POST["localtax1_type"]) || ($_POST['localtax1_type'] == '0')) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
  622. if ((! empty($_POST["localtax2_type"]) || ($_POST['localtax2_type'] == '0')) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
  623. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  624. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  625. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  626. if ($id == 10 && isset($_POST["code"])) // Spaces are not allowed into code
  627. {
  628. $_POST["code"]=preg_replace('/\s/','',$_POST["code"]);
  629. }
  630. // Si verif ok et action add, on ajoute la ligne
  631. if ($ok && GETPOST('actionadd'))
  632. {
  633. if ($tabrowid[$id])
  634. {
  635. // Recupere id libre pour insertion
  636. $newid=0;
  637. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  638. $result = $db->query($sql);
  639. if ($result)
  640. {
  641. $obj = $db->fetch_object($result);
  642. $newid=($obj->newid + 1);
  643. } else {
  644. dol_print_error($db);
  645. }
  646. }
  647. // Add new entry
  648. $sql = "INSERT INTO ".$tabname[$id]." (";
  649. // List of fields
  650. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  651. $sql.= $tabrowid[$id].",";
  652. $sql.= $tabfieldinsert[$id];
  653. $sql.=",active)";
  654. $sql.= " VALUES(";
  655. // List of values
  656. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  657. $sql.= $newid.",";
  658. $i=0;
  659. foreach ($listfieldinsert as $f => $value)
  660. {
  661. if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
  662. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  663. }
  664. else if ($value == 'entity') {
  665. $_POST[$listfieldvalue[$i]] = $conf->entity;
  666. }
  667. if ($i) $sql.=",";
  668. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  669. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  670. $i++;
  671. }
  672. $sql.=",1)";
  673. dol_syslog("actionadd", LOG_DEBUG);
  674. $result = $db->query($sql);
  675. if ($result) // Add is ok
  676. {
  677. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  678. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  679. }
  680. else
  681. {
  682. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  683. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  684. }
  685. else {
  686. dol_print_error($db);
  687. }
  688. }
  689. }
  690. // Si verif ok et action modify, on modifie la ligne
  691. if ($ok && GETPOST('actionmodify'))
  692. {
  693. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  694. else { $rowidcol="rowid"; }
  695. // Modify entry
  696. $sql = "UPDATE ".$tabname[$id]." SET ";
  697. // Modifie valeur des champs
  698. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  699. {
  700. $sql.= $tabrowid[$id]."=";
  701. $sql.= "'".$db->escape($rowid)."', ";
  702. }
  703. $i = 0;
  704. foreach ($listfieldmodify as $field)
  705. {
  706. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  707. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  708. }
  709. else if ($field == 'entity') {
  710. $_POST[$listfieldvalue[$i]] = $conf->entity;
  711. }
  712. if ($i) $sql.=",";
  713. $sql.= $field."=";
  714. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  715. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  716. $i++;
  717. }
  718. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  719. dol_syslog("actionmodify", LOG_DEBUG);
  720. //print $sql;
  721. $resql = $db->query($sql);
  722. if (! $resql)
  723. {
  724. setEventMessages($db->error(), null, 'errors');
  725. }
  726. }
  727. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  728. }
  729. if (GETPOST('actioncancel'))
  730. {
  731. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  732. }
  733. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  734. {
  735. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  736. else { $rowidcol="rowid"; }
  737. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  738. dol_syslog("delete", LOG_DEBUG);
  739. $result = $db->query($sql);
  740. if (! $result)
  741. {
  742. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  743. {
  744. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  745. }
  746. else
  747. {
  748. dol_print_error($db);
  749. }
  750. }
  751. }
  752. // activate
  753. if ($action == $acts[0])
  754. {
  755. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  756. else { $rowidcol="rowid"; }
  757. if ($rowid) {
  758. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  759. }
  760. elseif ($_GET["code"]) {
  761. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".dol_escape_htmltag($_GET["code"])."'";
  762. }
  763. $result = $db->query($sql);
  764. if (!$result)
  765. {
  766. dol_print_error($db);
  767. }
  768. }
  769. // disable
  770. if ($action == $acts[1])
  771. {
  772. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  773. else { $rowidcol="rowid"; }
  774. if ($rowid) {
  775. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  776. }
  777. elseif ($_GET["code"]) {
  778. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".dol_escape_htmltag($_GET["code"])."'";
  779. }
  780. $result = $db->query($sql);
  781. if (!$result)
  782. {
  783. dol_print_error($db);
  784. }
  785. }
  786. // favorite
  787. if ($action == 'activate_favorite')
  788. {
  789. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  790. else { $rowidcol="rowid"; }
  791. if ($rowid) {
  792. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'";
  793. }
  794. elseif ($_GET["code"]) {
  795. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".dol_escape_htmltag($_GET["code"])."'";
  796. }
  797. $result = $db->query($sql);
  798. if (!$result)
  799. {
  800. dol_print_error($db);
  801. }
  802. }
  803. // disable favorite
  804. if ($action == 'disable_favorite')
  805. {
  806. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  807. else { $rowidcol="rowid"; }
  808. if ($rowid) {
  809. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'";
  810. }
  811. elseif ($_GET["code"]) {
  812. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".dol_escape_htmltag($_GET["code"])."'";
  813. }
  814. $result = $db->query($sql);
  815. if (!$result)
  816. {
  817. dol_print_error($db);
  818. }
  819. }
  820. /*
  821. * View
  822. */
  823. $form = new Form($db);
  824. $formadmin=new FormAdmin($db);
  825. llxHeader();
  826. $titre=$langs->trans("DictionarySetup");
  827. $linkback='';
  828. if ($id)
  829. {
  830. $titre.=' - '.$langs->trans($tablib[$id]);
  831. $linkback='<a href="'.$_SERVER['PHP_SELF'].'">'.$langs->trans("BackToDictionaryList").'</a>';
  832. }
  833. $titlepicto='title_setup';
  834. if ($id == 10 && GETPOST('from') == 'accountancy')
  835. {
  836. $titre=$langs->trans("MenuVatAccounts");
  837. $titlepicto='title_accountancy';
  838. }
  839. if ($id == 7 && GETPOST('from') == 'accountancy')
  840. {
  841. $titre=$langs->trans("MenuTaxAccounts");
  842. $titlepicto='title_accountancy';
  843. }
  844. print load_fiche_titre($titre,$linkback,$titlepicto);
  845. if (empty($id))
  846. {
  847. print $langs->trans("DictionaryDesc");
  848. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  849. }
  850. print "<br>\n";
  851. $param = '&id='.$id;
  852. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  853. if ($search_code != '') $param.= '&search_code='.urlencode($search_country_id);
  854. $paramwithsearch = $param;
  855. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  856. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  857. if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
  858. // Confirmation de la suppression de la ligne
  859. if ($action == 'delete')
  860. {
  861. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'rowid='.$rowid.'&code='.urlencode($_GET["code"]).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  862. }
  863. //var_dump($elementList);
  864. /*
  865. * Show a dictionary
  866. */
  867. if ($id)
  868. {
  869. // Complete requete recherche valeurs avec critere de tri
  870. $sql=$tabsql[$id];
  871. if (! preg_match('/ WHERE /',$sql)) $sql.= " WHERE 1 = 1";
  872. if ($search_country_id > 0) $sql.= " AND c.rowid = ".$search_country_id;
  873. if ($search_code != '') $sql.= natural_search("code", $search_code);
  874. if ($sortfield)
  875. {
  876. // If sort order is "country", we use country_code instead
  877. if ($sortfield == 'country') $sortfield='country_code';
  878. $sql.= " ORDER BY ".$sortfield;
  879. if ($sortorder)
  880. {
  881. $sql.=" ".strtoupper($sortorder);
  882. }
  883. $sql.=", ";
  884. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  885. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  886. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  887. }
  888. else {
  889. $sql.=" ORDER BY ";
  890. }
  891. $sql.=$tabsqlsort[$id];
  892. $sql.=$db->plimit($listlimit+1,$offset);
  893. //print $sql;
  894. $fieldlist=explode(',',$tabfield[$id]);
  895. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  896. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  897. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  898. // Form to add a new line
  899. if ($tabname[$id])
  900. {
  901. $alabelisused=0;
  902. $fieldlist=explode(',',$tabfield[$id]);
  903. print '<table class="noborder" width="100%">';
  904. // Line for title
  905. print '<tr class="liste_titre">';
  906. foreach ($fieldlist as $field => $value)
  907. {
  908. // Determine le nom du champ par rapport aux noms possibles
  909. // dans les dictionnaires de donnees
  910. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  911. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  912. $class='';
  913. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  914. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  915. if ($fieldlist[$field]=='taux') {
  916. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  917. else $valuetoshow=$langs->trans("Amount");
  918. $class='center';
  919. }
  920. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $class="center"; $sortable=0; }
  921. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $class="center"; }
  922. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $class="center"; $sortable=0; }
  923. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $class="center"; }
  924. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  925. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  926. if ($fieldlist[$field]=='type') {
  927. if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
  928. else $valuetoshow=$langs->trans("Type");
  929. }
  930. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); $class='width100'; }
  931. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  932. {
  933. if ($id != 25) $valuetoshow=$form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
  934. else $valuetoshow=$langs->trans("Label");
  935. }
  936. if ($fieldlist[$field]=='libelle_facture') {
  937. $valuetoshow=$form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
  938. }
  939. if ($fieldlist[$field]=='country') {
  940. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  941. $valuetoshow=$langs->trans("Country");
  942. }
  943. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $class="center"; }
  944. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  945. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $class="center"; }
  946. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  947. if ($fieldlist[$field]=='width' || $fieldlist[$field]=='nx') { $valuetoshow=$langs->trans("Width"); }
  948. if ($fieldlist[$field]=='height' || $fieldlist[$field]=='ny') { $valuetoshow=$langs->trans("Height"); }
  949. if ($fieldlist[$field]=='unit' || $fieldlist[$field]=='metric') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  950. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
  951. if ($fieldlist[$field]=='accountancy_code') { $valuetoshow=$langs->trans("AccountancyCode"); }
  952. if ($fieldlist[$field]=='accountancy_code_sell') { $valuetoshow=$langs->trans("AccountancyCodeSell"); }
  953. if ($fieldlist[$field]=='accountancy_code_buy') { $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
  954. if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  955. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountparent"); }
  956. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  957. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  958. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  959. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  960. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  961. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  962. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  963. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  964. if ($fieldlist[$field]=='paper_size') { $valuetoshow=$langs->trans("PaperSize"); }
  965. if ($fieldlist[$field]=='orientation') { $valuetoshow=$langs->trans("Orientation"); }
  966. if ($fieldlist[$field]=='leftmargin') { $valuetoshow=$langs->trans("LeftMargin"); }
  967. if ($fieldlist[$field]=='topmargin') { $valuetoshow=$langs->trans("TopMargin"); }
  968. if ($fieldlist[$field]=='spacex') { $valuetoshow=$langs->trans("SpaceX"); }
  969. if ($fieldlist[$field]=='spacey') { $valuetoshow=$langs->trans("SpaceY"); }
  970. if ($fieldlist[$field]=='font_size') { $valuetoshow=$langs->trans("FontSize"); }
  971. if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
  972. if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
  973. if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
  974. if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("WithCounter"); }
  975. if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
  976. if ($fieldlist[$field]=='newbymonth') { $valuetoshow=$langs->trans("NewByMonth"); }
  977. if ($id == 2) // Special cas for state page
  978. {
  979. if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
  980. if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
  981. }
  982. if ($valuetoshow != '')
  983. {
  984. print '<td'.($class?' class="'.$class.'"':'').'>';
  985. if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1,$valuetoshow).'</a>';
  986. else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  987. else print $valuetoshow;
  988. print '</td>';
  989. }
  990. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  991. }
  992. if ($id == 4) print '<td></td>';
  993. print '<td>';
  994. print '<input type="hidden" name="id" value="'.$id.'">';
  995. print '</td>';
  996. print '<td style="min-width: 26px;"></td>';
  997. print '<td style="min-width: 26px;"></td>';
  998. print '</tr>';
  999. // Line to enter new values
  1000. print '<!-- line to add new entry --><tr class="oddeven nodrag nodrop nohover">';
  1001. $obj = new stdClass();
  1002. // If data was already input, we define them in obj to populate input fields.
  1003. if (GETPOST('actionadd'))
  1004. {
  1005. foreach ($fieldlist as $key=>$val)
  1006. {
  1007. if (GETPOST($val) != '')
  1008. $obj->$val=GETPOST($val);
  1009. }
  1010. }
  1011. $tmpaction = 'create';
  1012. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1013. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1014. $error=$hookmanager->error; $errors=$hookmanager->errors;
  1015. if ($id == 3) unset($fieldlist[2]); // Remove field ??? if dictionary Regions
  1016. if (empty($reshook))
  1017. {
  1018. fieldList($fieldlist, $obj, $tabname[$id], 'add');
  1019. }
  1020. if ($id == 4) print '<td></td>';
  1021. print '<td colspan="3" align="right">';
  1022. if ($action != 'edit')
  1023. {
  1024. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  1025. }
  1026. print '</td>';
  1027. print "</tr>";
  1028. $colspan=count($fieldlist)+3;
  1029. if ($id == 4) $colspan++;
  1030. print '</table>';
  1031. /*if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of *
  1032. {
  1033. print '* '.$langs->trans("LabelUsedByDefault").'.<br>';
  1034. }*/
  1035. }
  1036. print '</form>';
  1037. print '<br>';
  1038. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  1039. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1040. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  1041. // List of available record in database
  1042. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  1043. $resql=$db->query($sql);
  1044. if ($resql)
  1045. {
  1046. $num = $db->num_rows($resql);
  1047. $i = 0;
  1048. // There is several pages
  1049. if ($num > $listlimit)
  1050. {
  1051. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  1052. }
  1053. print '<table class="noborder" width="100%">';
  1054. // Title line with search boxes
  1055. print '<tr class="liste_titre_filter">';
  1056. $filterfound=0;
  1057. foreach ($fieldlist as $field => $value)
  1058. {
  1059. $showfield=1; // By defaut
  1060. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  1061. if ($showfield)
  1062. {
  1063. if ($value == 'country')
  1064. {
  1065. print '<td class="liste_titre">';
  1066. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
  1067. print '</td>';
  1068. $filterfound++;
  1069. }
  1070. elseif ($value == 'code')
  1071. {
  1072. print '<td class="liste_titre">';
  1073. print '<input type="text" name="search_code" value="'.dol_escape_htmltag($search_code).'">';
  1074. print '</td>';
  1075. $filterfound++;
  1076. }
  1077. else
  1078. {
  1079. print '<td class="liste_titre">';
  1080. print '</td>';
  1081. }
  1082. }
  1083. }
  1084. if ($id == 4) print '<td></td>';
  1085. print '<td class="liste_titre"></td>';
  1086. print '<td class="liste_titre" colspan="2" align="right">';
  1087. if ($filterfound)
  1088. {
  1089. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  1090. print $searchpicto;
  1091. }
  1092. print '</td>';
  1093. print '</tr>';
  1094. // Title of lines
  1095. print '<tr class="liste_titre">';
  1096. foreach ($fieldlist as $field => $value)
  1097. {
  1098. // Determine le nom du champ par rapport aux noms possibles
  1099. // dans les dictionnaires de donnees
  1100. $showfield=1; // By defaut
  1101. $align="left";
  1102. $sortable=1;
  1103. $valuetoshow='';
  1104. /*
  1105. $tmparray=getLabelOfField($fieldlist[$field]);
  1106. $showfield=$tmp['showfield'];
  1107. $valuetoshow=$tmp['valuetoshow'];
  1108. $align=$tmp['align'];
  1109. $sortable=$tmp['sortable'];
  1110. */
  1111. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  1112. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  1113. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  1114. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  1115. if ($fieldlist[$field]=='taux') {
  1116. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  1117. else $valuetoshow=$langs->trans("Amount");
  1118. $align='center';
  1119. }
  1120. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
  1121. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $align="center"; $sortable=0; }
  1122. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
  1123. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $align="center"; $sortable=0; }
  1124. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  1125. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  1126. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  1127. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  1128. if ($fieldlist[$field]=='position') { $align='right'; }
  1129. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  1130. {
  1131. //if ($id != 25) $valuetoshow=$form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
  1132. //else $valuetoshow=$langs->trans("Label");
  1133. $valuetoshow=$langs->trans("Label");
  1134. }
  1135. if ($fieldlist[$field]=='libelle_facture') {
  1136. //$valuetoshow=$form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"),2,1,img_help(1,''));
  1137. $valuetoshow=$langs->trans("LabelOnDocuments");
  1138. }
  1139. if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
  1140. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
  1141. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  1142. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
  1143. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  1144. if ($fieldlist[$field]=='width' || $fieldlist[$field]=='nx') { $valuetoshow=$langs->trans("Width"); }
  1145. if ($fieldlist[$field]=='height' || $fieldlist[$field]=='ny') { $valuetoshow=$langs->trans("Height"); }
  1146. if ($fieldlist[$field]=='unit' || $fieldlist[$field]=='metric') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  1147. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  1148. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  1149. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
  1150. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
  1151. if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  1152. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
  1153. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  1154. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  1155. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  1156. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  1157. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  1158. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  1159. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  1160. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  1161. if ($fieldlist[$field]=='paper_size') { $valuetoshow=$langs->trans("PaperSize"); }
  1162. if ($fieldlist[$field]=='orientation') { $valuetoshow=$langs->trans("Orientation"); }
  1163. if ($fieldlist[$field]=='leftmargin') { $valuetoshow=$langs->trans("LeftMargin"); }
  1164. if ($fieldlist[$field]=='topmargin') { $valuetoshow=$langs->trans("TopMargin"); }
  1165. if ($fieldlist[$field]=='spacex') { $valuetoshow=$langs->trans("SpaceX"); }
  1166. if ($fieldlist[$field]=='spacey') { $valuetoshow=$langs->trans("SpaceY"); }
  1167. if ($fieldlist[$field]=='font_size') { $valuetoshow=$langs->trans("FontSize"); }
  1168. if ($fieldlist[$field]=='custom_x') { $valuetoshow=$langs->trans("CustomX"); }
  1169. if ($fieldlist[$field]=='custom_y') { $valuetoshow=$langs->trans("CustomY"); }
  1170. if ($fieldlist[$field]=='percent') { $valuetoshow=$langs->trans("Percentage"); }
  1171. if ($fieldlist[$field]=='affect') { $valuetoshow=$langs->trans("WithCounter"); }
  1172. if ($fieldlist[$field]=='delay') { $valuetoshow=$langs->trans("NoticePeriod"); }
  1173. if ($fieldlist[$field]=='newbymonth') { $valuetoshow=$langs->trans("NewByMonth"); }
  1174. // Affiche nom du champ
  1175. if ($showfield)
  1176. {
  1177. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  1178. }
  1179. }
  1180. // Favorite - Only activated on country dictionary
  1181. if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  1182. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  1183. print getTitleFieldOfList('');
  1184. print getTitleFieldOfList('');
  1185. print '</tr>';
  1186. if ($num)
  1187. {
  1188. // Lines with values
  1189. while ($i < $num)
  1190. {
  1191. $obj = $db->fetch_object($resql);
  1192. //print_r($obj);
  1193. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  1194. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  1195. {
  1196. $tmpaction='edit';
  1197. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1198. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1199. $error=$hookmanager->error; $errors=$hookmanager->errors;
  1200. // Show fields
  1201. if (empty($reshook)) fieldList($fieldlist, $obj, $tabname[$id], 'edit');
  1202. print '<td colspan="3" align="center">';
  1203. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  1204. print '<input type="hidden" name="page" value="'.$page.'">';
  1205. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  1206. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  1207. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  1208. print '</td>';
  1209. }
  1210. else
  1211. {
  1212. $tmpaction = 'view';
  1213. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1214. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1215. $error=$hookmanager->error; $errors=$hookmanager->errors;
  1216. if (empty($reshook))
  1217. {
  1218. foreach ($fieldlist as $field => $value)
  1219. {
  1220. $showfield=1;
  1221. $align="left";
  1222. $valuetoshow=$obj->{$fieldlist[$field]};
  1223. if ($value == 'element')
  1224. {
  1225. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  1226. }
  1227. else if ($value == 'source')
  1228. {
  1229. $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
  1230. }
  1231. else if ($valuetoshow=='all') {
  1232. $valuetoshow=$langs->trans('All');
  1233. }
  1234. else if ($fieldlist[$field]=='country') {
  1235. if (empty($obj->country_code))
  1236. {
  1237. $valuetoshow='-';
  1238. }
  1239. else
  1240. {
  1241. $key=$langs->trans("Country".strtoupper($obj->country_code));
  1242. $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
  1243. }
  1244. }
  1245. else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  1246. $valuetoshow=yn($valuetoshow);
  1247. $align="center";
  1248. }
  1249. else if ($fieldlist[$field]=='type_cdr') {
  1250. if(empty($valuetoshow)) $valuetoshow = $langs->trans('None');
  1251. elseif($valuetoshow == 1) $valuetoshow = $langs->trans('AtEndOfMonth');
  1252. elseif($valuetoshow == 2) $valuetoshow = $langs->trans('CurrentNext');
  1253. $align="center";
  1254. }
  1255. else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) {
  1256. $valuetoshow=price($valuetoshow);
  1257. }
  1258. if ($value == 'private')
  1259. {
  1260. $valuetoshow = yn($elementList[$valuetoshow]);
  1261. }
  1262. else if ($fieldlist[$field]=='libelle_facture') {
  1263. $langs->load("bills");
  1264. $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
  1265. $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1266. $valuetoshow=nl2br($valuetoshow);
  1267. }
  1268. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
  1269. $key=$langs->trans("Country".strtoupper($obj->code));
  1270. $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1271. }
  1272. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
  1273. $langs->load("propal");
  1274. $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
  1275. $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1276. }
  1277. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
  1278. $key=$langs->trans("Action".strtoupper($obj->code));
  1279. $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1280. }
  1281. else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
  1282. $key=$langs->trans("Currency".strtoupper($obj->code_iso));
  1283. $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
  1284. }
  1285. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
  1286. $key=$langs->trans(strtoupper($obj->code));
  1287. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1288. }
  1289. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
  1290. $key=$langs->trans(strtoupper($obj->code));
  1291. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1292. }
  1293. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
  1294. $key=$langs->trans("Civility".strtoupper($obj->code));
  1295. $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1296. }
  1297. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
  1298. $langs->load('agenda');
  1299. $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  1300. $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1301. }
  1302. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
  1303. $langs->load("bills");
  1304. $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
  1305. $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1306. }
  1307. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
  1308. $langs->load("bills");
  1309. $key=$langs->trans("PaymentType".strtoupper($obj->code));
  1310. $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1311. }
  1312. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
  1313. $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
  1314. $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1315. }
  1316. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
  1317. $langs->load("orders");
  1318. $key=$langs->trans($obj->code);
  1319. $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
  1320. }
  1321. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
  1322. $langs->load("sendings");
  1323. $key=$langs->trans("SendingMethod".strtoupper($obj->code));
  1324. $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  1325. }
  1326. else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
  1327. {
  1328. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  1329. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  1330. }
  1331. else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
  1332. {
  1333. $langs->load('trips');
  1334. $key = $langs->trans(strtoupper($obj->code));
  1335. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  1336. }
  1337. else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
  1338. $showfield=0;
  1339. }
  1340. else if ($fieldlist[$field]=='unicode') {
  1341. $valuetoshow = $langs->getCurrencySymbol($obj->code,1);
  1342. }
  1343. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  1344. $langs->load("products");
  1345. $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
  1346. }
  1347. else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  1348. $langs->load("products");
  1349. $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
  1350. }
  1351. else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
  1352. {
  1353. $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
  1354. $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$fieldlist[$field]});
  1355. }
  1356. else if ($fieldlist[$field]=='localtax1' || $fieldlist[$field]=='localtax2') {
  1357. $align="center";
  1358. }
  1359. else if ($fieldlist[$field]=='localtax1_type') {
  1360. if ($obj->localtax1 != 0)
  1361. $valuetoshow=$localtax_typeList[$valuetoshow];
  1362. else
  1363. $valuetoshow = '';
  1364. $align="center";
  1365. }
  1366. else if ($fieldlist[$field]=='localtax2_type') {
  1367. if ($obj->localtax2 != 0)
  1368. $valuetoshow=$localtax_typeList[$valuetoshow];
  1369. else
  1370. $valuetoshow = '';
  1371. $align="center";
  1372. }
  1373. else if ($fieldlist[$field]=='taux') {
  1374. $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
  1375. $align="center";
  1376. }
  1377. else if (in_array($fieldlist[$field],array('recuperableonly')))
  1378. {
  1379. $align="center";
  1380. }
  1381. else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
  1382. $valuetoshow = length_accountg($valuetoshow);
  1383. }
  1384. $class='tddict';
  1385. if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
  1386. if ($fieldlist[$field] == 'code') $class.=' width100';
  1387. if ($fieldlist[$field] == 'position') $class.=' right';
  1388. // Show value for field
  1389. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  1390. }
  1391. }
  1392. // Can an entry be erased or disabled ?
  1393. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  1394. if (isset($obj->code) && $id != 10)
  1395. {
  1396. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  1397. else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  1398. else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  1399. }
  1400. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
  1401. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
  1402. $canbemodified=$iserasable;
  1403. if ($obj->code == 'RECEP') $canbemodified=1;
  1404. if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm") $canbemodified=1;
  1405. // Url
  1406. $rowidcol=$tabrowid[$id];
  1407. // If rowidcol not defined
  1408. if (empty($rowidcol) || in_array($id, array(6,7,8,13,17,19,27))) $rowidcol='rowid';
  1409. $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((! empty($obj->{$rowidcol}) || $obj->{$rowidcol} == '0')?$obj->{$rowidcol}:(! empty($obj->code)?urlencode($obj->code):'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'');
  1410. if ($param) $url .= '&'.$param;
  1411. $url.='&';
  1412. // Favorite
  1413. // Only activated on country dictionary
  1414. if ($id == 4)
  1415. {
  1416. print '<td align="center" class="nowrap">';
  1417. if ($iserasable) print '<a href="'.$url.'action='.$acts[$obj->favorite].'_favorite">'.$actl[$obj->favorite].'</a>';
  1418. else print $langs->trans("AlwaysActive");
  1419. print '</td>';
  1420. }
  1421. // Active
  1422. print '<td align="center" class="nowrap">';
  1423. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  1424. else
  1425. {
  1426. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  1427. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  1428. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  1429. else print $langs->trans("AlwaysActive");
  1430. }
  1431. print "</td>";
  1432. // Modify link
  1433. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  1434. else print '<td>&nbsp;</td>';
  1435. // Delete link
  1436. if ($iserasable)
  1437. {
  1438. print '<td align="center">';
  1439. if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
  1440. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  1441. print '</td>';
  1442. }
  1443. else print '<td>&nbsp;</td>';
  1444. print "</tr>\n";
  1445. }
  1446. $i++;
  1447. }
  1448. }
  1449. print '</table>';
  1450. }
  1451. else {
  1452. dol_print_error($db);
  1453. }
  1454. print '</form>';
  1455. }
  1456. else
  1457. {
  1458. /*
  1459. * Show list of dictionary to show
  1460. */
  1461. $lastlineisempty=false;
  1462. print '<table class="noborder" width="100%">';
  1463. print '<tr class="liste_titre">';
  1464. //print '<td>'.$langs->trans("Module").'</td>';
  1465. print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
  1466. print '<td>'.$langs->trans("Table").'</td>';
  1467. print '</tr>';
  1468. $showemptyline='';
  1469. foreach ($taborder as $i)
  1470. {
  1471. if (isset($tabname[$i]) && empty($tabcond[$i])) continue;
  1472. if ($i)
  1473. {
  1474. if ($showemptyline)
  1475. {
  1476. print '<tr class="oddeven"><td width="30%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  1477. $showemptyline=0;
  1478. }
  1479. $value=$tabname[$i];
  1480. print '<tr class="oddeven"><td width="50%">';
  1481. if (! empty($tabcond[$i]))
  1482. {
  1483. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">'.$langs->trans($tablib[$i]).'</a>';
  1484. }
  1485. else
  1486. {
  1487. print $langs->trans($tablib[$i]);
  1488. }
  1489. print '</td>';
  1490. print '<td>';
  1491. /*if (empty($tabcond[$i]))
  1492. {
  1493. print info_admin($langs->trans("DictionaryDisabledSinceNoModuleNeedIt"),1);
  1494. }*/
  1495. print '</td>';
  1496. print '<td>'.$tabname[$i].'</td></tr>';
  1497. $lastlineisempty=false;
  1498. }
  1499. else
  1500. {
  1501. if (! $lastlineisempty)
  1502. {
  1503. $showemptyline=1;
  1504. $lastlineisempty=true;
  1505. }
  1506. }
  1507. }
  1508. print '</table>';
  1509. }
  1510. print '<br>';
  1511. llxFooter();
  1512. $db->close();
  1513. /**
  1514. * Show fields in insert/edit mode
  1515. *
  1516. * @param array $fieldlist Array of fields
  1517. * @param Object $obj If we show a particular record, obj is filled with record fields
  1518. * @param string $tabname Name of SQL table
  1519. * @param string $context 'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered
  1520. * @return void
  1521. */
  1522. function fieldList($fieldlist, $obj='', $tabname='', $context='')
  1523. {
  1524. global $conf,$langs,$db;
  1525. global $form;
  1526. global $region_id;
  1527. global $elementList,$sourceList,$localtax_typeList;
  1528. global $bc;
  1529. $formadmin = new FormAdmin($db);
  1530. $formcompany = new FormCompany($db);
  1531. if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
  1532. foreach ($fieldlist as $field => $value)
  1533. {
  1534. if (in_array($fieldlist[$field], array('code', 'libelle', 'type')) && $tabname == MAIN_DB_PREFIX."c_actioncomm" && in_array($obj->type, array('system','systemauto')))
  1535. {
  1536. $hidden = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'');
  1537. print '<td>';
  1538. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$hidden.'">';
  1539. print $langs->trans($hidden);
  1540. print '</td>';
  1541. }
  1542. elseif ($fieldlist[$field] == 'country')
  1543. {
  1544. if (in_array('region_id',$fieldlist))
  1545. {
  1546. print '<td>';
  1547. //print join(',',$fieldlist);
  1548. print '</td>';
  1549. continue;
  1550. } // For state page, we do not show the country input (we link to region, not country)
  1551. print '<td>';
  1552. $fieldname='country';
  1553. print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
  1554. print '</td>';
  1555. }
  1556. elseif ($fieldlist[$field] == 'country_id')
  1557. {
  1558. if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
  1559. {
  1560. $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
  1561. print '<td class="tdoverflowmax100">';
  1562. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
  1563. print '</td>';
  1564. }
  1565. }
  1566. elseif ($fieldlist[$field] == 'region')
  1567. {
  1568. print '<td>';
  1569. $formcompany->select_region($region_id,'region');
  1570. print '</td>';
  1571. }
  1572. elseif ($fieldlist[$field] == 'region_id')
  1573. {
  1574. $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
  1575. print '<td>';
  1576. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
  1577. print '</td>';
  1578. }
  1579. elseif ($fieldlist[$field] == 'lang')
  1580. {
  1581. print '<td>';
  1582. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  1583. print '</td>';
  1584. }
  1585. // Le type de l'element (pour les type de contact)
  1586. elseif ($fieldlist[$field] == 'element')
  1587. {
  1588. print '<td>';
  1589. print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1590. print '</td>';
  1591. }
  1592. // La source de l'element (pour les type de contact)
  1593. elseif ($fieldlist[$field] == 'source')
  1594. {
  1595. print '<td>';
  1596. print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1597. print '</td>';
  1598. }
  1599. elseif ($fieldlist[$field] == 'private')
  1600. {
  1601. print '<td>';
  1602. print $form->selectyesno("private",(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1603. print '</td>';
  1604. }
  1605. elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
  1606. {
  1607. print '<td>';
  1608. print 'user<input type="hidden" name="type" value="user">';
  1609. print '</td>';
  1610. }
  1611. elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  1612. if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
  1613. else print '<td>';
  1614. if ($fieldlist[$field] == 'type_cdr') {
  1615. print $form->selectarray($fieldlist[$field], array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1616. } else {
  1617. print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
  1618. }
  1619. print '</td>';
  1620. }
  1621. elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
  1622. $align="left";
  1623. if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="center"; // Fields aligned on right
  1624. print '<td align="'.$align.'">';
  1625. print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="3" name="'.$fieldlist[$field].'">';
  1626. print '</td>';
  1627. }
  1628. elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
  1629. print '<td>';
  1630. $transfound=0;
  1631. // Special case for labels
  1632. if ($tabname == MAIN_DB_PREFIX.'c_payment_term')
  1633. {
  1634. $langs->load("bills");
  1635. $transkey="PaymentCondition".strtoupper($obj->code);
  1636. if ($langs->trans($transkey) != $transkey)
  1637. {
  1638. $transfound=1;
  1639. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  1640. }
  1641. }
  1642. if (! $transfound)
  1643. {
  1644. print '<textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  1645. }
  1646. print '</td>';
  1647. }
  1648. elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
  1649. print '<td><input type="text" class="flat minwidth75" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" name="'.$fieldlist[$field].'"></td>';
  1650. }
  1651. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  1652. print '<td class="maxxxx"><input type="text" class="flat minwidth75" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
  1653. }
  1654. elseif ($fieldlist[$field]=='unit') {
  1655. print '<td>';
  1656. $units = array(
  1657. 'mm' => $langs->trans('SizeUnitmm'),
  1658. 'cm' => $langs->trans('SizeUnitcm'),
  1659. 'point' => $langs->trans('SizeUnitpoint'),
  1660. 'inch' => $langs->trans('SizeUnitinch')
  1661. );
  1662. print $form->selectarray('unit', $units, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 0, 0, 0);
  1663. print '</td>';
  1664. }
  1665. // Le type de taxe locale
  1666. elseif ($fieldlist[$field] == 'localtax1_type' || $fieldlist[$field] == 'localtax2_type')
  1667. {
  1668. print '<td align="center">';
  1669. print $form->selectarray($fieldlist[$field], $localtax_typeList, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1670. print '</td>';
  1671. }
  1672. elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
  1673. {
  1674. print '<td>';
  1675. if (! empty($conf->accounting->enabled))
  1676. {
  1677. $fieldname = $fieldlist[$field];
  1678. $accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
  1679. print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  1680. }
  1681. else
  1682. {
  1683. $fieldname = $fieldlist[$field];
  1684. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname)?$obj->$fieldname:'').'" name="'.$fieldlist[$field].'">';
  1685. }
  1686. print '</td>';
  1687. }
  1688. else
  1689. {
  1690. $classtd=''; $class='';
  1691. if ($fieldlist[$field]=='code') $classtd='width100';
  1692. if ($fieldlist[$field]=='affect') $class='maxwidth50';
  1693. if ($fieldlist[$field]=='delay') $class='maxwidth50';
  1694. if ($fieldlist[$field]=='position') $class='maxwidth50';
  1695. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $class='quatrevingtpercent';
  1696. if ($fieldlist[$field]=='tracking') $class='quatrevingtpercent';
  1697. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $class='maxwidth50';
  1698. print '<td class="'.$classtd.'">';
  1699. $transfound=0;
  1700. if (in_array($fieldlist[$field], array('label','libelle')))
  1701. {
  1702. $transkey='';
  1703. // Special case for labels
  1704. if ($tabname == MAIN_DB_PREFIX.'c_civility') {
  1705. $transkey="Civility".strtoupper($obj->code);
  1706. }
  1707. if ($tabname == MAIN_DB_PREFIX.'c_payment_term') {
  1708. $langs->load("bills");
  1709. $transkey="PaymentCondition".strtoupper($obj->code);
  1710. }
  1711. if ($transkey && $langs->trans($transkey) != $transkey)
  1712. {
  1713. $transfound=1;
  1714. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  1715. }
  1716. }
  1717. if (! $transfound)
  1718. {
  1719. print '<input type="text" class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  1720. }
  1721. print '</td>';
  1722. }
  1723. }
  1724. }