dict.php 108 KB

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