2017-03-28 06:35:03 +02:00
< ? php
2022-06-12 07:30:09 +02:00
/* Copyright ( C ) 2017 - 2022 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2017-03-28 06:35:03 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2017-03-28 06:35:03 +02:00
*
*/
/**
2017-04-30 07:41:47 +02:00
* \file htdocs / accountancy / admin / journals_list . php
2019-05-13 22:25:15 +02:00
* \ingroup Accountancy ( Double entries )
2017-03-28 06:35:03 +02:00
* \brief Setup page to configure journals
*/
2018-06-26 01:25:03 +02:00
2021-02-22 21:36:42 +01:00
if ( ! defined ( 'CSRFCHECK_WITH_TOKEN' )) {
define ( 'CSRFCHECK_WITH_TOKEN' , '1' ); // Force use of CSRF protection with tokens even for GET
}
2020-09-30 12:54:05 +02:00
2017-03-28 06:35:03 +02:00
require '../../main.inc.php' ;
2017-05-01 08:16:09 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formadmin.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php' ;
2017-03-28 06:35:03 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2019-11-14 12:09:15 +01:00
$langs -> loadLangs ( array ( " admin " , " compta " , " accountancy " ));
2017-03-28 06:35:03 +02:00
2019-11-14 12:09:15 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ;
$confirm = GETPOST ( 'confirm' , 'alpha' );
$id = 35 ;
$rowid = GETPOST ( 'rowid' , 'alpha' );
$code = GETPOST ( 'code' , 'alpha' );
2017-05-01 08:16:09 +02:00
// Security access
2021-02-22 21:36:42 +01:00
if ( empty ( $user -> rights -> accounting -> chartofaccount )) {
2017-03-28 06:35:03 +02:00
accessforbidden ();
2017-05-01 08:16:09 +02:00
}
$acts [ 0 ] = " activate " ;
$acts [ 1 ] = " disable " ;
2021-04-19 22:52:13 +02:00
$actl [ 0 ] = img_picto ( $langs -> trans ( " Disabled " ), 'switch_off' , 'class="size15x"' );
$actl [ 1 ] = img_picto ( $langs -> trans ( " Activated " ), 'switch_on' , 'class="size15x"' );
2017-05-01 08:16:09 +02:00
2019-11-14 12:09:15 +01:00
$listoffset = GETPOST ( 'listoffset' , 'alpha' );
$listlimit = GETPOST ( 'listlimit' , 'int' ) > 0 ? GETPOST ( 'listlimit' , 'int' ) : 1000 ;
2017-05-01 08:16:09 +02:00
$active = 1 ;
2022-01-13 11:09:37 +01:00
$sortfield = GETPOST ( 'sortfield' , 'aZ09comma' );
$sortorder = GETPOST ( 'sortorder' , 'aZ09comma' );
2020-03-13 13:07:11 +01:00
$page = GETPOSTISSET ( 'pageplusone' ) ? ( GETPOST ( 'pageplusone' ) - 1 ) : GETPOST ( " page " , 'int' );
2021-02-22 21:36:42 +01:00
if ( empty ( $page ) || $page == - 1 ) {
$page = 0 ;
} // If $page is not defined, or '' or -1
2019-11-14 12:09:15 +01:00
$offset = $listlimit * $page ;
2017-05-01 08:16:09 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2021-02-22 21:36:42 +01:00
if ( empty ( $sortfield )) {
$sortfield = 'code' ;
}
if ( empty ( $sortorder )) {
$sortorder = 'ASC' ;
}
2017-05-01 08:16:09 +02:00
2017-03-28 06:35:03 +02:00
$error = 0 ;
2022-06-12 07:30:09 +02:00
$search_country_id = GETPOST ( 'search_country_id' , 'int' );
2017-06-10 12:56:28 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
2017-05-01 08:16:09 +02:00
$hookmanager -> initHooks ( array ( 'admin' ));
// This page is a generic page to edit dictionaries
// Put here declaration of dictionaries properties
// Sort order to show dictionary (0 is space). All other dictionaries (added by modules) will be at end of this.
2019-11-14 12:09:15 +01:00
$taborder = array ( 35 );
2017-05-01 08:16:09 +02:00
// Name of SQL tables of dictionaries
2019-11-14 12:09:15 +01:00
$tabname = array ();
$tabname [ 35 ] = MAIN_DB_PREFIX . " accounting_journal " ;
2017-03-28 06:35:03 +02:00
2017-05-01 08:16:09 +02:00
// Dictionary labels
2019-11-14 12:09:15 +01:00
$tablib = array ();
$tablib [ 35 ] = " DictionaryAccountancyJournal " ;
2017-03-28 06:35:03 +02:00
2017-05-01 08:16:09 +02:00
// Requests to extract data
2019-11-14 12:09:15 +01:00
$tabsql = array ();
$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 " ;
2017-03-28 06:35:03 +02:00
2017-05-01 08:16:09 +02:00
// Criteria to sort dictionaries
2019-11-14 12:09:15 +01:00
$tabsqlsort = array ();
$tabsqlsort [ 35 ] = " code ASC " ;
2017-05-01 08:16:09 +02:00
// Nom des champs en resultat de select pour affichage du dictionnaire
2019-11-14 12:09:15 +01:00
$tabfield = array ();
$tabfield [ 35 ] = " code,label,nature " ;
2017-05-01 08:16:09 +02:00
// Nom des champs d'edition pour modification d'un enregistrement
2019-11-14 12:09:15 +01:00
$tabfieldvalue = array ();
$tabfieldvalue [ 35 ] = " code,label,nature " ;
2017-05-01 08:16:09 +02:00
// Nom des champs dans la table pour insertion d'un enregistrement
2019-11-14 12:09:15 +01:00
$tabfieldinsert = array ();
$tabfieldinsert [ 35 ] = " code,label,nature " ;
2017-05-01 08:16:09 +02:00
// Nom du rowid si le champ n'est pas de type autoincrement
// Example: "" if id field is "rowid" and has autoincrement on
// "nameoffield" if id field is not "rowid" or has not autoincrement on
2019-11-14 12:09:15 +01:00
$tabrowid = array ();
$tabrowid [ 35 ] = " " ;
2017-05-01 08:16:09 +02:00
// Condition to show dictionary in setup page
2019-11-14 12:09:15 +01:00
$tabcond = array ();
2022-08-24 10:34:04 +02:00
$tabcond [ 35 ] = isModEnabled ( 'accounting' );
2017-05-01 08:16:09 +02:00
// List of help for fields
2019-11-14 12:09:15 +01:00
$tabhelp = array ();
2017-05-01 08:16:09 +02:00
$tabhelp [ 35 ] = array ( 'code' => $langs -> trans ( " EnterAnyCode " ));
// List of check for fields (NOT USED YET)
2019-11-14 12:09:15 +01:00
$tabfieldcheck = array ();
2017-05-01 08:16:09 +02:00
$tabfieldcheck [ 35 ] = array ();
// Complete all arrays with entries found into modules
2019-01-27 11:55:16 +01:00
complete_dictionary_with_modules ( $taborder , $tabname , $tablib , $tabsql , $tabsqlsort , $tabfield , $tabfieldvalue , $tabfieldinsert , $tabrowid , $tabcond , $tabhelp , $tabfieldcheck );
2017-05-01 08:16:09 +02:00
// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
$elementList = array ();
2018-09-09 13:42:38 +02:00
// Must match ids defined into eldy.lib.php
$sourceList = array (
'1' => $langs -> trans ( 'AccountingJournalType1' ),
'2' => $langs -> trans ( 'AccountingJournalType2' ),
'3' => $langs -> trans ( 'AccountingJournalType3' ),
'4' => $langs -> trans ( 'AccountingJournalType4' ),
'5' => $langs -> trans ( 'AccountingJournalType5' ),
'8' => $langs -> trans ( 'AccountingJournalType8' ),
'9' => $langs -> trans ( 'AccountingJournalType9' ),
);
2017-03-28 06:35:03 +02:00
/*
* Actions
*/
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'button_removefilter' , 'alpha' ) || GETPOST ( 'button_removefilter.x' , 'alpha' ) || GETPOST ( 'button_removefilter_x' , 'alpha' )) {
2017-10-07 13:09:31 +02:00
$search_country_id = '' ;
2017-05-01 08:16:09 +02:00
}
// Actions add or modify an entry into a dictionary
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'actionadd' , 'alpha' ) || GETPOST ( 'actionmodify' , 'alpha' )) {
2019-11-14 12:09:15 +01:00
$listfield = explode ( ',' , str_replace ( ' ' , '' , $tabfield [ $id ]));
$listfieldinsert = explode ( ',' , $tabfieldinsert [ $id ]);
$listfieldmodify = explode ( ',' , $tabfieldinsert [ $id ]);
$listfieldvalue = explode ( ',' , $tabfieldvalue [ $id ]);
2017-10-07 13:09:31 +02:00
// Check that all fields are filled
2019-11-14 12:09:15 +01:00
$ok = 1 ;
2022-02-22 22:03:34 +01:00
2017-10-07 13:09:31 +02:00
// Other checks
2021-02-22 21:36:42 +01:00
if ( GETPOSTISSET ( " code " )) {
if ( GETPOST ( " code " ) == '0' ) {
2019-11-14 12:09:15 +01:00
$ok = 0 ;
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> transnoentities ( 'ErrorCodeCantContainZero' ), null , 'errors' );
}
}
2021-02-22 21:36:42 +01:00
if ( ! GETPOST ( 'label' , 'alpha' )) {
2018-03-06 19:56:08 +01:00
setEventMessages ( $langs -> transnoentities ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " Label " )), null , 'errors' );
2019-11-14 12:09:15 +01:00
$ok = 0 ;
2018-03-06 19:56:08 +01:00
}
2017-05-01 08:16:09 +02:00
2017-10-07 13:09:31 +02:00
// Si verif ok et action add, on ajoute la ligne
2021-02-22 21:36:42 +01:00
if ( $ok && GETPOST ( 'actionadd' , 'alpha' )) {
if ( $tabrowid [ $id ]) {
2017-10-07 13:09:31 +02:00
// Recupere id libre pour insertion
2019-11-14 12:09:15 +01:00
$newid = 0 ;
2017-10-07 13:09:31 +02:00
$sql = " SELECT max( " . $tabrowid [ $id ] . " ) newid from " . $tabname [ $id ];
$result = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( $result ) {
2017-10-07 13:09:31 +02:00
$obj = $db -> fetch_object ( $result );
2019-11-14 12:09:15 +01:00
$newid = ( $obj -> newid + 1 );
2017-10-07 13:09:31 +02:00
} else {
dol_print_error ( $db );
}
}
// Add new entry
$sql = " INSERT INTO " . $tabname [ $id ] . " ( " ;
// List of fields
2021-02-22 21:36:42 +01:00
if ( $tabrowid [ $id ] && ! in_array ( $tabrowid [ $id ], $listfieldinsert )) {
2019-11-14 12:09:15 +01:00
$sql .= $tabrowid [ $id ] . " , " ;
2021-02-22 21:36:42 +01:00
}
2019-11-14 12:09:15 +01:00
$sql .= $tabfieldinsert [ $id ];
$sql .= " ,active,entity) " ;
$sql .= " VALUES( " ;
2017-10-07 13:09:31 +02:00
// List of values
2021-02-22 21:36:42 +01:00
if ( $tabrowid [ $id ] && ! in_array ( $tabrowid [ $id ], $listfieldinsert )) {
2019-11-14 12:09:15 +01:00
$sql .= $newid . " , " ;
2021-02-22 21:36:42 +01:00
}
2019-11-14 12:09:15 +01:00
$i = 0 ;
2021-02-22 21:36:42 +01:00
foreach ( $listfieldinsert as $f => $value ) {
if ( $i ) {
$sql .= " , " ;
}
2022-02-22 22:03:34 +01:00
if ( GETPOST ( $listfieldvalue [ $i ]) == '' ) {
2021-02-22 21:36:42 +01:00
$sql .= " null " ; // For vat, we want/accept code = ''
} else {
2022-02-22 22:03:34 +01:00
$sql .= " ' " . $db -> escape ( GETPOST ( $listfieldvalue [ $i ])) . " ' " ;
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2019-11-14 12:09:15 +01:00
$sql .= " ,1, " . $conf -> entity . " ) " ;
2017-10-07 13:09:31 +02:00
dol_syslog ( " actionadd " , LOG_DEBUG );
$result = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( $result ) { // Add is ok
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> transnoentities ( " RecordSaved " ), null , 'mesgs' );
2022-02-22 22:03:34 +01:00
$_POST = array ( 'id' => $id ); // Clean $_POST array, we keep only id
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
if ( $db -> errno () == 'DB_ERROR_RECORD_ALREADY_EXISTS' ) {
setEventMessages ( $langs -> transnoentities ( " ErrorRecordAlreadyExists " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
}
}
// Si verif ok et action modify, on modifie la ligne
2021-02-22 21:36:42 +01:00
if ( $ok && GETPOST ( 'actionmodify' , 'alpha' )) {
if ( $tabrowid [ $id ]) {
$rowidcol = $tabrowid [ $id ];
} else {
$rowidcol = " rowid " ;
}
2017-10-07 13:09:31 +02:00
// Modify entry
$sql = " UPDATE " . $tabname [ $id ] . " SET " ;
// Modifie valeur des champs
2021-02-22 21:36:42 +01:00
if ( $tabrowid [ $id ] && ! in_array ( $tabrowid [ $id ], $listfieldmodify )) {
2019-11-14 12:09:15 +01:00
$sql .= $tabrowid [ $id ] . " = " ;
$sql .= " ' " . $db -> escape ( $rowid ) . " ', " ;
2017-10-07 13:09:31 +02:00
}
$i = 0 ;
2021-02-22 21:36:42 +01:00
foreach ( $listfieldmodify as $field ) {
if ( $i ) {
$sql .= " , " ;
}
2022-02-22 22:03:34 +01:00
$sql .= $field . " = " ;
$sql .= " ' " . $db -> escape ( GETPOST ( $listfieldvalue [ $i ])) . " ' " ;
2017-10-07 13:09:31 +02:00
$i ++ ;
}
2020-09-19 20:11:04 +02:00
$sql .= " WHERE " . $rowidcol . " = " . (( int ) $rowid );
2022-02-22 22:03:34 +01:00
$sql .= " AND entity = " . (( int ) $conf -> entity );
2017-10-07 13:09:31 +02:00
dol_syslog ( " actionmodify " , LOG_DEBUG );
//print $sql;
$resql = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( ! $resql ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $db -> error (), null , 'errors' );
}
}
//$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
2017-05-01 08:16:09 +02:00
}
2018-10-12 16:49:53 +02:00
//if (GETPOST('actioncancel', 'alpha'))
2018-09-09 13:42:38 +02:00
//{
// $_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
//}
2017-05-01 08:16:09 +02:00
2021-02-22 21:36:42 +01:00
if ( $action == 'confirm_delete' && $confirm == 'yes' ) { // delete
if ( $tabrowid [ $id ]) {
$rowidcol = $tabrowid [ $id ];
} else {
$rowidcol = " rowid " ;
}
2017-10-07 13:09:31 +02:00
2020-09-19 20:11:04 +02:00
$sql = " DELETE from " . $tabname [ $id ] . " WHERE " . $rowidcol . " = " . (( int ) $rowid );
2022-02-22 22:03:34 +01:00
$sql .= " AND entity = " . (( int ) $conf -> entity );
2017-10-07 13:09:31 +02:00
dol_syslog ( " delete " , LOG_DEBUG );
$result = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( ! $result ) {
if ( $db -> errno () == 'DB_ERROR_CHILD_EXISTS' ) {
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> transnoentities ( " ErrorRecordIsUsedByChild " ), null , 'errors' );
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
}
2017-05-01 08:16:09 +02:00
}
// activate
2021-02-22 21:36:42 +01:00
if ( $action == $acts [ 0 ]) {
if ( $tabrowid [ $id ]) {
$rowidcol = $tabrowid [ $id ];
} else {
$rowidcol = " rowid " ;
}
2017-10-07 13:09:31 +02:00
if ( $rowid ) {
2020-09-19 20:11:04 +02:00
$sql = " UPDATE " . $tabname [ $id ] . " SET active = 1 WHERE " . $rowidcol . " = " . (( int ) $rowid );
2020-05-21 15:05:19 +02:00
} elseif ( $code ) {
2020-09-19 20:11:04 +02:00
$sql = " UPDATE " . $tabname [ $id ] . " SET active = 1 WHERE code=' " . $db -> escape ( $code ) . " ' " ;
2017-10-07 13:09:31 +02:00
}
2019-11-14 12:09:15 +01:00
$sql .= " AND entity = " . $conf -> entity ;
2017-10-07 13:09:31 +02:00
$result = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( ! $result ) {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
2017-05-01 08:16:09 +02:00
}
// disable
2021-02-22 21:36:42 +01:00
if ( $action == $acts [ 1 ]) {
if ( $tabrowid [ $id ]) {
$rowidcol = $tabrowid [ $id ];
} else {
$rowidcol = " rowid " ;
}
2017-10-07 13:09:31 +02:00
if ( $rowid ) {
2020-09-19 20:11:04 +02:00
$sql = " UPDATE " . $tabname [ $id ] . " SET active = 0 WHERE " . $rowidcol . " = " . (( int ) $rowid );
2020-05-21 15:05:19 +02:00
} elseif ( $code ) {
2020-09-19 20:11:04 +02:00
$sql = " UPDATE " . $tabname [ $id ] . " SET active = 0 WHERE code=' " . $db -> escape ( $code ) . " ' " ;
2017-10-07 13:09:31 +02:00
}
2019-11-14 12:09:15 +01:00
$sql .= " AND entity = " . $conf -> entity ;
2017-10-07 13:09:31 +02:00
$result = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( ! $result ) {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
2017-05-01 08:16:09 +02:00
}
2017-03-28 06:35:03 +02:00
2017-10-06 11:02:44 +02:00
2017-03-28 06:35:03 +02:00
/*
* View
*/
$form = new Form ( $db );
2019-11-14 12:09:15 +01:00
$formadmin = new FormAdmin ( $db );
2017-03-28 06:35:03 +02:00
2017-05-01 08:16:09 +02:00
llxHeader ();
2017-03-28 06:35:03 +02:00
2019-11-14 12:09:15 +01:00
$titre = $langs -> trans ( " DictionarySetup " );
$linkback = '' ;
2021-02-22 21:36:42 +01:00
if ( $id ) {
2019-11-14 12:09:15 +01:00
$titre .= ' - ' . $langs -> trans ( $tablib [ $id ]);
$titlepicto = 'title_accountancy' ;
2017-03-28 06:35:03 +02:00
}
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $titre , $linkback , $titlepicto );
2017-05-01 08:16:09 +02:00
2017-03-28 06:35:03 +02:00
2017-05-01 08:16:09 +02:00
// Confirmation de la suppression de la ligne
2021-02-22 21:36:42 +01:00
if ( $action == 'delete' ) {
2019-11-14 12:09:15 +01:00
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 );
2017-03-28 06:35:03 +02:00
}
2017-05-01 08:16:09 +02:00
//var_dump($elementList);
/*
* Show a dictionary
*/
2021-02-22 21:36:42 +01:00
if ( $id ) {
2017-10-07 13:09:31 +02:00
// Complete requete recherche valeurs avec critere de tri
2019-11-14 12:09:15 +01:00
$sql = $tabsql [ $id ];
2022-02-22 22:03:34 +01:00
$sql .= " WHERE a.entity = " . (( int ) $conf -> entity );
2017-10-07 13:09:31 +02:00
2018-04-25 16:01:06 +02:00
// If sort order is "country", we use country_code instead
2021-02-22 21:36:42 +01:00
if ( $sortfield == 'country' ) {
$sortfield = 'country_code' ;
}
2019-11-14 12:09:15 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $listlimit + 1 , $offset );
2017-10-07 13:09:31 +02:00
2019-11-14 12:09:15 +01:00
$fieldlist = explode ( ',' , $tabfield [ $id ]);
2017-10-07 13:09:31 +02:00
print '<form action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $id . '" method="POST">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2019-01-27 11:55:16 +01:00
print '<input type="hidden" name="from" value="' . dol_escape_htmltag ( GETPOST ( 'from' , 'alpha' )) . '">' ;
2017-10-07 13:09:31 +02:00
print '<div class="div-table-responsive">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2017-10-07 13:09:31 +02:00
// Form to add a new line
2021-02-22 21:36:42 +01:00
if ( $tabname [ $id ]) {
2019-11-14 12:09:15 +01:00
$fieldlist = explode ( ',' , $tabfield [ $id ]);
2017-10-07 13:09:31 +02:00
// Line for title
print '<tr class="liste_titre">' ;
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
2017-10-07 13:09:31 +02:00
// Determine le nom du champ par rapport aux noms possibles
// dans les dictionnaires de donnees
2019-11-14 12:09:15 +01:00
$valuetoshow = ucfirst ( $fieldlist [ $field ]); // Par defaut
$valuetoshow = $langs -> trans ( $valuetoshow ); // try to translate
$class = " left " ;
2020-10-31 14:32:18 +01:00
if ( $fieldlist [ $field ] == 'code' ) {
$valuetoshow = $langs -> trans ( " Code " );
}
2019-11-14 12:09:15 +01:00
if ( $fieldlist [ $field ] == 'libelle' || $fieldlist [ $field ] == 'label' ) {
$valuetoshow = $langs -> trans ( " Label " );
2017-10-07 13:09:31 +02:00
}
2020-10-31 14:32:18 +01:00
if ( $fieldlist [ $field ] == 'nature' ) {
$valuetoshow = $langs -> trans ( " NatureOfJournal " );
}
2017-10-07 13:09:31 +02:00
2019-03-03 10:31:46 +01:00
if ( $valuetoshow != '' ) {
print '<td class="' . $class . '">' ;
2021-02-22 21:36:42 +01:00
if ( ! empty ( $tabhelp [ $id ][ $value ]) && preg_match ( '/^http(s*):/i' , $tabhelp [ $id ][ $value ])) {
2021-11-22 02:35:55 +01:00
print '<a href="' . $tabhelp [ $id ][ $value ] . '">' . $valuetoshow . ' ' . img_help ( 1 , $valuetoshow ) . '</a>' ;
2021-02-22 21:36:42 +01:00
} elseif ( ! empty ( $tabhelp [ $id ][ $value ])) {
print $form -> textwithpicto ( $valuetoshow , $tabhelp [ $id ][ $value ]);
} else {
print $valuetoshow ;
}
2017-10-07 13:09:31 +02:00
print '</td>' ;
2019-02-03 14:29:45 +01:00
}
2017-10-07 13:09:31 +02:00
}
print '<td>' ;
print '<input type="hidden" name="id" value="' . $id . '">' ;
print '</td>' ;
print '<td style="min-width: 26px;"></td>' ;
print '<td style="min-width: 26px;"></td>' ;
print '<td style="min-width: 26px;"></td>' ;
print '</tr>' ;
// Line to enter new values
print '<tr class="oddeven nodrag nodrap nohover">' ;
$obj = new stdClass ();
// If data was already input, we define them in obj to populate input fields.
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'actionadd' , 'alpha' )) {
foreach ( $fieldlist as $key => $val ) {
if ( GETPOST ( $val ) != '' ) {
2019-11-14 12:09:15 +01:00
$obj -> $val = GETPOST ( $val );
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
}
}
$tmpaction = 'create' ;
2019-11-14 12:09:15 +01:00
$parameters = array ( 'fieldlist' => $fieldlist , 'tabname' => $tabname [ $id ]);
$reshook = $hookmanager -> executeHooks ( 'createDictionaryFieldlist' , $parameters , $obj , $tmpaction ); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager -> error ; $errors = $hookmanager -> errors ;
2017-10-07 13:09:31 +02:00
2021-02-22 21:36:42 +01:00
if ( empty ( $reshook )) {
fieldListJournal ( $fieldlist , $obj , $tabname [ $id ], 'add' );
2017-10-07 13:09:31 +02:00
}
2019-01-30 09:24:22 +01:00
print '<td colspan="4" class="right">' ;
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button button-add" name="actionadd" value="' . $langs -> trans ( " Add " ) . '">' ;
2017-10-07 13:09:31 +02:00
print '</td>' ;
print " </tr> " ;
2019-11-14 12:09:15 +01:00
print '<tr><td colspan="7"> </td></tr>' ; // Keep to have a line with enough height
2017-10-07 13:09:31 +02:00
}
// List of available record in database
dol_syslog ( " htdocs/admin/dict " , LOG_DEBUG );
2019-11-14 12:09:15 +01:00
$resql = $db -> query ( $sql );
2021-02-22 21:36:42 +01:00
if ( $resql ) {
2017-10-07 13:09:31 +02:00
$num = $db -> num_rows ( $resql );
$i = 0 ;
2022-02-22 22:03:34 +01:00
$param = '&id=' . (( int ) $id );
2021-02-22 21:36:42 +01:00
if ( $search_country_id > 0 ) {
2021-08-27 23:36:06 +02:00
$param .= '&search_country_id=' . urlencode ( $search_country_id );
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
$paramwithsearch = $param ;
2021-02-22 21:36:42 +01:00
if ( $sortorder ) {
$paramwithsearch .= '&sortorder=' . $sortorder ;
}
if ( $sortfield ) {
$paramwithsearch .= '&sortfield=' . $sortfield ;
}
if ( GETPOST ( 'from' , 'alpha' )) {
$paramwithsearch .= '&from=' . GETPOST ( 'from' , 'alpha' );
}
2017-10-07 13:09:31 +02:00
// There is several pages
2021-02-22 21:36:42 +01:00
if ( $num > $listlimit ) {
2019-11-14 12:09:15 +01:00
print '<tr class="none"><td class="right" colspan="' . ( 3 + count ( $fieldlist )) . '">' ;
print_fleche_navigation ( $page , $_SERVER [ " PHP_SELF " ], $paramwithsearch , ( $num > $listlimit ), '<li class="pagination"><span>' . $langs -> trans ( " Page " ) . ' ' . ( $page + 1 ) . '</span></li>' );
2017-10-07 13:09:31 +02:00
print '</td></tr>' ;
}
// Title line with search boxes
2019-07-15 22:59:18 +02:00
/* print '<tr class="liste_titre_filter liste_titre_add">' ;
2017-10-07 13:09:31 +02:00
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
print '<td class="liste_titre"></td>' ;
2019-03-19 13:44:21 +01:00
print '<td class="liste_titre center">' ;
2019-07-15 22:59:18 +02:00
$searchpicto = $form -> showFilterButtons ();
print $searchpicto ;
2017-10-07 13:09:31 +02:00
print '</td>' ;
print '</tr>' ;
2019-07-15 22:59:18 +02:00
*/
2019-09-23 21:55:30 +02:00
2017-10-07 13:09:31 +02:00
// Title of lines
2019-07-15 22:59:18 +02:00
print '<tr class="liste_titre liste_titre_add">' ;
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
2017-10-07 13:09:31 +02:00
// Determine le nom du champ par rapport aux noms possibles
// dans les dictionnaires de donnees
2019-11-14 12:09:15 +01:00
$showfield = 1 ; // By defaut
$class = " left " ;
$sortable = 1 ;
$valuetoshow = '' ;
2017-10-07 13:09:31 +02:00
/*
2021-02-22 21:36:42 +01:00
$tmparray = getLabelOfField ( $fieldlist [ $field ]);
$showfield = $tmp [ 'showfield' ];
$valuetoshow = $tmp [ 'valuetoshow' ];
$align = $tmp [ 'align' ];
$sortable = $tmp [ 'sortable' ];
2017-05-01 08:16:09 +02:00
*/
2019-11-14 12:09:15 +01:00
$valuetoshow = ucfirst ( $fieldlist [ $field ]); // By defaut
$valuetoshow = $langs -> trans ( $valuetoshow ); // try to translate
if ( $fieldlist [ $field ] == 'code' ) {
2020-10-31 14:32:18 +01:00
$valuetoshow = $langs -> trans ( " Code " );
}
2019-11-14 12:09:15 +01:00
if ( $fieldlist [ $field ] == 'libelle' || $fieldlist [ $field ] == 'label' ) {
2020-10-31 14:32:18 +01:00
$valuetoshow = $langs -> trans ( " Label " );
}
2019-11-14 12:09:15 +01:00
if ( $fieldlist [ $field ] == 'nature' ) {
2020-10-31 14:32:18 +01:00
$valuetoshow = $langs -> trans ( " NatureOfJournal " );
}
2017-10-07 13:09:31 +02:00
// Affiche nom du champ
2019-03-03 10:31:46 +01:00
if ( $showfield ) {
2019-11-14 12:09:15 +01:00
print getTitleFieldOfList ( $valuetoshow , 0 , $_SERVER [ " PHP_SELF " ], ( $sortable ? $fieldlist [ $field ] : '' ), ( $page ? 'page=' . $page . '&' : '' ), $param , " " , $sortfield , $sortorder , $class . ' ' );
2017-10-07 13:09:31 +02:00
}
}
2019-11-14 12:09:15 +01:00
print getTitleFieldOfList ( $langs -> trans ( " Status " ), 0 , $_SERVER [ " PHP_SELF " ], " active " , ( $page ? 'page=' . $page . '&' : '' ), $param , '' , $sortfield , $sortorder , 'center ' );
2017-10-07 13:09:31 +02:00
print getTitleFieldOfList ( '' );
print getTitleFieldOfList ( '' );
print getTitleFieldOfList ( '' );
print '</tr>' ;
2021-02-22 21:36:42 +01:00
if ( $num ) {
2017-10-07 13:09:31 +02:00
// Lines with values
2021-02-22 21:36:42 +01:00
while ( $i < $num ) {
2017-10-07 13:09:31 +02:00
$obj = $db -> fetch_object ( $resql );
//print_r($obj);
print '<tr class="oddeven" id="rowid-' . $obj -> rowid . '">' ;
2021-02-22 21:36:42 +01:00
if ( $action == 'edit' && ( $rowid == ( ! empty ( $obj -> rowid ) ? $obj -> rowid : $obj -> code ))) {
2019-11-14 12:09:15 +01:00
$tmpaction = 'edit' ;
$parameters = array ( 'fieldlist' => $fieldlist , 'tabname' => $tabname [ $id ]);
$reshook = $hookmanager -> executeHooks ( 'editDictionaryFieldlist' , $parameters , $obj , $tmpaction ); // Note that $action and $object may have been modified by some hooks
$error = $hookmanager -> error ; $errors = $hookmanager -> errors ;
2017-10-07 13:09:31 +02:00
// Show fields
2021-02-22 21:36:42 +01:00
if ( empty ( $reshook )) {
fieldListJournal ( $fieldlist , $obj , $tabname [ $id ], 'edit' );
}
2017-10-07 13:09:31 +02:00
2019-03-19 13:44:21 +01:00
print '<td class="center" colspan="4">' ;
2017-10-07 13:09:31 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="rowid" value="' . $rowid . '">' ;
2021-08-24 17:04:17 +02:00
print '<input type="submit" class="button button-edit" name="actionmodify" value="' . $langs -> trans ( " Modify " ) . '">' ;
2020-11-23 15:12:52 +01:00
print '<input type="submit" class="button button-cancel" name="actioncancel" value="' . $langs -> trans ( " Cancel " ) . '">' ;
2019-11-14 12:09:15 +01:00
print '<div name="' . ( ! empty ( $obj -> rowid ) ? $obj -> rowid : $obj -> code ) . '"></div>' ;
2017-10-07 13:09:31 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-22 21:36:42 +01:00
$tmpaction = 'view' ;
2021-10-23 21:39:07 +02:00
$parameters = array ( 'fieldlist' => $fieldlist , 'tabname' => $tabname [ $id ]);
2019-11-14 12:09:15 +01:00
$reshook = $hookmanager -> executeHooks ( 'viewDictionaryFieldlist' , $parameters , $obj , $tmpaction ); // Note that $action and $object may have been modified by some hooks
2017-10-07 13:09:31 +02:00
2019-11-14 12:09:15 +01:00
$error = $hookmanager -> error ; $errors = $hookmanager -> errors ;
2017-10-07 13:09:31 +02:00
2021-02-22 21:36:42 +01:00
if ( empty ( $reshook )) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " accountancy " );
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
2019-11-14 12:09:15 +01:00
$showfield = 1 ;
$class = " left " ;
$valuetoshow = $obj -> { $fieldlist [ $field ]};
if ( $valuetoshow == 'all' ) {
$valuetoshow = $langs -> trans ( 'All' );
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'nature' && $tabname [ $id ] == MAIN_DB_PREFIX . 'accounting_journal' ) {
2019-11-14 12:09:15 +01:00
$key = $langs -> trans ( " AccountingJournalType " . strtoupper ( $obj -> nature ));
$valuetoshow = ( $obj -> nature && $key != " AccountingJournalType " . strtoupper ( $langs -> trans ( $obj -> nature )) ? $key : $obj -> { $fieldlist [ $field ]});
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'label' && $tabname [ $id ] == MAIN_DB_PREFIX . 'accounting_journal' ) {
2019-11-14 12:09:15 +01:00
$valuetoshow = $langs -> trans ( $obj -> label );
2020-10-31 14:32:18 +01:00
}
2017-10-07 13:09:31 +02:00
2019-11-14 12:09:15 +01:00
$class = 'tddict' ;
2017-05-01 08:16:09 +02:00
// Show value for field
2021-02-22 21:36:42 +01:00
if ( $showfield ) {
2022-02-22 22:03:34 +01:00
print '<!-- ' . $fieldlist [ $field ] . ' --><td class="' . $class . '">' . dol_escape_htmltag ( $valuetoshow ) . '</td>' ;
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
}
}
// Can an entry be erased or disabled ?
2019-11-14 12:09:15 +01:00
$iserasable = 1 ; $canbedisabled = 1 ; $canbemodified = 1 ; // true by default
2019-01-27 23:23:38 +01:00
if ( isset ( $obj -> code ) && $id != 10 ) {
if (( $obj -> code == '0' || $obj -> code == '' || preg_match ( '/unknown/i' , $obj -> code ))) {
2020-10-31 14:32:18 +01:00
$iserasable = 0 ;
$canbedisabled = 0 ;
} elseif ( $obj -> code == 'RECEP' ) {
$iserasable = 0 ;
$canbedisabled = 0 ;
} elseif ( $obj -> code == 'EF0' ) {
$iserasable = 0 ;
$canbedisabled = 0 ;
}
2017-10-07 13:09:31 +02:00
}
2019-11-14 12:09:15 +01:00
$canbemodified = $iserasable ;
2017-10-07 13:09:31 +02:00
2019-11-14 12:09:15 +01:00
$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 ) : '' );
2021-02-22 21:36:42 +01:00
if ( $param ) {
$url .= '&' . $param ;
}
2019-11-14 12:09:15 +01:00
$url .= '&' ;
2017-10-07 13:09:31 +02:00
// Active
2019-03-19 13:44:21 +01:00
print '<td class="nowrap center">' ;
2021-02-22 21:36:42 +01:00
if ( $canbedisabled ) {
print '<a href="' . $url . 'action=' . $acts [ $obj -> active ] . '&token=' . newToken () . '">' . $actl [ $obj -> active ] . '</a>' ;
} else {
print $langs -> trans ( " AlwaysActive " );
}
2017-10-07 13:09:31 +02:00
print " </td> " ;
// Modify link
2021-02-22 21:36:42 +01:00
if ( $canbemodified ) {
print '<td class="center"><a class="reposition editfielda" href="' . $url . 'action=edit&token=' . newToken () . '">' . img_edit () . '</a></td>' ;
} else {
print '<td> </td>' ;
}
2017-10-07 13:09:31 +02:00
// Delete link
2021-02-22 21:36:42 +01:00
if ( $iserasable ) {
2019-03-19 13:44:21 +01:00
print '<td class="center">' ;
2021-02-22 21:36:42 +01:00
if ( $user -> admin ) {
print '<a href="' . $url . 'action=delete&token=' . newToken () . '">' . img_delete () . '</a>' ;
}
2017-10-07 13:09:31 +02:00
//else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
print '</td>' ;
2021-02-22 21:36:42 +01:00
} else {
print '<td> </td>' ;
}
2017-10-07 13:09:31 +02:00
print '<td></td>' ;
print '</td>' ;
}
print " </tr> \n " ;
$i ++ ;
}
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
dol_print_error ( $db );
}
print '</table>' ;
2017-09-05 20:42:34 +02:00
print '</div>' ;
2017-05-01 08:16:09 +02:00
2017-10-07 13:09:31 +02:00
print '</form>' ;
2017-03-28 06:35:03 +02:00
}
2017-05-01 08:16:09 +02:00
print '<br>' ;
2018-07-28 14:02:33 +02:00
// End of page
2017-03-28 06:35:03 +02:00
llxFooter ();
2017-05-01 08:16:09 +02:00
$db -> close ();
/**
* Show fields in insert / edit mode
*
2019-03-03 10:31:46 +01:00
* @ param array $fieldlist Array of fields
* @ param Object $obj If we show a particular record , obj is filled with record fields
* @ param string $tabname Name of SQL table
* @ 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
* @ return void
2017-05-01 08:16:09 +02:00
*/
2019-01-27 15:20:16 +01:00
function fieldListJournal ( $fieldlist , $obj = '' , $tabname = '' , $context = '' )
2017-05-01 08:16:09 +02:00
{
2019-11-14 12:09:15 +01:00
global $conf , $langs , $db ;
2017-05-01 08:16:09 +02:00
global $form , $mysoc ;
global $region_id ;
2019-11-14 12:09:15 +01:00
global $elementList , $sourceList , $localtax_typeList ;
2017-05-01 08:16:09 +02:00
global $bc ;
$formadmin = new FormAdmin ( $db );
$formcompany = new FormCompany ( $db );
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
if ( $fieldlist [ $field ] == 'nature' ) {
2017-05-01 08:16:09 +02:00
print '<td>' ;
2019-11-14 12:09:15 +01:00
print $form -> selectarray ( 'nature' , $sourceList , ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ));
2017-05-01 08:16:09 +02:00
print '</td>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'code' && isset ( $obj -> { $fieldlist [ $field ]})) {
2019-11-14 12:09:15 +01:00
print '<td><input type="text" class="flat minwidth100" value="' . ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ) . '" name="' . $fieldlist [ $field ] . '"></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-05-01 08:16:09 +02:00
print '<td>' ;
2019-11-14 12:09:15 +01:00
$size = '' ; $class = '' ;
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'code' ) {
$class = 'maxwidth100' ;
}
if ( $fieldlist [ $field ] == 'label' ) {
$class = 'quatrevingtpercent' ;
}
if ( $fieldlist [ $field ] == 'sortorder' || $fieldlist [ $field ] == 'sens' || $fieldlist [ $field ] == 'category_type' ) {
$size = 'size="2" ' ;
}
2019-11-14 12:09:15 +01:00
print '<input type="text" ' . $size . 'class="flat' . ( $class ? ' ' . $class : '' ) . '" value="' . ( isset ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ) . '" name="' . $fieldlist [ $field ] . '">' ;
2017-05-01 08:16:09 +02:00
print '</td>' ;
}
}
2017-07-07 20:05:32 +02:00
}