journals_list.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. <?php
  2. /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@zendsi.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/journals_list.php
  20. * \ingroup Advanced accountancy
  21. * \brief Setup page to configure journals
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  31. $langs->load("admin");
  32. $langs->load("compta");
  33. $langs->load("accountancy");
  34. $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
  35. $confirm=GETPOST('confirm','alpha');
  36. $id=GETPOST('id','int');
  37. $rowid=GETPOST('rowid','alpha');
  38. // Security access
  39. if (! empty($user->rights->accountancy->chartofaccount))
  40. {
  41. accessforbidden();
  42. }
  43. $acts[0] = "activate";
  44. $acts[1] = "disable";
  45. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  46. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  47. $listoffset=GETPOST('listoffset');
  48. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  49. $active = 1;
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page",'int');
  53. if ($page == -1) { $page = 0 ; }
  54. $offset = $listlimit * $page ;
  55. $pageprev = $page - 1;
  56. $pagenext = $page + 1;
  57. if (empty($sortfield)) $sortfield='code';
  58. if (empty($sortorder)) $sortorder='ASC';
  59. $error = 0;
  60. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  61. $hookmanager->initHooks(array('admin'));
  62. // This page is a generic page to edit dictionaries
  63. // Put here declaration of dictionaries properties
  64. // Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
  65. $taborder=array(35);
  66. // Name of SQL tables of dictionaries
  67. $tabname=array();
  68. $tabname[35]= MAIN_DB_PREFIX."accounting_journal";
  69. // Dictionary labels
  70. $tablib=array();
  71. $tablib[35]= "DictionaryAccountancyJournal";
  72. // Requests to extract data
  73. $tabsql=array();
  74. $tabsql[35]= "SELECT a.rowid as rowid, a.code as code, a.label, a.nature, a.active FROM ".MAIN_DB_PREFIX."accounting_journal as a";
  75. // Criteria to sort dictionaries
  76. $tabsqlsort=array();
  77. $tabsqlsort[35]="code ASC";
  78. // Nom des champs en resultat de select pour affichage du dictionnaire
  79. $tabfield=array();
  80. $tabfield[35]= "code,label,nature";
  81. // Nom des champs d'edition pour modification d'un enregistrement
  82. $tabfieldvalue=array();
  83. $tabfieldvalue[35]= "code,label,nature";
  84. // Nom des champs dans la table pour insertion d'un enregistrement
  85. $tabfieldinsert=array();
  86. $tabfieldinsert[35]= "code,label,nature";
  87. // Nom du rowid si le champ n'est pas de type autoincrement
  88. // Example: "" if id field is "rowid" and has autoincrement on
  89. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  90. $tabrowid=array();
  91. $tabrowid[35]= "";
  92. // Condition to show dictionary in setup page
  93. $tabcond=array();
  94. $tabcond[35]= ! empty($conf->accounting->enabled);
  95. // List of help for fields
  96. $tabhelp=array();
  97. $tabhelp[35] = array('code'=>$langs->trans("EnterAnyCode"));
  98. // List of check for fields (NOT USED YET)
  99. $tabfieldcheck=array();
  100. $tabfieldcheck[35] = array();
  101. // Complete all arrays with entries found into modules
  102. complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort,$tabfield,$tabfieldvalue,$tabfieldinsert,$tabrowid,$tabcond,$tabhelp,$tabfieldcheck);
  103. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  104. $elementList = array();
  105. // Must match ids defined into eldy.lib.php
  106. $sourceList = array(
  107. '1' => $langs->trans('AccountingJournalType1'),
  108. '2' => $langs->trans('AccountingJournalType2'),
  109. '3' => $langs->trans('AccountingJournalType3'),
  110. '4' => $langs->trans('AccountingJournalType4'),
  111. '9' => $langs->trans('AccountingJournalType9')
  112. );
  113. /*
  114. * Actions
  115. */
  116. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  117. {
  118. $search_country_id = '';
  119. }
  120. // Actions add or modify an entry into a dictionary
  121. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  122. {
  123. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  124. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  125. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  126. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  127. // Check that all fields are filled
  128. $ok=1;
  129. foreach ($listfield as $f => $value)
  130. {
  131. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  132. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  133. if ($fieldnamekey == 'nature') $fieldnamekey = 'Nature';
  134. }
  135. // Other checks
  136. if (isset($_POST["code"]))
  137. {
  138. if ($_POST["code"]=='0')
  139. {
  140. $ok=0;
  141. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  142. }
  143. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  144. {
  145. $ok = 0;
  146. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br />';
  147. }*/
  148. }
  149. // Clean some parameters
  150. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  151. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  152. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  153. // Si verif ok et action add, on ajoute la ligne
  154. if ($ok && GETPOST('actionadd'))
  155. {
  156. if ($tabrowid[$id])
  157. {
  158. // Recupere id libre pour insertion
  159. $newid=0;
  160. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  161. $result = $db->query($sql);
  162. if ($result)
  163. {
  164. $obj = $db->fetch_object($result);
  165. $newid=($obj->newid + 1);
  166. } else {
  167. dol_print_error($db);
  168. }
  169. }
  170. // Add new entry
  171. $sql = "INSERT INTO ".$tabname[$id]." (";
  172. // List of fields
  173. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  174. $sql.= $tabrowid[$id].",";
  175. $sql.= $tabfieldinsert[$id];
  176. $sql.=",active)";
  177. $sql.= " VALUES(";
  178. // List of values
  179. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  180. $sql.= $newid.",";
  181. $i=0;
  182. foreach ($listfieldinsert as $f => $value)
  183. {
  184. if ($value == 'entity') {
  185. $_POST[$listfieldvalue[$i]] = $conf->entity;
  186. }
  187. if ($i) $sql.=",";
  188. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  189. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  190. $i++;
  191. }
  192. $sql.=",1)";
  193. dol_syslog("actionadd", LOG_DEBUG);
  194. $result = $db->query($sql);
  195. if ($result) // Add is ok
  196. {
  197. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  198. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  199. }
  200. else
  201. {
  202. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  203. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  204. }
  205. else {
  206. dol_print_error($db);
  207. }
  208. }
  209. }
  210. // Si verif ok et action modify, on modifie la ligne
  211. if ($ok && GETPOST('actionmodify'))
  212. {
  213. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  214. else { $rowidcol="rowid"; }
  215. // Modify entry
  216. $sql = "UPDATE ".$tabname[$id]." SET ";
  217. // Modifie valeur des champs
  218. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  219. {
  220. $sql.= $tabrowid[$id]."=";
  221. $sql.= "'".$db->escape($rowid)."', ";
  222. }
  223. $i = 0;
  224. foreach ($listfieldmodify as $field)
  225. {
  226. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  227. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  228. }
  229. else if ($field == 'entity') {
  230. $_POST[$listfieldvalue[$i]] = $conf->entity;
  231. }
  232. if ($i) $sql.=",";
  233. $sql.= $field."=";
  234. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  235. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  236. $i++;
  237. }
  238. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  239. dol_syslog("actionmodify", LOG_DEBUG);
  240. //print $sql;
  241. $resql = $db->query($sql);
  242. if (! $resql)
  243. {
  244. setEventMessages($db->error(), null, 'errors');
  245. }
  246. }
  247. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  248. }
  249. if (GETPOST('actioncancel'))
  250. {
  251. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  252. }
  253. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  254. {
  255. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  256. else { $rowidcol="rowid"; }
  257. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  258. dol_syslog("delete", LOG_DEBUG);
  259. $result = $db->query($sql);
  260. if (! $result)
  261. {
  262. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  263. {
  264. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  265. }
  266. else
  267. {
  268. dol_print_error($db);
  269. }
  270. }
  271. }
  272. // activate
  273. if ($action == $acts[0])
  274. {
  275. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  276. else { $rowidcol="rowid"; }
  277. if ($rowid) {
  278. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  279. }
  280. elseif ($_GET["code"]) {
  281. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'";
  282. }
  283. $result = $db->query($sql);
  284. if (!$result)
  285. {
  286. dol_print_error($db);
  287. }
  288. }
  289. // disable
  290. if ($action == $acts[1])
  291. {
  292. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  293. else { $rowidcol="rowid"; }
  294. if ($rowid) {
  295. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  296. }
  297. elseif ($_GET["code"]) {
  298. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'";
  299. }
  300. $result = $db->query($sql);
  301. if (!$result)
  302. {
  303. dol_print_error($db);
  304. }
  305. }
  306. /*
  307. * View
  308. */
  309. $form = new Form($db);
  310. $formadmin=new FormAdmin($db);
  311. llxHeader();
  312. $titre=$langs->trans("DictionarySetup");
  313. $linkback='';
  314. if ($id)
  315. {
  316. $titre.=' - '.$langs->trans($tablib[$id]);
  317. $titlepicto='title_accountancy';
  318. }
  319. print load_fiche_titre($titre,$linkback,$titlepicto);
  320. if (empty($id))
  321. {
  322. print $langs->trans("DictionaryDesc");
  323. print " ".$langs->trans("OnlyActiveElementsAreShown")."<br>\n";
  324. }
  325. print "<br>\n";
  326. // Confirmation de la suppression de la ligne
  327. if ($action == 'delete')
  328. {
  329. 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);
  330. }
  331. //var_dump($elementList);
  332. /*
  333. * Show a dictionary
  334. */
  335. if ($id)
  336. {
  337. // Complete requete recherche valeurs avec critere de tri
  338. $sql=$tabsql[$id];
  339. if ($search_country_id > 0)
  340. {
  341. if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
  342. else $sql.=" WHERE ";
  343. $sql.= " c.rowid = ".$search_country_id;
  344. }
  345. if ($sortfield)
  346. {
  347. // If sort order is "country", we use country_code instead
  348. if ($sortfield == 'country') $sortfield='country_code';
  349. $sql.= " ORDER BY ".$sortfield;
  350. if ($sortorder)
  351. {
  352. $sql.=" ".strtoupper($sortorder);
  353. }
  354. $sql.=", ";
  355. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  356. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  357. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  358. }
  359. else {
  360. $sql.=" ORDER BY ";
  361. }
  362. $sql.=$tabsqlsort[$id];
  363. $sql.=$db->plimit($listlimit+1,$offset);
  364. //print $sql;
  365. $fieldlist=explode(',',$tabfield[$id]);
  366. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  367. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  368. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  369. print '<table class="noborder" width="100%">';
  370. // Form to add a new line
  371. if ($tabname[$id])
  372. {
  373. $alabelisused=0;
  374. $var=false;
  375. $fieldlist=explode(',',$tabfield[$id]);
  376. // Line for title
  377. print '<tr class="liste_titre">';
  378. foreach ($fieldlist as $field => $value)
  379. {
  380. // Determine le nom du champ par rapport aux noms possibles
  381. // dans les dictionnaires de donnees
  382. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  383. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  384. $align="left";
  385. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  386. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  387. {
  388. $valuetoshow=$langs->trans("Label");
  389. }
  390. if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
  391. if ($valuetoshow != '')
  392. {
  393. print '<td align="'.$align.'">';
  394. 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>';
  395. else if (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  396. else print $valuetoshow;
  397. print '</td>';
  398. }
  399. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  400. }
  401. print '<td>';
  402. print '<input type="hidden" name="id" value="'.$id.'">';
  403. print '</td>';
  404. print '<td style="min-width: 26px;"></td>';
  405. print '<td style="min-width: 26px;"></td>';
  406. print '<td style="min-width: 26px;"></td>';
  407. print '</tr>';
  408. // Line to enter new values
  409. print '<tr class="oddeven nodrag nodrap nohover">';
  410. $obj = new stdClass();
  411. // If data was already input, we define them in obj to populate input fields.
  412. if (GETPOST('actionadd'))
  413. {
  414. foreach ($fieldlist as $key=>$val)
  415. {
  416. if (GETPOST($val) != '')
  417. $obj->$val=GETPOST($val);
  418. }
  419. }
  420. $tmpaction = 'create';
  421. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  422. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  423. $error=$hookmanager->error; $errors=$hookmanager->errors;
  424. if (empty($reshook))
  425. {
  426. fieldList($fieldlist,$obj,$tabname[$id],'add');
  427. }
  428. print '<td colspan="4" align="right">';
  429. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  430. print '</td>';
  431. print "</tr>";
  432. print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  433. }
  434. // List of available record in database
  435. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  436. $resql=$db->query($sql);
  437. if ($resql)
  438. {
  439. $num = $db->num_rows($resql);
  440. $i = 0;
  441. $var=true;
  442. $param = '&id='.$id;
  443. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  444. $paramwithsearch = $param;
  445. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  446. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  447. if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
  448. // There is several pages
  449. if ($num > $listlimit)
  450. {
  451. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  452. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  453. print '</td></tr>';
  454. }
  455. // Title of lines
  456. print '<tr class="liste_titre liste_titre_add">';
  457. foreach ($fieldlist as $field => $value)
  458. {
  459. // Determine le nom du champ par rapport aux noms possibles
  460. // dans les dictionnaires de donnees
  461. $showfield=1; // By defaut
  462. $align="left";
  463. $sortable=1;
  464. $valuetoshow='';
  465. /*
  466. $tmparray=getLabelOfField($fieldlist[$field]);
  467. $showfield=$tmp['showfield'];
  468. $valuetoshow=$tmp['valuetoshow'];
  469. $align=$tmp['align'];
  470. $sortable=$tmp['sortable'];
  471. */
  472. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  473. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  474. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  475. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
  476. if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
  477. // Affiche nom du champ
  478. if ($showfield)
  479. {
  480. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  481. }
  482. }
  483. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  484. print getTitleFieldOfList('');
  485. print getTitleFieldOfList('');
  486. print getTitleFieldOfList('');
  487. print '</tr>';
  488. // Title line with search boxes
  489. print '<tr class="liste_titre_filter">';
  490. print '<td class="liste_titre"></td>';
  491. print '<td class="liste_titre"></td>';
  492. print '<td class="liste_titre"></td>';
  493. print '<td class="liste_titre"></td>';
  494. print '<td class="liste_titre"></td>';
  495. print '<td class="liste_titre"></td>';
  496. print '<td class="liste_titre" align="center">';
  497. if ($filterfound)
  498. {
  499. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  500. print $searchpicto;
  501. }
  502. print '</td>';
  503. print '</tr>';
  504. if ($num)
  505. {
  506. // Lines with values
  507. while ($i < $num)
  508. {
  509. $obj = $db->fetch_object($resql);
  510. //print_r($obj);
  511. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  512. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  513. {
  514. $tmpaction='edit';
  515. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  516. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  517. $error=$hookmanager->error; $errors=$hookmanager->errors;
  518. // Show fields
  519. if (empty($reshook)) fieldList($fieldlist,$obj,$tabname[$id],'edit');
  520. print '<td align="center" colspan="4">';
  521. print '<input type="hidden" name="page" value="'.$page.'">';
  522. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  523. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  524. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  525. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  526. print '</td>';
  527. }
  528. else
  529. {
  530. $tmpaction = 'view';
  531. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  532. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  533. $error=$hookmanager->error; $errors=$hookmanager->errors;
  534. if (empty($reshook))
  535. {
  536. foreach ($fieldlist as $field => $value)
  537. {
  538. $showfield=1;
  539. $align="left";
  540. $valuetoshow=$obj->{$fieldlist[$field]};
  541. if ($valuetoshow=='all') {
  542. $valuetoshow=$langs->trans('All');
  543. }
  544. else if ($fieldlist[$field]=='nature' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
  545. $langs->load("accountancy");
  546. $key=$langs->trans("AccountingJournalType".strtoupper($obj->nature));
  547. $valuetoshow=($obj->nature && $key != "AccountingJournalType".strtoupper($obj->nature)?$key:$obj->{$fieldlist[$field]});
  548. }
  549. $class='tddict';
  550. // Show value for field
  551. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  552. }
  553. }
  554. // Can an entry be erased or disabled ?
  555. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  556. if (isset($obj->code) && $id != 10)
  557. {
  558. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  559. else if ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  560. else if ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  561. }
  562. $canbemodified=$iserasable;
  563. $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):'');
  564. if ($param) $url .= '&'.$param;
  565. $url.='&';
  566. // Active
  567. print '<td align="center" class="nowrap">';
  568. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  569. else
  570. {
  571. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  572. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  573. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  574. else print $langs->trans("AlwaysActive");
  575. }
  576. print "</td>";
  577. // Modify link
  578. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  579. else print '<td>&nbsp;</td>';
  580. // Delete link
  581. if ($iserasable)
  582. {
  583. print '<td align="center">';
  584. if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
  585. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  586. print '</td>';
  587. }
  588. else print '<td>&nbsp;</td>';
  589. print '<td></td>';
  590. print '</td>';
  591. }
  592. print "</tr>\n";
  593. $i++;
  594. }
  595. }
  596. }
  597. else {
  598. dol_print_error($db);
  599. }
  600. print '</table>';
  601. print '</form>';
  602. }
  603. print '<br>';
  604. llxFooter();
  605. $db->close();
  606. /**
  607. * Show fields in insert/edit mode
  608. *
  609. * @param array $fieldlist Array of fields
  610. * @param Object $obj If we show a particular record, obj is filled with record fields
  611. * @param string $tabname Name of SQL table
  612. * @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
  613. * @return void
  614. */
  615. function fieldList($fieldlist, $obj='', $tabname='', $context='')
  616. {
  617. global $conf,$langs,$db;
  618. global $form, $mysoc;
  619. global $region_id;
  620. global $elementList,$sourceList,$localtax_typeList;
  621. global $bc;
  622. $formadmin = new FormAdmin($db);
  623. $formcompany = new FormCompany($db);
  624. foreach ($fieldlist as $field => $value)
  625. {
  626. if ($fieldlist[$field] == 'nature')
  627. {
  628. print '<td>';
  629. print $form->selectarray('nature', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  630. print '</td>';
  631. }
  632. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  633. print '<td><input type="text" class="flat minwidth100" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
  634. }
  635. else
  636. {
  637. print '<td>';
  638. $size=''; $class='';
  639. if ($fieldlist[$field]=='code') $class='maxwidth100';
  640. if ($fieldlist[$field]=='label') $class='quatrevingtpercent';
  641. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  642. print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  643. print '</td>';
  644. }
  645. }
  646. }