2016-10-15 14:38:43 +02:00
< ? php
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2019-06-20 13:37:06 +02:00
* Copyright ( C ) 2004 - 2019 Laurent Destailleur < eldy @ users . sourceforge . net >
2016-10-15 14:38:43 +02:00
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2016-10-15 14:38:43 +02:00
* Copyright ( C ) 2010 - 2016 Juanjo Menent < jmenent @ 2 byte . es >
2019-06-23 15:39:25 +02:00
* Copyright ( C ) 2011 - 2019 Philippe Grand < philippe . grand @ atoo - net . com >
2016-10-15 14:38:43 +02:00
* Copyright ( C ) 2011 Remy Younes < ryounes @ gmail . com >
* Copyright ( C ) 2012 - 2015 Marcos García < marcosgdf @ gmail . com >
* Copyright ( C ) 2012 Christophe Battarel < christophe . battarel @ ltairis . fr >
2019-01-28 21:39:22 +01:00
* Copyright ( C ) 2011 - 2016 Alexandre Spangaro < aspangaro @ open - dsi . fr >
2016-10-15 14:38:43 +02:00
* Copyright ( C ) 2015 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2016 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
*
* 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 />.
2016-10-15 14:38:43 +02:00
*/
/**
* \file htdocs / accountancy / admin / accountmodel . php
2019-05-13 22:25:15 +02:00
* \ingroup Accountancy ( Double entries )
2016-10-15 14:38:43 +02:00
* \brief Page to administer model of chart of accounts
*/
require '../../main.inc.php' ;
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' ;
2022-08-24 10:26:04 +02:00
if ( isModEnabled ( 'accounting' )) {
2021-02-22 21:36:42 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php' ;
}
2016-10-15 14:38:43 +02:00
2018-05-26 23:52:52 +02:00
// Load translation files required by the page
2020-02-18 23:47:25 +01:00
$langs -> loadLangs ( array ( " errors " , " admin " , " companies " , " resource " , " holiday " , " compta " , " accountancy " , " hrm " ));
2016-10-15 14:38:43 +02:00
2020-02-18 23:47:25 +01:00
$action = GETPOST ( 'action' , 'aZ09' ) ? GETPOST ( 'action' , 'aZ09' ) : 'view' ;
$confirm = GETPOST ( 'confirm' , 'alpha' );
$id = 31 ;
$rowid = GETPOST ( 'rowid' , 'alpha' );
$code = GETPOST ( 'code' , 'alpha' );
2016-10-15 14:38:43 +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"' );
2016-10-15 14:38:43 +02:00
2020-02-18 23:47:25 +01:00
$listoffset = GETPOST ( 'listoffset' , 'alpha' );
$listlimit = GETPOST ( 'listlimit' , 'int' ) > 0 ? GETPOST ( 'listlimit' , 'int' ) : 1000 ;
2016-10-15 14:38:43 +02:00
$active = 1 ;
2019-01-27 11:55:16 +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
2020-02-18 23:47:25 +01:00
$offset = $listlimit * $page ;
2016-10-15 14:38:43 +02:00
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2019-01-27 11:55:16 +01:00
$search_country_id = GETPOST ( 'search_country_id' , 'int' );
2016-10-15 14:38:43 +02:00
// Security check
2021-02-22 21:36:42 +01:00
if ( $user -> socid > 0 ) {
accessforbidden ();
}
2021-10-22 22:07:47 +02:00
if ( empty ( $user -> rights -> accounting -> chartofaccount )) {
2021-02-22 21:36:42 +01:00
accessforbidden ();
}
2016-10-15 14:38:43 +02:00
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
2016-10-15 14:38:43 +02:00
$hookmanager -> initHooks ( array ( 'admin' ));
// This page is a generic page to edit dictionaries
// Put here declaration of dictionaries properties
// Name of SQL tables of dictionaries
2020-02-18 23:47:25 +01:00
$tabname = array ();
2016-10-15 14:38:43 +02:00
2020-02-18 23:47:25 +01:00
$tabname [ 31 ] = MAIN_DB_PREFIX . " accounting_system " ;
2016-10-15 14:38:43 +02:00
// Dictionary labels
2020-02-18 23:47:25 +01:00
$tablib = array ();
$tablib [ 31 ] = " Pcg_version " ;
2016-10-15 14:38:43 +02:00
// Requests to extract data
2020-02-18 23:47:25 +01:00
$tabsql = array ();
$tabsql [ 31 ] = " SELECT s.rowid as rowid, pcg_version, s.label, s.fk_country as country_id, c.code as country_code, c.label as country, s.active FROM " . MAIN_DB_PREFIX . " accounting_system as s, " . MAIN_DB_PREFIX . " c_country as c WHERE s.fk_country=c.rowid and c.active=1 " ;
2016-10-15 14:38:43 +02:00
// Criteria to sort dictionaries
2020-02-18 23:47:25 +01:00
$tabsqlsort = array ();
$tabsqlsort [ 31 ] = " pcg_version ASC " ;
2016-10-15 14:38:43 +02:00
// Nom des champs en resultat de select pour affichage du dictionnaire
2020-02-18 23:47:25 +01:00
$tabfield = array ();
$tabfield [ 31 ] = " pcg_version,label,country_id,country " ;
2016-10-15 14:38:43 +02:00
// Nom des champs d'edition pour modification d'un enregistrement
2020-02-18 23:47:25 +01:00
$tabfieldvalue = array ();
$tabfieldvalue [ 31 ] = " pcg_version,label,country " ;
2016-10-15 14:38:43 +02:00
// Nom des champs dans la table pour insertion d'un enregistrement
2020-02-18 23:47:25 +01:00
$tabfieldinsert = array ();
$tabfieldinsert [ 31 ] = " pcg_version,label,fk_country " ;
2016-10-15 14:38:43 +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
2020-02-18 23:47:25 +01:00
$tabrowid = array ();
$tabrowid [ 31 ] = " " ;
2016-10-15 14:38:43 +02:00
// Condition to show dictionary in setup page
2020-02-18 23:47:25 +01:00
$tabcond = array ();
2022-08-24 10:26:04 +02:00
$tabcond [ 31 ] = isModEnabled ( 'accounting' );
2016-10-15 14:38:43 +02:00
// List of help for fields
2020-02-18 23:47:25 +01:00
$tabhelp = array ();
2016-10-15 14:38:43 +02:00
$tabhelp [ 31 ] = array ( 'pcg_version' => $langs -> trans ( " EnterAnyCode " ));
// List of check for fields (NOT USED YET)
2020-02-18 23:47:25 +01:00
$tabfieldcheck = array ();
2016-10-15 14:38:43 +02:00
$tabfieldcheck [ 31 ] = array ();
// Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
$elementList = array ();
2020-02-18 23:47:25 +01:00
$sourceList = array ();
2016-10-15 14:38:43 +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 = '' ;
2016-10-15 14:38:43 +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' )) {
2020-02-18 23:47:25 +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
2020-02-18 23:47:25 +01:00
$ok = 1 ;
2021-02-22 21:36:42 +01:00
foreach ( $listfield as $f => $value ) {
if ( $value == 'country_id' && in_array ( $tablib [ $id ], array ( 'Pcg_version' ))) {
continue ; // For some pages, country is not mandatory
}
if (( ! GETPOSTISSET ( $value )) || GETPOST ( $value ) == '' ) {
2020-02-18 23:47:25 +01:00
$ok = 0 ;
$fieldnamekey = $listfield [ $f ];
2017-10-07 13:09:31 +02:00
// We take translate key of field
2017-10-23 20:01:38 +02:00
2021-02-22 21:36:42 +01:00
if ( $fieldnamekey == 'pcg_version' ) {
$fieldnamekey = 'Pcg_version' ;
}
if ( $fieldnamekey == 'libelle' || ( $fieldnamekey == 'label' )) {
$fieldnamekey = 'Label' ;
}
2016-10-15 14:38:43 +02:00
2017-10-07 13:09:31 +02:00
setEventMessages ( $langs -> transnoentities ( " ErrorFieldRequired " , $langs -> transnoentities ( $fieldnamekey )), null , 'errors' );
}
}
// Other checks
2021-02-22 21:36:42 +01:00
if ( GETPOSTISSET ( " pcg_version " )) {
if ( GETPOST ( " pcg_version " ) == '0' ) {
2020-02-18 23:47:25 +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 ( GETPOSTISSET ( " country " ) && ( GETPOST ( " country " ) == '0' ) && ( $id != 2 )) {
2020-02-18 23:47:25 +01:00
$ok = 0 ;
2019-08-10 02:09:59 +02:00
setEventMessages ( $langs -> transnoentities ( " ErrorFieldRequired " , $langs -> transnoentities ( " Country " )), null , 'errors' );
2017-10-07 13:09:31 +02:00
}
2016-10-15 14:38:43 +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
2020-02-18 23:47:25 +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 );
2020-02-18 23:47:25 +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 )) {
2020-02-18 23:47:25 +01:00
$sql .= $tabrowid [ $id ] . " , " ;
2021-02-22 21:36:42 +01:00
}
2020-02-18 23:47:25 +01:00
$sql .= $tabfieldinsert [ $id ];
$sql .= " ,active) " ;
$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 )) {
2020-02-18 23:47:25 +01:00
$sql .= $newid . " , " ;
2021-02-22 21:36:42 +01:00
}
2020-02-18 23:47:25 +01:00
$i = 0 ;
2021-02-22 21:36:42 +01:00
foreach ( $listfieldinsert as $f => $value ) {
2019-01-27 11:55:16 +01:00
if ( $value == 'price' || preg_match ( '/^amount/i' , $value ) || $value == 'taux' ) {
2022-02-22 22:27:09 +01:00
$_POST [ $listfieldvalue [ $i ]] = price2num ( GETPOST ( $listfieldvalue [ $i ]), 'MU' );
2020-05-21 15:05:19 +02:00
} elseif ( $value == 'entity' ) {
2017-10-07 13:09:31 +02:00
$_POST [ $listfieldvalue [ $i ]] = $conf -> entity ;
}
2021-02-22 21:36:42 +01:00
if ( $i ) {
$sql .= " , " ;
}
2022-02-22 23:44:56 +01:00
if ( GETPOST ( $listfieldvalue [ $i ]) == '' ) {
2021-02-22 21:36:42 +01:00
$sql .= " null " ;
} else {
2022-02-22 22:27:09 +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 ++ ;
}
2020-02-18 23:47:25 +01:00
$sql .= " ,1) " ;
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' );
2020-02-18 23:47:25 +01:00
$_POST = array ( 'id' => $id ); // Clean $_POST array, we keep only
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 )) {
2020-02-18 23:47:25 +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 ) {
2019-01-27 11:55:16 +01:00
if ( $field == 'price' || preg_match ( '/^amount/i' , $field ) || $field == 'taux' ) {
2022-02-22 22:27:09 +01:00
$_POST [ $listfieldvalue [ $i ]] = price2num ( GETPOST ( $listfieldvalue [ $i ]), 'MU' );
2020-05-21 15:05:19 +02:00
} elseif ( $field == 'entity' ) {
2017-10-07 13:09:31 +02:00
$_POST [ $listfieldvalue [ $i ]] = $conf -> entity ;
}
2021-02-22 21:36:42 +01:00
if ( $i ) {
$sql .= " , " ;
}
2020-02-18 23:47:25 +01:00
$sql .= $field . " = " ;
2022-02-22 23:44:56 +01:00
if ( GETPOST ( $listfieldvalue [ $i ]) == '' ) {
2021-02-22 21:36:42 +01:00
$sql .= " null " ;
} else {
2022-02-22 22:27:09 +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 ++ ;
}
2020-09-19 20:11:04 +02:00
$sql .= " WHERE " . $rowidcol . " = " . (( int ) $rowid );
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
2016-10-15 14:38:43 +02:00
}
2021-02-22 21:36:42 +01:00
if ( GETPOST ( 'actioncancel' , 'alpha' )) {
2017-10-07 13:09:31 +02:00
//$_GET["id"]=GETPOST('id', 'int'); // Force affichage dictionnaire en cours d'edition
2016-10-15 14:38:43 +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 );
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 );
}
}
2016-10-15 14:38:43 +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
}
$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 );
}
2016-10-15 14:38:43 +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
}
$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 );
}
2016-10-15 14:38:43 +02:00
}
// favorite
2021-02-22 21:36:42 +01:00
if ( $action == 'activate_favorite' ) {
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 favorite = 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 favorite = 1 WHERE code=' " . $db -> escape ( $code ) . " ' " ;
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 );
}
2016-10-15 14:38:43 +02:00
}
// disable favorite
2021-02-22 21:36:42 +01:00
if ( $action == 'disable_favorite' ) {
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 favorite = 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 favorite = 0 WHERE code=' " . $db -> escape ( $code ) . " ' " ;
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 );
}
2016-10-15 14:38:43 +02:00
}
/*
* View
*/
$form = new Form ( $db );
2020-02-18 23:47:25 +01:00
$formadmin = new FormAdmin ( $db );
2016-10-15 14:38:43 +02:00
llxHeader ();
2020-02-18 23:47:25 +01:00
$titre = $langs -> trans ( $tablib [ $id ]);
$linkback = '' ;
2016-10-15 14:38:43 +02:00
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $titre , $linkback , 'title_accountancy' );
2016-10-15 14:38:43 +02:00
// Confirmation de la suppression de la ligne
2021-02-22 21:36:42 +01:00
if ( $action == 'delete' ) {
2020-02-18 23:47:25 +01:00
print $form -> formconfirm ( $_SERVER [ " PHP_SELF " ] . '?' . ( $page ? 'page=' . urlencode ( $page ) . '&' : '' ) . 'sortfield=' . urlencode ( $sortfield ) . '&sortorder=' . urlencode ( $sortorder ) . '&rowid=' . urlencode ( $rowid ) . '&code=' . urlencode ( $code ) . '&id=' . urlencode ( $id ), $langs -> trans ( 'DeleteLine' ), $langs -> trans ( 'ConfirmDeleteLine' ), 'confirm_delete' , '' , 0 , 1 );
2016-10-15 14:38:43 +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
2020-02-18 23:47:25 +01:00
$sql = $tabsql [ $id ];
2017-10-07 13:09:31 +02:00
2021-02-22 21:36:42 +01:00
if ( $search_country_id > 0 ) {
if ( preg_match ( '/ WHERE /' , $sql )) {
$sql .= " AND " ;
} else {
$sql .= " WHERE " ;
}
2021-04-24 20:18:11 +02:00
$sql .= " c.rowid = " . (( int ) $search_country_id );
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' ;
}
2020-02-18 23:47:25 +01:00
$sql .= $db -> order ( $sortfield , $sortorder );
$sql .= $db -> plimit ( $listlimit + 1 , $offset );
2017-10-07 13:09:31 +02:00
//print $sql;
2020-02-18 23:47:25 +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 () . '">' ;
2017-06-18 21:13:48 +02:00
2017-09-05 20:42:34 +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 ]) {
2020-02-18 23:47:25 +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
2020-02-18 23:47:25 +01:00
$valuetoshow = ucfirst ( $fieldlist [ $field ]); // Par defaut
$valuetoshow = $langs -> trans ( $valuetoshow ); // try to translate
$class = " left " ;
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'code' ) {
$valuetoshow = $langs -> trans ( " Code " );
}
if ( $fieldlist [ $field ] == 'libelle' || $fieldlist [ $field ] == 'label' ) {
2020-02-18 23:47:25 +01:00
$valuetoshow = $langs -> trans ( " Label " );
2017-10-07 13:09:31 +02:00
}
2020-02-18 23:47:25 +01:00
if ( $fieldlist [ $field ] == 'country' ) {
2021-02-22 21:36:42 +01:00
if ( in_array ( 'region_id' , $fieldlist )) {
print '<td> </td>' ; continue ;
} // For region page, we do not show the country input
2020-02-18 23:47:25 +01:00
$valuetoshow = $langs -> trans ( " Country " );
2017-10-07 13:09:31 +02:00
}
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'country_id' ) {
$valuetoshow = '' ;
}
if ( $fieldlist [ $field ] == 'pcg_version' || $fieldlist [ $field ] == 'fk_pcg_version' ) {
$valuetoshow = $langs -> trans ( " Pcg_version " );
}
2017-10-07 13:09:31 +02:00
2019-01-27 23:23:38 +01:00
if ( $valuetoshow != '' ) {
2019-03-03 10:31:46 +01:00
print '<td class="' . $class . '">' ;
2020-10-31 14:32:18 +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>' ;
2020-10-31 14:32:18 +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 '</tr>' ;
// Line to enter new values
2019-12-19 11:32:10 +01:00
print '<tr class="oddeven">' ;
2017-10-07 13:09:31 +02:00
$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 )) {
2020-02-18 23:47:25 +01:00
$obj -> $val = GETPOST ( $val );
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
}
}
$tmpaction = 'create' ;
2020-02-18 23:47:25 +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 )) {
2019-01-27 11:55:16 +01:00
fieldListAccountModel ( $fieldlist , $obj , $tabname [ $id ], 'add' );
2017-10-07 13:09:31 +02:00
}
2019-01-30 08:42:31 +01:00
print '<td colspan="3" 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> " ;
2020-02-18 23:47:25 +01:00
$colspan = count ( $fieldlist ) + 3 ;
2017-10-07 13:09:31 +02:00
2020-02-18 23:47:25 +01:00
print '<tr><td colspan="' . $colspan . '"> </td></tr>' ; // Keep to have a line with enough height
2017-10-07 13:09:31 +02:00
}
// List of available values in database
dol_syslog ( " htdocs/admin/dict " , LOG_DEBUG );
2020-02-18 23:47:25 +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 ;
2021-08-27 23:36:06 +02:00
$param = '&id=' . urlencode ( $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 ) {
2021-08-27 23:36:06 +02:00
$paramwithsearch .= '&sortorder=' . urlencode ( $sortorder );
2021-02-22 21:36:42 +01:00
}
if ( $sortfield ) {
2021-08-27 23:36:06 +02:00
$paramwithsearch .= '&sortfield=' . urlencode ( $sortfield );
2021-02-22 21:36:42 +01:00
}
2017-10-07 13:09:31 +02:00
// There is several pages
2021-02-22 21:36:42 +01:00
if ( $num > $listlimit ) {
2020-02-18 23:47:25 +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
print '<tr class="liste_titre liste_titre_add">' ;
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
2020-02-18 23:47:25 +01:00
$showfield = 1 ; // By defaut
2017-10-07 13:09:31 +02:00
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'region_id' || $fieldlist [ $field ] == 'country_id' ) {
$showfield = 0 ;
}
2017-10-07 13:09:31 +02:00
2021-02-22 21:36:42 +01:00
if ( $showfield ) {
if ( $value == 'country' ) {
2017-10-07 13:09:31 +02:00
print '<td class="liste_titre">' ;
print $form -> select_country ( $search_country_id , 'search_country_id' , '' , 28 , 'maxwidth200 maxwidthonsmartphone' );
print '</td>' ;
2020-05-21 15:05:19 +02:00
} else {
2017-10-07 13:09:31 +02:00
print '<td class="liste_titre"></td>' ;
}
}
}
print '<td class="liste_titre"></td>' ;
2019-01-30 08:42:31 +01:00
print '<td class="liste_titre right" colspan="2">' ;
2020-02-18 23:47:25 +01:00
$searchpicto = $form -> showFilterAndCheckAddButtons ( 0 );
2017-10-07 13:09:31 +02:00
print $searchpicto ;
print '</td>' ;
print '</tr>' ;
// Title of lines
print '<tr class="liste_titre">' ;
2020-02-18 23:47:25 +01:00
print getTitleFieldOfList ( $langs -> trans ( " Pcg_version " ), 0 , $_SERVER [ " PHP_SELF " ], " pcg_version " , ( $page ? 'page=' . $page . '&' : '' ), $param , '' , $sortfield , $sortorder , '' );
print getTitleFieldOfList ( $langs -> trans ( " Label " ), 0 , $_SERVER [ " PHP_SELF " ], " label " , ( $page ? 'page=' . $page . '&' : '' ), $param , '' , $sortfield , $sortorder , '' );
print getTitleFieldOfList ( $langs -> trans ( " Country " ), 0 , $_SERVER [ " PHP_SELF " ], " country_code " , ( $page ? 'page=' . $page . '&' : '' ), $param , '' , $sortfield , $sortorder , '' );
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 '</tr>' ;
2021-02-22 21:36:42 +01:00
if ( $num ) {
2021-05-25 15:38:12 +02:00
$i = 0 ;
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);
2021-05-25 15:38:12 +02:00
2017-10-07 13:09:31 +02:00
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 ))) {
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 () . '">' ;
2017-10-07 13:09:31 +02:00
print '<input type="hidden" name="page" value="' . $page . '">' ;
print '<input type="hidden" name="rowid" value="' . $rowid . '">' ;
2020-02-18 23:47:25 +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
2021-02-22 21:36:42 +01:00
if ( empty ( $reshook )) {
fieldListAccountModel ( $fieldlist , $obj , $tabname [ $id ], 'edit' );
}
2017-10-07 13:09:31 +02:00
2021-08-24 17:04:17 +02:00
print '<td colspan="3" class="right"><a name="' . ( ! empty ( $obj -> rowid ) ? $obj -> rowid : $obj -> code ) . '"> </a><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 " ) . '"></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2021-02-22 21:36:42 +01:00
$tmpaction = 'view' ;
2021-01-23 17:32:14 +01:00
$parameters = array ( 'fieldlist' => $fieldlist , 'tabname' => $tabname [ $id ]);
2020-02-18 23:47:25 +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
2020-02-18 23:47:25 +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 )) {
foreach ( $fieldlist as $field => $value ) {
2020-02-18 23:47:25 +01:00
$showfield = 1 ;
$class = " left " ;
$valuetoshow = $obj -> { $fieldlist [ $field ]};
2021-02-22 21:36:42 +01:00
if ( $value == 'type_template' ) {
2020-02-18 23:47:25 +01:00
$valuetoshow = isset ( $elementList [ $valuetoshow ]) ? $elementList [ $valuetoshow ] : $valuetoshow ;
2017-10-07 13:09:31 +02:00
}
2021-02-22 21:36:42 +01:00
if ( $value == 'element' ) {
2020-02-18 23:47:25 +01:00
$valuetoshow = isset ( $elementList [ $valuetoshow ]) ? $elementList [ $valuetoshow ] : $valuetoshow ;
2021-02-22 21:36:42 +01:00
} elseif ( $value == 'source' ) {
2020-02-18 23:47:25 +01:00
$valuetoshow = isset ( $sourceList [ $valuetoshow ]) ? $sourceList [ $valuetoshow ] : $valuetoshow ;
2020-05-21 15:05:19 +02:00
} elseif ( $valuetoshow == 'all' ) {
2020-02-18 23:47:25 +01:00
$valuetoshow = $langs -> trans ( 'All' );
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'country' ) {
2021-02-22 21:36:42 +01:00
if ( empty ( $obj -> country_code )) {
2020-02-18 23:47:25 +01:00
$valuetoshow = '-' ;
2020-05-21 15:05:19 +02:00
} else {
2020-02-18 23:47:25 +01:00
$key = $langs -> trans ( " Country " . strtoupper ( $obj -> country_code ));
$valuetoshow = ( $key != " Country " . strtoupper ( $obj -> country_code ) ? $obj -> country_code . " - " . $key : $obj -> country );
2017-10-07 13:09:31 +02:00
}
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'country_id' ) {
2020-02-18 23:47:25 +01:00
$showfield = 0 ;
2017-10-07 13:09:31 +02:00
}
2016-10-15 14:38:43 +02:00
2020-02-18 23:47:25 +01:00
$class = 'tddict' ;
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'tracking' ) {
$class .= ' tdoverflowauto' ;
}
2016-10-15 14:38:43 +02:00
// Show value for field
2021-02-22 21:36:42 +01:00
if ( $showfield ) {
print '<!-- ' . $fieldlist [ $field ] . ' --><td class="' . $class . '">' . $valuetoshow . '</td>' ;
}
2017-10-07 13:09:31 +02:00
}
}
// Can an entry be erased or disabled ?
2020-02-18 23:47:25 +01:00
$iserasable = 1 ; $canbedisabled = 1 ; $canbemodified = 1 ; // true by default
2017-10-07 13:09:31 +02:00
2022-07-15 16:22:22 +02:00
$url = $_SERVER [ " PHP_SELF " ] . '?token=' . newToken () . ( $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 ;
}
2020-02-18 23:47:25 +01:00
$url .= '&' ;
2017-10-07 13:09:31 +02:00
// Active
2019-03-03 10:31:46 +01:00
print '<td class="center nowrap">' ;
2021-02-22 21:36:42 +01:00
if ( $canbedisabled ) {
print '<a href="' . $url . 'action=' . $acts [ $obj -> active ] . '">' . $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 ) {
print '<td class="center"><a href="' . $url . 'action=delete&token=' . newToken () . '">' . img_delete () . '</a></td>' ;
} else {
print '<td> </td>' ;
}
2017-10-07 13:09:31 +02:00
print " </tr> \n " ;
}
2021-05-25 15:38:12 +02:00
2017-10-07 13:09:31 +02:00
$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>' ;
2016-10-15 14:38:43 +02:00
2017-10-07 13:09:31 +02:00
print '</form>' ;
2016-10-15 14:38:43 +02:00
}
print '<br>' ;
2018-07-28 14:02:33 +02:00
// End of page
2016-10-15 14:38:43 +02:00
llxFooter ();
$db -> close ();
/**
* Show fields in insert / edit mode
*
* @ 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
*/
2019-01-27 15:20:16 +01:00
function fieldListAccountModel ( $fieldlist , $obj = '' , $tabname = '' , $context = '' )
2016-10-15 14:38:43 +02:00
{
2020-02-18 23:47:25 +01:00
global $conf , $langs , $db ;
2016-10-15 14:38:43 +02:00
global $form ;
global $region_id ;
2020-02-18 23:47:25 +01:00
global $elementList , $sourceList ;
2016-10-15 14:38:43 +02:00
$formadmin = new FormAdmin ( $db );
$formcompany = new FormCompany ( $db );
2017-05-25 06:57:28 +02:00
$formaccounting = new FormAccounting ( $db );
2021-02-22 21:36:42 +01:00
foreach ( $fieldlist as $field => $value ) {
if ( $fieldlist [ $field ] == 'country' ) {
if ( in_array ( 'region_id' , $fieldlist )) {
2016-10-15 14:38:43 +02:00
print '<td>' ;
//print join(',',$fieldlist);
print '</td>' ;
continue ;
} // For state page, we do not show the country input (we link to region, not country)
print '<td>' ;
2020-02-18 23:47:25 +01:00
$fieldname = 'country' ;
print $form -> select_country (( ! empty ( $obj -> country_code ) ? $obj -> country_code : ( ! empty ( $obj -> country ) ? $obj -> country : '' )), $fieldname , '' , 28 , 'maxwidth200 maxwidthonsmartphone' );
2016-10-15 14:38:43 +02:00
print '</td>' ;
2021-02-22 21:36:42 +01:00
} elseif ( $fieldlist [ $field ] == 'country_id' ) {
if ( ! in_array ( 'country' , $fieldlist )) { // If there is already a field country, we don't show country_id (avoid duplicate)
2020-02-18 23:47:25 +01:00
$country_id = ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : 0 );
2016-10-15 14:38:43 +02:00
print '<td>' ;
print '<input type="hidden" name="' . $fieldlist [ $field ] . '" value="' . $country_id . '">' ;
print '</td>' ;
}
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'type_cdr' ) {
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'type_cdr' ) {
print '<td class="center">' ;
} else {
print '<td>' ;
}
2016-10-15 14:38:43 +02:00
if ( $fieldlist [ $field ] == 'type_cdr' ) {
2020-02-18 23:47:25 +01:00
print $form -> selectarray ( $fieldlist [ $field ], array ( 0 => $langs -> trans ( 'None' ), 1 => $langs -> trans ( 'AtEndOfMonth' ), 2 => $langs -> trans ( 'CurrentNext' )), ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ));
2016-10-15 14:38:43 +02:00
} else {
2020-02-18 23:47:25 +01:00
print $form -> selectyesno ( $fieldlist [ $field ], ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ), 1 );
2016-10-15 14:38:43 +02:00
}
print '</td>' ;
2020-05-21 15:05:19 +02:00
} elseif ( $fieldlist [ $field ] == 'code' && isset ( $obj -> { $fieldlist [ $field ]})) {
2020-02-18 23:47:25 +01:00
print '<td><input type="text" class="flat" value="' . ( ! empty ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ) . '" size="10" name="' . $fieldlist [ $field ] . '"></td>' ;
2020-05-21 15:05:19 +02:00
} else {
2016-10-15 14:38:43 +02:00
print '<td>' ;
2020-02-18 23:47:25 +01:00
$size = '' ; $class = '' ;
2021-02-22 21:36:42 +01:00
if ( $fieldlist [ $field ] == 'code' ) {
$size = 'size="8" ' ;
}
if ( $fieldlist [ $field ] == 'position' ) {
$size = 'size="4" ' ;
}
if ( $fieldlist [ $field ] == 'libelle' ) {
$size = 'centpercent' ;
}
if ( $fieldlist [ $field ] == 'sortorder' || $fieldlist [ $field ] == 'sens' || $fieldlist [ $field ] == 'category_type' ) {
$size = 'size="2" ' ;
}
2020-02-18 23:47:25 +01:00
print '<input type="text" ' . $size . ' class="flat' . ( $class ? ' ' . $class : '' ) . '" value="' . ( isset ( $obj -> { $fieldlist [ $field ]}) ? $obj -> { $fieldlist [ $field ]} : '' ) . '" name="' . $fieldlist [ $field ] . '">' ;
2016-10-15 14:38:43 +02:00
print '</td>' ;
}
}
}