dolibarr  7.0.0-beta
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@capnetworks.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 {
34  var $db;
35  var $error;
36 
37 
38 
44  function __construct($db)
45  {
46  $this->db = $db;
47 
48  return 1;
49  }
50 
51 
59  function typent_array($mode=0, $filter='')
60  {
61  global $langs,$mysoc;
62 
63  $effs = array();
64 
65  $sql = "SELECT id, code, libelle";
66  $sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
67  $sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
68  if ($filter) $sql.=" ".$filter;
69  $sql.= " ORDER by position, id";
70  dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
71  $resql=$this->db->query($sql);
72  if ($resql)
73  {
74  $num = $this->db->num_rows($resql);
75  $i = 0;
76 
77  while ($i < $num)
78  {
79  $objp = $this->db->fetch_object($resql);
80  if (! $mode) $key=$objp->id;
81  else $key=$objp->code;
82  if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
83  else $effs[$key] = $objp->libelle;
84  if ($effs[$key]=='-') $effs[$key]='';
85  $i++;
86  }
87  $this->db->free($resql);
88  }
89 
90  return $effs;
91  }
92 
100  function effectif_array($mode=0, $filter='')
101  {
102  $effs = array();
103 
104  $sql = "SELECT id, code, libelle";
105  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
106  $sql.= " WHERE active = 1";
107  if ($filter) $sql.=" ".$filter;
108  $sql .= " ORDER BY id ASC";
109  dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
110  $resql=$this->db->query($sql);
111  if ($resql)
112  {
113  $num = $this->db->num_rows($resql);
114  $i = 0;
115 
116  while ($i < $num)
117  {
118  $objp = $this->db->fetch_object($resql);
119  if (! $mode) $key=$objp->id;
120  else $key=$objp->code;
121 
122  $effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
123  $i++;
124  }
125  $this->db->free($resql);
126  }
127  return $effs;
128  }
129 
130 
140  function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
141  {
142  global $user, $langs;
143 
144  print '<form method="post" action="'.$page.'">';
145  print '<input type="hidden" name="action" value="setprospectlevel">';
146  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
147 
148  dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
149  $sql = "SELECT code, label";
150  $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
151  $sql.= " WHERE active > 0";
152  $sql.= " ORDER BY sortorder";
153  $resql = $this->db->query($sql);
154  if ($resql)
155  {
156  $options = array();
157 
158  if ($empty) {
159  $options[''] = '';
160  }
161 
162  while ($obj = $this->db->fetch_object($resql)) {
163  $level = $langs->trans($obj->code);
164 
165  if ($level == $obj->code) {
166  $level = $langs->trans($obj->label);
167  }
168 
169  $options[$obj->code] = $level;
170  }
171 
172  print Form::selectarray($htmlname, $options, $selected);
173  }
174  else dol_print_error($this->db);
175  if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
176  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
177  print '</form>';
178  }
179 
192  function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
193  {
194  print $this->select_state($selected,$country_codeid, $htmlname);
195  }
196 
210  function select_state($selected='',$country_codeid=0, $htmlname='state_id')
211  {
212  global $conf,$langs,$user;
213 
214  dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
215 
216  $langs->load("dict");
217 
218  $out='';
219 
220  // On recherche les departements/cantons/province active d'une region et pays actif
221  $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";
222  $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
223  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
224  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
225  if ($country_codeid && is_numeric($country_codeid)) $sql .= " AND c.rowid = '".$country_codeid."'";
226  if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$country_codeid."'";
227  $sql .= " ORDER BY c.code, d.code_departement";
228 
229  dol_syslog(get_class($this)."::select_departement", LOG_DEBUG);
230  $result=$this->db->query($sql);
231  if ($result)
232  {
233  if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
234  if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
235  $num = $this->db->num_rows($result);
236  $i = 0;
237  dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
238  if ($num)
239  {
240  $country='';
241  while ($i < $num)
242  {
243  $obj = $this->db->fetch_object($result);
244  if ($obj->code == '0') // Le code peut etre une chaine
245  {
246  $out.= '<option value="0">&nbsp;</option>';
247  }
248  else {
249  if (! $country || $country != $obj->country)
250  {
251  // Affiche la rupture si on est en mode liste multipays
252  if (! $country_codeid && $obj->country_code)
253  {
254  $out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
255  $country=$obj->country;
256  }
257  }
258 
259  if ((! empty($selected) && $selected == $obj->rowid)
260  || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
261  {
262  $out.= '<option value="'.$obj->rowid.'" selected>';
263  }
264  else
265  {
266  $out.= '<option value="'.$obj->rowid.'">';
267  }
268  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
269  if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 2) {
270  $out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
271  }
272  else if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE) && $conf->global->MAIN_SHOW_REGION_IN_STATE == 1) {
273  $out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
274  }
275  else {
276  $out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
277  }
278  $out.= '</option>';
279  }
280  $i++;
281  }
282  }
283  if (! empty($htmlname)) $out.= '</select>';
284  if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
285  }
286  else
287  {
288  dol_print_error($this->db);
289  }
290 
291  // Make select dynamic
292  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
293  $out .= ajax_combobox($htmlname);
294 
295  return $out;
296  }
297 
298 
309  function select_region($selected='',$htmlname='region_id')
310  {
311  global $conf,$langs;
312  $langs->load("dict");
313 
314  $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
315  $sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
316  $sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
317  $sql.= " ORDER BY c.code, c.label ASC";
318 
319  dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
320  $resql=$this->db->query($sql);
321  if ($resql)
322  {
323  print '<select class="flat" name="'.$htmlname.'">';
324  $num = $this->db->num_rows($resql);
325  $i = 0;
326  if ($num)
327  {
328  $country='';
329  while ($i < $num)
330  {
331  $obj = $this->db->fetch_object($resql);
332  if ($obj->code == 0) {
333  print '<option value="0">&nbsp;</option>';
334  }
335  else {
336  if ($country == '' || $country != $obj->country)
337  {
338  // Show break
339  $key=$langs->trans("Country".strtoupper($obj->country_code));
340  $valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
341  print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
342  $country=$obj->country;
343  }
344 
345  if ($selected > 0 && $selected == $obj->code)
346  {
347  print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
348  }
349  else
350  {
351  print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
352  }
353  }
354  $i++;
355  }
356  }
357  print '</select>';
358  }
359  else
360  {
361  dol_print_error($this->db);
362  }
363  }
364 
373  function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
374  {
375  global $conf,$langs,$user;
376  $langs->load("dict");
377 
378  $out='';
379 
380  $sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
381  $sql.= " WHERE active = 1";
382 
383  dol_syslog("Form::select_civility", LOG_DEBUG);
384  $resql=$this->db->query($sql);
385  if ($resql)
386  {
387  $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
388  $out.= '<option value="">&nbsp;</option>';
389  $num = $this->db->num_rows($resql);
390  $i = 0;
391  if ($num)
392  {
393  while ($i < $num)
394  {
395  $obj = $this->db->fetch_object($resql);
396  if ($selected == $obj->code)
397  {
398  $out.= '<option value="'.$obj->code.'" selected>';
399  }
400  else
401  {
402  $out.= '<option value="'.$obj->code.'">';
403  }
404  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
405  $out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
406  $out.= '</option>';
407  $i++;
408  }
409  }
410  $out.= '</select>';
411  if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
412  }
413  else
414  {
415  dol_print_error($this->db);
416  }
417 
418  return $out;
419  }
420 
432  function select_forme_juridique($selected='', $country_codeid=0, $filter='')
433  {
434  print $this->select_juridicalstatus($selected, $country_codeid, $filter);
435  }
436 
447  function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
448  {
449  global $conf,$langs,$user;
450  $langs->load("dict");
451 
452  $out='';
453 
454  // On recherche les formes juridiques actives des pays actifs
455  $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
456  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
457  $sql .= " WHERE f.fk_pays=c.rowid";
458  $sql .= " AND f.active = 1 AND c.active = 1";
459  if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
460  if ($filter) $sql .= " ".$filter;
461  $sql .= " ORDER BY c.code";
462 
463  dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
464  $resql=$this->db->query($sql);
465  if ($resql)
466  {
467  $out.= '<div id="particulier2" class="visible">';
468  $out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
469  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.
470 
471  $num = $this->db->num_rows($resql);
472  if ($num)
473  {
474  $i = 0;
475  $country=''; $arraydata=array();
476  while ($i < $num)
477  {
478  $obj = $this->db->fetch_object($resql);
479 
480  if ($obj->code) // We exclude empty line, we will add it later
481  {
482  $labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
483  $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)
484  $arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
485  }
486  $i++;
487  }
488 
489  $arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
490  if (empty($country_codeid)) // Introduce empty value (if $country_codeid not empty, empty value was already added)
491  {
492  $arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
493  }
494 
495  foreach($arraydata as $key => $val)
496  {
497  if (! $country || $country != $val['country'])
498  {
499  // Show break when we are in multi country mode
500  if (empty($country_codeid) && $val['country_code'])
501  {
502  $out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
503  $country=$val['country'];
504  }
505  }
506 
507  if ($selected > 0 && $selected == $val['code'])
508  {
509  $out.= '<option value="'.$val['code'].'" selected>';
510  }
511  else
512  {
513  $out.= '<option value="'.$val['code'].'">';
514  }
515  // If translation exists, we use it, otherwise we use default label in database
516  $out.= $val['label'];
517  $out.= '</option>';
518  }
519  }
520  $out.= '</select>';
521  if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
522 
523  // Make select dynamic
524  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
525  $out .= ajax_combobox($htmlname);
526 
527  $out.= '</div>';
528  }
529  else
530  {
531  dol_print_error($this->db);
532  }
533 
534  return $out;
535  }
536 
537 
550  function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='')
551  {
552  global $conf, $langs;
553 
554  if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
555  {
556  // Use Ajax search
557  $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
558 
559  $socid=0; $name='';
560  if ($selected > 0)
561  {
562  $tmpthirdparty=new Societe($this->db);
563  $result = $tmpthirdparty->fetch($selected);
564  if ($result > 0)
565  {
566  $socid = $selected;
567  $name = $tmpthirdparty->name;
568  }
569  }
570 
571 
572  $events=array();
573  // Add an entry 'method' to say 'yes, we must execute url with param action = method';
574  // Add an entry 'url' to say which url to execute
575  // Add an entry htmlname to say which element we must change once url is called
576  // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines
577  // To refresh contacts list on thirdparty list change
578  $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
579 
580  if (count($events)) // If there is some ajax events to run once selection is done, we add code here to run events
581  {
582  print '<script type="text/javascript">
583  jQuery(document).ready(function() {
584  $("#search_'.$htmlname.'").change(function() {
585  var obj = '.json_encode($events).';
586  $.each(obj, function(key,values) {
587  if (values.method.length) {
588  runJsCodeForEvent'.$htmlname.'(values);
589  }
590  });
591  /* Clean contact */
592  $("div#s2id_contactid>a>span").html(\'\');
593  });
594 
595  // Function used to execute events when search_htmlname change
596  function runJsCodeForEvent'.$htmlname.'(obj) {
597  var id = $("#'.$htmlname.'").val();
598  var method = obj.method;
599  var url = obj.url;
600  var htmlname = obj.htmlname;
601  console.log("Run runJsCodeForEvent-'.$htmlname.' from selectCompaniesForNewContact id="+id+" method="+method+" showempty="+showempty+" url="+url+" htmlname="+htmlname);
602  $.getJSON(url,
603  {
604  action: method,
605  id: id,
606  htmlname: htmlname
607  },
608  function(response) {
609  if (response != null)
610  {
611  console.log("Change select#"+htmlname+" with content "+response.value)
612  $.each(obj.params, function(key,action) {
613  if (key.length) {
614  var num = response.num;
615  if (num > 0) {
616  $("#" + key).removeAttr(action);
617  } else {
618  $("#" + key).attr(action, action);
619  }
620  }
621  });
622  $("select#" + htmlname).html(response.value);
623  }
624  }
625  );
626  };
627  });
628  </script>';
629  }
630 
631  print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
632  print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
633  print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
634  return $socid;
635  }
636  else
637  {
638  // Search to list thirdparties
639  $sql = "SELECT s.rowid, s.nom as name FROM";
640  $sql.= " ".MAIN_DB_PREFIX."societe as s";
641  $sql.= " WHERE s.entity IN (".getEntity('societe').")";
642  // For ajax search we limit here. For combo list, we limit later
643  if (is_array($limitto) && count($limitto))
644  {
645  $sql.= " AND s.rowid IN (".join(',',$limitto).")";
646  }
647  $sql.= " ORDER BY s.nom ASC";
648 
649  $resql = $this->db->query($sql);
650  if ($resql)
651  {
652  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"';
653  if ($conf->use_javascript_ajax)
654  {
655  $javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
656  print ' onChange="'.$javaScript.'"';
657  }
658  print '>';
659  $num = $this->db->num_rows($resql);
660  $i = 0;
661  if ($num)
662  {
663  while ($i < $num)
664  {
665  $obj = $this->db->fetch_object($resql);
666  if ($i == 0) $firstCompany = $obj->rowid;
667  $disabled=0;
668  if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
669  if ($selected > 0 && $selected == $obj->rowid)
670  {
671  print '<option value="'.$obj->rowid.'"';
672  if ($disabled) print ' disabled';
673  print ' selected>'.dol_trunc($obj->name,24).'</option>';
674  $firstCompany = $obj->rowid;
675  }
676  else
677  {
678  print '<option value="'.$obj->rowid.'"';
679  if ($disabled) print ' disabled';
680  print '>'.dol_trunc($obj->name,24).'</option>';
681  }
682  $i ++;
683  }
684  }
685  print "</select>\n";
686  return $firstCompany;
687  }
688  else
689  {
690  dol_print_error($this->db);
691  print 'Error sql';
692  }
693  }
694  }
695 
708  function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
709  {
710  global $user, $langs;
711 
712  if (is_object($object) && method_exists($object, 'liste_type_contact'))
713  {
714  $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
715  print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
716  if ($showempty) print '<option value="0"></option>';
717  foreach($lesTypes as $key=>$value)
718  {
719  print '<option value="'.$key.'"';
720  if ($key == $selected) print ' selected';
721  print '>'.$value.'</option>';
722  }
723  print "</select>";
724  if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
725  print "\n";
726  }
727  }
728 
741  function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
742  {
743  global $conf;
744 
745  $out='';
746 
747  $size='';
748  if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
749 
750  if ($conf->use_javascript_ajax && empty($disableautocomplete))
751  {
752  $out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
753  $moreattrib.=' autocomplete="off"';
754  }
755  $out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
756 
757  return $out;
758  }
759 
770  function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
771  {
772  global $conf,$langs;
773 
774  $formlength=0;
775  if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
776  if ($country_code == 'FR')
777  {
778  if (isset($idprof)) {
779  if ($idprof==1) $formlength=9;
780  else if ($idprof==2) $formlength=14;
781  else if ($idprof==3) $formlength=5; // 4 chiffres et 1 lettre depuis janvier
782  else if ($idprof==4) $formlength=32; // No maximum as we need to include a town name in this id
783  }
784  }
785  else if ($country_code == 'ES')
786  {
787  if ($idprof==1) $formlength=9; //CIF/NIF/NIE 9 digits
788  if ($idprof==2) $formlength=12; //NASS 12 digits without /
789  if ($idprof==3) $formlength=5; //CNAE 5 digits
790  if ($idprof==4) $formlength=32; //depend of college
791  }
792  }
793 
794  $selected=$preselected;
795  if (! $selected && isset($idprof)) {
796  if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
797  else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
798  else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
799  else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
800  }
801 
802  $maxlength=$formlength;
803  if (empty($formlength)) { $formlength=24; $maxlength=128; }
804 
805  $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
806 
807  return $out;
808  }
809 
818  function select_localtax($local, $selected, $htmlname)
819  {
820  $tax=get_localtax_by_third($local);
821 
822  $num = $this->db->num_rows($tax);
823  $i = 0;
824  if ($num)
825  {
826  $valors=explode(":", $tax);
827 
828  if (count($valors) > 1)
829  {
830  //montar select
831  print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
832  while ($i <= (count($valors))-1)
833  {
834  if ($selected == $valors[$i])
835  {
836  print '<option value="'.$valors[$i].'" selected>';
837  }
838  else
839  {
840  print '<option value="'.$valors[$i].'">';
841  }
842  print $valors[$i];
843  print '</option>';
844  $i++;
845  }
846  print'</select>';
847  }
848  }
849  }
850 
851 }
852 
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
typent_array($mode=0, $filter='')
Return list of labels (translated) of third parties type.
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
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
__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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1')
Show information for admin users or standard users.
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.
selectTypeContact($object, $selected, $htmlname= 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
Return a select list with types of contacts.
select_forme_juridique($selected='', $country_codeid=0, $filter='')
Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne...
form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
Affiche formulaire de selection des modes de reglement.
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...)
selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='')
Output list of third parties.
effectif_array($mode=0, $filter='')
Renvoie la liste des types d'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...
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:1013
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.