dict.php 110 KB

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