dict.php 100 KB

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