journals_list.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. <?php
  2. /* Copyright (C) 2017 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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. // Load translation files required by the page
  32. $langs->loadLangs(array("admin","compta","accountancy"));
  33. $action=GETPOST('action','aZ09')?GETPOST('action','aZ09'):'view';
  34. $confirm=GETPOST('confirm','alpha');
  35. $id=35;
  36. $rowid=GETPOST('rowid','alpha');
  37. $code=GETPOST('code','alpha');
  38. // Security access
  39. if (empty($user->rights->accounting->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', 'alpha');
  48. $listlimit=GETPOST('listlimit', 'int')>0?GETPOST('listlimit', 'int'):1000;
  49. $active = 1;
  50. $sortfield = GETPOST("sortfield",'alpha');
  51. $sortorder = GETPOST("sortorder",'alpha');
  52. $page = GETPOST("page",'int');
  53. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  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 page. Note that conf->hooks_modules contains array of hook context
  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. '5' => $langs->trans('AccountingJournalType5'),
  112. '8' => $langs->trans('AccountingJournalType8'),
  113. '9' => $langs->trans('AccountingJournalType9'),
  114. );
  115. /*
  116. * Actions
  117. */
  118. if (GETPOST('button_removefilter', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter_x', 'alpha'))
  119. {
  120. $search_country_id = '';
  121. }
  122. // Actions add or modify an entry into a dictionary
  123. if (GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha'))
  124. {
  125. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  126. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  127. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  128. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  129. // Check that all fields are filled
  130. $ok=1;
  131. foreach ($listfield as $f => $value)
  132. {
  133. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  134. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  135. if ($fieldnamekey == 'nature') $fieldnamekey = 'Nature';
  136. }
  137. // Other checks
  138. if (isset($_POST["code"]))
  139. {
  140. if ($_POST["code"]=='0')
  141. {
  142. $ok=0;
  143. setEventMessages($langs->transnoentities('ErrorCodeCantContainZero'), null, 'errors');
  144. }
  145. /*if (!is_numeric($_POST['code'])) // disabled, code may not be in numeric base
  146. {
  147. $ok = 0;
  148. $msg .= $langs->transnoentities('ErrorFieldFormat', $langs->transnoentities('Code')).'<br>';
  149. }*/
  150. }
  151. if (! GETPOST('label','alpha'))
  152. {
  153. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
  154. $ok=0;
  155. }
  156. // Clean some parameters
  157. if ($_POST["accountancy_code"] <= 0) $_POST["accountancy_code"]=''; // If empty, we force to null
  158. if ($_POST["accountancy_code_sell"] <= 0) $_POST["accountancy_code_sell"]=''; // If empty, we force to null
  159. if ($_POST["accountancy_code_buy"] <= 0) $_POST["accountancy_code_buy"]=''; // If empty, we force to null
  160. // Si verif ok et action add, on ajoute la ligne
  161. if ($ok && GETPOST('actionadd', 'alpha'))
  162. {
  163. if ($tabrowid[$id])
  164. {
  165. // Recupere id libre pour insertion
  166. $newid=0;
  167. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  168. $result = $db->query($sql);
  169. if ($result)
  170. {
  171. $obj = $db->fetch_object($result);
  172. $newid=($obj->newid + 1);
  173. } else {
  174. dol_print_error($db);
  175. }
  176. }
  177. // Add new entry
  178. $sql = "INSERT INTO ".$tabname[$id]." (";
  179. // List of fields
  180. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  181. $sql.= $tabrowid[$id].",";
  182. $sql.= $tabfieldinsert[$id];
  183. $sql.=",active,entity)";
  184. $sql.= " VALUES(";
  185. // List of values
  186. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  187. $sql.= $newid.",";
  188. $i=0;
  189. foreach ($listfieldinsert as $f => $value)
  190. {
  191. if ($value == 'entity') {
  192. $_POST[$listfieldvalue[$i]] = $conf->entity;
  193. }
  194. if ($i) $sql.=",";
  195. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null"; // For vat, we want/accept code = ''
  196. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  197. $i++;
  198. }
  199. $sql.=",1,".$conf->entity.")";
  200. dol_syslog("actionadd", LOG_DEBUG);
  201. $result = $db->query($sql);
  202. if ($result) // Add is ok
  203. {
  204. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  205. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  206. }
  207. else
  208. {
  209. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  210. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  211. }
  212. else {
  213. dol_print_error($db);
  214. }
  215. }
  216. }
  217. // Si verif ok et action modify, on modifie la ligne
  218. if ($ok && GETPOST('actionmodify', 'alpha'))
  219. {
  220. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  221. else { $rowidcol="rowid"; }
  222. // Modify entry
  223. $sql = "UPDATE ".$tabname[$id]." SET ";
  224. // Modifie valeur des champs
  225. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  226. {
  227. $sql.= $tabrowid[$id]."=";
  228. $sql.= "'".$db->escape($rowid)."', ";
  229. }
  230. $i = 0;
  231. foreach ($listfieldmodify as $field)
  232. {
  233. if ($field == 'price' || preg_match('/^amount/i',$field) || $field == 'taux') {
  234. $_POST[$listfieldvalue[$i]] = price2num($_POST[$listfieldvalue[$i]],'MU');
  235. }
  236. elseif ($field == 'entity') {
  237. $_POST[$listfieldvalue[$i]] = $conf->entity;
  238. }
  239. if ($i) $sql.=",";
  240. $sql.= $field."=";
  241. if ($_POST[$listfieldvalue[$i]] == '' && ! ($listfieldvalue[$i] == 'code' && $id == 10)) $sql.="null"; // For vat, we want/accept code = ''
  242. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  243. $i++;
  244. }
  245. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  246. $sql.=" AND entity = ".$conf->entity;
  247. dol_syslog("actionmodify", LOG_DEBUG);
  248. //print $sql;
  249. $resql = $db->query($sql);
  250. if (! $resql)
  251. {
  252. setEventMessages($db->error(), null, 'errors');
  253. }
  254. }
  255. //$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  256. }
  257. //if (GETPOST('actioncancel', 'alpha'))
  258. //{
  259. // $_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
  260. //}
  261. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  262. {
  263. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  264. else { $rowidcol="rowid"; }
  265. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  266. $sql.=" AND entity = ".$conf->entity;
  267. dol_syslog("delete", LOG_DEBUG);
  268. $result = $db->query($sql);
  269. if (! $result)
  270. {
  271. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  272. {
  273. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  274. }
  275. else
  276. {
  277. dol_print_error($db);
  278. }
  279. }
  280. }
  281. // activate
  282. if ($action == $acts[0])
  283. {
  284. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  285. else { $rowidcol="rowid"; }
  286. if ($rowid) {
  287. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  288. }
  289. elseif ($code) {
  290. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'";
  291. }
  292. $sql.=" AND entity = ".$conf->entity;
  293. $result = $db->query($sql);
  294. if (!$result)
  295. {
  296. dol_print_error($db);
  297. }
  298. }
  299. // disable
  300. if ($action == $acts[1])
  301. {
  302. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  303. else { $rowidcol="rowid"; }
  304. if ($rowid) {
  305. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  306. }
  307. elseif ($code) {
  308. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'";
  309. }
  310. $sql.=" AND entity = ".$conf->entity;
  311. $result = $db->query($sql);
  312. if (!$result)
  313. {
  314. dol_print_error($db);
  315. }
  316. }
  317. /*
  318. * View
  319. */
  320. $form = new Form($db);
  321. $formadmin=new FormAdmin($db);
  322. llxHeader();
  323. $titre=$langs->trans("DictionarySetup");
  324. $linkback='';
  325. if ($id)
  326. {
  327. $titre.=' - '.$langs->trans($tablib[$id]);
  328. $titlepicto='title_accountancy';
  329. }
  330. print load_fiche_titre($titre,$linkback,$titlepicto);
  331. // Confirmation de la suppression de la ligne
  332. if ($action == 'delete')
  333. {
  334. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  335. }
  336. //var_dump($elementList);
  337. /*
  338. * Show a dictionary
  339. */
  340. if ($id)
  341. {
  342. // Complete requete recherche valeurs avec critere de tri
  343. $sql=$tabsql[$id];
  344. $sql.= " WHERE a.entity = ".$conf->entity;
  345. // If sort order is "country", we use country_code instead
  346. if ($sortfield == 'country') $sortfield='country_code';
  347. $sql.=$db->order($sortfield,$sortorder);
  348. $sql.=$db->plimit($listlimit+1,$offset);
  349. $fieldlist=explode(',',$tabfield[$id]);
  350. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  351. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  352. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  353. print '<div class="div-table-responsive">';
  354. print '<table class="noborder" width="100%">';
  355. // Form to add a new line
  356. if ($tabname[$id])
  357. {
  358. $alabelisused=0;
  359. $fieldlist=explode(',',$tabfield[$id]);
  360. // Line for title
  361. print '<tr class="liste_titre">';
  362. foreach ($fieldlist as $field => $value)
  363. {
  364. // Determine le nom du champ par rapport aux noms possibles
  365. // dans les dictionnaires de donnees
  366. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  367. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  368. $align="left";
  369. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  370. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label')
  371. {
  372. $valuetoshow=$langs->trans("Label");
  373. }
  374. if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
  375. if ($valuetoshow != '')
  376. {
  377. print '<td align="'.$align.'">';
  378. 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>';
  379. elseif (! empty($tabhelp[$id][$value])) print $form->textwithpicto($valuetoshow,$tabhelp[$id][$value]);
  380. else print $valuetoshow;
  381. print '</td>';
  382. }
  383. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  384. }
  385. print '<td>';
  386. print '<input type="hidden" name="id" value="'.$id.'">';
  387. print '</td>';
  388. print '<td style="min-width: 26px;"></td>';
  389. print '<td style="min-width: 26px;"></td>';
  390. print '<td style="min-width: 26px;"></td>';
  391. print '</tr>';
  392. // Line to enter new values
  393. print '<tr class="oddeven nodrag nodrap nohover">';
  394. $obj = new stdClass();
  395. // If data was already input, we define them in obj to populate input fields.
  396. if (GETPOST('actionadd', 'alpha'))
  397. {
  398. foreach ($fieldlist as $key=>$val)
  399. {
  400. if (GETPOST($val) != '')
  401. $obj->$val=GETPOST($val);
  402. }
  403. }
  404. $tmpaction = 'create';
  405. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  406. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  407. $error=$hookmanager->error; $errors=$hookmanager->errors;
  408. if (empty($reshook))
  409. {
  410. fieldListJournal($fieldlist,$obj,$tabname[$id],'add');
  411. }
  412. print '<td colspan="4" align="right">';
  413. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  414. print '</td>';
  415. print "</tr>";
  416. print '<tr><td colspan="7">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  417. }
  418. // List of available record in database
  419. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  420. $resql=$db->query($sql);
  421. if ($resql)
  422. {
  423. $num = $db->num_rows($resql);
  424. $i = 0;
  425. $param = '&id='.$id;
  426. if ($search_country_id > 0) $param.= '&search_country_id='.$search_country_id;
  427. $paramwithsearch = $param;
  428. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  429. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  430. if (GETPOST('from', 'alpha')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
  431. // There is several pages
  432. if ($num > $listlimit)
  433. {
  434. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  435. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  436. print '</td></tr>';
  437. }
  438. // Title line with search boxes
  439. print '<tr class="liste_titre_filter liste_titre_add">';
  440. print '<td class="liste_titre"></td>';
  441. print '<td class="liste_titre"></td>';
  442. print '<td class="liste_titre"></td>';
  443. print '<td class="liste_titre"></td>';
  444. print '<td class="liste_titre"></td>';
  445. print '<td class="liste_titre"></td>';
  446. print '<td class="liste_titre" align="center">';
  447. if ($filterfound)
  448. {
  449. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  450. print $searchpicto;
  451. }
  452. print '</td>';
  453. print '</tr>';
  454. // Title of lines
  455. print '<tr class="liste_titre">';
  456. foreach ($fieldlist as $field => $value)
  457. {
  458. // Determine le nom du champ par rapport aux noms possibles
  459. // dans les dictionnaires de donnees
  460. $showfield=1; // By defaut
  461. $align="left";
  462. $sortable=1;
  463. $valuetoshow='';
  464. /*
  465. $tmparray=getLabelOfField($fieldlist[$field]);
  466. $showfield=$tmp['showfield'];
  467. $valuetoshow=$tmp['valuetoshow'];
  468. $align=$tmp['align'];
  469. $sortable=$tmp['sortable'];
  470. */
  471. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  472. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  473. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  474. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
  475. if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); }
  476. // Affiche nom du champ
  477. if ($showfield)
  478. {
  479. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  480. }
  481. }
  482. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  483. print getTitleFieldOfList('');
  484. print getTitleFieldOfList('');
  485. print getTitleFieldOfList('');
  486. print '</tr>';
  487. if ($num)
  488. {
  489. // Lines with values
  490. while ($i < $num)
  491. {
  492. $obj = $db->fetch_object($resql);
  493. //print_r($obj);
  494. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  495. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  496. {
  497. $tmpaction='edit';
  498. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  499. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  500. $error=$hookmanager->error; $errors=$hookmanager->errors;
  501. // Show fields
  502. if (empty($reshook)) fieldListJournal($fieldlist,$obj,$tabname[$id],'edit');
  503. print '<td align="center" colspan="4">';
  504. print '<input type="hidden" name="page" value="'.$page.'">';
  505. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  506. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  507. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  508. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  509. print '</td>';
  510. }
  511. else
  512. {
  513. $tmpaction = 'view';
  514. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  515. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  516. $error=$hookmanager->error; $errors=$hookmanager->errors;
  517. if (empty($reshook))
  518. {
  519. $langs->load("accountancy");
  520. foreach ($fieldlist as $field => $value)
  521. {
  522. $showfield=1;
  523. $align="left";
  524. $valuetoshow=$obj->{$fieldlist[$field]};
  525. if ($valuetoshow=='all') {
  526. $valuetoshow=$langs->trans('All');
  527. }
  528. elseif ($fieldlist[$field]=='nature' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
  529. $key=$langs->trans("AccountingJournalType".strtoupper($obj->nature));
  530. $valuetoshow=($obj->nature && $key != "AccountingJournalType".strtoupper($langs->trans($obj->nature))?$key:$obj->{$fieldlist[$field]});
  531. }
  532. elseif ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'accounting_journal') {
  533. $valuetoshow=$langs->trans($obj->label);
  534. }
  535. $class='tddict';
  536. // Show value for field
  537. if ($showfield) print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  538. }
  539. }
  540. // Can an entry be erased or disabled ?
  541. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  542. if (isset($obj->code) && $id != 10)
  543. {
  544. if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $canbedisabled = 0; }
  545. elseif ($obj->code == 'RECEP') { $iserasable = 0; $canbedisabled = 0; }
  546. elseif ($obj->code == 'EF0') { $iserasable = 0; $canbedisabled = 0; }
  547. }
  548. $canbemodified=$iserasable;
  549. $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):'');
  550. if ($param) $url .= '&'.$param;
  551. $url.='&';
  552. // Active
  553. print '<td align="center" class="nowrap">';
  554. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  555. else print $langs->trans("AlwaysActive");
  556. print "</td>";
  557. // Modify link
  558. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  559. else print '<td>&nbsp;</td>';
  560. // Delete link
  561. if ($iserasable)
  562. {
  563. print '<td align="center">';
  564. if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
  565. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  566. print '</td>';
  567. }
  568. else print '<td>&nbsp;</td>';
  569. print '<td></td>';
  570. print '</td>';
  571. }
  572. print "</tr>\n";
  573. $i++;
  574. }
  575. }
  576. }
  577. else {
  578. dol_print_error($db);
  579. }
  580. print '</table>';
  581. print '</div>';
  582. print '</form>';
  583. }
  584. print '<br>';
  585. // End of page
  586. llxFooter();
  587. $db->close();
  588. /**
  589. * Show fields in insert/edit mode
  590. *
  591. * @param array $fieldlist Array of fields
  592. * @param Object $obj If we show a particular record, obj is filled with record fields
  593. * @param string $tabname Name of SQL table
  594. * @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
  595. * @return void
  596. */
  597. function fieldListJournal($fieldlist, $obj = '', $tabname = '', $context = '')
  598. {
  599. global $conf,$langs,$db;
  600. global $form, $mysoc;
  601. global $region_id;
  602. global $elementList,$sourceList,$localtax_typeList;
  603. global $bc;
  604. $formadmin = new FormAdmin($db);
  605. $formcompany = new FormCompany($db);
  606. foreach ($fieldlist as $field => $value)
  607. {
  608. if ($fieldlist[$field] == 'nature')
  609. {
  610. print '<td>';
  611. print $form->selectarray('nature', $sourceList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  612. print '</td>';
  613. }
  614. elseif ($fieldlist[$field] == 'code' && isset($obj->{$fieldlist[$field]})) {
  615. print '<td><input type="text" class="flat minwidth100" value="'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'"></td>';
  616. }
  617. else
  618. {
  619. print '<td>';
  620. $size=''; $class='';
  621. if ($fieldlist[$field]=='code') $class='maxwidth100';
  622. if ($fieldlist[$field]=='label') $class='quatrevingtpercent';
  623. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  624. print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  625. print '</td>';
  626. }
  627. }
  628. }