dict.php 106 KB

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