accountmodel.php 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  6. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011-2015 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
  9. * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
  11. * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  12. * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/accountancy/admin/accountmodel.php
  30. * \ingroup Advanced accountancy
  31. * \brief Page to administer model of chart of accounts
  32. */
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  40. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  41. $langs->load("errors");
  42. $langs->load("admin");
  43. $langs->load("main");
  44. $langs->load("companies");
  45. $langs->load("resource");
  46. $langs->load("holiday");
  47. $langs->load("accountancy");
  48. $langs->load("hrm");
  49. $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
  50. $confirm=GETPOST('confirm','alpha');
  51. $id=GETPOST('id','int');
  52. $rowid=GETPOST('rowid','alpha');
  53. $acts[0] = "activate";
  54. $acts[1] = "disable";
  55. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  56. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  57. $listoffset=GETPOST('listoffset');
  58. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  59. $active = 1;
  60. $sortfield = GETPOST("sortfield",'alpha');
  61. $sortorder = GETPOST("sortorder",'alpha');
  62. $page = GETPOST("page",'int');
  63. if ($page == -1) { $page = 0 ; }
  64. $offset = $listlimit * $page ;
  65. $pageprev = $page - 1;
  66. $pagenext = $page + 1;
  67. $search_country_id = GETPOST('search_country_id','int');
  68. // Security check
  69. if ($user->societe_id > 0) accessforbidden();
  70. if (! $user->rights->accounting->chartofaccount) accessforbidden();
  71. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  72. $hookmanager->initHooks(array('admin'));
  73. // This page is a generic page to edit dictionaries
  74. // Put here declaration of dictionaries properties
  75. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  76. $taborder=array(9,0,4,3,2,0,1,8,19,16,27,0,5,11,0,33,34,0,6,0,29,0,7,17,24,28,0,10,23,12,13,0,14,0,22,20,18,21,0,15,30,0,25,0,26,0,31,32,0);
  77. // Name of SQL tables of dictionaries
  78. $tabname=array();
  79. $tabname[31]= MAIN_DB_PREFIX."accounting_system";
  80. $tabname[32]= MAIN_DB_PREFIX."c_accounting_category";
  81. // Dictionary labels
  82. $tablib=array();
  83. $tablib[31]= "Pcg_version";
  84. $tablib[32]= "DictionaryAccountancyCategory";
  85. // Requests to extract data
  86. $tabsql=array();
  87. $tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s";
  88. $tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.sens, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1";
  89. // Criteria to sort dictionaries
  90. $tabsqlsort=array();
  91. $tabsqlsort[31]="pcg_version ASC";
  92. $tabsqlsort[32]="position ASC";
  93. // Nom des champs en resultat de select pour affichage du dictionnaire
  94. $tabfield=array();
  95. $tabfield[31]= "pcg_version,label";
  96. $tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country";
  97. // Nom des champs d'edition pour modification d'un enregistrement
  98. $tabfieldvalue=array();
  99. $tabfieldvalue[31]= "pcg_version,label";
  100. $tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country";
  101. // Nom des champs dans la table pour insertion d'un enregistrement
  102. $tabfieldinsert=array();
  103. $tabfieldinsert[31]= "pcg_version,label";
  104. $tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
  105. // Nom du rowid si le champ n'est pas de type autoincrement
  106. // Example: "" if id field is "rowid" and has autoincrement on
  107. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  108. $tabrowid=array();
  109. $tabrowid[31]= "";
  110. $tabrowid[32]= "";
  111. // Condition to show dictionary in setup page
  112. $tabcond=array();
  113. $tabcond[31]= ! empty($conf->accounting->enabled);
  114. $tabcond[32]= ! empty($conf->accounting->enabled);
  115. // List of help for fields
  116. $tabhelp=array();
  117. $tabhelp[31] = array('pcg_version'=>$langs->trans("EnterAnyCode"));
  118. $tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"));
  119. // List of check for fields (NOT USED YET)
  120. $tabfieldcheck=array();
  121. $tabfieldcheck[31] = array();
  122. $tabfieldcheck[32] = array();
  123. // Complete all arrays with entries found into modules
  124. complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
  125. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  126. $elementList = array();
  127. $sourceList=array();
  128. if ($id == 11)
  129. {
  130. $langs->load("orders");
  131. $langs->load("contracts");
  132. $langs->load("projects");
  133. $langs->load("propal");
  134. $langs->load("bills");
  135. $langs->load("interventions");
  136. $elementList = array(
  137. '' => '',
  138. 'societe' => $langs->trans('ThirdParty'),
  139. // 'proposal' => $langs->trans('Proposal'),
  140. // 'order' => $langs->trans('Order'),
  141. // 'invoice' => $langs->trans('Bill'),
  142. 'invoice_supplier' => $langs->trans('SupplierBill'),
  143. 'order_supplier' => $langs->trans('SupplierOrder'),
  144. // 'intervention' => $langs->trans('InterventionCard'),
  145. // 'contract' => $langs->trans('Contract'),
  146. 'project' => $langs->trans('Project'),
  147. 'project_task' => $langs->trans('Task'),
  148. 'agenda' => $langs->trans('Agenda'),
  149. // old deprecated
  150. 'contrat' => $langs->trans('Contract'),
  151. 'propal' => $langs->trans('Proposal'),
  152. 'commande' => $langs->trans('Order'),
  153. 'facture' => $langs->trans('Bill'),
  154. 'resource' => $langs->trans('Resource'),
  155. // 'facture_fourn' => $langs->trans('SupplierBill'),
  156. 'fichinter' => $langs->trans('InterventionCard')
  157. );
  158. if (! empty($conf->global->MAIN_SUPPORT_SHARED_CONTACT_BETWEEN_THIRDPARTIES)) $elementList["societe"] = $langs->trans('ThirdParty');
  159. complete_elementList_with_modules($elementList);
  160. asort($elementList);
  161. $sourceList = array(
  162. 'internal' => $langs->trans('Internal'),
  163. 'external' => $langs->trans('External')
  164. );
  165. }
  166. if ($id == 25)
  167. {
  168. // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
  169. $elementList = array();
  170. if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSendProposal');
  171. if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder');
  172. if ($conf->facture->enabled) $elementList['facture_send']=$langs->trans('MailToSendInvoice');
  173. if ($conf->expedition->enabled) $elementList['shipping_send']=$langs->trans('MailToSendShipment');
  174. if ($conf->ficheinter->enabled) $elementList['fichinter_send']=$langs->trans('MailToSendIntervention');
  175. if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send']=$langs->trans('MailToSendSupplierRequestForQuotation');
  176. if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$langs->trans('MailToSendSupplierOrder');
  177. if ($conf->fournisseur->enabled) $elementList['invoice_supplier_send']=$langs->trans('MailToSendSupplierInvoice');
  178. if ($conf->societe->enabled) $elementList['thirdparty']=$langs->trans('MailToThirdparty');
  179. $parameters=array('elementList'=>$elementList);
  180. $reshook=$hookmanager->executeHooks('emailElementlist',$parameters); // Note that $action and $object may have been modified by some hooks
  181. if ($reshook == 0) {
  182. foreach ($hookmanager->resArray as $item => $value) {
  183. $elementList[$item] = $value;
  184. }
  185. }
  186. }
  187. // Define localtax_typeList (used for dictionary "llx_c_tva")
  188. $localtax_typeList = array();
  189. if ($id == 10)
  190. {
  191. $localtax_typeList = array(
  192. "0" => $langs->trans("No"),
  193. "1" => $langs->trans("Yes").' ('.$langs->trans("Type")." 1)", //$langs->trans("%ageOnAllWithoutVAT"),
  194. "2" => $langs->trans("Yes").' ('.$langs->trans("Type")." 2)", //$langs->trans("%ageOnAllBeforeVAT"),
  195. "3" => $langs->trans("Yes").' ('.$langs->trans("Type")." 3)", //$langs->trans("%ageOnProductsWithoutVAT"),
  196. "4" => $langs->trans("Yes").' ('.$langs->trans("Type")." 4)", //$langs->trans("%ageOnProductsBeforeVAT"),
  197. "5" => $langs->trans("Yes").' ('.$langs->trans("Type")." 5)", //$langs->trans("%ageOnServiceWithoutVAT"),
  198. "6" => $langs->trans("Yes").' ('.$langs->trans("Type")." 6)" //$langs->trans("%ageOnServiceBeforeVAT"),
  199. );
  200. }
  201. /*
  202. * Actions
  203. */
  204. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  205. {
  206. $search_country_id = '';
  207. }
  208. // Actions add or modify an entry into a dictionary
  209. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  210. {
  211. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  212. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  213. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  214. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  215. // Check that all fields are filled
  216. $ok=1;
  217. foreach ($listfield as $f => $value)
  218. {
  219. if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancysystem','DictionaryAccountancyCategory'))) continue; // For some pages, country is not mandatory
  220. if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
  221. if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
  222. if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
  223. if ($value == 'color' && empty($_POST['color'])) continue;
  224. if ($value == 'formula' && empty($_POST['formula'])) continue;
  225. if ((! isset($_POST[$value]) || $_POST[$value]=='')
  226. && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
  227. && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
  228. )
  229. )
  230. {
  231. $ok=0;
  232. $fieldnamekey=$listfield[$f];
  233. // We take translate key of field
  234. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  235. if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
  236. if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
  237. if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
  238. if ($fieldnamekey == 'module') $fieldnamekey='Module';
  239. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  240. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  241. if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
  242. if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
  243. if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
  244. if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
  245. if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible';
  246. if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder';
  247. if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
  248. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  249. }
  250. }
  251. // Other checks
  252. if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
  253. $ok=0;
  254. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  255. }
  256. if (isset($_POST["code"]))
  257. {
  258. if ($_POST["code"]=='0')
  259. {
  260. $ok=0;
  261. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  262. }
  263. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  264. {
  265. $ok = 0;
  266. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
  267. }*/
  268. }
  269. if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
  270. {
  271. if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
  272. {
  273. $_POST["country"]='';
  274. }
  275. else
  276. {
  277. $ok=0;
  278. setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
  279. }
  280. }
  281. if ($id == 3 && ! is_numeric($_POST["code"]))
  282. {
  283. $ok=0;
  284. setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric",$langs->transnoentities("Code")), null, 'errors');
  285. }
  286. // Clean some parameters
  287. if (isset($_POST["localtax1"]) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
  288. if (isset($_POST["localtax2"]) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
  289. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  290. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  291. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  292. // Si verif ok et action add, on ajoute la ligne
  293. if ($ok && GETPOST('actionadd'))
  294. {
  295. if ($tabrowid[$id])
  296. {
  297. // Recupere id libre pour insertion
  298. $newid=0;
  299. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  300. $result = $db->query($sql);
  301. if ($result)
  302. {
  303. $obj = $db->fetch_object($result);
  304. $newid=($obj->newid + 1);
  305. } else {
  306. dol_print_error($db);
  307. }
  308. }
  309. // Add new entry
  310. $sql = "INSERT INTO ".$tabname[$id]." (";
  311. // List of fields
  312. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  313. $sql.= $tabrowid[$id].",";
  314. $sql.= $tabfieldinsert[$id];
  315. $sql.=",active)";
  316. $sql.= " VALUES(";
  317. // List of values
  318. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  319. $sql.= $newid.",";
  320. $i=0;
  321. foreach ($listfieldinsert as $f => $value)
  322. {
  323. if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
  324. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  325. }
  326. else if ($value == 'entity') {
  327. $_POST[$listfieldvalue[$i]] = $conf->entity;
  328. }
  329. if ($i) $sql.=",";
  330. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  331. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  332. $i++;
  333. }
  334. $sql.=",1)";
  335. dol_syslog("actionadd", LOG_DEBUG);
  336. $result = $db->query($sql);
  337. if ($result) // Add is ok
  338. {
  339. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  340. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  341. }
  342. else
  343. {
  344. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  345. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  346. }
  347. else {
  348. dol_print_error($db);
  349. }
  350. }
  351. }
  352. // Si verif ok et action modify, on modifie la ligne
  353. if ($ok && GETPOST('actionmodify'))
  354. {
  355. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  356. else { $rowidcol="rowid"; }
  357. // Modify entry
  358. $sql = "UPDATE ".$tabname[$id]." SET ";
  359. // Modifie valeur des champs
  360. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  361. {
  362. $sql.= $tabrowid[$id]."=";
  363. $sql.= "'".$db->escape($rowid)."', ";
  364. }
  365. $i = 0;
  366. foreach ($listfieldmodify as $field)
  367. {
  368. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  369. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  370. }
  371. else if ($field == 'entity') {
  372. $_POST[$listfieldvalue[$i]] = $conf->entity;
  373. }
  374. if ($i) $sql.=",";
  375. $sql.= $field."=";
  376. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  377. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  378. $i++;
  379. }
  380. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  381. dol_syslog("actionmodify", LOG_DEBUG);
  382. //print $sql;
  383. $resql = $db->query($sql);
  384. if (! $resql)
  385. {
  386. setEventMessages($db->error(), null, 'errors');
  387. }
  388. }
  389. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  390. }
  391. if (GETPOST('actioncancel'))
  392. {
  393. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  394. }
  395. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  396. {
  397. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  398. else { $rowidcol="rowid"; }
  399. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  400. dol_syslog("delete", LOG_DEBUG);
  401. $result = $db->query($sql);
  402. if (! $result)
  403. {
  404. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  405. {
  406. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  407. }
  408. else
  409. {
  410. dol_print_error($db);
  411. }
  412. }
  413. }
  414. // activate
  415. if ($action == $acts[0])
  416. {
  417. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  418. else { $rowidcol="rowid"; }
  419. if ($rowid) {
  420. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  421. }
  422. elseif ($_GET["code"]) {
  423. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'";
  424. }
  425. $result = $db->query($sql);
  426. if (!$result)
  427. {
  428. dol_print_error($db);
  429. }
  430. }
  431. // disable
  432. if ($action == $acts[1])
  433. {
  434. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  435. else { $rowidcol="rowid"; }
  436. if ($rowid) {
  437. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  438. }
  439. elseif ($_GET["code"]) {
  440. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'";
  441. }
  442. $result = $db->query($sql);
  443. if (!$result)
  444. {
  445. dol_print_error($db);
  446. }
  447. }
  448. // favorite
  449. if ($action == 'activate_favorite')
  450. {
  451. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  452. else { $rowidcol="rowid"; }
  453. if ($rowid) {
  454. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'";
  455. }
  456. elseif ($_GET["code"]) {
  457. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$_GET["code"]."'";
  458. }
  459. $result = $db->query($sql);
  460. if (!$result)
  461. {
  462. dol_print_error($db);
  463. }
  464. }
  465. // disable favorite
  466. if ($action == 'disable_favorite')
  467. {
  468. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  469. else { $rowidcol="rowid"; }
  470. if ($rowid) {
  471. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'";
  472. }
  473. elseif ($_GET["code"]) {
  474. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$_GET["code"]."'";
  475. }
  476. $result = $db->query($sql);
  477. if (!$result)
  478. {
  479. dol_print_error($db);
  480. }
  481. }
  482. /*
  483. * View
  484. */
  485. $form = new Form($db);
  486. $formadmin=new FormAdmin($db);
  487. llxHeader();
  488. $titre=$langs->trans($tablib[$id]);
  489. $linkback='';
  490. print load_fiche_titre($titre,$linkback,'title_accountancy');
  491. if (empty($id))
  492. {
  493. print $langs->trans("DictionaryDesc");
  494. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  495. }
  496. print "<br>\n";
  497. // Confirmation de la suppression de la ligne
  498. if ($action == 'delete')
  499. {
  500. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$_GET["code"].'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  501. }
  502. //var_dump($elementList);
  503. /*
  504. * Show a dictionary
  505. */
  506. if ($id)
  507. {
  508. // Complete requete recherche valeurs avec critere de tri
  509. $sql=$tabsql[$id];
  510. if ($search_country_id > 0)
  511. {
  512. if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
  513. else $sql.=" WHERE ";
  514. $sql.= " c.rowid = ".$search_country_id;
  515. }
  516. if ($sortfield)
  517. {
  518. // If sort order is "country", we use country_code instead
  519. if ($sortfield == 'country') $sortfield='country_code';
  520. $sql.= " ORDER BY ".$sortfield;
  521. if ($sortorder)
  522. {
  523. $sql.=" ".strtoupper($sortorder);
  524. }
  525. $sql.=", ";
  526. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  527. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  528. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  529. }
  530. else {
  531. $sql.=" ORDER BY ";
  532. }
  533. $sql.=$tabsqlsort[$id];
  534. $sql.=$db->plimit($listlimit+1,$offset);
  535. //print $sql;
  536. $fieldlist=explode(',',$tabfield[$id]);
  537. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  538. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  539. print '<table class="noborder" width="100%">';
  540. // Form to add a new line
  541. if ($tabname[$id])
  542. {
  543. $alabelisused=0;
  544. $var=false;
  545. $fieldlist=explode(',',$tabfield[$id]);
  546. // Line for title
  547. print '<tr class="liste_titre">';
  548. foreach ($fieldlist as $field => $value)
  549. {
  550. // Determine le nom du champ par rapport aux noms possibles
  551. // dans les dictionnaires de donnees
  552. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  553. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  554. $align="left";
  555. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  556. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  557. if ($fieldlist[$field]=='taux') {
  558. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  559. else $valuetoshow=$langs->trans("Amount");
  560. $align='right';
  561. }
  562. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
  563. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2";}
  564. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
  565. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3";}
  566. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  567. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  568. if ($fieldlist[$field]=='type') {
  569. if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
  570. else $valuetoshow=$langs->trans("Type");
  571. }
  572. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  573. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  574. {
  575. $valuetoshow=$langs->trans("Label");
  576. if ($id != 25) $valuetoshow.="*";
  577. }
  578. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  579. if ($fieldlist[$field]=='country') {
  580. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  581. $valuetoshow=$langs->trans("Country");
  582. }
  583. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
  584. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  585. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
  586. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  587. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  588. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  589. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  590. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
  591. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  592. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); }
  593. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
  594. if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  595. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountparent"); }
  596. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  597. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  598. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  599. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  600. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  601. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  602. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  603. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  604. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  605. if ($id == 2) // Special cas for state page
  606. {
  607. if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
  608. if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
  609. }
  610. if ($valuetoshow != '')
  611. {
  612. print '<td align="'.$align.'">';
  613. if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1,$valuetoshow).'</a>';
  614. else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  615. else print $valuetoshow;
  616. print '</td>';
  617. }
  618. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  619. }
  620. if ($id == 4) print '<td></td>';
  621. print '<td>';
  622. print '<input type="hidden" name="id" value="'.$id.'">';
  623. print '</td>';
  624. print '<td style="min-width: 26px;"></td>';
  625. print '<td style="min-width: 26px;"></td>';
  626. print '</tr>';
  627. // Line to enter new values
  628. print "<tr ".$bcnd[$var].">";
  629. $obj = new stdClass();
  630. // If data was already input, we define them in obj to populate input fields.
  631. if (GETPOST('actionadd'))
  632. {
  633. foreach ($fieldlist as $key=>$val)
  634. {
  635. if (GETPOST($val))
  636. $obj->$val=GETPOST($val);
  637. }
  638. }
  639. $tmpaction = 'create';
  640. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  641. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  642. $error=$hookmanager->error; $errors=$hookmanager->errors;
  643. if ($id == 3) unset($fieldlist[2]);
  644. if (empty($reshook))
  645. {
  646. if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit')
  647. {
  648. fieldListAccountModel($fieldlist,$obj,$tabname[$id],'hide');
  649. }
  650. else
  651. {
  652. fieldListAccountModel($fieldlist,$obj,$tabname[$id],'add');
  653. }
  654. }
  655. if ($id == 4) print '<td></td>';
  656. print '<td colspan="3" align="right">';
  657. if ($tabname[$id] != MAIN_DB_PREFIX.'c_email_templates' || $action != 'edit')
  658. {
  659. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  660. }
  661. print '</td>';
  662. print "</tr>";
  663. if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates')
  664. {
  665. print '<tr><td colspan="8">* '.$langs->trans("AvailableVariables").": ";
  666. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  667. $tmp=FormMail::getAvailableSubstitKey('formemail');
  668. print implode(', ', $tmp);
  669. print '</td></tr>';
  670. }
  671. $colspan=count($fieldlist)+3;
  672. if ($id == 4) $colspan++;
  673. if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of *
  674. {
  675. print '<tr><td colspan="'.$colspan.'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
  676. }
  677. print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  678. }
  679. // List of available values in database
  680. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  681. $resql=$db->query($sql);
  682. if ($resql)
  683. {
  684. $num = $db->num_rows($resql);
  685. $i = 0;
  686. $var=true;
  687. $param = '&id='.$id;
  688. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  689. $paramwithsearch = $param;
  690. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  691. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  692. // There is several pages
  693. if ($num > $listlimit)
  694. {
  695. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  696. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  697. print '</td></tr>';
  698. }
  699. // Title of lines
  700. print '<tr class="liste_titre liste_titre_add">';
  701. foreach ($fieldlist as $field => $value)
  702. {
  703. // Determine le nom du champ par rapport aux noms possibles
  704. // dans les dictionnaires de donnees
  705. $showfield=1; // By defaut
  706. $align="left";
  707. $sortable=1;
  708. $valuetoshow='';
  709. /*
  710. $tmparray=getLabelOfField($fieldlist[$field]);
  711. $showfield=$tmp['showfield'];
  712. $valuetoshow=$tmp['valuetoshow'];
  713. $align=$tmp['align'];
  714. $sortable=$tmp['sortable'];
  715. */
  716. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  717. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  718. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  719. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  720. if ($fieldlist[$field]=='taux') {
  721. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  722. else $valuetoshow=$langs->trans("Amount");
  723. $align='right';
  724. }
  725. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
  726. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $sortable=0; }
  727. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
  728. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $sortable=0; }
  729. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  730. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  731. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  732. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  733. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  734. {
  735. $valuetoshow=$langs->trans("Label");
  736. if ($id != 25) $valuetoshow.="*";
  737. }
  738. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  739. if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
  740. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
  741. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  742. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
  743. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  744. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  745. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  746. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  747. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  748. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  749. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
  750. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
  751. if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  752. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
  753. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  754. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  755. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  756. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  757. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  758. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  759. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  760. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  761. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  762. // Affiche nom du champ
  763. if ($showfield)
  764. {
  765. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  766. }
  767. }
  768. // Favorite - Only activated on country dictionary
  769. if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  770. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  771. print getTitleFieldOfList('');
  772. print getTitleFieldOfList('');
  773. print '</tr>';
  774. // Title line with search boxes
  775. print '<tr class="liste_titre">';
  776. foreach ($fieldlist as $field => $value)
  777. {
  778. $showfield=1; // By defaut
  779. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  780. if ($showfield)
  781. {
  782. if ($value == 'country')
  783. {
  784. print '<td class="liste_titre">';
  785. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
  786. print '</td>';
  787. }
  788. else
  789. {
  790. print '<td class="liste_titre"></td>';
  791. }
  792. }
  793. }
  794. if ($id == 4) print '<td></td>';
  795. print '<td class="liste_titre"></td>';
  796. print '<td class="liste_titre" colspan="2" align="right">';
  797. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  798. print $searchpicto;
  799. print '</td>';
  800. print '</tr>';
  801. if ($num)
  802. {
  803. // Lines with values
  804. while ($i < $num)
  805. {
  806. $obj = $db->fetch_object($resql);
  807. //print_r($obj);
  808. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  809. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  810. {
  811. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  812. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  813. print '<input type="hidden" name="page" value="'.$page.'">';
  814. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  815. $tmpaction='edit';
  816. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  817. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  818. $error=$hookmanager->error; $errors=$hookmanager->errors;
  819. if (empty($reshook)) fieldListAccountModel($fieldlist,$obj,$tabname[$id],'edit');
  820. print '<td colspan="3" align="right"><a name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'">&nbsp;</a><input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  821. print '&nbsp;<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
  822. }
  823. else
  824. {
  825. $tmpaction = 'view';
  826. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  827. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  828. $error=$hookmanager->error; $errors=$hookmanager->errors;
  829. if (empty($reshook))
  830. {
  831. foreach ($fieldlist as $field => $value)
  832. {
  833. $showfield=1;
  834. $align="left";
  835. $valuetoshow=$obj->{$fieldlist[$field]};
  836. if ($value == 'type_template')
  837. {
  838. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  839. }
  840. if ($value == 'element')
  841. {
  842. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  843. }
  844. else if ($value == 'source')
  845. {
  846. $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
  847. }
  848. else if ($valuetoshow=='all') {
  849. $valuetoshow=$langs->trans('All');
  850. }
  851. else if ($fieldlist[$field]=='country') {
  852. if (empty($obj->country_code))
  853. {
  854. $valuetoshow='-';
  855. }
  856. else
  857. {
  858. $key=$langs->trans("Country".strtoupper($obj->country_code));
  859. $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
  860. }
  861. }
  862. else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  863. if(empty($valuetoshow)) $valuetoshow = $langs->trans('None');
  864. elseif($valuetoshow == 1) $valuetoshow = $langs->trans('AtEndOfMonth');
  865. elseif($valuetoshow == 2) $valuetoshow = $langs->trans('CurrentNext');
  866. $align="center";
  867. }
  868. else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) {
  869. $valuetoshow=price($valuetoshow);
  870. }
  871. else if ($fieldlist[$field]=='libelle_facture') {
  872. $langs->load("bills");
  873. $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
  874. $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  875. $valuetoshow=nl2br($valuetoshow);
  876. }
  877. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
  878. $key=$langs->trans("Country".strtoupper($obj->code));
  879. $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  880. }
  881. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
  882. $langs->load("propal");
  883. $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
  884. $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  885. }
  886. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
  887. $key=$langs->trans("Action".strtoupper($obj->code));
  888. $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  889. }
  890. else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
  891. $key=$langs->trans("Currency".strtoupper($obj->code_iso));
  892. $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
  893. }
  894. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
  895. $key=$langs->trans(strtoupper($obj->code));
  896. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  897. }
  898. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
  899. $key=$langs->trans(strtoupper($obj->code));
  900. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  901. }
  902. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
  903. $key=$langs->trans("Civility".strtoupper($obj->code));
  904. $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  905. }
  906. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
  907. $langs->load('agenda');
  908. $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  909. $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  910. }
  911. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
  912. $langs->load("bills");
  913. $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
  914. $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  915. }
  916. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
  917. $langs->load("bills");
  918. $key=$langs->trans("PaymentType".strtoupper($obj->code));
  919. $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  920. }
  921. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
  922. $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
  923. $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  924. }
  925. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
  926. $langs->load("orders");
  927. $key=$langs->trans($obj->code);
  928. $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
  929. }
  930. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
  931. $langs->load("sendings");
  932. $key=$langs->trans("SendingMethod".strtoupper($obj->code));
  933. $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  934. }
  935. else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
  936. {
  937. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  938. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  939. }
  940. else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
  941. {
  942. $langs->load('trips');
  943. $key = $langs->trans(strtoupper($obj->code));
  944. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  945. }
  946. else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
  947. $showfield=0;
  948. }
  949. else if ($fieldlist[$field]=='unicode') {
  950. $valuetoshow = $langs->getCurrencySymbol($obj->code,1);
  951. }
  952. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  953. $langs->load("products");
  954. $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
  955. }
  956. else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  957. $langs->load("products");
  958. $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
  959. }
  960. else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
  961. {
  962. $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
  963. $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$fieldlist[$field]});
  964. }
  965. else if ($fieldlist[$field]=='localtax1_type') {
  966. if ($obj->localtax1 != 0)
  967. $valuetoshow=$localtax_typeList[$valuetoshow];
  968. else
  969. $valuetoshow = '';
  970. $align="right";
  971. }
  972. else if ($fieldlist[$field]=='localtax2_type') {
  973. if ($obj->localtax2 != 0)
  974. $valuetoshow=$localtax_typeList[$valuetoshow];
  975. else
  976. $valuetoshow = '';
  977. $align="right";
  978. }
  979. else if ($fieldlist[$field]=='taux') {
  980. $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
  981. $align="right";
  982. }
  983. else if (in_array($fieldlist[$field],array('recuperableonly')))
  984. {
  985. $align="center";
  986. }
  987. else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
  988. $valuetoshow = length_accountg($valuetoshow);
  989. }
  990. $class='tddict';
  991. if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
  992. // Show value for field
  993. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  994. }
  995. }
  996. // Can an entry be erased or disabled ?
  997. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  998. if (isset($obj->code) && $id != 10)
  999. {
  1000. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  1001. else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  1002. else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  1003. }
  1004. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
  1005. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
  1006. $canbemodified=$iserasable;
  1007. if ($obj->code == 'RECEP') $canbemodified=1;
  1008. $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'');
  1009. if ($param) $url .= '&'.$param;
  1010. $url.='&';
  1011. // Favorite
  1012. // Only activated on country dictionary
  1013. if ($id == 4)
  1014. {
  1015. print '<td align="center" class="nowrap">';
  1016. if ($iserasable) print '<a href="'.$url.'action='.$acts[$obj->favorite].'_favorite">'.$actl[$obj->favorite].'</a>';
  1017. else print $langs->trans("AlwaysActive");
  1018. print '</td>';
  1019. }
  1020. // Active
  1021. print '<td align="center" class="nowrap">';
  1022. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  1023. else
  1024. {
  1025. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  1026. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  1027. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  1028. else print $langs->trans("AlwaysActive");
  1029. }
  1030. print "</td>";
  1031. // Modify link
  1032. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  1033. else print '<td>&nbsp;</td>';
  1034. // Delete link
  1035. if ($iserasable) print '<td align="center"><a href="'.$url.'action=delete">'.img_delete().'</a></td>';
  1036. else print '<td>&nbsp;</td>';
  1037. print "</tr>\n";
  1038. }
  1039. $i++;
  1040. }
  1041. }
  1042. }
  1043. else {
  1044. dol_print_error($db);
  1045. }
  1046. print '</table>';
  1047. print '</form>';
  1048. }
  1049. else
  1050. {
  1051. /*
  1052. * Show list of dictionary to show
  1053. */
  1054. $var=true;
  1055. $lastlineisempty=false;
  1056. print '<table class="noborder" width="100%">';
  1057. print '<tr class="liste_titre">';
  1058. //print '<td>'.$langs->trans("Module").'</td>';
  1059. print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
  1060. print '<td>'.$langs->trans("Table").'</td>';
  1061. print '</tr>';
  1062. $showemptyline='';
  1063. foreach ($taborder as $i)
  1064. {
  1065. if (isset($tabname[$i]) && empty($tabcond[$i])) continue;
  1066. if ($i)
  1067. {
  1068. if ($showemptyline)
  1069. {
  1070. print '<tr class="oddeven"><td width="30%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  1071. $showemptyline=0;
  1072. }
  1073. $value=$tabname[$i];
  1074. print '<tr class="oddeven"><td width="50%">';
  1075. if (! empty($tabcond[$i]))
  1076. {
  1077. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">'.$langs->trans($tablib[$i]).'</a>';
  1078. }
  1079. else
  1080. {
  1081. print $langs->trans($tablib[$i]);
  1082. }
  1083. print '</td>';
  1084. print '<td>';
  1085. /*if (empty($tabcond[$i]))
  1086. {
  1087. print info_admin($langs->trans("DictionaryDisabledSinceNoModuleNeedIt"),1);
  1088. }*/
  1089. print '</td>';
  1090. print '<td>'.$tabname[$i].'</td></tr>';
  1091. $lastlineisempty=false;
  1092. }
  1093. else
  1094. {
  1095. if (! $lastlineisempty)
  1096. {
  1097. $showemptyline=1;
  1098. $lastlineisempty=true;
  1099. }
  1100. }
  1101. }
  1102. print '</table>';
  1103. }
  1104. print '<br>';
  1105. llxFooter();
  1106. $db->close();
  1107. /**
  1108. * Show fields in insert/edit mode
  1109. *
  1110. * @param array $fieldlist Array of fields
  1111. * @param Object $obj If we show a particular record, obj is filled with record fields
  1112. * @param string $tabname Name of SQL table
  1113. * @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
  1114. * @return void
  1115. */
  1116. function fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
  1117. {
  1118. global $conf,$langs,$db;
  1119. global $form;
  1120. global $region_id;
  1121. global $elementList,$sourceList,$localtax_typeList;
  1122. global $bc;
  1123. $formadmin = new FormAdmin($db);
  1124. $formcompany = new FormCompany($db);
  1125. $formaccounting = new FormAccounting($db);
  1126. foreach ($fieldlist as $field => $value)
  1127. {
  1128. if ($fieldlist[$field] == 'country')
  1129. {
  1130. if (in_array('region_id',$fieldlist))
  1131. {
  1132. print '<td>';
  1133. //print join(',',$fieldlist);
  1134. print '</td>';
  1135. continue;
  1136. } // For state page, we do not show the country input (we link to region, not country)
  1137. print '<td>';
  1138. $fieldname='country';
  1139. print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
  1140. print '</td>';
  1141. }
  1142. elseif ($fieldlist[$field] == 'country_id')
  1143. {
  1144. if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
  1145. {
  1146. $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
  1147. print '<td>';
  1148. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
  1149. print '</td>';
  1150. }
  1151. }
  1152. elseif ($fieldlist[$field] == 'region')
  1153. {
  1154. print '<td>';
  1155. $formcompany->select_region($region_id,'region');
  1156. print '</td>';
  1157. }
  1158. elseif ($fieldlist[$field] == 'region_id')
  1159. {
  1160. $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
  1161. print '<td>';
  1162. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
  1163. print '</td>';
  1164. }
  1165. elseif ($fieldlist[$field] == 'lang')
  1166. {
  1167. print '<td>';
  1168. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  1169. print '</td>';
  1170. }
  1171. // Le type de template
  1172. elseif ($fieldlist[$field] == 'type_template')
  1173. {
  1174. print '<td>';
  1175. print $form->selectarray('type_template', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1176. print '</td>';
  1177. }
  1178. // Le type de l'element (pour les type de contact)
  1179. elseif ($fieldlist[$field] == 'element')
  1180. {
  1181. print '<td>';
  1182. print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1183. print '</td>';
  1184. }
  1185. // La source de l'element (pour les type de contact)
  1186. elseif ($fieldlist[$field] == 'source')
  1187. {
  1188. print '<td>';
  1189. print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1190. print '</td>';
  1191. }
  1192. elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
  1193. {
  1194. print '<td>';
  1195. print 'user<input type="hidden" name="type" value="user">';
  1196. print '</td>';
  1197. }
  1198. elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  1199. if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
  1200. else print '<td>';
  1201. if ($fieldlist[$field] == 'type_cdr') {
  1202. print $form->selectarray($fieldlist[$field], array(0=>$langs->trans('None'), 1=>$langs->trans('AtEndOfMonth'), 2=>$langs->trans('CurrentNext')), (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1203. } else {
  1204. print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
  1205. }
  1206. print '</td>';
  1207. }
  1208. elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
  1209. $align="left";
  1210. if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="right"; // Fields aligned on right
  1211. print '<td align="'.$align.'">';
  1212. print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="3" name="'.$fieldlist[$field].'">';
  1213. print '</td>';
  1214. }
  1215. elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
  1216. print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea></td>';
  1217. }
  1218. elseif (in_array($fieldlist[$field], array('content')))
  1219. {
  1220. if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
  1221. {
  1222. print '<td colspan="4"></td></tr><tr class="pair nohover"><td colspan="5">'; // To create an artificial CR for the current tr we are on
  1223. }
  1224. else print '<td>';
  1225. if ($context != 'hide')
  1226. {
  1227. //print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  1228. $okforextended=true;
  1229. if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
  1230. $doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_5, '90%');
  1231. print $doleditor->Create(1);
  1232. }
  1233. else print '&nbsp;';
  1234. print '</td>';
  1235. }
  1236. elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
  1237. print '<td><input type="text" class="flat" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" size="8" name="'.$fieldlist[$field].'"></td>';
  1238. }
  1239. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  1240. print '<td><input type="text" class="flat" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
  1241. }
  1242. elseif ($fieldlist[$field]=='unit') {
  1243. print '<td>';
  1244. $units = array(
  1245. 'mm' => $langs->trans('SizeUnitmm'),
  1246. 'cm' => $langs->trans('SizeUnitcm'),
  1247. 'point' => $langs->trans('SizeUnitpoint'),
  1248. 'inch' => $langs->trans('SizeUnitinch')
  1249. );
  1250. print $form->selectarray('unit', $units, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 0, 0, 0);
  1251. print '</td>';
  1252. }
  1253. // Le type de taxe locale
  1254. elseif ($fieldlist[$field] == 'localtax1_type' || $fieldlist[$field] == 'localtax2_type')
  1255. {
  1256. print '<td align="center">';
  1257. print $form->selectarray($fieldlist[$field], $localtax_typeList, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1258. print '</td>';
  1259. }
  1260. elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
  1261. {
  1262. print '<td>';
  1263. if (! empty($conf->accounting->enabled))
  1264. {
  1265. $accountancy_account = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
  1266. print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  1267. }
  1268. else
  1269. {
  1270. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" name="'.$fieldlist[$field].'">';
  1271. }
  1272. print '</td>';
  1273. }
  1274. else
  1275. {
  1276. print '<td>';
  1277. $size=''; $class='';
  1278. if ($fieldlist[$field]=='code') $size='size="8" ';
  1279. if ($fieldlist[$field]=='position') $size='size="4" ';
  1280. if ($fieldlist[$field]=='libelle') $size='centpercent';
  1281. if ($fieldlist[$field]=='tracking') $class='centpercent';
  1282. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  1283. print '<input type="text" '.$size.' class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  1284. print '</td>';
  1285. }
  1286. }
  1287. }