dolibarr  17.0.3
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  * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
35 
36 
40 class FormCompany extends Form
41 {
42 
43  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
51  public function typent_array($mode = 0, $filter = '')
52  {
53  // phpcs:enable
54  global $langs, $mysoc;
55 
56  $effs = array();
57 
58  $sql = "SELECT id, code, libelle";
59  $sql .= " FROM ".$this->db->prefix()."c_typent";
60  $sql .= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id) ? '0' : $mysoc->country_id).")";
61  if ($filter) {
62  $sql .= " ".$filter;
63  }
64  $sql .= " ORDER by position, id";
65  dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
66  $resql = $this->db->query($sql);
67  if ($resql) {
68  $num = $this->db->num_rows($resql);
69  $i = 0;
70 
71  while ($i < $num) {
72  $objp = $this->db->fetch_object($resql);
73  if (!$mode) {
74  $key = $objp->id;
75  } else {
76  $key = $objp->code;
77  }
78  if ($langs->trans($objp->code) != $objp->code) {
79  $effs[$key] = $langs->trans($objp->code);
80  } else {
81  $effs[$key] = $objp->libelle;
82  }
83  if ($effs[$key] == '-') {
84  $effs[$key] = '';
85  }
86  $i++;
87  }
88  $this->db->free($resql);
89  }
90 
91  return $effs;
92  }
93 
94  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
102  public function effectif_array($mode = 0, $filter = '')
103  {
104  // phpcs:enable
105  $effs = array();
106 
107  $sql = "SELECT id, code, libelle";
108  $sql .= " FROM ".$this->db->prefix()."c_effectif";
109  $sql .= " WHERE active = 1";
110  if ($filter) {
111  $sql .= " ".$filter;
112  }
113  $sql .= " ORDER BY id ASC";
114  dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
115  $resql = $this->db->query($sql);
116  if ($resql) {
117  $num = $this->db->num_rows($resql);
118  $i = 0;
119 
120  while ($i < $num) {
121  $objp = $this->db->fetch_object($resql);
122  if (!$mode) {
123  $key = $objp->id;
124  } else {
125  $key = $objp->code;
126  }
127 
128  $effs[$key] = $objp->libelle != '-' ? $objp->libelle : '';
129  $i++;
130  }
131  $this->db->free($resql);
132  }
133  return $effs;
134  }
135 
136 
137  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
147  public function form_prospect_level($page, $selected = '', $htmlname = 'prospect_level_id', $empty = 0)
148  {
149  // phpcs:enable
150  global $user, $langs;
151 
152  print '<form method="post" action="'.$page.'">';
153  print '<input type="hidden" name="action" value="setprospectlevel">';
154  print '<input type="hidden" name="token" value="'.newToken().'">';
155 
156  dol_syslog(get_class($this).'::form_prospect_level', LOG_DEBUG);
157  $sql = "SELECT code, label";
158  $sql .= " FROM ".$this->db->prefix()."c_prospectlevel";
159  $sql .= " WHERE active > 0";
160  $sql .= " ORDER BY sortorder";
161  $resql = $this->db->query($sql);
162  if ($resql) {
163  $options = array();
164 
165  if ($empty) {
166  $options[''] = '';
167  }
168 
169  while ($obj = $this->db->fetch_object($resql)) {
170  $level = $langs->trans($obj->code);
171 
172  if ($level == $obj->code) {
173  $level = $langs->trans($obj->label);
174  }
175 
176  $options[$obj->code] = $level;
177  }
178 
179  print Form::selectarray($htmlname, $options, $selected);
180  } else {
181  dol_print_error($this->db);
182  }
183  if (!empty($htmlname) && $user->admin) {
184  print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
185  }
186  print '<input type="submit" class="button button-save valignmiddle small" value="'.$langs->trans("Modify").'">';
187  print '</form>';
188  }
189 
199  public function formProspectContactLevel($page, $selected = '', $htmlname = 'prospect_contact_level_id', $empty = 0)
200  {
201  global $user, $langs;
202 
203  print '<form method="post" action="'.$page.'">';
204  print '<input type="hidden" name="action" value="setprospectcontactlevel">';
205  print '<input type="hidden" name="token" value="'.newToken().'">';
206 
207  dol_syslog(__METHOD__, LOG_DEBUG);
208  $sql = "SELECT code, label";
209  $sql .= " FROM ".$this->db->prefix()."c_prospectcontactlevel";
210  $sql .= " WHERE active > 0";
211  $sql .= " ORDER BY sortorder";
212  $resql = $this->db->query($sql);
213  if ($resql) {
214  $options = array();
215 
216  if ($empty) {
217  $options[''] = '';
218  }
219 
220  while ($obj = $this->db->fetch_object($resql)) {
221  $level = $langs->trans($obj->code);
222 
223  if ($level == $obj->code) {
224  $level = $langs->trans($obj->label);
225  }
226 
227  $options[$obj->code] = $level;
228  }
229 
230  print Form::selectarray($htmlname, $options, $selected);
231  } else {
232  dol_print_error($this->db);
233  }
234  if (!empty($htmlname) && $user->admin) {
235  print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
236  }
237  print '<input type="submit" class="button button-save valignmiddle small" value="'.$langs->trans("Modify").'">';
238  print '</form>';
239  }
240 
241  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
253  public function select_departement($selected = '', $country_codeid = 0, $htmlname = 'state_id')
254  {
255  // phpcs:enable
256  print $this->select_state($selected, $country_codeid, $htmlname);
257  }
258 
259  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
273  public function select_state($selected = 0, $country_codeid = 0, $htmlname = 'state_id', $morecss = 'maxwidth200onsmartphone minwidth300')
274  {
275  // phpcs:enable
276  global $conf, $langs, $user;
277 
278  dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid, LOG_DEBUG);
279 
280  $langs->load("dict");
281 
282  $out = '';
283 
284  // Serch departements/cantons/province active d'une region et pays actif
285  $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";
286  $sql .= " ".$this->db->prefix()."c_departements as d, ".$this->db->prefix()."c_regions as r,".$this->db->prefix()."c_country as c";
287  $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
288  $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
289  if ($country_codeid && is_numeric($country_codeid)) {
290  $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
291  }
292  if ($country_codeid && !is_numeric($country_codeid)) {
293  $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
294  }
295  $sql .= " ORDER BY c.code, d.code_departement";
296 
297  $result = $this->db->query($sql);
298  if ($result) {
299  if (!empty($htmlname)) {
300  $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">';
301  }
302  if ($country_codeid) {
303  $out .= '<option value="0">&nbsp;</option>';
304  }
305  $num = $this->db->num_rows($result);
306  $i = 0;
307  dol_syslog(get_class($this)."::select_departement num=".$num, LOG_DEBUG);
308  if ($num) {
309  $country = '';
310  while ($i < $num) {
311  $obj = $this->db->fetch_object($result);
312  if ($obj->code == '0') { // Le code peut etre une chaine
313  $out .= '<option value="0">&nbsp;</option>';
314  } else {
315  if (!$country || $country != $obj->country) {
316  // Show break if we are in list with multiple countries
317  if (!$country_codeid && $obj->country_code) {
318  $out .= '<option value="-1" disabled data-html="----- '.$obj->country.' -----">----- '.$obj->country." -----</option>\n";
319  $country = $obj->country;
320  }
321  }
322 
323  if (!empty($selected) && $selected == $obj->rowid) {
324  $out .= '<option value="'.$obj->rowid.'" selected>';
325  } else {
326  $out .= '<option value="'.$obj->rowid.'">';
327  }
328 
329  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
330  if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
331  ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
332  if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
333  $out .= $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
334  } else {
335  $out .= $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
336  }
337  } else {
338  if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
339  $out .= $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
340  } else {
341  $out .= ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
342  }
343  }
344 
345  $out .= '</option>';
346  }
347  $i++;
348  }
349  }
350  if (!empty($htmlname)) {
351  $out .= '</select>';
352  }
353  if (!empty($htmlname) && $user->admin) {
354  $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
355  }
356  } else {
357  dol_print_error($this->db);
358  }
359 
360  // Make select dynamic
361  if (!empty($htmlname)) {
362  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
363  $out .= ajax_combobox($htmlname);
364  }
365 
366  return $out;
367  }
368 
369 
370  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
381  public function select_region($selected = '', $htmlname = 'region_id')
382  {
383  // phpcs:enable
384  global $conf, $langs;
385  $langs->load("dict");
386 
387  $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
388  $sql .= " FROM ".$this->db->prefix()."c_regions as r, ".$this->db->prefix()."c_country as c";
389  $sql .= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
390  $sql .= " ORDER BY c.code, c.label ASC";
391 
392  dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
393  $resql = $this->db->query($sql);
394  if ($resql) {
395  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
396  $num = $this->db->num_rows($resql);
397  $i = 0;
398  if ($num) {
399  $country = '';
400  while ($i < $num) {
401  $obj = $this->db->fetch_object($resql);
402  if ($obj->code == 0) {
403  print '<option value="0">&nbsp;</option>';
404  } else {
405  if ($country == '' || $country != $obj->country) {
406  // Show break
407  $key = $langs->trans("Country".strtoupper($obj->country_code));
408  $valuetoshow = ($key != "Country".strtoupper($obj->country_code)) ? $obj->country_code." - ".$key : $obj->country;
409  print '<option value="-2" disabled>----- '.$valuetoshow." -----</option>\n";
410  $country = $obj->country;
411  }
412 
413  if ($selected > 0 && $selected == $obj->code) {
414  print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
415  } else {
416  print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
417  }
418  }
419  $i++;
420  }
421  }
422  print '</select>';
423  print ajax_combobox($htmlname);
424  } else {
425  dol_print_error($this->db);
426  }
427  }
428 
429  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
439  public function select_civility($selected = '', $htmlname = 'civility_id', $morecss = 'maxwidth150', $addjscombo = 1)
440  {
441  // phpcs:enable
442  global $conf, $langs, $user;
443  $langs->load("dict");
444 
445  $out = '';
446 
447  $sql = "SELECT rowid, code, label, active FROM ".$this->db->prefix()."c_civility";
448  $sql .= " WHERE active = 1";
449 
450  dol_syslog("Form::select_civility", LOG_DEBUG);
451  $resql = $this->db->query($sql);
452  if ($resql) {
453  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
454  $out .= '<option value="">&nbsp;</option>';
455  $num = $this->db->num_rows($resql);
456  $i = 0;
457  if ($num) {
458  while ($i < $num) {
459  $obj = $this->db->fetch_object($resql);
460  if ($selected == $obj->code) {
461  $out .= '<option value="'.$obj->code.'" selected>';
462  } else {
463  $out .= '<option value="'.$obj->code.'">';
464  }
465  // If translation exists, we use it, otherwise, we use tha had coded label
466  $out .= ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
467  $out .= '</option>';
468  $i++;
469  }
470  }
471  $out .= '</select>';
472  if ($user->admin) {
473  $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
474  }
475 
476  if ($addjscombo) {
477  // Enhance with select2
478  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
479  $out .= ajax_combobox($htmlname);
480  }
481  } else {
482  dol_print_error($this->db);
483  }
484 
485  return $out;
486  }
487 
488  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
500  public function select_forme_juridique($selected = '', $country_codeid = 0, $filter = '')
501  {
502  // phpcs:enable
503  print $this->select_juridicalstatus($selected, $country_codeid, $filter);
504  }
505 
506  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
518  public function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code', $morecss = '')
519  {
520  // phpcs:enable
521  global $conf, $langs, $user;
522  $langs->load("dict");
523 
524  $out = '';
525 
526  // On recherche les formes juridiques actives des pays actifs
527  $sql = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
528  $sql .= " FROM ".$this->db->prefix()."c_forme_juridique as f, ".$this->db->prefix()."c_country as c";
529  $sql .= " WHERE f.fk_pays=c.rowid";
530  $sql .= " AND f.active = 1 AND c.active = 1";
531  if ($country_codeid) {
532  $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
533  }
534  if ($filter) {
535  $sql .= " ".$filter;
536  }
537  $sql .= " ORDER BY c.code";
538 
539  dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
540  $resql = $this->db->query($sql);
541  if ($resql) {
542  $out .= '<div id="particulier2" class="visible">';
543  $out .= '<select class="flat minwidth200'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
544  if ($country_codeid) {
545  $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.
546  }
547 
548  $num = $this->db->num_rows($resql);
549  if ($num) {
550  $i = 0;
551  $country = '';
552  $arraydata = array();
553  while ($i < $num) {
554  $obj = $this->db->fetch_object($resql);
555 
556  if ($obj->code) { // We exclude empty line, we will add it later
557  $labelcountry = (($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
558  $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)
559  $arraydata[$obj->code] = array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
560  }
561  $i++;
562  }
563 
564  $arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC');
565  if (empty($country_codeid)) { // Introduce empty value (if $country_codeid not empty, empty value was already added)
566  $arraydata[0] = array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
567  }
568 
569  foreach ($arraydata as $key => $val) {
570  if (!$country || $country != $val['country']) {
571  // Show break when we are in multi country mode
572  if (empty($country_codeid) && $val['country_code']) {
573  $out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
574  $country = $val['country'];
575  }
576  }
577 
578  if ($selected > 0 && $selected == $val['code']) {
579  $out .= '<option value="'.$val['code'].'" selected>';
580  } else {
581  $out .= '<option value="'.$val['code'].'">';
582  }
583  // If translation exists, we use it, otherwise we use default label in database
584  $out .= $val['label'];
585  $out .= '</option>';
586  }
587  }
588  $out .= '</select>';
589  if ($user->admin) {
590  $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
591  }
592 
593  // Make select dynamic
594  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
595  $out .= ajax_combobox($htmlname);
596 
597  $out .= '</div>';
598  } else {
599  dol_print_error($this->db);
600  }
601 
602  return $out;
603  }
604 
605 
619  public function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany', $limitto = '', $forceid = 0, $moreparam = '', $morecss = '')
620  {
621  global $conf, $hookmanager;
622 
623  if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
624  // Use Ajax search
625  $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT) ? $conf->global->COMPANY_USE_SEARCH_TO_SELECT : 2);
626 
627  $socid = 0;
628  $name = '';
629  if ($selected > 0) {
630  $tmpthirdparty = new Societe($this->db);
631  $result = $tmpthirdparty->fetch($selected);
632  if ($result > 0) {
633  $socid = $selected;
634  $name = $tmpthirdparty->name;
635  }
636  }
637 
638 
639  $events = array();
640  // Add an entry 'method' to say 'yes, we must execute url with param action = method';
641  // Add an entry 'url' to say which url to execute
642  // Add an entry htmlname to say which element we must change once url is called
643  // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return 0 or >0 lines
644  // To refresh contacts list on thirdparty list change
645  $events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
646 
647  if (count($events)) { // If there is some ajax events to run once selection is done, we add code here to run events
648  print '<script type="text/javascript">
649  jQuery(document).ready(function() {
650  $("#search_'.$htmlname.'").change(function() {
651  var obj = '.json_encode($events).';
652  $.each(obj, function(key,values) {
653  if (values.method.length) {
654  runJsCodeForEvent'.$htmlname.'(values);
655  }
656  });
657 
658  $(this).trigger("blur");
659  });
660 
661  // Function used to execute events when search_htmlname change
662  function runJsCodeForEvent'.$htmlname.'(obj) {
663  var id = $("#'.$htmlname.'").val();
664  var method = obj.method;
665  var url = obj.url;
666  var htmlname = obj.htmlname;
667  var showempty = obj.showempty;
668  console.log("Run runJsCodeForEvent-'.$htmlname.' from selectCompaniesForNewContact id="+id+" method="+method+" showempty="+showempty+" url="+url+" htmlname="+htmlname);
669  $.getJSON(url,
670  {
671  action: method,
672  id: id,
673  htmlname: htmlname
674  },
675  function(response) {
676  if (response != null)
677  {
678  console.log("Change select#"+htmlname+" with content "+response.value)
679  $.each(obj.params, function(key,action) {
680  if (key.length) {
681  var num = response.num;
682  if (num > 0) {
683  $("#" + key).removeAttr(action);
684  } else {
685  $("#" + key).attr(action, action);
686  }
687  }
688  });
689  $("select#" + htmlname).html(response.value);
690  }
691  }
692  );
693  };
694  });
695  </script>';
696  }
697 
698  print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
699  print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
700  print ajax_autocompleter(($socid ? $socid : -1), $htmlname, DOL_URL_ROOT.'/societe/ajax/ajaxcompanies.php', '', $minLength, 0);
701  return $socid;
702  } else {
703  // Search to list thirdparties
704  $sql = "SELECT s.rowid, s.nom as name ";
705  if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST)) {
706  $sql .= ", s.code_client, s.code_fournisseur";
707  }
708  if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
709  $sql .= ", s.address, s.zip, s.town";
710  $sql .= ", dictp.code as country_code";
711  }
712  $sql .= " FROM ".$this->db->prefix()."societe as s";
713  if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) {
714  $sql .= " LEFT JOIN ".$this->db->prefix()."c_country as dictp ON dictp.rowid = s.fk_pays";
715  }
716  $sql .= " WHERE s.entity IN (".getEntity('societe').")";
717  // For ajax search we limit here. For combo list, we limit later
718  if (is_array($limitto) && count($limitto)) {
719  $sql .= " AND s.rowid IN (".$this->db->sanitize(join(',', $limitto)).")";
720  }
721  // Add where from hooks
722  $parameters = array();
723  $reshook = $hookmanager->executeHooks('selectCompaniesForNewContactListWhere', $parameters); // Note that $action and $object may have been modified by hook
724  $sql .= $hookmanager->resPrint;
725  $sql .= " ORDER BY s.nom ASC";
726 
727  $resql = $this->db->query($sql);
728  if ($resql) {
729  print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"';
730  if ($conf->use_javascript_ajax) {
731  $javaScript = "window.location='".dol_escape_js($_SERVER['PHP_SELF'])."?".$var_id."=".($forceid > 0 ? $forceid : $object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
732  print ' onChange="'.$javaScript.'"';
733  }
734  print '>';
735  print '<option value="-1">&nbsp;</option>';
736 
737  $num = $this->db->num_rows($resql);
738  $i = 0;
739  if ($num) {
740  while ($i < $num) {
741  $obj = $this->db->fetch_object($resql);
742  if ($i == 0) {
743  $firstCompany = $obj->rowid;
744  }
745  $disabled = 0;
746  if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) {
747  $disabled = 1;
748  }
749  if ($selected > 0 && $selected == $obj->rowid) {
750  print '<option value="'.$obj->rowid.'"';
751  if ($disabled) {
752  print ' disabled';
753  }
754  print ' selected>'.dol_trunc($obj->name, 24).'</option>';
755  $firstCompany = $obj->rowid;
756  } else {
757  print '<option value="'.$obj->rowid.'"';
758  if ($disabled) {
759  print ' disabled';
760  }
761  print '>'.dol_trunc($obj->name, 24).'</option>';
762  }
763  $i++;
764  }
765  }
766  print "</select>\n";
767  print ajax_combobox($htmlname);
768  return $firstCompany;
769  } else {
770  dol_print_error($this->db);
771  return 0;
772  }
773  }
774  }
775 
790  public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1, $forcehidetooltip = 0)
791  {
792  global $user, $langs;
793 
794  $out = '';
795  if (is_object($object) && method_exists($object, 'liste_type_contact')) {
796  $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
797 
798  $out .= '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
799  if ($showempty) {
800  $out .= '<option value="0">&nbsp;</option>';
801  }
802  foreach ($lesTypes as $key => $value) {
803  $out .= '<option value="'.$key.'"';
804  if ($key == $selected) {
805  $out .= ' selected';
806  }
807  $out .= '>'.$value.'</option>';
808  }
809  $out .= "</select>";
810  if ($user->admin && empty($forcehidetooltip)) {
811  $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
812  }
813 
814  $out .= ajax_combobox($htmlname);
815 
816  $out .= "\n";
817  }
818  if (empty($output)) {
819  return $out;
820  } else {
821  print $out;
822  }
823  }
824 
835  public function showRoles($htmlname, Contact $contact, $rendermode = 'view', $selected = array(), $morecss = 'minwidth500')
836  {
837  if ($rendermode === 'view') {
838  $toprint = array();
839  foreach ($contact->roles as $key => $val) {
840  $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #bbb;">'.$val['label'].'</li>';
841  }
842  return '<div class="select2-container-multi-dolibarr" style="width: 90%;" id="'.$htmlname.'"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
843  }
844 
845  if ($rendermode === 'edit') {
846  $contactType = $contact->listeTypeContacts('external', '', 1, '', '', 'agenda'); // We exclude agenda as there is no contact on such element
847  if (count($selected) > 0) {
848  $newselected = array();
849  foreach ($selected as $key => $val) {
850  if (is_array($val) && array_key_exists('id', $val) && in_array($val['id'], array_keys($contactType))) {
851  $newselected[] = $val['id'];
852  } else {
853  break;
854  }
855  }
856  if (count($newselected) > 0) {
857  $selected = $newselected;
858  }
859  }
860  return $this->multiselectarray($htmlname, $contactType, $selected, 0, 0, $morecss);
861  }
862 
863  return 'ErrorBadValueForParameterRenderMode'; // Should not happened
864  }
865 
866  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
879  public function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
880  {
881  // phpcs:enable
882  global $conf;
883 
884  $out = '';
885 
886  $size = '';
887  if (!empty($fieldsize)) {
888  $size = 'size="'.$fieldsize.'"';
889  }
890 
891  if ($conf->use_javascript_ajax && empty($disableautocomplete)) {
892  $out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
893  $moreattrib .= ' autocomplete="off"';
894  }
895  $out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
896 
897  return $out;
898  }
899 
900  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
911  public function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth200')
912  {
913  // phpcs:enable
914  global $conf, $langs, $hookmanager;
915 
916  $formlength = 0;
917  if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
918  if ($country_code == 'FR') {
919  if (isset($idprof)) {
920  if ($idprof == 1) {
921  $formlength = 9;
922  } elseif ($idprof == 2) {
923  $formlength = 14;
924  } elseif ($idprof == 3) {
925  $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
926  } elseif ($idprof == 4) {
927  $formlength = 32; // No maximum as we need to include a town name in this id
928  }
929  }
930  } elseif ($country_code == 'ES') {
931  if ($idprof == 1) {
932  $formlength = 9; //CIF/NIF/NIE 9 digits
933  }
934  if ($idprof == 2) {
935  $formlength = 12; //NASS 12 digits without /
936  }
937  if ($idprof == 3) {
938  $formlength = 5; //CNAE 5 digits
939  }
940  if ($idprof == 4) {
941  $formlength = 32; //depend of college
942  }
943  }
944  }
945 
946  $selected = $preselected;
947  if (!$selected && isset($idprof)) {
948  if ($idprof == 1 && !empty($this->idprof1)) {
949  $selected = $this->idprof1;
950  } elseif ($idprof == 2 && !empty($this->idprof2)) {
951  $selected = $this->idprof2;
952  } elseif ($idprof == 3 && !empty($this->idprof3)) {
953  $selected = $this->idprof3;
954  } elseif ($idprof == 4 && !empty($this->idprof4)) {
955  $selected = $this->idprof4;
956  }
957  }
958 
959  $maxlength = $formlength;
960  if (empty($formlength)) {
961  $formlength = 24;
962  $maxlength = 128;
963  }
964 
965  $out = '';
966 
967  // Execute hook getInputIdProf to complete or replace $out
968  $parameters = array('formlength'=>$formlength, 'selected'=>$preselected, 'idprof'=>$idprof, 'htmlname'=>$htmlname, 'country_code'=>$country_code);
969  $reshook = $hookmanager->executeHooks('getInputIdProf', $parameters);
970  if (empty($reshook)) {
971  $out .= '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
972  }
973  $out .= $hookmanager->resPrint;
974 
975  return $out;
976  }
977 
978  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
987  public function select_localtax($local, $selected, $htmlname)
988  {
989  // phpcs:enable
990  $tax = get_localtax_by_third($local);
991 
992  if ($tax) {
993  $valors = explode(":", $tax);
994  $nbvalues = count($valors);
995 
996  if ($nbvalues > 1) {
997  //montar select
998  print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
999  $i = 0;
1000  while ($i < $nbvalues) {
1001  if ($selected == $valors[$i]) {
1002  print '<option value="'.$valors[$i].'" selected>';
1003  } else {
1004  print '<option value="'.$valors[$i].'">';
1005  }
1006  print $valors[$i];
1007  print '</option>';
1008  $i++;
1009  }
1010  print '</select>';
1011  }
1012  }
1013  }
1014 
1026  public function selectProspectCustomerType($selected, $htmlname = 'client', $htmlidname = 'customerprospect', $typeinput = 'form', $morecss = '', $allowempty = '')
1027  {
1028  global $conf, $langs;
1029  if (!empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && !empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && !isModEnabled('fournisseur')) {
1030  return '' ;
1031  }
1032 
1033  $out = '<select class="flat '.$morecss.'" name="'.$htmlname.'" id="'.$htmlidname.'">';
1034  if ($typeinput == 'form') {
1035  if ($allowempty || ($selected == '' || $selected == '-1')) {
1036  $out .= '<option value="-1">';
1037  if (is_numeric($allowempty)) {
1038  $out .= '&nbsp;';
1039  } else {
1040  $out .= $langs->trans($allowempty);
1041  }
1042  $out .= '</option>';
1043  }
1044  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1045  $out .= '<option value="2"'.($selected == 2 ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1046  }
1047  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
1048  $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1049  }
1050  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1051  $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1052  }
1053  $out .= '<option value="0"'.((string) $selected == '0' ? ' selected' : '').'>'.$langs->trans('NorProspectNorCustomer').'</option>';
1054  } elseif ($typeinput == 'list') {
1055  $out .= '<option value="-1"'.(($selected == '' || $selected == '-1') ? ' selected' : '').'>&nbsp;</option>';
1056  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) {
1057  $out .= '<option value="2,3"'.($selected == '2,3' ? ' selected' : '').'>'.$langs->trans('Prospect').'</option>';
1058  }
1059  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1060  $out .= '<option value="1,3"'.($selected == '1,3' ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1061  }
1062  if (isModEnabled("fournisseur")) {
1063  $out .= '<option value="4"'.($selected == '4' ? ' selected' : '').'>'.$langs->trans('Supplier').'</option>';
1064  }
1065  $out .= '<option value="0"'.($selected == '0' ? ' selected' : '').'>'.$langs->trans('Other').'</option>';
1066  } elseif ($typeinput == 'admin') {
1067  if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTSCUSTOMERS)) {
1068  $out .= '<option value="3"'.($selected == 3 ? ' selected' : '').'>'.$langs->trans('ProspectCustomer').'</option>';
1069  }
1070  if (empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) {
1071  $out .= '<option value="1"'.($selected == 1 ? ' selected' : '').'>'.$langs->trans('Customer').'</option>';
1072  }
1073  }
1074  $out .= '</select>';
1075  $out .= ajax_combobox($htmlidname);
1076 
1077  return $out;
1078  }
1079 
1090  public function formThirdpartyType($page, $selected = '', $htmlname = 'socid', $filter = '', $nooutput = 0)
1091  {
1092  // phpcs:enable
1093  global $conf, $langs;
1094 
1095  $out = '';
1096  if ($htmlname != "none") {
1097  $out .= '<form method="post" action="'.$page.'">';
1098  $out .= '<input type="hidden" name="action" value="set_thirdpartytype">';
1099  $out .= '<input type="hidden" name="token" value="'.newToken().'">';
1100  $sortparam = (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT); // NONE means we keep sort of original array, so we sort on position. ASC, means next function will sort on label.
1101  $out .= $this->selectarray($htmlname, $this->typent_array(0, $filter), $selected, 1, 0, 0, '', 0, 0, 0, $sortparam, '', 1);
1102  $out .= '<input type="submit" class="button smallpaddingimp valignmiddle" value="'.$langs->trans("Modify").'">';
1103  $out .= '</form>';
1104  } else {
1105  if ($selected > 0) {
1106  $arr = $this->typent_array(0);
1107  $typent = $arr[$selected];
1108  $out .= $typent;
1109  } else {
1110  $out .= "&nbsp;";
1111  }
1112  }
1113 
1114  if ($nooutput) {
1115  return $out;
1116  } else {
1117  print $out;
1118  }
1119  }
1120 }
FormCompany\select_juridicalstatus
select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code', $morecss='')
Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
Definition: html.formcompany.class.php:518
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
db
$conf db
API class for accounts.
Definition: inc.php:41
FormCompany\select_ziptown
select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='', $morecss='')
Return a select list with zip codes and their town.
Definition: html.formcompany.class.php:879
ajax_autocompleter
ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array(), $moreparams='')
Generic function that return javascript to add to a page to transform a common input field into an au...
Definition: ajax.lib.php:47
FormCompany\select_state
select_state($selected=0, $country_codeid=0, $htmlname='state_id', $morecss='maxwidth200onsmartphone minwidth300')
Returns the drop-down list of departments/provinces/cantons for all countries or for a given country.
Definition: html.formcompany.class.php:273
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
dol_sort_array
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...
Definition: functions.lib.php:8714
FormCompany\effectif_array
effectif_array($mode=0, $filter='')
Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
Definition: html.formcompany.class.php:102
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1061
ajax_multiautocompleter
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:297
FormCompany\select_civility
select_civility($selected='', $htmlname='civility_id', $morecss='maxwidth150', $addjscombo=1)
Return combo list with people title.
Definition: html.formcompany.class.php:439
FormCompany\get_input_id_prof
get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss='maxwidth200')
Return HTML string to use as input of professional id into a HTML page (siren, siret,...
Definition: html.formcompany.class.php:911
FormCompany\selectTypeContact
selectTypeContact($object, $selected, $htmlname='type', $source='internal', $sortorder='position', $showempty=0, $morecss='', $output=1, $forcehidetooltip=0)
Return a select list with types of contacts.
Definition: html.formcompany.class.php:790
FormCompany\selectCompaniesForNewContact
selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
Output list of third parties.
Definition: html.formcompany.class.php:619
FormCompany\typent_array
typent_array($mode=0, $filter='')
Return list of labels (translated) of third parties type.
Definition: html.formcompany.class.php:51
FormCompany\select_departement
select_departement($selected='', $country_codeid=0, $htmlname='state_id')
Returns the drop-down list of departments/provinces/cantons for all countries or for a given country.
Definition: html.formcompany.class.php:253
FormCompany
Class to build HTML component for third parties management Only common components are here.
Definition: html.formcompany.class.php:40
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
Form\selectarray
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='minwidth75', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Definition: html.form.class.php:8002
FormCompany\select_localtax
select_localtax($local, $selected, $htmlname)
Return a HTML select with localtax values for thirdparties.
Definition: html.formcompany.class.php:987
FormCompany\formProspectContactLevel
formProspectContactLevel($page, $selected='', $htmlname='prospect_contact_level_id', $empty=0)
Affiche formulaire de selection des niveau de prospection pour les contacts.
Definition: html.formcompany.class.php:199
info_admin
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
Definition: functions.lib.php:4949
FormCompany\form_prospect_level
form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
Affiche formulaire de selection des modes de reglement.
Definition: html.formcompany.class.php:147
Form\multiselectarray
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Definition: html.form.class.php:8380
get_localtax_by_third
get_localtax_by_third($local)
Get values of localtaxes (1 or 2) for company country for the common vat with the highest value.
Definition: functions.lib.php:6156
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:53
FormCompany\select_forme_juridique
select_forme_juridique($selected='', $country_codeid=0, $filter='')
Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
Definition: html.formcompany.class.php:500
ajax_combobox
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:449
FormCompany\select_region
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...
Definition: html.formcompany.class.php:381
FormCompany\showRoles
showRoles($htmlname, Contact $contact, $rendermode='view', $selected=array(), $morecss='minwidth500')
showContactRoles on view and edit mode
Definition: html.formcompany.class.php:835
FormCompany\formThirdpartyType
formThirdpartyType($page, $selected='', $htmlname='socid', $filter='', $nooutput=0)
Output html select to select third-party type.
Definition: html.formcompany.class.php:1090
FormCompany\selectProspectCustomerType
selectProspectCustomerType($selected, $htmlname='client', $htmlidname='customerprospect', $typeinput='form', $morecss='', $allowempty='')
Return a HTML select for thirdparty type.
Definition: html.formcompany.class.php:1026
if
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
Definition: journals_list.php:25