accountmodel.php 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. /*
  188. * Actions
  189. */
  190. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  191. {
  192. $search_country_id = '';
  193. }
  194. // Actions add or modify an entry into a dictionary
  195. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  196. {
  197. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  198. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  199. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  200. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  201. // Check that all fields are filled
  202. $ok=1;
  203. foreach ($listfield as $f => $value)
  204. {
  205. if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancysystem','DictionaryAccountancyCategory'))) continue; // For some pages, country is not mandatory
  206. if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
  207. if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue;
  208. if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue;
  209. if ($value == 'color' && empty($_POST['color'])) continue;
  210. if ($value == 'formula' && empty($_POST['formula'])) continue;
  211. if ((! isset($_POST[$value]) || $_POST[$value]=='')
  212. && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
  213. && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
  214. )
  215. )
  216. {
  217. $ok=0;
  218. $fieldnamekey=$listfield[$f];
  219. // We take translate key of field
  220. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  221. if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
  222. if ($fieldnamekey == 'nbjour') $fieldnamekey='NbOfDays';
  223. if ($fieldnamekey == 'decalage') $fieldnamekey='Offset';
  224. if ($fieldnamekey == 'module') $fieldnamekey='Module';
  225. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  226. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  227. if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
  228. if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
  229. if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
  230. if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode';
  231. if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible';
  232. if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder';
  233. if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
  234. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  235. }
  236. }
  237. // Other checks
  238. if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
  239. $ok=0;
  240. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  241. }
  242. if (isset($_POST["code"]))
  243. {
  244. if ($_POST["code"]=='0')
  245. {
  246. $ok=0;
  247. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  248. }
  249. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  250. {
  251. $ok = 0;
  252. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
  253. }*/
  254. }
  255. if (isset($_POST["country"]) && ($_POST["country"]=='0') && ($id != 2))
  256. {
  257. if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
  258. {
  259. $_POST["country"]='';
  260. }
  261. else
  262. {
  263. $ok=0;
  264. setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
  265. }
  266. }
  267. if ($id == 3 && ! is_numeric($_POST["code"]))
  268. {
  269. $ok=0;
  270. setEventMessages($langs->transnoentities("ErrorFieldMustBeANumeric",$langs->transnoentities("Code")), null, 'errors');
  271. }
  272. // Clean some parameters
  273. if (isset($_POST["localtax1"]) && empty($_POST["localtax1"])) $_POST["localtax1"]='0'; // If empty, we force to 0
  274. if (isset($_POST["localtax2"]) && empty($_POST["localtax2"])) $_POST["localtax2"]='0'; // If empty, we force to 0
  275. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  276. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  277. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  278. // Si verif ok et action add, on ajoute la ligne
  279. if ($ok && GETPOST('actionadd'))
  280. {
  281. if ($tabrowid[$id])
  282. {
  283. // Recupere id libre pour insertion
  284. $newid=0;
  285. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  286. $result = $db->query($sql);
  287. if ($result)
  288. {
  289. $obj = $db->fetch_object($result);
  290. $newid=($obj->newid + 1);
  291. } else {
  292. dol_print_error($db);
  293. }
  294. }
  295. // Add new entry
  296. $sql = "INSERT INTO ".$tabname[$id]." (";
  297. // List of fields
  298. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  299. $sql.= $tabrowid[$id].",";
  300. $sql.= $tabfieldinsert[$id];
  301. $sql.=",active)";
  302. $sql.= " VALUES(";
  303. // List of values
  304. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  305. $sql.= $newid.",";
  306. $i=0;
  307. foreach ($listfieldinsert as $f => $value)
  308. {
  309. if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
  310. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  311. }
  312. else if ($value == 'entity') {
  313. $_POST[$listfieldvalue[$i]] = $conf->entity;
  314. }
  315. if ($i) $sql.=",";
  316. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  317. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  318. $i++;
  319. }
  320. $sql.=",1)";
  321. dol_syslog("actionadd", LOG_DEBUG);
  322. $result = $db->query($sql);
  323. if ($result) // Add is ok
  324. {
  325. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  326. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  327. }
  328. else
  329. {
  330. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  331. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  332. }
  333. else {
  334. dol_print_error($db);
  335. }
  336. }
  337. }
  338. // Si verif ok et action modify, on modifie la ligne
  339. if ($ok && GETPOST('actionmodify'))
  340. {
  341. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  342. else { $rowidcol="rowid"; }
  343. // Modify entry
  344. $sql = "UPDATE ".$tabname[$id]." SET ";
  345. // Modifie valeur des champs
  346. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  347. {
  348. $sql.= $tabrowid[$id]."=";
  349. $sql.= "'".$db->escape($rowid)."', ";
  350. }
  351. $i = 0;
  352. foreach ($listfieldmodify as $field)
  353. {
  354. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  355. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  356. }
  357. else if ($field == 'entity') {
  358. $_POST[$listfieldvalue[$i]] = $conf->entity;
  359. }
  360. if ($i) $sql.=",";
  361. $sql.= $field."=";
  362. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null";
  363. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  364. $i++;
  365. }
  366. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  367. dol_syslog("actionmodify", LOG_DEBUG);
  368. //print $sql;
  369. $resql = $db->query($sql);
  370. if (! $resql)
  371. {
  372. setEventMessages($db->error(), null, 'errors');
  373. }
  374. }
  375. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  376. }
  377. if (GETPOST('actioncancel'))
  378. {
  379. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  380. }
  381. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  382. {
  383. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  384. else { $rowidcol="rowid"; }
  385. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  386. dol_syslog("delete", LOG_DEBUG);
  387. $result = $db->query($sql);
  388. if (! $result)
  389. {
  390. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  391. {
  392. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  393. }
  394. else
  395. {
  396. dol_print_error($db);
  397. }
  398. }
  399. }
  400. // activate
  401. if ($action == $acts[0])
  402. {
  403. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  404. else { $rowidcol="rowid"; }
  405. if ($rowid) {
  406. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  407. }
  408. elseif ($_GET["code"]) {
  409. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'";
  410. }
  411. $result = $db->query($sql);
  412. if (!$result)
  413. {
  414. dol_print_error($db);
  415. }
  416. }
  417. // disable
  418. if ($action == $acts[1])
  419. {
  420. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  421. else { $rowidcol="rowid"; }
  422. if ($rowid) {
  423. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  424. }
  425. elseif ($_GET["code"]) {
  426. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'";
  427. }
  428. $result = $db->query($sql);
  429. if (!$result)
  430. {
  431. dol_print_error($db);
  432. }
  433. }
  434. // favorite
  435. if ($action == 'activate_favorite')
  436. {
  437. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  438. else { $rowidcol="rowid"; }
  439. if ($rowid) {
  440. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'";
  441. }
  442. elseif ($_GET["code"]) {
  443. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$_GET["code"]."'";
  444. }
  445. $result = $db->query($sql);
  446. if (!$result)
  447. {
  448. dol_print_error($db);
  449. }
  450. }
  451. // disable favorite
  452. if ($action == 'disable_favorite')
  453. {
  454. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  455. else { $rowidcol="rowid"; }
  456. if ($rowid) {
  457. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'";
  458. }
  459. elseif ($_GET["code"]) {
  460. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$_GET["code"]."'";
  461. }
  462. $result = $db->query($sql);
  463. if (!$result)
  464. {
  465. dol_print_error($db);
  466. }
  467. }
  468. /*
  469. * View
  470. */
  471. $form = new Form($db);
  472. $formadmin=new FormAdmin($db);
  473. llxHeader();
  474. $titre=$langs->trans($tablib[$id]);
  475. $linkback='';
  476. print load_fiche_titre($titre,$linkback,'title_accountancy');
  477. if (empty($id))
  478. {
  479. print $langs->trans("DictionaryDesc");
  480. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  481. }
  482. print "<br>\n";
  483. // Confirmation de la suppression de la ligne
  484. if ($action == 'delete')
  485. {
  486. 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);
  487. }
  488. //var_dump($elementList);
  489. /*
  490. * Show a dictionary
  491. */
  492. if ($id)
  493. {
  494. // Complete requete recherche valeurs avec critere de tri
  495. $sql=$tabsql[$id];
  496. if ($search_country_id > 0)
  497. {
  498. if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
  499. else $sql.=" WHERE ";
  500. $sql.= " c.rowid = ".$search_country_id;
  501. }
  502. if ($sortfield)
  503. {
  504. // If sort order is "country", we use country_code instead
  505. if ($sortfield == 'country') $sortfield='country_code';
  506. $sql.= " ORDER BY ".$sortfield;
  507. if ($sortorder)
  508. {
  509. $sql.=" ".strtoupper($sortorder);
  510. }
  511. $sql.=", ";
  512. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  513. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  514. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  515. }
  516. else {
  517. $sql.=" ORDER BY ";
  518. }
  519. $sql.=$tabsqlsort[$id];
  520. $sql.=$db->plimit($listlimit+1,$offset);
  521. //print $sql;
  522. $fieldlist=explode(',',$tabfield[$id]);
  523. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  524. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  525. print '<table class="noborder" width="100%">';
  526. // Form to add a new line
  527. if ($tabname[$id])
  528. {
  529. $alabelisused=0;
  530. $var=false;
  531. $fieldlist=explode(',',$tabfield[$id]);
  532. // Line for title
  533. print '<tr class="liste_titre">';
  534. foreach ($fieldlist as $field => $value)
  535. {
  536. // Determine le nom du champ par rapport aux noms possibles
  537. // dans les dictionnaires de donnees
  538. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  539. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  540. $align="left";
  541. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  542. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  543. if ($fieldlist[$field]=='taux') {
  544. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  545. else $valuetoshow=$langs->trans("Amount");
  546. $align='right';
  547. }
  548. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
  549. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2";}
  550. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
  551. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3";}
  552. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  553. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  554. if ($fieldlist[$field]=='type') {
  555. if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
  556. else $valuetoshow=$langs->trans("Type");
  557. }
  558. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  559. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  560. {
  561. $valuetoshow=$langs->trans("Label");
  562. if ($id != 25) $valuetoshow.="*";
  563. }
  564. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  565. if ($fieldlist[$field]=='country') {
  566. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  567. $valuetoshow=$langs->trans("Country");
  568. }
  569. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
  570. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  571. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
  572. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  573. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  574. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  575. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  576. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
  577. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  578. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); }
  579. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
  580. if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  581. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountparent"); }
  582. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  583. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  584. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  585. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  586. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  587. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  588. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  589. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  590. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  591. if ($id == 2) // Special cas for state page
  592. {
  593. if ($fieldlist[$field]=='region_id') { $valuetoshow='&nbsp;'; $showfield=1; }
  594. if ($fieldlist[$field]=='region') { $valuetoshow=$langs->trans("Country").'/'.$langs->trans("Region"); $showfield=1; }
  595. }
  596. if ($valuetoshow != '')
  597. {
  598. print '<td align="'.$align.'">';
  599. 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>';
  600. else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  601. else print $valuetoshow;
  602. print '</td>';
  603. }
  604. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  605. }
  606. if ($id == 4) print '<td></td>';
  607. print '<td>';
  608. print '<input type="hidden" name="id" value="'.$id.'">';
  609. print '</td>';
  610. print '<td style="min-width: 26px;"></td>';
  611. print '<td style="min-width: 26px;"></td>';
  612. print '</tr>';
  613. // Line to enter new values
  614. print "<tr ".$bcnd[$var].">";
  615. $obj = new stdClass();
  616. // If data was already input, we define them in obj to populate input fields.
  617. if (GETPOST('actionadd'))
  618. {
  619. foreach ($fieldlist as $key=>$val)
  620. {
  621. if (GETPOST($val))
  622. $obj->$val=GETPOST($val);
  623. }
  624. }
  625. $tmpaction = 'create';
  626. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  627. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  628. $error=$hookmanager->error; $errors=$hookmanager->errors;
  629. if ($id == 3) unset($fieldlist[2]);
  630. if (empty($reshook))
  631. {
  632. if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit')
  633. {
  634. fieldListAccountModel($fieldlist,$obj,$tabname[$id],'hide');
  635. }
  636. else
  637. {
  638. fieldListAccountModel($fieldlist,$obj,$tabname[$id],'add');
  639. }
  640. }
  641. if ($id == 4) print '<td></td>';
  642. print '<td colspan="3" align="right">';
  643. if ($tabname[$id] != MAIN_DB_PREFIX.'c_email_templates' || $action != 'edit')
  644. {
  645. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  646. }
  647. print '</td>';
  648. print "</tr>";
  649. if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates')
  650. {
  651. print '<tr><td colspan="8">* '.$langs->trans("AvailableVariables").": ";
  652. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  653. $tmp=FormMail::getAvailableSubstitKey('formemail');
  654. print implode(', ', $tmp);
  655. print '</td></tr>';
  656. }
  657. $colspan=count($fieldlist)+3;
  658. if ($id == 4) $colspan++;
  659. if (! empty($alabelisused) && $id != 25) // If there is one label among fields, we show legend of *
  660. {
  661. print '<tr><td colspan="'.$colspan.'">* '.$langs->trans("LabelUsedByDefault").'.</td></tr>';
  662. }
  663. print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  664. }
  665. // List of available values in database
  666. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  667. $resql=$db->query($sql);
  668. if ($resql)
  669. {
  670. $num = $db->num_rows($resql);
  671. $i = 0;
  672. $var=true;
  673. $param = '&id='.$id;
  674. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  675. $paramwithsearch = $param;
  676. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  677. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  678. // There is several pages
  679. if ($num > $listlimit)
  680. {
  681. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  682. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  683. print '</td></tr>';
  684. }
  685. // Title of lines
  686. print '<tr class="liste_titre liste_titre_add">';
  687. foreach ($fieldlist as $field => $value)
  688. {
  689. // Determine le nom du champ par rapport aux noms possibles
  690. // dans les dictionnaires de donnees
  691. $showfield=1; // By defaut
  692. $align="left";
  693. $sortable=1;
  694. $valuetoshow='';
  695. /*
  696. $tmparray=getLabelOfField($fieldlist[$field]);
  697. $showfield=$tmp['showfield'];
  698. $valuetoshow=$tmp['valuetoshow'];
  699. $align=$tmp['align'];
  700. $sortable=$tmp['sortable'];
  701. */
  702. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  703. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  704. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  705. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  706. if ($fieldlist[$field]=='taux') {
  707. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  708. else $valuetoshow=$langs->trans("Amount");
  709. $align='right';
  710. }
  711. if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; }
  712. if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $sortable=0; }
  713. if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; }
  714. if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $sortable=0; }
  715. if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); }
  716. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  717. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  718. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  719. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  720. {
  721. $valuetoshow=$langs->trans("Label");
  722. if ($id != 25) $valuetoshow.="*";
  723. }
  724. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  725. if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
  726. if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; }
  727. if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); }
  728. if ($fieldlist[$field]=='type_cdr') { $valuetoshow=$langs->trans("AtEndOfMonth"); $align="center"; }
  729. if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); }
  730. if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); }
  731. if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); }
  732. if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); }
  733. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  734. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  735. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
  736. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
  737. if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  738. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
  739. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  740. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  741. if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); }
  742. if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); }
  743. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  744. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  745. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  746. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  747. if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); }
  748. // Affiche nom du champ
  749. if ($showfield)
  750. {
  751. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  752. }
  753. }
  754. // Favorite - Only activated on country dictionary
  755. if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"), 0, $_SERVER["PHP_SELF"], "favorite", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  756. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  757. print getTitleFieldOfList('');
  758. print getTitleFieldOfList('');
  759. print '</tr>';
  760. // Title line with search boxes
  761. print '<tr class="liste_titre">';
  762. foreach ($fieldlist as $field => $value)
  763. {
  764. $showfield=1; // By defaut
  765. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  766. if ($showfield)
  767. {
  768. if ($value == 'country')
  769. {
  770. print '<td class="liste_titre">';
  771. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
  772. print '</td>';
  773. }
  774. else
  775. {
  776. print '<td class="liste_titre"></td>';
  777. }
  778. }
  779. }
  780. if ($id == 4) print '<td></td>';
  781. print '<td class="liste_titre"></td>';
  782. print '<td class="liste_titre" colspan="2" align="right">';
  783. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  784. print $searchpicto;
  785. print '</td>';
  786. print '</tr>';
  787. if ($num)
  788. {
  789. // Lines with values
  790. while ($i < $num)
  791. {
  792. $obj = $db->fetch_object($resql);
  793. //print_r($obj);
  794. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  795. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  796. {
  797. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  798. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  799. print '<input type="hidden" name="page" value="'.$page.'">';
  800. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  801. $tmpaction='edit';
  802. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  803. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  804. $error=$hookmanager->error; $errors=$hookmanager->errors;
  805. if (empty($reshook)) fieldListAccountModel($fieldlist,$obj,$tabname[$id],'edit');
  806. 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").'">';
  807. print '&nbsp;<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'"></td>';
  808. }
  809. else
  810. {
  811. $tmpaction = 'view';
  812. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  813. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  814. $error=$hookmanager->error; $errors=$hookmanager->errors;
  815. if (empty($reshook))
  816. {
  817. foreach ($fieldlist as $field => $value)
  818. {
  819. $showfield=1;
  820. $align="left";
  821. $valuetoshow=$obj->{$fieldlist[$field]};
  822. if ($value == 'type_template')
  823. {
  824. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  825. }
  826. if ($value == 'element')
  827. {
  828. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  829. }
  830. else if ($value == 'source')
  831. {
  832. $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
  833. }
  834. else if ($valuetoshow=='all') {
  835. $valuetoshow=$langs->trans('All');
  836. }
  837. else if ($fieldlist[$field]=='country') {
  838. if (empty($obj->country_code))
  839. {
  840. $valuetoshow='-';
  841. }
  842. else
  843. {
  844. $key=$langs->trans("Country".strtoupper($obj->country_code));
  845. $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
  846. }
  847. }
  848. else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  849. if(empty($valuetoshow)) $valuetoshow = $langs->trans('None');
  850. elseif($valuetoshow == 1) $valuetoshow = $langs->trans('AtEndOfMonth');
  851. elseif($valuetoshow == 2) $valuetoshow = $langs->trans('CurrentNext');
  852. $align="center";
  853. }
  854. else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) {
  855. $valuetoshow=price($valuetoshow);
  856. }
  857. else if ($fieldlist[$field]=='libelle_facture') {
  858. $langs->load("bills");
  859. $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
  860. $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  861. $valuetoshow=nl2br($valuetoshow);
  862. }
  863. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
  864. $key=$langs->trans("Country".strtoupper($obj->code));
  865. $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  866. }
  867. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
  868. $langs->load("propal");
  869. $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
  870. $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  871. }
  872. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
  873. $key=$langs->trans("Action".strtoupper($obj->code));
  874. $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  875. }
  876. else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
  877. $key=$langs->trans("Currency".strtoupper($obj->code_iso));
  878. $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
  879. }
  880. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
  881. $key=$langs->trans(strtoupper($obj->code));
  882. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  883. }
  884. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
  885. $key=$langs->trans(strtoupper($obj->code));
  886. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  887. }
  888. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
  889. $key=$langs->trans("Civility".strtoupper($obj->code));
  890. $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  891. }
  892. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
  893. $langs->load('agenda');
  894. $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  895. $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  896. }
  897. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
  898. $langs->load("bills");
  899. $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
  900. $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  901. }
  902. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
  903. $langs->load("bills");
  904. $key=$langs->trans("PaymentType".strtoupper($obj->code));
  905. $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  906. }
  907. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
  908. $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
  909. $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  910. }
  911. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
  912. $langs->load("orders");
  913. $key=$langs->trans($obj->code);
  914. $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
  915. }
  916. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
  917. $langs->load("sendings");
  918. $key=$langs->trans("SendingMethod".strtoupper($obj->code));
  919. $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  920. }
  921. else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
  922. {
  923. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  924. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  925. }
  926. else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
  927. {
  928. $langs->load('trips');
  929. $key = $langs->trans(strtoupper($obj->code));
  930. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  931. }
  932. else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
  933. $showfield=0;
  934. }
  935. else if ($fieldlist[$field]=='unicode') {
  936. $valuetoshow = $langs->getCurrencySymbol($obj->code,1);
  937. }
  938. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  939. $langs->load("products");
  940. $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
  941. }
  942. else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  943. $langs->load("products");
  944. $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
  945. }
  946. else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format'))
  947. {
  948. $key = $langs->trans('SizeUnit'.strtolower($obj->unit));
  949. $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->{$fieldlist[$field]});
  950. }
  951. else if ($fieldlist[$field]=='taux') {
  952. $valuetoshow = price($valuetoshow, 0, $langs, 0, 0);
  953. $align="right";
  954. }
  955. else if (in_array($fieldlist[$field],array('recuperableonly')))
  956. {
  957. $align="center";
  958. }
  959. else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
  960. $valuetoshow = length_accountg($valuetoshow);
  961. }
  962. $class='tddict';
  963. if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
  964. // Show value for field
  965. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  966. }
  967. }
  968. // Can an entry be erased or disabled ?
  969. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  970. if (isset($obj->code) && $id != 10)
  971. {
  972. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  973. else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  974. else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  975. }
  976. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
  977. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
  978. $canbemodified=$iserasable;
  979. if ($obj->code == 'RECEP') $canbemodified=1;
  980. $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):'');
  981. if ($param) $url .= '&'.$param;
  982. $url.='&';
  983. // Favorite
  984. // Only activated on country dictionary
  985. if ($id == 4)
  986. {
  987. print '<td align="center" class="nowrap">';
  988. if ($iserasable) print '<a href="'.$url.'action='.$acts[$obj->favorite].'_favorite">'.$actl[$obj->favorite].'</a>';
  989. else print $langs->trans("AlwaysActive");
  990. print '</td>';
  991. }
  992. // Active
  993. print '<td align="center" class="nowrap">';
  994. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  995. else
  996. {
  997. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  998. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  999. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  1000. else print $langs->trans("AlwaysActive");
  1001. }
  1002. print "</td>";
  1003. // Modify link
  1004. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  1005. else print '<td>&nbsp;</td>';
  1006. // Delete link
  1007. if ($iserasable) print '<td align="center"><a href="'.$url.'action=delete">'.img_delete().'</a></td>';
  1008. else print '<td>&nbsp;</td>';
  1009. print "</tr>\n";
  1010. }
  1011. $i++;
  1012. }
  1013. }
  1014. }
  1015. else {
  1016. dol_print_error($db);
  1017. }
  1018. print '</table>';
  1019. print '</form>';
  1020. }
  1021. else
  1022. {
  1023. /*
  1024. * Show list of dictionary to show
  1025. */
  1026. $var=true;
  1027. $lastlineisempty=false;
  1028. print '<table class="noborder" width="100%">';
  1029. print '<tr class="liste_titre">';
  1030. //print '<td>'.$langs->trans("Module").'</td>';
  1031. print '<td colspan="2">'.$langs->trans("Dictionary").'</td>';
  1032. print '<td>'.$langs->trans("Table").'</td>';
  1033. print '</tr>';
  1034. $showemptyline='';
  1035. foreach ($taborder as $i)
  1036. {
  1037. if (isset($tabname[$i]) && empty($tabcond[$i])) continue;
  1038. if ($i)
  1039. {
  1040. if ($showemptyline)
  1041. {
  1042. print '<tr class="oddeven"><td width="30%">&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>';
  1043. $showemptyline=0;
  1044. }
  1045. $value=$tabname[$i];
  1046. print '<tr class="oddeven"><td width="50%">';
  1047. if (! empty($tabcond[$i]))
  1048. {
  1049. print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$i.'">'.$langs->trans($tablib[$i]).'</a>';
  1050. }
  1051. else
  1052. {
  1053. print $langs->trans($tablib[$i]);
  1054. }
  1055. print '</td>';
  1056. print '<td>';
  1057. /*if (empty($tabcond[$i]))
  1058. {
  1059. print info_admin($langs->trans("DictionaryDisabledSinceNoModuleNeedIt"),1);
  1060. }*/
  1061. print '</td>';
  1062. print '<td>'.$tabname[$i].'</td></tr>';
  1063. $lastlineisempty=false;
  1064. }
  1065. else
  1066. {
  1067. if (! $lastlineisempty)
  1068. {
  1069. $showemptyline=1;
  1070. $lastlineisempty=true;
  1071. }
  1072. }
  1073. }
  1074. print '</table>';
  1075. }
  1076. print '<br>';
  1077. llxFooter();
  1078. $db->close();
  1079. /**
  1080. * Show fields in insert/edit mode
  1081. *
  1082. * @param array $fieldlist Array of fields
  1083. * @param Object $obj If we show a particular record, obj is filled with record fields
  1084. * @param string $tabname Name of SQL table
  1085. * @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
  1086. * @return void
  1087. */
  1088. function fieldListAccountModel($fieldlist, $obj='', $tabname='', $context='')
  1089. {
  1090. global $conf,$langs,$db;
  1091. global $form;
  1092. global $region_id;
  1093. global $elementList,$sourceList;
  1094. global $bc;
  1095. $formadmin = new FormAdmin($db);
  1096. $formcompany = new FormCompany($db);
  1097. $formaccounting = new FormAccounting($db);
  1098. foreach ($fieldlist as $field => $value)
  1099. {
  1100. if ($fieldlist[$field] == 'country')
  1101. {
  1102. if (in_array('region_id',$fieldlist))
  1103. {
  1104. print '<td>';
  1105. //print join(',',$fieldlist);
  1106. print '</td>';
  1107. continue;
  1108. } // For state page, we do not show the country input (we link to region, not country)
  1109. print '<td>';
  1110. $fieldname='country';
  1111. print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:'')), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
  1112. print '</td>';
  1113. }
  1114. elseif ($fieldlist[$field] == 'country_id')
  1115. {
  1116. if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
  1117. {
  1118. $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
  1119. print '<td>';
  1120. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
  1121. print '</td>';
  1122. }
  1123. }
  1124. elseif ($fieldlist[$field] == 'region')
  1125. {
  1126. print '<td>';
  1127. $formcompany->select_region($region_id,'region');
  1128. print '</td>';
  1129. }
  1130. elseif ($fieldlist[$field] == 'region_id')
  1131. {
  1132. $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
  1133. print '<td>';
  1134. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
  1135. print '</td>';
  1136. }
  1137. elseif ($fieldlist[$field] == 'lang')
  1138. {
  1139. print '<td>';
  1140. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  1141. print '</td>';
  1142. }
  1143. // Le type de template
  1144. elseif ($fieldlist[$field] == 'type_template')
  1145. {
  1146. print '<td>';
  1147. print $form->selectarray('type_template', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1148. print '</td>';
  1149. }
  1150. // Le type de l'element (pour les type de contact)
  1151. elseif ($fieldlist[$field] == 'element')
  1152. {
  1153. print '<td>';
  1154. print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1155. print '</td>';
  1156. }
  1157. // La source de l'element (pour les type de contact)
  1158. elseif ($fieldlist[$field] == 'source')
  1159. {
  1160. print '<td>';
  1161. print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1162. print '</td>';
  1163. }
  1164. elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
  1165. {
  1166. print '<td>';
  1167. print 'user<input type="hidden" name="type" value="user">';
  1168. print '</td>';
  1169. }
  1170. elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  1171. if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
  1172. else print '<td>';
  1173. if ($fieldlist[$field] == 'type_cdr') {
  1174. 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]}:''));
  1175. } else {
  1176. print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
  1177. }
  1178. print '</td>';
  1179. }
  1180. elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
  1181. $align="left";
  1182. if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="right"; // Fields aligned on right
  1183. print '<td align="'.$align.'">';
  1184. print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="3" name="'.$fieldlist[$field].'">';
  1185. print '</td>';
  1186. }
  1187. elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
  1188. print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea></td>';
  1189. }
  1190. elseif (in_array($fieldlist[$field], array('content')))
  1191. {
  1192. if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
  1193. {
  1194. 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
  1195. }
  1196. else print '<td>';
  1197. if ($context != 'hide')
  1198. {
  1199. //print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  1200. $okforextended=true;
  1201. if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
  1202. $doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_5, '90%');
  1203. print $doleditor->Create(1);
  1204. }
  1205. else print '&nbsp;';
  1206. print '</td>';
  1207. }
  1208. elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
  1209. print '<td><input type="text" class="flat" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" size="8" name="'.$fieldlist[$field].'"></td>';
  1210. }
  1211. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  1212. print '<td><input type="text" class="flat" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" size="10" name="'.$fieldlist[$field].'"></td>';
  1213. }
  1214. elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
  1215. {
  1216. print '<td>';
  1217. if (! empty($conf->accounting->enabled))
  1218. {
  1219. $accountancy_account = (! empty($obj->$fieldlist[$field]) ? $obj->$fieldlist[$field] : 0);
  1220. print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  1221. }
  1222. else
  1223. {
  1224. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldlist[$field])?$obj->$fieldlist[$field]:'').'" name="'.$fieldlist[$field].'">';
  1225. }
  1226. print '</td>';
  1227. }
  1228. else
  1229. {
  1230. print '<td>';
  1231. $size=''; $class='';
  1232. if ($fieldlist[$field]=='code') $size='size="8" ';
  1233. if ($fieldlist[$field]=='position') $size='size="4" ';
  1234. if ($fieldlist[$field]=='libelle') $size='centpercent';
  1235. if ($fieldlist[$field]=='tracking') $class='centpercent';
  1236. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  1237. print '<input type="text" '.$size.' class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  1238. print '</td>';
  1239. }
  1240. }
  1241. }