dolibarr 21.0.0-alpha
commonfieldsinimport.inc.php
1<?php
2'@phan-var-force DolibarrModules $this';
3
4if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement)) {
5 //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
6 dol_print_error(null, 'include of file commonfieldsinimport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement was not set');
7 exit;
8}
9if (empty($keyforalias)) {
10 $keyforalias = 't';
11}
12
13dol_include_once($keyforclassfile);
14if (class_exists($keyforclass)) {
15 $tmpobject = new $keyforclass($this->db);
16
17 // Add common fields
18 foreach ($tmpobject->fields as $keyfield => $valuefield) {
19 $fieldname = $keyforalias.'.'.$keyfield;
20 $fieldlabel = ucfirst($valuefield['label']);
21 $typeFilter = "Text";
22 $typefield = preg_replace('/\‍(.*$/', '', $valuefield['type']); // double(24,8) -> double
23 switch ($typefield) {
24 case 'int':
25 case 'integer':
26 case 'double':
27 case 'price':
28 $typeFilter = "Numeric";
29 break;
30 case 'date':
31 case 'datetime':
32 case 'timestamp':
33 $typeFilter = "Date";
34 break;
35 case 'boolean':
36 $typeFilter = "Boolean";
37 break;
38 /*
39 * case 'sellist':
40 * $tmp='';
41 * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
42 * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
43 * $tmpkeys=array_keys($tmpparam['options']);
44 * $tmp=array_shift($tmpkeys);
45 * }
46 * if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
47 * break;
48 */
49 }
50 $helpfield = '';
51 if (!empty($valuefield['help'])) {
52 $helpfield = preg_replace('/\‍(.*$/', '', $valuefield['help']);
53 }
54 if ($valuefield['enabled']) {
55 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
56 $this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
57 $this->import_entities_array[$r][$fieldname] = $keyforelement;
58 $this->import_help_array[$r][$fieldname] = $helpfield;
59 }
60 }
61} else {
62 dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
63}
64// End add common fields
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...