categories_list.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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/categories_list.php
  30. * \ingroup setup
  31. * \brief Page to administer data tables
  32. */
  33. require '../../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  40. 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. // Security access
  54. if (! empty($user->rights->accountancy->chartofaccount))
  55. {
  56. accessforbidden();
  57. }
  58. $acts[0] = "activate";
  59. $acts[1] = "disable";
  60. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  61. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  62. $listoffset=GETPOST('listoffset');
  63. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  64. $active = 1;
  65. $sortfield = GETPOST("sortfield",'alpha');
  66. $sortorder = GETPOST("sortorder",'alpha');
  67. $page = GETPOST("page",'int');
  68. if ($page == -1) { $page = 0 ; }
  69. $offset = $listlimit * $page ;
  70. $pageprev = $page - 1;
  71. $pagenext = $page + 1;
  72. $search_country_id = GETPOST('search_country_id','int');
  73. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  74. $hookmanager->initHooks(array('admin'));
  75. // This page is a generic page to edit dictionaries
  76. // Put here declaration of dictionaries properties
  77. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  78. $taborder=array(32);
  79. // Name of SQL tables of dictionaries
  80. $tabname=array();
  81. $tabname[32]= MAIN_DB_PREFIX."c_accounting_category";
  82. // Dictionary labels
  83. $tablib=array();
  84. $tablib[32]= "DictionaryAccountancyCategory";
  85. // Requests to extract data
  86. $tabsql=array();
  87. $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";
  88. // Criteria to sort dictionaries
  89. $tabsqlsort=array();
  90. $tabsqlsort[32]="position ASC";
  91. // Nom des champs en resultat de select pour affichage du dictionnaire
  92. $tabfield=array();
  93. $tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country";
  94. // Nom des champs d'edition pour modification d'un enregistrement
  95. $tabfieldvalue=array();
  96. $tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country";
  97. // Nom des champs dans la table pour insertion d'un enregistrement
  98. $tabfieldinsert=array();
  99. $tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country";
  100. // Nom du rowid si le champ n'est pas de type autoincrement
  101. // Example: "" if id field is "rowid" and has autoincrement on
  102. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  103. $tabrowid=array();
  104. $tabrowid[32]= "";
  105. // Condition to show dictionary in setup page
  106. $tabcond=array();
  107. $tabcond[32]= ! empty($conf->accounting->enabled);
  108. // List of help for fields
  109. $tabhelp=array();
  110. $tabhelp[32] = array('code'=>$langs->trans("EnterAnyCode"));
  111. // List of check for fields (NOT USED YET)
  112. $tabfieldcheck=array();
  113. $tabfieldcheck[32] = array();
  114. // Complete all arrays with entries found into modules
  115. complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
  116. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  117. $elementList = array();
  118. $sourceList=array();
  119. /*
  120. * Actions
  121. */
  122. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  123. {
  124. $search_country_id = '';
  125. }
  126. // Actions add or modify an entry into a dictionary
  127. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  128. {
  129. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  130. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  131. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  132. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  133. // Check that all fields are filled
  134. $ok=1;
  135. foreach ($listfield as $f => $value)
  136. {
  137. if ($value == 'country_id' && in_array($tablib[$id],array('DictionaryVAT','DictionaryRegion','DictionaryCompanyType','DictionaryHolidayTypes','DictionaryRevenueStamp','DictionaryAccountancysystem','DictionaryAccountancyCategory'))) continue; // For some pages, country is not mandatory
  138. if ($value == 'country' && in_array($tablib[$id],array('DictionaryCanton','DictionaryCompanyType','DictionaryRevenueStamp'))) continue; // For some pages, country is not mandatory
  139. if ($value == 'formula' && empty($_POST['formula'])) continue;
  140. if ((! isset($_POST[$value]) || $_POST[$value]=='')
  141. && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy')) // Fields that are not mandatory
  142. && (! ($id == 10 && $listfield[$f] == 'code')) // Code is mandatory fir table 10
  143. )
  144. )
  145. {
  146. $ok=0;
  147. $fieldnamekey=$listfield[$f];
  148. // We take translate key of field
  149. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  150. if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
  151. if ($fieldnamekey == 'module') $fieldnamekey='Module';
  152. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  153. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  154. if ($fieldnamekey == 'taux') $fieldnamekey = 'Rate';
  155. if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
  156. if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
  157. if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated';
  158. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  159. }
  160. }
  161. // Other checks
  162. if ($tabname[$id] == MAIN_DB_PREFIX."c_actioncomm" && isset($_POST["type"]) && in_array($_POST["type"],array('system','systemauto'))) {
  163. $ok=0;
  164. setEventMessages($langs->transnoentities('ErrorReservedTypeSystemSystemAuto'), null, 'errors');
  165. }
  166. if (isset($_POST["code"]))
  167. {
  168. if ($_POST["code"]=='0')
  169. {
  170. $ok=0;
  171. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  172. }
  173. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  174. {
  175. $ok = 0;
  176. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
  177. }*/
  178. }
  179. if (isset($_POST["country"]) && ($_POST["country"]=='0'))
  180. {
  181. if (in_array($tablib[$id],array('DictionaryCompanyType','DictionaryHolidayTypes'))) // Field country is no mandatory for such dictionaries
  182. {
  183. $_POST["country"]='';
  184. }
  185. else
  186. {
  187. $ok=0;
  188. setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->transnoentities("Country")), null, 'errors');
  189. }
  190. }
  191. // Clean some parameters
  192. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  193. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  194. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  195. // Si verif ok et action add, on ajoute la ligne
  196. if ($ok && GETPOST('actionadd'))
  197. {
  198. if ($tabrowid[$id])
  199. {
  200. // Recupere id libre pour insertion
  201. $newid=0;
  202. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  203. $result = $db->query($sql);
  204. if ($result)
  205. {
  206. $obj = $db->fetch_object($result);
  207. $newid=($obj->newid + 1);
  208. } else {
  209. dol_print_error($db);
  210. }
  211. }
  212. // Add new entry
  213. $sql = "INSERT INTO ".$tabname[$id]." (";
  214. // List of fields
  215. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  216. $sql.= $tabrowid[$id].",";
  217. $sql.= $tabfieldinsert[$id];
  218. $sql.=",active)";
  219. $sql.= " VALUES(";
  220. // List of values
  221. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  222. $sql.= $newid.",";
  223. $i=0;
  224. foreach ($listfieldinsert as $f => $value)
  225. {
  226. if ($value == 'price' || preg_match('/^amount/i',$value) || $value == 'taux') {
  227. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  228. }
  229. else if ($value == 'entity') {
  230. $_POST[$listfieldvalue[$i]] = $conf->entity;
  231. }
  232. if ($i) $sql.=",";
  233. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  234. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  235. $i++;
  236. }
  237. $sql.=",1)";
  238. dol_syslog("actionadd", LOG_DEBUG);
  239. $result = $db->query($sql);
  240. if ($result) // Add is ok
  241. {
  242. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  243. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  244. }
  245. else
  246. {
  247. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  248. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  249. }
  250. else {
  251. dol_print_error($db);
  252. }
  253. }
  254. }
  255. // Si verif ok et action modify, on modifie la ligne
  256. if ($ok && GETPOST('actionmodify'))
  257. {
  258. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  259. else { $rowidcol="rowid"; }
  260. // Modify entry
  261. $sql = "UPDATE ".$tabname[$id]." SET ";
  262. // Modifie valeur des champs
  263. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  264. {
  265. $sql.= $tabrowid[$id]."=";
  266. $sql.= "'".$db->escape($rowid)."', ";
  267. }
  268. $i = 0;
  269. foreach ($listfieldmodify as $field)
  270. {
  271. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  272. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  273. }
  274. else if ($field == 'entity') {
  275. $_POST[$listfieldvalue[$i]] = $conf->entity;
  276. }
  277. if ($i) $sql.=",";
  278. $sql.= $field."=";
  279. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  280. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  281. $i++;
  282. }
  283. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  284. dol_syslog("actionmodify", LOG_DEBUG);
  285. //print $sql;
  286. $resql = $db->query($sql);
  287. if (! $resql)
  288. {
  289. setEventMessages($db->error(), null, 'errors');
  290. }
  291. }
  292. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  293. }
  294. if (GETPOST('actioncancel'))
  295. {
  296. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  297. }
  298. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  299. {
  300. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  301. else { $rowidcol="rowid"; }
  302. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  303. dol_syslog("delete", LOG_DEBUG);
  304. $result = $db->query($sql);
  305. if (! $result)
  306. {
  307. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  308. {
  309. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  310. }
  311. else
  312. {
  313. dol_print_error($db);
  314. }
  315. }
  316. }
  317. // activate
  318. if ($action == $acts[0])
  319. {
  320. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  321. else { $rowidcol="rowid"; }
  322. if ($rowid) {
  323. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  324. }
  325. elseif ($_GET["code"]) {
  326. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'";
  327. }
  328. $result = $db->query($sql);
  329. if (!$result)
  330. {
  331. dol_print_error($db);
  332. }
  333. }
  334. // disable
  335. if ($action == $acts[1])
  336. {
  337. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  338. else { $rowidcol="rowid"; }
  339. if ($rowid) {
  340. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  341. }
  342. elseif ($_GET["code"]) {
  343. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'";
  344. }
  345. $result = $db->query($sql);
  346. if (!$result)
  347. {
  348. dol_print_error($db);
  349. }
  350. }
  351. // favorite
  352. if ($action == 'activate_favorite')
  353. {
  354. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  355. else { $rowidcol="rowid"; }
  356. if ($rowid) {
  357. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'";
  358. }
  359. elseif ($_GET["code"]) {
  360. $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$_GET["code"]."'";
  361. }
  362. $result = $db->query($sql);
  363. if (!$result)
  364. {
  365. dol_print_error($db);
  366. }
  367. }
  368. // disable favorite
  369. if ($action == 'disable_favorite')
  370. {
  371. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  372. else { $rowidcol="rowid"; }
  373. if ($rowid) {
  374. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'";
  375. }
  376. elseif ($_GET["code"]) {
  377. $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$_GET["code"]."'";
  378. }
  379. $result = $db->query($sql);
  380. if (!$result)
  381. {
  382. dol_print_error($db);
  383. }
  384. }
  385. /*
  386. * View
  387. */
  388. $form = new Form($db);
  389. $formadmin=new FormAdmin($db);
  390. llxHeader();
  391. $titre=$langs->trans("DictionarySetup");
  392. $linkback='';
  393. if ($id)
  394. {
  395. $titre.=' - '.$langs->trans($tablib[$id]);
  396. $linkback='<a href="'.$_SERVER['PHP_SELF'].'">'.$langs->trans("BackToDictionaryList").'</a>';
  397. }
  398. $titlepicto='title_setup';
  399. print load_fiche_titre($titre,$linkback,$titlepicto);
  400. // Confirmation de la suppression de la ligne
  401. if ($action == 'delete')
  402. {
  403. 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);
  404. }
  405. //var_dump($elementList);
  406. /*
  407. * Show a dictionary
  408. */
  409. if ($id)
  410. {
  411. // Complete requete recherche valeurs avec critere de tri
  412. $sql=$tabsql[$id];
  413. if ($search_country_id > 0)
  414. {
  415. if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
  416. else $sql.=" WHERE ";
  417. $sql.= " c.rowid = ".$search_country_id;
  418. }
  419. if ($sortfield)
  420. {
  421. // If sort order is "country", we use country_code instead
  422. if ($sortfield == 'country') $sortfield='country_code';
  423. $sql.= " ORDER BY ".$sortfield;
  424. if ($sortorder)
  425. {
  426. $sql.=" ".strtoupper($sortorder);
  427. }
  428. $sql.=", ";
  429. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  430. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  431. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  432. }
  433. else {
  434. $sql.=" ORDER BY ";
  435. }
  436. $sql.=$tabsqlsort[$id];
  437. $sql.=$db->plimit($listlimit+1,$offset);
  438. //print $sql;
  439. $fieldlist=explode(',',$tabfield[$id]);
  440. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  441. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  442. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  443. print '<table class="noborder" width="100%">';
  444. // Form to add a new line
  445. if ($tabname[$id])
  446. {
  447. $alabelisused=0;
  448. $var=false;
  449. $fieldlist=explode(',',$tabfield[$id]);
  450. // Line for title
  451. print '<tr class="liste_titre">';
  452. foreach ($fieldlist as $field => $value)
  453. {
  454. // Determine le nom du champ par rapport aux noms possibles
  455. // dans les dictionnaires de donnees
  456. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  457. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  458. $align="left";
  459. if ($fieldlist[$field]=='type') {
  460. if ($tabname[$id] == MAIN_DB_PREFIX."c_paiement") $valuetoshow=$form->textwithtooltip($langs->trans("Type"),$langs->trans("TypePaymentDesc"),2,1,img_help(1,''));
  461. else $valuetoshow=$langs->trans("Type");
  462. }
  463. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  464. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  465. {
  466. $valuetoshow=$langs->trans("Label");
  467. }
  468. if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; }
  469. if ($fieldlist[$field]=='country') {
  470. if (in_array('region_id',$fieldlist)) { print '<td>&nbsp;</td>'; continue; } // For region page, we do not show the country input
  471. $valuetoshow=$langs->trans("Country");
  472. }
  473. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $valuetoshow=''; }
  474. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  475. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); }
  476. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); }
  477. if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  478. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  479. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  480. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  481. if ($valuetoshow != '')
  482. {
  483. print '<td align="'.$align.'">';
  484. 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>';
  485. else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  486. else print $valuetoshow;
  487. print '</td>';
  488. }
  489. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  490. }
  491. print '<td>';
  492. print '<input type="hidden" name="id" value="'.$id.'">';
  493. print '</td>';
  494. print '<td style="min-width: 26px;"></td>';
  495. print '<td style="min-width: 26px;"></td>';
  496. print '<td style="min-width: 26px;"></td>';
  497. print '</tr>';
  498. // Line to enter new values
  499. print '<tr class="oddeven nodrag nodrop nohover">';
  500. $obj = new stdClass();
  501. // If data was already input, we define them in obj to populate input fields.
  502. if (GETPOST('actionadd'))
  503. {
  504. foreach ($fieldlist as $key=>$val)
  505. {
  506. if (GETPOST($val) != '')
  507. $obj->$val=GETPOST($val);
  508. }
  509. }
  510. $tmpaction = 'create';
  511. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  512. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  513. $error=$hookmanager->error; $errors=$hookmanager->errors;
  514. if (empty($reshook))
  515. {
  516. fieldListAccountingCategories($fieldlist,$obj,$tabname[$id],'add');
  517. }
  518. print '<td colspan="4" align="right">';
  519. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  520. print '</td>';
  521. print "</tr>";
  522. $colspan=count($fieldlist)+3;
  523. print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  524. }
  525. // List of available record in database
  526. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  527. $resql=$db->query($sql);
  528. if ($resql)
  529. {
  530. $num = $db->num_rows($resql);
  531. $i = 0;
  532. $var=true;
  533. $param = '&id='.$id;
  534. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  535. $paramwithsearch = $param;
  536. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  537. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  538. if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
  539. // There is several pages
  540. if ($num > $listlimit)
  541. {
  542. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  543. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  544. print '</td></tr>';
  545. }
  546. // Title line with search boxes
  547. print '<tr class="liste_titre liste_titre_add liste_titre_filter">';
  548. $filterfound=0;
  549. foreach ($fieldlist as $field => $value)
  550. {
  551. $showfield=1; // By defaut
  552. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  553. if ($showfield)
  554. {
  555. if ($value == 'country')
  556. {
  557. print '<td class="liste_titre">';
  558. print $form->select_country($search_country_id, 'search_country_id', '', 28, 'maxwidth200 maxwidthonsmartphone');
  559. print '</td>';
  560. $filterfound++;
  561. }
  562. else
  563. {
  564. print '<td class="liste_titre"></td>';
  565. }
  566. }
  567. }
  568. print '<td class="liste_titre"></td>';
  569. print '<td class="liste_titre"></td>';
  570. print '<td class="liste_titre"></td>';
  571. print '<td class="liste_titre" align="center">';
  572. if ($filterfound)
  573. {
  574. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  575. print $searchpicto;
  576. }
  577. print '</td>';
  578. print '</tr>';
  579. // Title of lines
  580. print '<tr class="liste_titre">';
  581. foreach ($fieldlist as $field => $value)
  582. {
  583. // Determine le nom du champ par rapport aux noms possibles
  584. // dans les dictionnaires de donnees
  585. $showfield=1; // By defaut
  586. $align="left";
  587. $sortable=1;
  588. $valuetoshow='';
  589. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  590. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  591. if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); }
  592. if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); }
  593. if ($fieldlist[$field]=='taux') {
  594. if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate");
  595. else $valuetoshow=$langs->trans("Amount");
  596. $align='center';
  597. }
  598. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  599. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  600. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  601. {
  602. $valuetoshow=$langs->trans("Label");
  603. if ($id != 25) $valuetoshow.="*";
  604. }
  605. if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); }
  606. if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; }
  607. if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); }
  608. if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; }
  609. if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; }
  610. if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); }
  611. if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); }
  612. if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); }
  613. if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); }
  614. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  615. if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); }
  616. if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); }
  617. if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); }
  618. // Affiche nom du champ
  619. if ($showfield)
  620. {
  621. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  622. }
  623. }
  624. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  625. print getTitleFieldOfList('');
  626. print getTitleFieldOfList('');
  627. print getTitleFieldOfList('');
  628. print '</tr>';
  629. if ($num)
  630. {
  631. // Lines with values
  632. while ($i < $num)
  633. {
  634. $obj = $db->fetch_object($resql);
  635. //print_r($obj);
  636. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  637. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  638. {
  639. $tmpaction='edit';
  640. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  641. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  642. $error=$hookmanager->error; $errors=$hookmanager->errors;
  643. // Show fields
  644. if (empty($reshook)) fieldListAccountingCategories($fieldlist,$obj,$tabname[$id],'edit');
  645. print '<td></td>';
  646. print '<td></td>';
  647. print '<td align="center">';
  648. print '<input type="hidden" name="page" value="'.$page.'">';
  649. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  650. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  651. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  652. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  653. print '</td>';
  654. }
  655. else
  656. {
  657. $tmpaction = 'view';
  658. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  659. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  660. $error=$hookmanager->error; $errors=$hookmanager->errors;
  661. if (empty($reshook))
  662. {
  663. foreach ($fieldlist as $field => $value)
  664. {
  665. $showfield=1;
  666. $align="left";
  667. $valuetoshow=$obj->{$fieldlist[$field]};
  668. if ($value == 'type_template')
  669. {
  670. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  671. }
  672. if ($value == 'element')
  673. {
  674. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  675. }
  676. else if ($value == 'source')
  677. {
  678. $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow;
  679. }
  680. else if ($valuetoshow=='all') {
  681. $valuetoshow=$langs->trans('All');
  682. }
  683. else if ($fieldlist[$field]=='country') {
  684. if (empty($obj->country_code))
  685. {
  686. $valuetoshow='-';
  687. }
  688. else
  689. {
  690. $key=$langs->trans("Country".strtoupper($obj->country_code));
  691. $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country);
  692. }
  693. }
  694. else if ($fieldlist[$field]=='libelle_facture') {
  695. $langs->load("bills");
  696. $key=$langs->trans("PaymentCondition".strtoupper($obj->code));
  697. $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  698. $valuetoshow=nl2br($valuetoshow);
  699. }
  700. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') {
  701. $key=$langs->trans("Country".strtoupper($obj->code));
  702. $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  703. }
  704. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') {
  705. $langs->load("propal");
  706. $key=$langs->trans("AvailabilityType".strtoupper($obj->code));
  707. $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  708. }
  709. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') {
  710. $key=$langs->trans("Action".strtoupper($obj->code));
  711. $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  712. }
  713. else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') {
  714. $key=$langs->trans("Currency".strtoupper($obj->code_iso));
  715. $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->{$fieldlist[$field]});
  716. }
  717. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') {
  718. $key=$langs->trans(strtoupper($obj->code));
  719. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  720. }
  721. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') {
  722. $key=$langs->trans(strtoupper($obj->code));
  723. $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  724. }
  725. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') {
  726. $key=$langs->trans("Civility".strtoupper($obj->code));
  727. $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  728. }
  729. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') {
  730. $langs->load('agenda');
  731. $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code));
  732. $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  733. }
  734. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') {
  735. $langs->load("bills");
  736. $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code));
  737. $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  738. }
  739. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') {
  740. $langs->load("bills");
  741. $key=$langs->trans("PaymentType".strtoupper($obj->code));
  742. $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  743. }
  744. else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') {
  745. $key=$langs->trans("DemandReasonType".strtoupper($obj->code));
  746. $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  747. }
  748. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') {
  749. $langs->load("orders");
  750. $key=$langs->trans($obj->code);
  751. $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->{$fieldlist[$field]};
  752. }
  753. else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') {
  754. $langs->load("sendings");
  755. $key=$langs->trans("SendingMethod".strtoupper($obj->code));
  756. $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->{$fieldlist[$field]});
  757. }
  758. else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format')
  759. {
  760. $key = $langs->trans('PaperFormat'.strtoupper($obj->code));
  761. $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  762. }
  763. else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees')
  764. {
  765. $langs->load('trips');
  766. $key = $langs->trans(strtoupper($obj->code));
  767. $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->{$fieldlist[$field]});
  768. }
  769. else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') {
  770. $showfield=0;
  771. }
  772. else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  773. $langs->load("products");
  774. $valuetoshow=$langs->trans($obj->{$fieldlist[$field]});
  775. }
  776. else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') {
  777. $langs->load("products");
  778. $valuetoshow = $langs->trans($obj->{$fieldlist[$field]});
  779. }
  780. else if (in_array($fieldlist[$field],array('recuperableonly')))
  781. {
  782. $align="center";
  783. }
  784. else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') {
  785. $valuetoshow = length_accountg($valuetoshow);
  786. }
  787. $class='tddict';
  788. if ($fieldlist[$field] == 'tracking') $class.=' tdoverflowauto';
  789. // Show value for field
  790. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  791. }
  792. }
  793. // Can an entry be erased or disabled ?
  794. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  795. if (isset($obj->code))
  796. {
  797. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  798. else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  799. else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  800. }
  801. if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; }
  802. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $canbedisabled=0; $canbedisabled = 0; }
  803. $canbemodified=$iserasable;
  804. if ($obj->code == 'RECEP') $canbemodified=1;
  805. $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):'');
  806. if ($param) $url .= '&'.$param;
  807. $url.='&';
  808. // Active
  809. print '<td align="center" class="nowrap">';
  810. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  811. else
  812. {
  813. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  814. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  815. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  816. else print $langs->trans("AlwaysActive");
  817. }
  818. print "</td>";
  819. // Modify link
  820. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  821. else print '<td>&nbsp;</td>';
  822. // Delete link
  823. if ($iserasable)
  824. {
  825. print '<td align="center">';
  826. if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
  827. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  828. print '</td>';
  829. }
  830. else print '<td>&nbsp;</td>';
  831. // Link to setup the group
  832. print '<td>';
  833. if (empty($obj->formula))
  834. {
  835. print '<a href="'.DOL_URL_ROOT.'/accountancy/admin/categories.php?action=display&account_category='.$obj->rowid.'">'.$langs->trans("Setup").'</a>';
  836. }
  837. print '</td>';
  838. print "</tr>\n";
  839. }
  840. $i++;
  841. }
  842. }
  843. }
  844. else {
  845. dol_print_error($db);
  846. }
  847. print '</table>';
  848. print '</form>';
  849. }
  850. print '<br>';
  851. llxFooter();
  852. $db->close();
  853. /**
  854. * Show fields in insert/edit mode
  855. *
  856. * @param array $fieldlist Array of fields
  857. * @param Object $obj If we show a particular record, obj is filled with record fields
  858. * @param string $tabname Name of SQL table
  859. * @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
  860. * @return void
  861. */
  862. function fieldListAccountingCategories($fieldlist, $obj='', $tabname='', $context='')
  863. {
  864. global $conf,$langs,$db;
  865. global $form, $mysoc;
  866. global $region_id;
  867. global $elementList,$sourceList,$localtax_typeList;
  868. global $bc;
  869. $formadmin = new FormAdmin($db);
  870. $formcompany = new FormCompany($db);
  871. if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
  872. foreach ($fieldlist as $field => $value)
  873. {
  874. if ($fieldlist[$field] == 'country')
  875. {
  876. if (in_array('region_id',$fieldlist))
  877. {
  878. print '<td>';
  879. //print join(',',$fieldlist);
  880. print '</td>';
  881. continue;
  882. } // For state page, we do not show the country input (we link to region, not country)
  883. print '<td>';
  884. $fieldname='country';
  885. print $form->select_country((! empty($obj->country_code)?$obj->country_code:(! empty($obj->country)?$obj->country:$mysoc->country_code)), $fieldname, '', 28, 'maxwidth200 maxwidthonsmartphone');
  886. print '</td>';
  887. }
  888. elseif ($fieldlist[$field] == 'country_id')
  889. {
  890. if (! in_array('country',$fieldlist)) // If there is already a field country, we don't show country_id (avoid duplicate)
  891. {
  892. $country_id = (! empty($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : 0);
  893. print '<td>';
  894. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$country_id.'">';
  895. print '</td>';
  896. }
  897. }
  898. elseif ($fieldlist[$field] == 'region')
  899. {
  900. print '<td>';
  901. $formcompany->select_region($region_id,'region');
  902. print '</td>';
  903. }
  904. elseif ($fieldlist[$field] == 'region_id')
  905. {
  906. $region_id = (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:0);
  907. print '<td>';
  908. print '<input type="hidden" name="'.$fieldlist[$field].'" value="'.$region_id.'">';
  909. print '</td>';
  910. }
  911. elseif ($fieldlist[$field] == 'lang')
  912. {
  913. print '<td>';
  914. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  915. print '</td>';
  916. }
  917. // Le type de template
  918. elseif ($fieldlist[$field] == 'type_template')
  919. {
  920. print '<td>';
  921. print $form->selectarray('type_template', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  922. print '</td>';
  923. }
  924. // Le type de l'element (pour les type de contact)
  925. elseif ($fieldlist[$field] == 'element')
  926. {
  927. print '<td>';
  928. print $form->selectarray('element', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  929. print '</td>';
  930. }
  931. // La source de l'element (pour les type de contact)
  932. elseif ($fieldlist[$field] == 'source')
  933. {
  934. print '<td>';
  935. print $form->selectarray('source', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  936. print '</td>';
  937. }
  938. elseif ($fieldlist[$field] == 'type' && $tabname == MAIN_DB_PREFIX."c_actioncomm")
  939. {
  940. print '<td>';
  941. print 'user<input type="hidden" name="type" value="user">';
  942. print '</td>';
  943. }
  944. elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'type_cdr' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') {
  945. if ($fieldlist[$field] == 'type_cdr') print '<td align="center">';
  946. else print '<td>';
  947. if ($fieldlist[$field] == 'type_cdr') {
  948. 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]}:''));
  949. } else {
  950. print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1);
  951. }
  952. print '</td>';
  953. }
  954. elseif (in_array($fieldlist[$field],array('nbjour','decalage','taux','localtax1','localtax2'))) {
  955. $align="left";
  956. if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) $align="center"; // Fields aligned on right
  957. print '<td align="'.$align.'">';
  958. print '<input type="text" class="flat" value="'.(isset($obj->{$fieldlist[$field]}) ? $obj->{$fieldlist[$field]} : '').'" size="3" name="'.$fieldlist[$field].'">';
  959. print '</td>';
  960. }
  961. elseif (in_array($fieldlist[$field], array('libelle_facture'))) {
  962. print '<td><textarea cols="30" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea></td>';
  963. }
  964. elseif (in_array($fieldlist[$field], array('content')))
  965. {
  966. if ($tabname == MAIN_DB_PREFIX.'c_email_templates')
  967. {
  968. 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
  969. }
  970. else print '<td>';
  971. if ($context != 'hide')
  972. {
  973. //print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  974. $okforextended=true;
  975. if ($tabname == MAIN_DB_PREFIX.'c_email_templates' && empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
  976. $doleditor = new DolEditor($fieldlist[$field], (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_5, '90%');
  977. print $doleditor->Create(1);
  978. }
  979. else print '&nbsp;';
  980. print '</td>';
  981. }
  982. elseif ($fieldlist[$field] == 'price' || preg_match('/^amount/i',$fieldlist[$field])) {
  983. print '<td><input type="text" class="flat minwidth75" value="'.price((! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'')).'" name="'.$fieldlist[$field].'"></td>';
  984. }
  985. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  986. print '<td><input type="text" class="flat minwidth100" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
  987. }
  988. elseif ($fieldlist[$field]=='unit') {
  989. print '<td>';
  990. $units = array(
  991. 'mm' => $langs->trans('SizeUnitmm'),
  992. 'cm' => $langs->trans('SizeUnitcm'),
  993. 'point' => $langs->trans('SizeUnitpoint'),
  994. 'inch' => $langs->trans('SizeUnitinch')
  995. );
  996. print $form->selectarray('unit', $units, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 0, 0, 0);
  997. print '</td>';
  998. }
  999. // Le type de taxe locale
  1000. elseif ($fieldlist[$field] == 'localtax1_type' || $fieldlist[$field] == 'localtax2_type')
  1001. {
  1002. print '<td align="center">';
  1003. print $form->selectarray($fieldlist[$field], $localtax_typeList, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  1004. print '</td>';
  1005. }
  1006. elseif ($fieldlist[$field] == 'accountancy_code' || $fieldlist[$field] == 'accountancy_code_sell' || $fieldlist[$field] == 'accountancy_code_buy')
  1007. {
  1008. print '<td>';
  1009. if (! empty($conf->accounting->enabled))
  1010. {
  1011. $fieldname = $fieldlist[$field];
  1012. $accountancy_account = (! empty($obj->$fieldname) ? $obj->$fieldname : 0);
  1013. print $formaccounting->select_account($accountancy_account, $fieldlist[$field], 1, '', 1, 1, 'maxwidth200 maxwidthonsmartphone');
  1014. }
  1015. else
  1016. {
  1017. $fieldname = $fieldlist[$field];
  1018. print '<input type="text" size="10" class="flat" value="'.(isset($obj->$fieldname)?$obj->$fieldname:'').'" name="'.$fieldlist[$field].'">';
  1019. }
  1020. print '</td>';
  1021. }
  1022. else
  1023. {
  1024. print '<td>';
  1025. $size=''; $class='';
  1026. if ($fieldlist[$field]=='code') $class='maxwidth100';
  1027. if ($fieldlist[$field]=='position') $class='maxwidth50';
  1028. if ($fieldlist[$field]=='libelle') $class='quatrevingtpercent';
  1029. if ($fieldlist[$field]=='tracking') $class='quatrevingtpercent';
  1030. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  1031. print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  1032. print '</td>';
  1033. }
  1034. }
  1035. }