journals_list.php 23 KB

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