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