dolibarr  19.0.0-dev
html.formother.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
8  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
9  * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
10  * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
11  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
12  * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
39 class FormOther
40 {
41  private $db;
42 
46  public $error;
47 
48 
54  public function __construct($db)
55  {
56  $this->db = $db;
57  }
58 
67  public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode = 'all')
68  {
69  global $langs;
70 
71  $out = '';
72 
73  $out .= '<!-- Popup for mass barcode scanning -->'."\n";
74  $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
75  $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
76 
77  if ($mode == 'product') {
78  $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
79  } elseif ($mode == 'lot') {
80  $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
81  } else { // $mode = 'all'
82  $out .= '<input type="radio" name="barcodemode" value="barcodeforautodetect" id="barcodeforautodetect" checked="checked"> <label for="barcodeforautodetect">Autodetect if we scan a product barcode or a lot/serial barcode</label><br>';
83  $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
84  $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
85  }
86  $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
87  $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
88  $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
89  $out .= $stringaddbarcode.' <input type="text" name="barcodeproductqty" class="width50 right" value="1"><br>';
90  $out .= '<br>';
91  $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
92 
93  /*print '<br>'.$langs->trans("or").'<br>';
94 
95  print '<br>';
96 
97  print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
98  */
99  $out .= '<br>';
100  $out .= '<center>';
101  $out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).'" name="addscan" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
102  $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
103  $out .= '</center>';
104  $out .= '<br>';
105  $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
106 
107  $out .= '<script nonce="'.getNonce().'">';
108  $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
109  $out .= 'console.log("select choice");';
110  $out .= 'jQuery("#scantoolmessage").text("");';
111  $out .= '});'."\n";
112  $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
113  console.log("We call js to execute \''.dol_escape_js($jstoexecuteonadd).'\'");
114  '.dol_escape_js($jstoexecuteonadd).'();
115  return false; /* We want to stay on the scan tool */
116  })';
117  $out .= '</script>';
118 
119  $out .= '</center>';
120  $out .= '</div>';
121 
122  return $out;
123  }
124 
125  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
136  public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
137  {
138  // phpcs:enable
139  global $conf, $langs, $user;
140 
141  $sql = "SELECT rowid, label, fk_user";
142  $sql .= " FROM ".$this->db->prefix()."export_model";
143  $sql .= " WHERE type = '".$this->db->escape($type)."'";
144  if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
145  $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
146  }
147  $sql .= " ORDER BY label";
148  $result = $this->db->query($sql);
149  if ($result) {
150  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
151  if ($useempty) {
152  print '<option value="-1">&nbsp;</option>';
153  }
154 
155  $tmpuser = new User($this->db);
156 
157  $num = $this->db->num_rows($result);
158  $i = 0;
159  while ($i < $num) {
160  $obj = $this->db->fetch_object($result);
161 
162  $label = $obj->label;
163  if ($obj->fk_user == 0) {
164  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
165  } elseif ($obj->fk_user > 0) {
166  $tmpuser->fetch($obj->fk_user);
167  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
168  }
169 
170  if ($selected == $obj->rowid) {
171  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
172  } else {
173  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
174  }
175  print $label;
176  print '</option>';
177  $i++;
178  }
179  print "</select>";
180  print ajax_combobox($htmlname);
181  } else {
182  dol_print_error($this->db);
183  }
184  }
185 
186 
187  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
198  public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
199  {
200  // phpcs:enable
201  global $conf, $langs, $user;
202 
203  $sql = "SELECT rowid, label, fk_user";
204  $sql .= " FROM ".$this->db->prefix()."import_model";
205  $sql .= " WHERE type = '".$this->db->escape($type)."'";
206  if (empty($conf->global->EXPORTS_SHARE_MODELS)) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
207  $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
208  }
209  $sql .= " ORDER BY label";
210  $result = $this->db->query($sql);
211  if ($result) {
212  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
213  if ($useempty) {
214  print '<option value="-1">&nbsp;</option>';
215  }
216 
217  $tmpuser = new User($this->db);
218 
219  $num = $this->db->num_rows($result);
220  $i = 0;
221  while ($i < $num) {
222  $obj = $this->db->fetch_object($result);
223 
224  $label = $obj->label;
225  if ($obj->fk_user == 0) {
226  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
227  } elseif ($obj->fk_user > 0) {
228  $tmpuser->fetch($obj->fk_user);
229  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
230  }
231 
232  if ($selected == $obj->rowid) {
233  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
234  } else {
235  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
236  }
237  print $label;
238  print '</option>';
239  $i++;
240  }
241  print "</select>";
242  print ajax_combobox($htmlname);
243  } else {
244  dol_print_error($this->db);
245  }
246  }
247 
248 
249  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
257  public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
258  {
259  // phpcs:enable
260  global $langs;
261 
262  $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
263  $sql .= " c.label as country";
264  $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
265  $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
266  $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
267 
268  dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
269  $resql = $this->db->query($sql);
270  if ($resql) {
271  print '<select class="flat" name="'.$htmlname.'">';
272  $num = $this->db->num_rows($resql);
273  $i = 0;
274  print '<option value="-1">&nbsp;</option>'."\n";
275  if ($num) {
276  while ($i < $num) {
277  $obj = $this->db->fetch_object($resql);
278  if ($selected && $selected == $obj->rowid) {
279  print '<option value="'.$obj->rowid.'" selected>';
280  } else {
281  print '<option value="'.$obj->rowid.'">';
282  //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
283  }
284  $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
285  print $selectOptionValue;
286  print '</option>';
287  $i++;
288  }
289  }
290  print '</select>';
291  return 0;
292  } else {
293  dol_print_error($this->db);
294  return 1;
295  }
296  }
297 
298 
299  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
308  public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
309  {
310  // phpcs:enable
311  global $langs;
312 
313  $out = '';
314 
315  $sql = "SELECT r.taux, r.revenuestamp_type";
316  $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
317  $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
318  $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
319 
320  dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
321  $resql = $this->db->query($sql);
322  if ($resql) {
323  $out .= '<select class="flat" name="'.$htmlname.'">';
324  $num = $this->db->num_rows($resql);
325  $i = 0;
326  $out .= '<option value="0">&nbsp;</option>'."\n";
327  if ($num) {
328  while ($i < $num) {
329  $obj = $this->db->fetch_object($resql);
330  if (($selected && $selected == $obj->taux) || $num == 1) {
331  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
332  } else {
333  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
334  //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
335  }
336  $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
337  $out .= '</option>';
338  $i++;
339  }
340  }
341  $out .= '</select>';
342  return $out;
343  } else {
344  dol_print_error($this->db);
345  return '';
346  }
347  }
348 
349 
350  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
363  public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
364  {
365  // phpcs:enable
366  $return = '<select class="flat" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
367  if ($showempty) {
368  $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
369  }
370 
371  for ($i = $start; $i <= $end; $i += $increment) {
372  if ($selected != '' && (int) $selected == $i) {
373  $return .= '<option value="'.$i.'" selected>';
374  } else {
375  $return .= '<option value="'.$i.'">';
376  }
377  $return .= $i.' % ';
378  $return .= '</option>';
379  }
380 
381  $return .= '</select>';
382 
383  return $return;
384  }
385 
386  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
399  public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
400  {
401  // phpcs:enable
402  global $conf, $langs;
403  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
404 
405  // For backward compatibility
406  if (is_numeric($type)) {
407  dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
408  }
409 
410  // Load list of "categories"
411  $static_categs = new Categorie($this->db);
412  $tab_categs = $static_categs->get_full_arbo($type);
413 
414  $moreforfilter = '';
415 
416  // Print a select with each of them
417  $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
418  if ($showempty) {
419  $textforempty = ' ';
420  if (!empty($conf->use_javascript_ajax)) {
421  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
422  }
423  if (!is_numeric($showempty)) {
424  $textforempty = $showempty;
425  }
426  $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
427  //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
428  $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
429  }
430 
431  if (is_array($tab_categs)) {
432  foreach ($tab_categs as $categ) {
433  $moreforfilter .= '<option value="'.$categ['id'].'"';
434  if ($categ['id'] == $selected) {
435  $moreforfilter .= ' selected';
436  }
437  $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
438  $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
439  }
440  }
441  if ($nocateg) {
442  $langs->load("categories");
443  $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
444  }
445  $moreforfilter .= '</select>';
446 
447  // Enhance with select2
448  if ($conf->use_javascript_ajax) {
449  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
450  $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
451  $moreforfilter .= $comboenhancement;
452  }
453 
454  return $moreforfilter;
455  }
456 
457 
458  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
471  public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
472  {
473  // phpcs:enable
474  global $conf, $langs, $hookmanager;
475 
476  $langs->load('users');
477 
478  $out = '';
479 
480  $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
481 
482  // Select each sales and print them in a select input
483  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
484  if ($showempty) {
485  $textforempty = ' ';
486  if (!is_numeric($showempty)) {
487  $textforempty = $showempty;
488  }
489  if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
490  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
491  }
492  $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
493  }
494 
495  // Get list of users allowed to be viewed
496  $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
497  $sql_usr .= " FROM ".$this->db->prefix()."user as u";
498 
499  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
500  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
501  $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
502  } else {
503  $sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('usergroup')."))";
504  $sql_usr .= " OR u.entity = 0"; // Show always superadmin
505  }
506  } else {
507  $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
508  }
509 
510  if (empty($user->rights->user->user->lire)) {
511  $sql_usr .= " AND u.rowid = ".((int) $user->id);
512  }
513  if (!empty($user->socid)) {
514  $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
515  }
516 
517  //Add hook to filter on user (for exemple on usergroup define in custom modules)
518  if (!empty($reshook)) {
519  $sql_usr .= $hookmanager->resArray[0];
520  }
521 
522  // Add existing sales representatives of thirdparty of external user
523  if (empty($user->rights->user->user->lire) && $user->socid) {
524  $sql_usr .= " UNION ";
525  $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
526  $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
527 
528  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
529  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
530  $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
531  } else {
532  $sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM ".$this->db->prefix()."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('usergroup')."))";
533  }
534  } else {
535  $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
536  }
537 
538  $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
539 
540  //Add hook to filter on user (for exemple on usergroup define in custom modules)
541  if (!empty($reshook)) {
542  $sql_usr .= $hookmanager->resArray[1];
543  }
544  }
545 
546  if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
547  $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
548  } else {
549  $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
550  }
551  //print $sql_usr;exit;
552 
553  $resql_usr = $this->db->query($sql_usr);
554  if ($resql_usr) {
555  $userstatic = new User($this->db);
556 
557  while ($obj_usr = $this->db->fetch_object($resql_usr)) {
558  $userstatic->id = $obj_usr->rowid;
559  $userstatic->lastname = $obj_usr->lastname;
560  $userstatic->firstname = $obj_usr->firstname;
561  $userstatic->photo = $obj_usr->photo;
562  $userstatic->statut = $obj_usr->status;
563  $userstatic->entity = $obj_usr->entity;
564  $userstatic->admin = $obj_usr->admin;
565 
566  $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
567  if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
568  $labeltoshow = $obj_usr->login;
569  }
570 
571  $out .= '<option value="'.$obj_usr->rowid.'"';
572  if ($obj_usr->rowid == $selected) {
573  $out .= ' selected';
574  }
575  $out .= ' data-html="';
576  $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
577  if ($showstatus >= 0 && $obj_usr->status == 0) {
578  $outhtml .= '<strike class="opacitymediumxxx">';
579  }
580  $outhtml .= $labeltoshow;
581  if ($showstatus >= 0 && $obj_usr->status == 0) {
582  $outhtml .= '</strike>';
583  }
584  $out .= dol_escape_htmltag($outhtml);
585  $out .= '">';
586 
587  $out .= $labeltoshow;
588  // Complete name with more info
589  $moreinfo = 0;
590  if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
591  $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
592  $moreinfo++;
593  }
594  if ($showstatus >= 0) {
595  if ($obj_usr->status == 1 && $showstatus == 1) {
596  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
597  $moreinfo++;
598  }
599  if ($obj_usr->status == 0) {
600  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
601  $moreinfo++;
602  }
603  }
604  $out .= ($moreinfo ? ')' : '');
605  $out .= '</option>';
606  }
607  $this->db->free($resql_usr);
608  } else {
609  dol_print_error($this->db);
610  }
611 
612  if ($norepresentative) {
613  $langs->load("companies");
614  $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
615  }
616 
617  $out .= '</select>';
618 
619  // Enhance with select2
620  if ($conf->use_javascript_ajax) {
621  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
622 
623  $comboenhancement = ajax_combobox($htmlname);
624  if ($comboenhancement) {
625  $out .= $comboenhancement;
626  }
627  }
628 
629  return $out;
630  }
631 
647  public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
648  {
649  global $user, $langs;
650 
651  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
652 
653  //print $modeproject.'-'.$modetask;
654  $task = new Task($this->db);
655  $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
656  if ($tasksarray) {
657  print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
658  if ($useempty) {
659  print '<option value="0">&nbsp;</option>';
660  }
661  $j = 0;
662  $level = 0;
663  $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
664  print '</select>';
665 
666  print ajax_combobox($htmlname);
667  } else {
668  print '<div class="warning">'.$langs->trans("NoProject").'</div>';
669  }
670  }
671 
684  private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
685  {
686  global $langs, $user, $conf;
687 
688  $lastprojectid = 0;
689 
690  $numlines = count($lines);
691  for ($i = 0; $i < $numlines; $i++) {
692  if ($lines[$i]->fk_task_parent == $parent) {
693  //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
694 
695  // Break on a new project
696  if ($parent == 0) { // We are on a task at first level
697  if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
698  if ($i > 0) {
699  print '<option value="0" disabled>----------</option>';
700  }
701  print '<option value="'.$lines[$i]->fk_project.'_0"';
702  if ($selectedproject == $lines[$i]->fk_project) {
703  print ' selected';
704  }
705 
706  $labeltoshow = $lines[$i]->projectref;
707  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
708  if (empty($lines[$i]->public)) {
709  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
710  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
711  } else {
712  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
713  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
714  }
715 
716  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
717  print '>'; // Project -> Task
718  print $labeltoshow;
719  print "</option>\n";
720 
721  $lastprojectid = $lines[$i]->fk_project;
722  $inc++;
723  }
724  }
725 
726  $newdisablechildoftaskid = $disablechildoftaskid;
727 
728  // Print task
729  if (isset($lines[$i]->id)) { // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
730  // Check if we must disable entry
731  $disabled = 0;
732  if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
733  $disabled++;
734  if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
735  $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
736  }
737  }
738 
739  print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
740  if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
741  print ' selected';
742  }
743  if ($disabled) {
744  print ' disabled';
745  }
746 
747  $labeltoshow = $lines[$i]->projectref;
748  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
749  if (empty($lines[$i]->public)) {
750  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
751  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
752  } else {
753  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
754  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
755  }
756  if ($lines[$i]->id) {
757  $labeltoshow .= ' > ';
758  }
759  for ($k = 0; $k < $level; $k++) {
760  $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
761  }
762  $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
763 
764  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
765  print '>';
766  print $labeltoshow;
767  print "</option>\n";
768  $inc++;
769  }
770 
771  $level++;
772  if ($lines[$i]->id) {
773  $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
774  }
775  $level--;
776  }
777  }
778  }
779 
780 
789  public static function showColor($color, $textifnotdefined = '')
790  {
791  $textcolor = 'FFF';
792  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
793  if (colorIsLight($color)) {
794  $textcolor = '000';
795  }
796 
797  $color = colorArrayToHex(colorStringToArray($color, array()), '');
798 
799  if ($color) {
800  return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
801  } else {
802  return $textifnotdefined;
803  }
804  }
805 
806  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
819  public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
820  {
821  // phpcs:enable
822  print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
823  }
824 
839  public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '', $default = '')
840  {
841  // Deprecation warning
842  if ($form_name) {
843  dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
844  }
845 
846  global $langs, $conf;
847 
848  $out = '';
849 
850  if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
851  // Case of selection of any color
852  $langs->load("other");
853  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
854  $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
855  $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
856  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
857  jQuery(document).ready(function(){
858  var originalhex = null;
859  $(\'#colorpicker'.$prefix.'\').jPicker( {
860  window: {
861  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
862  effects:
863  {
864  type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
865  speed:
866  {
867  show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
868  hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
869  }
870  },
871  position:
872  {
873  x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
874  y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
875  },
876  },
877  images: {
878  clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
879  picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
880  },
881  localization: // alter these to change the text presented by the picker (e.g. different language)
882  {
883  text:
884  {
885  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
886  newColor: \''.dol_escape_js($langs->trans("New")).'\',
887  currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
888  ok: \''.dol_escape_js($langs->trans("Validate")).'\',
889  cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
890  }
891  }
892  },
893  function(color, context) { console.log("close color selector"); },
894  function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
895  if ($setpropertyonselect) {
896  $out .= 'if (originalhex == null) {';
897  $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
898  $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
899  $out .= '}';
900  $out .= 'if (hex != null) {';
901  $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
902  $out .= '}';
903  }
904  $out .= '},
905  function(color, context) {
906  console.log("cancel selection of color");';
907  if ($setpropertyonselect) {
908  $out .= 'if (originalhex != null) {
909  console.log("Restore old color "+originalhex);
910  document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
911  }';
912  }
913  $out .= '
914  }
915  );
916  });
917  </script>';
918  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
919  } else {
920  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat input-nobottom colorselector valignmiddle '.($morecss ? ' '.$morecss : '').'" type="color" value="#'.dol_escape_htmltag($set_color !== '' ? $set_color : $default).'" />';
921  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
922  jQuery(document).ready(function(){
923  var originalhex = null;
924  jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
925  var hex = jQuery("#colorpicker'.$prefix.'").val();
926  console.log("new color selected in input color "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
927  if ($setpropertyonselect) {
928  $out .= 'if (originalhex == null) {';
929  $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
930  $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
931  $out .= '}';
932  $out .= 'if (hex != null) {';
933  $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
934  $out .= '}';
935  }
936  $out .= '
937  });
938  });
939  </script>';
940  }
941  } else {
942  // In most cases, this is not used. We used instead function with no specific list of colors
943  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
944  $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
945  $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
946  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
947  jQuery(document).ready(function(){
948  jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
949  size: 14,
950  label: \'\',
951  hide: true
952  });
953  });
954  </script>';
955  }
956  $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
957  //print '<option value="-1">&nbsp;</option>';
958  foreach ($arrayofcolors as $val) {
959  $out .= '<option value="'.$val.'"';
960  if ($set_color == $val) {
961  $out .= ' selected';
962  }
963  $out .= '>'.$val.'</option>';
964  }
965  $out .= '</select>';
966  }
967 
968  return $out;
969  }
970 
971  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
982  public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
983  {
984  // phpcs:enable
985  global $conf;
986 
987  $file = $conf->$module->dir_temp.'/'.$name.'.png';
988 
989  // On cree le repertoire contenant les icones
990  if (!file_exists($conf->$module->dir_temp)) {
991  dol_mkdir($conf->$module->dir_temp);
992  }
993 
994  // On cree l'image en vraies couleurs
995  $image = imagecreatetruecolor($x, $y);
996 
997  $color = substr($color, 1, 6);
998 
999  $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
1000  $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
1001  $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
1002 
1003  $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
1004  //print $rouge.$vert.$bleu;
1005  imagefill($image, 0, 0, $couleur); //on remplit l'image
1006  // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
1007  ImagePng($image, $file); //renvoie une image sous format png
1008  ImageDestroy($image);
1009  }
1010 
1011  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1020  public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
1021  {
1022  // phpcs:enable
1023  global $langs;
1024 
1025  $week = array(
1026  0=>$langs->trans("Day0"),
1027  1=>$langs->trans("Day1"),
1028  2=>$langs->trans("Day2"),
1029  3=>$langs->trans("Day3"),
1030  4=>$langs->trans("Day4"),
1031  5=>$langs->trans("Day5"),
1032  6=>$langs->trans("Day6")
1033  );
1034 
1035  $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1036  if ($useempty) {
1037  $select_week .= '<option value="-1">&nbsp;</option>';
1038  }
1039  foreach ($week as $key => $val) {
1040  if ($selected == $key) {
1041  $select_week .= '<option value="'.$key.'" selected>';
1042  } else {
1043  $select_week .= '<option value="'.$key.'">';
1044  }
1045  $select_week .= $val;
1046  $select_week .= '</option>';
1047  }
1048  $select_week .= '</select>';
1049 
1050  $select_week .= ajax_combobox($htmlname);
1051 
1052  return $select_week;
1053  }
1054 
1055  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1067  public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1068  {
1069  // phpcs:enable
1070  global $langs;
1071 
1072  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1073 
1074  if ($longlabel) {
1075  $montharray = monthArray($langs, 0); // Get array
1076  } else {
1077  $montharray = monthArray($langs, 1);
1078  }
1079 
1080  $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1081  if ($useempty) {
1082  $select_month .= '<option value="0">&nbsp;</option>';
1083  }
1084  foreach ($montharray as $key => $val) {
1085  if ($selected == $key) {
1086  $select_month .= '<option value="'.$key.'" selected>';
1087  } else {
1088  $select_month .= '<option value="'.$key.'">';
1089  }
1090  $select_month .= $val;
1091  $select_month .= '</option>';
1092  }
1093  $select_month .= '</select>';
1094 
1095  // Add code for jquery to use multiselect
1096  if ($addjscombo) {
1097  // Enhance with select2
1098  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1099  $select_month .= ajax_combobox($htmlname);
1100  }
1101 
1102  return $select_month;
1103  }
1104 
1105  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1122  public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp', $addjscombo = false)
1123  {
1124  // phpcs:enable
1125  print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1126  }
1127 
1143  public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1144  {
1145  $out = '';
1146 
1147  $currentyear = date("Y") + $offset;
1148  $max_year = $currentyear + $max_year;
1149  $min_year = $currentyear - $min_year;
1150  if (empty($selected) && empty($useempty)) {
1151  $selected = $currentyear;
1152  }
1153 
1154  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1155  if ($useempty) {
1156  $selected_html = '';
1157  if ($selected == '') {
1158  $selected_html = ' selected';
1159  }
1160  $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1161  }
1162  if (!$invert) {
1163  for ($y = $max_year; $y >= $min_year; $y--) {
1164  $selected_html = '';
1165  if ($selected > 0 && $y == $selected) {
1166  $selected_html = ' selected';
1167  }
1168  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1169  }
1170  } else {
1171  for ($y = $min_year; $y <= $max_year; $y++) {
1172  $selected_html = '';
1173  if ($selected > 0 && $y == $selected) {
1174  $selected_html = ' selected';
1175  }
1176  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1177  }
1178  }
1179  $out .= "</select>\n";
1180 
1181  // Add code for jquery to use multiselect
1182  if ($addjscombo) {
1183  // Enhance with select2
1184  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1185  $out .= ajax_combobox($htmlname);
1186  }
1187 
1188  return $out;
1189  }
1190 
1191 
1200  public static function getBoxesArea($user, $areacode)
1201  {
1202  global $conf, $langs, $db;
1203 
1204  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1205 
1206  $confuserzone = 'MAIN_BOXES_'.$areacode;
1207 
1208  // $boxactivated will be array of boxes enabled into global setup
1209  // $boxidactivatedforuser will be array of boxes choosed by user
1210 
1211  $selectboxlist = '';
1212  $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone) ?null:$user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
1213 
1214  $boxidactivatedforuser = array();
1215  foreach ($boxactivated as $box) {
1216  if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1217  $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1218  }
1219  }
1220 
1221  // Define selectboxlist
1222  $arrayboxtoactivatelabel = array();
1223  if (!empty($user->conf->$confuserzone)) {
1224  $boxorder = '';
1225  $langs->load("boxes"); // Load label of boxes
1226  foreach ($boxactivated as $box) {
1227  if (!empty($boxidactivatedforuser[$box->id])) {
1228  continue; // Already visible for user
1229  }
1230  $label = $langs->transnoentitiesnoconv($box->boxlabel);
1231  //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1232  if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1233  $label = $label.' <span class="fa fa-bar-chart"></span>';
1234  }
1235  $arrayboxtoactivatelabel[$box->id] = array('label'=>$label, 'data-html'=>img_picto('', $box->boximg, 'class="pictofixedwidth"').$langs->trans($label)); // We keep only boxes not shown for user, to show into combo list
1236  }
1237  foreach ($boxidactivatedforuser as $boxid) {
1238  if (empty($boxorder)) {
1239  $boxorder .= 'A:';
1240  }
1241  $boxorder .= $boxid.',';
1242  }
1243 
1244  //var_dump($boxidactivatedforuser);
1245 
1246  // Class Form must have been already loaded
1247  $selectboxlist .= '<!-- Form with select box list -->'."\n";
1248  $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1249  $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1250  $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1251  $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1252  $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1253  $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1254  $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone hideonprint', 0, 'hidden selected', 0, 0);
1255  if (empty($conf->use_javascript_ajax)) {
1256  $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1257  }
1258  $selectboxlist .= '</form>';
1259  if (!empty($conf->use_javascript_ajax)) {
1260  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1261  $selectboxlist .= ajax_combobox("boxcombo");
1262  }
1263  }
1264 
1265  // Javascript code for dynamic actions
1266  if (!empty($conf->use_javascript_ajax)) {
1267  $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1268 
1269  // To update list of activated boxes
1270  function updateBoxOrder(closing) {
1271  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1272  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1273  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1274  if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title
1275  {
1276  jQuery.ajax({
1277  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1278  async: false
1279  });
1280  // We force reload to be sure to get all boxes into list
1281  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1282  }
1283  else
1284  {
1285  jQuery.ajax({
1286  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1287  async: true
1288  });
1289  }
1290  }
1291 
1292  jQuery(document).ready(function() {
1293  jQuery("#boxcombo").change(function() {
1294  var boxid=jQuery("#boxcombo").val();
1295  if (boxid > 0) {
1296  console.log("A box widget has been selected for addition, we call ajax page to add it.")
1297  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1298  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1299  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1300  jQuery.ajax({
1301  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1302  }).done(function() {
1303  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1304  });
1305  }
1306  });';
1307  if (!count($arrayboxtoactivatelabel)) {
1308  $selectboxlist .= 'jQuery("#boxcombo").hide();';
1309  }
1310  $selectboxlist .= '
1311 
1312  jQuery("#boxhalfleft, #boxhalfright").sortable({
1313  handle: \'.boxhandle\',
1314  revert: \'invalid\',
1315  items: \'.boxdraggable\',
1316  containment: \'document\',
1317  connectWith: \'#boxhalfleft, #boxhalfright\',
1318  stop: function(event, ui) {
1319  console.log("We moved box so we call updateBoxOrder with ajax actions");
1320  updateBoxOrder(1); /* 1 to avoid message after a move */
1321  }
1322  });
1323 
1324  jQuery(".boxclose").click(function() {
1325  var self = this; // because JQuery can modify this
1326  var boxid = self.id.substring(8);
1327  if (boxid > 0) {
1328  var label = jQuery(\'#boxlabelentry\'+boxid).val();
1329  console.log("We close box "+boxid);
1330  jQuery(\'#boxto_\'+boxid).remove();
1331  jQuery(\'#boxcombo\').append(new Option(label, boxid));
1332  updateBoxOrder(1); /* 1 to avoid message after a remove */
1333  }
1334  });
1335 
1336  });'."\n";
1337 
1338  $selectboxlist .= '</script>'."\n";
1339  }
1340 
1341  // Define boxlista and boxlistb
1342  $boxlista = '';
1343  $boxlistb = '';
1344  $nbboxactivated = count($boxidactivatedforuser);
1345 
1346  if ($nbboxactivated) {
1347  // Load translation files required by the page
1348  $langs->loadLangs(array("boxes", "projects"));
1349 
1350  $emptybox = new ModeleBoxes($db);
1351 
1352  $boxlista .= "\n<!-- Box left container -->\n";
1353 
1354  // Define $box_max_lines
1355  $box_max_lines = 5;
1356  if (!empty($conf->global->MAIN_BOXES_MAXLINES)) {
1357  $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1358  }
1359 
1360  $ii = 0;
1361  foreach ($boxactivated as $key => $box) {
1362  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1363  continue;
1364  }
1365  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1366  $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1367  }
1368  if (preg_match('/^A/i', $box->box_order)) { // column A
1369  $ii++;
1370  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1371  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1372  // Show box
1373  $box->loadBox($box_max_lines);
1374  $boxlista .= $box->showBox(null, null, 1);
1375  }
1376  }
1377 
1378  if ($conf->browser->layout != 'phone') {
1379  $emptybox->box_id = 'A';
1380  $emptybox->info_box_head = array();
1381  $emptybox->info_box_contents = array();
1382  $boxlista .= $emptybox->showBox(array(), array(), 1);
1383  }
1384  $boxlista .= "<!-- End box left container -->\n";
1385 
1386  $boxlistb .= "\n<!-- Box right container -->\n";
1387 
1388  $ii = 0;
1389  foreach ($boxactivated as $key => $box) {
1390  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1391  continue;
1392  }
1393  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1394  $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1395  }
1396  if (preg_match('/^B/i', $box->box_order)) { // colonne B
1397  $ii++;
1398  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1399  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1400  // Show box
1401  $box->loadBox($box_max_lines);
1402  $boxlistb .= $box->showBox(null, null, 1);
1403  }
1404  }
1405 
1406  if ($conf->browser->layout != 'phone') {
1407  $emptybox->box_id = 'B';
1408  $emptybox->info_box_head = array();
1409  $emptybox->info_box_contents = array();
1410  $boxlistb .= $emptybox->showBox(array(), array(), 1);
1411  }
1412 
1413  $boxlistb .= "<!-- End box right container -->\n";
1414  }
1415 
1416  return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1417  }
1418 
1419 
1420  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1433  public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1434  {
1435  // phpcs:enable
1436  global $langs, $conf;
1437 
1438  $langs->load("admin");
1439 
1440  $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1441  $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1442  $sql .= " ORDER BY ".$labelfield;
1443 
1444  dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1445  $result = $this->db->query($sql);
1446  if ($result) {
1447  $num = $this->db->num_rows($result);
1448  $i = 0;
1449  if ($num) {
1450  print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1451  if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1452  print '<option value="-1">&nbsp;</option>';
1453  }
1454 
1455  while ($i < $num) {
1456  $obj = $this->db->fetch_object($result);
1457  if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1458  print '<option value="'.$obj->{$keyfield}.'" selected>';
1459  } else {
1460  print '<option value="'.$obj->{$keyfield}.'">';
1461  }
1462  $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != ($dictionarytable.$obj->{$labelfield}) ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1463  print $label;
1464  print '</option>';
1465  $i++;
1466  }
1467  print "</select>";
1468  } else {
1469  print $langs->trans("DictionaryEmpty");
1470  }
1471  } else {
1472  dol_print_error($this->db);
1473  }
1474  }
1475 
1486  public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1487  {
1488  global $langs;
1489 
1490  $automatic = "automatic";
1491  $manual = "manual";
1492  if ($option) {
1493  $automatic = "1";
1494  $manual = "0";
1495  }
1496 
1497  $disabled = ($disabled ? ' disabled' : '');
1498 
1499  $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1500  if ($useempty) {
1501  $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1502  }
1503  if (("$value" == 'automatic') || ($value == 1)) {
1504  $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1505  $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1506  } else {
1507  $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1508  $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1509  $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1510  }
1511  $resultautomanual .= '</select>'."\n";
1512  return $resultautomanual;
1513  }
1514 
1515 
1526  public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1527  {
1528  global $langs, $extrafields, $form;
1529 
1530  $arrayofgroupbylabel = array();
1531  foreach ($arrayofgroupby as $key => $val) {
1532  $arrayofgroupbylabel[$key] = $val['label'];
1533  }
1534  $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1535 
1536  return $result;
1537  }
1538 
1549  public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1550  {
1551  global $form;
1552 
1553  $arrayofxaxislabel = array();
1554  foreach ($arrayofxaxis as $key => $val) {
1555  $arrayofxaxislabel[$key] = $val['label'];
1556  }
1557  $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1558 
1559  return $result;
1560  }
1561 }
Classe permettant la generation de composants html autre Only common components are here.
__construct($db)
Constructor.
select_dictionary($htmlname, $dictionarytable, $keyfield='code', $labelfield='label', $selected='', $useempty=0, $moreattrib='')
Return a HTML select list of a dictionary.
getHTMLScannerForm($jstoexecuteonadd='barcodescannerjs', $mode='all')
Return the HTML code for scanner tool.
Class toolbox to validate values.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
table tableforfield button
0 = Do not include form tag and submit button -1 = Do not include form tag but include submit button
Definition: style.css.php:848
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:120
$conf db user
Definition: repair.php:124