dict.php 100 KB

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