dolibarr 18.0.6
extrafieldsinimport.inc.php
1<?php
2
3// $keyforselect = name of main table
4// keyforelement = name of picto
5// $keyforaliasextra = a key to avoid conflict with extrafields of other objects
6
7if (empty($keyforselect) || empty($keyforelement) || empty($keyforaliasextra)) {
8 //print $keyforselet.' - '.$keyforelement.' - '.$keyforaliasextra;
9 dol_print_error('', 'include of file extrafieldsinimport.inc.php was done but var $keyforselect or $keyforelement or $keyforaliasextra was not set');
10 exit;
11}
12
13// Add extra fields
14$sql = "SELECT name, label, type, param, fieldcomputed, fielddefault, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields";
15$sql .= " WHERE elementtype = '".$this->db->escape($keyforselect)."' AND type <> 'separate' AND entity IN (0, ".((int) $conf->entity).') ORDER BY pos ASC';
16//print $sql;
17$resql = $this->db->query($sql);
18if ($resql) { // This can fail when class is used on old database (during migration for example)
19 while ($obj = $this->db->fetch_object($resql)) {
20 $fieldname = $keyforaliasextra.'.'.$obj->name;
21 $fieldlabel = ucfirst($obj->label);
22 $typeFilter = "Text";
23 $typefield = preg_replace('/\‍(.*$/', '', $obj->type); // double(24,8) -> double
24 switch ($typefield) {
25 case 'int':
26 case 'integer':
27 case 'double':
28 case 'price':
29 $typeFilter = "Numeric";
30 break;
31 case 'date':
32 case 'datetime':
33 case 'timestamp':
34 $typeFilter = "Date";
35 break;
36 case 'boolean':
37 $typeFilter = "Boolean";
38 break;
39 case 'checkbox':
40 case 'select':
41 if (!empty($conf->global->EXPORT_LABEL_FOR_SELECT)) {
42 $tmpparam = jsonOrUnserialize($obj->param); // $tmpparam may be array with 'options' = array(key1=>val1, key2=>val2 ...)
43 if ($tmpparam['options'] && is_array($tmpparam['options'])) {
44 $typeFilter = "Select:".$obj->param;
45 }
46 }
47 break;
48 case 'sellist':
49 $tmp = '';
50 $tmpparam = jsonOrUnserialize($obj->param); // $tmp may be array 'options' => array 'c_currencies:code_iso:code_iso' => null
51 if (is_array($tmpparam) && array_key_exists('options', $tmpparam) && $tmpparam['options'] && is_array($tmpparam['options'])) {
52 $tmpkeys = array_keys($tmpparam['options']);
53 $tmp = array_shift($tmpkeys);
54 }
55 if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) {
56 $typeFilter = "List:".$tmp;
57 }
58 break;
59 }
60 if ($obj->type != 'separate') {
61 // If not a computed field
62 if (empty($obj->fieldcomputed)) {
63 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
64 $this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
65 $this->import_entities_array[$r][$fieldname] = $keyforelement;
66 } else {
67 // If this is a computed field
68 $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
69 $this->import_TypeFields_array[$r][$fieldname] = $typeFilter.'Compute';
70 $this->import_entities_array[$r][$fieldname] = $keyforelement;
71 }
72 }
73 }
74}
75// End add axtra fields
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
jsonOrUnserialize($stringtodecode)
Decode an encode string.