dict.php 114 KB

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