dolibarr  9.0.0
html.formcompany.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2008-2012 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2008-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
33 {
37  public $db;
38 
42  public $error='';
43 
49  function __construct($db)
50  {
51  $this->db = $db;
52  }
53 
54 
55  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
63  function typent_array($mode=0, $filter='')
64  {
65  // phpcs:enable
66  global $langs,$mysoc;
67 
68  $effs = array();
69 
70  $sql = "SELECT id, code, libelle";
71  $sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
72  $sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
73  if ($filter) $sql.=" ".$filter;
74  $sql.= " ORDER by position, id";
75  dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
76  $resql=$this->db->query($sql);
77  if ($resql)
78  {
79  $num = $this->db->num_rows($resql);
80  $i = 0;
81 
82  while ($i < $num)
83  {
84  $objp = $this->db->fetch_object($resql);
85  if (! $mode) $key=$objp->id;
86  else $key=$objp->code;
87  if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
88  else $effs[$key] = $objp->libelle;
89  if ($effs[$key]=='-') $effs[$key]='';
90  $i++;
91  }
92  $this->db->free($resql);
93  }
94 
95  return $effs;
96  }
97 
98  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
106  function effectif_array($mode=0, $filter='')
107  {
108  // phpcs:enable
109  $effs = array();
110 
111  $sql = "SELECT id, code, libelle";
112  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
113  $sql.= " WHERE active = 1";
114  if ($filter) $sql.=" ".$filter;
115  $sql .= " ORDER BY id ASC";
116  dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
117  $resql=$this->db->query($sql);
118  if ($resql)
119  {
120  $num = $this->db->num_rows($resql);
121  $i = 0;
122 
123  while ($i < $num)
124  {
125  $objp = $this->db->fetch_object($resql);
126  if (! $mode) $key=$objp->id;
127  else $key=$objp->code;
128 
129  $effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
130  $i++;
131  }
132  $this->db->free($resql);
133  }
134  return $effs;
135  }
136 
137 
138  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
148  function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
149  {
150  // phpcs:enable
151  global $user, $langs;
152 
153  print '<form method="post" action="'.$page.'">';
154  print '<input type="hidden" name="action" value="setprospectlevel">';
155  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
156 
157  dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
158  $sql = "SELECT code, label";
159  $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
160  $sql.= " WHERE active > 0";
161  $sql.= " ORDER BY sortorder";
162  $resql = $this->db->query($sql);
163  if ($resql)
164  {
165  $options = array();
166 
167  if ($empty) {
168  $options[''] = '';
169  }
170 
171  while ($obj = $this->db->fetch_object($resql)) {
172  $level = $langs->trans($obj->code);
173 
174  if ($level == $obj->code) {
175  $level = $langs->trans($obj->label);
176  }
177 
178  $options[$obj->code] = $level;
179  }
180 
181  print Form::selectarray($htmlname, $options, $selected);
182  }
183  else dol_print_error($this->db);
184  if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
185  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186  print '</form>';
187  }
188 
189  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
202  function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
203  {
204  // phpcs:enable
205  print $this->select_state($selected,$country_codeid, $htmlname);
206  }
207 
208  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
222  function select_state($selected='',$country_codeid=0, $htmlname='state_id')
223  {
224  // phpcs:enable
225  global $conf,$langs,$user;
226 
227  dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
228 
229  $langs->load("dict");
230 
231  $out='';
232 
233  // Serch departements/cantons/province active d'une region et pays actif
234  $sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
235  $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
236  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
237  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
238  if ($country_codeid && is_numeric($country_codeid)) $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
239  if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
240  $sql .= " ORDER BY c.code, d.code_departement";
241 
242  $result=$this->db->query($sql);
243  if ($result)
244  {
245  if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246  if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
247  $num = $this->db->num_rows($result);
248  $i = 0;
249  dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
250  if ($num)
251  {
252  $country='';
253  while ($i < $num)
254  {
255  $obj = $this->db->fetch_object($result);
256  if ($obj->code == '0') // Le code peut etre une chaine
257  {
258  $out.= '<option value="0">&nbsp;</option>';
259  }
260  else {
261  if (! $country || $country != $obj->country)
262  {
263  // Affiche la rupture si on est en mode liste multipays
264  if (! $country_codeid && $obj->country_code)
265  {
266  $out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
267  $country=$obj->country;
268  }
269  }
270 
271  if ((! empty($selected) && $selected == $obj->rowid)
272  || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
273  {
274  $out.= '<option value="'.$obj->rowid.'" selected>';
275  }
276  else
277  {
278  $out.= '<option value="'.$obj->rowid.'">';
279  }
280 
281  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
282  if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
283  ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
284  if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285  $out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
286  }
287  else {
288  $out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
289  }
290  }
291  else {
292  if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293  $out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
294  }
295  else {
296  $out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
297  }
298  }
299 
300  $out.= '</option>';
301  }
302  $i++;
303  }
304  }
305  if (! empty($htmlname)) $out.= '</select>';
306  if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
307  }
308  else
309  {
310  dol_print_error($this->db);
311  }
312 
313  // Make select dynamic
314  if (! empty($htmlname))
315  {
316  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
317  $out .= ajax_combobox($htmlname);
318  }
319 
320  return $out;
321  }
322 
323 
324  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
335  function select_region($selected='',$htmlname='region_id')
336  {
337  // phpcs:enable
338  global $conf,$langs;
339  $langs->load("dict");
340 
341  $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
342  $sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
343  $sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
344  $sql.= " ORDER BY c.code, c.label ASC";
345 
346  dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
347  $resql=$this->db->query($sql);
348  if ($resql)
349  {
350  print '<select class="flat" name="'.$htmlname.'">';
351  $num = $this->db->num_rows($resql);
352  $i = 0;
353  if ($num)
354  {
355  $country='';
356  while ($i < $num)
357  {
358  $obj = $this->db->fetch_object($resql);
359  if ($obj->code == 0) {
360  print '<option value="0">&nbsp;</option>';
361  }
362  else {
363  if ($country == '' || $country != $obj->country)
364  {
365  // Show break
366  $key=$langs->trans("Country".strtoupper($obj->country_code));
367  $valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
368  print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
369  $country=$obj->country;
370  }
371 
372  if ($selected > 0 && $selected == $obj->code)
373  {
374  print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
375  }
376  else
377  {
378  print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
379  }
380  }
381  $i++;
382  }
383  }
384  print '</select>';
385  }
386  else
387  {
388  dol_print_error($this->db);
389  }
390  }
391 
392  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
401  function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
402  {
403  // phpcs:enable
404  global $conf,$langs,$user;
405  $langs->load("dict");
406 
407  $out='';
408 
409  $sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
410  $sql.= " WHERE active = 1";
411 
412  dol_syslog("Form::select_civility", LOG_DEBUG);
413  $resql=$this->db->query($sql);
414  if ($resql)
415  {
416  $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
417  $out.= '<option value="">&nbsp;</option>';
418  $num = $this->db->num_rows($resql);
419  $i = 0;
420  if ($num)
421  {
422  while ($i < $num)
423  {
424  $obj = $this->db->fetch_object($resql);
425  if ($selected == $obj->code)
426  {
427  $out.= '<option value="'.$obj->code.'" selected>';
428  }
429  else
430  {
431  $out.= '<option value="'.$obj->code.'">';
432  }
433  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
434  $out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
435  $out.= '</option>';
436  $i++;
437  }
438  }
439  $out.= '</select>';
440  if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
441  }
442  else
443  {
444  dol_print_error($this->db);
445  }
446 
447  return $out;
448  }
449 
450  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
462  function select_forme_juridique($selected='', $country_codeid=0, $filter='')
463  {
464  // phpcs:enable
465  print $this->select_juridicalstatus($selected, $country_codeid, $filter);
466  }
467 
468  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
479  function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
480  {
481  // phpcs:enable
482  global $conf,$langs,$user;
483  $langs->load("dict");
484 
485  $out='';
486 
487  // On recherche les formes juridiques actives des pays actifs
488  $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
489  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
490  $sql .= " WHERE f.fk_pays=c.rowid";
491  $sql .= " AND f.active = 1 AND c.active = 1";
492  if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
493  if ($filter) $sql .= " ".$filter;
494  $sql .= " ORDER BY c.code";
495 
496  dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
497  $resql=$this->db->query($sql);
498  if ($resql)
499  {
500  $out.= '<div id="particulier2" class="visible">';
501  $out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502  if ($country_codeid) $out.= '<option value="0">&nbsp;</option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
503 
504  $num = $this->db->num_rows($resql);
505  if ($num)
506  {
507  $i = 0;
508  $country=''; $arraydata=array();
509  while ($i < $num)
510  {
511  $obj = $this->db->fetch_object($resql);
512 
513  if ($obj->code) // We exclude empty line, we will add it later
514  {
515  $labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
516  $labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:'')); // $obj->label is already in output charset (converted by database driver)
517  $arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
518  }
519  $i++;
520  }
521 
522  $arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
523  if (empty($country_codeid)) // Introduce empty value (if $country_codeid not empty, empty value was already added)
524  {
525  $arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
526  }
527 
528  foreach($arraydata as $key => $val)
529  {
530  if (! $country || $country != $val['country'])
531  {
532  // Show break when we are in multi country mode
533  if (empty($country_codeid) && $val['country_code'])
534  {
535  $out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
536  $country=$val['country'];
537  }
538  }
539 
540  if ($selected > 0 && $selected == $val['code'])
541  {
542  $out.= '<option value="'.$val['code'].'" selected>';
543  }
544  else
545  {
546  $out.= '<option value="'.$val['code'].'">';
547  }
548  // If translation exists, we use it, otherwise we use default label in database
549  $out.= $val['label'];
550  $out.= '</option>';
551  }
552  }
553  $out.= '</select>';
554  if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
555 
556  // Make select dynamic
557  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
558  $out .= ajax_combobox($htmlname);
559 
560  $out.= '</div>';
561  }
562  else
563  {
564  dol_print_error($this->db);
565  }
566 
567  return $out;
568  }
569 
570 
584  function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
585  {
586  global $conf, $langs;
587 
588  if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
589  {
590  // Use Ajax search
591  $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
592 
593  $socid=0; $name='';
594  if ($selected > 0)
595  {
596  $tmpthirdparty=new Societe($this->db);
597  $result = $tmpthirdparty->fetch($selected);
598  if ($result > 0)
599  {
600  $socid = $selected;
601  $name = $tmpthirdparty->name;
602  }
603  }
604 
605 
606  $events=array();
607  // Add an entry 'method' to say 'yes, we must execute url with param action = method';
608  // Add an entry 'url' to say which url to execute
609  // Add an entry htmlname to say which element we must change once url is called
610  // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines
611  // To refresh contacts list on thirdparty list change
612  $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
613 
614  if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events
615  {
616  print '<script type="text/javascript">
617  jQuery(document).ready(function() {
618  $("#search_'.$htmlname.'").change(function() {
619  var obj = '.json_encode($events).';
620  $.each(obj, function(key,values) {
621  if (values.method.length) {
622  runJsCodeForEvent'.$htmlname.'(values);
623  }
624  });
625 
626  $(this).trigger("blur");
627  });
628 
629  // Function used to execute events when search_htmlname change
630  function runJsCodeForEvent'.$htmlname.'(obj) {
631  var id = $("#'.$htmlname.'").val();
632  var method = obj.method;
633  var url = obj.url;
634  var htmlname = obj.htmlname;
635  var showempty = obj.showempty;
636  console.log("Run runJsCodeForEvent-'.$htmlname.' from selectCompaniesForNewContact id="+id+" method="+method+" showempty="+showempty+" url="+url+" htmlname="+htmlname);
637  $.getJSON(url,
638  {
639  action: method,
640  id: id,
641  htmlname: htmlname
642  },
643  function(response) {
644  if (response != null)
645  {
646  console.log("Change select#"+htmlname+" with content "+response.value)
647  $.each(obj.params, function(key,action) {
648  if (key.length) {
649  var num = response.num;
650  if (num > 0) {
651  $("#" + key).removeAttr(action);
652  } else {
653  $("#" + key).attr(action, action);
654  }
655  }
656  });
657  $("select#" + htmlname).html(response.value);
658  }
659  }
660  );
661  };
662  });
663  </script>';
664  }
665 
666  print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
667  print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
668  print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
669  return $socid;
670  }
671  else
672  {
673  // Search to list thirdparties
674  $sql = "SELECT s.rowid, s.nom as name FROM";
675  $sql.= " ".MAIN_DB_PREFIX."societe as s";
676  $sql.= " WHERE s.entity IN (".getEntity('societe').")";
677  // For ajax search we limit here. For combo list, we limit later
678  if (is_array($limitto) && count($limitto))
679  {
680  $sql.= " AND s.rowid IN (".join(',',$limitto).")";
681  }
682  $sql.= " ORDER BY s.nom ASC";
683 
684  $resql = $this->db->query($sql);
685  if ($resql)
686  {
687  print '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"';
688  if ($conf->use_javascript_ajax)
689  {
690  $javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
691  print ' onChange="'.$javaScript.'"';
692  }
693  print '>';
694  $num = $this->db->num_rows($resql);
695  $i = 0;
696  if ($num)
697  {
698  while ($i < $num)
699  {
700  $obj = $this->db->fetch_object($resql);
701  if ($i == 0) $firstCompany = $obj->rowid;
702  $disabled=0;
703  if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
704  if ($selected > 0 && $selected == $obj->rowid)
705  {
706  print '<option value="'.$obj->rowid.'"';
707  if ($disabled) print ' disabled';
708  print ' selected>'.dol_trunc($obj->name,24).'</option>';
709  $firstCompany = $obj->rowid;
710  }
711  else
712  {
713  print '<option value="'.$obj->rowid.'"';
714  if ($disabled) print ' disabled';
715  print '>'.dol_trunc($obj->name,24).'</option>';
716  }
717  $i ++;
718  }
719  }
720  print "</select>\n";
721  return $firstCompany;
722  }
723  else
724  {
725  dol_print_error($this->db);
726  print 'Error sql';
727  }
728  }
729  }
730 
743  function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
744  {
745  global $user, $langs;
746 
747  if (is_object($object) && method_exists($object, 'liste_type_contact'))
748  {
749  $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
750  print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
751  if ($showempty) print '<option value="0"></option>';
752  foreach($lesTypes as $key=>$value)
753  {
754  print '<option value="'.$key.'"';
755  if ($key == $selected) print ' selected';
756  print '>'.$value.'</option>';
757  }
758  print "</select>";
759  if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
760  print "\n";
761  }
762  }
763 
764  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
777  function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
778  {
779  // phpcs:enable
780  global $conf;
781 
782  $out='';
783 
784  $size='';
785  if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
786 
787  if ($conf->use_javascript_ajax && empty($disableautocomplete))
788  {
789  $out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
790  $moreattrib.=' autocomplete="off"';
791  }
792  $out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
793 
794  return $out;
795  }
796 
797  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
808  function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
809  {
810  // phpcs:enable
811  global $conf,$langs;
812 
813  $formlength=0;
814  if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
815  if ($country_code == 'FR')
816  {
817  if (isset($idprof)) {
818  if ($idprof==1) $formlength=9;
819  else if ($idprof==2) $formlength=14;
820  else if ($idprof==3) $formlength=5; // 4 chiffres et 1 lettre depuis janvier
821  else if ($idprof==4) $formlength=32; // No maximum as we need to include a town name in this id
822  }
823  }
824  else if ($country_code == 'ES')
825  {
826  if ($idprof==1) $formlength=9; //CIF/NIF/NIE 9 digits
827  if ($idprof==2) $formlength=12; //NASS 12 digits without /
828  if ($idprof==3) $formlength=5; //CNAE 5 digits
829  if ($idprof==4) $formlength=32; //depend of college
830  }
831  }
832 
833  $selected=$preselected;
834  if (! $selected && isset($idprof)) {
835  if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
836  else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
837  else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
838  else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
839  }
840 
841  $maxlength=$formlength;
842  if (empty($formlength)) { $formlength=24; $maxlength=128; }
843 
844  $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
845 
846  return $out;
847  }
848 
849  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
858  function select_localtax($local, $selected, $htmlname)
859  {
860  // phpcs:enable
861  $tax=get_localtax_by_third($local);
862 
863  $num = $this->db->num_rows($tax);
864  $i = 0;
865  if ($num)
866  {
867  $valors=explode(":", $tax);
868 
869  if (count($valors) > 1)
870  {
871  //montar select
872  print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
873  while ($i <= (count($valors))-1)
874  {
875  if ($selected == $valors[$i])
876  {
877  print '<option value="'.$valors[$i].'" selected>';
878  }
879  else
880  {
881  print '<option value="'.$valors[$i].'">';
882  }
883  print $valors[$i];
884  print '</option>';
885  $i++;
886  }
887  print'</select>';
888  }
889  }
890  }
891 }
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
typent_array($mode=0, $filter='')
Return list of labels (translated) of third parties type.
print
Draft customers invoices.
Definition: index.php:91
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
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
select_departement($selected='', $country_codeid=0, $htmlname='state_id')
Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays don...
select_civility($selected='', $htmlname='civility_id', $morecss='maxwidth100')
Return combo list with people title.
ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
Generic function that return javascript to add to a page to transform a common input field into an au...
Definition: ajax.lib.php:224
__construct($db)
Constructor.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Class to build HTML component for third parties management Only common components are here...
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
select_localtax($local, $selected, $htmlname)
Return a HTML select with localtax values for thirdparties.
select_forme_juridique($selected='', $country_codeid=0, $filter='')
Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne...
selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
Output list of third parties.
form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
Affiche formulaire de selection des modes de reglement.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
selectTypeContact($object, $selected, $htmlname='type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
Return a select list with types of contacts.
get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss='maxwidth100onsmartphone quatrevingtpercent')
Return HTML string to use as input of professional id into a HTML page (siren, siret, etc...)
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
effectif_array($mode=0, $filter='')
Renvoie la liste des types d&#39;effectifs possibles (pas de traduction car nombre)
select_state($selected='', $country_codeid=0, $htmlname='state_id')
Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays don...
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value...
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array())
Generic function that return javascript to add to a page to transform a common input field into an au...
Definition: ajax.lib.php:46
select_region($selected='', $htmlname='region_id')
Retourne la liste deroulante des regions actives dont le pays est actif La cle de la liste est le cod...
select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='', $morecss='')
Return a select list with zip codes and their town.