dolibarr  9.0.0
extrafields.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6  * Copyright (C) 2009-2012 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2009-2012 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro>
9  * Copyright (C) 2015 Charles-Fr BENKE <charles.fr@benke.fr>
10  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
11  * Copyright (C) 2017 Nicolas ZABOURI <info@inovea-conseil.com>
12  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
39 {
43  public $db;
44 
45  // type of element (for what object is the extrafield)
46  // @deprecated
47  var $attribute_elementtype;
48  // Array with type of the extra field
49  // @deprecated
50  var $attribute_type;
51  // Array with label of extra field
52  // @deprecated
53  var $attribute_label;
54  // Array with size of extra field
55  // @deprecated
56  var $attribute_size;
57  // array with list of possible values for some types of extra fields
58  // @deprecated
59  var $attribute_choice;
60  // Array to store compute formula for computed fields
61  // @deprecated
62  var $attribute_computed;
63  // Array to store default value
64  // @deprecated
65  var $attribute_default;
66  // Array to store if attribute is unique or not
67  // @deprecated
68  var $attribute_unique;
69  // Array to store if attribute is required or not
70  // @deprecated
71  var $attribute_required;
72  // Array to store parameters of attribute (used in select type)
73  // @deprecated
74  var $attribute_param;
75  // Array to store position of attribute
76  // @deprecated
77  var $attribute_pos;
78  // Array to store if attribute is editable regardless of the document status
79  // @deprecated
80  var $attribute_alwayseditable;
81  // Array to store permission to check
82  // @deprecated
83  var $attribute_perms;
84  // Array to store language file to translate label of values
85  // @deprecated
86  var $attribute_langfile;
87  // Array to store if field is visible by default on list
88  // @deprecated
89  var $attribute_list;
90 
91  // New array to store extrafields definition
92  var $attributes;
93 
97  public $error='';
98 
99  var $errno;
100 
101 
102  public static $type2label=array(
103  'varchar'=>'String',
104  'text'=>'TextLong',
105  'html'=>'HtmlText',
106  'int'=>'Int',
107  'double'=>'Float',
108  'date'=>'Date',
109  'datetime'=>'DateAndTime',
110  'boolean'=>'Boolean',
111  'price'=>'ExtrafieldPrice',
112  'phone'=>'ExtrafieldPhone',
113  'mail'=>'ExtrafieldMail',
114  'url'=>'ExtrafieldUrl',
115  'password' => 'ExtrafieldPassword',
116  'select' => 'ExtrafieldSelect',
117  'sellist' => 'ExtrafieldSelectList',
118  'radio' => 'ExtrafieldRadio',
119  'checkbox' => 'ExtrafieldCheckBox',
120  'chkbxlst' => 'ExtrafieldCheckBoxFromList',
121  'link' => 'ExtrafieldLink',
122  'separate' => 'ExtrafieldSeparator',
123  );
124 
125 
131  function __construct($db)
132  {
133  $this->db = $db;
134  $this->error = array();
135  $this->attributes = array();
136 
137  // For old usage
138  $this->attribute_elementtype = array();
139  $this->attribute_type = array();
140  $this->attribute_label = array();
141  $this->attribute_size = array();
142  $this->attribute_computed = array();
143  $this->attribute_default = array();
144  $this->attribute_unique = array();
145  $this->attribute_required = array();
146  $this->attribute_perms = array();
147  $this->attribute_langfile = array();
148  $this->attribute_list = array();
149  }
150 
174  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')
175  {
176  if (empty($attrname)) return -1;
177  if (empty($label)) return -1;
178 
179  if ($elementtype == 'thirdparty') $elementtype='societe';
180  if ($elementtype == 'contact') $elementtype='socpeople';
181 
182  // Create field into database except for separator type which is not stored in database
183  if ($type != 'separate')
184  {
185  $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed, $help);
186  }
187  $err1=$this->errno;
188  if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate')
189  {
190  // Add declaration of field into table
191  $result2=$this->create_label($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $param, $alwayseditable, $perms, $list, $help, $default_value, $computed, $entity, $langfile, $enabled);
192  $err2=$this->errno;
193  if ($result2 > 0 || ($err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' && $err2 == 'DB_ERROR_RECORD_ALREADY_EXISTS'))
194  {
195  $this->error='';
196  $this->errno=0;
197  return 1;
198  }
199  else return -2;
200  }
201  else
202  {
203  return -1;
204  }
205  }
206 
224  private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list='0', $computed='')
225  {
226  if ($elementtype == 'thirdparty') $elementtype='societe';
227  if ($elementtype == 'contact') $elementtype='socpeople';
228 
229  $table=$elementtype.'_extrafields';
230  if ($elementtype == 'categorie') $table='categories_extrafields';
231 
232  if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname))
233  {
234  if ($type=='boolean') {
235  $typedb='int';
236  $lengthdb='1';
237  } elseif($type=='price') {
238  $typedb='double';
239  $lengthdb='24,8';
240  } elseif($type=='phone') {
241  $typedb='varchar';
242  $lengthdb='20';
243  } elseif($type=='mail') {
244  $typedb='varchar';
245  $lengthdb='128';
246  } elseif($type=='url') {
247  $typedb='varchar';
248  $lengthdb='255';
249  } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){
250  $typedb='varchar';
251  $lengthdb='255';
252  } elseif ($type=='link') {
253  $typedb='int';
254  $lengthdb='11';
255  } elseif ($type=='html') {
256  $typedb='text';
257  $lengthdb=$length;
258  } elseif($type=='password') {
259  $typedb='varchar';
260  $lengthdb='128';
261  } else {
262  $typedb=$type;
263  $lengthdb=$length;
264  if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255';
265  }
266  $field_desc = array(
267  'type'=>$typedb,
268  'value'=>$lengthdb,
269  'null'=>($required?'NOT NULL':'NULL'),
270  'default' => $default_value
271  );
272 
273  $result=$this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
274  if ($result > 0)
275  {
276  if ($unique)
277  {
278  $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")";
279  $resql=$this->db->query($sql,1,'dml');
280  }
281  return 1;
282  }
283  else
284  {
285  $this->error=$this->db->lasterror();
286  $this->errno=$this->db->lasterrno();
287  return -1;
288  }
289  }
290  else
291  {
292  return 0;
293  }
294  }
295 
296  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
320  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')
321  {
322  // phpcs:enable
323  global $conf,$user;
324 
325  if ($elementtype == 'thirdparty') $elementtype='societe';
326  if ($elementtype == 'contact') $elementtype='socpeople';
327 
328  // Clean parameters
329  if (empty($pos)) $pos=0;
330  if (empty($list)) $list='0';
331  if (empty($required)) $required=0;
332  if (empty($unique)) $unique=0;
333  if (empty($alwayseditable)) $alwayseditable=0;
334 
335  if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname))
336  {
337  if (is_array($param) && count($param) > 0)
338  {
339  $params = serialize($param);
340  }
341  elseif (strlen($param) > 0)
342  {
343  $params = trim($param);
344  }
345  else
346  {
347  $params='';
348  }
349 
350  $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(";
351  $sql.= " name,";
352  $sql.= " label,";
353  $sql.= " type,";
354  $sql.= " pos,";
355  $sql.= " size,";
356  $sql.= " entity,";
357  $sql.= " elementtype,";
358  $sql.= " fieldunique,";
359  $sql.= " fieldrequired,";
360  $sql.= " param,";
361  $sql.= " alwayseditable,";
362  $sql.= " perms,";
363  $sql.= " langs,";
364  $sql.= " list,";
365  $sql.= " fielddefault,";
366  $sql.= " fieldcomputed,";
367  $sql.= " fk_user_author,";
368  $sql.= " fk_user_modif,";
369  $sql.= " datec,";
370  $sql.= " enabled,";
371  $sql.= " help";
372  $sql.= " )";
373  $sql.= " VALUES('".$attrname."',";
374  $sql.= " '".$this->db->escape($label)."',";
375  $sql.= " '".$this->db->escape($type)."',";
376  $sql.= " ".$pos.",";
377  $sql.= " '".$this->db->escape($size)."',";
378  $sql.= " ".($entity===''?$conf->entity:$entity).",";
379  $sql.= " '".$this->db->escape($elementtype)."',";
380  $sql.= " ".$unique.",";
381  $sql.= " ".$required.",";
382  $sql.= " '".$this->db->escape($params)."',";
383  $sql.= " ".$alwayseditable.",";
384  $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
385  $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
386  $sql.= " '".$this->db->escape($list)."',";
387  $sql.= " ".($default?"'".$this->db->escape($default)."'":"null").",";
388  $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
389  $sql .= " " . (is_object($user) ? $user->id : 0). ",";
390  $sql .= " " . (is_object($user) ? $user->id : 0). ",";
391  $sql .= "'" . $this->db->idate(dol_now()) . "',";
392  $sql.= " ".($enabled?"'".$this->db->escape($enabled)."'":"1").",";
393  $sql.= " ".($help?"'".$this->db->escape($help)."'":"null");
394  $sql.=')';
395 
396  dol_syslog(get_class($this)."::create_label", LOG_DEBUG);
397  if ($this->db->query($sql))
398  {
399  return 1;
400  }
401  else
402  {
403  $this->error=$this->db->lasterror();
404  $this->errno=$this->db->lasterrno();
405  return -1;
406  }
407  }
408  }
409 
417  function delete($attrname, $elementtype='member')
418  {
419  if ($elementtype == 'thirdparty') $elementtype='societe';
420  if ($elementtype == 'contact') $elementtype='socpeople';
421 
422  $table=$elementtype.'_extrafields';
423  if ($elementtype == 'categorie') $table='categories_extrafields';
424 
425  $error=0;
426 
427  if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
428  {
429  $result=$this->delete_label($attrname,$elementtype);
430  if ($result < 0)
431  {
432  $this->error=$this->db->lasterror();
433  $error++;
434  }
435 
436  if (! $error)
437  {
438  $sql = "SELECT COUNT(rowid) as nb";
439  $sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
440  $sql.= " WHERE elementtype = '".$elementtype."'";
441  $sql.= " AND name = '".$attrname."'";
442  //$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
443  $resql = $this->db->query($sql);
444  if ($resql)
445  {
446  $obj = $this->db->fetch_object($resql);
447  if ($obj->nb <= 0)
448  {
449  $result=$this->db->DDLDropField(MAIN_DB_PREFIX.$table,$attrname); // This also drop the unique key
450  if ($result < 0)
451  {
452  $this->error=$this->db->lasterror();
453  $error++;
454  }
455  }
456  }
457  }
458 
459  return $result;
460  }
461  else
462  {
463  return 0;
464  }
465  }
466 
467  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
475  private function delete_label($attrname, $elementtype='member')
476  {
477  // phpcs:enable
478  global $conf;
479 
480  if ($elementtype == 'thirdparty') $elementtype='societe';
481  if ($elementtype == 'contact') $elementtype='socpeople';
482 
483  if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
484  {
485  $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
486  $sql.= " WHERE name = '".$attrname."'";
487  $sql.= " AND entity IN (0,".$conf->entity.')';
488  $sql.= " AND elementtype = '".$elementtype."'";
489 
490  dol_syslog(get_class($this)."::delete_label", LOG_DEBUG);
491  $resql=$this->db->query($sql);
492  if ($resql)
493  {
494  return 1;
495  }
496  else
497  {
498  print dol_print_error($this->db);
499  return -1;
500  }
501  }
502  else
503  {
504  return 0;
505  }
506  }
507 
532  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)
533  {
534  if ($elementtype == 'thirdparty') $elementtype='societe';
535  if ($elementtype == 'contact') $elementtype='socpeople';
536 
537  $table=$elementtype.'_extrafields';
538  if ($elementtype == 'categorie') $table='categories_extrafields';
539 
540  if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
541  {
542  if ($type=='boolean') {
543  $typedb='int';
544  $lengthdb='1';
545  } elseif($type=='price') {
546  $typedb='double';
547  $lengthdb='24,8';
548  } elseif($type=='phone') {
549  $typedb='varchar';
550  $lengthdb='20';
551  } elseif($type=='mail') {
552  $typedb='varchar';
553  $lengthdb='128';
554  } elseif($type=='url') {
555  $typedb='varchar';
556  $lengthdb='255';
557  } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') || ($type=='checkbox') || ($type=='chkbxlst')) {
558  $typedb='varchar';
559  $lengthdb='255';
560  } elseif ($type == 'html') {
561  $typedb='text';
562  } elseif ($type=='link') {
563  $typedb='int';
564  $lengthdb='11';
565  } elseif($type=='password') {
566  $typedb='varchar';
567  $lengthdb='50';
568  } else {
569  $typedb=$type;
570  $lengthdb=$length;
571  }
572  $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default);
573 
574  if ($type != 'separate') // No table update when separate type
575  {
576  $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc);
577  }
578  if ($result > 0 || $type == 'separate')
579  {
580  if ($label)
581  {
582  $result=$this->update_label($attrname,$label,$type,$length,$elementtype,$unique,$required,$pos,$param,$alwayseditable,$perms,$list,$help,$default,$computed,$entity,$langfile,$enabled, $totalizable);
583  }
584  if ($result > 0)
585  {
586  $sql='';
587  if ($unique)
588  {
589  $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")";
590  }
591  else
592  {
593  $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname;
594  }
595  dol_syslog(get_class($this).'::update', LOG_DEBUG);
596  $resql=$this->db->query($sql,1,'dml');
597  return 1;
598  }
599  else
600  {
601  $this->error=$this->db->lasterror();
602  return -1;
603  }
604  }
605  else
606  {
607  $this->error=$this->db->lasterror();
608  return -1;
609  }
610  }
611  else
612  {
613  return 0;
614  }
615  }
616 
617  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
642  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)
643  {
644  // phpcs:enable
645  global $conf, $user;
646  dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable);
647 
648  // Clean parameters
649  if ($elementtype == 'thirdparty') $elementtype='societe';
650  if ($elementtype == 'contact') $elementtype='socpeople';
651 
652  if (empty($pos)) $pos=0;
653  if (empty($list)) $list='0';
654  if (empty($totalizable)) {
655  $totalizable = 0;
656  }
657  if (empty($required)) $required=0;
658  if (empty($unique)) $unique=0;
659  if (empty($alwayseditable)) $alwayseditable=0;
660 
661  if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname))
662  {
663  $this->db->begin();
664 
665  if (is_array($param) && count($param) > 0)
666  {
667  $params = serialize($param);
668  }
669  elseif (strlen($param) > 0)
670  {
671  $params = trim($param);
672  }
673  else
674  {
675  $params='';
676  }
677 
678  if ($entity === '' || $entity != '0')
679  {
680  // We dont want on all entities, we delete all and current
681  $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
682  $sql_del.= " WHERE name = '".$attrname."'";
683  $sql_del.= " AND entity IN (0, ".($entity===''?$conf->entity:$entity).")";
684  $sql_del.= " AND elementtype = '".$elementtype."'";
685  }
686  else
687  {
688  // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity)
689  $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields";
690  $sql_del.= " WHERE name = '".$attrname."'";
691  $sql_del.= " AND entity = 0";
692  $sql_del.= " AND elementtype = '".$elementtype."'";
693  }
694  $resql1=$this->db->query($sql_del);
695 
696  $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields(";
697  $sql.= " name,"; // This is code
698  $sql.= " entity,";
699  $sql.= " label,";
700  $sql.= " type,";
701  $sql.= " size,";
702  $sql.= " elementtype,";
703  $sql.= " fieldunique,";
704  $sql.= " fieldrequired,";
705  $sql.= " perms,";
706  $sql.= " langs,";
707  $sql.= " pos,";
708  $sql.= " alwayseditable,";
709  $sql.= " param,";
710  $sql.= " list,";
711  $sql.= " totalizable,";
712  $sql.= " fielddefault,";
713  $sql.= " fieldcomputed,";
714  $sql.= " fk_user_author,";
715  $sql.= " fk_user_modif,";
716  $sql.= " datec,";
717  $sql.= " enabled,";
718  $sql.= " help";
719  $sql.= ") VALUES (";
720  $sql.= "'".$attrname."',";
721  $sql.= " ".($entity===''?$conf->entity:$entity).",";
722  $sql.= " '".$this->db->escape($label)."',";
723  $sql.= " '".$this->db->escape($type)."',";
724  $sql.= " '".$this->db->escape($size)."',";
725  $sql.= " '".$this->db->escape($elementtype)."',";
726  $sql.= " ".$unique.",";
727  $sql.= " ".$required.",";
728  $sql.= " ".($perms?"'".$this->db->escape($perms)."'":"null").",";
729  $sql.= " ".($langfile?"'".$this->db->escape($langfile)."'":"null").",";
730  $sql.= " ".$pos.",";
731  $sql.= " '".$this->db->escape($alwayseditable)."',";
732  $sql.= " '".$this->db->escape($params)."',";
733  $sql.= " '".$this->db->escape($list)."', ";
734  $sql.= " ".$totalizable.",";
735  $sql.= " ".(($default!='')?"'".$this->db->escape($default)."'":"null").",";
736  $sql.= " ".($computed?"'".$this->db->escape($computed)."'":"null").",";
737  $sql .= " " . $user->id . ",";
738  $sql .= " " . $user->id . ",";
739  $sql .= "'" . $this->db->idate(dol_now()) . "',";
740  $sql .= "'" . $this->db->escape($enabled). "',";
741  $sql.= " ".($help?"'".$this->db->escape($help)."'":"null");
742  $sql.= ")";
743 
744  $resql2=$this->db->query($sql);
745 
746  if ($resql1 && $resql2)
747  {
748  $this->db->commit();
749  return 1;
750  }
751  else
752  {
753  $this->db->rollback();
754  print dol_print_error($this->db);
755  return -1;
756  }
757  }
758  else
759  {
760  return 0;
761  }
762  }
763 
764 
765  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
773  function fetch_name_optionals_label($elementtype,$forceload=false)
774  {
775  // phpcs:enable
776  global $conf;
777 
778  if (empty($elementtype)) return array();
779 
780  if ($elementtype == 'thirdparty') $elementtype='societe';
781  if ($elementtype == 'contact') $elementtype='socpeople';
782  if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur';
783 
784  $array_name_label=array();
785 
786  // To avoid conflicts with external modules. TODO Remove this.
787  if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label;
788 
789  // Set array of label of entity
790  // TODO Remove completely loading of label. This should be done by presentation.
791  $labelmulticompany=array();
792  if (!empty($conf->multicompany->enabled))
793  {
794  $sql_entity_name='SELECT rowid, label FROM '.MAIN_DB_PREFIX.'entity WHERE rowid in (0,'.$conf->entity.')';
795  $resql_entity_name=$this->db->query($sql_entity_name);
796  if ($resql_entity_name)
797  {
798  while ($obj = $this->db->fetch_object($resql_entity_name))
799  {
800  $labelmulticompany[$obj->rowid]=$obj->label;
801  }
802  }
803  }
804 
805  // We should not have several time this log. If we have, there is some optimization to do by calling a simple $object->fetch_optionals() that include cache management.
806  dol_syslog("fetch_name_optionals_label elementtype=".$elementtype);
807 
808  $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help";
809  $sql.= " FROM ".MAIN_DB_PREFIX."extrafields";
810  $sql.= " WHERE entity IN (0,".$conf->entity.")";
811  if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element
812  $sql.= " ORDER BY pos";
813 
814  $resql=$this->db->query($sql);
815  if ($resql)
816  {
817  if ($this->db->num_rows($resql))
818  {
819  while ($tab = $this->db->fetch_object($resql))
820  {
821  // We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label']
822  if ($tab->type != 'separate')
823  {
824  $array_name_label[$tab->name]=$tab->label;
825  }
826 
827  // Old usage
828  $this->attribute_type[$tab->name]=$tab->type;
829  $this->attribute_label[$tab->name]=$tab->label;
830  $this->attribute_size[$tab->name]=$tab->size;
831  $this->attribute_elementtype[$tab->name]=$tab->elementtype;
832  $this->attribute_default[$tab->name]=$tab->fielddefault;
833  $this->attribute_computed[$tab->name]=$tab->fieldcomputed;
834  $this->attribute_unique[$tab->name]=$tab->fieldunique;
835  $this->attribute_required[$tab->name]=$tab->fieldrequired;
836  $this->attribute_param[$tab->name]=($tab->param ? unserialize($tab->param) : '');
837  $this->attribute_pos[$tab->name]=$tab->pos;
838  $this->attribute_alwayseditable[$tab->name]=$tab->alwayseditable;
839  $this->attribute_perms[$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms);
840  $this->attribute_langfile[$tab->name]=$tab->langs;
841  $this->attribute_list[$tab->name]=$tab->list;
842  $this->attribute_totalizable[$tab->name]=$tab->totalizable;
843  $this->attribute_entityid[$tab->name]=$tab->entity;
844  $this->attribute_entitylabel[$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]);
845 
846  // New usage
847  $this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type;
848  $this->attributes[$tab->elementtype]['label'][$tab->name]=$tab->label;
849  $this->attributes[$tab->elementtype]['size'][$tab->name]=$tab->size;
850  $this->attributes[$tab->elementtype]['elementtype'][$tab->name]=$tab->elementtype;
851  $this->attributes[$tab->elementtype]['default'][$tab->name]=$tab->fielddefault;
852  $this->attributes[$tab->elementtype]['computed'][$tab->name]=$tab->fieldcomputed;
853  $this->attributes[$tab->elementtype]['unique'][$tab->name]=$tab->fieldunique;
854  $this->attributes[$tab->elementtype]['required'][$tab->name]=$tab->fieldrequired;
855  $this->attributes[$tab->elementtype]['param'][$tab->name]=($tab->param ? unserialize($tab->param) : '');
856  $this->attributes[$tab->elementtype]['pos'][$tab->name]=$tab->pos;
857  $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name]=$tab->alwayseditable;
858  $this->attributes[$tab->elementtype]['perms'][$tab->name]=(strlen($tab->perms) == 0 ? 1 : $tab->perms);
859  $this->attributes[$tab->elementtype]['langfile'][$tab->name]=$tab->langs;
860  $this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list;
861  $this->attributes[$tab->elementtype]['totalizable'][$tab->name]=$tab->totalizable;
862  $this->attributes[$tab->elementtype]['entityid'][$tab->name]=$tab->entity;
863  $this->attributes[$tab->elementtype]['entitylabel'][$tab->name]=(empty($labelmulticompany[$tab->entity])?'Entity'.$tab->entity:$labelmulticompany[$tab->entity]);
864  $this->attributes[$tab->elementtype]['enabled'][$tab->name]=$tab->enabled;
865  $this->attributes[$tab->elementtype]['help'][$tab->name]=$tab->help;
866 
867  $this->attributes[$tab->elementtype]['loaded']=1;
868  }
869  }
870  if ($elementtype) $this->attributes[$elementtype]['loaded']=1; // If nothing found, we also save tag 'loaded'
871  }
872  else
873  {
874  $this->error=$this->db->lasterror();
875  dol_syslog(get_class($this)."::fetch_name_optionals_label ".$this->error, LOG_ERR);
876  }
877 
878  return $array_name_label;
879  }
880 
881 
896  function showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='')
897  {
898  global $conf,$langs,$form;
899 
900  if (! is_object($form))
901  {
902  require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
903  $form=new Form($this->db);
904  }
905 
906  $out='';
907 
908  $keyprefix = $keyprefix.'options_'; // Because we work on extrafields
909 
910  if (! empty($extrafieldsobjectkey))
911  {
912  $label=$this->attributes[$extrafieldsobjectkey]['label'][$key];
913  $type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
914  $size=$this->attributes[$extrafieldsobjectkey]['size'][$key];
915  $default=$this->attributes[$extrafieldsobjectkey]['default'][$key];
916  $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key];
917  $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key];
918  $required=$this->attributes[$extrafieldsobjectkey]['required'][$key];
919  $param=$this->attributes[$extrafieldsobjectkey]['param'][$key];
920  $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1);
921  $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key];
922  $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
923  $totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key];
924  $help=$this->attributes[$extrafieldsobjectkey]['help'][$key];
925  $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)
926  }
927  else // Old usage
928  {
929  $label=$this->attribute_label[$key];
930  $type =$this->attribute_type[$key];
931  $size =$this->attribute_size[$key];
932  $elementtype=$this->attribute_elementtype[$key]; // Seems not used
933  $default=$this->attribute_default[$key];
934  $computed=$this->attribute_computed[$key];
935  $unique=$this->attribute_unique[$key];
936  $required=$this->attribute_required[$key];
937  $param=$this->attribute_param[$key];
938  $langfile=$this->attribute_langfile[$key];
939  $list=$this->attribute_list[$key];
940  $totalizable=$this->attribute_totalizable[$key];
941  $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)
942  }
943 
944  if ($computed)
945  {
946  if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
947  else return '';
948  }
949 
950  if (empty($morecss))
951  {
952  if ($type == 'date')
953  {
954  $morecss = 'minwidth100imp';
955  }
956  elseif ($type == 'datetime')
957  {
958  $morecss = 'minwidth200imp';
959  }
960  elseif (in_array($type,array('int','integer','double','price')))
961  {
962  $morecss = 'maxwidth75';
963  }
964  elseif ($type == 'password')
965  {
966  $morecss='maxwidth100';
967  }
968  elseif ($type == 'url')
969  {
970  $morecss='minwidth400';
971  }
972  elseif ($type == 'boolean')
973  {
974  $morecss='';
975  }
976  else
977  {
978  if (round($size) < 12)
979  {
980  $morecss = 'minwidth100';
981  }
982  else if (round($size) <= 48)
983  {
984  $morecss = 'minwidth200';
985  }
986  else
987  {
988  $morecss = 'minwidth400';
989  }
990  }
991  }
992 
993  if (in_array($type,array('date','datetime')))
994  {
995  $tmp=explode(',',$size);
996  $newsize=$tmp[0];
997 
998  $showtime = in_array($type,array('datetime')) ? 1 : 0;
999 
1000  // Do not show current date when field not required (see selectDate() method)
1001  if (!$required && $value == '') $value = '-1';
1002 
1003  // TODO Must also support $moreparam
1004  $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1);
1005  }
1006  elseif (in_array($type,array('int','integer')))
1007  {
1008  $tmp=explode(',',$size);
1009  $newsize=$tmp[0];
1010  $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:'').'>';
1011  }
1012  elseif (preg_match('/varchar/', $type))
1013  {
1014  $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:'').'>';
1015  }
1016  elseif (in_array($type, array('mail', 'phone', 'url')))
1017  {
1018  $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1019  }
1020  elseif ($type == 'text')
1021  {
1022  if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
1023  {
1024  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1025  $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%');
1026  $out=$doleditor->Create(1);
1027  }
1028  else
1029  {
1030  $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1031  }
1032  }
1033  elseif ($type == 'html')
1034  {
1035  if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
1036  {
1037  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1038  $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%');
1039  $out=$doleditor->Create(1);
1040  }
1041  else
1042  {
1043  $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>';
1044  }
1045  }
1046  elseif ($type == 'boolean')
1047  {
1048  $checked='';
1049  if (!empty($value)) {
1050  $checked=' checked value="1" ';
1051  } else {
1052  $checked=' value="1" ';
1053  }
1054  $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>';
1055  }
1056  elseif ($type == 'price')
1057  {
1058  if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
1059  $value=price($value);
1060  }
1061  $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency);
1062  }
1063  elseif ($type == 'double')
1064  {
1065  if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
1066  $value=price($value);
1067  }
1068  $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> ';
1069  }
1070  elseif ($type == 'select')
1071  {
1072  $out = '';
1073  if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
1074  {
1075  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1076  $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1077  }
1078 
1079  $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
1080  $out.='<option value="0">&nbsp;</option>';
1081  foreach ($param['options'] as $key => $val)
1082  {
1083  if ((string) $key == '') continue;
1084  list($val, $parent) = explode('|', $val);
1085  $out.='<option value="'.$key.'"';
1086  $out.= (((string) $value == (string) $key)?' selected':'');
1087  $out.= (!empty($parent)?' parent="'.$parent.'"':'');
1088  $out.='>';
1089  if ($langfile && $val) $out.=$langs->trans($val);
1090  else $out.=$val;
1091  $out.='</option>';
1092  }
1093  $out.='</select>';
1094  }
1095  elseif ($type == 'sellist')
1096  {
1097  $out = '';
1098  if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2))
1099  {
1100  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1101  $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0);
1102  }
1103 
1104  $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>';
1105  if (is_array($param['options']))
1106  {
1107  $param_list=array_keys($param['options']);
1108  $InfoFieldList = explode(":", $param_list[0]);
1109  $parentName='';
1110  $parentField='';
1111  // 0 : tableName
1112  // 1 : label field name
1113  // 2 : key fields name (if differ of rowid)
1114  // 3 : key field parent (for dependent lists)
1115  // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
1116  $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid');
1117 
1118 
1119  if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4]))
1120  {
1121  if (strpos($InfoFieldList[4], 'extra.') !== false)
1122  {
1123  $keyList='main.'.$InfoFieldList[2].' as rowid';
1124  } else {
1125  $keyList=$InfoFieldList[2].' as rowid';
1126  }
1127  }
1128  if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3]))
1129  {
1130  list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
1131  $keyList.= ', '.$parentField;
1132  }
1133 
1134  $fields_label = explode('|',$InfoFieldList[1]);
1135  if (is_array($fields_label))
1136  {
1137  $keyList .=', ';
1138  $keyList .= implode(', ', $fields_label);
1139  }
1140 
1141  $sqlwhere='';
1142  $sql = 'SELECT '.$keyList;
1143  $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
1144  if (!empty($InfoFieldList[4]))
1145  {
1146  // can use curent entity filter
1147  if (strpos($InfoFieldList[4], '$ENTITY$')!==false) {
1148  $InfoFieldList[4]=str_replace('$ENTITY$',$conf->entity,$InfoFieldList[4]);
1149  }
1150  // can use SELECT request
1151  if (strpos($InfoFieldList[4], '$SEL$')!==false) {
1152  $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
1153  }
1154 
1155  // current object id can be use into filter
1156  if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
1157  $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
1158  } else {
1159  $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
1160  }
1161  //We have to join on extrafield table
1162  if (strpos($InfoFieldList[4], 'extra')!==false)
1163  {
1164  $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra';
1165  $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4];
1166  }
1167  else
1168  {
1169  $sqlwhere.= ' WHERE '.$InfoFieldList[4];
1170  }
1171  }
1172  else
1173  {
1174  $sqlwhere.= ' WHERE 1=1';
1175  }
1176  // Some tables may have field, some other not. For the moment we disable it.
1177  if (in_array($InfoFieldList[0],array('tablewithentity')))
1178  {
1179  $sqlwhere.= ' AND entity = '.$conf->entity;
1180  }
1181  $sql.=$sqlwhere;
1182  //print $sql;
1183 
1184  $sql .= ' ORDER BY ' . implode(', ', $fields_label);
1185 
1186  dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG);
1187  $resql = $this->db->query($sql);
1188  if ($resql)
1189  {
1190  $out.='<option value="0">&nbsp;</option>';
1191  $num = $this->db->num_rows($resql);
1192  $i = 0;
1193  while ($i < $num)
1194  {
1195  $labeltoshow='';
1196  $obj = $this->db->fetch_object($resql);
1197 
1198  // Several field into label (eq table:code|libelle:rowid)
1199  $notrans = false;
1200  $fields_label = explode('|',$InfoFieldList[1]);
1201  if (is_array($fields_label))
1202  {
1203  $notrans = true;
1204  foreach ($fields_label as $field_toshow)
1205  {
1206  $labeltoshow.= $obj->$field_toshow.' ';
1207  }
1208  }
1209  else
1210  {
1211  $labeltoshow=$obj->{$InfoFieldList[1]};
1212  }
1213  $labeltoshow=dol_trunc($labeltoshow,45);
1214 
1215  if ($value == $obj->rowid)
1216  {
1217  foreach ($fields_label as $field_toshow)
1218  {
1219  $translabel=$langs->trans($obj->$field_toshow);
1220  if ($translabel!=$obj->$field_toshow) {
1221  $labeltoshow=dol_trunc($translabel,18).' ';
1222  }else {
1223  $labeltoshow=dol_trunc($obj->$field_toshow,18).' ';
1224  }
1225  }
1226  $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
1227  }
1228  else
1229  {
1230  if (! $notrans)
1231  {
1232  $translabel=$langs->trans($obj->{$InfoFieldList[1]});
1233  if ($translabel!=$obj->{$InfoFieldList[1]}) {
1234  $labeltoshow=dol_trunc($translabel,18);
1235  }
1236  else {
1237  $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
1238  }
1239  }
1240  if (empty($labeltoshow)) $labeltoshow='(not defined)';
1241  if ($value==$obj->rowid)
1242  {
1243  $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
1244  }
1245 
1246  if (!empty($InfoFieldList[3]) && $parentField)
1247  {
1248  $parent = $parentName.':'.$obj->{$parentField};
1249  }
1250 
1251  $out.='<option value="'.$obj->rowid.'"';
1252  $out.= ($value==$obj->rowid?' selected':'');
1253  $out.= (!empty($parent)?' parent="'.$parent.'"':'');
1254  $out.='>'.$labeltoshow.'</option>';
1255  }
1256 
1257  $i++;
1258  }
1259  $this->db->free($resql);
1260  }
1261  else {
1262  print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>';
1263  }
1264  }
1265  $out.='</select>';
1266  }
1267  elseif ($type == 'checkbox')
1268  {
1269  $value_arr=explode(',',$value);
1270  $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%');
1271  }
1272  elseif ($type == 'radio')
1273  {
1274  $out='';
1275  foreach ($param['options'] as $keyopt => $val)
1276  {
1277  $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'');
1278  $out.=' value="'.$keyopt.'"';
1279  $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"';
1280  $out.= ($value==$keyopt?'checked':'');
1281  $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>';
1282  }
1283  }
1284  elseif ($type == 'chkbxlst')
1285  {
1286  if (is_array($value)) {
1287  $value_arr = $value;
1288  }
1289  else {
1290  $value_arr = explode(',', $value);
1291  }
1292 
1293  if (is_array($param['options'])) {
1294  $param_list = array_keys($param['options']);
1295  $InfoFieldList = explode(":", $param_list[0]);
1296  $parentName='';
1297  $parentField='';
1298  // 0 : tableName
1299  // 1 : label field name
1300  // 2 : key fields name (if differ of rowid)
1301  // 3 : key field parent (for dependent lists)
1302  // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
1303  $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid');
1304 
1305  if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
1306  list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
1307  $keyList .= ', ' . $parentField;
1308  }
1309  if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
1310  if (strpos($InfoFieldList[4], 'extra.') !== false) {
1311  $keyList = 'main.' . $InfoFieldList[2] . ' as rowid';
1312  } else {
1313  $keyList = $InfoFieldList[2] . ' as rowid';
1314  }
1315  }
1316 
1317  $fields_label = explode('|', $InfoFieldList[1]);
1318  if (is_array($fields_label)) {
1319  $keyList .= ', ';
1320  $keyList .= implode(', ', $fields_label);
1321  }
1322 
1323  $sqlwhere = '';
1324  $sql = 'SELECT ' . $keyList;
1325  $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0];
1326  if (! empty($InfoFieldList[4])) {
1327 
1328  // can use SELECT request
1329  if (strpos($InfoFieldList[4], '$SEL$')!==false) {
1330  $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
1331  }
1332 
1333  // current object id can be use into filter
1334  if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
1335  $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
1336  } else {
1337  $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
1338  }
1339 
1340  // We have to join on extrafield table
1341  if (strpos($InfoFieldList[4], 'extra') !== false) {
1342  $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra';
1343  $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4];
1344  } else {
1345  $sqlwhere .= ' WHERE ' . $InfoFieldList[4];
1346  }
1347  } else {
1348  $sqlwhere .= ' WHERE 1=1';
1349  }
1350  // Some tables may have field, some other not. For the moment we disable it.
1351  if (in_array($InfoFieldList[0], array ('tablewithentity')))
1352  {
1353  $sqlwhere .= ' AND entity = ' . $conf->entity;
1354  }
1355  // $sql.=preg_replace('/^ AND /','',$sqlwhere);
1356  // print $sql;
1357 
1358  $sql .= $sqlwhere;
1359  dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG);
1360  $resql = $this->db->query($sql);
1361  if ($resql) {
1362  $num = $this->db->num_rows($resql);
1363  $i = 0;
1364 
1365  $data=array();
1366 
1367  while ( $i < $num ) {
1368  $labeltoshow = '';
1369  $obj = $this->db->fetch_object($resql);
1370 
1371  $notrans = false;
1372  // Several field into label (eq table:code|libelle:rowid)
1373  $fields_label = explode('|', $InfoFieldList[1]);
1374  if (is_array($fields_label)) {
1375  $notrans = true;
1376  foreach ( $fields_label as $field_toshow ) {
1377  $labeltoshow .= $obj->$field_toshow . ' ';
1378  }
1379  } else {
1380  $labeltoshow = $obj->{$InfoFieldList[1]};
1381  }
1382  $labeltoshow = dol_trunc($labeltoshow, 45);
1383 
1384  if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1385  foreach ( $fields_label as $field_toshow ) {
1386  $translabel = $langs->trans($obj->$field_toshow);
1387  if ($translabel != $obj->$field_toshow) {
1388  $labeltoshow = dol_trunc($translabel, 18) . ' ';
1389  } else {
1390  $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' ';
1391  }
1392  }
1393 
1394  $data[$obj->rowid]=$labeltoshow;
1395  } else {
1396  if (! $notrans) {
1397  $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1398  if ($translabel != $obj->{$InfoFieldList[1]}) {
1399  $labeltoshow = dol_trunc($translabel, 18);
1400  } else {
1401  $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
1402  }
1403  }
1404  if (empty($labeltoshow))
1405  $labeltoshow = '(not defined)';
1406 
1407  if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1408  $data[$obj->rowid]=$labeltoshow;
1409  }
1410 
1411  if (! empty($InfoFieldList[3]) && $parentField) {
1412  $parent = $parentName . ':' . $obj->{$parentField};
1413  }
1414 
1415  $data[$obj->rowid]=$labeltoshow;
1416  }
1417 
1418  $i ++;
1419  }
1420  $this->db->free($resql);
1421 
1422  $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%');
1423  } else {
1424  print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>';
1425  }
1426  }
1427  }
1428  elseif ($type == 'link')
1429  {
1430  $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
1431  $showempty=(($required && $default != '')?0:1);
1432  $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty);
1433  }
1434  elseif ($type == 'password')
1435  {
1436  // If prefix is 'search_', field is used as a filter, we use a common text field.
1437  $out='<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug.
1438  $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:'').'>';
1439  }
1440  if (!empty($hidden)) {
1441  $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>';
1442  }
1443  /* Add comments
1444  if ($type == 'date') $out.=' (YYYY-MM-DD)';
1445  elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)';
1446  */
1447  return $out;
1448  }
1449 
1450 
1460  function showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='')
1461  {
1462  global $conf,$langs;
1463 
1464  if (! empty($extrafieldsobjectkey))
1465  {
1466  $label=$this->attributes[$extrafieldsobjectkey]['label'][$key];
1467  $type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
1468  $size=$this->attributes[$extrafieldsobjectkey]['size'][$key];
1469  $default=$this->attributes[$extrafieldsobjectkey]['default'][$key];
1470  $computed=$this->attributes[$extrafieldsobjectkey]['computed'][$key];
1471  $unique=$this->attributes[$extrafieldsobjectkey]['unique'][$key];
1472  $required=$this->attributes[$extrafieldsobjectkey]['required'][$key];
1473  $param=$this->attributes[$extrafieldsobjectkey]['param'][$key];
1474  $perms=dol_eval($this->attributes[$extrafieldsobjectkey]['perms'][$key], 1);
1475  $langfile=$this->attributes[$extrafieldsobjectkey]['langfile'][$key];
1476  $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1);
1477  $help=$this->attributes[$extrafieldsobjectkey]['help'][$key];
1478  $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)
1479  }
1480  else // Old usage
1481  {
1482  $label=$this->attribute_label[$key];
1483  $type=$this->attribute_type[$key];
1484  $size=$this->attribute_size[$key];
1485  $default=$this->attribute_default[$key];
1486  $computed=$this->attribute_computed[$key];
1487  $unique=$this->attribute_unique[$key];
1488  $required=$this->attribute_required[$key];
1489  $param=$this->attribute_param[$key];
1490  $perms=dol_eval($this->attribute_perms[$key], 1);
1491  $langfile=$this->attribute_langfile[$key];
1492  $list=dol_eval($this->attribute_list[$key], 1);
1493  $help=''; // Not supported with old syntax
1494  $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)
1495  }
1496 
1497  if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method.
1498 
1499  // If field is a computed field, value must become result of compute
1500  if ($computed)
1501  {
1502  // Make the eval of compute string
1503  //var_dump($computed);
1504  $value = dol_eval($computed, 1, 0);
1505  }
1506 
1507  $showsize=0;
1508  if ($type == 'date')
1509  {
1510  $showsize=10;
1511  $value=dol_print_date($value, 'day');
1512  }
1513  elseif ($type == 'datetime')
1514  {
1515  $showsize=19;
1516  $value=dol_print_date($value, 'dayhour');
1517  }
1518  elseif ($type == 'int')
1519  {
1520  $showsize=10;
1521  }
1522  elseif ($type == 'double')
1523  {
1524  if (!empty($value)) {
1525  $value=price($value);
1526  }
1527  }
1528  elseif ($type == 'boolean')
1529  {
1530  $checked='';
1531  if (!empty($value)) {
1532  $checked=' checked ';
1533  }
1534  $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>';
1535  }
1536  elseif ($type == 'mail')
1537  {
1538  $value=dol_print_email($value, 0, 0, 0, 64, 1, 1);
1539  }
1540  elseif ($type == 'url')
1541  {
1542  $value=dol_print_url($value,'_blank',32,1);
1543  }
1544  elseif ($type == 'phone')
1545  {
1546  $value=dol_print_phone($value, '', 0, 0, '', '&nbsp;', 1);
1547  }
1548  elseif ($type == 'price')
1549  {
1550  $value=price($value, 0, $langs, 0, 0, -1, $conf->currency);
1551  }
1552  elseif ($type == 'select')
1553  {
1554  if ($langfile && $param['options'][$value]) $value=$langs->trans($param['options'][$value]);
1555  else $value=$param['options'][$value];
1556  }
1557  elseif ($type == 'sellist')
1558  {
1559  $param_list=array_keys($param['options']);
1560  $InfoFieldList = explode(":", $param_list[0]);
1561 
1562  $selectkey="rowid";
1563  $keyList='rowid';
1564 
1565  if (count($InfoFieldList)>=3)
1566  {
1567  $selectkey = $InfoFieldList[2];
1568  $keyList=$InfoFieldList[2].' as rowid';
1569  }
1570 
1571  $fields_label = explode('|',$InfoFieldList[1]);
1572  if(is_array($fields_label)) {
1573  $keyList .=', ';
1574  $keyList .= implode(', ', $fields_label);
1575  }
1576 
1577  $sql = 'SELECT '.$keyList;
1578  $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0];
1579  if (strpos($InfoFieldList[4], 'extra')!==false)
1580  {
1581  $sql.= ' as main';
1582  }
1583  if ($selectkey=='rowid' && empty($value)) {
1584  $sql.= " WHERE ".$selectkey."=0";
1585  } elseif ($selectkey=='rowid') {
1586  $sql.= " WHERE ".$selectkey."=".$this->db->escape($value);
1587  }else {
1588  $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1589  }
1590 
1591  //$sql.= ' AND entity = '.$conf->entity;
1592 
1593  dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG);
1594  $resql = $this->db->query($sql);
1595  if ($resql)
1596  {
1597  $value=''; // value was used, so now we reste it to use it to build final output
1598 
1599  $obj = $this->db->fetch_object($resql);
1600 
1601  // Several field into label (eq table:code|libelle:rowid)
1602  $fields_label = explode('|',$InfoFieldList[1]);
1603 
1604  if(is_array($fields_label) && count($fields_label)>1)
1605  {
1606  foreach ($fields_label as $field_toshow)
1607  {
1608  $translabel='';
1609  if (!empty($obj->$field_toshow)) {
1610  $translabel=$langs->trans($obj->$field_toshow);
1611  }
1612  if ($translabel!=$field_toshow) {
1613  $value.=dol_trunc($translabel,18).' ';
1614  }else {
1615  $value.=$obj->$field_toshow.' ';
1616  }
1617  }
1618  }
1619  else
1620  {
1621  $translabel='';
1622  if (!empty($obj->{$InfoFieldList[1]})) {
1623  $translabel=$langs->trans($obj->{$InfoFieldList[1]});
1624  }
1625  if ($translabel!=$obj->{$InfoFieldList[1]}) {
1626  $value=dol_trunc($translabel,18);
1627  }else {
1628  $value=$obj->{$InfoFieldList[1]};
1629  }
1630  }
1631  }
1632  else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING);
1633  }
1634  elseif ($type == 'radio')
1635  {
1636  $value=$param['options'][$value];
1637  }
1638  elseif ($type == 'checkbox')
1639  {
1640  $value_arr=explode(',',$value);
1641  $value='';
1642  $toprint=array();
1643  if (is_array($value_arr))
1644  {
1645  foreach ($value_arr as $keyval=>$valueval) {
1646  $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>';
1647  }
1648  }
1649  $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
1650  }
1651  elseif ($type == 'chkbxlst')
1652  {
1653  $value_arr = explode(',', $value);
1654 
1655  $param_list = array_keys($param['options']);
1656  $InfoFieldList = explode(":", $param_list[0]);
1657 
1658  $selectkey = "rowid";
1659  $keyList = 'rowid';
1660 
1661  if (count($InfoFieldList) >= 3) {
1662  $selectkey = $InfoFieldList[2];
1663  $keyList = $InfoFieldList[2] . ' as rowid';
1664  }
1665 
1666  $fields_label = explode('|', $InfoFieldList[1]);
1667  if (is_array($fields_label)) {
1668  $keyList .= ', ';
1669  $keyList .= implode(', ', $fields_label);
1670  }
1671 
1672  $sql = 'SELECT ' . $keyList;
1673  $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0];
1674  if (strpos($InfoFieldList[4], 'extra') !== false) {
1675  $sql .= ' as main';
1676  }
1677  // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'";
1678  // $sql.= ' AND entity = '.$conf->entity;
1679 
1680  dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG);
1681  $resql = $this->db->query($sql);
1682  if ($resql) {
1683  $value = ''; // value was used, so now we reste it to use it to build final output
1684  $toprint=array();
1685  while ( $obj = $this->db->fetch_object($resql) ) {
1686 
1687  // Several field into label (eq table:code|libelle:rowid)
1688  $fields_label = explode('|', $InfoFieldList[1]);
1689  if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
1690  if (is_array($fields_label) && count($fields_label) > 1) {
1691  foreach ( $fields_label as $field_toshow ) {
1692  $translabel = '';
1693  if (! empty($obj->$field_toshow)) {
1694  $translabel = $langs->trans($obj->$field_toshow);
1695  }
1696  if ($translabel != $field_toshow) {
1697  $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>';
1698  } else {
1699  $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>';
1700  }
1701  }
1702  } else {
1703  $translabel = '';
1704  if (! empty($obj->{$InfoFieldList[1]})) {
1705  $translabel = $langs->trans($obj->{$InfoFieldList[1]});
1706  }
1707  if ($translabel != $obj->{$InfoFieldList[1]}) {
1708  $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>';
1709  } else {
1710  $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
1711  }
1712  }
1713  }
1714  }
1715  $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
1716  } else {
1717  dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING);
1718  }
1719  }
1720  elseif ($type == 'link')
1721  {
1722  $out='';
1723 
1724  // Only if something to display (perf)
1725  if ($value) // If we have -1 here, pb is into sert, not into ouptu
1726  {
1727  $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath'
1728 
1729  $InfoFieldList = explode(":", $param_list[0]);
1730  $classname=$InfoFieldList[0];
1731  $classpath=$InfoFieldList[1];
1732  if (! empty($classpath))
1733  {
1734  dol_include_once($InfoFieldList[1]);
1735  if ($classname && class_exists($classname))
1736  {
1737  $object = new $classname($this->db);
1738  $object->fetch($value);
1739  $value=$object->getNomUrl(3);
1740  }
1741  }
1742  else
1743  {
1744  dol_syslog('Error bad setup of extrafield', LOG_WARNING);
1745  return 'Error bad setup of extrafield';
1746  }
1747  }
1748  }
1749  elseif ($type == 'text')
1750  {
1751  $value=dol_htmlentitiesbr($value);
1752  }
1753  elseif ($type == 'html')
1754  {
1755  $value=dol_htmlentitiesbr($value);
1756  }
1757  elseif ($type == 'password')
1758  {
1759  $value=dol_trunc(preg_replace('/./i','*',$value), 8, 'right', 'UTF-8', 1);
1760  }
1761  else
1762  {
1763  $showsize=round($size);
1764  if ($showsize > 48) $showsize=48;
1765  }
1766 
1767  //print $type.'-'.$size;
1768  $out=$value;
1769 
1770  return $out;
1771  }
1772 
1780  function getAlignFlag($key, $extrafieldsobjectkey='')
1781  {
1782  global $conf,$langs;
1783 
1784  if (! empty($extrafieldsobjectkey)) $type=$this->attributes[$extrafieldsobjectkey]['type'][$key];
1785  else $type=$this->attribute_type[$key];
1786 
1787  $align='';
1788 
1789  if ($type == 'date')
1790  {
1791  $align="center";
1792  }
1793  elseif ($type == 'datetime')
1794  {
1795  $align="center";
1796  }
1797  elseif ($type == 'int')
1798  {
1799  $align="right";
1800  }
1801  elseif ($type == 'double')
1802  {
1803  $align="right";
1804  }
1805  elseif ($type == 'boolean')
1806  {
1807  $align="center";
1808  }
1809  elseif ($type == 'radio')
1810  {
1811  $align="center";
1812  }
1813  elseif ($type == 'checkbox')
1814  {
1815  $align="center";
1816  }
1817  elseif ($type == 'price')
1818  {
1819  $align="right";
1820  }
1821 
1822  return $align;
1823  }
1824 
1832  function showSeparator($key, $object)
1833  {
1834  global $langs;
1835 
1836  $out = '<tr class="trextrafieldseparator trextrafieldseparator'.$key.'"><td colspan="2"><strong>';
1837  $out.= $langs->trans($this->attributes[$object->table_element]['label'][$key]);
1838  $out.= '</strong></td></tr>';
1839  return $out;
1840  }
1841 
1850  function setOptionalsFromPost($extralabels, &$object, $onlykey='')
1851  {
1852  global $_POST, $langs;
1853  $nofillrequired='';// For error when required field left blank
1854  $error_field_required = array();
1855 
1856  if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label'];
1857 
1858  if (is_array($extralabels))
1859  {
1860  // Get extra fields
1861  foreach ($extralabels as $key => $value)
1862  {
1863  if (! empty($onlykey) && $key != $onlykey) continue;
1864 
1865  $key_type = $this->attributes[$object->table_element]['type'][$key];
1866  if ($key_type == 'separate') continue;
1867 
1868  $enabled = 1;
1869  if (isset($this->attributes[$object->table_element]['list'][$key]))
1870  {
1871  $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1);
1872  }
1873  $perms = 1;
1874  if (isset($this->attributes[$object->table_element]['perms'][$key]))
1875  {
1876  $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1);
1877  }
1878  if (empty($enabled)) continue;
1879  if (empty($perms)) continue;
1880 
1881  if ($this->attributes[$object->table_element]['required'][$key]) // Value is required
1882  {
1883  // Check if empty without using GETPOST, value can be alpha, int, array, etc...
1884  if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0')
1885  || (is_array($_POST["options_".$key]) && empty($_POST["options_".$key])))
1886  {
1887  //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key];
1888  $nofillrequired++;
1889  $error_field_required[] = $langs->transnoentitiesnoconv($value);
1890  }
1891  }
1892 
1893  if (in_array($key_type,array('date')))
1894  {
1895  // Clean parameters
1896  // TODO GMT date in memory must be GMT so we should add gm=true in parameters
1897  $value_key=dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
1898  }
1899  elseif (in_array($key_type,array('datetime')))
1900  {
1901  // Clean parameters
1902  // TODO GMT date in memory must be GMT so we should add gm=true in parameters
1903  $value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]);
1904  }
1905  else if (in_array($key_type,array('checkbox','chkbxlst')))
1906  {
1907  $value_arr=GETPOST("options_".$key, 'array'); // check if an array
1908  if (!empty($value_arr)) {
1909  $value_key=implode($value_arr,',');
1910  }else {
1911  $value_key='';
1912  }
1913  }
1914  else if (in_array($key_type,array('price','double')))
1915  {
1916  $value_arr=GETPOST("options_".$key, 'alpha');
1917  $value_key=price2num($value_arr);
1918  }
1919  else
1920  {
1921  $value_key=GETPOST("options_".$key);
1922  }
1923 
1924  $object->array_options["options_".$key]=$value_key;
1925  }
1926 
1927  if ($nofillrequired) {
1928  $langs->load('errors');
1929  setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors');
1930  return -1;
1931  }
1932  else {
1933  return 1;
1934  }
1935  }
1936  else {
1937  return 0;
1938  }
1939  }
1940 
1949  function getOptionalsFromPost($extrafieldsobjectkey, $keyprefix='', $keysuffix='')
1950  {
1951  global $_POST;
1952 
1953  if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label']))
1954  {
1955  $extralabels = $this->attributes[$extrafieldsobjectkey]['label'];
1956  }
1957  else
1958  {
1959  $extralabels = $extrafieldsobjectkey;
1960  }
1961 
1962  if (is_array($extralabels))
1963  {
1964  $array_options = array();
1965 
1966  // Get extra fields
1967  foreach ($extralabels as $key => $value)
1968  {
1969  $key_type = '';
1970  if (is_string($extrafieldsobjectkey))
1971  {
1972  $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key];
1973  }
1974 
1975  if (in_array($key_type,array('date','datetime')))
1976  {
1977  // Clean parameters
1978  $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]);
1979  }
1980  else if (in_array($key_type,array('checkbox', 'chkbxlst')))
1981  {
1982  $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
1983  // Make sure we get an array even if there's only one checkbox
1984  $value_arr=(array) $value_arr;
1985  $value_key=implode(',', $value_arr);
1986  }
1987  else if (in_array($key_type,array('price','double')))
1988  {
1989  $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix);
1990  $value_key=price2num($value_arr);
1991  }
1992  else
1993  {
1994  $value_key=GETPOST($keysuffix."options_".$key.$keyprefix);
1995  }
1996 
1997  $array_options[$keysuffix."options_".$key]=$value_key; // No keyprefix here. keyprefix is used only for read.
1998  }
1999 
2000  return $array_options;
2001  }
2002 
2003  return 0;
2004  }
2005 }
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)
Modify description of personalized attribute.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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')
Add a new extra field parameter.
print
Draft customers invoices.
Definition: index.php:91
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
showInputField($key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss='', $objectid=0, $extrafieldsobjectkey='')
Return HTML string to put an input field into a page Code very similar with showInputField of common ...
dol_print_url($url, $target='_blank', $max=32, $withpicto=0)
Show Url link.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
__construct($db)
Constructor.
getAlignFlag($key, $extrafieldsobjectkey='')
Return tag to describe alignement to use for this extrafield.
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)
Modify type of a personalized attribute.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
setOptionalsFromPost($extralabels, &$object, $onlykey='')
Fill array_options property of object by extrafields value (using for data sent by forms) ...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
if(! function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='', $param='', $perms='', $list='0', $computed='')
Add a new optional attribute.
showOutputField($key, $value, $moreparam='', $extrafieldsobjectkey='')
Return HTML string to put an output field into a page.
delete_label($attrname, $elementtype='member')
Delete description of an optional attribute.
dol_now($mode='gmt')
Return date for now.
showSeparator($key, $object)
Return HTML string to print separator extrafield.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
fetch_name_optionals_label($elementtype, $forceload=false)
Load array this->attributes, or old this->attribute_xxx like attribute_label, attribute_type, ...
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Class to manage a WYSIWYG editor.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ="&nbsp;", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
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')
Add description of a new optional attribute.
getOptionalsFromPost($extrafieldsobjectkey, $keyprefix='', $keysuffix='')
return array_options array of data of extrafields value of object sent by a search form ...