dict.php 97 KB

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