dict.php 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  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-2022 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] = (isModEnabled("societe"));
  466. $tabcond[2] = true;
  467. $tabcond[3] = true;
  468. $tabcond[4] = true;
  469. $tabcond[5] = (isModEnabled("societe") || isModEnabled('adherent'));
  470. $tabcond[6] = isModEnabled('agenda');
  471. $tabcond[7] = isModEnabled('tax');
  472. $tabcond[8] = isModEnabled("societe");
  473. $tabcond[9] = true;
  474. $tabcond[10] = true;
  475. $tabcond[11] = (isModEnabled("societe"));
  476. $tabcond[12] = (isModEnabled('commande') || isModEnabled("propal") || isModEnabled('facture') || (isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_invoice") || isModEnabled("supplier_order"));
  477. $tabcond[13] = (isModEnabled('commande') || isModEnabled("propal") || isModEnabled('facture') || (isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_invoice") || isModEnabled("supplier_order"));
  478. $tabcond[14] = (isModEnabled("product") && (isModEnabled('ecotax') || !empty($conf->global->MAIN_SHOW_ECOTAX_DICTIONNARY)));
  479. $tabcond[15] = true;
  480. $tabcond[16] = (isModEnabled("societe") && empty($conf->global->SOCIETE_DISABLE_PROSPECTS));
  481. $tabcond[17] = (isModEnabled('deplacement') || isModEnabled('expensereport'));
  482. $tabcond[18] = isModEnabled("expedition") || isModEnabled("reception");
  483. $tabcond[19] = isModEnabled("societe");
  484. $tabcond[20] = (isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || isModEnabled("supplier_order");
  485. $tabcond[21] = isModEnabled("propal");
  486. $tabcond[22] = (isModEnabled('commande') || isModEnabled("propal"));
  487. $tabcond[23] = true;
  488. $tabcond[24] = isModEnabled('resource');
  489. $tabcond[25] = isModEnabled('website');
  490. //$tabcond[26]= isModEnabled("product");
  491. $tabcond[27] = isModEnabled("societe");
  492. $tabcond[28] = isModEnabled('holiday');
  493. $tabcond[29] = isModEnabled('project');
  494. $tabcond[30] = isModEnabled('label');
  495. //$tabcond[31]= !empty($conf->accounting->enabled);
  496. $tabcond[32] = (isModEnabled('holiday') || isModEnabled('hrm'));
  497. $tabcond[33] = isModEnabled('hrm');
  498. $tabcond[34] = isModEnabled('hrm');
  499. $tabcond[35] = isModEnabled('expensereport') && !empty($conf->global->MAIN_USE_EXPENSE_IK);
  500. $tabcond[36] = isModEnabled('expensereport') && !empty($conf->global->MAIN_USE_EXPENSE_IK);
  501. $tabcond[37] = isModEnabled("product");
  502. $tabcond[38] = isModEnabled('socialnetworks');
  503. $tabcond[39] = (isModEnabled("societe") && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES));
  504. $tabcond[40] = (isModEnabled("societe") && !empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES));
  505. $tabcond[41] = isModEnabled('intracommreport');
  506. $tabcond[42] = isModEnabled("product");
  507. $tabcond[43] = isModEnabled("product") && isModEnabled('productbatch') && $conf->global->MAIN_FEATURES_LEVEL >= 2;
  508. $tabcond[44] = isModEnabled('asset');
  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. // When a dictionnary is commented
  563. if (!isset($tabcond[$i])) {
  564. continue;
  565. }
  566. $tabcomplete[$key]['id'] = $i;
  567. $tabcomplete[$key]['cond'] = $tabcond[$i];
  568. $tabcomplete[$key]['rowid'] = $tabrowid[$i];
  569. $tabcomplete[$key]['fieldinsert'] = $tabfieldinsert[$i];
  570. $tabcomplete[$key]['fieldvalue'] = $tabfieldvalue[$i];
  571. $tabcomplete[$key]['lib'] = $tablib[$i];
  572. $tabcomplete[$key]['sql'] = $tabsql[$i];
  573. $tabcomplete[$key]['sqlsort'] = $tabsqlsort[$i];
  574. $tabcomplete[$key]['field'] = $tabfield[$i];
  575. }
  576. $keytable = '';
  577. if ($id > 0) {
  578. $arrayofkeys = array_keys($tabcomplete);
  579. $keytable = $arrayofkeys[$id - 1];
  580. }
  581. // Defaut sortorder
  582. if (empty($sortfield)) {
  583. $tmp1 = explode(',', empty($tabcomplete[$keytable]['sqlsort']) ? '' : $tabcomplete[$keytable]['sqlsort']);
  584. $tmp2 = explode(' ', $tmp1[0]);
  585. $sortfield = preg_replace('/^.*\./', '', $tmp2[0]);
  586. $sortorder = (!empty($tmp2[1]) ? $tmp2[1] : '');
  587. //var_dump($sortfield);var_dump($sortorder);
  588. }
  589. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  590. $elementList = array();
  591. $sourceList = array();
  592. if ($id == 11) {
  593. $elementList = array(
  594. '' => '',
  595. 'agenda' => img_picto('', 'action', 'class="pictofixedwidth"').$langs->trans('Agenda'),
  596. 'dolresource' => img_picto('', 'resource', 'class="pictofixedwidth"').$langs->trans('Resource'),
  597. 'societe' => img_picto('', 'company', 'class="pictofixedwidth"').$langs->trans('ThirdParty'),
  598. // 'proposal' => $langs->trans('Proposal'),
  599. // 'order' => $langs->trans('Order'),
  600. // 'invoice' => $langs->trans('Bill'),
  601. // 'intervention' => $langs->trans('InterventionCard'),
  602. // 'contract' => $langs->trans('Contract'),
  603. 'project' => img_picto('', 'project', 'class="pictofixedwidth"').$langs->trans('Project'),
  604. 'project_task' => img_picto('', 'projecttask', 'class="pictofixedwidth"').$langs->trans('Task'),
  605. 'propal' => img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans('Proposal'),
  606. 'commande' => img_picto('', 'order', 'class="pictofixedwidth"').$langs->trans('Order'),
  607. 'facture' => img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans('Bill'),
  608. 'fichinter' => img_picto('', 'intervention', 'class="pictofixedwidth"').$langs->trans('InterventionCard'),
  609. 'contrat' => img_picto('', 'contract', 'class="pictofixedwidth"').$langs->trans('Contract'),
  610. 'ticket' => img_picto('', 'ticket', 'class="pictofixedwidth"').$langs->trans('Ticket'),
  611. 'supplier_proposal' => img_picto('', 'supplier_proposal', 'class="pictofixedwidth"').$langs->trans('SupplierProposal'),
  612. 'order_supplier' => img_picto('', 'supplier_order', 'class="pictofixedwidth"').$langs->trans('SupplierOrder'),
  613. 'invoice_supplier' => img_picto('', 'supplier_invoice', 'class="pictofixedwidth"').$langs->trans('SupplierBill'),
  614. );
  615. if (!empty($conf->global->MAIN_FEATURES_LEVEL) && $conf->global->MAIN_FEATURES_LEVEL >= 2) {
  616. $elementList['conferenceorbooth'] = img_picto('', 'eventorganization', 'class="pictofixedwidth"').$langs->trans('ConferenceOrBooth');
  617. }
  618. complete_elementList_with_modules($elementList);
  619. //asort($elementList);
  620. $sourceList = array(
  621. 'internal' => $langs->trans('Internal'),
  622. 'external' => $langs->trans('External')
  623. );
  624. }
  625. // Define localtax_typeList (used for dictionary "llx_c_tva")
  626. $localtax_typeList = array(
  627. "0" => $langs->trans("No"),
  628. "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
  629. "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
  630. "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
  631. "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
  632. "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
  633. "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
  634. );
  635. /*
  636. * Actions
  637. */
  638. $object = new stdClass();
  639. $parameters = array(
  640. 'id' =>$id,
  641. 'rowid' =>$rowid,
  642. 'code' =>$code,
  643. 'confirm' =>$confirm,
  644. 'entity' =>$entity,
  645. 'taborder' =>$taborder,
  646. 'tabname' =>$tabname,
  647. 'tablib' =>$tablib,
  648. 'tabsql' =>$tabsql,
  649. 'tabsqlsort' =>$tabsqlsort,
  650. 'tabfield' =>$tabfield,
  651. 'tabfieldvalue' =>$tabfieldvalue,
  652. 'tabfieldinsert'=>$tabfieldinsert,
  653. 'tabrowid' =>$tabrowid,
  654. 'tabcond' =>$tabcond,
  655. 'tabhelp' =>$tabhelp,
  656. 'tabcomplete' =>$tabcomplete
  657. );
  658. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  659. if ($reshook < 0) {
  660. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  661. }
  662. if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha')) {
  663. $search_country_id = '';
  664. $search_code = '';
  665. }
  666. if (empty($reshook)) {
  667. // Actions add or modify an entry into a dictionary
  668. if (GETPOST('actionadd') || GETPOST('actionmodify')) {
  669. $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
  670. $listfieldinsert = explode(',', $tabfieldinsert[$id]);
  671. $listfieldmodify = explode(',', $tabfieldinsert[$id]);
  672. $listfieldvalue = explode(',', $tabfieldvalue[$id]);
  673. // Check that all mandatory fields are filled
  674. $ok = 1;
  675. foreach ($listfield as $f => $value) {
  676. // Discard check of mandatory fields for country for some tables
  677. if ($value == 'country_id' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryVAT', 'DictionaryRegion', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp', 'DictionaryAccountancysystem', 'DictionaryAccountancyCategory'))) {
  678. continue; // For some pages, country is not mandatory
  679. }
  680. if ($value == 'country' && in_array($tablib[$id], array('DictionaryPublicHolidays', 'DictionaryCanton', 'DictionaryCompanyType', 'DictionaryHolidayTypes', 'DictionaryRevenueStamp'))) {
  681. continue; // For some pages, country is not mandatory
  682. }
  683. // Discard check of mandatory fiedls for other fields
  684. if ($value == 'localtax1' && !GETPOST('localtax1_type')) {
  685. continue;
  686. }
  687. if ($value == 'localtax2' && !GETPOST('localtax2_type')) {
  688. continue;
  689. }
  690. if ($value == 'color' && !GETPOST('color')) {
  691. continue;
  692. }
  693. if ($value == 'formula' && !GETPOST('formula')) {
  694. continue;
  695. }
  696. if ($value == 'dayrule' && !GETPOST('dayrule')) {
  697. continue;
  698. }
  699. if ($value == 'sortorder') {
  700. continue; // For a column name 'sortorder', we use the field name 'position'
  701. }
  702. if ((!GETPOSTISSET($value) || GETPOST($value) == '')
  703. && (!in_array($value, array('decalage', 'module', 'accountancy_code', 'accountancy_code_sell', 'accountancy_code_buy', 'tracking', 'picto', 'deposit_percent')) // Fields that are not mandatory
  704. && ($id != 10 || ($value != 'code' && $value != 'note')) // Field code and note is not mandatory for dictionary table 10
  705. )
  706. ) {
  707. $ok = 0;
  708. $fieldnamekey = $value;
  709. // We take translate key of field
  710. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
  711. $fieldnamekey = 'Label';
  712. }
  713. if ($fieldnamekey == 'libelle_facture') {
  714. $fieldnamekey = 'LabelOnDocuments';
  715. }
  716. if ($fieldnamekey == 'deposit_percent') {
  717. $fieldnamekey = 'DepositPercent';
  718. }
  719. if ($fieldnamekey == 'nbjour') {
  720. $fieldnamekey = 'NbOfDays';
  721. }
  722. if ($fieldnamekey == 'decalage') {
  723. $fieldnamekey = 'Offset';
  724. }
  725. if ($fieldnamekey == 'module') {
  726. $fieldnamekey = 'Module';
  727. }
  728. if ($fieldnamekey == 'code') {
  729. $fieldnamekey = 'Code';
  730. }
  731. if ($fieldnamekey == 'note') {
  732. $fieldnamekey = 'Note';
  733. }
  734. if ($fieldnamekey == 'taux') {
  735. $fieldnamekey = 'Rate';
  736. }
  737. if ($fieldnamekey == 'type') {
  738. $fieldnamekey = 'Type';
  739. }
  740. if ($fieldnamekey == 'position') {
  741. $fieldnamekey = 'Position';
  742. }
  743. if ($fieldnamekey == 'unicode') {
  744. $fieldnamekey = 'Unicode';
  745. }
  746. if ($fieldnamekey == 'deductible') {
  747. $fieldnamekey = 'Deductible';
  748. }
  749. if ($fieldnamekey == 'sortorder') {
  750. $fieldnamekey = 'SortOrder';
  751. }
  752. if ($fieldnamekey == 'category_type') {
  753. $fieldnamekey = 'Calculated';
  754. }
  755. if ($fieldnamekey == 'revenuestamp_type') {
  756. $fieldnamekey = 'TypeOfRevenueStamp';
  757. }
  758. if ($fieldnamekey == 'use_default') {
  759. $fieldnamekey = 'UseByDefault';
  760. }
  761. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  762. }
  763. }
  764. // Other checks
  765. if (GETPOST('actionadd') && $tabname[$id] == "c_actioncomm" && GETPOSTISSET("type") && in_array(GETPOST("type"), array('system', 'systemauto'))) {
  766. $ok = 0;
  767. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  768. }
  769. if (GETPOSTISSET("code")) {
  770. if (GETPOST("code") == '0') {
  771. $ok = 0;
  772. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  773. }
  774. }
  775. if (GETPOSTISSET("country") && (GETPOST("country") == '0') && ($id != 2)) {
  776. if (in_array($tablib[$id], array('DictionaryCompanyType', 'DictionaryHolidayTypes'))) { // Field country is no mandatory for such dictionaries
  777. $_POST["country"] = '';
  778. } else {
  779. $ok = 0;
  780. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities("Country")), null, 'errors');
  781. }
  782. }
  783. if (($id == 3 || $id == 42) && !is_numeric(GETPOST("code"))) {
  784. $ok = 0;
  785. setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric", $langs->transnoentities("Code")), null, 'errors');
  786. }
  787. // Clean some parameters
  788. if ((GETPOST("localtax1_type") || (GETPOST('localtax1_type') == '0')) && !GETPOST("localtax1")) {
  789. $_POST["localtax1"] = '0'; // If empty, we force to 0
  790. }
  791. if ((GETPOST("localtax2_type") || (GETPOST('localtax2_type') == '0')) && !GETPOST("localtax2")) {
  792. $_POST["localtax2"] = '0'; // If empty, we force to 0
  793. }
  794. if (GETPOST("accountancy_code") <= 0) {
  795. $_POST["accountancy_code"] = ''; // If empty, we force to null
  796. }
  797. if (GETPOST("accountancy_code_sell") <= 0) {
  798. $_POST["accountancy_code_sell"] = ''; // If empty, we force to null
  799. }
  800. if (GETPOST("accountancy_code_buy") <= 0) {
  801. $_POST["accountancy_code_buy"] = ''; // If empty, we force to null
  802. }
  803. if ($id == 10 && GETPOSTISSET("code")) { // Spaces are not allowed into code for tax dictionary
  804. $_POST["code"] = preg_replace('/[^a-zA-Z0-9\-\+]/', '', GETPOST("code"));
  805. }
  806. $tablename = $tabname[$id];
  807. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  808. // If check ok and action add, add the line
  809. if ($ok && GETPOST('actionadd')) {
  810. if ($tabrowid[$id]) {
  811. // Get free id for insert
  812. $newid = 0;
  813. $sql = "SELECT MAX(".$tabrowid[$id].") as newid FROM ".MAIN_DB_PREFIX.$tablename;
  814. $result = $db->query($sql);
  815. if ($result) {
  816. $obj = $db->fetch_object($result);
  817. $newid = ($obj->newid + 1);
  818. } else {
  819. dol_print_error($db);
  820. }
  821. }
  822. // Add new entry
  823. $sql = "INSERT INTO ".MAIN_DB_PREFIX.$tablename." (";
  824. // List of fields
  825. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  826. $sql .= $tabrowid[$id].",";
  827. }
  828. $sql .= $tabfieldinsert[$id];
  829. $sql .= ",active)";
  830. $sql .= " VALUES(";
  831. // List of values
  832. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldinsert)) {
  833. $sql .= $newid.",";
  834. }
  835. $i = 0;
  836. foreach ($listfieldinsert as $f => $value) {
  837. $keycode = $listfieldvalue[$i];
  838. if (empty($keycode)) {
  839. $keycode = $value;
  840. }
  841. if ($value == 'price' || preg_match('/^amount/i', $value)) {
  842. $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
  843. } elseif ($value == 'taux' || $value == 'localtax1') {
  844. $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
  845. } elseif ($value == 'entity') {
  846. $_POST[$keycode] = getEntity($tablename);
  847. }
  848. if ($i) {
  849. $sql .= ",";
  850. }
  851. if ($keycode == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
  852. $sql .= (int) GETPOST('position', 'int');
  853. } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == 10)) {
  854. $sql .= "null"; // For vat, we want/accept code = ''
  855. } elseif ($keycode == 'content') {
  856. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  857. } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
  858. $sql .= (int) GETPOST($keycode, 'int');
  859. } else {
  860. $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
  861. }
  862. $i++;
  863. }
  864. $sql .= ",1)";
  865. dol_syslog("actionadd", LOG_DEBUG);
  866. $resql = $db->query($sql);
  867. if ($resql) { // Add is ok
  868. setEventMessages($langs->transnoentities("RecordCreatedSuccessfully"), null, 'mesgs');
  869. // Clean $_POST array, we keep only id of dictionary
  870. if ($id == 10 && GETPOST('country', 'int') > 0) {
  871. $search_country_id = GETPOST('country', 'int');
  872. }
  873. $_POST = array('id'=>$id);
  874. } else {
  875. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  876. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  877. } else {
  878. dol_print_error($db);
  879. }
  880. }
  881. }
  882. // If verif ok and action modify, modify the line
  883. if ($ok && GETPOST('actionmodify')) {
  884. if ($tabrowid[$id]) {
  885. $rowidcol = $tabrowid[$id];
  886. } else {
  887. $rowidcol = "rowid";
  888. }
  889. // Modify entry
  890. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET ";
  891. // Modifie valeur des champs
  892. if ($tabrowid[$id] && !in_array($tabrowid[$id], $listfieldmodify)) {
  893. $sql .= $tabrowid[$id]."=";
  894. $sql .= "'".$db->escape($rowid)."', ";
  895. }
  896. $i = 0;
  897. foreach ($listfieldmodify as $field) {
  898. $keycode = $listfieldvalue[$i];
  899. if (empty($keycode)) {
  900. $keycode = $field;
  901. }
  902. if ($field == 'price' || preg_match('/^amount/i', $field)) {
  903. $_POST[$keycode] = price2num(GETPOST($keycode), 'MU');
  904. } elseif ($field == 'taux' || $field == 'localtax1') {
  905. $_POST[$keycode] = price2num(GETPOST($keycode), 8); // Note that localtax2 can be a list of rates separated by coma like X:Y:Z
  906. } elseif ($field == 'entity') {
  907. $_POST[$keycode] = getEntity($tablename);
  908. }
  909. if ($i) {
  910. $sql .= ",";
  911. }
  912. $sql .= $field."=";
  913. if ($listfieldvalue[$i] == 'sortorder') { // For column name 'sortorder', we use the field name 'position'
  914. $sql .= (int) GETPOST('position', 'int');
  915. } elseif (GETPOST($keycode) == '' && !($keycode == 'code' && $id == 10)) {
  916. $sql .= "null"; // For vat, we want/accept code = ''
  917. } elseif ($keycode == 'content') {
  918. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  919. } elseif (in_array($keycode, array('joinfile', 'private', 'pos', 'position', 'scale', 'use_default'))) {
  920. $sql .= (int) GETPOST($keycode, 'int');
  921. } else {
  922. $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
  923. }
  924. $i++;
  925. }
  926. if (in_array($rowidcol, array('code', 'code_iso'))) {
  927. $sql .= " WHERE ".$rowidcol." = '".$db->escape($rowid)."'";
  928. } else {
  929. $sql .= " WHERE ".$rowidcol." = ".((int) $rowid);
  930. }
  931. if (in_array('entity', $listfieldmodify)) {
  932. $sql .= " AND entity = ".((int) getEntity($tablename, 0));
  933. }
  934. dol_syslog("actionmodify", LOG_DEBUG);
  935. //print $sql;
  936. $resql = $db->query($sql);
  937. if (!$resql) {
  938. setEventMessages($db->error(), null, 'errors');
  939. }
  940. }
  941. }
  942. if ($action == 'confirm_delete' && $confirm == 'yes') { // delete
  943. if ($tabrowid[$id]) {
  944. $rowidcol = $tabrowid[$id];
  945. } else {
  946. $rowidcol = "rowid";
  947. }
  948. $tablename = $tabname[$id];
  949. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  950. $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tablename." WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  951. dol_syslog("delete", LOG_DEBUG);
  952. $result = $db->query($sql);
  953. if (!$result) {
  954. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
  955. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  956. } else {
  957. dol_print_error($db);
  958. }
  959. }
  960. }
  961. // activate
  962. if ($action == $acts[0]) {
  963. if ($tabrowid[$id]) {
  964. $rowidcol = $tabrowid[$id];
  965. } else {
  966. $rowidcol = "rowid";
  967. }
  968. $tablename = $tabname[$id];
  969. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  970. if ($rowid) {
  971. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET active = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  972. } elseif ($code) {
  973. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET active = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  974. }
  975. $result = $db->query($sql);
  976. if (!$result) {
  977. dol_print_error($db);
  978. }
  979. }
  980. // disable
  981. if ($action == $acts[1]) {
  982. if ($tabrowid[$id]) {
  983. $rowidcol = $tabrowid[$id];
  984. } else {
  985. $rowidcol = "rowid";
  986. }
  987. $tablename = $tabname[$id];
  988. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  989. if ($rowid) {
  990. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET active = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  991. } elseif ($code) {
  992. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET active = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  993. }
  994. $result = $db->query($sql);
  995. if (!$result) {
  996. dol_print_error($db);
  997. }
  998. }
  999. // favorite
  1000. if ($action == 'activate_favorite') {
  1001. if ($tabrowid[$id]) {
  1002. $rowidcol = $tabrowid[$id];
  1003. } else {
  1004. $rowidcol = "rowid";
  1005. }
  1006. $tablename = $tabname[$id];
  1007. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  1008. if ($rowid) {
  1009. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET favorite = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1010. } elseif ($code) {
  1011. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET favorite = 1 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1012. }
  1013. $result = $db->query($sql);
  1014. if (!$result) {
  1015. dol_print_error($db);
  1016. }
  1017. }
  1018. // disable favorite
  1019. if ($action == 'disable_favorite') {
  1020. if ($tabrowid[$id]) {
  1021. $rowidcol = $tabrowid[$id];
  1022. } else {
  1023. $rowidcol = "rowid";
  1024. }
  1025. $tablename = $tabname[$id];
  1026. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  1027. if ($rowid) {
  1028. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET favorite = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1029. } elseif ($code) {
  1030. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET favorite = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1031. }
  1032. $result = $db->query($sql);
  1033. if (!$result) {
  1034. dol_print_error($db);
  1035. }
  1036. }
  1037. // Is in EEC - Activate
  1038. if ($action == 'activate_eec') {
  1039. if ($tabrowid[$id]) {
  1040. $rowidcol = $tabrowid[$id];
  1041. } else {
  1042. $rowidcol = "rowid";
  1043. }
  1044. $tablename = $tabname[$id];
  1045. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  1046. if ($rowid) {
  1047. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET eec = 1 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1048. } elseif ($code) {
  1049. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET eec = 1 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. // Is in EEC - Disable
  1057. if ($action == 'disable_eec') {
  1058. if ($tabrowid[$id]) {
  1059. $rowidcol = $tabrowid[$id];
  1060. } else {
  1061. $rowidcol = "rowid";
  1062. }
  1063. $tablename = $tabname[$id];
  1064. $tablename = preg_replace('/^'.preg_quote(MAIN_DB_PREFIX, '/').'/', '', $tablename);
  1065. if ($rowid) {
  1066. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET eec = 0 WHERE ".$rowidcol." = '".$db->escape($rowid)."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1067. } elseif ($code) {
  1068. $sql = "UPDATE ".MAIN_DB_PREFIX.$tablename." SET eec = 0 WHERE code = '".$db->escape(dol_escape_htmltag($code))."'".($entity != '' ? " AND entity = ".(int) $entity : '');
  1069. }
  1070. $result = $db->query($sql);
  1071. if (!$result) {
  1072. dol_print_error($db);
  1073. }
  1074. }
  1075. }
  1076. /*
  1077. * View
  1078. */
  1079. $form = new Form($db);
  1080. $formadmin = new FormAdmin($db);
  1081. $title = $langs->trans("DictionarySetup");
  1082. llxHeader('', $title);
  1083. $linkback = '';
  1084. if ($id) {
  1085. $title .= ' - '.$langs->trans($tablib[$id]);
  1086. $linkback = '<a href="'.$_SERVER['PHP_SELF'].'">'.$langs->trans("BackToDictionaryList").'</a>';
  1087. }
  1088. $titlepicto = 'title_setup';
  1089. if ($id == 10 && GETPOST('from') == 'accountancy') {
  1090. $title = $langs->trans("MenuVatAccounts");
  1091. $titlepicto = 'accountancy';
  1092. }
  1093. if ($id == 7 && GETPOST('from') == 'accountancy') {
  1094. $title = $langs->trans("MenuTaxAccounts");
  1095. $titlepicto = 'accountancy';
  1096. }
  1097. print load_fiche_titre($title, $linkback, $titlepicto);
  1098. if (empty($id)) {
  1099. print '<span class="opacitymedium">'.$langs->trans("DictionaryDesc");
  1100. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  1101. print '</span><br>';
  1102. }
  1103. $param = '&id='.urlencode($id);
  1104. if ($search_country_id > 0) {
  1105. $param .= '&search_country_id='.urlencode($search_country_id);
  1106. }
  1107. if ($search_code != '') {
  1108. $param .= '&search_code='.urlencode($search_country_id);
  1109. }
  1110. if ($entity != '') {
  1111. $param .= '&entity='.(int) $entity;
  1112. }
  1113. $paramwithsearch = $param;
  1114. if ($sortorder) {
  1115. $paramwithsearch .= '&sortorder='.urlencode($sortorder);
  1116. }
  1117. if ($sortfield) {
  1118. $paramwithsearch .= '&sortfield='.urlencode($sortfield);
  1119. }
  1120. if (GETPOST('from')) {
  1121. $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
  1122. }
  1123. // Confirmation of the deletion of the line
  1124. if ($action == 'delete') {
  1125. 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);
  1126. }
  1127. /*
  1128. * Show a dictionary
  1129. */
  1130. if ($id > 0) {
  1131. // Complete search values request with sort criteria
  1132. $sql = $tabsql[$id];
  1133. if (!preg_match('/ WHERE /', $sql)) {
  1134. $sql .= " WHERE 1 = 1";
  1135. }
  1136. if ($search_country_id > 0) {
  1137. $sql .= " AND c.rowid = ".((int) $search_country_id);
  1138. }
  1139. if ($search_code != '' && $id == 9) {
  1140. $sql .= natural_search("code_iso", $search_code);
  1141. } elseif ($search_code != '' && $id == 28) {
  1142. $sql .= natural_search("h.code", $search_code);
  1143. } elseif ($search_code != '' && ($id == 7 || $id == 32)) {
  1144. $sql .= natural_search("a.code", $search_code);
  1145. } elseif ($search_code != '' && $id == 3) {
  1146. $sql .= natural_search("r.code_region", $search_code);
  1147. } elseif ($search_code != '' && ($id == 8 || $id == 10)) {
  1148. $sql .= natural_search("t.code", $search_code);
  1149. } elseif ($search_code != '' && $id == 1) {
  1150. $sql .= natural_search("f.code", $search_code);
  1151. } elseif ($search_code != '' && $id == 2) {
  1152. $sql .= natural_search("d.code_departement", $search_code);
  1153. } elseif ($search_code != '' && $id != 9) {
  1154. $sql .= natural_search("code", $search_code);
  1155. }
  1156. if ($sortfield) {
  1157. // If sort order is "country", we use country_code instead
  1158. if ($sortfield == 'country') {
  1159. $sortfield = 'country_code';
  1160. }
  1161. $sql .= $db->order($sortfield, $sortorder);
  1162. $sql .= ", ";
  1163. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  1164. $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i', '', $tabsqlsort[$id]);
  1165. $tabsqlsort[$id] = preg_replace('/([a-z]+\.)?'.$sortfield.',/i', '', $tabsqlsort[$id]);
  1166. } else {
  1167. $sql .= " ORDER BY ";
  1168. }
  1169. $sql .= $tabsqlsort[$id];
  1170. $sql .= $db->plimit($listlimit + 1, $offset);
  1171. //print $sql;
  1172. if (empty($tabfield[$id])) {
  1173. dol_print_error($db, 'The table with id '.$id.' has no array tabfield defined');
  1174. exit;
  1175. }
  1176. $fieldlist = explode(',', $tabfield[$id]);
  1177. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  1178. print '<input type="hidden" name="token" value="'.newToken().'">';
  1179. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  1180. if ($id == 10 && empty($conf->global->FACTURE_TVAOPTION)) {
  1181. print info_admin($langs->trans("VATIsUsedIsOff", $langs->transnoentities("Setup"), $langs->transnoentities("CompanyFoundation")));
  1182. print "<br>\n";
  1183. }
  1184. // Form to add a new line
  1185. if ($tabname[$id]) {
  1186. $withentity = null;
  1187. $fieldlist = explode(',', $tabfield[$id]);
  1188. print '<div class="div-table-responsive-no-min">';
  1189. print '<table class="noborder centpercent">';
  1190. // Line for title
  1191. print '<!-- line title to add new entry -->';
  1192. $tdsoffields = '<tr class="liste_titre">';
  1193. foreach ($fieldlist as $field => $value) {
  1194. if ($value == 'entity') {
  1195. $withentity = getEntity($tabname[$id]);
  1196. continue;
  1197. }
  1198. // Define field friendly name from its technical name
  1199. $valuetoshow = ucfirst($value); // Par defaut
  1200. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  1201. $class = '';
  1202. if ($value == 'pos') {
  1203. $valuetoshow = $langs->trans("Position"); $class = 'right';
  1204. }
  1205. if ($value == 'source') {
  1206. $valuetoshow = $langs->trans("Contact");
  1207. }
  1208. if ($value == 'price') {
  1209. $valuetoshow = $langs->trans("PriceUHT");
  1210. }
  1211. if ($value == 'taux') {
  1212. if ($tabname[$id] != "c_revenuestamp") {
  1213. $valuetoshow = $langs->trans("Rate");
  1214. } else {
  1215. $valuetoshow = $langs->trans("Amount");
  1216. }
  1217. $class = 'center';
  1218. }
  1219. if ($value == 'localtax1_type') {
  1220. $valuetoshow = $langs->trans("UseLocalTax")." 2"; $class = "center"; $sortable = 0;
  1221. }
  1222. if ($value == 'localtax1') {
  1223. $valuetoshow = $langs->trans("RateOfTaxN", '2'); $class = "center";
  1224. }
  1225. if ($value == 'localtax2_type') {
  1226. $valuetoshow = $langs->trans("UseLocalTax")." 3"; $class = "center"; $sortable = 0;
  1227. }
  1228. if ($value == 'localtax2') {
  1229. $valuetoshow = $langs->trans("RateOfTaxN", '3'); $class = "center";
  1230. }
  1231. if ($value == 'organization') {
  1232. $valuetoshow = $langs->trans("Organization");
  1233. }
  1234. if ($value == 'lang') {
  1235. $valuetoshow = $langs->trans("Language");
  1236. }
  1237. if ($value == 'type') {
  1238. if ($tabname[$id] == "c_paiement") {
  1239. $valuetoshow = $form->textwithtooltip($langs->trans("Type"), $langs->trans("TypePaymentDesc"), 2, 1, img_help(1, ''));
  1240. } else {
  1241. $valuetoshow = $langs->trans("Type");
  1242. }
  1243. }
  1244. if ($value == 'code') {
  1245. $valuetoshow = $langs->trans("Code"); $class = 'maxwidth100';
  1246. }
  1247. if ($value == 'libelle' || $value == 'label') {
  1248. $valuetoshow = $form->textwithtooltip($langs->trans("Label"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
  1249. }
  1250. if ($value == 'libelle_facture') {
  1251. $valuetoshow = $form->textwithtooltip($langs->trans("LabelOnDocuments"), $langs->trans("LabelUsedByDefault"), 2, 1, img_help(1, ''));
  1252. }
  1253. if ($value == 'deposit_percent') {
  1254. $valuetoshow = $langs->trans('DepositPercent');
  1255. $class = 'right';
  1256. }
  1257. if ($value == 'country') {
  1258. if (in_array('region_id', $fieldlist)) {
  1259. print '<td>&nbsp;</td>'; continue;
  1260. } // For region page, we do not show the country input
  1261. $valuetoshow = $langs->trans("Country");
  1262. }
  1263. if ($value == 'recuperableonly') {
  1264. $valuetoshow = $langs->trans("NPR"); $class = "center";
  1265. }
  1266. if ($value == 'nbjour') {
  1267. $valuetoshow = $langs->trans("NbOfDays");
  1268. $class = 'right';
  1269. }
  1270. if ($value == 'type_cdr') {
  1271. $valuetoshow = $langs->trans("AtEndOfMonth"); $class = "center";
  1272. }
  1273. if ($value == 'decalage') {
  1274. $valuetoshow = $langs->trans("Offset");
  1275. $class = 'right';
  1276. }
  1277. if ($value == 'width' || $value == 'nx') {
  1278. $valuetoshow = $langs->trans("Width");
  1279. }
  1280. if ($value == 'height' || $value == 'ny') {
  1281. $valuetoshow = $langs->trans("Height");
  1282. }
  1283. if ($value == 'unit' || $value == 'metric') {
  1284. $valuetoshow = $langs->trans("MeasuringUnit");
  1285. }
  1286. if ($value == 'region_id' || $value == 'country_id') {
  1287. $valuetoshow = '';
  1288. }
  1289. if ($value == 'accountancy_code') {
  1290. $valuetoshow = $langs->trans("AccountancyCode");
  1291. }
  1292. if ($value == 'accountancy_code_sell') {
  1293. $valuetoshow = $langs->trans("AccountancyCodeSell");
  1294. }
  1295. if ($value == 'accountancy_code_buy') {
  1296. $valuetoshow = $langs->trans("AccountancyCodeBuy");
  1297. }
  1298. if ($value == 'pcg_version' || $value == 'fk_pcg_version') {
  1299. $valuetoshow = $langs->trans("Pcg_version");
  1300. }
  1301. if ($value == 'account_parent') {
  1302. $valuetoshow = $langs->trans("Accountparent");
  1303. }
  1304. if ($value == 'pcg_type') {
  1305. $valuetoshow = $langs->trans("Pcg_type");
  1306. }
  1307. if ($value == 'pcg_subtype') {
  1308. $valuetoshow = $langs->trans("Pcg_subtype");
  1309. }
  1310. if ($value == 'sortorder') {
  1311. $valuetoshow = $langs->trans("SortOrder");
  1312. $class = 'center';
  1313. }
  1314. if ($value == 'short_label') {
  1315. $valuetoshow = $langs->trans("ShortLabel");
  1316. }
  1317. if ($value == 'fk_parent') {
  1318. $valuetoshow = $langs->trans("ParentID"); $class = 'center';
  1319. }
  1320. if ($value == 'range_account') {
  1321. $valuetoshow = $langs->trans("Range");
  1322. }
  1323. if ($value == 'sens') {
  1324. $valuetoshow = $langs->trans("Sens");
  1325. }
  1326. if ($value == 'category_type') {
  1327. $valuetoshow = $langs->trans("Calculated");
  1328. }
  1329. if ($value == 'formula') {
  1330. $valuetoshow = $langs->trans("Formula");
  1331. }
  1332. if ($value == 'paper_size') {
  1333. $valuetoshow = $langs->trans("PaperSize");
  1334. }
  1335. if ($value == 'orientation') {
  1336. $valuetoshow = $langs->trans("Orientation");
  1337. }
  1338. if ($value == 'leftmargin') {
  1339. $valuetoshow = $langs->trans("LeftMargin");
  1340. }
  1341. if ($value == 'topmargin') {
  1342. $valuetoshow = $langs->trans("TopMargin");
  1343. }
  1344. if ($value == 'spacex') {
  1345. $valuetoshow = $langs->trans("SpaceX");
  1346. }
  1347. if ($value == 'spacey') {
  1348. $valuetoshow = $langs->trans("SpaceY");
  1349. }
  1350. if ($value == 'font_size') {
  1351. $valuetoshow = $langs->trans("FontSize");
  1352. }
  1353. if ($value == 'custom_x') {
  1354. $valuetoshow = $langs->trans("CustomX");
  1355. }
  1356. if ($value == 'custom_y') {
  1357. $valuetoshow = $langs->trans("CustomY");
  1358. }
  1359. if ($value == 'percent') {
  1360. $valuetoshow = $langs->trans("Percentage");
  1361. }
  1362. if ($value == 'affect') {
  1363. $valuetoshow = $langs->trans("WithCounter");
  1364. }
  1365. if ($value == 'delay') {
  1366. $valuetoshow = $langs->trans("NoticePeriod");
  1367. }
  1368. if ($value == 'newbymonth') {
  1369. $valuetoshow = $langs->trans("NewByMonth");
  1370. }
  1371. if ($value == 'fk_tva') {
  1372. $valuetoshow = $langs->trans("VAT");
  1373. }
  1374. if ($value == 'range_ik') {
  1375. $valuetoshow = $langs->trans("RangeIk");
  1376. }
  1377. if ($value == 'fk_c_exp_tax_cat') {
  1378. $valuetoshow = $langs->trans("CarCategory");
  1379. }
  1380. if ($value == 'revenuestamp_type') {
  1381. $valuetoshow = $langs->trans('TypeOfRevenueStamp');
  1382. }
  1383. if ($value == 'use_default') {
  1384. $valuetoshow = $langs->trans('Default'); $class = 'center';
  1385. }
  1386. if ($value == 'unit_type') {
  1387. $valuetoshow = $langs->trans('TypeOfUnit');
  1388. }
  1389. if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
  1390. $valuetoshow = $langs->trans('TicketGroupIsPublic'); $class = 'center';
  1391. }
  1392. if ($value == 'block_if_negative') {
  1393. $valuetoshow = $langs->trans('BlockHolidayIfNegative');
  1394. }
  1395. if ($value == 'type_duration') {
  1396. $valuetoshow = $langs->trans('Unit');
  1397. }
  1398. if ($id == 2) { // Special case for state page
  1399. if ($value == 'region_id') {
  1400. $valuetoshow = '&nbsp;'; $showfield = 1;
  1401. }
  1402. if ($value == 'region') {
  1403. $valuetoshow = $langs->trans("Country").'/'.$langs->trans("Region"); $showfield = 1;
  1404. }
  1405. }
  1406. if ($valuetoshow != '') {
  1407. $tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : '');
  1408. $tdsoffields .= '<th'.($class ? ' class="'.$class.'"' : '').'>';
  1409. if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
  1410. $tdsoffields .= '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  1411. } elseif ($tooltiphelp) {
  1412. $tdsoffields .= $form->textwithpicto($valuetoshow, $tooltiphelp);
  1413. } else {
  1414. $tdsoffields .= $valuetoshow;
  1415. }
  1416. $tdsoffields .= '</th>';
  1417. }
  1418. }
  1419. if ($id == 4) {
  1420. $tdsoffields .= '<th></th>';
  1421. $tdsoffields .= '<th></th>';
  1422. }
  1423. $tdsoffields .= '<th>';
  1424. $tdsoffields .= '<input type="hidden" name="id" value="'.$id.'">';
  1425. if (!is_null($withentity)) {
  1426. $tdsoffields .= '<input type="hidden" name="entity" value="'.$withentity.'">';
  1427. }
  1428. $tdsoffields .= '</th>';
  1429. $tdsoffields .= '<th style="min-width: 26px;"></th>';
  1430. $tdsoffields .= '<th style="min-width: 26px;"></th>';
  1431. $tdsoffields .= '</tr>';
  1432. print $tdsoffields;
  1433. // Line to enter new values
  1434. print '<!-- line input to add new entry -->';
  1435. print '<tr class="oddeven nodrag nodrop nohover">';
  1436. $obj = new stdClass();
  1437. // If data was already input, we define them in obj to populate input fields.
  1438. if (GETPOST('actionadd')) {
  1439. foreach ($fieldlist as $key => $val) {
  1440. if (GETPOST($val) != '') {
  1441. $obj->$val = GETPOST($val);
  1442. }
  1443. }
  1444. }
  1445. $tmpaction = 'create';
  1446. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1447. $reshook = $hookmanager->executeHooks('createDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1448. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1449. if ($id == 3) {
  1450. unset($fieldlist[2]); // Remove field ??? if dictionary Regions
  1451. }
  1452. if (empty($reshook)) {
  1453. fieldList($fieldlist, $obj, $tabname[$id], 'add');
  1454. }
  1455. if ($id == 4) {
  1456. print '<td></td>';
  1457. print '<td></td>';
  1458. }
  1459. print '<td colspan="3" class="center">';
  1460. if ($action != 'edit') {
  1461. print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'">';
  1462. }
  1463. print '</td>';
  1464. print "</tr>";
  1465. print '</table>';
  1466. print '</div>';
  1467. }
  1468. print '</form>';
  1469. print '<br>';
  1470. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  1471. print '<input type="hidden" name="token" value="'.newToken().'">';
  1472. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  1473. // List of available record in database
  1474. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  1475. $resql = $db->query($sql);
  1476. if ($resql) {
  1477. $num = $db->num_rows($resql);
  1478. $i = 0;
  1479. // There is several pages
  1480. if ($num > $listlimit || $page) {
  1481. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
  1482. print '<div class="clearboth"></div>';
  1483. }
  1484. print '<div class="div-table-responsive">';
  1485. print '<table class="noborder centpercent">';
  1486. // Title line with search input fields
  1487. print '<!-- line title to search record -->'."\n";
  1488. print '<tr class="liste_titre_filter">';
  1489. $filterfound = 0;
  1490. foreach ($fieldlist as $field => $value) {
  1491. if ($value == 'entity') {
  1492. continue;
  1493. }
  1494. $showfield = 1; // By default
  1495. if ($value == 'region_id' || $value == 'country_id') {
  1496. $showfield = 0;
  1497. }
  1498. if ($showfield) {
  1499. if ($value == 'country') {
  1500. print '<td class="liste_titre">';
  1501. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth150 maxwidthonsmartphone');
  1502. print '</td>';
  1503. $filterfound++;
  1504. } elseif ($value == 'code') {
  1505. print '<td class="liste_titre">';
  1506. print '<input type="text" class="maxwidth100" name="search_code" value="'.dol_escape_htmltag($search_code).'">';
  1507. print '</td>';
  1508. $filterfound++;
  1509. } else {
  1510. print '<td class="liste_titre">';
  1511. print '</td>';
  1512. }
  1513. }
  1514. }
  1515. if ($id == 4) {
  1516. print '<td></td>';
  1517. print '<td></td>';
  1518. }
  1519. print '<td class="liste_titre"></td>';
  1520. print '<td class="liste_titre right" colspan="2">';
  1521. if ($filterfound) {
  1522. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  1523. print $searchpicto;
  1524. }
  1525. print '</td>';
  1526. print '</tr>';
  1527. // Title of lines
  1528. print '<!-- line title of record -->'."\n";
  1529. print '<tr class="liste_titre">';
  1530. foreach ($fieldlist as $field => $value) {
  1531. if ($value == 'entity') {
  1532. continue;
  1533. }
  1534. if (in_array($value, array('label', 'libelle', 'libelle_facture')) && empty($tabcomplete[$tabname[$id]]['help'][$value])) {
  1535. $tabcomplete[$tabname[$id]]['help'][$value] = $langs->trans('LabelUsedByDefault');
  1536. }
  1537. // Determines the name of the field in relation to the possible names
  1538. // in data dictionaries
  1539. $showfield = 1; // By default
  1540. $cssprefix = '';
  1541. $sortable = 1;
  1542. $valuetoshow = ucfirst($value); // By default
  1543. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  1544. // Special cases
  1545. if ($value == 'source') {
  1546. $valuetoshow = $langs->trans("Contact");
  1547. }
  1548. if ($value == 'price') {
  1549. $valuetoshow = $langs->trans("PriceUHT");
  1550. }
  1551. if ($value == 'taux') {
  1552. if ($tabname[$id] != "c_revenuestamp") {
  1553. $valuetoshow = $langs->trans("Rate");
  1554. } else {
  1555. $valuetoshow = $langs->trans("Amount");
  1556. }
  1557. $cssprefix = 'center ';
  1558. }
  1559. if ($value == 'localtax1_type') {
  1560. $valuetoshow = $langs->trans("UseLocalTax")." 2"; $cssprefix = "center "; $sortable = 0;
  1561. }
  1562. if ($value == 'localtax1') {
  1563. $valuetoshow = $langs->trans("RateOfTaxN", '2'); $cssprefix = "center "; $sortable = 0;
  1564. }
  1565. if ($value == 'localtax2_type') {
  1566. $valuetoshow = $langs->trans("UseLocalTax")." 3"; $cssprefix = "center "; $sortable = 0;
  1567. }
  1568. if ($value == 'localtax2') {
  1569. $valuetoshow = $langs->trans("RateOfTaxN", '3'); $cssprefix = "center "; $sortable = 0;
  1570. }
  1571. if ($value == 'organization') {
  1572. $valuetoshow = $langs->trans("Organization");
  1573. }
  1574. if ($value == 'lang') {
  1575. $valuetoshow = $langs->trans("Language");
  1576. }
  1577. if ($value == 'type') {
  1578. $valuetoshow = $langs->trans("Type");
  1579. }
  1580. if ($value == 'code') {
  1581. $valuetoshow = $langs->trans("Code");
  1582. }
  1583. if (in_array($value, array('pos', 'position'))) {
  1584. $valuetoshow = $langs->trans("Position"); $cssprefix = 'right ';
  1585. }
  1586. if ($value == 'libelle' || $value == 'label') {
  1587. $valuetoshow = $langs->trans("Label");
  1588. }
  1589. if ($value == 'libelle_facture') {
  1590. $valuetoshow = $langs->trans("LabelOnDocuments");
  1591. }
  1592. if ($value == 'deposit_percent') {
  1593. $valuetoshow = $langs->trans('DepositPercent');
  1594. $cssprefix = 'right ';
  1595. }
  1596. if ($value == 'country') {
  1597. $valuetoshow = $langs->trans("Country");
  1598. }
  1599. if ($value == 'recuperableonly') {
  1600. $valuetoshow = $langs->trans("NPR"); $cssprefix = "center ";
  1601. }
  1602. if ($value == 'nbjour') {
  1603. $valuetoshow = $langs->trans("NbOfDays");
  1604. $cssprefix = 'right ';
  1605. }
  1606. if ($value == 'type_cdr') {
  1607. $valuetoshow = $langs->trans("AtEndOfMonth"); $cssprefix = "center ";
  1608. }
  1609. if ($value == 'decalage') {
  1610. $valuetoshow = $langs->trans("Offset");
  1611. $cssprefix = 'right ';
  1612. }
  1613. if ($value == 'width' || $value == 'nx') {
  1614. $valuetoshow = $langs->trans("Width");
  1615. }
  1616. if ($value == 'height' || $value == 'ny') {
  1617. $valuetoshow = $langs->trans("Height");
  1618. }
  1619. if ($value == 'unit' || $value == 'metric') {
  1620. $valuetoshow = $langs->trans("MeasuringUnit");
  1621. }
  1622. if ($value == 'accountancy_code') {
  1623. $valuetoshow = $langs->trans("AccountancyCode");
  1624. }
  1625. if ($value == 'accountancy_code_sell') {
  1626. $valuetoshow = $langs->trans("AccountancyCodeSell"); $sortable = 0;
  1627. }
  1628. if ($value == 'accountancy_code_buy') {
  1629. $valuetoshow = $langs->trans("AccountancyCodeBuy"); $sortable = 0;
  1630. }
  1631. if ($value == 'fk_pcg_version') {
  1632. $valuetoshow = $langs->trans("Pcg_version");
  1633. }
  1634. if ($value == 'account_parent') {
  1635. $valuetoshow = $langs->trans("Accountsparent");
  1636. }
  1637. if ($value == 'pcg_type') {
  1638. $valuetoshow = $langs->trans("Pcg_type");
  1639. }
  1640. if ($value == 'pcg_subtype') {
  1641. $valuetoshow = $langs->trans("Pcg_subtype");
  1642. }
  1643. if ($value == 'sortorder') {
  1644. $valuetoshow = $langs->trans("SortOrder");
  1645. $cssprefix = 'center ';
  1646. }
  1647. if ($value == 'short_label') {
  1648. $valuetoshow = $langs->trans("ShortLabel");
  1649. }
  1650. if ($value == 'fk_parent') {
  1651. $valuetoshow = $langs->trans("ParentID"); $cssprefix = 'center ';
  1652. }
  1653. if ($value == 'range_account') {
  1654. $valuetoshow = $langs->trans("Range");
  1655. }
  1656. if ($value == 'sens') {
  1657. $valuetoshow = $langs->trans("Sens");
  1658. }
  1659. if ($value == 'category_type') {
  1660. $valuetoshow = $langs->trans("Calculated");
  1661. }
  1662. if ($value == 'formula') {
  1663. $valuetoshow = $langs->trans("Formula");
  1664. }
  1665. if ($value == 'paper_size') {
  1666. $valuetoshow = $langs->trans("PaperSize");
  1667. }
  1668. if ($value == 'orientation') {
  1669. $valuetoshow = $langs->trans("Orientation");
  1670. }
  1671. if ($value == 'leftmargin') {
  1672. $valuetoshow = $langs->trans("LeftMargin");
  1673. }
  1674. if ($value == 'topmargin') {
  1675. $valuetoshow = $langs->trans("TopMargin");
  1676. }
  1677. if ($value == 'spacex') {
  1678. $valuetoshow = $langs->trans("SpaceX");
  1679. }
  1680. if ($value == 'spacey') {
  1681. $valuetoshow = $langs->trans("SpaceY");
  1682. }
  1683. if ($value == 'font_size') {
  1684. $valuetoshow = $langs->trans("FontSize");
  1685. }
  1686. if ($value == 'custom_x') {
  1687. $valuetoshow = $langs->trans("CustomX");
  1688. }
  1689. if ($value == 'custom_y') {
  1690. $valuetoshow = $langs->trans("CustomY");
  1691. }
  1692. if ($value == 'percent') {
  1693. $valuetoshow = $langs->trans("Percentage");
  1694. }
  1695. if ($value == 'affect') {
  1696. $valuetoshow = $langs->trans("WithCounter");
  1697. }
  1698. if ($value == 'delay') {
  1699. $valuetoshow = $langs->trans("NoticePeriod");
  1700. }
  1701. if ($value == 'newbymonth') {
  1702. $valuetoshow = $langs->trans("NewByMonth");
  1703. }
  1704. if ($value == 'fk_tva') {
  1705. $valuetoshow = $langs->trans("VAT");
  1706. }
  1707. if ($value == 'range_ik') {
  1708. $valuetoshow = $langs->trans("RangeIk");
  1709. }
  1710. if ($value == 'fk_c_exp_tax_cat') {
  1711. $valuetoshow = $langs->trans("CarCategory");
  1712. }
  1713. if ($value == 'revenuestamp_type') {
  1714. $valuetoshow = $langs->trans('TypeOfRevenueStamp');
  1715. }
  1716. if ($value == 'use_default') {
  1717. $valuetoshow = $langs->trans('Default'); $cssprefix = 'center ';
  1718. }
  1719. if ($value == 'unit_type') {
  1720. $valuetoshow = $langs->trans('TypeOfUnit');
  1721. }
  1722. if ($value == 'public' && $tablib[$id] == 'TicketDictCategory') {
  1723. $valuetoshow = $langs->trans('TicketGroupIsPublic'); $cssprefix = 'center ';
  1724. }
  1725. if ($value == 'block_if_negative') {
  1726. $valuetoshow = $langs->trans('BlockHolidayIfNegative');
  1727. }
  1728. if ($value == 'type_duration') {
  1729. $valuetoshow = $langs->trans('Unit');
  1730. }
  1731. if ($value == 'region_id' || $value == 'country_id') {
  1732. $showfield = 0;
  1733. }
  1734. // Show field title
  1735. if ($showfield) {
  1736. $tooltiphelp = (isset($tabcomplete[$tabname[$id]]['help'][$value]) ? $tabcomplete[$tabname[$id]]['help'][$value] : '');
  1737. if ($tooltiphelp && preg_match('/^http(s*):/i', $tooltiphelp)) {
  1738. $newvaluetoshow = '<a href="'.$tooltiphelp.'" target="_blank">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  1739. } elseif ($tooltiphelp) {
  1740. $newvaluetoshow = $form->textwithpicto($valuetoshow, $tooltiphelp);
  1741. } else {
  1742. $newvaluetoshow = $valuetoshow;
  1743. }
  1744. print getTitleFieldOfList($newvaluetoshow, 0, $_SERVER["PHP_SELF"], ($sortable ? $value : ''), ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $cssprefix);
  1745. }
  1746. }
  1747. // Favorite & EEC - Only activated on country dictionary
  1748. if ($id == 4) {
  1749. print getTitleFieldOfList($langs->trans("InEEC"), 0, $_SERVER["PHP_SELF"], "eec", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder, '', 0, $langs->trans("CountryIsInEEC"));
  1750. print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
  1751. }
  1752. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, 'align="center"', $sortfield, $sortorder);
  1753. print getTitleFieldOfList('');
  1754. print getTitleFieldOfList('');
  1755. print '</tr>';
  1756. if ($num) {
  1757. // Lines with values
  1758. while ($i < $num) {
  1759. $obj = $db->fetch_object($resql);
  1760. //print_r($obj);
  1761. print '<tr class="oddeven" id="rowid-'.(empty($obj->rowid) ? '' : $obj->rowid).'">';
  1762. if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
  1763. $tmpaction = 'edit';
  1764. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1765. $reshook = $hookmanager->executeHooks('editDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1766. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1767. // Show fields
  1768. if (empty($reshook)) {
  1769. $withentity = fieldList($fieldlist, $obj, $tabname[$id], 'edit');
  1770. }
  1771. print '<td colspan="3" class="center">';
  1772. print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
  1773. print '<input type="hidden" name="page" value="'.dol_escape_htmltag($page).'">';
  1774. print '<input type="hidden" name="rowid" value="'.dol_escape_htmltag($rowid).'">';
  1775. if (!is_null($withentity)) {
  1776. print '<input type="hidden" name="entity" value="'.$withentity.'">';
  1777. }
  1778. print '<input type="submit" class="button button-edit" name="actionmodify" value="'.$langs->trans("Modify").'">';
  1779. print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  1780. print '</td>';
  1781. } else {
  1782. $tmpaction = 'view';
  1783. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1784. $reshook = $hookmanager->executeHooks('viewDictionaryFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1785. $error = $hookmanager->error; $errors = $hookmanager->errors;
  1786. if (empty($reshook)) {
  1787. $withentity = null;
  1788. foreach ($fieldlist as $field => $value) {
  1789. //var_dump($fieldlist);
  1790. $class = '';
  1791. $showfield = 1;
  1792. $valuetoshow = empty($obj->{$value}) ? '' : $obj->{$value};
  1793. $titletoshow = '';
  1794. if ($value == 'entity') {
  1795. $withentity = $valuetoshow;
  1796. continue;
  1797. }
  1798. if ($value == 'element') {
  1799. $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
  1800. } elseif ($value == 'source') {
  1801. $valuetoshow = isset($sourceList[$valuetoshow]) ? $sourceList[$valuetoshow] : $valuetoshow;
  1802. } elseif ($valuetoshow == 'all') {
  1803. $valuetoshow = $langs->trans('All');
  1804. } elseif ($value == 'country') {
  1805. if (empty($obj->country_code)) {
  1806. $valuetoshow = '-';
  1807. } else {
  1808. $key = $langs->trans("Country".strtoupper($obj->country_code));
  1809. $valuetoshow = ($key != "Country".strtoupper($obj->country_code) ? $obj->country_code." - ".$key : $obj->country);
  1810. }
  1811. } elseif ($value == 'recuperableonly' || $value == 'deductible' || $value == 'category_type') {
  1812. $valuetoshow = yn($valuetoshow);
  1813. $class = "center";
  1814. } elseif ($value == 'type_cdr') {
  1815. if (empty($valuetoshow)) {
  1816. $valuetoshow = $langs->trans('None');
  1817. } elseif ($valuetoshow == 1) {
  1818. $valuetoshow = $langs->trans('AtEndOfMonth');
  1819. } elseif ($valuetoshow == 2) {
  1820. $valuetoshow = $langs->trans('CurrentNext');
  1821. }
  1822. $class = "center";
  1823. } elseif ($value == 'price' || preg_match('/^amount/i', $value)) {
  1824. $valuetoshow = price($valuetoshow);
  1825. }
  1826. if ($value == 'private') {
  1827. $valuetoshow = yn($valuetoshow);
  1828. } elseif ($value == 'libelle_facture') {
  1829. $langs->load("bills");
  1830. $key = $langs->trans("PaymentCondition".strtoupper($obj->code));
  1831. $valuetoshow = ($obj->code && $key != "PaymentCondition".strtoupper($obj->code) ? $key : $obj->{$value});
  1832. $valuetoshow = nl2br($valuetoshow);
  1833. } elseif ($value == 'label' && $tabname[$id] == 'c_country') {
  1834. $key = $langs->trans("Country".strtoupper($obj->code));
  1835. $valuetoshow = ($obj->code && $key != "Country".strtoupper($obj->code) ? $key : $obj->{$value});
  1836. } elseif ($value == 'label' && $tabname[$id] == 'c_availability') {
  1837. $langs->load("propal");
  1838. $key = $langs->trans("AvailabilityType".strtoupper($obj->code));
  1839. $valuetoshow = ($obj->code && $key != "AvailabilityType".strtoupper($obj->code) ? $key : $obj->{$value});
  1840. } elseif ($value == 'libelle' && $tabname[$id] == 'c_actioncomm') {
  1841. $key = $langs->trans("Action".strtoupper($obj->code));
  1842. $valuetoshow = ($obj->code && $key != "Action".strtoupper($obj->code) ? $key : $obj->{$value});
  1843. } elseif (!empty($obj->code_iso) && $value == 'label' && $tabname[$id] == 'c_currencies') {
  1844. $key = $langs->trans("Currency".strtoupper($obj->code_iso));
  1845. $valuetoshow = ($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso) ? $key : $obj->{$value});
  1846. } elseif ($value == 'libelle' && $tabname[$id] == 'c_typent') {
  1847. $key = $langs->trans(strtoupper($obj->code));
  1848. $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->{$value});
  1849. } elseif ($value == 'libelle' && $tabname[$id] == 'c_prospectlevel') {
  1850. $key = $langs->trans(strtoupper($obj->code));
  1851. $valuetoshow = ($key != strtoupper($obj->code) ? $key : $obj->{$value});
  1852. } elseif ($value == 'label' && $tabname[$id] == 'c_civility') {
  1853. $key = $langs->trans("Civility".strtoupper($obj->code));
  1854. $valuetoshow = ($obj->code && $key != "Civility".strtoupper($obj->code) ? $key : $obj->{$value});
  1855. } elseif ($value == 'libelle' && $tabname[$id] == 'c_type_contact') {
  1856. $langs->load('agenda');
  1857. $key = $langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  1858. $valuetoshow = ($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code) ? $key : $obj->{$value});
  1859. } elseif ($value == 'libelle' && $tabname[$id] == 'c_payment_term') {
  1860. $langs->load("bills");
  1861. $key = $langs->trans("PaymentConditionShort".strtoupper($obj->code));
  1862. $valuetoshow = ($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code) ? $key : $obj->{$value});
  1863. } elseif ($value == 'libelle' && $tabname[$id] == 'c_paiement') {
  1864. $langs->load("bills");
  1865. $key = $langs->trans("PaymentType".strtoupper($obj->code));
  1866. $valuetoshow = ($obj->code && $key != "PaymentType".strtoupper($obj->code) ? $key : $obj->{$value});
  1867. } elseif ($value == 'type' && $tabname[$id] == 'c_paiement') {
  1868. $payment_type_list = array(0=>$langs->trans('PaymentTypeCustomer'), 1=>$langs->trans('PaymentTypeSupplier'), 2=>$langs->trans('PaymentTypeBoth'));
  1869. $valuetoshow = $payment_type_list[$valuetoshow];
  1870. } elseif ($value == 'label' && $tabname[$id] == 'c_input_reason') {
  1871. $key = $langs->trans("DemandReasonType".strtoupper($obj->code));
  1872. $valuetoshow = ($obj->code && $key != "DemandReasonType".strtoupper($obj->code) ? $key : $obj->{$value});
  1873. } elseif ($value == 'libelle' && $tabname[$id] == 'c_input_method') {
  1874. $langs->load("orders");
  1875. $key = $langs->trans($obj->code);
  1876. $valuetoshow = ($obj->code && $key != $obj->code) ? $key : $obj->{$value};
  1877. } elseif ($value == 'libelle' && $tabname[$id] == 'c_shipment_mode') {
  1878. $langs->load("sendings");
  1879. $key = $langs->trans("SendingMethod".strtoupper($obj->code));
  1880. $valuetoshow = ($obj->code && $key != "SendingMethod".strtoupper($obj->code) ? $key : $obj->{$value});
  1881. } elseif ($value == 'libelle' && $tabname[$id] == 'c_paper_format') {
  1882. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  1883. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$value});
  1884. } elseif ($value == 'label' && $tabname[$id] == 'c_type_fees') {
  1885. $langs->load('trips');
  1886. $key = $langs->trans(strtoupper($obj->code));
  1887. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$value});
  1888. } elseif ($value == 'region_id' || $value == 'country_id') {
  1889. $showfield = 0;
  1890. } elseif ($value == 'unicode') {
  1891. $valuetoshow = $langs->getCurrencySymbol($obj->code, 1);
  1892. } elseif ($value == 'label' && $tabname[GETPOST("id", 'int')] == 'c_units') {
  1893. $langs->load("products");
  1894. $valuetoshow = $langs->trans($obj->{$value});
  1895. } elseif ($value == 'short_label' && $tabname[GETPOST("id", 'int')] == 'c_units') {
  1896. $langs->load("products");
  1897. $valuetoshow = $langs->trans($obj->{$value});
  1898. } elseif (($value == 'unit') && ($tabname[$id] == 'c_paper_format')) {
  1899. $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
  1900. $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$value});
  1901. } elseif ($value == 'localtax1' || $value == 'localtax2') {
  1902. $class = "center";
  1903. } elseif ($value == 'localtax1_type') {
  1904. if ($obj->localtax1 != 0) {
  1905. $valuetoshow = $localtax_typeList[$valuetoshow];
  1906. } else {
  1907. $valuetoshow = '';
  1908. }
  1909. $class = "center";
  1910. } elseif ($value == 'localtax2_type') {
  1911. if ($obj->localtax2 != 0) {
  1912. $valuetoshow = $localtax_typeList[$valuetoshow];
  1913. } else {
  1914. $valuetoshow = '';
  1915. }
  1916. $class = "center";
  1917. } elseif ($value == 'taux') {
  1918. $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
  1919. $class = "center";
  1920. } elseif (in_array($value, array('recuperableonly'))) {
  1921. $class = "center";
  1922. } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
  1923. if (!empty($conf->accounting->enabled)) {
  1924. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
  1925. $tmpaccountingaccount = new AccountingAccount($db);
  1926. $tmpaccountingaccount->fetch(0, $valuetoshow, 1);
  1927. $titletoshow = $langs->transnoentitiesnoconv("Pcgtype").': '.$tmpaccountingaccount->pcg_type;
  1928. }
  1929. $valuetoshow = length_accountg($valuetoshow);
  1930. } elseif ($value == 'fk_tva') {
  1931. foreach ($form->cache_vatrates as $key => $Tab) {
  1932. if ($form->cache_vatrates[$key]['rowid'] == $valuetoshow) {
  1933. $valuetoshow = $form->cache_vatrates[$key]['label'];
  1934. break;
  1935. }
  1936. }
  1937. } elseif ($value == 'fk_c_exp_tax_cat') {
  1938. $tmpid = $valuetoshow;
  1939. $valuetoshow = getDictionaryValue('c_exp_tax_cat', 'label', $tmpid);
  1940. $valuetoshow = $langs->trans($valuetoshow ? $valuetoshow : $tmpid);
  1941. } elseif ($tabname[$id] == 'c_exp_tax_cat') {
  1942. $valuetoshow = $langs->trans($valuetoshow);
  1943. } elseif ($value == 'label' && $tabname[$id] == 'c_units') {
  1944. $langs->load('other');
  1945. $key = $langs->trans($obj->label);
  1946. $valuetoshow = ($obj->label && $key != strtoupper($obj->label) ? $key : $obj->{$value});
  1947. } elseif ($value == 'code' && $id == 3) {
  1948. $valuetoshow = $obj->state_code;
  1949. } elseif ($value == 'label' && $tabname[$id] == 'c_product_nature') {
  1950. $langs->load("products");
  1951. $valuetoshow = $langs->trans($obj->{$value});
  1952. } elseif ($fieldlist[$field] == 'label' && $tabname[$id] == 'c_productbatch_qcstatus') {
  1953. $langs->load("productbatch");
  1954. $valuetoshow = $langs->trans($obj->{$value});
  1955. } elseif ($value == 'block_if_negative') {
  1956. $valuetoshow = yn($obj->{$value});
  1957. } elseif ($value == 'icon') {
  1958. $valuetoshow = $obj->{$value}." ".img_picto("", $obj->{$value});
  1959. } elseif ($value == 'type_duration') {
  1960. $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'));
  1961. $valuetoshow =$TDurationTypes[$obj->{$value}];
  1962. }
  1963. $class .= ($class ? ' ' : '').'tddict';
  1964. if ($value == 'note' && $id == 10) {
  1965. $class .= ' tdoverflowmax200';
  1966. }
  1967. if ($value == 'tracking') {
  1968. $class .= ' tdoverflowauto';
  1969. }
  1970. if (in_array($value, array('nbjour', 'decalage', 'pos', 'position', 'deposit_percent'))) {
  1971. $class .= ' right';
  1972. }
  1973. if (in_array($value, array('localtax1_type', 'localtax2_type'))) {
  1974. $class .= ' nowrap';
  1975. }
  1976. if (in_array($value, array('use_default', 'fk_parent', 'sortorder'))) {
  1977. $class .= ' center';
  1978. }
  1979. if ($value == 'public') {
  1980. $class .= ' center';
  1981. }
  1982. // Show value for field
  1983. if ($showfield) {
  1984. print '<!-- '. $value .' --><td class="'.$class.'"'.($titletoshow ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.$valuetoshow.'</td>';
  1985. }
  1986. }
  1987. }
  1988. // Can an entry be erased or disabled ?
  1989. // all true by default
  1990. $iserasable = 1;
  1991. $canbedisabled = 1;
  1992. $canbemodified = 1;
  1993. if (isset($obj->code) && $id != 10 && $id != 42) {
  1994. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i', $obj->code))) {
  1995. $iserasable = 0; $canbedisabled = 0;
  1996. } elseif ($obj->code == 'RECEP') {
  1997. $iserasable = 0; $canbedisabled = 0;
  1998. } elseif ($obj->code == 'EF0') {
  1999. $iserasable = 0; $canbedisabled = 0;
  2000. }
  2001. }
  2002. if ($id == 25 && in_array($obj->code, array('banner', 'blogpost', 'other', 'page'))) {
  2003. $iserasable = 0; $canbedisabled = 0;
  2004. if (in_array($obj->code, array('banner'))) {
  2005. $canbedisabled = 1;
  2006. }
  2007. }
  2008. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) {
  2009. $iserasable = 0;
  2010. }
  2011. if (in_array(empty($obj->code) ? '' : $obj->code, array('AC_OTH', 'AC_OTH_AUTO')) || in_array(empty($obj->type) ? '' : $obj->type, array('systemauto'))) {
  2012. $canbedisabled = 0; $canbedisabled = 0;
  2013. }
  2014. $canbemodified = $iserasable;
  2015. if (!empty($obj->code) && $obj->code == 'RECEP') {
  2016. $canbemodified = 1;
  2017. }
  2018. if ($tabname[$id] == "c_actioncomm") {
  2019. $canbemodified = 1;
  2020. }
  2021. // Build Url. The table is id=, the id of line is rowid=
  2022. $rowidcol = $tabrowid[$id];
  2023. // If rowidcol not defined
  2024. if (empty($rowidcol) || in_array($id, array(6, 7, 8, 13, 17, 19, 27, 32))) {
  2025. $rowidcol = 'rowid';
  2026. }
  2027. $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) : '');
  2028. if (!empty($param)) {
  2029. $url .= '&'.$param;
  2030. }
  2031. if (!is_null($withentity)) {
  2032. $url .= '&entity='.$withentity;
  2033. }
  2034. $url .= '&';
  2035. // Favorite & EEC
  2036. // Only activated on country dictionary
  2037. if ($id == 4) {
  2038. print '<td class="nowrap center">';
  2039. // Is in EEC
  2040. if ($iserasable) {
  2041. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->eec].'_eec&token='.newToken().'">'.$actl[$obj->eec].'</a>';
  2042. } else {
  2043. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2044. }
  2045. print '</td>';
  2046. print '<td class="nowrap center">';
  2047. // Favorite
  2048. if ($iserasable) {
  2049. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->favorite].'_favorite&token='.newToken().'">'.$actl[$obj->favorite].'</a>';
  2050. } else {
  2051. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2052. }
  2053. print '</td>';
  2054. }
  2055. // Active
  2056. print '<td class="nowrap center">';
  2057. if ($canbedisabled) {
  2058. print '<a class="reposition" href="'.$url.'action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
  2059. } else {
  2060. if (in_array($obj->code, array('AC_OTH', 'AC_OTH_AUTO'))) {
  2061. print $langs->trans("AlwaysActive");
  2062. } elseif (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) {
  2063. print $langs->trans("Deprecated");
  2064. } elseif (isset($obj->type) && in_array($obj->type, array('system')) && !empty($obj->active) && $obj->code != 'AC_OTH') {
  2065. print $langs->trans("UsedOnlyWithTypeOption");
  2066. } else {
  2067. print '<span class="opacitymedium">'.$langs->trans("AlwaysActive").'</span>';
  2068. }
  2069. }
  2070. print "</td>";
  2071. // Modify link
  2072. if ($canbemodified) {
  2073. print '<td align="center"><a class="reposition editfielda" href="'.$url.'action=edit&token='.newToken().'">'.img_edit().'</a></td>';
  2074. } else {
  2075. print '<td>&nbsp;</td>';
  2076. }
  2077. // Delete link
  2078. if ($iserasable) {
  2079. print '<td class="center">';
  2080. if ($user->admin) {
  2081. print '<a class="reposition" href="'.$url.'action=delete&token='.newToken().'">'.img_delete().'</a>';
  2082. }
  2083. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  2084. print '</td>';
  2085. } else {
  2086. print '<td>&nbsp;</td>';
  2087. }
  2088. print "</tr>\n";
  2089. }
  2090. $i++;
  2091. }
  2092. }
  2093. print '</table>';
  2094. print '</div>';
  2095. } else {
  2096. dol_print_error($db);
  2097. }
  2098. print '</form>';
  2099. } else {
  2100. /*
  2101. * Show list of dictionary to show
  2102. */
  2103. $lastlineisempty = false;
  2104. print '<div class="div-table-responsive-no-min">';
  2105. print '<table class="noborder centpercent">';
  2106. print '<tr class="liste_titre">';
  2107. print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
  2108. print '<td></td>';
  2109. print '</tr>';
  2110. $showemptyline = '';
  2111. foreach ($taborder as $i) {
  2112. if (isset($tabname[$i]) && empty($tabcond[$i])) {
  2113. continue;
  2114. }
  2115. if ($i) {
  2116. if ($showemptyline) {
  2117. print '<tr class="oddeven"><td width="50%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  2118. $showemptyline = 0;
  2119. }
  2120. $value = $tabname[$i];
  2121. print '<tr class="oddeven"><td width="50%">';
  2122. if (!empty($tabcond[$i])) {
  2123. $tabnamenoprefix = preg_replace('/'.MAIN_DB_PREFIX.'/', '', $tabname[$i]);
  2124. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">';
  2125. if (!empty($tabcomplete[$tabnamenoprefix]['picto'])) {
  2126. print img_picto('', $tabcomplete[$tabnamenoprefix]['picto'], 'class="pictofixedwidth paddingrightonly"');
  2127. }
  2128. print $langs->trans($tablib[$i]);
  2129. print '</a>';
  2130. } else {
  2131. print $langs->trans($tablib[$i]);
  2132. }
  2133. print '</td>';
  2134. print '<td>';
  2135. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">';
  2136. print img_picto('Edit', 'edit', '');
  2137. print '</a>';
  2138. print '</td>';
  2139. print '<td class="right">';
  2140. print $form->textwithpicto('', $langs->trans("Table").': '.MAIN_DB_PREFIX.$tabname[$i]);
  2141. print '</td>';
  2142. print '</tr>';
  2143. $lastlineisempty = false;
  2144. } else {
  2145. if (!$lastlineisempty) {
  2146. $showemptyline = 1;
  2147. $lastlineisempty = true;
  2148. }
  2149. }
  2150. }
  2151. print '</table>';
  2152. print '</div>';
  2153. }
  2154. print '<br>';
  2155. // End of page
  2156. llxFooter();
  2157. $db->close();
  2158. /**
  2159. * Show fields in insert/edit mode
  2160. *
  2161. * @param array $fieldlist Array of fields
  2162. * @param Object $obj If we show a particular record, obj is filled with record fields
  2163. * @param string $tabname Name of SQL table
  2164. * @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
  2165. * @return string '' or value of entity into table
  2166. */
  2167. function fieldList($fieldlist, $obj = '', $tabname = '', $context = '')
  2168. {
  2169. global $conf, $langs, $db, $mysoc;
  2170. global $form;
  2171. global $region_id;
  2172. global $elementList, $sourceList, $localtax_typeList;
  2173. $formadmin = new FormAdmin($db);
  2174. $formcompany = new FormCompany($db);
  2175. $formaccounting = new FormAccounting($db);
  2176. $withentity = '';
  2177. foreach ($fieldlist as $field => $value) {
  2178. if ($value == 'entity') {
  2179. $withentity = $obj->{$value};
  2180. continue;
  2181. }
  2182. if (in_array($value, array('code', 'libelle', 'type')) && $tabname == "c_actioncomm" && in_array($obj->type, array('system', 'systemauto'))) {
  2183. $hidden = (!empty($obj->{$value}) ? $obj->{$value}:'');
  2184. print '<td>';
  2185. print '<input type="hidden" name="'. $value .'" value="'.$hidden.'">';
  2186. print $langs->trans($hidden);
  2187. print '</td>';
  2188. } elseif ($value == 'country') {
  2189. if (in_array('region_id', $fieldlist)) {
  2190. print '<td>';
  2191. print '</td>';
  2192. continue;
  2193. } // For state page, we do not show the country input (we link to region, not country)
  2194. print '<td>';
  2195. $fieldname = 'country';
  2196. print $form->select_country((!empty($obj->country_code) ? $obj->country_code : (!empty($obj->country) ? $obj->country : '')), $fieldname, '', 28, 'maxwidth150 maxwidthonsmartphone');
  2197. print '</td>';
  2198. } elseif ($value == 'country_id') {
  2199. if (!in_array('country', $fieldlist)) { // If there is already a field country, we don't show country_id (avoid duplicate)
  2200. $country_id = (!empty($obj->{$value}) ? $obj->{$value} : 0);
  2201. print '<td class="tdoverflowmax100">';
  2202. print '<input type="hidden" name="'. $value .'" value="'.$country_id.'">';
  2203. print '</td>';
  2204. }
  2205. } elseif ($value == 'region') {
  2206. print '<td>';
  2207. $formcompany->select_region($region_id, 'region');
  2208. print '</td>';
  2209. } elseif ($value == 'region_id') {
  2210. $region_id = (!empty($obj->{$value}) ? $obj->{$value}:0);
  2211. print '<td>';
  2212. print '<input type="hidden" name="'. $value .'" value="'.$region_id.'">';
  2213. print '</td>';
  2214. } elseif ($value == 'lang') {
  2215. print '<td>';
  2216. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT, 'lang');
  2217. print '</td>';
  2218. } elseif (in_array($value, array('element', 'source'))) { // Example: the type and source of the element (for contact types)
  2219. $tmparray = array();
  2220. if ($value == 'element') {
  2221. $tmparray = $elementList;
  2222. } else {
  2223. $tmparray = $sourceList;
  2224. }
  2225. print '<td>';
  2226. print $form->selectarray($value, $tmparray, (!empty($obj->{$value}) ? $obj->{$value}:''), 0, 0, 0, '', 0, 0, 0, '', 'maxwidth250');
  2227. print '</td>';
  2228. } elseif (in_array($value, array('public', 'use_default'))) {
  2229. // Fields 0/1 with a combo select Yes/No
  2230. print '<td class="center">';
  2231. print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2232. print '</td>';
  2233. } elseif ($value == 'private') {
  2234. // Fields 'no'/'yes' with a combo select Yes/No
  2235. print '<td>';
  2236. print $form->selectyesno("private", (!empty($obj->{$value}) ? $obj->{$value}:''));
  2237. print '</td>';
  2238. } elseif ($value == 'type' && $tabname == "c_actioncomm") {
  2239. $type = (!empty($obj->type) ? $obj->type : 'user'); // Check if type is different of 'user' (external module)
  2240. print '<td>';
  2241. print $type.'<input type="hidden" name="type" value="'.$type.'">';
  2242. print '</td>';
  2243. } elseif ($value == 'type' && $tabname == 'c_paiement') {
  2244. print '<td>';
  2245. $select_list = array(0=>$langs->trans('PaymentTypeCustomer'), 1=>$langs->trans('PaymentTypeSupplier'), 2=>$langs->trans('PaymentTypeBoth'));
  2246. print $form->selectarray($value, $select_list, (!empty($obj->{$value}) ? $obj->{$value}:'2'));
  2247. print '</td>';
  2248. } elseif ($value == 'recuperableonly' || $value == 'type_cdr' || $value == 'deductible' || $value == 'category_type') {
  2249. if ($value == 'type_cdr') {
  2250. print '<td class="center">';
  2251. } else {
  2252. print '<td>';
  2253. }
  2254. if ($value == 'type_cdr') {
  2255. print $form->selectarray($value, array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (!empty($obj->{$value}) ? $obj->{$value}:''));
  2256. } else {
  2257. print $form->selectyesno($value, (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2258. }
  2259. print '</td>';
  2260. } elseif (in_array($value, array('nbjour', 'decalage', 'taux', 'localtax1', 'localtax2'))) {
  2261. $class = "right";
  2262. if (in_array($value, array('taux', 'localtax1', 'localtax2'))) {
  2263. $class = "center"; // Fields aligned on right
  2264. }
  2265. print '<td class="'.$class.'">';
  2266. print '<input type="text" class="flat" value="'.(isset($obj->{$value}) ? $obj->{$value} : '').'" size="3" name="'. $value .'">';
  2267. print '</td>';
  2268. } elseif (in_array($value, array('libelle_facture'))) {
  2269. print '<td>';
  2270. $transfound = 0;
  2271. $transkey = '';
  2272. // Special case for labels
  2273. if ($tabname == 'c_payment_term') {
  2274. $langs->load("bills");
  2275. $transkey = "PaymentCondition".strtoupper($obj->code);
  2276. if ($langs->trans($transkey) != $transkey) {
  2277. $transfound = 1;
  2278. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  2279. }
  2280. }
  2281. if (!$transfound) {
  2282. print '<textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'. $value .'">'.(!empty($obj->{$value}) ? $obj->{$value}:'').'</textarea>';
  2283. } else {
  2284. print '<input type="hidden" name="'. $value .'" value="'.$transkey.'">';
  2285. }
  2286. print '</td>';
  2287. } elseif ($value == 'price' || preg_match('/^amount/i', $value)) {
  2288. print '<td><input type="text" class="flat minwidth75" value="'.price((!empty($obj->{$value}) ? $obj->{$value}:'')).'" name="'. $value .'"></td>';
  2289. } elseif ($value == 'code' && isset($obj->{$value})) {
  2290. print '<td><input type="text" class="flat minwidth75 maxwidth100" value="'.(!empty($obj->{$value}) ? $obj->{$value}:'').'" name="'. $value .'"></td>';
  2291. } elseif ($value == 'unit') {
  2292. print '<td>';
  2293. $units = array(
  2294. 'mm' => $langs->trans('SizeUnitmm'),
  2295. 'cm' => $langs->trans('SizeUnitcm'),
  2296. 'point' => $langs->trans('SizeUnitpoint'),
  2297. 'inch' => $langs->trans('SizeUnitinch')
  2298. );
  2299. print $form->selectarray('unit', $units, (!empty($obj->{$value}) ? $obj->{$value}:''), 0, 0, 0);
  2300. print '</td>';
  2301. } elseif ($value == 'localtax1_type' || $value == 'localtax2_type') {
  2302. // Le type de taxe locale
  2303. print '<td class="center">';
  2304. print $form->selectarray($value, $localtax_typeList, (!empty($obj->{$value}) ? $obj->{$value}:''));
  2305. print '</td>';
  2306. } elseif ($value == 'accountancy_code' || $value == 'accountancy_code_sell' || $value == 'accountancy_code_buy') {
  2307. print '<td>';
  2308. if (!empty($conf->accounting->enabled)) {
  2309. $fieldname = $value;
  2310. $accountancy_account = (!empty($obj->$fieldname) ? $obj->$fieldname : 0);
  2311. print $formaccounting->select_account($accountancy_account, '.'. $value, 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  2312. } else {
  2313. $fieldname = $value;
  2314. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname) ? $obj->$fieldname : '').'" name="'. $value .'">';
  2315. }
  2316. print '</td>';
  2317. } elseif ($value == 'fk_tva') {
  2318. print '<td>';
  2319. print $form->load_tva('fk_tva', $obj->taux, $mysoc, new Societe($db), 0, 0, '', false, -1);
  2320. print '</td>';
  2321. } elseif ($value == 'fk_c_exp_tax_cat') {
  2322. print '<td>';
  2323. print $form->selectExpenseCategories($obj->fk_c_exp_tax_cat);
  2324. print '</td>';
  2325. } elseif ($value == 'fk_range') {
  2326. print '<td>';
  2327. print $form->selectExpenseRanges($obj->fk_range);
  2328. print '</td>';
  2329. } elseif ($value == 'block_if_negative') {
  2330. print '<td>';
  2331. print $form->selectyesno("block_if_negative", (!empty($obj->{$value}) ? $obj->{$value}:''), 1);
  2332. print '</td>';
  2333. } elseif ($value == 'type_duration') {
  2334. print '<td>';
  2335. print $form->selectTypeDuration('', $obj->{$value}, array('i','h'));
  2336. print '</td>';
  2337. } else {
  2338. $fieldValue = isset($obj->{$value}) ? $obj->{$value}: '';
  2339. $classtd = ''; $class = '';
  2340. if ($value == 'sortorder') {
  2341. $fieldlist[$field] = 'position';
  2342. }
  2343. if ($fieldlist[$field] == 'code') {
  2344. $class = 'maxwidth100';
  2345. }
  2346. if (in_array($fieldlist[$field], array('deposit_percent'))) {
  2347. $classtd = 'right'; $class = 'maxwidth50 right';
  2348. }
  2349. if (in_array($fieldlist[$field], array('pos', 'position'))) {
  2350. $classtd = 'center'; $class = 'maxwidth50 center';
  2351. }
  2352. if (in_array($fieldlist[$field], array('dayrule', 'day', 'month', 'year', 'use_default', 'affect', 'delay', 'public', 'sortorder', 'sens', 'category_type', 'fk_parent'))) {
  2353. $class = 'maxwidth50 center';
  2354. }
  2355. if (in_array($fieldlist[$field], array('use_default', 'public', 'fk_parent'))) {
  2356. $classtd = 'center';
  2357. }
  2358. if (in_array($fieldlist[$field], array('libelle', 'label', 'tracking'))) {
  2359. $class = 'quatrevingtpercent';
  2360. }
  2361. // Fields that must be suggested as '0' instead of ''
  2362. if ($fieldlist[$field] == 'fk_parent') {
  2363. if (empty($fieldValue)) {
  2364. $fieldValue = '0';
  2365. }
  2366. }
  2367. // Labels Length
  2368. $maxlength = '';
  2369. if (in_array($fieldlist[$field], array('libelle', 'label'))) {
  2370. switch ($tabname) {
  2371. case 'c_accounting_category':
  2372. case 'c_ecotaxe':
  2373. case 'c_email_senderprofile':
  2374. case 'c_forme_juridique':
  2375. case 'c_holiday_types':
  2376. case 'c_payment_term':
  2377. case 'c_transport_mode':
  2378. $maxlength = ' maxlength="255"';
  2379. break;
  2380. case 'c_email_templates':
  2381. $maxlength = ' maxlength="180"';
  2382. break;
  2383. case 'c_socialnetworks':
  2384. $maxlength = ' maxlength="150"';
  2385. break;
  2386. default:
  2387. $maxlength = ' maxlength="128"';
  2388. }
  2389. }
  2390. print '<td class="'.$classtd.'">';
  2391. $transfound = 0;
  2392. $transkey = '';
  2393. if (in_array($fieldlist[$field], array('label', 'libelle'))) { // For label
  2394. // Special case for labels
  2395. if ($tabname == 'c_civility' && !empty($obj->code)) {
  2396. $transkey = "Civility".strtoupper($obj->code);
  2397. }
  2398. if ($tabname == 'c_payment_term' && !empty($obj->code)) {
  2399. $langs->load("bills");
  2400. $transkey = "PaymentConditionShort".strtoupper($obj->code);
  2401. }
  2402. if ($transkey && $langs->trans($transkey) != $transkey) {
  2403. $transfound = 1;
  2404. print $form->textwithpicto($langs->trans($transkey), $langs->trans("GoIntoTranslationMenuToChangeThis"));
  2405. }
  2406. }
  2407. if (!$transfound) {
  2408. print '<input type="text" class="flat'.($class ? ' '.$class : '').'"'.($maxlength ? ' '.$maxlength : '').' value="'.dol_escape_htmltag($fieldValue).'" name="'.$fieldlist[$field].'">';
  2409. } else {
  2410. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$transkey.'">';
  2411. }
  2412. print '</td>';
  2413. }
  2414. }
  2415. return $withentity;
  2416. }