dict.php 103 KB

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