dict.php 106 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2010-2022 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011-2021 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-2022 Alexandre Spangaro <aspangaro@open-dsi.fr>
  12. * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. * Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
  15. * Copyright (C) 2020-2022 Open-Dsi <support@open-dsi.fr>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  29. */
  30. /**
  31. * \file htdocs/admin/dict.php
  32. * \ingroup setup
  33. * \brief Page to administer data tables
  34. */
  35. require '../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  43. // Load translation files required by the page
  44. $langs->loadLangs(array("errors", "admin", "main", "companies", "resource", "holiday", "accountancy", "hrm", "orders", "contracts", "projects", "propal", "bills", "interventions", "ticket"));
  45. $action = GETPOST('action', 'alpha') ?GETPOST('action', 'alpha') : 'view';
  46. $confirm = GETPOST('confirm', 'alpha');
  47. $id = GETPOST('id', 'int');
  48. $rowid = GETPOST('rowid', 'alpha');
  49. $entity = GETPOST('entity', 'int');
  50. $code = GETPOST('code', 'alpha');
  51. $allowed = $user->admin;
  52. if ($id == 7 && !empty($user->rights->accounting->chartofaccount)) {
  53. $allowed = 1; // Tax page allowed to manager of chart account
  54. }
  55. if ($id == 10 && !empty($user->rights->accounting->chartofaccount)) {
  56. $allowed = 1; // Vat page allowed to manager of chart account
  57. }
  58. if ($id == 17 && !empty($user->rights->accounting->chartofaccount)) {
  59. $allowed = 1; // Dictionary with type of expense report and accounting account allowed to manager of chart account
  60. }
  61. if (!$allowed) {
  62. accessforbidden();
  63. }
  64. $acts = array(); $actl = array();
  65. $acts[0] = "activate";
  66. $acts[1] = "disable";
  67. $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
  68. $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
  69. $listoffset = GETPOST('listoffset');
  70. $listlimit = GETPOST('listlimit') > 0 ?GETPOST('listlimit') : 1000; // To avoid too long dictionaries
  71. $active = 1;
  72. $sortfield = GETPOST('sortfield', 'aZ09comma');
  73. $sortorder = GETPOST('sortorder', 'aZ09comma');
  74. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  75. if (empty($page) || $page == -1) {
  76. $page = 0;
  77. } // If $page is not defined, or '' or -1
  78. $offset = $listlimit * $page;
  79. $pageprev = $page - 1;
  80. $pagenext = $page + 1;
  81. $search_country_id = GETPOST('search_country_id', 'int');
  82. if (!GETPOSTISSET('search_country_id') && $search_country_id == '' && ($id == 2 || $id == 3 || $id == 10)) { // Not a so good idea to force on current country for all dictionaries. Some tables have entries that are for all countries, we must be able to see them, so this is done for dedicated dictionaries only.
  83. $search_country_id = $mysoc->country_id;
  84. }
  85. $search_code = GETPOST('search_code', 'alpha');
  86. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  87. $hookmanager->initHooks(array('admin', 'dictionaryadmin'));
  88. // This page is a generic page to edit dictionaries
  89. // Put here declaration of dictionaries properties
  90. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  91. $taborder = array(9, 15, 30, 0, 4, 3, 2, 0, 1, 8, 19, 16, 39, 27, 40, 38, 0, 5, 11, 0, 6, 24, 0, 29, 0, 33, 34, 32, 28, 17, 35, 36, 0, 10, 23, 12, 13, 7, 0, 14, 0, 22, 20, 18, 21, 41, 0, 37, 42, 0, 43, 0, 25, 0, 44, 0);
  92. // Name of SQL tables of dictionaries
  93. $tabname = array();
  94. $tabname[1] = "c_forme_juridique";
  95. $tabname[2] = "c_departements";
  96. $tabname[3] = "c_regions";
  97. $tabname[4] = "c_country";
  98. $tabname[5] = "c_civility";
  99. $tabname[6] = "c_actioncomm";
  100. $tabname[7] = "c_chargesociales";
  101. $tabname[8] = "c_typent";
  102. $tabname[9] = "c_currencies";
  103. $tabname[10] = "c_tva";
  104. $tabname[11] = "c_type_contact";
  105. $tabname[12] = "c_payment_term";
  106. $tabname[13] = "c_paiement";
  107. $tabname[14] = "c_ecotaxe";
  108. $tabname[15] = "c_paper_format";
  109. $tabname[16] = "c_prospectlevel";
  110. $tabname[17] = "c_type_fees";
  111. $tabname[18] = "c_shipment_mode";
  112. $tabname[19] = "c_effectif";
  113. $tabname[20] = "c_input_method";
  114. $tabname[21] = "c_availability";
  115. $tabname[22] = "c_input_reason";
  116. $tabname[23] = "c_revenuestamp";
  117. $tabname[24] = "c_type_resource";
  118. $tabname[25] = "c_type_container";
  119. //$tabname[26]= "c_units";
  120. $tabname[27] = "c_stcomm";
  121. $tabname[28] = "c_holiday_types";
  122. $tabname[29] = "c_lead_status";
  123. $tabname[30] = "c_format_cards";
  124. //$tabname[31]= "accounting_system";
  125. $tabname[32] = "c_hrm_public_holiday";
  126. $tabname[33] = "c_hrm_department";
  127. $tabname[34] = "c_hrm_function";
  128. $tabname[35] = "c_exp_tax_cat";
  129. $tabname[36] = "c_exp_tax_range";
  130. $tabname[37] = "c_units";
  131. $tabname[38] = "c_socialnetworks";
  132. $tabname[39] = "c_prospectcontactlevel";
  133. $tabname[40] = "c_stcommcontact";
  134. $tabname[41] = "c_transport_mode";
  135. $tabname[42] = "c_product_nature";
  136. $tabname[43] = "c_productbatch_qcstatus";
  137. $tabname[44] = "c_asset_disposal_type";
  138. // Dictionary labels
  139. $tablib = array();
  140. $tablib[1] = "DictionaryCompanyJuridicalType";
  141. $tablib[2] = "DictionaryCanton";
  142. $tablib[3] = "DictionaryRegion";
  143. $tablib[4] = "DictionaryCountry";
  144. $tablib[5] = "DictionaryCivility";
  145. $tablib[6] = "DictionaryActions";
  146. $tablib[7] = "DictionarySocialContributions";
  147. $tablib[8] = "DictionaryCompanyType";
  148. $tablib[9] = "DictionaryCurrency";
  149. $tablib[10] = "DictionaryVAT";
  150. $tablib[11] = "DictionaryTypeContact";
  151. $tablib[12] = "DictionaryPaymentConditions";
  152. $tablib[13] = "DictionaryPaymentModes";
  153. $tablib[14] = "DictionaryEcotaxe";
  154. $tablib[15] = "DictionaryPaperFormat";
  155. $tablib[16] = "DictionaryProspectLevel";
  156. $tablib[17] = "DictionaryFees";
  157. $tablib[18] = "DictionarySendingMethods";
  158. $tablib[19] = "DictionaryStaff";
  159. $tablib[20] = "DictionaryOrderMethods";
  160. $tablib[21] = "DictionaryAvailability";
  161. $tablib[22] = "DictionarySource";
  162. $tablib[23] = "DictionaryRevenueStamp";
  163. $tablib[24] = "DictionaryResourceType";
  164. $tablib[25] = "DictionaryTypeOfContainer";
  165. //$tablib[26]= "DictionaryUnits";
  166. $tablib[27] = "DictionaryProspectStatus";
  167. $tablib[28] = "DictionaryHolidayTypes";
  168. $tablib[29] = "DictionaryOpportunityStatus";
  169. $tablib[30] = "DictionaryFormatCards";
  170. //$tablib[31]= "DictionaryAccountancysystem";
  171. $tablib[32] = "DictionaryPublicHolidays";
  172. $tablib[33] = "DictionaryDepartment";
  173. $tablib[34] = "DictionaryFunction";
  174. $tablib[35] = "DictionaryExpenseTaxCat";
  175. $tablib[36] = "DictionaryExpenseTaxRange";
  176. $tablib[37] = "DictionaryMeasuringUnits";
  177. $tablib[38] = "DictionarySocialNetworks";
  178. $tablib[39] = "DictionaryProspectContactLevel";
  179. $tablib[40] = "DictionaryProspectContactStatus";
  180. $tablib[41] = "DictionaryTransportMode";
  181. $tablib[42] = "DictionaryProductNature";
  182. $tablib[43] = "DictionaryBatchStatus";
  183. $tablib[44] = "DictionaryAssetDisposalType";
  184. // Requests to extract data
  185. $tabsql = array();
  186. $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";
  187. $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";
  188. $tabsql[3] = "SELECT r.rowid as rowid, r.code_region as state_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";
  189. $tabsql[4] = "SELECT c.rowid as rowid, c.code, c.label, c.active, c.favorite, c.eec FROM ".MAIN_DB_PREFIX."c_country AS c";
  190. $tabsql[5] = "SELECT c.rowid as rowid, c.code as code, c.label, c.active FROM ".MAIN_DB_PREFIX."c_civility AS c";
  191. $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";
  192. $tabsql[7] = "SELECT a.id as rowid, a.code as code, a.libelle AS libelle, a.accountancy_code as accountancy_code, 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";
  193. $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";
  194. $tabsql[9] = "SELECT c.code_iso as code, c.label, c.unicode, c.active FROM ".MAIN_DB_PREFIX."c_currencies AS c";
  195. $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";
  196. $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";
  197. $tabsql[12] = "SELECT c.rowid as rowid, c.code, c.libelle, c.libelle_facture, c.deposit_percent, c.nbjour, c.type_cdr, c.decalage, c.active, c.sortorder, c.entity FROM ".MAIN_DB_PREFIX."c_payment_term AS c WHERE c.entity = ".getEntity($tabname[12]);
  198. $tabsql[13] = "SELECT c.id as rowid, c.code, c.libelle, c.type, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_paiement AS c WHERE c.entity = ".getEntity($tabname[13]);
  199. $tabsql[14] = "SELECT e.rowid as rowid, e.code as code, e.label, 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";
  200. $tabsql[15] = "SELECT rowid as rowid, code, label as libelle, width, height, unit, active FROM ".MAIN_DB_PREFIX."c_paper_format";
  201. $tabsql[16] = "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectlevel";
  202. $tabsql[17] = "SELECT id as rowid, code, label, accountancy_code, active FROM ".MAIN_DB_PREFIX."c_type_fees";
  203. $tabsql[18] = "SELECT rowid as rowid, code, libelle, tracking, active FROM ".MAIN_DB_PREFIX."c_shipment_mode";
  204. $tabsql[19] = "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_effectif";
  205. $tabsql[20] = "SELECT rowid as rowid, code, libelle, active FROM ".MAIN_DB_PREFIX."c_input_method";
  206. $tabsql[21] = "SELECT c.rowid as rowid, c.code, c.label, c.type_duration, c.qty, c.active, c.position FROM ".MAIN_DB_PREFIX."c_availability AS c";
  207. $tabsql[22] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_input_reason";
  208. $tabsql[23] = "SELECT t.rowid as rowid, t.taux, t.revenuestamp_type, 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";
  209. $tabsql[24] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_type_resource";
  210. $tabsql[25] = "SELECT rowid as rowid, code, label, active, module FROM ".MAIN_DB_PREFIX."c_type_container as t WHERE t.entity = ".getEntity($tabname[25]);
  211. //$tabsql[26]= "SELECT rowid as rowid, code, label, short_label, active FROM ".MAIN_DB_PREFIX."c_units";
  212. $tabsql[27] = "SELECT id as rowid, code, libelle, picto, active FROM ".MAIN_DB_PREFIX."c_stcomm";
  213. $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.block_if_negative, h.sortorder, 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";
  214. $tabsql[29] = "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status";
  215. $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";
  216. //$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s";
  217. $tabsql[32] = "SELECT a.id as rowid, a.entity, a.code, a.fk_country as country_id, c.code as country_code, c.label as country, a.dayrule, a.day, a.month, a.year, a.active FROM ".MAIN_DB_PREFIX."c_hrm_public_holiday as a LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON a.fk_country=c.rowid AND c.active=1";
  218. $tabsql[33] = "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department";
  219. $tabsql[34] = "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function";
  220. $tabsql[35] = "SELECT c.rowid, c.label, c.active, c.entity FROM ".MAIN_DB_PREFIX."c_exp_tax_cat c";
  221. $tabsql[36] = "SELECT r.rowid, r.fk_c_exp_tax_cat, r.range_ik, r.active, r.entity FROM ".MAIN_DB_PREFIX."c_exp_tax_range r";
  222. $tabsql[37] = "SELECT r.rowid, r.code, r.sortorder, r.label, r.short_label, r.unit_type, r.scale, r.active FROM ".MAIN_DB_PREFIX."c_units r";
  223. $tabsql[38] = "SELECT s.rowid, s.entity, s.code, s.label, s.url, s.icon, s.active FROM ".MAIN_DB_PREFIX."c_socialnetworks as s WHERE s.entity = ".getEntity($tabname[38]);
  224. $tabsql[39] = "SELECT code, label as libelle, sortorder, active FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
  225. $tabsql[40] = "SELECT id as rowid, code, libelle, picto, active FROM ".MAIN_DB_PREFIX."c_stcommcontact";
  226. $tabsql[41] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_transport_mode";
  227. $tabsql[42] = "SELECT rowid as rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_product_nature";
  228. $tabsql[43] = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_productbatch_qcstatus";
  229. $tabsql[44] = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_asset_disposal_type";
  230. // Criteria to sort dictionaries
  231. $tabsqlsort = array();
  232. $tabsqlsort[1] = "country ASC, code ASC";
  233. $tabsqlsort[2] = "country ASC, code ASC";
  234. $tabsqlsort[3] = "country ASC, code ASC";
  235. $tabsqlsort[4] = "code ASC";
  236. $tabsqlsort[5] = "label ASC";
  237. $tabsqlsort[6] = "a.type ASC, a.module ASC, a.position ASC, a.code ASC";
  238. $tabsqlsort[7] = "c.label ASC, a.code ASC, a.libelle ASC";
  239. $tabsqlsort[8] = "country DESC,".(!empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? ' t.position ASC,' : '')." libelle ASC";
  240. $tabsqlsort[9] = "label ASC";
  241. $tabsqlsort[10] = "country ASC, code ASC, taux ASC, recuperableonly ASC, localtax1 ASC, localtax2 ASC";
  242. $tabsqlsort[11] = "t.element ASC, t.source ASC, t.position ASC, t.code ASC";
  243. $tabsqlsort[12] = "sortorder ASC, code ASC";
  244. $tabsqlsort[13] = "code ASC";
  245. $tabsqlsort[14] = "country ASC, e.organization ASC, code ASC";
  246. $tabsqlsort[15] = "rowid ASC";
  247. $tabsqlsort[16] = "sortorder ASC";
  248. $tabsqlsort[17] = "code ASC";
  249. $tabsqlsort[18] = "code ASC, libelle ASC";
  250. $tabsqlsort[19] = "id ASC";
  251. $tabsqlsort[20] = "code ASC, libelle ASC";
  252. $tabsqlsort[21] = "position ASC, type_duration ASC, qty ASC";
  253. $tabsqlsort[22] = "code ASC, label ASC";
  254. $tabsqlsort[23] = "country ASC, taux ASC";
  255. $tabsqlsort[24] = "code ASC, label ASC";
  256. $tabsqlsort[25] = "t.module ASC, t.code ASC, t.label ASC";
  257. //$tabsqlsort[26]="code ASC";
  258. $tabsqlsort[27] = "code ASC";
  259. $tabsqlsort[28] = "sortorder ASC, country ASC, code ASC";
  260. $tabsqlsort[29] = "position ASC";
  261. $tabsqlsort[30] = "code ASC";
  262. //$tabsqlsort[31]="pcg_version ASC";
  263. $tabsqlsort[32] = "country, year ASC, month ASC, day ASC";
  264. $tabsqlsort[33] = "code ASC";
  265. $tabsqlsort[34] = "code ASC";
  266. $tabsqlsort[35] = "c.label ASC";
  267. $tabsqlsort[36] = "r.fk_c_exp_tax_cat ASC, r.range_ik ASC";
  268. $tabsqlsort[37] = "sortorder ASC";
  269. $tabsqlsort[38] = "rowid, code ASC";
  270. $tabsqlsort[39] = "sortorder ASC";
  271. $tabsqlsort[40] = "code ASC";
  272. $tabsqlsort[41] = "code ASC";
  273. $tabsqlsort[42] = "code ASC";
  274. $tabsqlsort[43] = "code ASC";
  275. $tabsqlsort[44] = "code ASC";
  276. // Field names in select result for dictionary display
  277. $tabfield = array();
  278. $tabfield[1] = "code,libelle,country";
  279. $tabfield[2] = "code,libelle,region_id,region,country"; // "code,libelle,region,country_code-country"
  280. $tabfield[3] = "code,libelle,country_id,country";
  281. $tabfield[4] = "code,label";
  282. $tabfield[5] = "code,label";
  283. $tabfield[6] = "code,libelle,type,color,position";
  284. $tabfield[7] = "code,libelle,country,accountancy_code";
  285. $tabfield[8] = "code,libelle,country_id,country".(!empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? ',position' : '');
  286. $tabfield[9] = "code,label,unicode";
  287. $tabfield[10] = "country_id,country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
  288. $tabfield[11] = "element,source,code,libelle,position";
  289. $tabfield[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
  290. $tabfield[13] = "code,libelle,type,entity";
  291. $tabfield[14] = "code,label,price,organization,country";
  292. $tabfield[15] = "code,libelle,width,height,unit";
  293. $tabfield[16] = "code,libelle,sortorder";
  294. $tabfield[17] = "code,label,accountancy_code";
  295. $tabfield[18] = "code,libelle,tracking";
  296. $tabfield[19] = "code,libelle";
  297. $tabfield[20] = "code,libelle";
  298. $tabfield[21] = "code,label,qty,type_duration,position";
  299. $tabfield[22] = "code,label";
  300. $tabfield[23] = "country_id,country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
  301. $tabfield[24] = "code,label";
  302. $tabfield[25] = "code,label";
  303. //$tabfield[26]= "code,label,short_label";
  304. $tabfield[27] = "code,libelle,picto";
  305. $tabfield[28] = "code,label,affect,delay,newbymonth,country_id,country,block_if_negative,sortorder";
  306. $tabfield[29] = "code,label,percent,position";
  307. $tabfield[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  308. //$tabfield[31]= "pcg_version,label";
  309. $tabfield[32] = "code,dayrule,year,month,day,country_id,country";
  310. $tabfield[33] = "code,label";
  311. $tabfield[34] = "code,label";
  312. $tabfield[35] = "label";
  313. $tabfield[36] = "range_ik,fk_c_exp_tax_cat";
  314. $tabfield[37] = "code,label,short_label,unit_type,scale,sortorder";
  315. $tabfield[38] = "code,label,url,icon,entity";
  316. $tabfield[39] = "code,libelle,sortorder";
  317. $tabfield[40] = "code,libelle,picto";
  318. $tabfield[41] = "code,label";
  319. $tabfield[42] = "code,label";
  320. $tabfield[43] = "code,label";
  321. $tabfield[44] = "code,label";
  322. // Edit field names for editing a record
  323. $tabfieldvalue = array();
  324. $tabfieldvalue[1] = "code,libelle,country";
  325. $tabfieldvalue[2] = "code,libelle,region"; // "code,libelle,region"
  326. $tabfieldvalue[3] = "code,libelle,country";
  327. $tabfieldvalue[4] = "code,label";
  328. $tabfieldvalue[5] = "code,label";
  329. $tabfieldvalue[6] = "code,libelle,type,color,position";
  330. $tabfieldvalue[7] = "code,libelle,country,accountancy_code";
  331. $tabfieldvalue[8] = "code,libelle,country".(!empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? ',position' : '');
  332. $tabfieldvalue[9] = "code,label,unicode";
  333. $tabfieldvalue[10] = "country,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
  334. $tabfieldvalue[11] = "element,source,code,libelle,position";
  335. $tabfieldvalue[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder";
  336. $tabfieldvalue[13] = "code,libelle,type";
  337. $tabfieldvalue[14] = "code,label,price,organization,country";
  338. $tabfieldvalue[15] = "code,libelle,width,height,unit";
  339. $tabfieldvalue[16] = "code,libelle,sortorder";
  340. $tabfieldvalue[17] = "code,label,accountancy_code";
  341. $tabfieldvalue[18] = "code,libelle,tracking";
  342. $tabfieldvalue[19] = "code,libelle";
  343. $tabfieldvalue[20] = "code,libelle";
  344. $tabfieldvalue[21] = "code,label,qty,type_duration,position";
  345. $tabfieldvalue[22] = "code,label";
  346. $tabfieldvalue[23] = "country,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
  347. $tabfieldvalue[24] = "code,label";
  348. $tabfieldvalue[25] = "code,label";
  349. //$tabfieldvalue[26]= "code,label,short_label";
  350. $tabfieldvalue[27] = "code,libelle,picto";
  351. $tabfieldvalue[28] = "code,label,affect,delay,newbymonth,country,block_if_negative,sortorder";
  352. $tabfieldvalue[29] = "code,label,percent,position";
  353. $tabfieldvalue[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  354. //$tabfieldvalue[31]= "pcg_version,label";
  355. $tabfieldvalue[32] = "code,dayrule,day,month,year,country";
  356. $tabfieldvalue[33] = "code,label";
  357. $tabfieldvalue[34] = "code,label";
  358. $tabfieldvalue[35] = "label";
  359. $tabfieldvalue[36] = "range_ik,fk_c_exp_tax_cat";
  360. $tabfieldvalue[37] = "code,label,short_label,unit_type,scale,sortorder";
  361. $tabfieldvalue[38] = "code,label,url,icon";
  362. $tabfieldvalue[39] = "code,libelle,sortorder";
  363. $tabfieldvalue[40] = "code,libelle,picto";
  364. $tabfieldvalue[41] = "code,label";
  365. $tabfieldvalue[42] = "code,label";
  366. $tabfieldvalue[43] = "code,label";
  367. $tabfieldvalue[44] = "code,label";
  368. // Field names in the table for inserting a record
  369. $tabfieldinsert = array();
  370. $tabfieldinsert[1] = "code,libelle,fk_pays";
  371. $tabfieldinsert[2] = "code_departement,nom,fk_region";
  372. $tabfieldinsert[3] = "code_region,nom,fk_pays";
  373. $tabfieldinsert[4] = "code,label";
  374. $tabfieldinsert[5] = "code,label";
  375. $tabfieldinsert[6] = "code,libelle,type,color,position";
  376. $tabfieldinsert[7] = "code,libelle,fk_pays,accountancy_code";
  377. $tabfieldinsert[8] = "code,libelle,fk_country".(!empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? ',position' : '');
  378. $tabfieldinsert[9] = "code_iso,label,unicode";
  379. $tabfieldinsert[10] = "fk_pays,code,taux,localtax1_type,localtax1,localtax2_type,localtax2,recuperableonly,accountancy_code_sell,accountancy_code_buy,note";
  380. $tabfieldinsert[11] = "element,source,code,libelle,position";
  381. $tabfieldinsert[12] = "code,libelle,libelle_facture,deposit_percent,nbjour,type_cdr,decalage,sortorder,entity";
  382. $tabfieldinsert[13] = "code,libelle,type,entity";
  383. $tabfieldinsert[14] = "code,label,price,organization,fk_pays";
  384. $tabfieldinsert[15] = "code,label,width,height,unit";
  385. $tabfieldinsert[16] = "code,label,sortorder";
  386. $tabfieldinsert[17] = "code,label,accountancy_code";
  387. $tabfieldinsert[18] = "code,libelle,tracking";
  388. $tabfieldinsert[19] = "code,libelle";
  389. $tabfieldinsert[20] = "code,libelle";
  390. $tabfieldinsert[21] = "code,label,qty,type_duration,position";
  391. $tabfieldinsert[22] = "code,label";
  392. $tabfieldinsert[23] = "fk_pays,taux,revenuestamp_type,accountancy_code_sell,accountancy_code_buy,note";
  393. $tabfieldinsert[24] = "code,label";
  394. $tabfieldinsert[25] = "code,label";
  395. //$tabfieldinsert[26]= "code,label,short_label";
  396. $tabfieldinsert[27] = "code,libelle,picto";
  397. $tabfieldinsert[28] = "code,label,affect,delay,newbymonth,fk_country,block_if_negative,sortorder";
  398. $tabfieldinsert[29] = "code,label,percent,position";
  399. $tabfieldinsert[30] = "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y";
  400. //$tabfieldinsert[31]= "pcg_version,label";
  401. //$tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
  402. $tabfieldinsert[32] = "code,dayrule,day,month,year,fk_country";
  403. $tabfieldinsert[33] = "code,label";
  404. $tabfieldinsert[34] = "code,label";
  405. $tabfieldinsert[35] = "label";
  406. $tabfieldinsert[36] = "range_ik,fk_c_exp_tax_cat";
  407. $tabfieldinsert[37] = "code,label,short_label,unit_type,scale,sortorder";
  408. $tabfieldinsert[38] = "code,label,url,icon,entity";
  409. $tabfieldinsert[39] = "code,label,sortorder";
  410. $tabfieldinsert[40] = "code,libelle,picto";
  411. $tabfieldinsert[41] = "code,label";
  412. $tabfieldinsert[42] = "code,label";
  413. $tabfieldinsert[43] = "code,label";
  414. $tabfieldinsert[44] = "code,label";
  415. // Rowid name of field depending if field is autoincrement on or off..
  416. // Use "" if id field is "rowid" and has autoincrement on
  417. // Use "nameoffield" if id field is not "rowid" or has not autoincrement on
  418. $tabrowid = array();
  419. $tabrowid[1] = "";
  420. $tabrowid[2] = "";
  421. $tabrowid[3] = "";
  422. $tabrowid[4] = "rowid";
  423. $tabrowid[5] = "rowid";
  424. $tabrowid[6] = "id";
  425. $tabrowid[7] = "id";
  426. $tabrowid[8] = "id";
  427. $tabrowid[9] = "code_iso";
  428. $tabrowid[10] = "";
  429. $tabrowid[11] = "rowid";
  430. $tabrowid[12] = "";
  431. $tabrowid[13] = "id";
  432. $tabrowid[14] = "";
  433. $tabrowid[15] = "";
  434. $tabrowid[16] = "code";
  435. $tabrowid[17] = "id";
  436. $tabrowid[18] = "rowid";
  437. $tabrowid[19] = "id";
  438. $tabrowid[20] = "";
  439. $tabrowid[21] = "rowid";
  440. $tabrowid[22] = "rowid";
  441. $tabrowid[23] = "";
  442. $tabrowid[24] = "";
  443. $tabrowid[25] = "";
  444. //$tabrowid[26]= "";
  445. $tabrowid[27] = "id";
  446. $tabrowid[28] = "";
  447. $tabrowid[29] = "";
  448. $tabrowid[30] = "";
  449. //$tabrowid[31]= "";
  450. $tabrowid[32] = "id";
  451. $tabrowid[33] = "rowid";
  452. $tabrowid[34] = "rowid";
  453. $tabrowid[35] = "";
  454. $tabrowid[36] = "";
  455. $tabrowid[37] = "";
  456. $tabrowid[38] = "";
  457. $tabrowid[39] = "code";
  458. $tabrowid[40] = "id";
  459. $tabrowid[41] = "";
  460. $tabrowid[42] = "rowid";
  461. $tabrowid[43] = "rowid";
  462. $tabrowid[44] = "rowid";
  463. // Condition to show dictionary in setup page
  464. $tabcond = array();
  465. $tabcond[1] = (!empty($conf->societe->enabled));
  466. $tabcond[2] = true;
  467. $tabcond[3] = true;
  468. $tabcond[4] = true;
  469. $tabcond[5] = (!empty($conf->societe->enabled) || !empty($conf->adherent->enabled));
  470. $tabcond[6] = !empty($conf->agenda->enabled);
  471. $tabcond[7] = !empty($conf->tax->enabled);
  472. $tabcond[8] = !empty($conf->societe->enabled);
  473. $tabcond[9] = true;
  474. $tabcond[10] = true;
  475. $tabcond[11] = (!empty($conf->societe->enabled));
  476. $tabcond[12] = (!empty($conf->commande->enabled) || !empty($conf->propal->enabled) || !empty($conf->facture->enabled) || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled) || !empty($conf->supplier_order->enabled));
  477. $tabcond[13] = (!empty($conf->commande->enabled) || !empty($conf->propal->enabled) || !empty($conf->facture->enabled) || (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_invoice->enabled) || !empty($conf->supplier_order->enabled));
  478. $tabcond[14] = (!empty($conf->product->enabled) && (!empty($conf->ecotax->enabled) || !empty($conf->global->MAIN_SHOW_ECOTAX_DICTIONNARY)));
  479. $tabcond[15] = true;
  480. $tabcond[16] = (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS));
  481. $tabcond[17] = (!empty($conf->deplacement->enabled) || !empty($conf->expensereport->enabled));
  482. $tabcond[18] = !empty($conf->expedition->enabled) || !empty($conf->reception->enabled);
  483. $tabcond[19] = !empty($conf->societe->enabled);
  484. $tabcond[20] = (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled);
  485. $tabcond[21] = !empty($conf->propal->enabled);
  486. $tabcond[22] = (!empty($conf->commande->enabled) || !empty($conf->propal->enabled));
  487. $tabcond[23] = true;
  488. $tabcond[24] = !empty($conf->resource->enabled);
  489. $tabcond[25] = !empty($conf->website->enabled);
  490. //$tabcond[26]= ! empty($conf->product->enabled);
  491. $tabcond[27] = !empty($conf->societe->enabled);
  492. $tabcond[28] = !empty($conf->holiday->enabled);
  493. $tabcond[29] = !empty($conf->projet->enabled);
  494. $tabcond[30] = !empty($conf->label->enabled);
  495. //$tabcond[31]= ! empty($conf->accounting->enabled);
  496. $tabcond[32] = (!empty($conf->holiday->enabled) || !empty($conf->hrm->enabled));
  497. $tabcond[33] = !empty($conf->hrm->enabled);
  498. $tabcond[34] = !empty($conf->hrm->enabled);
  499. $tabcond[35] = !empty($conf->expensereport->enabled) && !empty($conf->global->MAIN_USE_EXPENSE_IK);
  500. $tabcond[36] = !empty($conf->expensereport->enabled) && !empty($conf->global->MAIN_USE_EXPENSE_IK);
  501. $tabcond[37] = !empty($conf->product->enabled);
  502. $tabcond[38] = !empty($conf->socialnetworks->enabled);
  503. $tabcond[39] = (!empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES));
  504. $tabcond[40] = (!empty($conf->societe->enabled) && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES));
  505. $tabcond[41] = !empty($conf->intracommreport->enabled);
  506. $tabcond[42] = !empty($conf->product->enabled);
  507. $tabcond[43] = !empty($conf->product->enabled) && !empty($conf->productbatch->enabled) && $conf->global->MAIN_FEATURES_LEVEL >= 2;
  508. $tabcond[44] = !empty($conf->asset->enabled);
  509. // List of help for fields (no more used, help is defined into tabcomplete)
  510. $tabhelp = array();
  511. // Table to store complete informations (will replace all other table). Key is table name.
  512. $tabcomplete = array(
  513. 'c_forme_juridique'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  514. 'c_departements'=>array('picto'=>'state', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  515. 'c_regions'=>array('picto'=>'region', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  516. 'c_country'=>array('picto'=>'country', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  517. 'c_civility'=>array('picto'=>'contact', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  518. 'c_actioncomm'=>array('picto'=>'action', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'color'=>$langs->trans("ColorFormat"), 'position'=>$langs->trans("PositionIntoComboList"))),
  519. 'c_chargesociales'=>array('picto'=>'bill', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  520. 'c_typent'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"))),
  521. 'c_currencies'=>array('picto'=>'multicurrency', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'unicode'=>$langs->trans("UnicodeCurrency"))),
  522. 'c_tva'=>array('picto'=>'bill', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'taux'=>$langs->trans("SellTaxRate"), 'recuperableonly'=>$langs->trans("RecuperableOnly"), 'localtax1_type'=>$langs->trans("LocalTaxDesc"), 'localtax2_type'=>$langs->trans("LocalTaxDesc"))),
  523. 'c_type_contact'=>array('picto'=>'contact', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"))),
  524. 'c_payment_term'=>array('picto'=>'bill', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'type_cdr'=>$langs->trans("TypeCdr", $langs->transnoentitiesnoconv("NbOfDays"), $langs->transnoentitiesnoconv("Offset"), $langs->transnoentitiesnoconv("NbOfDays"), $langs->transnoentitiesnoconv("Offset")))),
  525. 'c_paiement'=>array('picto'=>'bill', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  526. 'c_ecotaxe'=>array('picto'=>'bill', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  527. 'c_paper_format'=>array('picto'=>'generic', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  528. 'c_prospectlevel'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  529. 'c_type_fees'=>array('picto'=>'trip', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  530. 'c_shipment_mode'=>array('picto'=>'shipment', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'tracking'=>$langs->trans("UrlTrackingDesc"))),
  531. 'c_effectif'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  532. 'c_input_method'=>array('picto'=>'order', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  533. 'c_input_reason'=>array('picto'=>'order', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'position'=>$langs->trans("PositionIntoComboList"))),
  534. 'c_availability'=>array('picto'=>'shipment', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  535. 'c_revenuestamp'=>array('picto'=>'bill', 'help'=>array('revenuestamp_type'=>$langs->trans('FixedOrPercent'))),
  536. 'c_type_resource'=>array('picto'=>'resource', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  537. 'c_type_container'=>array('picto'=>'website', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  538. 'c_stcomm'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'picto'=>$langs->trans("PictoHelp"))),
  539. 'c_holiday_types'=>array('picto'=>'holiday', 'help'=>array('affect'=>$langs->trans("FollowedByACounter"), 'delay'=>$langs->trans("MinimumNoticePeriod"), 'newbymonth'=>$langs->trans("NbAddedAutomatically"))),
  540. 'c_lead_status'=>array('picto'=>'project', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'percent'=>$langs->trans("OpportunityPercent"), 'position'=>$langs->trans("PositionIntoComboList"))),
  541. 'c_format_cards'=>array('picto'=>'generic', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'name'=>$langs->trans("LabelName"), 'paper_size'=>$langs->trans("LabelPaperSize"))),
  542. 'c_hrm_public_holiday'=>array('picto'=>'holiday', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'dayrule'=>"Keep empty for a date defined with month and day (most common case).<br>Use a keyword like 'easter', 'eastermonday', ... for a date predefined by complex rules.", 'country'=>$langs->trans("CountryIfSpecificToOneCountry"), 'year'=>$langs->trans("ZeroMeansEveryYear"))),
  543. 'c_hrm_department'=>array('picto'=>'hrm', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  544. 'c_hrm_function'=>array('picto'=>'hrm', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  545. 'c_exp_tax_cat'=>array('picto'=>'expensereport', 'help'=>array()),
  546. 'c_exp_tax_range'=>array('picto'=>'expensereport', 'help'=>array('range_ik'=>$langs->trans('PrevRangeToThisRange'))),
  547. 'c_units'=>array('picto'=>'product', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'unit_type' => $langs->trans('Measuringtype_durationDesc'), 'scale' => $langs->trans('MeasuringScaleDesc'))),
  548. 'c_socialnetworks'=>array('picto'=>'share-alt', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'url' => $langs->trans('UrlSocialNetworksDesc'), 'icon' => $langs->trans('FafaIconSocialNetworksDesc'))),
  549. 'c_prospectcontactlevel'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  550. 'c_stcommcontact'=>array('picto'=>'company', 'help'=>array('code'=>$langs->trans("EnterAnyCode"), 'picto'=>$langs->trans("PictoHelp"))),
  551. 'c_transport_mode'=>array('picto'=>'incoterm', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  552. 'c_product_nature'=>array('picto'=>'product', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  553. 'c_productbatch_qcstatus'=>array('picto'=>'lot', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  554. 'c_asset_disposal_type'=>array('picto'=>'asset', 'help'=>array('code'=>$langs->trans("EnterAnyCode"))),
  555. );
  556. // Complete all arrays with entries found into modules
  557. complete_dictionary_with_modules($taborder, $tabname, $tablib, $tabsql, $tabsqlsort, $tabfield, $tabfieldvalue, $tabfieldinsert, $tabrowid, $tabcond, $tabhelp, $tabcomplete);
  558. // Complete the table $tabcomplete
  559. $i = 0;
  560. foreach ($tabcomplete as $key => $value) {
  561. $i++;
  562. $tabcomplete[$key]['id'] = $i;
  563. $tabcomplete[$key]['cond'] = $tabcond[$i];
  564. $tabcomplete[$key]['rowid'] = $tabrowid[$i];
  565. $tabcomplete[$key]['fieldinsert'] = $tabfieldinsert[$i];
  566. $tabcomplete[$key]['fieldvalue'] = $tabfieldvalue[$i];
  567. $tabcomplete[$key]['lib'] = $tablib[$i];
  568. $tabcomplete[$key]['sql'] = $tabsql[$i];
  569. $tabcomplete[$key]['sqlsort'] = $tabsqlsort[$i];
  570. $tabcomplete[$key]['field'] = $tabfield[$i];
  571. }
  572. $keytable = '';
  573. if ($id > 0) {
  574. $arrayofkeys = array_keys($tabcomplete);
  575. $keytable = $arrayofkeys[$id - 1];
  576. }
  577. // Defaut sortorder
  578. if (empty($sortfield)) {
  579. $tmp1 = explode(',', empty($tabcomplete[$keytable]['sqlsort']) ? '' : $tabcomplete[$keytable]['sqlsort']);
  580. $tmp2 = explode(' ', $tmp1[0]);
  581. $sortfield = preg_replace('/^.*\./', '', $tmp2[0]);
  582. $sortorder = $tmp2[1];
  583. //var_dump($sortfield);var_dump($sortorder);
  584. }
  585. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  586. $elementList = array();
  587. $sourceList = array();
  588. if ($id == 11) {
  589. $elementList = array(
  590. '' => '',
  591. 'societe' => $langs->trans('ThirdParty'),
  592. // 'proposal' => $langs->trans('Proposal'),
  593. // 'order' => $langs->trans('Order'),
  594. // 'invoice' => $langs->trans('Bill'),
  595. 'supplier_proposal' => $langs->trans('SupplierProposal'),
  596. 'order_supplier' => $langs->trans('SupplierOrder'),
  597. 'invoice_supplier' => $langs->trans('SupplierBill'),
  598. // 'intervention' => $langs->trans('InterventionCard'),
  599. // 'contract' => $langs->trans('Contract'),
  600. 'project' => $langs->trans('Project'),
  601. 'project_task' => $langs->trans('Task'),
  602. 'ticket' => $langs->trans('Ticket'),
  603. 'agenda' => $langs->trans('Agenda'),
  604. 'dolresource' => $langs->trans('Resource'),
  605. // old deprecated
  606. 'propal' => $langs->trans('Proposal'),
  607. 'commande' => $langs->trans('Order'),
  608. 'facture' => $langs->trans('Bill'),
  609. 'fichinter' => $langs->trans('InterventionCard'),
  610. 'contrat' => $langs->trans('Contract'),
  611. );
  612. if (!empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) {
  613. $elementList["societe"] = $langs->trans('ThirdParty');
  614. }
  615. complete_elementList_with_modules($elementList);
  616. asort($elementList);
  617. $sourceList = array(
  618. 'internal' => $langs->trans('Internal'),
  619. 'external' => $langs->trans('External')
  620. );
  621. }
  622. // Define localtax_typeList (used for dictionary "llx_c_tva")
  623. $localtax_typeList = array(
  624. "0" => $langs->trans("No"),
  625. "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
  626. "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
  627. "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
  628. "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
  629. "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
  630. "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
  631. );
  632. /*
  633. * Actions
  634. */
  635. $object = new stdClass();
  636. $parameters = array(
  637. 'id' =>$id,
  638. 'rowid' =>$rowid,
  639. 'code' =>$code,
  640. 'confirm' =>$confirm,
  641. 'entity' =>$entity,
  642. 'taborder' =>$taborder,
  643. 'tabname' =>$tabname,
  644. 'tablib' =>$tablib,
  645. 'tabsql' =>$tabsql,
  646. 'tabsqlsort' =>$tabsqlsort,
  647. 'tabfield' =>$tabfield,
  648. 'tabfieldvalue' =>$tabfieldvalue,
  649. 'tabfieldinsert'=>$tabfieldinsert,
  650. 'tabrowid' =>$tabrowid,
  651. 'tabcond' =>$tabcond,
  652. 'tabhelp' =>$tabhelp,
  653. 'tabcomplete' =>$tabcomplete
  654. );
  655. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  656. if ($reshook < 0) {
  657. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  658. }
  659. if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
  660. $search_country_id = '';
  661. $search_code = '';
  662. }
  663. if (empty($reshook)) {
  664. // Actions add or modify an entry into a dictionary
  665. if (GETPOST('actionadd') || GETPOST('actionmodify')) {
  666. $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
  667. $listfieldinsert = explode(',', $tabfieldinsert[$id]);
  668. $listfieldmodify = explode(',', $tabfieldinsert[$id]);
  669. $listfieldvalue = explode(',', $tabfieldvalue[$id]);
  670. // Check that all mandatory fields are filled
  671. $ok = 1;
  672. foreach ($listfield as $f => $value) {
  673. // Discard check of mandatory fields for country for some tables
  674. if ($value == 'country_id' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryVAT', 'DictionaryRegion', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp', 'DictionaryAccountancysystem', 'DictionaryAccountancyCategory'))) {
  675. continue; // For some pages, country is not mandatory
  676. }
  677. if ($value == 'country' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryCanton', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) {
  678. continue; // For some pages, country is not mandatory
  679. }
  680. // Discard check of mandatory fiedls for other fields
  681. if ($value == 'localtax1' && !GETPOST('localtax1_type')) {
  682. continue;
  683. }
  684. if ($value == 'localtax2' && !GETPOST('localtax2_type')) {
  685. continue;
  686. }
  687. if ($value == 'color' && !GETPOST('color')) {
  688. continue;
  689. }
  690. if ($value == 'formula' && !GETPOST('formula')) {
  691. continue;
  692. }
  693. if ($value == 'dayrule' && !GETPOST('dayrule')) {
  694. continue;
  695. }
  696. if ($value == 'sortorder') {
  697. continue; // For a column name 'sortorder', we use the field name 'position'
  698. }
  699. if ((!GETPOSTISSET($value) || GETPOST($value) == '')
  700. && (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto', 'deposit_percent')) // Fields that are not mandatory
  701. && ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
  702. )
  703. ) {
  704. $ok = 0;
  705. $fieldnamekey = $value;
  706. // We take translate key of field
  707. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
  708. $fieldnamekey = 'Label';
  709. }
  710. if ($fieldnamekey == 'libelle_facture') {
  711. $fieldnamekey = 'LabelOnDocuments';
  712. }
  713. if ($fieldnamekey == 'deposit_percent') {
  714. $fieldnamekey = 'DepositPercent';
  715. }
  716. if ($fieldnamekey == 'nbjour') {
  717. $fieldnamekey = 'NbOfDays';
  718. }
  719. if ($fieldnamekey == 'decalage') {
  720. $fieldnamekey = 'Offset';
  721. }
  722. if ($fieldnamekey == 'module') {
  723. $fieldnamekey = 'Module';
  724. }
  725. if ($fieldnamekey == 'code') {
  726. $fieldnamekey = 'Code';
  727. }
  728. if ($fieldnamekey == 'note') {
  729. $fieldnamekey = 'Note';
  730. }
  731. if ($fieldnamekey == 'taux') {
  732. $fieldnamekey = 'Rate';
  733. }
  734. if ($fieldnamekey == 'type') {
  735. $fieldnamekey = 'Type';
  736. }
  737. if ($fieldnamekey == 'position') {
  738. $fieldnamekey = 'Position';
  739. }
  740. if ($fieldnamekey == 'unicode') {
  741. $fieldnamekey = 'Unicode';
  742. }
  743. if ($fieldnamekey == 'deductible') {
  744. $fieldnamekey = 'Deductible';
  745. }
  746. if ($fieldnamekey == 'sortorder') {
  747. $fieldnamekey = 'SortOrder';
  748. }
  749. if ($fieldnamekey == 'category_type') {
  750. $fieldnamekey = 'Calculated';
  751. }
  752. if ($fieldnamekey == 'revenuestamp_type') {
  753. $fieldnamekey = 'TypeOfRevenueStamp';
  754. }
  755. if ($fieldnamekey == 'use_default') {
  756. $fieldnamekey = 'UseByDefault';
  757. }
  758. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  759. }
  760. }
  761. // Other checks
  762. if (GETPOST('actionadd') && $tabname[$id] == "c_actioncomm" && GETPOSTISSET("type") && in_array(GETPOST("type"), array('system', 'systemauto'))) {
  763. $ok = 0;
  764. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  765. }
  766. if (GETPOSTISSET("code")) {
  767. if (GETPOST("code") == '0') {
  768. $ok = 0;
  769. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  770. }
  771. }
  772. if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != 2)) {
  773. if (in_array($tablib[$id], array('DictionaryCompanyType', 'DictionaryHolidayTypes'))) { // Field country is no mandatory for such dictionaries
  774. $_POST["country"] = '';
  775. } else {
  776. $ok = 0;
  777. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
  778. }
  779. }
  780. if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code"))) {
  781. $ok = 0;
  782. setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
  783. }
  784. // Clean some parameters
  785. if ((GETPOST("localtax1_type") || (GETPOST('localtax1_type') == '0')) && !GETPOST("localtax1")) {
  786. $_POST["localtax1"] = '0'; // If empty, we force to 0
  787. }
  788. if ((GETPOST("localtax2_type") || (GETPOST('localtax2_type') == '0')) && !GETPOST("localtax2")) {
  789. $_POST["localtax2"] = '0'; // If empty, we force to 0
  790. }
  791. if (GETPOST("accountancy_code") <= 0) {
  792. $_POST["accountancy_code"] = ''; // If empty, we force to null
  793. }
  794. if (GETPOST("accountancy_code_sell") <= 0) {
  795. $_POST["accountancy_code_sell"] = ''; // If empty, we force to null
  796. }
  797. if (GETPOST("accountancy_code_buy") <= 0) {
  798. $_POST["accountancy_code_buy"] = ''; // If empty, we force to null
  799. }
  800. if ($id == 10 && GETPOSTISSET("code")) { // Spaces are not allowed into code for tax dictionary
  801. $_POST["code"] = preg_replace('/[^a-zA-Z0-9\-\+]/', '', GETPOST("code"));
  802. }
  803. // If check ok and action add, add the line
  804. if ($ok && GETPOST('actionadd')) {
  805. if ($tabrowid[$id]) {
  806. // Get free id for insert
  807. $newid = 0;
  808. $sql = "SELECT MAX(".$tabrowid[$id].") as newid FROM ".MAIN_DB_PREFIX.$tabname[$id];
  809. $result = $db->query($sql);
  810. if ($result) {
  811. $obj = $db->fetch_object($result);
  812. $newid = ($obj->newid + 1);
  813. } else {
  814. dol_print_error($db);
  815. }
  816. }
  817. // Add new entry
  818. $sql = "INSERT INTO ".MAIN_DB_PREFIX.$tabname[$id]." (";
  819. // List of fields
  820. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  821. $sql .= $tabrowid[$id].",";
  822. }
  823. $sql .= $tabfieldinsert[$id];
  824. $sql .= ",active)";
  825. $sql .= " VALUES(";
  826. // List of values
  827. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  828. $sql .= $newid.",";
  829. }
  830. $i = 0;
  831. foreach ($listfieldinsert as $f => $value) {
  832. $keycode = $listfieldvalue[$i];
  833. if (empty($keycode)) {
  834. $keycode = $value;
  835. }
  836. if ($value == 'price' || preg_match('/^amount/i', $value)) {
  837. $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
  838. } elseif ($value == 'taux' || $value == 'localtax1') {
  839. $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
  840. } elseif ($value == 'entity') {
  841. $_POST[$keycode] = getEntity($tabname[$id]);
  842. }
  843. if ($i) {
  844. $sql .= ",";
  845. }
  846. if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
  847. $sql .= (int) GETPOST('position', 'int');
  848. } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == 10)) {
  849. $sql .= "null"; // For vat, we want/accept code = ''
  850. } elseif ($keycode == 'content') {
  851. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  852. } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
  853. $sql .= (int) GETPOST($keycode, 'int');
  854. } else {
  855. $sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
  856. }
  857. $i++;
  858. }
  859. $sql .= ",1)";
  860. dol_syslog("actionadd", LOG_DEBUG);
  861. $resql = $db->query($sql);
  862. if ($resql) { // Add is ok
  863. setEventMessages($langs->transnoentities("RecordCreatedSuccessfully"), null, 'mesgs');
  864. // Clean $_POST array, we keep only id of dictionary
  865. if ($id == 10 && GETPOST('country', 'int') > 0) {
  866. $search_country_id = GETPOST('country', 'int');
  867. }
  868. $_POST = array('id'=>$id);
  869. } else {
  870. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  871. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  872. } else {
  873. dol_print_error($db);
  874. }
  875. }
  876. }
  877. // If verif ok and action modify, modify the line
  878. if ($ok && GETPOST('actionmodify')) {
  879. if ($tabrowid[$id]) {
  880. $rowidcol = $tabrowid[$id];
  881. } else {
  882. $rowidcol = "rowid";
  883. }
  884. // Modify entry
  885. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET ";
  886. // Modifie valeur des champs
  887. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
  888. $sql .= $tabrowid[$id]."=";
  889. $sql .= "'".$db->escape($rowid)."', ";
  890. }
  891. $i = 0;
  892. foreach ($listfieldmodify as $field) {
  893. $keycode = $listfieldvalue[$i];
  894. if (empty($keycode)) {
  895. $keycode = $field;
  896. }
  897. if ($field == 'price' || preg_match('/^amount/i', $field)) {
  898. $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
  899. } elseif ($field == 'taux' || $field == 'localtax1') {
  900. $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
  901. } elseif ($field == 'entity') {
  902. $_POST[$keycode] = getEntity($tabname[$id]);
  903. }
  904. if ($i) {
  905. $sql .= ",";
  906. }
  907. $sql .= $field."=";
  908. if ($listfieldvalue[$i] == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
  909. $sql .= (int) GETPOST('position', 'int');
  910. } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == 10)) {
  911. $sql .= "null"; // For vat, we want/accept code = ''
  912. } elseif ($keycode == 'content') {
  913. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  914. } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
  915. $sql .= (int) GETPOST($keycode, 'int');
  916. } else {
  917. $sql .= "'".$db->escape(GETPOST($keycode, 'nohtml'))."'";
  918. }
  919. $i++;
  920. }
  921. if (in_array($rowidcol, array('code', 'code_iso'))) {
  922. $sql .= " WHERE ".$rowidcol." = '".$db->escape($rowid)."'";
  923. } else {
  924. $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
  925. }
  926. if (in_array('entity', $listfieldmodify)) {
  927. $sql .= " AND entity = ".((int) getEntity($tabname[$id], 0));
  928. }
  929. dol_syslog("actionmodify", LOG_DEBUG);
  930. //print $sql;
  931. $resql = $db->query($sql);
  932. if (!$resql) {
  933. setEventMessages($db->error(), null, 'errors');
  934. }
  935. }
  936. }
  937. if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
  938. if ($tabrowid[$id]) {
  939. $rowidcol = $tabrowid[$id];
  940. } else {
  941. $rowidcol = "rowid";
  942. }
  943. $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabname[$id]." WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  944. dol_syslog("delete", LOG_DEBUG);
  945. $result = $db->query($sql);
  946. if (!$result) {
  947. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
  948. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  949. } else {
  950. dol_print_error($db);
  951. }
  952. }
  953. }
  954. // activate
  955. if ($action == $acts[0]) {
  956. if ($tabrowid[$id]) {
  957. $rowidcol = $tabrowid[$id];
  958. } else {
  959. $rowidcol = "rowid";
  960. }
  961. if ($rowid) {
  962. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET active = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  963. } elseif ($code) {
  964. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET active = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  965. }
  966. $result = $db->query($sql);
  967. if (!$result) {
  968. dol_print_error($db);
  969. }
  970. }
  971. // disable
  972. if ($action == $acts[1]) {
  973. if ($tabrowid[$id]) {
  974. $rowidcol = $tabrowid[$id];
  975. } else {
  976. $rowidcol = "rowid";
  977. }
  978. if ($rowid) {
  979. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET active = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  980. } elseif ($code) {
  981. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET active = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  982. }
  983. $result = $db->query($sql);
  984. if (!$result) {
  985. dol_print_error($db);
  986. }
  987. }
  988. // favorite
  989. if ($action == 'activate_favorite') {
  990. if ($tabrowid[$id]) {
  991. $rowidcol = $tabrowid[$id];
  992. } else {
  993. $rowidcol = "rowid";
  994. }
  995. if ($rowid) {
  996. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  997. } elseif ($code) {
  998. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET favorite = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  999. }
  1000. $result = $db->query($sql);
  1001. if (!$result) {
  1002. dol_print_error($db);
  1003. }
  1004. }
  1005. // disable favorite
  1006. if ($action == 'disable_favorite') {
  1007. if ($tabrowid[$id]) {
  1008. $rowidcol = $tabrowid[$id];
  1009. } else {
  1010. $rowidcol = "rowid";
  1011. }
  1012. if ($rowid) {
  1013. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1014. } elseif ($code) {
  1015. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET favorite = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1016. }
  1017. $result = $db->query($sql);
  1018. if (!$result) {
  1019. dol_print_error($db);
  1020. }
  1021. }
  1022. // Is in EEC - Activate
  1023. if ($action == 'activate_eec') {
  1024. if ($tabrowid[$id]) {
  1025. $rowidcol = $tabrowid[$id];
  1026. } else {
  1027. $rowidcol = "rowid";
  1028. }
  1029. if ($rowid) {
  1030. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET eec = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1031. } elseif ($code) {
  1032. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET eec = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1033. }
  1034. $result = $db->query($sql);
  1035. if (!$result) {
  1036. dol_print_error($db);
  1037. }
  1038. }
  1039. // Is in EEC - Disable
  1040. if ($action == 'disable_eec') {
  1041. if ($tabrowid[$id]) {
  1042. $rowidcol = $tabrowid[$id];
  1043. } else {
  1044. $rowidcol = "rowid";
  1045. }
  1046. if ($rowid) {
  1047. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET eec = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1048. } elseif ($code) {
  1049. $sql = "UPDATE ".MAIN_DB_PREFIX.$tabname[$id]." SET eec = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1050. }
  1051. $result = $db->query($sql);
  1052. if (!$result) {
  1053. dol_print_error($db);
  1054. }
  1055. }
  1056. }
  1057. /*
  1058. * View
  1059. */
  1060. $form = new Form($db);
  1061. $formadmin = new FormAdmin($db);
  1062. $title = $langs->trans("DictionarySetup");
  1063. llxHeader('', $title);
  1064. $linkback = '';
  1065. if ($id) {
  1066. $title .= ' - '.$langs->trans($tablib[$id]);
  1067. $linkback = '<a href="'.$_SERVER['PHP_SELF'].'">'.$langs->trans("BackToDictionaryList").'</a>';
  1068. }
  1069. $titlepicto = 'title_setup';
  1070. if ($id == 10 && GETPOST('from') == 'accountancy') {
  1071. $title = $langs->trans("MenuVatAccounts");
  1072. $titlepicto = 'accountancy';
  1073. }
  1074. if ($id == 7 && GETPOST('from') == 'accountancy') {
  1075. $title = $langs->trans("MenuTaxAccounts");
  1076. $titlepicto = 'accountancy';
  1077. }
  1078. print load_fiche_titre($title, $linkback, $titlepicto);
  1079. if (empty($id)) {
  1080. print '<span class="opacitymedium">'.$langs->trans("DictionaryDesc");
  1081. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  1082. print '</span><br>';
  1083. }
  1084. $param = '&id='.urlencode($id);
  1085. if ($search_country_id > 0) {
  1086. $param .= '&search_country_id='.urlencode($search_country_id);
  1087. }
  1088. if ($search_code != '') {
  1089. $param .= '&search_code='.urlencode($search_country_id);
  1090. }
  1091. if ($entity != '') {
  1092. $param .= '&entity='.(int) $entity;
  1093. }
  1094. $paramwithsearch = $param;
  1095. if ($sortorder) {
  1096. $paramwithsearch .= '&sortorder='.urlencode($sortorder);
  1097. }
  1098. if ($sortfield) {
  1099. $paramwithsearch .= '&sortfield='.urlencode($sortfield);
  1100. }
  1101. if (GETPOST('from')) {
  1102. $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
  1103. }
  1104. // Confirmation of the deletion of the line
  1105. if ($action == 'delete') {
  1106. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'rowid='.urlencode($rowid).'&code='.urlencode($code).$paramwithsearch, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
  1107. }
  1108. //var_dump($elementList);
  1109. /*
  1110. * Show a dictionary
  1111. */
  1112. if ($id > 0) {
  1113. // Complete search values request with sort criteria
  1114. $sql = $tabsql[$id];
  1115. if (!preg_match('/ WHERE /', $sql)) {
  1116. $sql .= " WHERE 1 = 1";
  1117. }
  1118. if ($search_country_id > 0) {
  1119. $sql .= " AND c.rowid = ".((int) $search_country_id);
  1120. }
  1121. if ($search_code != '' && $id == 9) {
  1122. $sql .= natural_search("code_iso", $search_code);
  1123. } elseif ($search_code != '' && $id == 28) {
  1124. $sql .= natural_search("h.code", $search_code);
  1125. } elseif ($search_code != '' && $id == 32) {
  1126. $sql .= natural_search("a.code", $search_code);
  1127. } elseif ($search_code != '' && $id == 3) {
  1128. $sql .= natural_search("r.code_region", $search_code);
  1129. } elseif ($search_code != '' && $id == 7) {
  1130. $sql .= natural_search("a.code", $search_code);
  1131. } elseif ($search_code != '' && $id == 10) {
  1132. $sql .= natural_search("t.code", $search_code);
  1133. } elseif ($search_code != '' && $id != 9) {
  1134. $sql .= natural_search("code", $search_code);
  1135. }
  1136. if ($sortfield) {
  1137. // If sort order is "country", we use country_code instead
  1138. if ($sortfield == 'country') {
  1139. $sortfield = 'country_code';
  1140. }
  1141. $sql .= $db->order($sortfield, $sortorder);
  1142. $sql .= ", ";
  1143. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  1144. $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i', '', $tabsqlsort[$id]);
  1145. $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.',/i', '', $tabsqlsort[$id]);
  1146. } else {
  1147. $sql .= " ORDER BY ";
  1148. }
  1149. $sql .= $tabsqlsort[$id];
  1150. $sql .= $db->plimit($listlimit + 1, $offset);
  1151. //print $sql;
  1152. if (empty($tabfield[$id])) {
  1153. dol_print_error($db, 'The table with id '.$id.' has no array tabfield defined');
  1154. exit;
  1155. }
  1156. $fieldlist = explode(',', $tabfield[$id]);
  1157. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  1158. print '<input type="hidden" name="token" value="'.newToken().'">';
  1159. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  1160. if ($id == 10 && empty($conf->global->FACTURE_TVAOPTION)) {
  1161. print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation")));
  1162. print "<br>\n";
  1163. }
  1164. // Form to add a new line
  1165. if ($tabname[$id]) {
  1166. $withentity = null;
  1167. $fieldlist = explode(',', $tabfield[$id]);
  1168. print '<div class="div-table-responsive-no-min">';
  1169. print '<table class="noborder centpercent">';
  1170. // Line for title
  1171. print '<!-- line title to add new entry -->';
  1172. $tdsoffields = '<tr class="liste_titre">';
  1173. foreach ($fieldlist as $field => $value) {
  1174. if ($value == 'entity') {
  1175. $withentity = getEntity($tabname[$id]);
  1176. continue;
  1177. }
  1178. // Define field friendly name from its technical name
  1179. $valuetoshow = ucfirst($value); // Par defaut
  1180. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  1181. $class = '';
  1182. if ($value == 'pos') {
  1183. $valuetoshow = $langs->trans("Position"); $class = 'right';
  1184. }
  1185. if ($value == 'source') {
  1186. $valuetoshow = $langs->trans("Contact");
  1187. }
  1188. if ($value == 'price') {
  1189. $valuetoshow = $langs->trans("PriceUHT");
  1190. }
  1191. if ($value == 'taux') {
  1192. if ($tabname[$id] != "c_revenuestamp") {
  1193. $valuetoshow = $langs->trans("Rate");
  1194. } else {
  1195. $valuetoshow = $langs->trans("Amount");
  1196. }
  1197. $class = 'center';
  1198. }
  1199. if ($value == 'localtax1_type') {
  1200. $valuetoshow = $langs->trans("UseLocalTax")." 2"; $class = "center"; $sortable = 0;
  1201. }
  1202. if ($value == 'localtax1') {
  1203. $valuetoshow = $langs->trans("RateOfTaxN", '2'); $class = "center";
  1204. }
  1205. if ($value == 'localtax2_type') {
  1206. $valuetoshow = $langs->trans("UseLocalTax")." 3"; $class = "center"; $sortable = 0;
  1207. }
  1208. if ($value == 'localtax2') {
  1209. $valuetoshow = $langs->trans("RateOfTaxN", '3'); $class = "center";
  1210. }
  1211. if ($value == 'organization') {
  1212. $valuetoshow = $langs->trans("Organization");
  1213. }
  1214. if ($value == 'lang') {
  1215. $valuetoshow = $langs->trans("Language");
  1216. }
  1217. if ($value == 'type') {
  1218. if ($tabname[$id] == "c_paiement") {
  1219. $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
  1220. } else {
  1221. $valuetoshow = $langs->trans("Type");
  1222. }
  1223. }
  1224. if ($value == 'code') {
  1225. $valuetoshow = $langs->trans("Code"); $class = 'maxwidth100';
  1226. }
  1227. if ($value == 'libelle' || $value == 'label') {
  1228. $valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
  1229. }
  1230. if ($value == 'libelle_facture') {
  1231. $valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
  1232. }
  1233. if ($value == 'deposit_percent') {
  1234. $valuetoshow = $langs->trans('DepositPercent');
  1235. $class = 'right';
  1236. }
  1237. if ($value == 'country') {
  1238. if (in_array('region_id', $fieldlist)) {
  1239. print '<td>&nbsp;</td>'; continue;
  1240. } // For region page, we do not show the country input
  1241. $valuetoshow = $langs->trans("Country");
  1242. }
  1243. if ($value == 'recuperableonly') {
  1244. $valuetoshow = $langs->trans("NPR"); $class = "center";
  1245. }
  1246. if ($value == 'nbjour') {
  1247. $valuetoshow = $langs->trans("NbOfDays");
  1248. $class = 'right';
  1249. }
  1250. if ($value == 'type_cdr') {
  1251. $valuetoshow = $langs->trans("AtEndOfMonth"); $class = "center";
  1252. }
  1253. if ($value == 'decalage') {
  1254. $valuetoshow = $langs->trans("Offset");
  1255. $class = 'right';
  1256. }
  1257. if ($value == 'width' || $value == 'nx') {
  1258. $valuetoshow = $langs->trans("Width");
  1259. }
  1260. if ($value == 'height' || $value == 'ny') {
  1261. $valuetoshow = $langs->trans("Height");
  1262. }
  1263. if ($value == 'unit' || $value == 'metric') {
  1264. $valuetoshow = $langs->trans("MeasuringUnit");
  1265. }
  1266. if ($value == 'region_id' || $value == 'country_id') {
  1267. $valuetoshow = '';
  1268. }
  1269. if ($value == 'accountancy_code') {
  1270. $valuetoshow = $langs->trans("AccountancyCode");
  1271. }
  1272. if ($value == 'accountancy_code_sell') {
  1273. $valuetoshow = $langs->trans("AccountancyCodeSell");
  1274. }
  1275. if ($value == 'accountancy_code_buy') {
  1276. $valuetoshow = $langs->trans("AccountancyCodeBuy");
  1277. }
  1278. if ($value == 'pcg_version' || $value == 'fk_pcg_version') {
  1279. $valuetoshow = $langs->trans("Pcg_version");
  1280. }
  1281. if ($value == 'account_parent') {
  1282. $valuetoshow = $langs->trans("Accountparent");
  1283. }
  1284. if ($value == 'pcg_type') {
  1285. $valuetoshow = $langs->trans("Pcg_type");
  1286. }
  1287. if ($value == 'pcg_subtype') {
  1288. $valuetoshow = $langs->trans("Pcg_subtype");
  1289. }
  1290. if ($value == 'sortorder') {
  1291. $valuetoshow = $langs->trans("SortOrder");
  1292. $class = 'center';
  1293. }
  1294. if ($value == 'short_label') {
  1295. $valuetoshow = $langs->trans("ShortLabel");
  1296. }
  1297. if ($value == 'fk_parent') {
  1298. $valuetoshow = $langs->trans("ParentID"); $class = 'center';
  1299. }
  1300. if ($value == 'range_account') {
  1301. $valuetoshow = $langs->trans("Range");
  1302. }
  1303. if ($value == 'sens') {
  1304. $valuetoshow = $langs->trans("Sens");
  1305. }
  1306. if ($value == 'category_type') {
  1307. $valuetoshow = $langs->trans("Calculated");
  1308. }
  1309. if ($value == 'formula') {
  1310. $valuetoshow = $langs->trans("Formula");
  1311. }
  1312. if ($value == 'paper_size') {
  1313. $valuetoshow = $langs->trans("PaperSize");
  1314. }
  1315. if ($value == 'orientation') {
  1316. $valuetoshow = $langs->trans("Orientation");
  1317. }
  1318. if ($value == 'leftmargin') {
  1319. $valuetoshow = $langs->trans("LeftMargin");
  1320. }
  1321. if ($value == 'topmargin') {
  1322. $valuetoshow = $langs->trans("TopMargin");
  1323. }
  1324. if ($value == 'spacex') {
  1325. $valuetoshow = $langs->trans("SpaceX");
  1326. }
  1327. if ($value == 'spacey') {
  1328. $valuetoshow = $langs->trans("SpaceY");
  1329. }
  1330. if ($value == 'font_size') {
  1331. $valuetoshow = $langs->trans("FontSize");
  1332. }
  1333. if ($value == 'custom_x') {
  1334. $valuetoshow = $langs->trans("CustomX");
  1335. }
  1336. if ($value == 'custom_y') {
  1337. $valuetoshow = $langs->trans("CustomY");
  1338. }
  1339. if ($value == 'percent') {
  1340. $valuetoshow = $langs->trans("Percentage");
  1341. }
  1342. if ($value == 'affect') {
  1343. $valuetoshow = $langs->trans("WithCounter");
  1344. }
  1345. if ($value == 'delay') {
  1346. $valuetoshow = $langs->trans("NoticePeriod");
  1347. }
  1348. if ($value == 'newbymonth') {
  1349. $valuetoshow = $langs->trans("NewByMonth");
  1350. }
  1351. if ($value == 'fk_tva') {
  1352. $valuetoshow = $langs->trans("VAT");
  1353. }
  1354. if ($value == 'range_ik') {
  1355. $valuetoshow = $langs->trans("RangeIk");
  1356. }
  1357. if ($value == 'fk_c_exp_tax_cat') {
  1358. $valuetoshow = $langs->trans("CarCategory");
  1359. }
  1360. if ($value == 'revenuestamp_type') {
  1361. $valuetoshow = $langs->trans('TypeOfRevenueStamp');
  1362. }
  1363. if ($value == 'use_default') {
  1364. $valuetoshow = $langs->trans('Default'); $class = 'center';
  1365. }
  1366. if ($value == 'unit_type') {
  1367. $valuetoshow = $langs->trans('TypeOfUnit');
  1368. }
  1369. if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
  1370. $valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center';
  1371. }
  1372. if ($value == 'block_if_negative') {
  1373. $valuetoshow = $langs->trans('BlockHolidayIfNegative');
  1374. }
  1375. if ($value == 'type_duration') {
  1376. $valuetoshow = $langs->trans('Unit');
  1377. }
  1378. if ($id == 2) { // Special case for state page
  1379. if ($value == 'region_id') {
  1380. $valuetoshow = '&nbsp;'; $showfield = 1;
  1381. }
  1382. if ($value == 'region') {
  1383. $valuetoshow = $langs->trans("Country").'/'.$langs->trans("Region"); $showfield = 1;
  1384. }
  1385. }
  1386. if ($valuetoshow != '') {
  1387. $tdsoffields .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
  1388. if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
  1389. $tdsoffields .= '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  1390. } elseif (!empty($tabhelp[$id][$value])) {
  1391. $tdsoffields .= $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
  1392. } else {
  1393. $tdsoffields .= $valuetoshow;
  1394. }
  1395. $tdsoffields .= '</th>';
  1396. }
  1397. }
  1398. if ($id == 4) {
  1399. $tdsoffields .= '<th></th>';
  1400. $tdsoffields .= '<th></th>';
  1401. }
  1402. $tdsoffields .= '<th>';
  1403. $tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
  1404. if (!is_null($withentity)) {
  1405. $tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
  1406. }
  1407. $tdsoffields .= '</th>';
  1408. $tdsoffields .= '<th style="min-width: 26px;"></th>';
  1409. $tdsoffields .= '<th style="min-width: 26px;"></th>';
  1410. $tdsoffields .= '</tr>';
  1411. print $tdsoffields;
  1412. // Line to enter new values
  1413. print '<!-- line input to add new entry -->';
  1414. print '<tr class="oddeven nodrag nodrop nohover">';
  1415. $obj = new stdClass();
  1416. // If data was already input, we define them in obj to populate input fields.
  1417. if (GETPOST('actionadd')) {
  1418. foreach ($fieldlist as $key => $val) {
  1419. if (GETPOST($val) != '') {
  1420. $obj->$val = GETPOST($val);
  1421. }
  1422. }
  1423. }
  1424. $tmpaction = 'create';
  1425. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1426. $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1427. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1428. if ($id == 3) {
  1429. unset($fieldlist[2]); // Remove field ??? if dictionary Regions
  1430. }
  1431. if (empty($reshook)) {
  1432. fieldList($fieldlist, $obj, $tabname[$id], 'add');
  1433. }
  1434. if ($id == 4) {
  1435. print '<td></td>';
  1436. print '<td></td>';
  1437. }
  1438. print '<td colspan="3" class="center">';
  1439. if ($action != 'edit') {
  1440. print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
  1441. }
  1442. print '</td>';
  1443. print "</tr>";
  1444. print '</table>';
  1445. print '</div>';
  1446. }
  1447. print '</form>';
  1448. print '<br>';
  1449. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  1450. print '<input type="hidden" name="token" value="'.newToken().'">';
  1451. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  1452. // List of available record in database
  1453. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  1454. $resql = $db->query($sql);
  1455. if ($resql) {
  1456. $num = $db->num_rows($resql);
  1457. $i = 0;
  1458. // There is several pages
  1459. if ($num > $listlimit || $page) {
  1460. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
  1461. print '<div class="clearboth"></div>';
  1462. }
  1463. print '<div class="div-table-responsive">';
  1464. print '<table class="noborder centpercent">';
  1465. // Title line with search input fields
  1466. print '<!-- line title to search record -->'."\n";
  1467. print '<tr class="liste_titre_filter">';
  1468. $filterfound = 0;
  1469. foreach ($fieldlist as $field => $value) {
  1470. if ($value == 'entity') {
  1471. continue;
  1472. }
  1473. $showfield = 1; // By default
  1474. if ($value == 'region_id' || $value == 'country_id') {
  1475. $showfield = 0;
  1476. }
  1477. if ($showfield) {
  1478. if ($value == 'country') {
  1479. print '<td class="liste_titre">';
  1480. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
  1481. print '</td>';
  1482. $filterfound++;
  1483. } elseif ($value == 'code') {
  1484. print '<td class="liste_titre">';
  1485. print '<input type="text" class="maxwidth100" name="search_code" value="'.dol_escape_htmltag($search_code).'">';
  1486. print '</td>';
  1487. $filterfound++;
  1488. } else {
  1489. print '<td class="liste_titre">';
  1490. print '</td>';
  1491. }
  1492. }
  1493. }
  1494. if ($id == 4) {
  1495. print '<td></td>';
  1496. print '<td></td>';
  1497. }
  1498. print '<td class="liste_titre"></td>';
  1499. print '<td class="liste_titre right" colspan="2">';
  1500. if ($filterfound) {
  1501. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  1502. print $searchpicto;
  1503. }
  1504. print '</td>';
  1505. print '</tr>';
  1506. // Title of lines
  1507. print '<!-- line title of record -->'."\n";
  1508. print '<tr class="liste_titre">';
  1509. foreach ($fieldlist as $field => $value) {
  1510. if ($value == 'entity') {
  1511. continue;
  1512. }
  1513. if (in_array($value, array('label', 'libelle', 'libelle_facture')) && empty($tabhelp[$id][$value])) {
  1514. $tabhelp[$id][$value] = $langs->trans('LabelUsedByDefault');
  1515. }
  1516. // Determines the name of the field in relation to the possible names
  1517. // in data dictionaries
  1518. $showfield = 1; // By default
  1519. $cssprefix = '';
  1520. $sortable = 1;
  1521. $valuetoshow = ucfirst($value); // By default
  1522. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  1523. // Special cases
  1524. if ($value == 'source') {
  1525. $valuetoshow = $langs->trans("Contact");
  1526. }
  1527. if ($value == 'price') {
  1528. $valuetoshow = $langs->trans("PriceUHT");
  1529. }
  1530. if ($value == 'taux') {
  1531. if ($tabname[$id] != "c_revenuestamp") {
  1532. $valuetoshow = $langs->trans("Rate");
  1533. } else {
  1534. $valuetoshow = $langs->trans("Amount");
  1535. }
  1536. $cssprefix = 'center ';
  1537. }
  1538. if ($value == 'localtax1_type') {
  1539. $valuetoshow = $langs->trans("UseLocalTax")." 2"; $cssprefix = "center "; $sortable = 0;
  1540. }
  1541. if ($value == 'localtax1') {
  1542. $valuetoshow = $langs->trans("RateOfTaxN", '2'); $cssprefix = "center "; $sortable = 0;
  1543. }
  1544. if ($value == 'localtax2_type') {
  1545. $valuetoshow = $langs->trans("UseLocalTax")." 3"; $cssprefix = "center "; $sortable = 0;
  1546. }
  1547. if ($value == 'localtax2') {
  1548. $valuetoshow = $langs->trans("RateOfTaxN", '3'); $cssprefix = "center "; $sortable = 0;
  1549. }
  1550. if ($value == 'organization') {
  1551. $valuetoshow = $langs->trans("Organization");
  1552. }
  1553. if ($value == 'lang') {
  1554. $valuetoshow = $langs->trans("Language");
  1555. }
  1556. if ($value == 'type') {
  1557. $valuetoshow = $langs->trans("Type");
  1558. }
  1559. if ($value == 'code') {
  1560. $valuetoshow = $langs->trans("Code");
  1561. }
  1562. if (in_array($value, array('pos', 'position'))) {
  1563. $valuetoshow = $langs->trans("Position"); $cssprefix = 'right ';
  1564. }
  1565. if ($value == 'libelle' || $value == 'label') {
  1566. $valuetoshow = $langs->trans("Label");
  1567. }
  1568. if ($value == 'libelle_facture') {
  1569. $valuetoshow = $langs->trans("LabelOnDocuments");
  1570. }
  1571. if ($value == 'deposit_percent') {
  1572. $valuetoshow = $langs->trans('DepositPercent');
  1573. $cssprefix = 'right ';
  1574. }
  1575. if ($value == 'country') {
  1576. $valuetoshow = $langs->trans("Country");
  1577. }
  1578. if ($value == 'recuperableonly') {
  1579. $valuetoshow = $langs->trans("NPR"); $cssprefix = "center ";
  1580. }
  1581. if ($value == 'nbjour') {
  1582. $valuetoshow = $langs->trans("NbOfDays");
  1583. $cssprefix = 'right ';
  1584. }
  1585. if ($value == 'type_cdr') {
  1586. $valuetoshow = $langs->trans("AtEndOfMonth"); $cssprefix = "center ";
  1587. }
  1588. if ($value == 'decalage') {
  1589. $valuetoshow = $langs->trans("Offset");
  1590. $cssprefix = 'right ';
  1591. }
  1592. if ($value == 'width' || $value == 'nx') {
  1593. $valuetoshow = $langs->trans("Width");
  1594. }
  1595. if ($value == 'height' || $value == 'ny') {
  1596. $valuetoshow = $langs->trans("Height");
  1597. }
  1598. if ($value == 'unit' || $value == 'metric') {
  1599. $valuetoshow = $langs->trans("MeasuringUnit");
  1600. }
  1601. if ($value == 'accountancy_code') {
  1602. $valuetoshow = $langs->trans("AccountancyCode");
  1603. }
  1604. if ($value == 'accountancy_code_sell') {
  1605. $valuetoshow = $langs->trans("AccountancyCodeSell"); $sortable = 0;
  1606. }
  1607. if ($value == 'accountancy_code_buy') {
  1608. $valuetoshow = $langs->trans("AccountancyCodeBuy"); $sortable = 0;
  1609. }
  1610. if ($value == 'fk_pcg_version') {
  1611. $valuetoshow = $langs->trans("Pcg_version");
  1612. }
  1613. if ($value == 'account_parent') {
  1614. $valuetoshow = $langs->trans("Accountsparent");
  1615. }
  1616. if ($value == 'pcg_type') {
  1617. $valuetoshow = $langs->trans("Pcg_type");
  1618. }
  1619. if ($value == 'pcg_subtype') {
  1620. $valuetoshow = $langs->trans("Pcg_subtype");
  1621. }
  1622. if ($value == 'sortorder') {
  1623. $valuetoshow = $langs->trans("SortOrder");
  1624. $cssprefix = 'center ';
  1625. }
  1626. if ($value == 'short_label') {
  1627. $valuetoshow = $langs->trans("ShortLabel");
  1628. }
  1629. if ($value == 'fk_parent') {
  1630. $valuetoshow = $langs->trans("ParentID"); $cssprefix = 'center ';
  1631. }
  1632. if ($value == 'range_account') {
  1633. $valuetoshow = $langs->trans("Range");
  1634. }
  1635. if ($value == 'sens') {
  1636. $valuetoshow = $langs->trans("Sens");
  1637. }
  1638. if ($value == 'category_type') {
  1639. $valuetoshow = $langs->trans("Calculated");
  1640. }
  1641. if ($value == 'formula') {
  1642. $valuetoshow = $langs->trans("Formula");
  1643. }
  1644. if ($value == 'paper_size') {
  1645. $valuetoshow = $langs->trans("PaperSize");
  1646. }
  1647. if ($value == 'orientation') {
  1648. $valuetoshow = $langs->trans("Orientation");
  1649. }
  1650. if ($value == 'leftmargin') {
  1651. $valuetoshow = $langs->trans("LeftMargin");
  1652. }
  1653. if ($value == 'topmargin') {
  1654. $valuetoshow = $langs->trans("TopMargin");
  1655. }
  1656. if ($value == 'spacex') {
  1657. $valuetoshow = $langs->trans("SpaceX");
  1658. }
  1659. if ($value == 'spacey') {
  1660. $valuetoshow = $langs->trans("SpaceY");
  1661. }
  1662. if ($value == 'font_size') {
  1663. $valuetoshow = $langs->trans("FontSize");
  1664. }
  1665. if ($value == 'custom_x') {
  1666. $valuetoshow = $langs->trans("CustomX");
  1667. }
  1668. if ($value == 'custom_y') {
  1669. $valuetoshow = $langs->trans("CustomY");
  1670. }
  1671. if ($value == 'percent') {
  1672. $valuetoshow = $langs->trans("Percentage");
  1673. }
  1674. if ($value == 'affect') {
  1675. $valuetoshow = $langs->trans("WithCounter");
  1676. }
  1677. if ($value == 'delay') {
  1678. $valuetoshow = $langs->trans("NoticePeriod");
  1679. }
  1680. if ($value == 'newbymonth') {
  1681. $valuetoshow = $langs->trans("NewByMonth");
  1682. }
  1683. if ($value == 'fk_tva') {
  1684. $valuetoshow = $langs->trans("VAT");
  1685. }
  1686. if ($value == 'range_ik') {
  1687. $valuetoshow = $langs->trans("RangeIk");
  1688. }
  1689. if ($value == 'fk_c_exp_tax_cat') {
  1690. $valuetoshow = $langs->trans("CarCategory");
  1691. }
  1692. if ($value == 'revenuestamp_type') {
  1693. $valuetoshow = $langs->trans('TypeOfRevenueStamp');
  1694. }
  1695. if ($value == 'use_default') {
  1696. $valuetoshow = $langs->trans('Default'); $cssprefix = 'center ';
  1697. }
  1698. if ($value == 'unit_type') {
  1699. $valuetoshow = $langs->trans('TypeOfUnit');
  1700. }
  1701. if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
  1702. $valuetoshow = $langs->trans('TicketGroupIsPublic'); $cssprefix = 'center ';
  1703. }
  1704. if ($value == 'block_if_negative') {
  1705. $valuetoshow = $langs->trans('BlockHolidayIfNegative');
  1706. }
  1707. if ($value == 'type_duration') {
  1708. $valuetoshow = $langs->trans('Unit');
  1709. }
  1710. if ($value == 'region_id' || $value == 'country_id') {
  1711. $showfield = 0;
  1712. }
  1713. // Show field title
  1714. if ($showfield) {
  1715. if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
  1716. $newvaluetoshow = '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  1717. } elseif (!empty($tabhelp[$id][$value])) {
  1718. $newvaluetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value]);
  1719. } else {
  1720. $newvaluetoshow = $valuetoshow;
  1721. }
  1722. print getTitleFieldOfList($newvaluetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $value : ''), ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $cssprefix);
  1723. }
  1724. }
  1725. // Favorite & EEC - Only activated on country dictionary
  1726. if ($id == 4) {
  1727. print getTitleFieldOfList($langs->trans("InEEC"), 0, $_SERVER["PHP_SELF"], "eec", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder, '', 0, $langs->trans("CountryIsInEEC"));
  1728. print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
  1729. }
  1730. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
  1731. print getTitleFieldOfList('');
  1732. print getTitleFieldOfList('');
  1733. print '</tr>';
  1734. if ($num) {
  1735. // Lines with values
  1736. while ($i < $num) {
  1737. $obj = $db->fetch_object($resql);
  1738. //print_r($obj);
  1739. print '<tr class="oddeven" id="rowid-'.(empty($obj->rowid) ? '' : $obj->rowid).'">';
  1740. if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
  1741. $tmpaction = 'edit';
  1742. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1743. $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1744. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1745. // Show fields
  1746. if (empty($reshook)) {
  1747. $withentity = fieldList($fieldlist, $obj, $tabname[$id], 'edit');
  1748. }
  1749. print '<td colspan="3" class="center">';
  1750. print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
  1751. print '<input type="hidden" name="page" value="'.dol_escape_htmltag($page).'">';
  1752. print '<input type="hidden" name="rowid" value="'.dol_escape_htmltag($rowid).'">';
  1753. if (!is_null($withentity)) {
  1754. print '<input type="hidden" name="entity" value="'.$withentity.'">';
  1755. }
  1756. print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
  1757. print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  1758. print '</td>';
  1759. } else {
  1760. $tmpaction = 'view';
  1761. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1762. $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1763. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1764. if (empty($reshook)) {
  1765. $withentity = null;
  1766. foreach ($fieldlist as $field => $value) {
  1767. //var_dump($fieldlist);
  1768. $class = '';
  1769. $showfield = 1;
  1770. $valuetoshow = empty($obj->{$value}) ? '' : $obj->{$value};
  1771. $titletoshow = '';
  1772. if ($value == 'entity') {
  1773. $withentity = $valuetoshow;
  1774. continue;
  1775. }
  1776. if ($value == 'element') {
  1777. $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
  1778. } elseif ($value == 'source') {
  1779. $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
  1780. } elseif ($valuetoshow == 'all') {
  1781. $valuetoshow = $langs->trans('All');
  1782. } elseif ($value == 'country') {
  1783. if (empty($obj->country_code)) {
  1784. $valuetoshow = '-';
  1785. } else {
  1786. $key = $langs->trans("Country".strtoupper($obj->country_code));
  1787. $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
  1788. }
  1789. } elseif ($value == 'recuperableonly' || $value == 'deductible' || $value == 'category_type') {
  1790. $valuetoshow = yn($valuetoshow);
  1791. $class = "center";
  1792. } elseif ($value == 'type_cdr') {
  1793. if (empty($valuetoshow)) {
  1794. $valuetoshow = $langs->trans('None');
  1795. } elseif ($valuetoshow == 1) {
  1796. $valuetoshow = $langs->trans('AtEndOfMonth');
  1797. } elseif ($valuetoshow == 2) {
  1798. $valuetoshow = $langs->trans('CurrentNext');
  1799. }
  1800. $class = "center";
  1801. } elseif ($value == 'price' || preg_match('/^amount/i', $value)) {
  1802. $valuetoshow = price($valuetoshow);
  1803. }
  1804. if ($value == 'private') {
  1805. $valuetoshow = yn($elementList[$valuetoshow]);
  1806. } elseif ($value == 'libelle_facture') {
  1807. $langs->load("bills");
  1808. $key = $langs->trans("PaymentCondition".strtoupper($obj->code));
  1809. $valuetoshow = ($obj->code && $key != "PaymentCondition".strtoupper($obj->code) ? $key : $obj->{$value});
  1810. $valuetoshow = nl2br($valuetoshow);
  1811. } elseif ($value == 'label' && $tabname[$id] == 'c_country') {
  1812. $key = $langs->trans("Country".strtoupper($obj->code));
  1813. $valuetoshow = ($obj->code && $key != "Country".strtoupper($obj->code) ? $key : $obj->{$value});
  1814. } elseif ($value == 'label' && $tabname[$id] == 'c_availability') {
  1815. $langs->load("propal");
  1816. $key = $langs->trans("AvailabilityType".strtoupper($obj->code));
  1817. $valuetoshow = ($obj->code && $key != "AvailabilityType".strtoupper($obj->code) ? $key : $obj->{$value});
  1818. } elseif ($value == 'libelle' && $tabname[$id] == 'c_actioncomm') {
  1819. $key = $langs->trans("Action".strtoupper($obj->code));
  1820. $valuetoshow = ($obj->code && $key != "Action".strtoupper($obj->code) ? $key : $obj->{$value});
  1821. } elseif (!empty($obj->code_iso) && $value == 'label' && $tabname[$id] == 'c_currencies') {
  1822. $key = $langs->trans("Currency".strtoupper($obj->code_iso));
  1823. $valuetoshow = ($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso) ? $key : $obj->{$value});
  1824. } elseif ($value == 'libelle' && $tabname[$id] == 'c_typent') {
  1825. $key = $langs->trans(strtoupper($obj->code));
  1826. $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->{$value});
  1827. } elseif ($value == 'libelle' && $tabname[$id] == 'c_prospectlevel') {
  1828. $key = $langs->trans(strtoupper($obj->code));
  1829. $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->{$value});
  1830. } elseif ($value == 'label' && $tabname[$id] == 'c_civility') {
  1831. $key = $langs->trans("Civility".strtoupper($obj->code));
  1832. $valuetoshow = ($obj->code && $key != "Civility".strtoupper($obj->code) ? $key : $obj->{$value});
  1833. } elseif ($value == 'libelle' && $tabname[$id] == 'c_type_contact') {
  1834. $langs->load('agenda');
  1835. $key = $langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  1836. $valuetoshow = ($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code) ? $key : $obj->{$value});
  1837. } elseif ($value == 'libelle' && $tabname[$id] == 'c_payment_term') {
  1838. $langs->load("bills");
  1839. $key = $langs->trans("PaymentConditionShort".strtoupper($obj->code));
  1840. $valuetoshow = ($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code) ? $key : $obj->{$value});
  1841. } elseif ($value == 'libelle' && $tabname[$id] == 'c_paiement') {
  1842. $langs->load("bills");
  1843. $key = $langs->trans("PaymentType".strtoupper($obj->code));
  1844. $valuetoshow = ($obj->code && $key != "PaymentType".strtoupper($obj->code) ? $key : $obj->{$value});
  1845. } elseif ($value == 'type' && $tabname[$id] == 'c_paiement') {
  1846. $payment_type_list = array(0=>$langs->trans('PaymentTypeCustomer'), 1=>$langs->trans('PaymentTypeSupplier'), 2=>$langs->trans('PaymentTypeBoth'));
  1847. $valuetoshow = $payment_type_list[$valuetoshow];
  1848. } elseif ($value == 'label' && $tabname[$id] == 'c_input_reason') {
  1849. $key = $langs->trans("DemandReasonType".strtoupper($obj->code));
  1850. $valuetoshow = ($obj->code && $key != "DemandReasonType".strtoupper($obj->code) ? $key : $obj->{$value});
  1851. } elseif ($value == 'libelle' && $tabname[$id] == 'c_input_method') {
  1852. $langs->load("orders");
  1853. $key = $langs->trans($obj->code);
  1854. $valuetoshow = ($obj->code && $key != $obj->code) ? $key : $obj->{$value};
  1855. } elseif ($value == 'libelle' && $tabname[$id] == 'c_shipment_mode') {
  1856. $langs->load("sendings");
  1857. $key = $langs->trans("SendingMethod".strtoupper($obj->code));
  1858. $valuetoshow = ($obj->code && $key != "SendingMethod".strtoupper($obj->code) ? $key : $obj->{$value});
  1859. } elseif ($value == 'libelle' && $tabname[$id] == 'c_paper_format') {
  1860. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  1861. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$value});
  1862. } elseif ($value == 'label' && $tabname[$id] == 'c_type_fees') {
  1863. $langs->load('trips');
  1864. $key = $langs->trans(strtoupper($obj->code));
  1865. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$value});
  1866. } elseif ($value == 'region_id' || $value == 'country_id') {
  1867. $showfield = 0;
  1868. } elseif ($value == 'unicode') {
  1869. $valuetoshow = $langs->getCurrencySymbol($obj->code, 1);
  1870. } elseif ($value == 'label' && $tabname[GETPOST("id", 'int')] == 'c_units') {
  1871. $langs->load("products");
  1872. $valuetoshow = $langs->trans($obj->{$value});
  1873. } elseif ($value == 'short_label' && $tabname[GETPOST("id", 'int')] == 'c_units') {
  1874. $langs->load("products");
  1875. $valuetoshow = $langs->trans($obj->{$value});
  1876. } elseif (($value == 'unit') && ($tabname[$id] == 'c_paper_format')) {
  1877. $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
  1878. $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$value});
  1879. } elseif ($value == 'localtax1' || $value == 'localtax2') {
  1880. $class = "center";
  1881. } elseif ($value == 'localtax1_type') {
  1882. if ($obj->localtax1 != 0) {
  1883. $valuetoshow = $localtax_typeList[$valuetoshow];
  1884. } else {
  1885. $valuetoshow = '';
  1886. }
  1887. $class = "center";
  1888. } elseif ($value == 'localtax2_type') {
  1889. if ($obj->localtax2 != 0) {
  1890. $valuetoshow = $localtax_typeList[$valuetoshow];
  1891. } else {
  1892. $valuetoshow = '';
  1893. }
  1894. $class = "center";
  1895. } elseif ($value == 'taux') {
  1896. $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
  1897. $class = "center";
  1898. } elseif (in_array($value, array('recuperableonly'))) {
  1899. $class = "center";
  1900. } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
  1901. if (!empty($conf->accounting->enabled)) {
  1902. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  1903. $tmpaccountingaccount = new AccountingAccount($db);
  1904. $tmpaccountingaccount->fetch(0, $valuetoshow, 1);
  1905. $titletoshow = $langs->transnoentitiesnoconv("Pcgtype").': '.$tmpaccountingaccount->pcg_type;
  1906. }
  1907. $valuetoshow = length_accountg($valuetoshow);
  1908. } elseif ($value == 'fk_tva') {
  1909. foreach ($form->cache_vatrates as $key => $Tab) {
  1910. if ($form->cache_vatrates[$key]['rowid'] == $valuetoshow) {
  1911. $valuetoshow = $form->cache_vatrates[$key]['libtva'];
  1912. break;
  1913. }
  1914. }
  1915. } elseif ($value == 'fk_c_exp_tax_cat') {
  1916. $tmpid = $valuetoshow;
  1917. $valuetoshow = getDictionaryValue('c_exp_tax_cat', 'label', $tmpid);
  1918. $valuetoshow = $langs->trans($valuetoshow ? $valuetoshow : $tmpid);
  1919. } elseif ($tabname[$id] == 'c_exp_tax_cat') {
  1920. $valuetoshow = $langs->trans($valuetoshow);
  1921. } elseif ($value == 'label' && $tabname[$id] == 'c_units') {
  1922. $langs->load('other');
  1923. $key = $langs->trans($obj->label);
  1924. $valuetoshow = ($obj->label && $key != strtoupper($obj->label) ? $key : $obj->{$value});
  1925. } elseif ($value == 'code' && $id == 3) {
  1926. $valuetoshow = $obj->state_code;
  1927. } elseif ($value == 'label' && $tabname[$id] == 'c_product_nature') {
  1928. $langs->load("products");
  1929. $valuetoshow = $langs->trans($obj->{$value});
  1930. } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == 'c_productbatch_qcstatus') {
  1931. $langs->load("productbatch");
  1932. $valuetoshow = $langs->trans($obj->{$value});
  1933. } elseif ($value == 'block_if_negative') {
  1934. $valuetoshow = yn($obj->{$value});
  1935. } elseif ($value == 'type_duration') {
  1936. $TDurationTypes = array('y'=>$langs->trans('Years'), 'm'=>$langs->trans('Month'), 'w'=>$langs->trans('Weeks'), 'd'=>$langs->trans('Days'), 'h'=>$langs->trans('Hours'), 'i'=>$langs->trans('Minutes'));
  1937. $valuetoshow =$TDurationTypes[$obj->{$value}];
  1938. }
  1939. $class .= ($class ? ' ' : '').'tddict';
  1940. if ($value == 'note' && $id == 10) {
  1941. $class .= ' tdoverflowmax200';
  1942. }
  1943. if ($value == 'tracking') {
  1944. $class .= ' tdoverflowauto';
  1945. }
  1946. if (in_array($value, array('nbjour', 'decalage', 'pos', 'position', 'deposit_percent'))) {
  1947. $class .= ' right';
  1948. }
  1949. if (in_array($value, array('localtax1_type', 'localtax2_type'))) {
  1950. $class .= ' nowrap';
  1951. }
  1952. if (in_array($value, array('use_default', 'fk_parent', 'sortorder'))) {
  1953. $class .= ' center';
  1954. }
  1955. if ($value == 'public') {
  1956. $class .= ' center';
  1957. }
  1958. // Show value for field
  1959. if ($showfield) {
  1960. print '<!-- '. $value .' --><td class="'.$class.'"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.$valuetoshow.'</td>';
  1961. }
  1962. }
  1963. }
  1964. // Can an entry be erased or disabled ?
  1965. // all true by default
  1966. $iserasable = 1;
  1967. $canbedisabled = 1;
  1968. $canbemodified = 1;
  1969. if (isset($obj->code) && $id != 10 && $id != 42) {
  1970. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
  1971. $iserasable = 0; $canbedisabled = 0;
  1972. } elseif ($obj->code == 'RECEP') {
  1973. $iserasable = 0; $canbedisabled = 0;
  1974. } elseif ($obj->code == 'EF0') {
  1975. $iserasable = 0; $canbedisabled = 0;
  1976. }
  1977. }
  1978. if ($id == 25 && in_array($obj->code, array('banner', 'blogpost', 'other', 'page'))) {
  1979. $iserasable = 0; $canbedisabled = 0;
  1980. if (in_array($obj->code, array('banner'))) {
  1981. $canbedisabled = 1;
  1982. }
  1983. }
  1984. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) {
  1985. $iserasable = 0;
  1986. }
  1987. if (in_array(empty($obj->code) ? '' : $obj->code, array('AC_OTH', 'AC_OTH_AUTO')) || in_array(empty($obj->type) ? '' : $obj->type, array('systemauto'))) {
  1988. $canbedisabled = 0; $canbedisabled = 0;
  1989. }
  1990. $canbemodified = $iserasable;
  1991. if (!empty($obj->code) && $obj->code == 'RECEP') {
  1992. $canbemodified = 1;
  1993. }
  1994. if ($tabname[$id] == "c_actioncomm") {
  1995. $canbemodified = 1;
  1996. }
  1997. // Build Url. The table is id=, the id of line is rowid=
  1998. $rowidcol = $tabrowid[$id];
  1999. // If rowidcol not defined
  2000. if (empty($rowidcol) || in_array($id, array(6, 7, 8, 13, 17, 19, 27, 32))) {
  2001. $rowidcol = 'rowid';
  2002. }
  2003. $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(isset($obj->{$rowidcol}) ? $obj->{$rowidcol} : (!empty($obj->code) ? urlencode($obj->code) : '')).'&code='.(!empty($obj->code) ?urlencode($obj->code) : '');
  2004. if (!empty($param)) {
  2005. $url .= '&'.$param;
  2006. }
  2007. if (!is_null($withentity)) {
  2008. $url .= '&entity='.$withentity;
  2009. }
  2010. $url .= '&';
  2011. // Favorite & EEC
  2012. // Only activated on country dictionary
  2013. if ($id == 4) {
  2014. print '<td class="nowrap center">';
  2015. // Is in EEC
  2016. if ($iserasable) {
  2017. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->eec].'_eec&token='.newToken().'">'.$actl[$obj->eec].'</a>';
  2018. } else {
  2019. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2020. }
  2021. print '</td>';
  2022. print '<td class="nowrap center">';
  2023. // Favorite
  2024. if ($iserasable) {
  2025. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->favorite].'_favorite&token='.newToken().'">'.$actl[$obj->favorite].'</a>';
  2026. } else {
  2027. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2028. }
  2029. print '</td>';
  2030. }
  2031. // Active
  2032. print '<td class="nowrap center">';
  2033. if ($canbedisabled) {
  2034. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
  2035. } else {
  2036. if (in_array($obj->code, array('AC_OTH', 'AC_OTH_AUTO'))) {
  2037. print $langs->trans("AlwaysActive");
  2038. } elseif (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) {
  2039. print $langs->trans("Deprecated");
  2040. } elseif (isset($obj->type) && in_array($obj->type, array('system')) && !empty($obj->active) && $obj->code != 'AC_OTH') {
  2041. print $langs->trans("UsedOnlyWithTypeOption");
  2042. } else {
  2043. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2044. }
  2045. }
  2046. print "</td>";
  2047. // Modify link
  2048. if ($canbemodified) {
  2049. print '<td align="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
  2050. } else {
  2051. print '<td>&nbsp;</td>';
  2052. }
  2053. // Delete link
  2054. if ($iserasable) {
  2055. print '<td class="center">';
  2056. if ($user->admin) {
  2057. print '<a class="reposition" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
  2058. }
  2059. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  2060. print '</td>';
  2061. } else {
  2062. print '<td>&nbsp;</td>';
  2063. }
  2064. print "</tr>\n";
  2065. }
  2066. $i++;
  2067. }
  2068. }
  2069. print '</table>';
  2070. print '</div>';
  2071. } else {
  2072. dol_print_error($db);
  2073. }
  2074. print '</form>';
  2075. } else {
  2076. /*
  2077. * Show list of dictionary to show
  2078. */
  2079. $lastlineisempty = false;
  2080. print '<div class="div-table-responsive-no-min">';
  2081. print '<table class="noborder centpercent">';
  2082. print '<tr class="liste_titre">';
  2083. print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
  2084. print '<td></td>';
  2085. print '</tr>';
  2086. $showemptyline = '';
  2087. foreach ($taborder as $i) {
  2088. if (isset($tabname[$i]) && empty($tabcond[$i])) {
  2089. continue;
  2090. }
  2091. if ($i) {
  2092. if ($showemptyline) {
  2093. print '<tr class="oddeven"><td width="50%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  2094. $showemptyline = 0;
  2095. }
  2096. $value = $tabname[$i];
  2097. print '<tr class="oddeven"><td width="50%">';
  2098. if (!empty($tabcond[$i])) {
  2099. $tabnamenoprefix = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabname[$i]);
  2100. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">';
  2101. if (!empty($tabcomplete[$tabnamenoprefix]['picto'])) {
  2102. print img_picto('', $tabcomplete[$tabnamenoprefix]['picto'], 'class="pictofixedwidth paddingrightonly"');
  2103. }
  2104. print $langs->trans($tablib[$i]);
  2105. print '</a>';
  2106. } else {
  2107. print $langs->trans($tablib[$i]);
  2108. }
  2109. print '</td>';
  2110. print '<td>';
  2111. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">';
  2112. print img_picto('Edit', 'edit', '');
  2113. print '</a>';
  2114. print '</td>';
  2115. print '<td class="right">';
  2116. print $form->textwithpicto('', $langs->trans("Table").': '.MAIN_DB_PREFIX.$tabname[$i]);
  2117. print '</td>';
  2118. print '</tr>';
  2119. $lastlineisempty = false;
  2120. } else {
  2121. if (!$lastlineisempty) {
  2122. $showemptyline = 1;
  2123. $lastlineisempty = true;
  2124. }
  2125. }
  2126. }
  2127. print '</table>';
  2128. print '</div>';
  2129. }
  2130. print '<br>';
  2131. // End of page
  2132. llxFooter();
  2133. $db->close();
  2134. /**
  2135. * Show fields in insert/edit mode
  2136. *
  2137. * @param array $fieldlist Array of fields
  2138. * @param Object $obj If we show a particular record, obj is filled with record fields
  2139. * @param string $tabname Name of SQL table
  2140. * @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
  2141. * @return string '' or value of entity into table
  2142. */
  2143. function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
  2144. {
  2145. global $conf, $langs, $db, $mysoc;
  2146. global $form;
  2147. global $region_id;
  2148. global $elementList, $sourceList, $localtax_typeList;
  2149. $formadmin = new FormAdmin($db);
  2150. $formcompany = new FormCompany($db);
  2151. $formaccounting = new FormAccounting($db);
  2152. $withentity = '';
  2153. foreach ($fieldlist as $field => $value) {
  2154. if ($value == 'entity') {
  2155. $withentity = $obj->{$value};
  2156. continue;
  2157. }
  2158. if (in_array($value, array('code', 'libelle', 'type')) && $tabname == "c_actioncomm" && in_array($obj->type, array('system', 'systemauto'))) {
  2159. $hidden = (!empty($obj->{$value}) ? $obj->{$value}:'');
  2160. print '<td>';
  2161. print '<input type="hidden" name="'. $value .'" value="'.$hidden.'">';
  2162. print $langs->trans($hidden);
  2163. print '</td>';
  2164. } elseif ($value == 'country') {
  2165. if (in_array('region_id', $fieldlist)) {
  2166. print '<td>';
  2167. print '</td>';
  2168. continue;
  2169. } // For state page, we do not show the country input (we link to region, not country)
  2170. print '<td>';
  2171. $fieldname = 'country';
  2172. print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
  2173. print '</td>';
  2174. } elseif ($value == 'country_id') {
  2175. if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
  2176. $country_id = (!empty($obj->{$value}) ? $obj->{$value} : 0);
  2177. print '<td class="tdoverflowmax100">';
  2178. print '<input type="hidden" name="'. $value .'" value="'.$country_id.'">';
  2179. print '</td>';
  2180. }
  2181. } elseif ($value == 'region') {
  2182. print '<td>';
  2183. $formcompany->select_region($region_id, 'region');
  2184. print '</td>';
  2185. } elseif ($value == 'region_id') {
  2186. $region_id = (!empty($obj->{$value}) ? $obj->{$value}:0);
  2187. print '<td>';
  2188. print '<input type="hidden" name="'. $value .'" value="'.$region_id.'">';
  2189. print '</td>';
  2190. } elseif ($value == 'lang') {
  2191. print '<td>';
  2192. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'lang');
  2193. print '</td>';
  2194. } elseif (in_array($value, array('element', 'source'))) { //Example: the type and source of the element (for contact types)
  2195. print '<td>';
  2196. print $form->selectarray($value, $elementList, (!empty($obj->{$value}) ? $obj->{$value}:''));
  2197. print '</td>';
  2198. } elseif (in_array($value, array('public', 'use_default'))) {
  2199. // Fields 0/1 with a combo select Yes/No
  2200. print '<td class="center">';
  2201. print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2202. print '</td>';
  2203. } elseif ($value == 'private') {
  2204. // Fields 'no'/'yes' with a combo select Yes/No
  2205. print '<td>';
  2206. print $form->selectyesno("private", (!empty($obj->{$value}) ? $obj->{$value}:''));
  2207. print '</td>';
  2208. } elseif ($value == 'type' && $tabname == "c_actioncomm") {
  2209. $type = (!empty($obj->type) ? $obj->type : 'user'); // Check if type is different of 'user' (external module)
  2210. print '<td>';
  2211. print $type.'<input type="hidden" name="type" value="'.$type.'">';
  2212. print '</td>';
  2213. } elseif ($value == 'type' && $tabname == 'c_paiement') {
  2214. print '<td>';
  2215. $select_list = array(0=>$langs->trans('PaymentTypeCustomer'), 1=>$langs->trans('PaymentTypeSupplier'), 2=>$langs->trans('PaymentTypeBoth'));
  2216. print $form->selectarray($value, $select_list, (!empty($obj->{$value}) ? $obj->{$value}:'2'));
  2217. print '</td>';
  2218. } elseif ($value == 'recuperableonly' || $value == 'type_cdr' || $value == 'deductible' || $value == 'category_type') {
  2219. if ($value == 'type_cdr') {
  2220. print '<td class="center">';
  2221. } else {
  2222. print '<td>';
  2223. }
  2224. if ($value == 'type_cdr') {
  2225. print $form->selectarray($value, array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (!empty($obj->{$value}) ? $obj->{$value}:''));
  2226. } else {
  2227. print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2228. }
  2229. print '</td>';
  2230. } elseif (in_array($value, array('nbjour', 'decalage', 'taux', 'localtax1', 'localtax2'))) {
  2231. $class = "right";
  2232. if (in_array($value, array('taux', 'localtax1', 'localtax2'))) {
  2233. $class = "center"; // Fields aligned on right
  2234. }
  2235. print '<td class="'.$class.'">';
  2236. print '<input type="text" class="flat" value="'.(isset($obj->{$value}) ? $obj->{$value} : '').'" size="3" name="'. $value .'">';
  2237. print '</td>';
  2238. } elseif (in_array($value, array('libelle_facture'))) {
  2239. print '<td>';
  2240. $transfound = 0;
  2241. $transkey = '';
  2242. // Special case for labels
  2243. if ($tabname == 'c_payment_term') {
  2244. $langs->load("bills");
  2245. $transkey = "PaymentCondition".strtoupper($obj->code);
  2246. if ($langs->trans($transkey) != $transkey) {
  2247. $transfound = 1;
  2248. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  2249. }
  2250. }
  2251. if (!$transfound) {
  2252. print '<textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'. $value .'">'.(!empty($obj->{$value}) ? $obj->{$value}:'').'</textarea>';
  2253. } else {
  2254. print '<input type="hidden" name="'. $value .'" value="'.$transkey.'">';
  2255. }
  2256. print '</td>';
  2257. } elseif ($value == 'price' || preg_match('/^amount/i', $value)) {
  2258. print '<td><input type="text" class="flat minwidth75" value="'.price((!empty($obj->{$value}) ? $obj->{$value}:'')).'" name="'. $value .'"></td>';
  2259. } elseif ($value == 'code' && isset($obj->{$value})) {
  2260. print '<td><input type="text" class="flat minwidth75 maxwidth100" value="'.(!empty($obj->{$value}) ? $obj->{$value}:'').'" name="'. $value .'"></td>';
  2261. } elseif ($value == 'unit') {
  2262. print '<td>';
  2263. $units = array(
  2264. 'mm' => $langs->trans('SizeUnitmm'),
  2265. 'cm' => $langs->trans('SizeUnitcm'),
  2266. 'point' => $langs->trans('SizeUnitpoint'),
  2267. 'inch' => $langs->trans('SizeUnitinch')
  2268. );
  2269. print $form->selectarray('unit', $units, (!empty($obj->{$value}) ? $obj->{$value}:''), 0, 0, 0);
  2270. print '</td>';
  2271. } elseif ($value == 'localtax1_type' || $value == 'localtax2_type') {
  2272. // Le type de taxe locale
  2273. print '<td class="center">';
  2274. print $form->selectarray($value, $localtax_typeList, (!empty($obj->{$value}) ? $obj->{$value}:''));
  2275. print '</td>';
  2276. } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
  2277. print '<td>';
  2278. if (!empty($conf->accounting->enabled)) {
  2279. $fieldname = $value;
  2280. $accountancy_account = (!empty($obj->$fieldname) ? $obj->$fieldname : 0);
  2281. print $formaccounting->select_account($accountancy_account, '.'. $value, 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  2282. } else {
  2283. $fieldname = $value;
  2284. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname : '').'" name="'. $value .'">';
  2285. }
  2286. print '</td>';
  2287. } elseif ($value == 'fk_tva') {
  2288. print '<td>';
  2289. print $form->load_tva('fk_tva', $obj->taux, $mysoc, new Societe($db), 0, 0, '', false, -1);
  2290. print '</td>';
  2291. } elseif ($value == 'fk_c_exp_tax_cat') {
  2292. print '<td>';
  2293. print $form->selectExpenseCategories($obj->fk_c_exp_tax_cat);
  2294. print '</td>';
  2295. } elseif ($value == 'fk_range') {
  2296. print '<td>';
  2297. print $form->selectExpenseRanges($obj->fk_range);
  2298. print '</td>';
  2299. } elseif ($value == 'block_if_negative') {
  2300. print '<td>';
  2301. print $form->selectyesno("block_if_negative", (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2302. print '</td>';
  2303. } elseif ($value == 'type_duration') {
  2304. print '<td>';
  2305. print $form->selectTypeDuration('', $obj->{$value}, array('i','h'));
  2306. print '</td>';
  2307. } else {
  2308. $fieldValue = isset($obj->{$value}) ? $obj->{$value}: '';
  2309. $classtd = ''; $class = '';
  2310. if ($value == 'sortorder') {
  2311. $fieldlist[$field] = 'position';
  2312. }
  2313. if ($fieldlist[$field] == 'code') {
  2314. $class = 'maxwidth100';
  2315. }
  2316. if (in_array($fieldlist[$field], array('deposit_percent'))) {
  2317. $classtd = 'right'; $class = 'maxwidth50 right';
  2318. }
  2319. if (in_array($fieldlist[$field], array('pos', 'position'))) {
  2320. $classtd = 'center'; $class = 'maxwidth50 center';
  2321. }
  2322. if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'use_default', 'affect', 'delay', 'public', 'sortorder', 'sens', 'category_type', 'fk_parent'))) {
  2323. $class = 'maxwidth50 center';
  2324. }
  2325. if (in_array($fieldlist[$field], array('use_default', 'public', 'fk_parent'))) {
  2326. $classtd = 'center';
  2327. }
  2328. if (in_array($fieldlist[$field], array('libelle', 'label', 'tracking'))) {
  2329. $class = 'quatrevingtpercent';
  2330. }
  2331. // Fields that must be suggested as '0' instead of ''
  2332. if ($fieldlist[$field] == 'fk_parent') {
  2333. if (empty($fieldValue)) {
  2334. $fieldValue = '0';
  2335. }
  2336. }
  2337. // Labels Length
  2338. $maxlength = '';
  2339. if (in_array($fieldlist[$field], array('libelle', 'label'))) {
  2340. switch ($tabname) {
  2341. case 'c_accounting_category':
  2342. case 'c_ecotaxe':
  2343. case 'c_email_senderprofile':
  2344. case 'c_forme_juridique':
  2345. case 'c_holiday_types':
  2346. case 'c_payment_term':
  2347. case 'c_transport_mode':
  2348. $maxlength = ' maxlength="255"';
  2349. break;
  2350. case 'c_email_templates':
  2351. $maxlength = ' maxlength="180"';
  2352. break;
  2353. case 'c_socialnetworks':
  2354. $maxlength = ' maxlength="150"';
  2355. break;
  2356. default:
  2357. $maxlength = ' maxlength="128"';
  2358. }
  2359. }
  2360. print '<td class="'.$classtd.'">';
  2361. $transfound = 0;
  2362. $transkey = '';
  2363. if (in_array($fieldlist[$field], array('label', 'libelle'))) { // For label
  2364. // Special case for labels
  2365. if ($tabname == 'c_civility' && !empty($obj->code)) {
  2366. $transkey = "Civility".strtoupper($obj->code);
  2367. }
  2368. if ($tabname == 'c_payment_term' && !empty($obj->code)) {
  2369. $langs->load("bills");
  2370. $transkey = "PaymentConditionShort".strtoupper($obj->code);
  2371. }
  2372. if ($transkey && $langs->trans($transkey) != $transkey) {
  2373. $transfound = 1;
  2374. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  2375. }
  2376. }
  2377. if (!$transfound) {
  2378. print '<input type="text" class="flat'.($class ? ' '.$class : '').'"'.($maxlength ? ' '.$maxlength : '').' value="'.dol_escape_htmltag($fieldValue).'" name="'.$fieldlist[$field].'">';
  2379. } else {
  2380. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$transkey.'">';
  2381. }
  2382. print '</td>';
  2383. }
  2384. }
  2385. return $withentity;
  2386. }