dolibarr 25.0.0-alpha
commonfieldsinimport.inc.php
1<?php
2/* Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
3 * Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
4 */
5'@phan-var-force DolibarrModules $this';
8if (empty($keyforclass) || empty($keyforclassfile) || empty($keyforelement) || empty($r)) {
9 //print $keyforclass.' - '.$keyforclassfile.' - '.$keyforelement;
10 dol_print_error(null, 'include of file commonfieldsinimport.inc.php was done but var $keyforclass or $keyforclassfile or $keyforelement or $r was not set');
11 exit;
12}
13if (empty($keyforalias)) {
14 $keyforalias = 't';
15}
16
17dol_include_once($keyforclassfile);
18if (class_exists($keyforclass)) {
20 $tmpobject = new $keyforclass($this->db);
21 '@phan-var-force CommonObject $tmpobject';
22
23 // Add common fields
24 foreach ($tmpobject->fields as $keyfield => $valuefield) {
25 $fieldname = $keyforalias.'.'.$keyfield;
26 $fieldlabel = ucfirst($valuefield['label']);
27 $typeFilter = "Text";
28 $typefield = preg_replace('/\‍(.*$/', '', $valuefield['type']); // double(24,8) -> double
29 switch ($typefield) {
30 case 'int':
31 case 'integer':
32 case 'double':
33 case 'price':
34 $typeFilter = "Numeric";
35 break;
36 case 'date':
37 case 'datetime':
38 case 'timestamp':
39 $typeFilter = "Date";
40 break;
41 case 'boolean':
42 $typeFilter = "Boolean";
43 break;
44 /*
45 * case 'sellist':
46 * $tmp='';
47 * $tmpparam=jsonOrUnserialize($obj->param); // $tmp ay be array 'options' => array 'c_currencies:code_iso:code_iso' => null
48 * if ($tmpparam['options'] && is_array($tmpparam['options'])) {
49 * $tmpkeys=array_keys($tmpparam['options']);
50 * $tmp=array_shift($tmpkeys);
51 * }
52 * if (preg_match('/[a-z0-9_]+:[a-z0-9_]+:[a-z0-9_]+/', $tmp)) $typeFilter="List:".$tmp;
53 * break;
54 */
55 }
56 $helpfield = '';
57 if (!empty($valuefield['help'])) {
58 $helpfield = preg_replace('/\‍(.*$/', '', $valuefield['help']);
59 }
60 if ($valuefield['enabled']) {
61 $this->import_fields_array[$r][$fieldname] = $fieldlabel;
62 $this->import_TypeFields_array[$r][$fieldname] = $typeFilter;
63 $this->import_entities_array[$r][$fieldname] = $keyforelement;
64 $this->import_help_array[$r][$fieldname] = $helpfield;
65 }
66 }
67} else {
68 dol_print_error($this->db, 'Failed to find class '.$keyforclass.', even after the include of '.$keyforclassfile);
69}
70// 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...