2004-10-19 20:58:50 +02:00
< ? php
2016-02-11 20:01:51 +01:00
/* Copyright ( C ) 2002 - 2003 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2002 - 2003 Jean - Louis Bergamo < jlb @ j1b . org >
* Copyright ( C ) 2004 Sebastien Di Cintio < sdicintio @ ressource - toi . org >
* Copyright ( C ) 2004 Benoit Mortier < benoit . mortier @ opensides . be >
* Copyright ( C ) 2009 - 2012 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2009 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2016-02-11 20:01:51 +01:00
* Copyright ( C ) 2013 Florian Henry < forian . henry @ open - concept . pro >
* Copyright ( C ) 2015 Charles - Fr BENKE < charles . fr @ benke . fr >
* Copyright ( C ) 2016 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2017-09-25 16:14:14 +02:00
* Copyright ( C ) 2017 Nicolas ZABOURI < info @ inovea - conseil . com >
2022-09-01 14:01:27 +02:00
* Copyright ( C ) 2018 - 2022 Frédéric France < frederic . france @ netlogic . fr >
2022-11-29 20:35:43 +01:00
* Copyright ( C ) 2022 Antonin MARCHAL < antonin @ letempledujeu . fr >
2014-03-05 09:57:36 +01: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 />.
2014-03-05 09:57:36 +01:00
*/
2003-02-13 19:14:57 +01:00
2008-11-09 13:21:20 +01:00
/**
2011-06-19 16:27:06 +02:00
* \file htdocs / core / class / extrafields . class . php
2013-07-27 14:21:47 +02:00
* \ingroup core
* \brief File of class to manage extra fields
*/
2004-07-28 00:46:33 +02:00
2014-05-01 16:26:57 +02:00
2008-11-09 13:21:20 +01:00
/**
2012-02-01 20:44:06 +01:00
* Class to manage standard extra fields
2013-07-27 14:21:47 +02:00
*/
2011-06-19 16:27:06 +02:00
class ExtraFields
2003-02-13 19:14:57 +01:00
{
2018-08-22 11:06:34 +02:00
/**
2020-09-08 21:27:28 +02:00
* @ var DoliDB Database handler .
*/
public $db ;
2017-05-24 22:48:44 +02:00
2019-02-24 09:17:45 +01:00
/**
2020-09-08 21:27:28 +02:00
* @ var array New array to store extrafields definition
*/
2019-02-24 09:17:45 +01:00
public $attributes ;
2017-06-07 16:44:04 +02:00
2022-02-24 12:54:33 +01:00
/**
* @ var array Array with boolean of status of groups
*/
public $expand_display ;
2018-08-22 10:37:16 +02:00
/**
* @ var string Error code ( or message )
*/
2019-11-13 19:35:39 +01:00
public $error = '' ;
2018-09-09 10:40:00 +02:00
2019-02-24 09:17:45 +01:00
/**
* @ var string [] Array of Error code ( or message )
*/
public $errors = array ();
2020-09-08 21:27:28 +02:00
/**
2019-02-25 21:39:45 +01:00
* @ var string DB Error number
2019-02-24 09:17:45 +01:00
*/
public $errno ;
2011-06-19 16:27:06 +02:00
2022-09-01 14:01:27 +02:00
/**
* @ var array array of type to label
*/
2019-11-13 19:35:39 +01:00
public static $type2label = array (
2020-09-08 21:27:28 +02:00
'varchar' => 'String1Line' ,
'text' => 'TextLongNLines' ,
'html' => 'HtmlText' ,
'int' => 'Int' ,
'double' => 'Float' ,
'date' => 'Date' ,
'datetime' => 'DateAndTime' ,
2023-02-11 00:22:24 +01:00
//'datetimegmt'=>'DateAndTimeUTC',
2020-09-08 21:27:28 +02:00
'boolean' => 'Boolean' ,
'price' => 'ExtrafieldPrice' ,
2022-09-21 14:59:46 +02:00
'pricecy' => 'ExtrafieldPriceWithCurrency' ,
2020-09-08 21:27:28 +02:00
'phone' => 'ExtrafieldPhone' ,
'mail' => 'ExtrafieldMail' ,
'url' => 'ExtrafieldUrl' ,
2022-07-09 12:56:38 +02:00
'ip' => 'ExtrafieldIP' ,
2020-09-08 21:27:28 +02:00
'password' => 'ExtrafieldPassword' ,
'select' => 'ExtrafieldSelect' ,
'sellist' => 'ExtrafieldSelectList' ,
'radio' => 'ExtrafieldRadio' ,
'checkbox' => 'ExtrafieldCheckBox' ,
'chkbxlst' => 'ExtrafieldCheckBoxFromList' ,
'link' => 'ExtrafieldLink' ,
'separate' => 'ExtrafieldSeparator' ,
2012-09-13 10:14:25 +02:00
);
2008-06-01 00:08:59 +02:00
2017-06-07 11:38:42 +02:00
2009-11-07 11:34:25 +01:00
/**
2011-09-11 20:35:38 +02:00
* Constructor
*
2012-02-01 20:44:06 +01:00
* @ param DoliDB $db Database handler
2020-09-08 21:27:28 +02:00
*/
2019-02-27 20:45:07 +01:00
public function __construct ( $db )
2008-06-01 00:08:59 +02:00
{
2012-02-01 20:44:06 +01:00
$this -> db = $db ;
2019-02-24 09:17:45 +01:00
$this -> error = '' ;
$this -> errors = array ();
2018-01-27 19:29:57 +01:00
$this -> attributes = array ();
2008-06-01 00:08:59 +02:00
}
2013-04-21 17:36:23 +02:00
/**
* Add a new extra field parameter
*
2017-08-27 12:06:46 +02:00
* @ param string $attrname Code of attribute
* @ param string $label label of attribute
2022-09-21 14:59:46 +02:00
* @ param string $type Type of attribute ( 'boolean' , 'int' , 'varchar' , 'text' , 'html' , 'date' , 'datehour' , 'price' , 'pricecy' , 'phone' , 'mail' , 'password' , 'url' , 'select' , 'checkbox' , 'separate' , ... )
2017-08-27 12:06:46 +02:00
* @ param int $pos Position of attribute
2019-01-25 12:03:07 +01:00
* @ param string $size Size / length definition of attribute ( '5' , '24,8' , ... ) . For float , it contains 2 numeric separated with a comma .
2018-04-12 23:16:23 +02:00
* @ param string $elementtype Element type . Same value than object -> table_element ( Example 'member' , 'product' , 'thirdparty' , ... )
2017-08-27 12:06:46 +02:00
* @ param int $unique Is field unique or not
* @ param int $required Is field required or not
* @ param string $default_value Defaulted value ( In database . use the default_value feature for default value on screen . Example : '' , '0' , 'null' , 'avalue' )
* @ param array | string $param Params for field ( ex for select list : array ( 'options' => array ( value '=>' label of option ' )) )
* @ param int $alwayseditable Is attribute always editable regardless of the document status
* @ param string $perms Permission to check
2023-02-25 00:57:02 +01:00
* @ param string $list Visibility ( '0' = never visible , '1' = visible on list + forms , '2' = list only , '3' = form only or 'eval string' )
2018-06-28 19:13:23 +02:00
* @ param string $help Text with help tooltip
2017-08-27 12:06:46 +02:00
* @ param string $computed Computed value
2018-01-13 13:16:33 +01:00
* @ param string $entity Entity of extrafields ( for multicompany modules )
2017-08-27 12:06:46 +02:00
* @ param string $langfile Language file
2018-01-13 13:16:33 +01:00
* @ param string $enabled Condition to have the field enabled or not
2019-11-05 12:47:38 +01:00
* @ param int $totalizable Is a measure . Must show a total on lists
2021-11-29 00:49:18 +01:00
* @ param int $printable Is extrafield displayed on PDF
2022-07-09 14:39:20 +02:00
* @ param array $moreparams More parameters . Example : array ( 'css' => , 'csslist' => Css on list , 'cssview' =>... )
2017-12-09 23:19:29 +01:00
* @ return int <= 0 if KO , > 0 if OK
2013-04-21 17:36:23 +02:00
*/
2022-07-09 14:39:20 +02:00
public function addExtraField ( $attrname , $label , $type , $pos , $size , $elementtype , $unique = 0 , $required = 0 , $default_value = '' , $param = '' , $alwayseditable = 0 , $perms = '' , $list = '-1' , $help = '' , $computed = '' , $entity = '' , $langfile = '' , $enabled = '1' , $totalizable = 0 , $printable = 0 , $moreparams = array ())
2011-06-19 20:09:41 +02:00
{
2021-02-23 22:03:23 +01:00
if ( empty ( $attrname )) {
return - 1 ;
}
if ( empty ( $label )) {
return - 1 ;
}
2013-04-21 17:36:23 +02:00
2021-10-21 17:09:48 +02:00
$result = 0 ;
2021-02-23 22:03:23 +01:00
if ( $type == 'separate' ) {
2021-03-01 20:37:16 +01:00
$unique = 0 ;
$required = 0 ;
2021-02-23 22:03:23 +01:00
} // Force unique and not required if this is a separator field to avoid troubles.
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-02-07 17:41:20 +01:00
2013-04-21 17:36:23 +02:00
// Create field into database except for separator type which is not stored in database
2021-02-23 22:03:23 +01:00
if ( $type != 'separate' ) {
2022-07-09 14:39:20 +02:00
$result = $this -> create ( $attrname , $type , $size , $elementtype , $unique , $required , $default_value , $param , $perms , $list , $computed , $help , $moreparams );
2013-04-21 17:36:23 +02:00
}
2020-01-30 01:48:28 +01:00
$err1 = $this -> errno ;
2021-02-23 22:03:23 +01:00
if ( $result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate' ) {
2013-04-21 17:36:23 +02:00
// Add declaration of field into table
2022-07-09 14:39:20 +02:00
$result2 = $this -> create_label ( $attrname , $label , $type , $pos , $size , $elementtype , $unique , $required , $param , $alwayseditable , $perms , $list , $help , $default_value , $computed , $entity , $langfile , $enabled , $totalizable , $printable , $moreparams );
2020-01-30 01:48:28 +01:00
$err2 = $this -> errno ;
2021-02-23 22:03:23 +01:00
if ( $result2 > 0 || ( $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS' )) {
2020-01-30 01:48:28 +01:00
$this -> error = '' ;
$this -> errno = 0 ;
2013-04-21 17:36:23 +02:00
return 1 ;
2021-02-23 22:03:23 +01:00
} else {
return - 2 ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-04-21 17:36:23 +02:00
return - 1 ;
}
2011-06-19 20:09:41 +02:00
}
2009-11-07 11:34:25 +01:00
/**
2014-03-05 09:57:36 +01:00
* Add a new optional attribute .
2012-10-24 21:28:24 +02:00
* This is a private method . For public method , use addExtraField .
2012-02-01 20:44:06 +01:00
*
2012-02-20 10:09:28 +01:00
* @ param string $attrname code of attribute
2022-09-21 14:59:46 +02:00
* @ param int $type Type of attribute ( 'boolean' , 'int' , 'varchar' , 'text' , 'html' , 'date' , 'datehour' , 'price' , 'pricecy' , 'phone' , 'mail' , 'password' , 'url' , 'select' , 'checkbox' , ... )
2015-04-30 00:07:30 +02:00
* @ param string $length Size / length of attribute ( '5' , '24,8' , ... )
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , 'contact' , ... )
2013-04-21 17:36:23 +02:00
* @ param int $unique Is field unique or not
* @ param int $required Is field required or not
2017-05-24 22:48:44 +02:00
* @ param string $default_value Default value for field ( in database )
2013-04-21 17:36:23 +02:00
* @ param array $param Params for field ( ex for select list : array ( 'options' => array ( 'value' => 'label of option' ))
2015-03-10 22:27:16 +01:00
* @ param string $perms Permission
2018-04-10 15:39:11 +02:00
* @ param string $list Into list view by default
2017-05-24 22:48:44 +02:00
* @ param string $computed Computed value
2019-09-06 10:36:49 +02:00
* @ param string $help Help on tooltip
2022-07-09 14:39:20 +02:00
* @ param array $moreparams More parameters . Example : array ( 'css' => , 'csslist' => , 'cssview' =>... )
2013-04-21 17:36:23 +02:00
* @ return int <= 0 if KO , > 0 if OK
2009-11-07 11:34:25 +01:00
*/
2022-07-09 14:39:20 +02:00
private function create ( $attrname , $type = 'varchar' , $length = 255 , $elementtype = 'member' , $unique = 0 , $required = 0 , $default_value = '' , $param = '' , $perms = '' , $list = '0' , $computed = '' , $help = '' , $moreparams = array ())
2011-06-19 16:27:06 +02:00
{
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2019-11-13 19:35:39 +01:00
$table = $elementtype . '_extrafields' ;
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'categorie' ) {
$table = 'categories_extrafields' ;
}
2019-11-13 19:35:39 +01:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $attrname ) && preg_match ( " /^ \ w[a-zA-Z0-9_]* $ / " , $attrname ) && ! is_numeric ( $attrname )) {
2019-11-13 19:35:39 +01:00
if ( $type == 'boolean' ) {
$typedb = 'int' ;
$lengthdb = '1' ;
} elseif ( $type == 'price' ) {
$typedb = 'double' ;
$lengthdb = '24,8' ;
2022-09-21 14:59:46 +02:00
} elseif ( $type == 'pricecy' ) {
$typedb = 'varchar' ;
$lengthdb = '64' ;
2019-11-13 19:35:39 +01:00
} elseif ( $type == 'phone' ) {
$typedb = 'varchar' ;
$lengthdb = '20' ;
2022-07-09 12:56:38 +02:00
} elseif ( $type == 'mail' || $type == 'ip' ) {
2019-11-13 19:35:39 +01:00
$typedb = 'varchar' ;
$lengthdb = '128' ;
} elseif ( $type == 'url' ) {
$typedb = 'varchar' ;
$lengthdb = '255' ;
} elseif (( $type == 'select' ) || ( $type == 'sellist' ) || ( $type == 'radio' ) || ( $type == 'checkbox' ) || ( $type == 'chkbxlst' )) {
$typedb = 'varchar' ;
$lengthdb = '255' ;
} elseif ( $type == 'link' ) {
$typedb = 'int' ;
$lengthdb = '11' ;
} elseif ( $type == 'html' ) {
$typedb = 'text' ;
$lengthdb = $length ;
} elseif ( $type == 'password' ) {
$typedb = 'varchar' ;
$lengthdb = '128' ;
2013-01-12 14:02:39 +01:00
} else {
2019-11-13 19:35:39 +01:00
$typedb = $type ;
$lengthdb = $length ;
2021-02-23 22:03:23 +01:00
if ( $type == 'varchar' && empty ( $lengthdb )) {
$lengthdb = '255' ;
}
2013-01-12 14:02:39 +01:00
}
2013-02-14 23:34:44 +01:00
$field_desc = array (
2018-07-09 13:02:01 +02:00
'type' => $typedb ,
'value' => $lengthdb ,
2019-11-13 19:35:39 +01:00
'null' => ( $required ? 'NOT NULL' : 'NULL' ),
2018-07-09 13:02:01 +02:00
'default' => $default_value
2013-02-14 23:34:44 +01:00
);
2013-04-21 17:36:23 +02:00
2022-01-27 10:19:35 +01:00
$result = $this -> db -> DDLAddField ( $this -> db -> prefix () . $table , $attrname , $field_desc );
2021-02-23 22:03:23 +01:00
if ( $result > 0 ) {
if ( $unique ) {
2022-01-27 10:19:35 +01:00
$sql = " ALTER TABLE " . $this -> db -> prefix () . $table . " ADD UNIQUE INDEX uk_ " . $table . " _ " . $attrname . " ( " . $attrname . " ) " ;
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql , 1 , 'dml' );
2012-09-22 20:27:06 +02:00
}
2008-06-01 00:08:59 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
$this -> errno = $this -> db -> lasterrno ();
2011-06-12 17:47:10 +02:00
return - 1 ;
2008-06-01 00:08:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2008-06-01 00:08:59 +02:00
return 0 ;
}
2004-07-28 00:46:33 +02:00
}
2003-02-19 18:47:22 +01:00
2020-09-08 21:27:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-06-01 00:08:59 +02:00
/**
2014-03-05 09:57:36 +01:00
* Add description of a new optional attribute
2012-02-01 20:44:06 +01:00
*
2014-04-23 12:07:22 +02:00
* @ param string $attrname code of attribute
* @ param string $label label of attribute
2018-02-27 17:30:13 +01:00
* @ param int $type Type of attribute ( 'int' , 'varchar' , 'text' , 'html' , 'date' , 'datehour' , 'float' )
2014-04-23 12:07:22 +02:00
* @ param int $pos Position of attribute
2015-04-30 00:07:30 +02:00
* @ param string $size Size / length of attribute ( '5' , '24,8' , ... )
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , ... )
2014-04-23 12:07:22 +02:00
* @ param int $unique Is field unique or not
* @ param int $required Is field required or not
2017-08-27 12:06:46 +02:00
* @ param array | string $param Params for field ( ex for select list : array ( 'options' => array ( value '=>' label of option ' )) )
2014-10-16 13:28:39 +02:00
* @ param int $alwayseditable Is attribute always editable regardless of the document status
2015-03-10 18:33:14 +01:00
* @ param string $perms Permission to check
2018-04-10 15:39:11 +02:00
* @ param string $list Visibily
2018-06-28 19:13:23 +02:00
* @ param string $help Help on tooltip
2017-05-24 22:48:44 +02:00
* @ param string $default Default value ( in database . use the default_value feature for default value on screen ) .
* @ param string $computed Computed value
2017-08-04 09:00:11 +02:00
* @ param string $entity Entity of extrafields
2017-08-27 12:06:46 +02:00
* @ param string $langfile Language file
2018-01-13 13:16:33 +01:00
* @ param string $enabled Condition to have the field enabled or not
2019-11-05 12:47:38 +01:00
* @ param int $totalizable Is a measure . Must show a total on lists
2022-07-09 14:39:20 +02:00
* @ param int $printable Is extrafield displayed on PDF
* @ param array $moreparams More parameters . Example : array ( 'css' => , 'csslist' => , 'cssview' =>... )
2014-04-23 12:07:22 +02:00
* @ return int <= 0 if KO , > 0 if OK
2020-09-08 21:27:28 +02:00
* @ throws Exception
2009-01-27 00:58:37 +01:00
*/
2022-07-09 14:39:20 +02:00
private function create_label ( $attrname , $label = '' , $type = '' , $pos = 0 , $size = 0 , $elementtype = 'member' , $unique = 0 , $required = 0 , $param = '' , $alwayseditable = 0 , $perms = '' , $list = '-1' , $help = '' , $default = '' , $computed = '' , $entity = '' , $langfile = '' , $enabled = '1' , $totalizable = 0 , $printable = 0 , $moreparams = array ())
2003-02-19 18:47:22 +01:00
{
2020-09-08 21:27:28 +02:00
// phpcs:enable
2019-11-13 19:35:39 +01:00
global $conf , $user ;
2009-11-07 14:55:15 +01:00
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-02-07 17:41:20 +01:00
2009-01-27 00:58:37 +01:00
// Clean parameters
2021-02-23 22:03:23 +01:00
if ( empty ( $pos )) {
$pos = 0 ;
}
if ( empty ( $list )) {
$list = '0' ;
}
if ( empty ( $required )) {
$required = 0 ;
}
if ( empty ( $unique )) {
$unique = 0 ;
}
if ( empty ( $printable )) {
$printable = 0 ;
}
if ( empty ( $alwayseditable )) {
$alwayseditable = 0 ;
}
if ( empty ( $totalizable )) {
$totalizable = 0 ;
}
2022-07-09 14:39:20 +02:00
$css = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'css' ])) {
$css = $moreparams [ 'css' ];
}
$csslist = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'csslist' ])) {
$csslist = $moreparams [ 'csslist' ];
}
$cssview = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'cssview' ])) {
$cssview = $moreparams [ 'cssview' ];
}
2021-02-23 22:03:23 +01:00
if ( ! empty ( $attrname ) && preg_match ( " /^ \ w[a-zA-Z0-9-_]* $ / " , $attrname ) && ! is_numeric ( $attrname )) {
if ( is_array ( $param ) && count ( $param ) > 0 ) {
2018-01-27 19:35:30 +01:00
$params = serialize ( $param );
2021-02-23 22:03:23 +01:00
} elseif ( strlen ( $param ) > 0 ) {
2013-02-14 23:34:44 +01:00
$params = trim ( $param );
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$params = '' ;
2013-02-14 23:34:44 +01:00
}
2013-04-21 17:36:23 +02:00
2022-01-27 10:19:35 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " extrafields( " ;
2020-01-30 01:48:28 +01:00
$sql .= " name, " ;
$sql .= " label, " ;
$sql .= " type, " ;
$sql .= " pos, " ;
$sql .= " size, " ;
$sql .= " entity, " ;
$sql .= " elementtype, " ;
$sql .= " fieldunique, " ;
$sql .= " fieldrequired, " ;
$sql .= " param, " ;
$sql .= " alwayseditable, " ;
$sql .= " perms, " ;
$sql .= " langs, " ;
$sql .= " list, " ;
2020-02-23 23:03:17 +01:00
$sql .= " printable, " ;
2020-01-30 01:48:28 +01:00
$sql .= " fielddefault, " ;
$sql .= " fieldcomputed, " ;
$sql .= " fk_user_author, " ;
$sql .= " fk_user_modif, " ;
$sql .= " datec, " ;
$sql .= " enabled, " ;
$sql .= " help, " ;
2022-07-09 14:39:20 +02:00
$sql .= " totalizable, " ;
$sql .= " css, " ;
$sql .= " csslist, " ;
$sql .= " cssview " ;
2020-01-30 01:48:28 +01:00
$sql .= " ) " ;
2020-09-19 21:19:04 +02:00
$sql .= " VALUES(' " . $this -> db -> escape ( $attrname ) . " ', " ;
2020-01-30 01:48:28 +01:00
$sql .= " ' " . $this -> db -> escape ( $label ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $type ) . " ', " ;
2021-06-14 13:51:09 +02:00
$sql .= " " . (( int ) $pos ) . " , " ;
2020-01-30 01:48:28 +01:00
$sql .= " ' " . $this -> db -> escape ( $size ) . " ', " ;
$sql .= " " . ( $entity === '' ? $conf -> entity : $entity ) . " , " ;
$sql .= " ' " . $this -> db -> escape ( $elementtype ) . " ', " ;
2021-06-14 13:51:09 +02:00
$sql .= " " . (( int ) $unique ) . " , " ;
$sql .= " " . (( int ) $required ) . " , " ;
2020-01-30 01:48:28 +01:00
$sql .= " ' " . $this -> db -> escape ( $params ) . " ', " ;
2021-06-14 13:51:09 +02:00
$sql .= " " . (( int ) $alwayseditable ) . " , " ;
2020-01-30 01:48:28 +01:00
$sql .= " " . ( $perms ? " ' " . $this -> db -> escape ( $perms ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $langfile ? " ' " . $this -> db -> escape ( $langfile ) . " ' " : " null " ) . " , " ;
$sql .= " ' " . $this -> db -> escape ( $list ) . " ', " ;
2020-02-23 23:03:17 +01:00
$sql .= " ' " . $this -> db -> escape ( $printable ) . " ', " ;
2020-01-30 01:48:28 +01:00
$sql .= " " . ( $default ? " ' " . $this -> db -> escape ( $default ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $computed ? " ' " . $this -> db -> escape ( $computed ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( is_object ( $user ) ? $user -> id : 0 ) . " , " ;
$sql .= " " . ( is_object ( $user ) ? $user -> id : 0 ) . " , " ;
$sql .= " ' " . $this -> db -> idate ( dol_now ()) . " ', " ;
$sql .= " " . ( $enabled ? " ' " . $this -> db -> escape ( $enabled ) . " ' " : " 1 " ) . " , " ;
$sql .= " " . ( $help ? " ' " . $this -> db -> escape ( $help ) . " ' " : " null " ) . " , " ;
2022-07-09 14:39:20 +02:00
$sql .= " " . ( $totalizable ? 'TRUE' : 'FALSE' ) . " , " ;
$sql .= " " . ( $css ? " ' " . $this -> db -> escape ( $css ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $csslist ? " ' " . $this -> db -> escape ( $csslist ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $cssview ? " ' " . $this -> db -> escape ( $cssview ) . " ' " : " null " );
2020-01-30 01:48:28 +01:00
$sql .= ')' ;
2017-08-24 13:23:15 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::create_label " , LOG_DEBUG );
2021-02-23 22:03:23 +01:00
if ( $this -> db -> query ( $sql )) {
2008-06-01 00:08:59 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
$this -> errno = $this -> db -> lasterrno ();
2012-03-03 13:42:27 +01:00
return - 1 ;
2008-06-01 00:08:59 +02:00
}
}
2003-02-19 18:47:22 +01:00
}
2008-06-01 00:08:59 +02:00
2009-01-27 00:58:37 +01:00
/**
2014-03-05 09:57:36 +01:00
* Delete an optional attribute
2012-02-01 20:44:06 +01:00
*
2012-02-20 10:09:28 +01:00
* @ param string $attrname Code of attribute to delete
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , 'contact' , ... )
2012-02-20 10:09:28 +01:00
* @ return int < 0 if KO , 0 if nothing is done , 1 if OK
2009-01-27 00:58:37 +01:00
*/
2019-02-27 20:45:07 +01:00
public function delete ( $attrname , $elementtype = 'member' )
2003-02-19 18:47:22 +01:00
{
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-02-07 17:41:20 +01:00
2019-11-13 19:35:39 +01:00
$table = $elementtype . '_extrafields' ;
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'categorie' ) {
$table = 'categories_extrafields' ;
}
2012-10-25 10:06:29 +02:00
2019-11-13 19:35:39 +01:00
$error = 0 ;
2017-06-07 11:38:42 +02:00
2021-02-23 22:03:23 +01:00
if ( ! empty ( $attrname ) && preg_match ( " /^ \ w[a-zA-Z0-9-_]* $ / " , $attrname )) {
2019-11-13 19:35:39 +01:00
$result = $this -> delete_label ( $attrname , $elementtype );
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2020-09-08 21:27:28 +02:00
$this -> error = $this -> db -> lasterror ();
2019-11-13 19:35:39 +01:00
$this -> errors [] = $this -> db -> lasterror ();
2020-09-08 21:27:28 +02:00
$error ++ ;
2008-06-01 00:08:59 +02:00
}
2009-01-27 00:58:37 +01:00
2021-02-23 22:03:23 +01:00
if ( ! $error ) {
2020-09-08 21:27:28 +02:00
$sql = " SELECT COUNT(rowid) as nb " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " extrafields " ;
2020-09-19 21:19:04 +02:00
$sql .= " WHERE elementtype = ' " . $this -> db -> escape ( $elementtype ) . " ' " ;
$sql .= " AND name = ' " . $this -> db -> escape ( $attrname ) . " ' " ;
2020-09-08 21:27:28 +02:00
//$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-09-08 21:27:28 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2021-02-23 22:03:23 +01:00
if ( $obj -> nb <= 0 ) {
2022-01-27 10:19:35 +01:00
$result = $this -> db -> DDLDropField ( $this -> db -> prefix () . $table , $attrname ); // This also drop the unique key
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2020-09-08 21:27:28 +02:00
$this -> error = $this -> db -> lasterror ();
$this -> errors [] = $this -> db -> lasterror ();
$error ++ ;
}
}
}
2017-01-04 15:05:13 +01:00
}
2017-06-07 11:38:42 +02:00
2009-01-27 00:58:37 +01:00
return $result ;
2020-05-21 15:05:19 +02:00
} else {
2008-06-01 00:08:59 +02:00
return 0 ;
}
}
2003-02-19 18:47:22 +01:00
2020-09-08 21:27:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-01-27 00:58:37 +01:00
/**
2014-03-05 09:57:36 +01:00
* Delete description of an optional attribute
2012-02-01 20:44:06 +01:00
*
2012-02-20 10:09:28 +01:00
* @ param string $attrname Code of attribute to delete
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , ... )
2013-04-21 17:36:23 +02:00
* @ return int < 0 if KO , 0 if nothing is done , 1 if OK
2009-01-27 00:58:37 +01:00
*/
2019-01-27 15:20:16 +01:00
private function delete_label ( $attrname , $elementtype = 'member' )
2003-02-19 18:47:22 +01:00
{
2020-09-08 21:27:28 +02:00
// phpcs:enable
2009-11-07 11:34:25 +01:00
global $conf ;
2009-11-07 14:55:15 +01:00
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-02-07 17:41:20 +01:00
2021-02-23 22:03:23 +01:00
if ( isset ( $attrname ) && $attrname != '' && preg_match ( " /^ \ w[a-zA-Z0-9-_]* $ / " , $attrname )) {
2022-01-27 10:19:35 +01:00
$sql = " DELETE FROM " . $this -> db -> prefix () . " extrafields " ;
2020-09-19 21:19:04 +02:00
$sql .= " WHERE name = ' " . $this -> db -> escape ( $attrname ) . " ' " ;
2019-11-13 19:35:39 +01:00
$sql .= " AND entity IN (0, " . $conf -> entity . ')' ;
2020-09-19 21:19:04 +02:00
$sql .= " AND elementtype = ' " . $this -> db -> escape ( $elementtype ) . " ' " ;
2008-06-01 00:08:59 +02:00
2014-06-12 11:31:53 +02:00
dol_syslog ( get_class ( $this ) . " ::delete_label " , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2008-06-01 00:08:59 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-26 18:28:44 +01:00
dol_print_error ( $this -> db );
2011-06-19 16:27:06 +02:00
return - 1 ;
2008-06-01 00:08:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2008-06-01 00:08:59 +02:00
return 0 ;
}
}
2003-02-14 18:14:29 +01:00
2009-01-27 00:58:37 +01:00
/**
2011-03-08 11:48:53 +01:00
* Modify type of a personalized attribute
2012-02-01 20:44:06 +01:00
*
2012-02-20 10:09:28 +01:00
* @ param string $attrname Name of attribute
2012-09-22 20:27:06 +02:00
* @ param string $label Label of attribute
2018-02-27 17:30:13 +01:00
* @ param string $type Type of attribute ( 'boolean' , 'int' , 'varchar' , 'text' , 'html' , 'date' , 'datehour' , 'price' , 'phone' , 'mail' , 'password' , 'url' , 'select' , 'checkbox' , ... )
2012-02-20 10:09:28 +01:00
* @ param int $length Length of attribute
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , 'contact' , ... )
2013-04-21 17:36:23 +02:00
* @ param int $unique Is field unique or not
* @ param int $required Is field required or not
* @ param int $pos Position of attribute
2017-08-24 13:43:36 +02:00
* @ param array $param Params for field ( ex for select list : array ( 'options' => array ( value '=>' label of option ' )) )
2014-10-16 13:28:39 +02:00
* @ param int $alwayseditable Is attribute always editable regardless of the document status
2015-03-10 18:33:14 +01:00
* @ param string $perms Permission to check
2018-04-10 15:39:11 +02:00
* @ param string $list Visibility
2018-06-28 19:13:23 +02:00
* @ param string $help Help on tooltip
2017-05-24 22:48:44 +02:00
* @ param string $default Default value ( in database . use the default_value feature for default value on screen ) .
* @ param string $computed Computed value
2017-08-04 09:00:11 +02:00
* @ param string $entity Entity of extrafields
2017-08-27 12:06:46 +02:00
* @ param string $langfile Language file
2018-01-13 13:16:33 +01:00
* @ param string $enabled Condition to have the field enabled or not
2020-09-08 21:27:28 +02:00
* @ param int $totalizable Is extrafield totalizable on list
2022-07-09 14:39:20 +02:00
* @ param int $printable Is extrafield displayed on PDF
* @ param array $moreparams More parameters . Example : array ( 'css' => , 'csslist' => , 'cssview' =>... )
2012-02-20 10:09:28 +01:00
* @ return int > 0 if OK , <= 0 if KO
2020-09-08 21:27:28 +02:00
* @ throws Exception
2009-11-07 11:34:25 +01:00
*/
2022-07-09 14:39:20 +02:00
public function update ( $attrname , $label , $type , $length , $elementtype , $unique = 0 , $required = 0 , $pos = 0 , $param = '' , $alwayseditable = 0 , $perms = '' , $list = '' , $help = '' , $default = '' , $computed = '' , $entity = '' , $langfile = '' , $enabled = '1' , $totalizable = 0 , $printable = 0 , $moreparams = array ())
2003-02-19 18:47:22 +01:00
{
2021-05-11 11:35:54 +02:00
global $hookmanager ;
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-02-07 17:41:20 +01:00
2020-09-08 21:27:28 +02:00
$table = $elementtype . '_extrafields' ;
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'categorie' ) {
$table = 'categories_extrafields' ;
}
2011-06-19 16:27:06 +02:00
2021-02-23 22:03:23 +01:00
if ( isset ( $attrname ) && $attrname != '' && preg_match ( " /^ \ w[a-zA-Z0-9-_]* $ / " , $attrname )) {
2019-11-13 19:35:39 +01:00
if ( $type == 'boolean' ) {
$typedb = 'int' ;
$lengthdb = '1' ;
} elseif ( $type == 'price' ) {
$typedb = 'double' ;
$lengthdb = '24,8' ;
2022-09-21 14:59:46 +02:00
} elseif ( $type == 'pricecy' ) {
$typedb = 'varchar' ;
$lengthdb = '64' ;
2019-11-13 19:35:39 +01:00
} elseif ( $type == 'phone' ) {
$typedb = 'varchar' ;
$lengthdb = '20' ;
2022-07-09 12:56:38 +02:00
} elseif ( $type == 'mail' || $type == 'ip' ) {
2019-11-13 19:35:39 +01:00
$typedb = 'varchar' ;
$lengthdb = '128' ;
} elseif ( $type == 'url' ) {
$typedb = 'varchar' ;
$lengthdb = '255' ;
} elseif (( $type == 'select' ) || ( $type == 'sellist' ) || ( $type == 'radio' ) || ( $type == 'checkbox' ) || ( $type == 'chkbxlst' )) {
$typedb = 'varchar' ;
$lengthdb = '255' ;
2018-02-27 17:30:13 +01:00
} elseif ( $type == 'html' ) {
2019-11-13 19:35:39 +01:00
$typedb = 'text' ;
} elseif ( $type == 'link' ) {
$typedb = 'int' ;
$lengthdb = '11' ;
} elseif ( $type == 'password' ) {
$typedb = 'varchar' ;
$lengthdb = '50' ;
2013-01-12 14:02:39 +01:00
} else {
2019-11-13 19:35:39 +01:00
$typedb = $type ;
$lengthdb = $length ;
2013-01-12 14:02:39 +01:00
}
2019-11-13 19:35:39 +01:00
$field_desc = array ( 'type' => $typedb , 'value' => $lengthdb , 'null' => ( $required ? 'NOT NULL' : 'NULL' ), 'default' => $default );
2013-04-21 17:36:23 +02:00
2021-05-11 22:12:15 +02:00
if ( is_object ( $hookmanager )) {
2021-05-11 11:35:54 +02:00
$hookmanager -> initHooks ( array ( 'extrafieldsdao' ));
$parameters = array ( 'field_desc' =>& $field_desc , 'table' => $table , 'attr_name' => $attrname , 'label' => $label , 'type' => $type , 'length' => $length , 'unique' => $unique , 'required' => $required , 'pos' => $pos , 'param' => $param , 'alwayseditable' => $alwayseditable , 'perms' => $perms , 'list' => $list , 'help' => $help , 'default' => $default , 'computed' => $computed , 'entity' => $entity , 'langfile' => $langfile , 'enabled' => $enabled , 'totalizable' => $totalizable , 'printable' => $printable );
$reshook = $hookmanager -> executeHooks ( 'updateExtrafields' , $parameters , $this , $action ); // Note that $action and $object may have been modified by some hooks
if ( $reshook < 0 ) {
$this -> error = $this -> db -> lasterror ();
return - 1 ;
}
}
2021-02-23 22:03:23 +01:00
if ( $type != 'separate' ) { // No table update when separate type
2022-01-27 10:19:35 +01:00
$result = $this -> db -> DDLUpdateField ( $this -> db -> prefix () . $table , $attrname , $field_desc );
2013-03-16 00:00:57 +01:00
}
2021-02-23 22:03:23 +01:00
if ( $result > 0 || $type == 'separate' ) {
if ( $label ) {
2022-07-09 14:39:20 +02:00
$result = $this -> update_label ( $attrname , $label , $type , $length , $elementtype , $unique , $required , $pos , $param , $alwayseditable , $perms , $list , $help , $default , $computed , $entity , $langfile , $enabled , $totalizable , $printable , $moreparams );
2012-09-30 21:26:58 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $result > 0 ) {
2019-11-13 19:35:39 +01:00
$sql = '' ;
2021-02-23 22:03:23 +01:00
if ( $unique ) {
2022-01-27 10:19:35 +01:00
$sql = " ALTER TABLE " . $this -> db -> prefix () . $table . " ADD UNIQUE INDEX uk_ " . $table . " _ " . $attrname . " ( " . $attrname . " ) " ;
2020-05-21 15:05:19 +02:00
} else {
2022-02-10 10:13:24 +01:00
$sql = " ALTER TABLE " . $this -> db -> prefix () . $table . " DROP INDEX IF EXISTS uk_ " . $table . " _ " . $attrname ;
2012-09-22 20:27:06 +02:00
}
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . '::update' , LOG_DEBUG );
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql , 1 , 'dml' );
2022-02-10 10:11:46 +01:00
/* if ( $resql < 0 ) {
2022-02-08 08:46:15 +01:00
$this -> error = $this -> db -> lasterror ();
return - 1 ;
2022-02-10 10:11:46 +01:00
} */
2012-09-22 20:27:06 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2012-09-22 20:27:06 +02:00
return - 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$this -> error = $this -> db -> lasterror ();
2011-06-12 17:47:10 +02:00
return - 1 ;
2008-06-01 00:08:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2008-06-01 00:08:59 +02:00
return 0 ;
}
}
2003-02-19 18:47:22 +01:00
2020-09-08 21:27:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2009-11-07 11:34:25 +01:00
/**
2011-06-19 16:27:06 +02:00
* Modify description of personalized attribute
2012-02-01 20:44:06 +01:00
*
* @ param string $attrname Name of attribute
* @ param string $label Label of attribute
2013-04-21 17:36:23 +02:00
* @ param string $type Type of attribute
* @ param int $size Length of attribute
2015-02-07 17:41:20 +01:00
* @ param string $elementtype Element type ( 'member' , 'product' , 'thirdparty' , ... )
2013-04-21 17:36:23 +02:00
* @ param int $unique Is field unique or not
* @ param int $required Is field required or not
* @ param int $pos Position of attribute
* @ param array $param Params for field ( ex for select list : array ( 'options' => array ( value '=>' label of option ' )) )
2014-10-16 13:28:39 +02:00
* @ param int $alwayseditable Is attribute always editable regardless of the document status
2015-03-10 18:33:14 +01:00
* @ param string $perms Permission to check
2018-04-10 15:39:11 +02:00
* @ param string $list Visiblity
2018-06-28 19:13:23 +02:00
* @ param string $help Help on tooltip .
2017-05-24 22:48:44 +02:00
* @ param string $default Default value ( in database . use the default_value feature for default value on screen ) .
* @ param string $computed Computed value
2017-08-04 09:00:11 +02:00
* @ param string $entity Entity of extrafields
2017-08-27 12:06:46 +02:00
* @ param string $langfile Language file
2018-01-13 13:16:33 +01:00
* @ param string $enabled Condition to have the field enabled or not
2020-09-08 21:27:28 +02:00
* @ param int $totalizable Is extrafield totalizable on list
2022-07-09 14:39:20 +02:00
* @ param int $printable Is extrafield displayed on PDF
* @ param array $moreparams More parameters . Example : array ( 'css' => , 'csslist' => , 'cssview' =>... )
2020-09-08 21:27:28 +02:00
* @ return int <= 0 if KO , > 0 if OK
* @ throws Exception
2013-04-21 17:36:23 +02:00
*/
2022-07-09 14:39:20 +02:00
private function update_label ( $attrname , $label , $type , $size , $elementtype , $unique = 0 , $required = 0 , $pos = 0 , $param = '' , $alwayseditable = 0 , $perms = '' , $list = '0' , $help = '' , $default = '' , $computed = '' , $entity = '' , $langfile = '' , $enabled = '1' , $totalizable = 0 , $printable = 0 , $moreparams = array ())
2008-06-01 00:08:59 +02:00
{
2020-09-08 21:27:28 +02:00
// phpcs:enable
2017-07-25 11:57:36 +02:00
global $conf , $user ;
2020-02-23 23:03:17 +01:00
dol_syslog ( get_class ( $this ) . " ::update_label " . $attrname . " , " . $label . " , " . $type . " , " . $size . " , " . $elementtype . " , " . $unique . " , " . $required . " , " . $pos . " , " . $alwayseditable . " , " . $perms . " , " . $list . " , " . $default . " , " . $computed . " , " . $entity . " , " . $langfile . " , " . $enabled . " , " . $totalizable . " , " . $printable );
2009-11-07 14:55:15 +01:00
2015-03-10 22:27:16 +01:00
// Clean parameters
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
2015-05-25 17:19:22 +02:00
2021-02-23 22:03:23 +01:00
if ( empty ( $pos )) {
$pos = 0 ;
}
if ( empty ( $list )) {
$list = '0' ;
}
2020-09-08 21:27:28 +02:00
if ( empty ( $totalizable )) {
$totalizable = 0 ;
}
2021-02-23 22:03:23 +01:00
if ( empty ( $required )) {
$required = 0 ;
}
if ( empty ( $unique )) {
$unique = 0 ;
}
if ( empty ( $alwayseditable )) {
$alwayseditable = 0 ;
}
2015-02-07 17:41:20 +01:00
2022-07-09 14:39:20 +02:00
$css = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'css' ])) {
$css = $moreparams [ 'css' ];
}
$csslist = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'csslist' ])) {
$csslist = $moreparams [ 'csslist' ];
}
$cssview = '' ;
if ( ! empty ( $moreparams ) && ! empty ( $moreparams [ 'cssview' ])) {
$cssview = $moreparams [ 'cssview' ];
}
2021-02-23 22:03:23 +01:00
if ( isset ( $attrname ) && $attrname != '' && preg_match ( " /^ \ w[a-zA-Z0-9-_]* $ / " , $attrname )) {
2009-11-07 14:55:15 +01:00
$this -> db -> begin ();
2013-04-21 17:36:23 +02:00
2021-02-23 22:03:23 +01:00
if ( is_array ( $param ) && count ( $param ) > 0 ) {
2018-01-31 10:51:40 +01:00
$params = serialize ( $param );
2023-03-13 16:24:19 +01:00
} elseif ( is_array ( $param )) {
$params = '' ;
2021-02-23 22:03:23 +01:00
} elseif ( strlen ( $param ) > 0 ) {
2018-01-31 10:51:40 +01:00
$params = trim ( $param );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$params = '' ;
2013-02-15 11:19:49 +01:00
}
2013-04-21 17:36:23 +02:00
2021-02-23 22:03:23 +01:00
if ( $entity === '' || $entity != '0' ) {
2018-09-10 17:36:46 +02:00
// We dont want on all entities, we delete all and current
2022-01-27 10:19:35 +01:00
$sql_del = " DELETE FROM " . $this -> db -> prefix () . " extrafields " ;
2020-09-19 21:19:04 +02:00
$sql_del .= " WHERE name = ' " . $this -> db -> escape ( $attrname ) . " ' " ;
2019-11-13 19:35:39 +01:00
$sql_del .= " AND entity IN (0, " . ( $entity === '' ? $conf -> entity : $entity ) . " ) " ;
2020-09-19 21:19:04 +02:00
$sql_del .= " AND elementtype = ' " . $this -> db -> escape ( $elementtype ) . " ' " ;
2020-05-21 15:05:19 +02:00
} else {
2018-09-10 17:36:46 +02:00
// We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity)
2022-01-27 10:19:35 +01:00
$sql_del = " DELETE FROM " . $this -> db -> prefix () . " extrafields " ;
2020-09-19 21:19:04 +02:00
$sql_del .= " WHERE name = ' " . $this -> db -> escape ( $attrname ) . " ' " ;
2019-11-13 19:35:39 +01:00
$sql_del .= " AND entity = 0 " ;
2020-09-19 21:19:04 +02:00
$sql_del .= " AND elementtype = ' " . $this -> db -> escape ( $elementtype ) . " ' " ;
2018-09-10 17:36:46 +02:00
}
2019-11-13 19:35:39 +01:00
$resql1 = $this -> db -> query ( $sql_del );
2009-11-07 14:55:15 +01:00
2022-01-27 10:19:35 +01:00
$sql = " INSERT INTO " . $this -> db -> prefix () . " extrafields( " ;
2019-11-13 19:35:39 +01:00
$sql .= " name, " ; // This is code
$sql .= " entity, " ;
$sql .= " label, " ;
$sql .= " type, " ;
$sql .= " size, " ;
$sql .= " elementtype, " ;
$sql .= " fieldunique, " ;
$sql .= " fieldrequired, " ;
$sql .= " perms, " ;
$sql .= " langs, " ;
$sql .= " pos, " ;
$sql .= " alwayseditable, " ;
$sql .= " param, " ;
$sql .= " list, " ;
2020-02-23 23:03:17 +01:00
$sql .= " printable, " ;
2020-09-08 21:27:28 +02:00
$sql .= " totalizable, " ;
2019-11-13 19:35:39 +01:00
$sql .= " fielddefault, " ;
$sql .= " fieldcomputed, " ;
$sql .= " fk_user_author, " ;
$sql .= " fk_user_modif, " ;
$sql .= " datec, " ;
$sql .= " enabled, " ;
2022-07-09 14:39:20 +02:00
$sql .= " help, " ;
$sql .= " css, " ;
$sql .= " csslist, " ;
$sql .= " cssview " ;
2019-11-13 19:35:39 +01:00
$sql .= " ) VALUES ( " ;
2020-09-19 21:19:04 +02:00
$sql .= " ' " . $this -> db -> escape ( $attrname ) . " ', " ;
2019-11-13 19:35:39 +01:00
$sql .= " " . ( $entity === '' ? $conf -> entity : $entity ) . " , " ;
$sql .= " ' " . $this -> db -> escape ( $label ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $type ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $size ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $elementtype ) . " ', " ;
$sql .= " " . $unique . " , " ;
$sql .= " " . $required . " , " ;
$sql .= " " . ( $perms ? " ' " . $this -> db -> escape ( $perms ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $langfile ? " ' " . $this -> db -> escape ( $langfile ) . " ' " : " null " ) . " , " ;
$sql .= " " . $pos . " , " ;
$sql .= " ' " . $this -> db -> escape ( $alwayseditable ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $params ) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $list ) . " ', " ;
2020-02-23 23:03:17 +01:00
$sql .= " ' " . $this -> db -> escape ( $printable ) . " ', " ;
2020-09-08 21:27:28 +02:00
$sql .= " " . ( $totalizable ? 'TRUE' : 'FALSE' ) . " , " ;
2019-11-13 19:35:39 +01:00
$sql .= " " . (( $default != '' ) ? " ' " . $this -> db -> escape ( $default ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $computed ? " ' " . $this -> db -> escape ( $computed ) . " ' " : " null " ) . " , " ;
$sql .= " " . $user -> id . " , " ;
$sql .= " " . $user -> id . " , " ;
$sql .= " ' " . $this -> db -> idate ( dol_now ()) . " ', " ;
$sql .= " ' " . $this -> db -> escape ( $enabled ) . " ', " ;
2022-07-09 14:39:20 +02:00
$sql .= " " . ( $help ? " ' " . $this -> db -> escape ( $help ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $css ? " ' " . $this -> db -> escape ( $css ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $csslist ? " ' " . $this -> db -> escape ( $csslist ) . " ' " : " null " ) . " , " ;
$sql .= " " . ( $cssview ? " ' " . $this -> db -> escape ( $cssview ) . " ' " : " null " );
2019-11-13 19:35:39 +01:00
$sql .= " ) " ;
$resql2 = $this -> db -> query ( $sql );
2008-06-01 00:08:59 +02:00
2021-02-23 22:03:23 +01:00
if ( $resql1 && $resql2 ) {
2009-11-07 14:55:15 +01:00
$this -> db -> commit ();
2008-06-01 00:08:59 +02:00
return 1 ;
2020-05-21 15:05:19 +02:00
} else {
2009-11-07 14:55:15 +01:00
$this -> db -> rollback ();
2019-11-26 18:28:44 +01:00
dol_print_error ( $this -> db );
2012-09-22 20:27:06 +02:00
return - 1 ;
2008-06-01 00:08:59 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2008-06-01 00:08:59 +02:00
return 0 ;
}
2003-02-19 18:47:22 +01:00
}
2004-07-28 00:46:33 +02:00
2004-09-25 13:02:10 +02:00
2020-09-08 21:27:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2008-12-18 00:44:04 +01:00
/**
2022-09-02 08:53:13 +02:00
* Load array this -> attributes
2012-02-01 20:44:06 +01:00
*
2020-08-04 12:47:09 +02:00
* @ param string $elementtype Type of element ( '' = all or $object -> table_element like 'adherent' , 'commande' , 'thirdparty' , 'facture' , 'propal' , 'product' , ... ) .
2019-10-06 14:41:52 +02:00
* @ param boolean $forceload Force load of extra fields whatever is status of cache .
2017-06-07 16:44:04 +02:00
* @ return array Array of attributes keys + label for all extra fields .
2008-12-18 00:44:04 +01:00
*/
2019-02-27 20:45:07 +01:00
public function fetch_name_optionals_label ( $elementtype , $forceload = false )
2003-02-19 18:47:22 +01:00
{
2020-09-08 21:27:28 +02:00
// phpcs:enable
2020-03-20 10:05:08 +01:00
global $conf ;
2009-11-07 14:55:15 +01:00
2021-02-23 22:03:23 +01:00
if ( empty ( $elementtype )) {
return array ();
}
2015-04-06 19:46:10 +02:00
2021-02-23 22:03:23 +01:00
if ( $elementtype == 'thirdparty' ) {
$elementtype = 'societe' ;
}
if ( $elementtype == 'contact' ) {
$elementtype = 'socpeople' ;
}
if ( $elementtype == 'order_supplier' ) {
$elementtype = 'commande_fournisseur' ;
}
2015-02-07 17:41:20 +01:00
2019-11-13 19:35:39 +01:00
$array_name_label = array ();
2015-04-06 19:46:10 +02:00
2019-11-10 17:48:50 +01:00
// We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode
2022-06-04 02:08:08 +02:00
$sql = " SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help, " ;
$sql .= " css, cssview, csslist " ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . " extrafields " ;
2019-03-21 11:53:04 +01:00
//$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later
2021-02-23 22:03:23 +01:00
if ( $elementtype ) {
$sql .= " WHERE elementtype = ' " . $this -> db -> escape ( $elementtype ) . " ' " ; // Filed with object->table_element
}
2019-11-13 19:35:39 +01:00
$sql .= " ORDER BY pos " ;
2009-01-27 00:58:37 +01:00
2019-11-13 19:35:39 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2022-09-16 09:31:02 +02:00
$count = 0 ;
2021-02-23 22:03:23 +01:00
if ( $this -> db -> num_rows ( $resql )) {
while ( $tab = $this -> db -> fetch_object ( $resql )) {
if ( $tab -> entity != 0 && $tab -> entity != $conf -> entity ) {
2020-09-08 21:27:28 +02:00
// This field is not in current entity. We discard but before we save it into the array of mandatory fields if it is a mandatory field without default value
2021-02-23 22:03:23 +01:00
if ( $tab -> fieldrequired && is_null ( $tab -> fielddefault )) {
2020-09-08 21:27:28 +02:00
$this -> attributes [ $tab -> elementtype ][ 'mandatoryfieldsofotherentities' ][ $tab -> name ] = $tab -> type ;
}
continue ;
}
2019-03-21 11:53:04 +01:00
2017-06-07 16:44:04 +02:00
// We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label']
2021-02-23 22:03:23 +01:00
if ( $tab -> type != 'separate' ) {
2020-01-30 01:48:28 +01:00
$array_name_label [ $tab -> name ] = $tab -> label ;
2013-03-15 23:39:18 +01:00
}
2017-08-24 13:23:15 +02:00
2020-01-30 01:48:28 +01:00
$this -> attributes [ $tab -> elementtype ][ 'type' ][ $tab -> name ] = $tab -> type ;
$this -> attributes [ $tab -> elementtype ][ 'label' ][ $tab -> name ] = $tab -> label ;
$this -> attributes [ $tab -> elementtype ][ 'size' ][ $tab -> name ] = $tab -> size ;
$this -> attributes [ $tab -> elementtype ][ 'elementtype' ][ $tab -> name ] = $tab -> elementtype ;
$this -> attributes [ $tab -> elementtype ][ 'default' ][ $tab -> name ] = $tab -> fielddefault ;
$this -> attributes [ $tab -> elementtype ][ 'computed' ][ $tab -> name ] = $tab -> fieldcomputed ;
$this -> attributes [ $tab -> elementtype ][ 'unique' ][ $tab -> name ] = $tab -> fieldunique ;
$this -> attributes [ $tab -> elementtype ][ 'required' ][ $tab -> name ] = $tab -> fieldrequired ;
2021-06-30 17:14:19 +02:00
$this -> attributes [ $tab -> elementtype ][ 'param' ][ $tab -> name ] = ( $tab -> param ? jsonOrUnserialize ( $tab -> param ) : '' );
2020-01-30 01:48:28 +01:00
$this -> attributes [ $tab -> elementtype ][ 'pos' ][ $tab -> name ] = $tab -> pos ;
$this -> attributes [ $tab -> elementtype ][ 'alwayseditable' ][ $tab -> name ] = $tab -> alwayseditable ;
2022-07-14 10:56:55 +02:00
$this -> attributes [ $tab -> elementtype ][ 'perms' ][ $tab -> name ] = (( is_null ( $tab -> perms ) || strlen ( $tab -> perms ) == 0 ) ? 1 : $tab -> perms );
2020-01-30 01:48:28 +01:00
$this -> attributes [ $tab -> elementtype ][ 'langfile' ][ $tab -> name ] = $tab -> langs ;
$this -> attributes [ $tab -> elementtype ][ 'list' ][ $tab -> name ] = $tab -> list ;
2020-02-23 23:03:17 +01:00
$this -> attributes [ $tab -> elementtype ][ 'printable' ][ $tab -> name ] = $tab -> printable ;
2020-09-08 21:27:28 +02:00
$this -> attributes [ $tab -> elementtype ][ 'totalizable' ][ $tab -> name ] = ( $tab -> totalizable ? 1 : 0 );
2020-01-30 01:48:28 +01:00
$this -> attributes [ $tab -> elementtype ][ 'entityid' ][ $tab -> name ] = $tab -> entity ;
$this -> attributes [ $tab -> elementtype ][ 'enabled' ][ $tab -> name ] = $tab -> enabled ;
$this -> attributes [ $tab -> elementtype ][ 'help' ][ $tab -> name ] = $tab -> help ;
2022-06-04 02:08:08 +02:00
$this -> attributes [ $tab -> elementtype ][ 'css' ][ $tab -> name ] = $tab -> css ;
$this -> attributes [ $tab -> elementtype ][ 'cssview' ][ $tab -> name ] = $tab -> cssview ;
$this -> attributes [ $tab -> elementtype ][ 'csslist' ][ $tab -> name ] = $tab -> csslist ;
2020-01-30 01:48:28 +01:00
$this -> attributes [ $tab -> elementtype ][ 'loaded' ] = 1 ;
2022-09-16 09:31:02 +02:00
$count ++ ;
2008-06-01 00:08:59 +02:00
}
}
2021-02-23 22:03:23 +01:00
if ( $elementtype ) {
$this -> attributes [ $elementtype ][ 'loaded' ] = 1 ; // If nothing found, we also save tag 'loaded'
2022-09-16 09:31:02 +02:00
$this -> attributes [ $elementtype ][ 'count' ] = $count ;
2021-02-23 22:03:23 +01:00
}
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$this -> error = $this -> db -> lasterror ();
2016-06-29 12:26:01 +02:00
dol_syslog ( get_class ( $this ) . " ::fetch_name_optionals_label " . $this -> error , LOG_ERR );
2008-06-01 00:08:59 +02:00
}
2014-11-17 15:09:52 +01:00
return $array_name_label ;
2008-06-01 00:08:59 +02:00
}
2009-11-07 14:55:15 +01:00
2011-06-22 13:41:37 +02:00
/**
2014-02-16 23:51:29 +01:00
* Return HTML string to put an input field into a page
2017-10-25 11:42:14 +02:00
* Code very similar with showInputField of common object
2012-02-20 10:09:28 +01:00
*
2020-11-10 17:24:17 +01:00
* @ param string $key Key of attribute
* @ param string | array $value Preselected value to show ( for date type it must be in timestamp format , for amount or price it must be a php numeric value ); for dates in filter mode , a range array ( 'start' =>< timestamp > , 'end' =>< timestamp > ) should be provided
2020-11-10 17:29:03 +01:00
* @ param string $moreparam To add more parameters on html input tag
2020-11-10 17:24:17 +01:00
* @ param string $keysuffix Prefix string to add after name and id of field ( can be used to avoid duplicate names )
* @ param string $keyprefix Suffix string to add before name and id of field ( can be used to avoid duplicate names )
* @ param string $morecss More css ( to defined size of field . Old behaviour : may also be a numeric )
* @ param int $objectid Current object id
2022-09-02 08:53:13 +02:00
* @ param string $extrafieldsobjectkey The key to use to store retreived data ( for example $object -> table_element )
2020-11-10 17:24:17 +01:00
* @ param string $mode 1 = Used for search filters
2015-08-24 14:42:07 +02:00
* @ return string
2011-06-22 13:41:37 +02:00
*/
2019-09-24 16:26:15 +02:00
public function showInputField ( $key , $value , $moreparam = '' , $keysuffix = '' , $keyprefix = '' , $morecss = '' , $objectid = 0 , $extrafieldsobjectkey = '' , $mode = 0 )
2011-06-22 13:41:37 +02:00
{
2019-11-13 19:35:39 +01:00
global $conf , $langs , $form ;
2017-10-26 02:55:43 +02:00
2021-02-23 22:03:23 +01:00
if ( ! is_object ( $form )) {
2017-10-26 02:55:43 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/class/html.form.class.php' ;
2019-11-13 19:35:39 +01:00
$form = new Form ( $this -> db );
2017-10-26 02:55:43 +02:00
}
2013-01-18 15:57:11 +01:00
2019-11-13 19:35:39 +01:00
$out = '' ;
2017-11-19 16:55:28 +01:00
2021-02-23 22:03:23 +01:00
if ( ! preg_match ( '/options_$/' , $keyprefix )) { // Because we work on extrafields, we add 'options_' to prefix if not already added
2019-06-19 15:48:04 +02:00
$keyprefix = $keyprefix . 'options_' ;
}
2017-10-25 11:42:14 +02:00
2022-09-02 08:53:13 +02:00
if ( empty ( $extrafieldsobjectkey )) {
dol_syslog ( get_class ( $this ) . '::showInputField extrafieldsobjectkey required' , LOG_ERR );
return 'BadValueForParamExtraFieldsObjectKey' ;
2018-04-17 13:52:50 +02:00
}
2015-03-10 18:33:14 +01:00
2022-09-02 08:53:13 +02:00
$label = $this -> attributes [ $extrafieldsobjectkey ][ 'label' ][ $key ];
$type = $this -> attributes [ $extrafieldsobjectkey ][ 'type' ][ $key ];
$size = $this -> attributes [ $extrafieldsobjectkey ][ 'size' ][ $key ];
$default = $this -> attributes [ $extrafieldsobjectkey ][ 'default' ][ $key ];
$computed = $this -> attributes [ $extrafieldsobjectkey ][ 'computed' ][ $key ];
$unique = $this -> attributes [ $extrafieldsobjectkey ][ 'unique' ][ $key ];
$required = $this -> attributes [ $extrafieldsobjectkey ][ 'required' ][ $key ];
$param = $this -> attributes [ $extrafieldsobjectkey ][ 'param' ][ $key ];
2023-03-20 11:36:28 +01:00
$perms = dol_eval ( $this -> attributes [ $extrafieldsobjectkey ][ 'perms' ][ $key ], 1 , 1 , '2' );
2022-09-02 08:53:13 +02:00
$langfile = $this -> attributes [ $extrafieldsobjectkey ][ 'langfile' ][ $key ];
2023-03-20 11:36:28 +01:00
$list = dol_eval ( $this -> attributes [ $extrafieldsobjectkey ][ 'list' ][ $key ], 1 , 1 , '2' );
2022-09-02 08:53:13 +02:00
$totalizable = $this -> attributes [ $extrafieldsobjectkey ][ 'totalizable' ][ $key ];
$help = $this -> attributes [ $extrafieldsobjectkey ][ 'help' ][ $key ];
$hidden = ( empty ( $list ) ? 1 : 0 ); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
2021-02-23 22:03:23 +01:00
if ( $computed ) {
if ( ! preg_match ( '/^search_/' , $keyprefix )) {
return '<span class="opacitymedium">' . $langs -> trans ( " AutomaticallyCalculated " ) . '</span>' ;
} else {
return '' ;
}
2017-06-10 22:49:16 +02:00
}
2017-06-07 11:38:42 +02:00
2022-07-09 14:39:20 +02:00
//
// 'css' is used in creation and update. 'cssview' is used in view mode. 'csslist' is used for columns in lists. For example: 'css'=>'minwidth300 maxwidth500 widthcentpercentminusx', 'cssview'=>'wordbreak', 'csslist'=>'tdoverflowmax200'
2020-12-23 19:14:47 +01:00
if ( empty ( $morecss )) {
2022-07-09 14:39:20 +02:00
// Add automatic css
2020-12-23 19:14:47 +01:00
if ( $type == 'date' ) {
2018-02-06 10:34:29 +01:00
$morecss = 'minwidth100imp' ;
2023-02-11 00:22:24 +01:00
} elseif ( $type == 'datetime' || $type == 'datetimegmt' || $type == 'link' ) {
2018-02-06 10:34:29 +01:00
$morecss = 'minwidth200imp' ;
2020-12-23 19:14:47 +01:00
} elseif ( in_array ( $type , array ( 'int' , 'integer' , 'double' , 'price' ))) {
2018-02-06 10:34:29 +01:00
$morecss = 'maxwidth75' ;
2020-12-23 19:14:47 +01:00
} elseif ( $type == 'password' ) {
2019-11-13 19:35:39 +01:00
$morecss = 'maxwidth100' ;
2020-12-23 19:14:47 +01:00
} elseif ( $type == 'url' ) {
2019-11-13 19:35:39 +01:00
$morecss = 'minwidth400' ;
2020-12-23 19:14:47 +01:00
} elseif ( $type == 'boolean' ) {
2019-11-13 19:35:39 +01:00
$morecss = '' ;
2022-05-06 12:04:57 +02:00
} elseif ( $type == 'radio' ) {
$morecss = 'width25' ;
2020-05-21 15:05:19 +02:00
} else {
2020-12-23 19:14:47 +01:00
if ( empty ( $size ) || round ( $size ) < 12 ) {
2018-02-06 10:34:29 +01:00
$morecss = 'minwidth100' ;
2020-12-23 19:14:47 +01:00
} elseif ( round ( $size ) <= 48 ) {
2018-02-06 10:34:29 +01:00
$morecss = 'minwidth200' ;
2020-05-21 15:05:19 +02:00
} else {
2018-02-06 10:34:29 +01:00
$morecss = 'minwidth400' ;
2017-10-16 21:05:12 +02:00
}
}
2022-07-09 14:39:20 +02:00
// If css forced in attribute, we use this one
if ( ! empty ( $this -> attributes [ $extrafieldsobjectkey ][ 'css' ][ $key ])) {
$morecss = $this -> attributes [ $extrafieldsobjectkey ][ 'css' ][ $key ];
}
2013-04-21 17:36:23 +02:00
}
2017-06-07 11:38:42 +02:00
2021-03-04 10:31:31 +01:00
if ( in_array ( $type , array ( 'date' ))) {
2019-11-13 19:35:39 +01:00
$tmp = explode ( ',' , $size );
$newsize = $tmp [ 0 ];
2021-03-04 10:31:31 +01:00
$showtime = 0 ;
2014-05-01 16:26:57 +02:00
2018-09-09 10:40:00 +02:00
// Do not show current date when field not required (see selectDate() method)
2021-02-23 22:03:23 +01:00
if ( ! $required && $value == '' ) {
$value = '-1' ;
}
2014-05-01 16:26:57 +02:00
2020-11-10 17:24:17 +01:00
if ( $mode == 1 ) {
// search filter on a date extrafield shows two inputs to select a date range
$prefill = array (
'start' => isset ( $value [ 'start' ]) ? $value [ 'start' ] : '' ,
2021-01-17 15:59:04 +01:00
'end' => isset ( $value [ 'end' ]) ? $value [ 'end' ] : ''
);
2021-03-05 19:29:09 +01:00
$out = '<div ' . ( $moreparam ? $moreparam : '' ) . '><div class="nowrap">' ;
$out .= $form -> selectDate ( $prefill [ 'start' ], $keyprefix . $key . $keysuffix . '_start' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " From " ));
$out .= '</div><div class="nowrap">' ;
$out .= $form -> selectDate ( $prefill [ 'end' ], $keyprefix . $key . $keysuffix . '_end' , 0 , 0 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ));
$out .= '</div></div>' ;
2020-11-10 17:24:17 +01:00
} else {
2020-11-10 17:29:03 +01:00
// TODO Must also support $moreparam
2020-11-10 17:24:17 +01:00
$out = $form -> selectDate ( $value , $keyprefix . $key . $keysuffix , $showtime , $showtime , $required , '' , 1 , (( $keyprefix != 'search_' && $keyprefix != 'search_options_' ) ? 1 : 0 ), 0 , 1 );
}
2023-02-11 00:22:24 +01:00
} elseif ( in_array ( $type , array ( 'datetime' , 'datetimegmt' ))) {
2021-03-04 10:31:31 +01:00
$tmp = explode ( ',' , $size );
$newsize = $tmp [ 0 ];
$showtime = 1 ;
// Do not show current date when field not required (see selectDate() method)
2021-03-05 19:29:09 +01:00
if ( ! $required && $value == '' ) {
$value = '-1' ;
}
2021-03-04 10:31:31 +01:00
2021-03-05 19:29:09 +01:00
if ( $mode == 1 ) {
// search filter on a date extrafield shows two inputs to select a date range
$prefill = array (
'start' => isset ( $value [ 'start' ]) ? $value [ 'start' ] : '' ,
'end' => isset ( $value [ 'end' ]) ? $value [ 'end' ] : ''
);
$out = '<div ' . ( $moreparam ? $moreparam : '' ) . '><div class="nowrap">' ;
$out .= $form -> selectDate ( $prefill [ 'start' ], $keyprefix . $key . $keysuffix . '_start' , 1 , 1 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " From " ), 'tzuserrel' );
$out .= '</div><div class="nowrap">' ;
$out .= $form -> selectDate ( $prefill [ 'end' ], $keyprefix . $key . $keysuffix . '_end' , 1 , 1 , 1 , '' , 1 , 0 , 0 , '' , '' , '' , '' , 1 , '' , $langs -> trans ( " to " ), 'tzuserrel' );
$out .= '</div></div>' ;
} else {
// TODO Must also support $moreparam
$out = $form -> selectDate ( $value , $keyprefix . $key . $keysuffix , $showtime , $showtime , $required , '' , 1 , (( $keyprefix != 'search_' && $keyprefix != 'search_options_' ) ? 1 : 0 ), 0 , 1 , '' , '' , '' , 1 , '' , '' , 'tzuserrel' );
}
} elseif ( in_array ( $type , array ( 'int' , 'integer' ))) {
2019-11-13 19:35:39 +01:00
$tmp = explode ( ',' , $size );
$newsize = $tmp [ 0 ];
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" maxlength="' . $newsize . '" value="' . dol_escape_htmltag ( $value ) . '"' . ( $moreparam ? $moreparam : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
} elseif ( preg_match ( '/varchar/' , $type )) {
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" maxlength="' . $size . '" value="' . dol_escape_htmltag ( $value ) . '"' . ( $moreparam ? $moreparam : '' ) . '>' ;
2022-07-09 12:56:38 +02:00
} elseif ( in_array ( $type , array ( 'mail' , 'ip' , 'phone' , 'url' ))) {
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag ( $value ) . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'text' ) {
if ( ! preg_match ( '/search_/' , $keyprefix )) { // If keyprefix is search_ or search_options_, we must just use a simple text field
2018-02-27 17:30:13 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2019-11-13 19:35:39 +01:00
$doleditor = new DolEditor ( $keyprefix . $key . $keysuffix , $value , '' , 200 , 'dolibarr_notes' , 'In' , false , false , false , ROWS_5 , '90%' );
$out = $doleditor -> Create ( 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag ( $value ) . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2018-02-27 17:30:13 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'html' ) {
if ( ! preg_match ( '/search_/' , $keyprefix )) { // If keyprefix is search_ or search_options_, we must just use a simple text field
2017-12-01 12:55:28 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php' ;
2022-08-31 22:02:31 +02:00
$doleditor = new DolEditor ( $keyprefix . $key . $keysuffix , $value , '' , 200 , 'dolibarr_notes' , 'In' , false , false , isModEnabled ( 'fckeditor' ) && $conf -> global -> FCKEDITOR_ENABLE_SOCIETE , ROWS_5 , '90%' );
2019-11-13 19:35:39 +01:00
$out = $doleditor -> Create ( 1 );
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . dol_escape_htmltag ( $value ) . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2017-12-01 12:55:28 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'boolean' ) {
if ( empty ( $mode )) {
2019-11-13 19:35:39 +01:00
$checked = '' ;
2019-09-24 16:26:15 +02:00
if ( ! empty ( $value )) {
2019-11-13 19:35:39 +01:00
$checked = ' checked value="1" ' ;
2019-09-24 16:26:15 +02:00
} else {
2019-11-13 19:35:39 +01:00
$checked = ' value="1" ' ;
2019-09-24 16:26:15 +02:00
}
2021-08-30 21:48:46 +02:00
$out = '<input type="checkbox" class="flat valignmiddle' . ( $morecss ? ' ' . $morecss : '' ) . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . $checked . ' ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2020-05-21 15:05:19 +02:00
} else {
2019-11-13 19:35:39 +01:00
$out .= $form -> selectyesno ( $keyprefix . $key . $keysuffix , $value , 1 , false , 1 );
2013-04-21 17:36:23 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'price' ) {
2017-10-04 15:17:20 +02:00
if ( ! empty ( $value )) { // $value in memory is a php numeric, we format it into user number format.
2019-11-13 19:35:39 +01:00
$value = price ( $value );
2017-10-04 15:17:20 +02:00
}
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ( $moreparam ? $moreparam : '' ) . '> ' . $langs -> getCurrencySymbol ( $conf -> currency );
2022-09-21 14:59:46 +02:00
} elseif ( $type == 'pricecy' ) {
$currency = $conf -> currency ;
if ( ! empty ( $value )) {
2022-09-21 20:09:52 +02:00
// $value in memory is a php string like '10.01:USD'
2022-09-21 14:59:46 +02:00
$pricetmp = explode ( ':' , $value );
$currency = ! empty ( $pricetmp [ 1 ]) ? $pricetmp [ 1 ] : $conf -> currency ;
$value = price ( $pricetmp [ 0 ]);
}
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ( $moreparam ? $moreparam : '' ) . '> ' ;
$out .= $form -> selectCurrency ( $currency , $keyprefix . $key . $keysuffix . 'currency_id' );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'double' ) {
2017-10-04 15:17:20 +02:00
if ( ! empty ( $value )) { // $value in memory is a php numeric, we format it into user number format.
2019-11-13 19:35:39 +01:00
$value = price ( $value );
2013-06-10 14:13:44 +02:00
}
2019-11-13 19:35:39 +01:00
$out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ( $moreparam ? $moreparam : '' ) . '> ' ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'select' ) {
2014-01-09 02:10:03 +01:00
$out = '' ;
2022-03-15 18:24:49 +01:00
if ( $mode ) {
$options = array ();
foreach ( $param [ 'options' ] as $okey => $val ) {
if (( string ) $okey == '' ) {
continue ;
}
2014-01-09 02:10:03 +01:00
2023-04-04 12:26:59 +02:00
$valarray = explode ( '|' , $val );
$val = $valarray [ 0 ];
2022-03-15 18:24:49 +01:00
if ( $langfile && $val ) {
$options [ $okey ] = $langs -> trans ( $val );
} else {
$options [ $okey ] = $val ;
}
2021-02-23 22:03:23 +01:00
}
2022-03-15 18:24:49 +01:00
$selected = array ();
if ( ! is_array ( $value )) {
$selected = explode ( ',' , $value );
2020-12-29 17:48:52 +01:00
}
2022-03-15 18:24:49 +01:00
$out .= $form -> multiselectarray ( $keyprefix . $key . $keysuffix , $options , $selected , 0 , 0 , $morecss , 0 , 0 , '' , '' , '' , ! empty ( $conf -> use_javascript_ajax ) && empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLE_SELECT2 ));
} else {
if ( ! empty ( $conf -> use_javascript_ajax ) && empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLE_SELECT2 )) {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $keyprefix . $key . $keysuffix , array (), 0 );
2021-02-23 22:03:23 +01:00
}
2022-03-15 18:24:49 +01:00
$out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
$out .= '<option value="0"> </option>' ;
2022-12-31 12:39:42 +01:00
foreach ( $param [ 'options' ] as $key2 => $val2 ) {
if (( string ) $key2 == '' ) {
2022-03-15 18:24:49 +01:00
continue ;
}
2022-12-31 12:39:42 +01:00
$valarray = explode ( '|' , $val2 );
$val2 = $valarray [ 0 ];
2022-03-15 18:24:49 +01:00
$parent = '' ;
if ( ! empty ( $valarray [ 1 ])) {
$parent = $valarray [ 1 ];
}
2022-12-31 12:39:42 +01:00
$out .= '<option value="' . $key2 . '"' ;
$out .= ((( string ) $value == ( string ) $key2 ) ? ' selected' : '' );
2022-03-15 18:24:49 +01:00
$out .= ( ! empty ( $parent ) ? ' parent="' . $parent . '"' : '' );
$out .= '>' ;
2022-12-31 12:39:42 +01:00
if ( $langfile && $val2 ) {
$out .= $langs -> trans ( $val2 );
2022-03-15 18:24:49 +01:00
} else {
2022-12-31 12:39:42 +01:00
$out .= $val2 ;
2022-03-15 18:24:49 +01:00
}
$out .= '</option>' ;
}
$out .= '</select>' ;
2013-04-21 17:36:23 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'sellist' ) {
2014-01-09 02:10:03 +01:00
$out = '' ;
2021-03-15 14:16:55 +01:00
if ( ! empty ( $conf -> use_javascript_ajax ) && empty ( $conf -> global -> MAIN_EXTRAFIELDS_DISABLE_SELECT2 )) {
2019-11-13 19:35:39 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php' ;
$out .= ajax_combobox ( $keyprefix . $key . $keysuffix , array (), 0 );
2014-01-09 02:10:03 +01:00
}
2019-11-13 19:35:39 +01:00
$out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2021-02-23 22:03:23 +01:00
if ( is_array ( $param [ 'options' ])) {
2019-11-13 19:35:39 +01:00
$param_list = array_keys ( $param [ 'options' ]);
2013-07-25 20:18:45 +02:00
$InfoFieldList = explode ( " : " , $param_list [ 0 ]);
2019-11-13 19:35:39 +01:00
$parentName = '' ;
$parentField = '' ;
2013-11-05 13:11:36 +01:00
// 0 : tableName
// 1 : label field name
// 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
2020-09-08 21:27:28 +02:00
// 5 : id category type
// 6 : ids categories list separated by comma for category root
2019-11-13 19:35:39 +01:00
$keyList = ( empty ( $InfoFieldList [ 2 ]) ? 'rowid' : $InfoFieldList [ 2 ] . ' as rowid' );
2013-11-05 13:11:36 +01:00
2016-07-05 15:45:33 +02:00
2021-02-23 22:03:23 +01:00
if ( count ( $InfoFieldList ) > 4 && ! empty ( $InfoFieldList [ 4 ])) {
if ( strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2019-11-13 19:35:39 +01:00
$keyList = 'main.' . $InfoFieldList [ 2 ] . ' as rowid' ;
2013-11-05 13:11:36 +01:00
} else {
2019-11-13 19:35:39 +01:00
$keyList = $InfoFieldList [ 2 ] . ' as rowid' ;
2013-11-04 19:21:13 +01:00
}
}
2021-02-23 22:03:23 +01:00
if ( count ( $InfoFieldList ) > 3 && ! empty ( $InfoFieldList [ 3 ])) {
2016-07-05 15:45:33 +02:00
list ( $parentName , $parentField ) = explode ( '|' , $InfoFieldList [ 3 ]);
2019-11-13 19:35:39 +01:00
$keyList .= ', ' . $parentField ;
2016-07-05 15:45:33 +02:00
}
2013-06-27 13:35:28 +02:00
2020-09-08 21:27:28 +02:00
$filter_categorie = false ;
if ( count ( $InfoFieldList ) > 5 ) {
if ( $InfoFieldList [ 0 ] == 'categorie' ) {
$filter_categorie = true ;
}
}
if ( $filter_categorie === false ) {
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $fields_label )) {
$keyList .= ', ' ;
$keyList .= implode ( ', ' , $fields_label );
}
$sqlwhere = '' ;
2021-09-30 15:59:47 +02:00
$sql = " SELECT " . $keyList ;
2022-01-27 10:19:35 +01:00
$sql .= ' FROM ' . $this -> db -> prefix () . $InfoFieldList [ 0 ];
2020-09-08 21:27:28 +02:00
if ( ! empty ( $InfoFieldList [ 4 ])) {
2022-05-02 14:46:03 +02:00
// can use current entity filter
2020-09-08 21:27:28 +02:00
if ( strpos ( $InfoFieldList [ 4 ], '$ENTITY$' ) !== false ) {
$InfoFieldList [ 4 ] = str_replace ( '$ENTITY$' , $conf -> entity , $InfoFieldList [ 4 ]);
}
// can use SELECT request
if ( strpos ( $InfoFieldList [ 4 ], '$SEL$' ) !== false ) {
$InfoFieldList [ 4 ] = str_replace ( '$SEL$' , 'SELECT' , $InfoFieldList [ 4 ]);
}
// current object id can be use into filter
if ( strpos ( $InfoFieldList [ 4 ], '$ID$' ) !== false && ! empty ( $objectid )) {
$InfoFieldList [ 4 ] = str_replace ( '$ID$' , $objectid , $InfoFieldList [ 4 ]);
} else {
$InfoFieldList [ 4 ] = str_replace ( '$ID$' , '0' , $InfoFieldList [ 4 ]);
}
//We have to join on extrafield table
2023-02-03 13:11:17 +01:00
if ( strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2022-01-27 10:19:35 +01:00
$sql .= ' as main, ' . $this -> db -> prefix () . $InfoFieldList [ 0 ] . '_extrafields as extra' ;
2021-08-28 00:55:51 +02:00
$sqlwhere .= " WHERE extra.fk_object=main. " . $InfoFieldList [ 2 ] . " AND " . $InfoFieldList [ 4 ];
2020-09-08 21:27:28 +02:00
} else {
2021-08-28 00:55:51 +02:00
$sqlwhere .= " WHERE " . $InfoFieldList [ 4 ];
2020-09-08 21:27:28 +02:00
}
} else {
$sqlwhere .= ' WHERE 1=1' ;
}
// Some tables may have field, some other not. For the moment we disable it.
if ( in_array ( $InfoFieldList [ 0 ], array ( 'tablewithentity' ))) {
2021-08-28 00:55:51 +02:00
$sqlwhere .= ' AND entity = ' . (( int ) $conf -> entity );
2020-09-08 21:27:28 +02:00
}
$sql .= $sqlwhere ;
//print $sql;
$sql .= ' ORDER BY ' . implode ( ', ' , $fields_label );
dol_syslog ( get_class ( $this ) . '::showInputField type=sellist' , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$out .= '<option value="0"> </option>' ;
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
while ( $i < $num ) {
$labeltoshow = '' ;
$obj = $this -> db -> fetch_object ( $resql );
2023-04-08 15:08:55 +02:00
// Several field into label (eq table:code|label:rowid)
2020-09-08 21:27:28 +02:00
$notrans = false ;
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $fields_label ) && count ( $fields_label ) > 1 ) {
$notrans = true ;
foreach ( $fields_label as $field_toshow ) {
$labeltoshow .= $obj -> $field_toshow . ' ' ;
}
} else {
$labeltoshow = $obj -> { $InfoFieldList [ 1 ]};
}
2020-09-11 23:31:48 +02:00
$labeltoshow = $labeltoshow ;
2020-09-08 21:27:28 +02:00
if ( $value == $obj -> rowid ) {
if ( ! $notrans ) {
foreach ( $fields_label as $field_toshow ) {
$translabel = $langs -> trans ( $obj -> $field_toshow );
2020-09-11 23:31:48 +02:00
$labeltoshow = $translabel . ' ' ;
2020-09-08 21:27:28 +02:00
}
}
$out .= '<option value="' . $obj -> rowid . '" selected>' . $labeltoshow . '</option>' ;
} else {
if ( ! $notrans ) {
$translabel = $langs -> trans ( $obj -> { $InfoFieldList [ 1 ]});
2020-09-14 04:30:04 +02:00
$labeltoshow = $translabel ;
2020-09-08 21:27:28 +02:00
}
2021-02-23 22:03:23 +01:00
if ( empty ( $labeltoshow )) {
$labeltoshow = '(not defined)' ;
}
2020-09-08 21:27:28 +02:00
if ( ! empty ( $InfoFieldList [ 3 ]) && $parentField ) {
$parent = $parentName . ':' . $obj -> { $parentField };
}
$out .= '<option value="' . $obj -> rowid . '"' ;
$out .= ( $value == $obj -> rowid ? ' selected' : '' );
$out .= ( ! empty ( $parent ) ? ' parent="' . $parent . '"' : '' );
$out .= '>' . $labeltoshow . '</option>' ;
}
$i ++ ;
}
$this -> db -> free ( $resql );
} else {
print 'Error in request ' . $sql . ' ' . $this -> db -> lasterror () . '. Check setup of extra parameters.<br>' ;
}
} else {
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-09-08 21:27:28 +02:00
$data = $form -> select_all_categories ( Categorie :: $MAP_ID_TO_CODE [ $InfoFieldList [ 5 ]], '' , 'parent' , 64 , $InfoFieldList [ 6 ], 1 , 1 );
$out .= '<option value="0"> </option>' ;
2022-06-23 18:00:58 +02:00
if ( is_array ( $data )) {
foreach ( $data as $data_key => $data_value ) {
$out .= '<option value="' . $data_key . '"' ;
$out .= ( $value == $data_key ? ' selected' : '' );
$out .= '>' . $data_value . '</option>' ;
}
2020-09-08 21:27:28 +02:00
}
}
2013-04-21 17:36:23 +02:00
}
2019-11-13 19:35:39 +01:00
$out .= '</select>' ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'checkbox' ) {
2021-04-30 12:20:43 +02:00
$value_arr = $value ;
2021-05-03 16:16:44 +02:00
if ( ! is_array ( $value )) {
2021-04-30 12:20:43 +02:00
$value_arr = explode ( ',' , $value );
}
2019-11-13 19:35:39 +01:00
$out = $form -> multiselectarray ( $keyprefix . $key . $keysuffix , ( empty ( $param [ 'options' ]) ? null : $param [ 'options' ]), $value_arr , '' , 0 , '' , 0 , '100%' );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'radio' ) {
2019-11-13 19:35:39 +01:00
$out = '' ;
2021-02-23 22:03:23 +01:00
foreach ( $param [ 'options' ] as $keyopt => $val ) {
2019-11-13 19:35:39 +01:00
$out .= '<input class="flat ' . $morecss . '" type="radio" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ( $moreparam ? $moreparam : '' );
$out .= ' value="' . $keyopt . '"' ;
$out .= ' id="' . $keyprefix . $key . $keysuffix . '_' . $keyopt . '"' ;
$out .= ( $value == $keyopt ? 'checked' : '' );
2022-05-06 12:04:12 +02:00
$out .= '/><label for="' . $keyprefix . $key . $keysuffix . '_' . $keyopt . '">' . $langs -> trans ( $val ) . '</label><br>' ;
2013-04-21 17:36:23 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'chkbxlst' ) {
2015-05-18 13:13:50 +02:00
if ( is_array ( $value )) {
$value_arr = $value ;
2020-05-21 15:05:19 +02:00
} else {
2015-05-18 13:13:50 +02:00
$value_arr = explode ( ',' , $value );
}
2015-03-10 18:33:14 +01:00
2015-01-18 16:02:31 +01:00
if ( is_array ( $param [ 'options' ])) {
$param_list = array_keys ( $param [ 'options' ]);
$InfoFieldList = explode ( " : " , $param_list [ 0 ]);
2019-11-13 19:35:39 +01:00
$parentName = '' ;
$parentField = '' ;
2015-01-18 16:02:31 +01:00
// 0 : tableName
// 1 : label field name
// 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
2020-09-08 21:27:28 +02:00
// 5 : id category type
// 6 : ids categories list separated by comma for category root
2019-11-13 19:35:39 +01:00
$keyList = ( empty ( $InfoFieldList [ 2 ]) ? 'rowid' : $InfoFieldList [ 2 ] . ' as rowid' );
2015-03-10 18:33:14 +01:00
2019-11-13 19:35:39 +01:00
if ( count ( $InfoFieldList ) > 3 && ! empty ( $InfoFieldList [ 3 ])) {
list ( $parentName , $parentField ) = explode ( '|' , $InfoFieldList [ 3 ]);
$keyList .= ', ' . $parentField ;
2015-01-18 16:02:31 +01:00
}
2019-11-13 19:35:39 +01:00
if ( count ( $InfoFieldList ) > 4 && ! empty ( $InfoFieldList [ 4 ])) {
2015-01-18 16:02:31 +01:00
if ( strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2019-11-13 19:35:39 +01:00
$keyList = 'main.' . $InfoFieldList [ 2 ] . ' as rowid' ;
2015-01-18 16:02:31 +01:00
} else {
2019-11-13 19:35:39 +01:00
$keyList = $InfoFieldList [ 2 ] . ' as rowid' ;
2015-01-18 16:02:31 +01:00
}
}
2015-03-10 18:33:14 +01:00
2020-09-08 21:27:28 +02:00
$filter_categorie = false ;
if ( count ( $InfoFieldList ) > 5 ) {
if ( $InfoFieldList [ 0 ] == 'categorie' ) {
$filter_categorie = true ;
}
}
if ( $filter_categorie === false ) {
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $fields_label )) {
$keyList .= ', ' ;
$keyList .= implode ( ', ' , $fields_label );
}
$sqlwhere = '' ;
2021-09-30 15:59:47 +02:00
$sql = " SELECT " . $keyList ;
2022-01-27 10:19:35 +01:00
$sql .= ' FROM ' . $this -> db -> prefix () . $InfoFieldList [ 0 ];
2020-09-08 21:27:28 +02:00
if ( ! empty ( $InfoFieldList [ 4 ])) {
2022-05-02 14:46:03 +02:00
// can use current entity filter
if ( strpos ( $InfoFieldList [ 4 ], '$ENTITY$' ) !== false ) {
$InfoFieldList [ 4 ] = str_replace ( '$ENTITY$' , $conf -> entity , $InfoFieldList [ 4 ]);
}
2020-09-08 21:27:28 +02:00
// can use SELECT request
if ( strpos ( $InfoFieldList [ 4 ], '$SEL$' ) !== false ) {
$InfoFieldList [ 4 ] = str_replace ( '$SEL$' , 'SELECT' , $InfoFieldList [ 4 ]);
}
// current object id can be use into filter
if ( strpos ( $InfoFieldList [ 4 ], '$ID$' ) !== false && ! empty ( $objectid )) {
$InfoFieldList [ 4 ] = str_replace ( '$ID$' , $objectid , $InfoFieldList [ 4 ]);
} elseif ( preg_match ( " #^.*list.php $ # " , $_SERVER [ " PHP_SELF " ])) {
// Pattern for word=$ID$
$word = '\b[a-zA-Z0-9-\.-_]+\b=\$ID\$' ;
// Removing space arount =, ( and )
$InfoFieldList [ 4 ] = preg_replace ( '# *(=|\(|\)) *#' , '$1' , $InfoFieldList [ 4 ]);
$nbPreg = 1 ;
// While we have parenthesis
while ( $nbPreg != 0 ) {
// Init des compteurs
$nbPregRepl = $nbPregSel = 0 ;
// On retire toutes les parenthèses sans = avant
$InfoFieldList [ 4 ] = preg_replace ( '#([^=])(\([^)^(]*(' . $word . ')[^)^(]*\))#' , '$1 $3 ' , $InfoFieldList [ 4 ], - 1 , $nbPregRepl );
// On retire les espaces autour des = et parenthèses
$InfoFieldList [ 4 ] = preg_replace ( '# *(=|\(|\)) *#' , '$1' , $InfoFieldList [ 4 ]);
// On retire toutes les parenthèses avec = avant
$InfoFieldList [ 4 ] = preg_replace ( '#\b[a-zA-Z0-9-\.-_]+\b=\([^)^(]*(' . $word . ')[^)^(]*\)#' , '$1 ' , $InfoFieldList [ 4 ], - 1 , $nbPregSel );
// On retire les espaces autour des = et parenthèses
$InfoFieldList [ 4 ] = preg_replace ( '# *(=|\(|\)) *#' , '$1' , $InfoFieldList [ 4 ]);
// Calcul du compteur général pour la boucle
$nbPreg = $nbPregRepl + $nbPregSel ;
}
// Si l'on a un AND ou un OR, avant ou après
preg_match ( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' , $InfoFieldList [ 4 ], $matchCondition );
while ( ! empty ( $matchCondition [ 0 ])) {
// If the two sides differ but are not empty
if ( ! empty ( $matchCondition [ 1 ]) && ! empty ( $matchCondition [ 3 ]) && $matchCondition [ 1 ] != $matchCondition [ 3 ]) {
// Nobody sain would do that without parentheses
$InfoFieldList [ 4 ] = str_replace ( '$ID$' , '0' , $InfoFieldList [ 4 ]);
} else {
if ( ! empty ( $matchCondition [ 1 ])) {
$boolCond = (( $matchCondition [ 1 ] == " AND " ) ? ' AND TRUE ' : ' OR FALSE ' );
$InfoFieldList [ 4 ] = str_replace ( $matchCondition [ 0 ], $boolCond . $matchCondition [ 3 ], $InfoFieldList [ 4 ]);
} elseif ( ! empty ( $matchCondition [ 3 ])) {
$boolCond = (( $matchCondition [ 3 ] == " AND " ) ? ' TRUE AND ' : ' FALSE OR' );
$InfoFieldList [ 4 ] = str_replace ( $matchCondition [ 0 ], $boolCond , $InfoFieldList [ 4 ]);
} else {
$InfoFieldList [ 4 ] = " TRUE " ;
}
}
// Si l'on a un AND ou un OR, avant ou après
preg_match ( '#(AND|OR|) *(' . $word . ') *(AND|OR|)#' , $InfoFieldList [ 4 ], $matchCondition );
}
} else {
$InfoFieldList [ 4 ] = str_replace ( '$ID$' , '0' , $InfoFieldList [ 4 ]);
}
// We have to join on extrafield table
if ( strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2022-01-27 10:19:35 +01:00
$sql .= ' as main, ' . $this -> db -> prefix () . $InfoFieldList [ 0 ] . '_extrafields as extra' ;
2021-08-28 00:55:51 +02:00
$sqlwhere .= " WHERE extra.fk_object=main. " . $InfoFieldList [ 2 ] . " AND " . $InfoFieldList [ 4 ];
2020-09-08 21:27:28 +02:00
} else {
2021-08-28 00:55:51 +02:00
$sqlwhere .= " WHERE " . $InfoFieldList [ 4 ];
2020-09-08 21:27:28 +02:00
}
} else {
$sqlwhere .= ' WHERE 1=1' ;
}
// Some tables may have field, some other not. For the moment we disable it.
if ( in_array ( $InfoFieldList [ 0 ], array ( 'tablewithentity' ))) {
2021-08-28 00:55:51 +02:00
$sqlwhere .= " AND entity = " . (( int ) $conf -> entity );
2020-09-08 21:27:28 +02:00
}
// $sql.=preg_replace('/^ AND /','',$sqlwhere);
// print $sql;
$sql .= $sqlwhere ;
dol_syslog ( get_class ( $this ) . '::showInputField type=chkbxlst' , LOG_DEBUG );
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
$i = 0 ;
$data = array ();
while ( $i < $num ) {
$labeltoshow = '' ;
$obj = $this -> db -> fetch_object ( $resql );
$notrans = false ;
2023-04-08 15:08:55 +02:00
// Several field into label (eq table:code|label:rowid)
2020-09-08 21:27:28 +02:00
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $fields_label )) {
$notrans = true ;
foreach ( $fields_label as $field_toshow ) {
$labeltoshow .= $obj -> $field_toshow . ' ' ;
}
} else {
$labeltoshow = $obj -> { $InfoFieldList [ 1 ]};
}
$labeltoshow = dol_trunc ( $labeltoshow , 45 );
if ( is_array ( $value_arr ) && in_array ( $obj -> rowid , $value_arr )) {
2023-01-18 17:36:05 +01:00
$labeltoshow = '' ;
2020-09-08 21:27:28 +02:00
foreach ( $fields_label as $field_toshow ) {
$translabel = $langs -> trans ( $obj -> $field_toshow );
if ( $translabel != $obj -> $field_toshow ) {
2023-01-18 17:36:05 +01:00
$labeltoshow .= ' ' . dol_trunc ( $translabel , 18 ) . ' ' ;
2020-09-08 21:27:28 +02:00
} else {
2023-01-18 17:36:05 +01:00
$labeltoshow .= ' ' . dol_trunc ( $obj -> $field_toshow , 18 ) . ' ' ;
2020-09-08 21:27:28 +02:00
}
}
$data [ $obj -> rowid ] = $labeltoshow ;
} else {
if ( ! $notrans ) {
$translabel = $langs -> trans ( $obj -> { $InfoFieldList [ 1 ]});
if ( $translabel != $obj -> { $InfoFieldList [ 1 ]}) {
$labeltoshow = dol_trunc ( $translabel , 18 );
} else {
$labeltoshow = dol_trunc ( $obj -> { $InfoFieldList [ 1 ]}, 18 );
}
}
2021-02-23 22:03:23 +01:00
if ( empty ( $labeltoshow )) {
2020-09-08 21:27:28 +02:00
$labeltoshow = '(not defined)' ;
2021-02-23 22:03:23 +01:00
}
2020-09-08 21:27:28 +02:00
if ( is_array ( $value_arr ) && in_array ( $obj -> rowid , $value_arr )) {
$data [ $obj -> rowid ] = $labeltoshow ;
}
if ( ! empty ( $InfoFieldList [ 3 ]) && $parentField ) {
$parent = $parentName . ':' . $obj -> { $parentField };
}
$data [ $obj -> rowid ] = $labeltoshow ;
}
$i ++ ;
}
$this -> db -> free ( $resql );
$out = $form -> multiselectarray ( $keyprefix . $key . $keysuffix , $data , $value_arr , '' , 0 , '' , 0 , '100%' );
} else {
print 'Error in request ' . $sql . ' ' . $this -> db -> lasterror () . '. Check setup of extra parameters.<br>' ;
}
} else {
2020-04-10 10:59:32 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-09-08 21:27:28 +02:00
$data = $form -> select_all_categories ( Categorie :: $MAP_ID_TO_CODE [ $InfoFieldList [ 5 ]], '' , 'parent' , 64 , $InfoFieldList [ 6 ], 1 , 1 );
$out = $form -> multiselectarray ( $keyprefix . $key . $keysuffix , $data , $value_arr , '' , 0 , '' , 0 , '100%' );
}
2015-01-18 16:02:31 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'link' ) {
2020-04-10 10:59:32 +02:00
$param_list = array_keys ( $param [ 'options' ]); // $param_list='ObjectName:classPath'
$showempty = (( $required && $default != '' ) ? 0 : 1 );
$out = $form -> selectForForms ( $param_list [ 0 ], $keyprefix . $key . $keysuffix , $value , $showempty , '' , '' , $morecss );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'password' ) {
2017-09-30 18:52:33 +02:00
// If prefix is 'search_', field is used as a filter, we use a common text field.
2020-04-10 10:59:32 +02:00
$out = '<input style="display:none" type="text" name="fakeusernameremembered">' ; // Hidden field to reduce impact of evil Google Chrome autopopulate bug.
$out .= '<input autocomplete="new-password" type="' . ( $keyprefix == 'search_' ? 'text' : 'password' ) . '" class="flat ' . $morecss . '" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ( $moreparam ? $moreparam : '' ) . '>' ;
2016-06-28 10:21:10 +02:00
}
2016-04-20 17:30:40 +02:00
if ( ! empty ( $hidden )) {
2020-04-10 10:59:32 +02:00
$out = '<input type="hidden" value="' . $value . '" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '"/>' ;
2016-04-20 17:30:40 +02:00
}
2013-04-21 17:36:23 +02:00
/* Add comments
if ( $type == 'date' ) $out .= ' (YYYY-MM-DD)' ;
2017-10-16 21:05:12 +02:00
elseif ( $type == 'datetime' ) $out .= ' (YYYY-MM-DD HH:MM:SS)' ;
*/
2022-08-31 22:14:20 +02:00
/* if ( ! empty ( $help ) && $keyprefix != 'search_options_' ) {
2019-10-02 18:14:41 +02:00
$out .= $form -> textwithpicto ( '' , $help , 1 , 'help' , '' , 0 , 3 );
2020-03-26 20:05:17 +01:00
} */
2013-04-21 17:36:23 +02:00
return $out ;
2011-06-22 13:41:37 +02:00
}
2017-10-16 21:05:12 +02:00
2013-04-21 17:36:23 +02:00
/**
* Return HTML string to put an output field into a page
*
2018-01-31 14:01:58 +01:00
* @ param string $key Key of attribute
* @ param string $value Value to show
* @ param string $moreparam To add more parameters on html input tag ( only checkbox use html input for output rendering )
2021-12-06 20:32:44 +01:00
* @ param string $extrafieldsobjectkey Required ( for example $object -> table_element ) .
2018-01-31 14:01:58 +01:00
* @ return string Formated value
2013-04-21 17:36:23 +02:00
*/
2019-02-27 20:45:07 +01:00
public function showOutputField ( $key , $value , $moreparam = '' , $extrafieldsobjectkey = '' )
2013-04-21 17:36:23 +02:00
{
2020-01-30 01:48:28 +01:00
global $conf , $langs ;
2022-09-02 08:53:13 +02:00
if ( empty ( $extrafieldsobjectkey )) {
dol_syslog ( get_class ( $this ) . '::showOutputField extrafieldsobjectkey required' , LOG_ERR );
return 'BadValueForParamExtraFieldsObjectKey' ;
2020-01-30 01:48:28 +01:00
}
2022-09-02 08:53:13 +02:00
$label = $this -> attributes [ $extrafieldsobjectkey ][ 'label' ][ $key ];
$type = $this -> attributes [ $extrafieldsobjectkey ][ 'type' ][ $key ];
$size = $this -> attributes [ $extrafieldsobjectkey ][ 'size' ][ $key ]; // Can be '255', '24,8'...
$default = $this -> attributes [ $extrafieldsobjectkey ][ 'default' ][ $key ];
$computed = $this -> attributes [ $extrafieldsobjectkey ][ 'computed' ][ $key ];
$unique = $this -> attributes [ $extrafieldsobjectkey ][ 'unique' ][ $key ];
$required = $this -> attributes [ $extrafieldsobjectkey ][ 'required' ][ $key ];
$param = $this -> attributes [ $extrafieldsobjectkey ][ 'param' ][ $key ];
2023-03-20 11:36:28 +01:00
$perms = dol_eval ( $this -> attributes [ $extrafieldsobjectkey ][ 'perms' ][ $key ], 1 , 1 , '2' );
2022-09-02 08:53:13 +02:00
$langfile = $this -> attributes [ $extrafieldsobjectkey ][ 'langfile' ][ $key ];
2023-03-20 11:36:28 +01:00
$list = dol_eval ( $this -> attributes [ $extrafieldsobjectkey ][ 'list' ][ $key ], 1 , 1 , '2' );
2022-09-02 08:53:13 +02:00
$help = $this -> attributes [ $extrafieldsobjectkey ][ 'help' ][ $key ];
$hidden = ( empty ( $list ) ? 1 : 0 ); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller)
2021-02-23 22:03:23 +01:00
if ( $hidden ) {
return '' ; // This is a protection. If field is hidden, we should just not call this method.
}
2015-03-10 22:27:16 +01:00
2019-07-11 22:18:44 +02:00
//if ($computed) $value = // $value is already calculated into $value before calling this method
2019-08-21 03:38:57 +02:00
2020-01-30 01:48:28 +01:00
$showsize = 0 ;
2021-02-23 22:03:23 +01:00
if ( $type == 'date' ) {
2020-01-30 01:48:28 +01:00
$showsize = 10 ;
2021-10-22 11:58:00 +02:00
if ( $value !== '' ) {
$value = dol_print_date ( $value , 'day' ); // For date without hour, date is always GMT for storage and output
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'datetime' ) {
2020-01-30 01:48:28 +01:00
$showsize = 19 ;
2021-10-22 11:58:00 +02:00
if ( $value !== '' ) {
$value = dol_print_date ( $value , 'dayhour' , 'tzuserrel' );
}
2023-02-11 00:22:24 +01:00
} elseif ( $type == 'datetimegmt' ) {
$showsize = 19 ;
if ( $value !== '' ) {
$value = dol_print_date ( $value , 'dayhour' , 'gmt' );
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'int' ) {
2020-01-30 01:48:28 +01:00
$showsize = 10 ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'double' ) {
2013-06-10 14:13:44 +02:00
if ( ! empty ( $value )) {
2019-06-28 12:56:31 +02:00
//$value=price($value);
$sizeparts = explode ( " , " , $size );
2022-08-22 16:04:40 +02:00
$number_decimals = array_key_exists ( 1 , $sizeparts ) ? $sizeparts [ 1 ] : 0 ;
2019-11-13 19:35:39 +01:00
$value = price ( $value , 0 , $langs , 0 , 0 , $number_decimals , '' );
2013-06-10 14:13:44 +02:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'boolean' ) {
2019-11-13 19:35:39 +01:00
$checked = '' ;
2013-04-21 17:36:23 +02:00
if ( ! empty ( $value )) {
2019-11-13 19:35:39 +01:00
$checked = ' checked ' ;
2013-04-21 17:36:23 +02:00
}
2019-11-13 19:35:39 +01:00
$value = '<input type="checkbox" ' . $checked . ' ' . ( $moreparam ? $moreparam : '' ) . ' readonly disabled>' ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'mail' ) {
2019-11-13 19:35:39 +01:00
$value = dol_print_email ( $value , 0 , 0 , 0 , 64 , 1 , 1 );
2022-07-09 12:56:38 +02:00
} elseif ( $type == 'ip' ) {
$value = dol_print_ip ( $value , 0 );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'url' ) {
2019-11-13 19:35:39 +01:00
$value = dol_print_url ( $value , '_blank' , 32 , 1 );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'phone' ) {
2019-11-13 19:35:39 +01:00
$value = dol_print_phone ( $value , '' , 0 , 0 , '' , ' ' , 'phone' );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'price' ) {
2020-04-28 14:22:52 +02:00
//$value = price($value, 0, $langs, 0, 0, -1, $conf->currency);
2021-02-23 22:03:23 +01:00
if ( $value || $value == '0' ) {
2022-02-18 10:50:00 +01:00
$value = price ( $value , 0 , $langs , 0 , $conf -> global -> MAIN_MAX_DECIMALS_TOT , - 1 ) . ' ' . $langs -> getCurrencySymbol ( $conf -> currency );
2021-02-23 22:03:23 +01:00
}
2022-09-21 14:59:46 +02:00
} elseif ( $type == 'pricecy' ) {
$currency = $conf -> currency ;
if ( ! empty ( $value )) {
2022-09-21 20:09:52 +02:00
// $value in memory is a php string like '0.01:EUR'
2022-09-21 14:59:46 +02:00
$pricetmp = explode ( ':' , $value );
$currency = ! empty ( $pricetmp [ 1 ]) ? $pricetmp [ 1 ] : $conf -> currency ;
$value = $pricetmp [ 0 ];
}
if ( $value || $value == '0' ) {
$value = price ( $value , 0 , $langs , 0 , $conf -> global -> MAIN_MAX_DECIMALS_TOT , - 1 , $currency );
}
2020-05-28 20:20:39 +02:00
} elseif ( $type == 'select' ) {
2021-03-19 10:05:20 +01:00
$valstr = ( ! empty ( $param [ 'options' ][ $value ]) ? $param [ 'options' ][ $value ] : '' );
2021-02-23 22:03:23 +01:00
if (( $pos = strpos ( $valstr , " | " )) !== false ) {
2020-05-28 16:18:00 +02:00
$valstr = substr ( $valstr , 0 , $pos );
2020-05-28 16:11:02 +02:00
}
2021-02-23 22:03:23 +01:00
if ( $langfile && $valstr ) {
$value = $langs -> trans ( $valstr );
} else {
$value = $valstr ;
}
2020-05-28 20:20:39 +02:00
} elseif ( $type == 'sellist' ) {
2019-11-13 19:35:39 +01:00
$param_list = array_keys ( $param [ 'options' ]);
2013-04-24 23:54:02 +02:00
$InfoFieldList = explode ( " : " , $param_list [ 0 ]);
2013-06-27 13:35:28 +02:00
2019-11-13 19:35:39 +01:00
$selectkey = " rowid " ;
$keyList = 'rowid' ;
2013-06-27 13:35:28 +02:00
2021-02-23 22:03:23 +01:00
if ( count ( $InfoFieldList ) >= 3 ) {
2013-06-27 13:35:28 +02:00
$selectkey = $InfoFieldList [ 2 ];
2019-11-13 19:35:39 +01:00
$keyList = $InfoFieldList [ 2 ] . ' as rowid' ;
2013-06-27 13:35:28 +02:00
}
2013-04-21 17:36:23 +02:00
2019-01-27 11:55:16 +01:00
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
2019-11-13 19:35:39 +01:00
if ( is_array ( $fields_label )) {
$keyList .= ', ' ;
2013-06-27 13:35:28 +02:00
$keyList .= implode ( ', ' , $fields_label );
}
2020-06-22 08:57:52 +02:00
$filter_categorie = false ;
if ( count ( $InfoFieldList ) > 5 ) {
if ( $InfoFieldList [ 0 ] == 'categorie' ) {
$filter_categorie = true ;
}
}
2021-09-30 15:59:47 +02:00
$sql = " SELECT " . $keyList ;
2022-01-27 10:19:35 +01:00
$sql .= ' FROM ' . $this -> db -> prefix () . $InfoFieldList [ 0 ];
2023-02-03 13:11:17 +01:00
if ( ! empty ( $InfoFieldList [ 4 ]) && strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2019-11-13 19:35:39 +01:00
$sql .= ' as main' ;
2013-11-15 15:44:04 +01:00
}
2019-11-13 19:35:39 +01:00
if ( $selectkey == 'rowid' && empty ( $value )) {
2021-06-09 15:36:47 +02:00
$sql .= " WHERE " . $selectkey . " = 0 " ;
2019-11-13 19:35:39 +01:00
} elseif ( $selectkey == 'rowid' ) {
2021-06-09 15:36:47 +02:00
$sql .= " WHERE " . $selectkey . " = " . (( int ) $value );
2019-11-13 19:35:39 +01:00
} else {
2021-06-09 15:36:47 +02:00
$sql .= " WHERE " . $selectkey . " = ' " . $this -> db -> escape ( $value ) . " ' " ;
2016-08-16 08:54:12 +02:00
}
2013-04-25 00:14:43 +02:00
//$sql.= ' AND entity = '.$conf->entity;
2014-02-04 20:49:07 +01:00
2014-06-13 01:34:39 +02:00
dol_syslog ( get_class ( $this ) . ':showOutputField:$type=sellist' , LOG_DEBUG );
2013-04-21 17:36:23 +02:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) {
2020-06-22 08:57:52 +02:00
if ( $filter_categorie === false ) {
$value = '' ; // value was used, so now we reste it to use it to build final output
2014-02-04 20:49:07 +01:00
2020-06-22 08:57:52 +02:00
$obj = $this -> db -> fetch_object ( $resql );
2013-06-10 14:13:44 +02:00
2023-04-08 15:08:55 +02:00
// Several field into label (eq table:code|label:rowid)
2020-06-22 08:57:52 +02:00
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
2014-02-04 20:49:07 +01:00
2020-06-22 08:57:52 +02:00
if ( is_array ( $fields_label ) && count ( $fields_label ) > 1 ) {
foreach ( $fields_label as $field_toshow ) {
$translabel = '' ;
if ( ! empty ( $obj -> $field_toshow )) {
$translabel = $langs -> trans ( $obj -> $field_toshow );
}
2022-09-15 16:47:39 +02:00
if ( $translabel != $obj -> $field_toshow ) {
$value .= dol_trunc ( $translabel , 24 ) . ' ' ;
2020-06-22 08:57:52 +02:00
} else {
2020-09-08 21:27:28 +02:00
$value .= $obj -> $field_toshow . ' ' ;
2020-06-22 08:57:52 +02:00
}
}
} else {
2019-11-13 19:35:39 +01:00
$translabel = '' ;
2022-06-07 09:57:15 +02:00
$tmppropname = $InfoFieldList [ 1 ];
//$obj->$tmppropname = '';
if ( ! empty ( isset ( $obj -> $tmppropname ) ? $obj -> $tmppropname : '' )) {
$translabel = $langs -> trans ( $obj -> $tmppropname );
2014-10-27 19:38:27 +01:00
}
2022-06-07 09:57:15 +02:00
if ( $translabel != ( isset ( $obj -> $tmppropname ) ? $obj -> $tmppropname : '' )) {
2020-06-22 08:57:52 +02:00
$value = dol_trunc ( $translabel , 18 );
2019-11-13 19:35:39 +01:00
} else {
2022-06-07 09:57:15 +02:00
$value = isset ( $obj -> $tmppropname ) ? $obj -> $tmppropname : '' ;
2013-06-27 13:35:28 +02:00
}
}
2020-05-21 15:05:19 +02:00
} else {
2020-06-22 08:57:52 +02:00
$toprint = array ();
$obj = $this -> db -> fetch_object ( $resql );
2022-05-25 18:02:18 +02:00
if ( $obj -> rowid ) {
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
$c = new Categorie ( $this -> db );
$result = $c -> fetch ( $obj -> rowid );
if ( $result > 0 ) {
$ways = $c -> print_all_ways (); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
foreach ( $ways as $way ) {
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ( $c -> color ? ' style="background: #' . $c -> color . ';"' : ' style="background: #bbb"' ) . '>' . img_object ( '' , 'category' ) . ' ' . $way . '</li>' ;
}
}
2013-06-27 13:35:28 +02:00
}
2020-06-22 08:57:52 +02:00
$value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2013-06-27 13:35:28 +02:00
}
2021-02-23 22:03:23 +01:00
} else {
dol_syslog ( get_class ( $this ) . '::showOutputField error ' . $this -> db -> lasterror (), LOG_WARNING );
}
} elseif ( $type == 'radio' ) {
2022-11-29 20:44:44 +01:00
if ( ! isset ( $param [ 'options' ][ $value ])) {
2022-11-30 10:44:10 +01:00
$langs -> load ( 'errors' );
2022-11-29 20:35:43 +01:00
$value = $langs -> trans ( 'ErrorNoValueForRadioType' );
} else {
$value = $langs -> trans ( $param [ 'options' ][ $value ]);
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'checkbox' ) {
2019-11-13 19:35:39 +01:00
$value_arr = explode ( ',' , $value );
$value = '' ;
$toprint = array ();
2021-02-23 22:03:23 +01:00
if ( is_array ( $value_arr )) {
foreach ( $value_arr as $keyval => $valueval ) {
2022-06-14 18:11:19 +02:00
if ( ! empty ( $valueval )) {
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $param [ 'options' ][ $valueval ] . '</li>' ;
}
2013-04-21 17:36:23 +02:00
}
}
2019-11-13 19:35:39 +01:00
$value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'chkbxlst' ) {
2015-01-18 16:02:31 +01:00
$value_arr = explode ( ',' , $value );
2015-03-10 18:33:14 +01:00
2017-10-26 02:55:43 +02:00
$param_list = array_keys ( $param [ 'options' ]);
2015-01-18 16:02:31 +01:00
$InfoFieldList = explode ( " : " , $param_list [ 0 ]);
2015-03-10 18:33:14 +01:00
2015-01-18 16:02:31 +01:00
$selectkey = " rowid " ;
$keyList = 'rowid' ;
2015-03-10 18:33:14 +01:00
2015-01-18 16:02:31 +01:00
if ( count ( $InfoFieldList ) >= 3 ) {
$selectkey = $InfoFieldList [ 2 ];
2019-11-13 19:35:39 +01:00
$keyList = $InfoFieldList [ 2 ] . ' as rowid' ;
2015-01-18 16:02:31 +01:00
}
2015-03-10 18:33:14 +01:00
2015-01-18 16:02:31 +01:00
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $fields_label )) {
$keyList .= ', ' ;
$keyList .= implode ( ', ' , $fields_label );
}
2015-03-10 18:33:14 +01:00
2020-06-22 08:57:52 +02:00
$filter_categorie = false ;
if ( count ( $InfoFieldList ) > 5 ) {
if ( $InfoFieldList [ 0 ] == 'categorie' ) {
$filter_categorie = true ;
}
}
2021-09-30 15:59:47 +02:00
$sql = " SELECT " . $keyList ;
2022-01-27 10:19:35 +01:00
$sql .= " FROM " . $this -> db -> prefix () . $InfoFieldList [ 0 ];
2023-02-03 13:11:17 +01:00
if ( strpos ( $InfoFieldList [ 4 ], 'extra.' ) !== false ) {
2015-01-18 16:02:31 +01:00
$sql .= ' as main' ;
}
// $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
// $sql.= ' AND entity = '.$conf->entity;
2015-03-10 18:33:14 +01:00
2020-01-30 01:48:28 +01:00
dol_syslog ( get_class ( $this ) . ':showOutputField:$type=chkbxlst' , LOG_DEBUG );
2015-01-18 16:02:31 +01:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
2020-06-22 08:57:52 +02:00
if ( $filter_categorie === false ) {
$value = '' ; // value was used, so now we reste it to use it to build final output
$toprint = array ();
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2023-04-08 15:08:55 +02:00
// Several field into label (eq table:code|label:rowid)
2020-06-22 08:57:52 +02:00
$fields_label = explode ( '|' , $InfoFieldList [ 1 ]);
if ( is_array ( $value_arr ) && in_array ( $obj -> rowid , $value_arr )) {
if ( is_array ( $fields_label ) && count ( $fields_label ) > 1 ) {
2023-01-18 17:36:05 +01:00
$label = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' ;
2020-06-22 08:57:52 +02:00
foreach ( $fields_label as $field_toshow ) {
$translabel = '' ;
if ( ! empty ( $obj -> $field_toshow )) {
$translabel = $langs -> trans ( $obj -> $field_toshow );
}
if ( $translabel != $field_toshow ) {
2023-01-18 17:36:05 +01:00
$label .= ' ' . dol_trunc ( $translabel , 18 );
2020-06-22 08:57:52 +02:00
} else {
2023-01-18 17:36:05 +01:00
$label .= ' ' . $obj -> $field_toshow ;
2020-06-22 08:57:52 +02:00
}
}
2023-01-18 17:36:05 +01:00
$label .= '</li>' ;
$toprint [] = $label ;
2020-06-22 08:57:52 +02:00
} else {
2015-01-18 16:02:31 +01:00
$translabel = '' ;
2020-06-22 08:57:52 +02:00
if ( ! empty ( $obj -> { $InfoFieldList [ 1 ]})) {
$translabel = $langs -> trans ( $obj -> { $InfoFieldList [ 1 ]});
2015-01-18 16:02:31 +01:00
}
2020-06-22 08:57:52 +02:00
if ( $translabel != $obj -> { $InfoFieldList [ 1 ]}) {
2020-11-23 19:53:58 +01:00
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . dol_trunc ( $translabel , 18 ) . '</li>' ;
2015-01-18 16:02:31 +01:00
} else {
2020-11-23 19:53:58 +01:00
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb">' . $obj -> { $InfoFieldList [ 1 ]} . '</li>' ;
2015-01-18 16:02:31 +01:00
}
}
2020-06-22 08:57:52 +02:00
}
}
} else {
2020-09-08 21:27:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
2020-06-22 08:57:52 +02:00
$toprint = array ();
while ( $obj = $this -> db -> fetch_object ( $resql )) {
if ( is_array ( $value_arr ) && in_array ( $obj -> rowid , $value_arr )) {
$c = new Categorie ( $this -> db );
$c -> fetch ( $obj -> rowid );
$ways = $c -> print_all_ways (); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formatted text
foreach ( $ways as $way ) {
2020-11-23 19:53:58 +01:00
$toprint [] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ( $c -> color ? ' style="background: #' . $c -> color . ';"' : ' style="background: #bbb"' ) . '>' . img_object ( '' , 'category' ) . ' ' . $way . '</li>' ;
2015-01-18 16:02:31 +01:00
}
}
}
}
2022-07-11 11:55:39 +02:00
if ( ! empty ( $toprint )) $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode ( ' ' , $toprint ) . '</ul></div>' ;
2017-02-03 09:25:26 +01:00
} else {
2019-11-13 19:35:39 +01:00
dol_syslog ( get_class ( $this ) . '::showOutputField error ' . $this -> db -> lasterror (), LOG_WARNING );
2017-02-03 09:25:26 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'link' ) {
2019-11-13 19:35:39 +01:00
$out = '' ;
2018-01-31 14:01:58 +01:00
2018-02-01 19:03:21 +01:00
// Only if something to display (perf)
2021-02-23 22:03:23 +01:00
if ( $value ) { // If we have -1 here, pb is into insert, not into ouptut (fix insert instead of changing code here to compensate)
2019-11-13 19:35:39 +01:00
$param_list = array_keys ( $param [ 'options' ]); // $param_list='ObjectName:classPath'
2017-10-26 02:55:43 +02:00
2015-03-18 13:23:14 +01:00
$InfoFieldList = explode ( " : " , $param_list [ 0 ]);
2019-11-13 19:35:39 +01:00
$classname = $InfoFieldList [ 0 ];
$classpath = $InfoFieldList [ 1 ];
2021-02-23 22:03:23 +01:00
if ( ! empty ( $classpath )) {
2017-10-26 02:55:43 +02:00
dol_include_once ( $InfoFieldList [ 1 ]);
2021-02-23 22:03:23 +01:00
if ( $classname && class_exists ( $classname )) {
2017-10-26 02:55:43 +02:00
$object = new $classname ( $this -> db );
$object -> fetch ( $value );
2019-11-13 19:35:39 +01:00
$value = $object -> getNomUrl ( 3 );
2017-10-26 02:55:43 +02:00
}
2020-05-21 15:05:19 +02:00
} else {
2017-10-26 02:55:43 +02:00
dol_syslog ( 'Error bad setup of extrafield' , LOG_WARNING );
return 'Error bad setup of extrafield' ;
}
2015-03-14 12:31:22 +01:00
}
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'text' ) {
2019-11-13 19:35:39 +01:00
$value = dol_htmlentitiesbr ( $value );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'html' ) {
2019-11-13 19:35:39 +01:00
$value = dol_htmlentitiesbr ( $value );
2021-02-23 22:03:23 +01:00
} elseif ( $type == 'password' ) {
2019-11-13 19:35:39 +01:00
$value = dol_trunc ( preg_replace ( '/./i' , '*' , $value ), 8 , 'right' , 'UTF-8' , 1 );
2020-05-21 15:05:19 +02:00
} else {
2021-06-16 14:31:22 +02:00
$showsize = round (( float ) $size );
2021-02-23 22:03:23 +01:00
if ( $showsize > 48 ) {
$showsize = 48 ;
}
2013-04-21 17:36:23 +02:00
}
2016-04-20 17:30:40 +02:00
2013-04-21 17:36:23 +02:00
//print $type.'-'.$size;
2019-11-13 19:35:39 +01:00
$out = $value ;
2016-04-20 17:30:40 +02:00
2013-04-21 17:36:23 +02:00
return $out ;
}
2015-10-29 22:12:11 +01:00
/**
2022-06-04 02:08:08 +02:00
* Return the CSS to use for this extrafield into list
2015-10-29 22:12:11 +01:00
*
2018-01-31 14:01:58 +01:00
* @ param string $key Key of attribute
* @ param string $extrafieldsobjectkey If defined , use the new method to get extrafields data
* @ return string Formated value
2015-10-29 22:12:11 +01:00
*/
2019-02-27 20:45:07 +01:00
public function getAlignFlag ( $key , $extrafieldsobjectkey = '' )
2015-10-29 22:12:11 +01:00
{
2019-11-13 19:35:39 +01:00
global $conf , $langs ;
2015-10-29 22:12:11 +01:00
2022-09-05 18:31:48 +02:00
$type = 'varchar' ;
2021-02-23 22:03:23 +01:00
if ( ! empty ( $extrafieldsobjectkey )) {
$type = $this -> attributes [ $extrafieldsobjectkey ][ 'type' ][ $key ];
}
2015-10-29 22:12:11 +01:00
2022-06-04 02:08:08 +02:00
$cssstring = '' ;
2016-04-20 17:30:40 +02:00
2023-02-11 00:22:24 +01:00
if ( in_array ( $type , array ( 'date' , 'datetime' , 'datetimegmt' ))) {
2022-06-04 02:08:08 +02:00
$cssstring = " center " ;
2022-09-05 18:31:48 +02:00
} elseif ( in_array ( $type , array ( 'int' , 'price' , 'double' ))) {
2022-06-04 02:08:08 +02:00
$cssstring = " right " ;
2022-09-05 18:31:48 +02:00
} elseif ( in_array ( $type , array ( 'boolean' , 'radio' , 'checkbox' , 'ip' ))) {
2022-06-04 02:08:08 +02:00
$cssstring = " center " ;
2018-07-26 09:41:44 +02:00
}
2016-04-20 17:30:40 +02:00
2022-06-04 02:08:08 +02:00
if ( ! empty ( $this -> attributes [ $extrafieldsobjectkey ][ 'csslist' ][ $key ])) {
$cssstring .= ( $cssstring ? ' ' : '' ) . $this -> attributes [ $extrafieldsobjectkey ][ 'csslist' ][ $key ];
2022-09-05 18:31:48 +02:00
} else {
if ( in_array ( $type , array ( 'ip' ))) {
$cssstring .= ( $cssstring ? ' ' : '' ) . 'tdoverflowmax150' ;
}
2022-06-04 02:08:08 +02:00
}
return $cssstring ;
2015-10-29 22:12:11 +01:00
}
2016-04-20 17:30:40 +02:00
2013-04-21 17:36:23 +02:00
/**
* Return HTML string to print separator extrafield
*
* @ param string $key Key of attribute
2022-11-09 19:13:44 +01:00
* @ param object $object Object
2019-11-16 14:38:05 +01:00
* @ param int $colspan Value of colspan to use ( it must includes the first column with title )
2021-01-04 20:00:57 +01:00
* @ param string $display_type " card " for form display , " line " for document line display ( extrafields on propal line , order line , etc ... )
2022-03-30 18:20:09 +02:00
* @ param string $mode Show output ( 'view' ) or input ( 'create' or 'edit' ) for extrafield
2018-04-13 10:48:29 +02:00
* @ return string HTML code with line for separator
2013-04-21 17:36:23 +02:00
*/
2022-03-30 18:20:09 +02:00
public function showSeparator ( $key , $object , $colspan = 2 , $display_type = 'card' , $mode = '' )
2013-04-21 17:36:23 +02:00
{
2021-09-10 20:49:22 +02:00
global $conf , $langs ;
2018-04-13 10:48:29 +02:00
2021-10-21 17:09:48 +02:00
$tagtype = 'tr' ;
$tagtype_dyn = 'td' ;
if ( $display_type == 'line' ) {
2020-12-22 12:52:01 +01:00
$tagtype = 'div' ;
$tagtype_dyn = 'span' ;
2021-01-04 20:00:57 +01:00
$colspan = 0 ;
2020-12-22 12:52:01 +01:00
}
2022-02-24 12:54:33 +01:00
$extrafield_param = $this -> attributes [ $object -> table_element ][ 'param' ][ $key ];
$extrafield_param_list = array ();
if ( ! empty ( $extrafield_param ) && is_array ( $extrafield_param )) {
$extrafield_param_list = array_keys ( $extrafield_param [ 'options' ]);
}
2023-02-04 14:59:44 +01:00
// Set $extrafield_collapse_display_value (do we have to collapse/expand the group after the separator)
2022-02-24 12:54:33 +01:00
$extrafield_collapse_display_value = - 1 ;
$expand_display = false ;
if ( is_array ( $extrafield_param_list ) && count ( $extrafield_param_list ) > 0 ) {
$extrafield_collapse_display_value = intval ( $extrafield_param_list [ 0 ]);
2022-12-08 18:57:58 +01:00
$expand_display = (( isset ( $_COOKIE [ 'DOLCOLLAPSE_' . $object -> table_element . '_extrafields_' . $key ]) || GETPOST ( 'ignorecollapsesetup' , 'int' )) ? ( empty ( $_COOKIE [ 'DOLCOLLAPSE_' . $object -> table_element . '_extrafields_' . $key ]) ? false : true ) : ( $extrafield_collapse_display_value == 2 ? false : true ));
2022-02-24 12:54:33 +01:00
}
2023-02-05 22:17:09 +01:00
$disabledcookiewrite = 0 ;
2022-03-30 18:20:09 +02:00
if ( $mode == 'create' ) {
2023-02-05 22:17:09 +01:00
// On create mode, force separator group to not be collapsable
$extrafield_collapse_display_value = 1 ;
$expand_display = true ; // We force group to be shown expanded
$disabledcookiewrite = 1 ; // We keep status of group unchanged into the cookie
2022-03-30 18:20:09 +02:00
}
2022-02-24 12:54:33 +01:00
2020-12-22 12:52:01 +01:00
$out = '<' . $tagtype . ' id="trextrafieldseparator' . $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' ) . '" class="trextrafieldseparator trextrafieldseparator' . $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' ) . '">' ;
$out .= '<' . $tagtype_dyn . ' ' . ( ! empty ( $colspan ) ? 'colspan="' . $colspan . '"' : '' ) . '>' ;
2021-09-10 20:49:22 +02:00
// Some js code will be injected here to manage the collapsing of extrafields
2022-03-30 18:20:09 +02:00
// Output the picto
2023-02-04 14:59:44 +01:00
$out .= '<span class="' . ( $extrafield_collapse_display_value ? 'cursorpointer ' : '' ) . ( $extrafield_collapse_display_value == 0 ? 'fas fa-square opacitymedium' : 'far fa-' . (( $expand_display ? 'minus' : 'plus' ) . '-square' )) . '"></span>' ;
2022-03-30 18:20:09 +02:00
$out .= ' ' ;
2022-02-24 12:54:33 +01:00
$out .= '<strong>' ;
2019-11-13 19:35:39 +01:00
$out .= $langs -> trans ( $this -> attributes [ $object -> table_element ][ 'label' ][ $key ]);
2020-12-22 12:52:01 +01:00
$out .= '</strong>' ;
$out .= '</' . $tagtype_dyn . '>' ;
$out .= '</' . $tagtype . '>' ;
2019-05-03 16:14:44 +02:00
2022-03-01 04:02:06 +01:00
$collapse_group = $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' );
//$extrafields_collapse_num = $this->attributes[$object->table_element]['pos'][$key].(!empty($object->id)?'_'.$object->id:'');
2022-02-24 12:54:33 +01:00
if ( $extrafield_collapse_display_value == 1 || $extrafield_collapse_display_value == 2 ) {
// Set the collapse_display status to cookie in priority or if ignorecollapsesetup is 1, if cookie and ignorecollapsesetup not defined, use the setup.
2022-03-01 04:02:06 +01:00
$this -> expand_display [ $collapse_group ] = $expand_display ;
2022-02-24 12:54:33 +01:00
2023-02-05 22:17:09 +01:00
if ( ! empty ( $conf -> use_javascript_ajax )) {
2022-02-24 12:54:33 +01:00
$out .= '<!-- Add js script to manage the collapse/uncollapse of extrafields separators ' . $key . ' -->' . " \n " ;
2023-02-18 15:10:05 +01:00
$out .= '<script nonce="' . getNonce () . '" type="text/javascript">' . " \n " ;
2022-02-24 12:54:33 +01:00
$out .= 'jQuery(document).ready(function(){' . " \n " ;
2023-02-05 22:17:09 +01:00
if ( empty ( $disabledcookiewrite )) {
if ( $expand_display === false ) {
$out .= ' console.log("Inject js for the collapsing of extrafield ' . $key . ' - hide");' . " \n " ;
$out .= ' jQuery(".trextrafields_collapse' . $collapse_group . '").hide();' . " \n " ;
} else {
$out .= ' console.log("Inject js for collapsing of extrafield ' . $key . ' - keep visible and set cookie");' . " \n " ;
$out .= ' document.cookie = "DOLCOLLAPSE_' . $object -> table_element . '_extrafields_' . $key . '=1; path=' . $_SERVER [ " PHP_SELF " ] . '"' . " \n " ;
}
2020-09-08 21:27:28 +02:00
}
2022-02-24 12:54:33 +01:00
$out .= ' jQuery("#trextrafieldseparator' . $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' ) . '").click(function(){' . " \n " ;
2023-02-05 22:17:09 +01:00
$out .= ' console.log("We click on collapse/uncollapse to hide/show .trextrafields_collapse' . $collapse_group . '");' . " \n " ;
2022-03-01 04:02:06 +01:00
$out .= ' jQuery(".trextrafields_collapse' . $collapse_group . '").toggle(100, function(){' . " \n " ;
$out .= ' if (jQuery(".trextrafields_collapse' . $collapse_group . '").is(":hidden")) {' . " \n " ;
2022-02-24 12:54:33 +01:00
$out .= ' jQuery("#trextrafieldseparator' . $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' ) . ' ' . $tagtype_dyn . ' span").addClass("fa-plus-square").removeClass("fa-minus-square");' . " \n " ;
$out .= ' document.cookie = "DOLCOLLAPSE_' . $object -> table_element . '_extrafields_' . $key . '=0; path=' . $_SERVER [ " PHP_SELF " ] . '"' . " \n " ;
$out .= ' } else {' . " \n " ;
$out .= ' jQuery("#trextrafieldseparator' . $key . ( ! empty ( $object -> id ) ? '_' . $object -> id : '' ) . ' ' . $tagtype_dyn . ' span").addClass("fa-minus-square").removeClass("fa-plus-square");' . " \n " ;
$out .= ' document.cookie = "DOLCOLLAPSE_' . $object -> table_element . '_extrafields_' . $key . '=1; path=' . $_SERVER [ " PHP_SELF " ] . '"' . " \n " ;
$out .= ' }' . " \n " ;
$out .= ' });' . " \n " ;
$out .= ' });' . " \n " ;
$out .= '});' . " \n " ;
$out .= '</script>' . " \n " ;
2020-09-08 21:27:28 +02:00
}
2022-03-01 04:02:06 +01:00
} else {
$this -> expand_display [ $collapse_group ] = 1 ;
2020-09-08 21:27:28 +02:00
}
2019-05-03 16:14:44 +02:00
2013-04-21 17:36:23 +02:00
return $out ;
}
/**
2013-11-05 13:11:36 +01:00
* Fill array_options property of object by extrafields value ( using for data sent by forms )
2013-04-21 17:36:23 +02:00
*
2022-12-28 11:41:59 +01:00
* @ param array | null $extralabels Deprecated ( old $array of extrafields , now set this to null )
* @ param object $object Object
* @ param string $onlykey Only some keys are filled :
* 'string' => When we make update of only one extrafield ( $action = 'update_extras' ), calling page can set this to avoid to have other extrafields being reset .
* '@GETPOSTISSET' => When we make update of several extrafields ( $action = 'update' ), calling page can set this to avoid to have fields not into POST being reset .
* @ param int $todefaultifmissing 1 = Set value to the default value in database if value is mandatory and missing
* @ return int 1 if array_options set , 0 if no value , - 1 if error ( field required missing for example )
2013-04-21 17:36:23 +02:00
*/
2022-05-16 13:57:11 +02:00
public function setOptionalsFromPost ( $extralabels , & $object , $onlykey = '' , $todefaultifmissing = 0 )
2013-04-21 17:36:23 +02:00
{
2013-07-26 10:46:45 +02:00
global $_POST , $langs ;
2019-10-06 14:41:52 +02:00
2019-11-13 19:35:39 +01:00
$nofillrequired = 0 ; // For error when required field left blank
2013-07-26 10:46:45 +02:00
$error_field_required = array ();
2013-06-10 14:13:44 +02:00
2021-03-17 15:14:43 +01:00
if ( isset ( $this -> attributes [ $object -> table_element ][ 'label' ]) && is_array ( $this -> attributes [ $object -> table_element ][ 'label' ])) {
2021-02-23 22:03:23 +01:00
$extralabels = $this -> attributes [ $object -> table_element ][ 'label' ];
}
2018-04-12 23:16:23 +02:00
2021-02-23 22:03:23 +01:00
if ( is_array ( $extralabels )) {
2013-04-21 17:36:23 +02:00
// Get extra fields
2021-02-23 22:03:23 +01:00
foreach ( $extralabels as $key => $value ) {
if ( ! empty ( $onlykey ) && $onlykey != '@GETPOSTISSET' && $key != $onlykey ) {
continue ;
}
2022-01-14 10:12:30 +01:00
2022-01-14 10:10:10 +01:00
if ( ! empty ( $onlykey ) && $onlykey == '@GETPOSTISSET' && ! GETPOSTISSET ( 'options_' . $key ) && ( ! in_array ( $this -> attributes [ $object -> table_element ][ 'type' ][ $key ], array ( 'boolean' , 'chkbxlst' )))) {
2021-12-08 18:27:03 +01:00
//when unticking boolean field, it's not set in POST
2021-02-23 22:03:23 +01:00
continue ;
}
2013-11-05 13:11:36 +01:00
2018-04-12 23:16:23 +02:00
$key_type = $this -> attributes [ $object -> table_element ][ 'type' ][ $key ];
2021-02-23 22:03:23 +01:00
if ( $key_type == 'separate' ) {
continue ;
}
2018-04-12 23:16:23 +02:00
$enabled = 1 ;
2021-10-17 18:58:34 +02:00
if ( isset ( $this -> attributes [ $object -> table_element ][ 'enabled' ][ $key ])) { // 'enabled' is often a condition on module enabled or not
2023-03-20 11:36:28 +01:00
$enabled = dol_eval ( $this -> attributes [ $object -> table_element ][ 'enabled' ][ $key ], 1 , 1 , '2' );
2018-04-12 23:16:23 +02:00
}
2021-10-17 18:58:34 +02:00
$visibility = 1 ;
if ( isset ( $this -> attributes [ $object -> table_element ][ 'list' ][ $key ])) { // 'list' is option for visibility
2023-03-20 11:36:28 +01:00
$visibility = intval ( dol_eval ( $this -> attributes [ $object -> table_element ][ 'list' ][ $key ], 1 , 1 , '2' ));
2021-10-17 18:58:34 +02:00
}
2018-04-12 23:16:23 +02:00
$perms = 1 ;
2021-02-23 22:03:23 +01:00
if ( isset ( $this -> attributes [ $object -> table_element ][ 'perms' ][ $key ])) {
2023-03-20 11:36:28 +01:00
$perms = dol_eval ( $this -> attributes [ $object -> table_element ][ 'perms' ][ $key ], 1 , 1 , '2' );
2018-04-12 23:16:23 +02:00
}
2022-10-29 12:46:22 +02:00
if ( empty ( $enabled )
2022-10-18 10:50:21 +02:00
|| (
$onlykey === '@GETPOSTISSET'
&& in_array ( $this -> attributes [ $object -> table_element ][ 'type' ][ $key ], array ( 'boolean' , 'chkbxlst' ))
&& in_array ( abs ( $enabled ), array ( 2 , 5 ))
&& ! GETPOSTISSET ( 'options_' . $key ) // Update hidden checkboxes and multiselect only if they are provided
)
) {
2021-02-23 22:03:23 +01:00
continue ;
}
2023-02-13 10:37:36 +01:00
if ( empty ( $visibility ) || $visibility == 5 ) {
2021-10-17 18:58:34 +02:00
continue ;
}
2021-02-23 22:03:23 +01:00
if ( empty ( $perms )) {
continue ;
}
2018-04-12 23:16:23 +02:00
2021-02-23 22:03:23 +01:00
if ( $this -> attributes [ $object -> table_element ][ 'required' ][ $key ]) { // Value is required
2021-01-31 19:02:57 +01:00
// Check if functionally empty without using GETPOST (depending on the type of extrafield, a
2021-01-27 23:46:09 +01:00
// technically non-empty value may be treated as empty functionally).
// value can be alpha, int, array, etc...
2021-02-23 22:03:23 +01:00
if (( ! is_array ( $_POST [ " options_ " . $key ]) && empty ( $_POST [ " options_ " . $key ]) && $this -> attributes [ $object -> table_element ][ 'type' ][ $key ] != 'select' && $_POST [ " options_ " . $key ] != '0' )
|| ( ! is_array ( $_POST [ " options_ " . $key ]) && empty ( $_POST [ " options_ " . $key ]) && $this -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'select' )
|| ( ! is_array ( $_POST [ " options_ " . $key ]) && isset ( $_POST [ " options_ " . $key ]) && $this -> attributes [ $object -> table_element ][ 'type' ][ $key ] == 'sellist' && $_POST [ 'options_' . $key ] == '0' )
|| ( is_array ( $_POST [ " options_ " . $key ]) && empty ( $_POST [ " options_ " . $key ]))) {
2018-10-08 14:26:18 +02:00
//print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
2022-05-16 13:57:11 +02:00
// Field is not defined. We mark this as a problem. We may fix it later if there is a default value and $todefaultifmissing is set.
2018-10-08 14:26:18 +02:00
$nofillrequired ++ ;
2022-05-16 13:57:11 +02:00
$error_field_required [ $key ] = $langs -> transnoentitiesnoconv ( $value );
2018-10-08 14:26:18 +02:00
}
2013-07-26 10:46:45 +02:00
}
2013-04-21 17:36:23 +02:00
2020-07-04 13:13:17 +02:00
if ( in_array ( $key_type , array ( 'date' ))) {
2018-01-14 03:12:22 +01:00
// Clean parameters
2021-03-04 10:31:31 +01:00
$value_key = dol_mktime ( 12 , 0 , 0 , GETPOST ( " options_ " . $key . " month " , 'int' ), GETPOST ( " options_ " . $key . " day " , 'int' ), GETPOST ( " options_ " . $key . " year " , 'int' ));
2020-07-04 13:13:17 +02:00
} elseif ( in_array ( $key_type , array ( 'datetime' ))) {
2013-04-21 17:36:23 +02:00
// Clean parameters
2021-03-04 10:31:31 +01:00
$value_key = dol_mktime ( GETPOST ( " options_ " . $key . " hour " , 'int' ), GETPOST ( " options_ " . $key . " min " , 'int' ), GETPOST ( " options_ " . $key . " sec " , 'int' ), GETPOST ( " options_ " . $key . " month " , 'int' ), GETPOST ( " options_ " . $key . " day " , 'int' ), GETPOST ( " options_ " . $key . " year " , 'int' ), 'tzuserrel' );
2023-02-11 00:22:24 +01:00
} elseif ( in_array ( $key_type , array ( 'datetimegmt' ))) {
// Clean parameters
$value_key = dol_mktime ( GETPOST ( " options_ " . $key . " hour " , 'int' ), GETPOST ( " options_ " . $key . " min " , 'int' ), GETPOST ( " options_ " . $key . " sec " , 'int' ), GETPOST ( " options_ " . $key . " month " , 'int' ), GETPOST ( " options_ " . $key . " day " , 'int' ), GETPOST ( " options_ " . $key . " year " , 'int' ), 'gmt' );
2020-07-04 13:13:17 +02:00
} elseif ( in_array ( $key_type , array ( 'checkbox' , 'chkbxlst' ))) {
2020-01-30 01:48:28 +01:00
$value_arr = GETPOST ( " options_ " . $key , 'array' ); // check if an array
2013-07-23 15:52:41 +02:00
if ( ! empty ( $value_arr )) {
2022-06-09 15:52:47 +02:00
$value_key = implode ( ',' , $value_arr );
2020-01-30 01:48:28 +01:00
} else {
$value_key = '' ;
2013-07-23 15:52:41 +02:00
}
2020-07-04 13:13:17 +02:00
} elseif ( in_array ( $key_type , array ( 'price' , 'double' ))) {
2020-01-30 01:48:28 +01:00
$value_arr = GETPOST ( " options_ " . $key , 'alpha' );
$value_key = price2num ( $value_arr );
2022-09-21 14:59:46 +02:00
} elseif ( in_array ( $key_type , array ( 'pricecy' , 'double' ))) {
$value_key = price2num ( GETPOST ( " options_ " . $key , 'alpha' )) . ':' . GETPOST ( " options_ " . $key . " currency_id " , 'alpha' );
2020-07-04 13:13:17 +02:00
} elseif ( in_array ( $key_type , array ( 'html' ))) {
2020-11-18 12:45:37 +01:00
$value_key = GETPOST ( " options_ " . $key , 'restricthtml' );
2020-08-02 16:06:51 +02:00
} elseif ( in_array ( $key_type , array ( 'text' ))) {
2020-07-30 14:47:51 +02:00
$value_key = GETPOST ( " options_ " . $key , 'alphanohtml' );
2020-05-21 15:05:19 +02:00
} else {
2020-01-30 01:48:28 +01:00
$value_key = GETPOST ( " options_ " . $key );
2021-02-23 22:03:23 +01:00
if ( in_array ( $key_type , array ( 'link' )) && $value_key == '-1' ) {
$value_key = '' ;
}
2013-04-21 17:36:23 +02:00
}
2018-04-23 22:56:40 +02:00
2022-05-16 13:57:11 +02:00
if ( ! empty ( $error_field_required [ $key ]) && $todefaultifmissing ) {
// Value is required but we have a default value and we asked to set empty value to the default value
if ( ! empty ( $this -> attributes [ $object -> table_element ][ 'default' ]) && ! is_null ( $this -> attributes [ $object -> table_element ][ 'default' ][ $key ])) {
$value_key = $this -> attributes [ $object -> table_element ][ 'default' ][ $key ];
unset ( $error_field_required [ $key ]);
$nofillrequired -- ;
}
}
2020-01-30 01:48:28 +01:00
$object -> array_options [ " options_ " . $key ] = $value_key ;
2013-04-21 17:36:23 +02:00
}
2017-09-20 14:46:51 +02:00
if ( $nofillrequired ) {
2013-07-26 10:46:45 +02:00
$langs -> load ( 'errors' );
2022-05-16 13:57:11 +02:00
$this -> error = $langs -> trans ( 'ErrorFieldsRequired' ) . ' : ' . implode ( ', ' , $error_field_required );
setEventMessages ( $this -> error , null , 'errors' );
2013-07-26 10:46:45 +02:00
return - 1 ;
2020-05-21 15:05:19 +02:00
} else {
2013-07-26 10:46:45 +02:00
return 1 ;
}
2020-05-21 15:05:19 +02:00
} else {
2013-04-21 17:36:23 +02:00
return 0 ;
}
}
2016-04-20 17:30:40 +02:00
2013-06-10 14:13:44 +02:00
/**
2018-01-14 03:12:22 +01:00
* return array_options array of data of extrafields value of object sent by a search form
2013-06-10 14:13:44 +02:00
*
2018-12-13 20:45:51 +01:00
* @ param array | string $extrafieldsobjectkey array of extrafields ( old usage ) or value of object -> table_element ( new usage )
* @ param string $keyprefix Prefix string to add into name and id of field ( can be used to avoid duplicate names )
* @ param string $keysuffix Suffix string to add into name and id of field ( can be used to avoid duplicate names )
* @ return array | int array_options set or 0 if no value
2013-06-10 14:13:44 +02:00
*/
2019-02-27 20:45:07 +01:00
public function getOptionalsFromPost ( $extrafieldsobjectkey , $keyprefix = '' , $keysuffix = '' )
2013-06-10 14:13:44 +02:00
{
global $_POST ;
2021-02-23 22:03:23 +01:00
if ( is_string ( $extrafieldsobjectkey ) && ! empty ( $this -> attributes [ $extrafieldsobjectkey ][ 'label' ]) && is_array ( $this -> attributes [ $extrafieldsobjectkey ][ 'label' ])) {
2018-12-13 20:45:51 +01:00
$extralabels = $this -> attributes [ $extrafieldsobjectkey ][ 'label' ];
2020-05-21 15:05:19 +02:00
} else {
2018-12-13 20:45:51 +01:00
$extralabels = $extrafieldsobjectkey ;
}
2018-04-12 23:16:23 +02:00
2021-02-23 22:03:23 +01:00
if ( is_array ( $extralabels )) {
2018-12-13 20:45:51 +01:00
$array_options = array ();
2013-06-10 14:13:44 +02:00
// Get extra fields
2021-02-23 22:03:23 +01:00
foreach ( $extralabels as $key => $value ) {
2018-12-13 20:45:51 +01:00
$key_type = '' ;
2021-02-23 22:03:23 +01:00
if ( is_string ( $extrafieldsobjectkey )) {
2018-12-13 20:45:51 +01:00
$key_type = $this -> attributes [ $extrafieldsobjectkey ][ 'type' ][ $key ];
}
2013-06-10 14:13:44 +02:00
2021-03-04 10:31:31 +01:00
if ( in_array ( $key_type , array ( 'date' ))) {
2021-03-05 19:29:09 +01:00
$dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start' ;
$dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end' ;
if ( GETPOSTISSET ( $dateparamname_start . 'year' ) && GETPOSTISSET ( $dateparamname_end . 'year' )) {
// values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc.
$value_key = array (
'start' => dol_mktime ( 0 , 0 , 0 , GETPOST ( $dateparamname_start . 'month' , 'int' ), GETPOST ( $dateparamname_start . 'day' , 'int' ), GETPOST ( $dateparamname_start . 'year' , 'int' )),
'end' => dol_mktime ( 23 , 59 , 59 , GETPOST ( $dateparamname_end . 'month' , 'int' ), GETPOST ( $dateparamname_end . 'day' , 'int' ), GETPOST ( $dateparamname_end . 'year' , 'int' ))
);
} elseif ( GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix . " year " )) {
// Clean parameters
$value_key = dol_mktime ( 12 , 0 , 0 , GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " month " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " day " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " year " , 'int' ));
} else {
continue ; // Value was not provided, we should not set it.
}
2023-02-11 00:22:24 +01:00
} elseif ( in_array ( $key_type , array ( 'datetime' , 'datetimegmt' ))) {
2020-11-10 17:24:17 +01:00
$dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start' ;
$dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end' ;
if ( GETPOSTISSET ( $dateparamname_start . 'year' ) && GETPOSTISSET ( $dateparamname_end . 'year' )) {
// values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc.
2022-09-15 14:13:27 +02:00
$dateparamname_end_hour = GETPOST ( $dateparamname_end . 'hour' , 'int' ) != '-1' ? GETPOST ( $dateparamname_end . 'hour' , 'int' ) : '23' ;
$dateparamname_end_min = GETPOST ( $dateparamname_end . 'min' , 'int' ) != '-1' ? GETPOST ( $dateparamname_end . 'min' , 'int' ) : '59' ;
$dateparamname_end_sec = GETPOST ( $dateparamname_end . 'sec' , 'int' ) != '-1' ? GETPOST ( $dateparamname_end . 'sec' , 'int' ) : '59' ;
2023-02-11 00:22:24 +01:00
if ( $key_type == 'datetimegmt' ) {
$value_key = array (
'start' => dol_mktime ( GETPOST ( $dateparamname_start . 'hour' , 'int' ), GETPOST ( $dateparamname_start . 'min' , 'int' ), GETPOST ( $dateparamname_start . 'sec' , 'int' ), GETPOST ( $dateparamname_start . 'month' , 'int' ), GETPOST ( $dateparamname_start . 'day' , 'int' ), GETPOST ( $dateparamname_start . 'year' , 'int' ), 'gmt' ),
'end' => dol_mktime ( $dateparamname_end_hour , $dateparamname_end_min , $dateparamname_end_sec , GETPOST ( $dateparamname_end . 'month' , 'int' ), GETPOST ( $dateparamname_end . 'day' , 'int' ), GETPOST ( $dateparamname_end . 'year' , 'int' ), 'gmt' )
);
} else {
$value_key = array (
'start' => dol_mktime ( GETPOST ( $dateparamname_start . 'hour' , 'int' ), GETPOST ( $dateparamname_start . 'min' , 'int' ), GETPOST ( $dateparamname_start . 'sec' , 'int' ), GETPOST ( $dateparamname_start . 'month' , 'int' ), GETPOST ( $dateparamname_start . 'day' , 'int' ), GETPOST ( $dateparamname_start . 'year' , 'int' ), 'tzuserrel' ),
'end' => dol_mktime ( $dateparamname_end_hour , $dateparamname_end_min , $dateparamname_end_sec , GETPOST ( $dateparamname_end . 'month' , 'int' ), GETPOST ( $dateparamname_end . 'day' , 'int' ), GETPOST ( $dateparamname_end . 'year' , 'int' ), 'tzuserrel' )
);
}
2020-11-10 17:24:17 +01:00
} elseif ( GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix . " year " )) {
// Clean parameters
2023-02-11 00:22:24 +01:00
if ( $key_type == 'datetimegmt' ) {
$value_key = dol_mktime ( GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " hour " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " min " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " sec " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " month " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " day " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " year " , 'int' ), 'gmt' );
} else {
$value_key = dol_mktime ( GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " hour " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " min " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " sec " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " month " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " day " , 'int' ), GETPOST ( $keysuffix . " options_ " . $key . $keyprefix . " year " , 'int' ), 'tzuserrel' );
}
2020-11-10 17:24:17 +01:00
} else {
continue ; // Value was not provided, we should not set it.
}
2022-03-15 18:24:49 +01:00
} elseif ( $key_type == 'select' ) {
// to detect if we are in search context
2022-03-30 11:49:48 +02:00
if ( GETPOSTISARRAY ( $keysuffix . " options_ " . $key . $keyprefix )) {
2022-03-15 18:24:49 +01:00
$value_arr = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix , 'array:aZ09' );
// Make sure we get an array even if there's only one selected
$value_arr = ( array ) $value_arr ;
$value_key = implode ( ',' , $value_arr );
} else {
$value_key = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix );
}
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $key_type , array ( 'checkbox' , 'chkbxlst' ))) {
if ( ! GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix )) {
continue ; // Value was not provided, we should not set it.
}
2019-11-13 19:35:39 +01:00
$value_arr = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix );
2015-11-30 18:06:15 +01:00
// Make sure we get an array even if there's only one checkbox
2019-11-13 19:35:39 +01:00
$value_arr = ( array ) $value_arr ;
$value_key = implode ( ',' , $value_arr );
2021-02-23 22:03:23 +01:00
} elseif ( in_array ( $key_type , array ( 'price' , 'double' , 'int' ))) {
2021-10-21 18:54:07 +02:00
if ( ! GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix )) {
2021-02-23 22:03:23 +01:00
continue ; // Value was not provided, we should not set it.
}
2021-10-21 18:54:07 +02:00
$value_arr = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix );
2021-10-21 18:42:06 +02:00
if ( $keysuffix != 'search_' ) { // If value is for a search, we must keep complex string like '>100 <=150'
2021-06-11 17:57:55 +02:00
$value_key = price2num ( $value_arr );
} else {
$value_key = $value_arr ;
}
2021-10-21 18:42:06 +02:00
} elseif ( in_array ( $key_type , array ( 'boolean' ))) {
if ( ! GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix )) {
$value_key = '' ;
} else {
$value_arr = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix );
$value_key = $value_arr ;
}
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 22:03:23 +01:00
if ( ! GETPOSTISSET ( $keysuffix . " options_ " . $key . $keyprefix )) {
continue ; // Value was not provided, we should not set it.
}
2019-11-13 19:35:39 +01:00
$value_key = GETPOST ( $keysuffix . " options_ " . $key . $keyprefix );
2013-06-10 14:13:44 +02:00
}
2014-02-16 23:51:29 +01:00
2019-11-13 19:35:39 +01:00
$array_options [ $keysuffix . " options_ " . $key ] = $value_key ; // No keyprefix here. keyprefix is used only for read.
2013-06-10 14:13:44 +02:00
}
return $array_options ;
}
2018-12-13 20:45:51 +01:00
return 0 ;
2013-06-10 14:13:44 +02:00
}
2003-02-13 19:14:57 +01:00
}