2016-12-02 12:02:08 +01:00
< ? php
2015-12-17 20:40:33 +01:00
2021-04-16 10:26:35 +02:00
// $keyforselect = name of main table
// keyforelement = name of picto
// $keyforaliasextra = a key to avoid conflict with extrafields of other objects
2021-02-23 22:03:23 +01:00
if ( empty ( $keyforselect ) || empty ( $keyforelement ) || empty ( $keyforaliasextra )) {
2020-10-31 14:32:18 +01:00
//print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
dol_print_error ( '' , 'include of file extrafieldsinexport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set' );
exit ;
2015-12-17 20:40:33 +01:00
}
// Add extra fields
2020-09-19 22:41:05 +02:00
$sql = " SELECT name, label, type, param, fieldcomputed, fielddefault FROM " . MAIN_DB_PREFIX . " extrafields " ;
2022-04-04 13:59:50 +02:00
$sql .= " WHERE elementtype = ' " . $this -> db -> escape ( $keyforselect ) . " ' AND type <> 'separate' AND entity IN (0, " . (( int ) $conf -> entity ) . ') ORDER BY pos ASC' ;
2015-12-17 20:40:33 +01:00
//print $sql;
2020-01-30 01:48:28 +01:00
$resql = $this -> db -> query ( $sql );
2021-02-23 22:03:23 +01:00
if ( $resql ) { // This can fail when class is used on old database (during migration for example)
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2020-01-30 01:48:28 +01:00
$fieldname = $keyforaliasextra . '.' . $obj -> name ;
$fieldlabel = ucfirst ( $obj -> label );
$typeFilter = " Text " ;
$typefield = preg_replace ( '/\(.*$/' , '' , $obj -> type ); // double(24,8) -> double
2017-07-28 14:54:13 +02:00
switch ( $typefield ) {
2015-12-17 20:40:33 +01:00
case 'int' :
2017-07-28 14:54:13 +02:00
case 'integer' :
2015-12-17 20:40:33 +01:00
case 'double' :
case 'price' :
2020-01-30 01:48:28 +01:00
$typeFilter = " Numeric " ;
2015-12-17 20:40:33 +01:00
break ;
case 'date' :
case 'datetime' :
2017-07-28 14:54:13 +02:00
case 'timestamp' :
2020-01-30 01:48:28 +01:00
$typeFilter = " Date " ;
2015-12-17 20:40:33 +01:00
break ;
case 'boolean' :
2020-01-30 01:48:28 +01:00
$typeFilter = " Boolean " ;
2015-12-17 20:40:33 +01:00
break ;
2021-06-24 11:54:05 +02:00
case 'checkbox' :
2019-07-02 18:06:51 +02:00
case 'select' :
2021-02-23 22:03:23 +01:00
if ( ! empty ( $conf -> global -> EXPORT_LABEL_FOR_SELECT )) {
2021-06-30 17:14:19 +02:00
$tmpparam = jsonOrUnserialize ( $obj -> param ); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...)
2020-10-31 14:32:18 +01:00
if ( $tmpparam [ 'options' ] && is_array ( $tmpparam [ 'options' ])) {
$typeFilter = " Select: " . $obj -> param ;
}
}
break ;
2015-12-17 20:40:33 +01:00
case 'sellist' :
2020-01-30 01:48:28 +01:00
$tmp = '' ;
2021-06-30 17:14:19 +02:00
$tmpparam = jsonOrUnserialize ( $obj -> param ); // $tmp may be array 'options' => array 'c_currencies:code_iso:code_iso' => null
2021-10-21 15:50:04 +02:00
if ( is_array ( $tmpparam ) && array_key_exists ( 'options' , $tmpparam ) && $tmpparam [ 'options' ] && is_array ( $tmpparam [ 'options' ])) {
2020-01-30 01:48:28 +01:00
$tmpkeys = array_keys ( $tmpparam [ 'options' ]);
$tmp = array_shift ( $tmpkeys );
2015-12-17 20:40:33 +01:00
}
2021-02-23 22:03:23 +01:00
if ( preg_match ( '/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/' , $tmp )) {
$typeFilter = " List: " . $tmp ;
}
2015-12-17 20:40:33 +01:00
break ;
}
2021-02-23 22:03:23 +01:00
if ( $obj -> type != 'separate' ) {
2020-10-31 14:32:18 +01:00
// If not a computed field
2021-02-23 22:03:23 +01:00
if ( empty ( $obj -> fieldcomputed )) {
2020-10-31 14:32:18 +01:00
$this -> export_fields_array [ $r ][ $fieldname ] = $fieldlabel ;
$this -> export_TypeFields_array [ $r ][ $fieldname ] = $typeFilter ;
$this -> export_entities_array [ $r ][ $fieldname ] = $keyforelement ;
2021-03-01 20:37:16 +01:00
} else {
// If this is a computed field
2020-10-31 14:32:18 +01:00
$this -> export_fields_array [ $r ][ $fieldname ] = $fieldlabel ;
$this -> export_TypeFields_array [ $r ][ $fieldname ] = $typeFilter . 'Compute' ;
$this -> export_special_array [ $r ][ $fieldname ] = $obj -> fieldcomputed ;
$this -> export_entities_array [ $r ][ $fieldname ] = $keyforelement ;
2017-06-13 18:50:31 +02:00
}
2016-12-09 17:17:58 +01:00
}
2015-12-17 20:40:33 +01:00
}
}
// End add axtra fields