dolibarr  20.0.0-beta
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  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
14  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
41 class FormOther
42 {
43  private $db;
44 
48  public $error;
49 
50 
56  public function __construct($db)
57  {
58  $this->db = $db;
59  }
60 
70  public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode = 'all', $warehouseselect = 0)
71  {
72  global $langs;
73 
74  $out = '';
75 
76  $out .= '<!-- Popup for mass barcode scanning -->'."\n";
77  $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
78  $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
79 
80  if ($mode == 'product') {
81  $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
82  } elseif ($mode == 'lot') {
83  $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
84  } else { // $mode = 'all'
85  $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>';
86  $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
87  $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
88  }
89  $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
90  $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
91  $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
92  $out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
93  if ($warehouseselect > 0) {
94  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
95  $formproduct = new FormProduct($this->db);
96  $formproduct->loadWarehouses();
97  $out .= img_picto('', 'stock', 'class="pictofixedwidth"');
98  $out .= $formproduct->selectWarehouses('', "warehousenew", '', 0, 0, 0, '', 0, 1);
99  $out .= '<br>';
100  $out .= '<br>';
101  }
102  $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
103 
104  /*print '<br>'.$langs->trans("or").'<br>';
105 
106  print '<br>';
107 
108  print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
109  */
110  $out .= '<br>';
111  $out .= '<center>';
112  $out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).'" name="addscan" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
113  $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
114  $out .= '</center>';
115  $out .= '<br>';
116  $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
117 
118  $out .= '<script nonce="'.getNonce().'">';
119  $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
120  $out .= 'console.log("select choice");';
121  $out .= 'jQuery("#scantoolmessage").text("");';
122  $out .= '});'."\n";
123  $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
124  console.log("We call js to execute \''.dol_escape_js($jstoexecuteonadd).'\'");
125  '.dol_escape_js($jstoexecuteonadd).'();
126  return false; /* We want to stay on the scan tool */
127  })';
128  $out .= '</script>';
129 
130  $out .= '</center>';
131  $out .= '</div>';
132 
133  return $out;
134  }
135 
136  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
147  public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
148  {
149  // phpcs:enable
150  global $conf, $langs, $user;
151 
152  $sql = "SELECT rowid, label, fk_user";
153  $sql .= " FROM ".$this->db->prefix()."export_model";
154  $sql .= " WHERE type = '".$this->db->escape($type)."'";
155  if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
156  $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
157  }
158  $sql .= " ORDER BY label";
159  $result = $this->db->query($sql);
160  if ($result) {
161  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
162  if ($useempty) {
163  print '<option value="-1">&nbsp;</option>';
164  }
165 
166  $tmpuser = new User($this->db);
167 
168  $num = $this->db->num_rows($result);
169  $i = 0;
170  while ($i < $num) {
171  $obj = $this->db->fetch_object($result);
172 
173  $label = $obj->label;
174  if ($obj->fk_user == 0) {
175  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
176  } elseif ($obj->fk_user > 0) {
177  $tmpuser->fetch($obj->fk_user);
178  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
179  }
180 
181  if ($selected == $obj->rowid) {
182  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
183  } else {
184  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
185  }
186  print $label;
187  print '</option>';
188  $i++;
189  }
190  print "</select>";
191  print ajax_combobox($htmlname);
192  } else {
193  dol_print_error($this->db);
194  }
195  }
196 
197 
198  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
209  public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
210  {
211  // phpcs:enable
212  global $conf, $langs, $user;
213 
214  $sql = "SELECT rowid, label, fk_user";
215  $sql .= " FROM ".$this->db->prefix()."import_model";
216  $sql .= " WHERE type = '".$this->db->escape($type)."'";
217  if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
218  $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
219  }
220  $sql .= " ORDER BY label";
221  $result = $this->db->query($sql);
222  if ($result) {
223  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
224  if ($useempty) {
225  print '<option value="-1">&nbsp;</option>';
226  }
227 
228  $tmpuser = new User($this->db);
229 
230  $num = $this->db->num_rows($result);
231  $i = 0;
232  while ($i < $num) {
233  $obj = $this->db->fetch_object($result);
234 
235  $label = $obj->label;
236  if ($obj->fk_user == 0) {
237  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
238  } elseif ($obj->fk_user > 0) {
239  $tmpuser->fetch($obj->fk_user);
240  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
241  }
242 
243  if ($selected == $obj->rowid) {
244  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
245  } else {
246  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
247  }
248  print $label;
249  print '</option>';
250  $i++;
251  }
252  print "</select>";
253  print ajax_combobox($htmlname);
254  } else {
255  dol_print_error($this->db);
256  }
257  }
258 
259 
260  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
268  public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
269  {
270  // phpcs:enable
271  global $langs;
272 
273  $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
274  $sql .= " c.label as country";
275  $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
276  $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
277  $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
278 
279  dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
280  $resql = $this->db->query($sql);
281  if ($resql) {
282  print '<select class="flat" name="'.$htmlname.'">';
283  $num = $this->db->num_rows($resql);
284  $i = 0;
285  print '<option value="-1">&nbsp;</option>'."\n";
286  if ($num) {
287  while ($i < $num) {
288  $obj = $this->db->fetch_object($resql);
289  if ($selected && $selected == $obj->rowid) {
290  print '<option value="'.$obj->rowid.'" selected>';
291  } else {
292  print '<option value="'.$obj->rowid.'">';
293  //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
294  }
295  $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
296  print $selectOptionValue;
297  print '</option>';
298  $i++;
299  }
300  }
301  print '</select>';
302  return 0;
303  } else {
304  dol_print_error($this->db);
305  return 1;
306  }
307  }
308 
309 
310  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
319  public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
320  {
321  // phpcs:enable
322  global $langs;
323 
324  $out = '';
325 
326  $sql = "SELECT r.taux, r.revenuestamp_type";
327  $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
328  $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
329  $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
330 
331  dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
332  $resql = $this->db->query($sql);
333  if ($resql) {
334  $out .= '<select class="flat" name="'.$htmlname.'">';
335  $num = $this->db->num_rows($resql);
336  $i = 0;
337  $out .= '<option value="0">&nbsp;</option>'."\n";
338  if ($num) {
339  while ($i < $num) {
340  $obj = $this->db->fetch_object($resql);
341  if (($selected && $selected == $obj->taux) || $num == 1) {
342  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
343  } else {
344  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
345  }
346  $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
347  $out .= '</option>';
348  $i++;
349  }
350  }
351  $out .= '</select>';
352  return $out;
353  } else {
354  dol_print_error($this->db);
355  return '';
356  }
357  }
358 
359 
360  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
373  public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
374  {
375  // phpcs:enable
376  $return = '<select class="flat maxwidth75 right" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
377  if ($showempty) {
378  $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
379  }
380 
381  for ($i = $start; $i <= $end; $i += $increment) {
382  if ($selected != '' && (int) $selected == $i) {
383  $return .= '<option value="'.$i.'" selected>';
384  } else {
385  $return .= '<option value="'.$i.'">';
386  }
387  $return .= $i.' % ';
388  $return .= '</option>';
389  }
390 
391  $return .= '</select>';
392 
393  return $return;
394  }
395 
396  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
409  public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
410  {
411  // phpcs:enable
412  global $conf, $langs;
413  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
414 
415  // For backward compatibility
416  if (is_numeric($type)) {
417  dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
418  }
419 
420  // Load list of "categories"
421  $static_categs = new Categorie($this->db);
422  $tab_categs = $static_categs->get_full_arbo($type);
423 
424  $moreforfilter = '';
425 
426  // Print a select with each of them
427  $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
428  if ($showempty) {
429  $textforempty = ' ';
430  if (!empty($conf->use_javascript_ajax)) {
431  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
432  }
433  if (!is_numeric($showempty)) {
434  $textforempty = $showempty;
435  }
436  $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
437  //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
438  $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
439  }
440 
441  if (is_array($tab_categs)) {
442  foreach ($tab_categs as $categ) {
443  $moreforfilter .= '<option value="'.$categ['id'].'"';
444  if ($categ['id'] == $selected) {
445  $moreforfilter .= ' selected';
446  }
447  $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
448  $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
449  }
450  }
451  if ($nocateg) {
452  $langs->load("categories");
453  $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
454  }
455  $moreforfilter .= '</select>';
456 
457  // Enhance with select2
458  if ($conf->use_javascript_ajax) {
459  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
460  $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
461  $moreforfilter .= $comboenhancement;
462  }
463 
464  return $moreforfilter;
465  }
466 
467 
468  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
481  public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
482  {
483  // phpcs:enable
484  global $conf, $langs, $hookmanager;
485  global $action;
486 
487  $langs->load('users');
488 
489  $out = '';
490 
491  $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
492 
493  // Select each sales and print them in a select input
494  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
495  if ($showempty) {
496  $textforempty = ' ';
497  if (!is_numeric($showempty)) {
498  $textforempty = $showempty;
499  }
500  if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
501  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
502  }
503  $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
504  }
505 
506  // Get list of users allowed to be viewed
507  $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
508  $sql_usr .= " FROM ".$this->db->prefix()."user as u";
509 
510  if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
511  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
512  $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
513  } else {
514  $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')."))";
515  $sql_usr .= " OR u.entity = 0"; // Show always superadmin
516  }
517  } else {
518  $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
519  }
520 
521  if (!$user->hasRight('user', 'user', 'lire')) {
522  $sql_usr .= " AND u.rowid = ".((int) $user->id);
523  }
524  if (!empty($user->socid)) {
525  $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
526  }
527  if (getDolGlobalString('USER_HIDE_NONEMPLOYEE_IN_COMBOBOX')) {
528  $sql_usr .= " AND u.employee <> 0";
529  }
530  if (getDolGlobalString('USER_HIDE_EXTERNAL_IN_COMBOBOX')) {
531  $sql_usr .= " AND u.fk_soc IS NULL";
532  }
533  if (getDolGlobalString('USER_HIDE_INACTIVE_IN_COMBOBOX')) {
534  $sql_usr .= " AND u.statut <> 0";
535  }
536 
537  //Add hook to filter on user (for example on usergroup define in custom modules)
538  if (!empty($reshook)) {
539  $sql_usr .= $hookmanager->resArray[0];
540  }
541 
542  // Add existing sales representatives of thirdparty of external user
543  if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
544  $sql_usr .= " UNION ";
545  $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
546  $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
547 
548  if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
549  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
550  $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
551  } else {
552  $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')."))";
553  }
554  } else {
555  $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
556  }
557 
558  $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
559 
560  //Add hook to filter on user (for example on usergroup define in custom modules)
561  if (!empty($reshook)) {
562  $sql_usr .= $hookmanager->resArray[1];
563  }
564  }
565 
566  if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
567  $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
568  } else {
569  $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
570  }
571  //print $sql_usr;exit;
572 
573  $resql_usr = $this->db->query($sql_usr);
574  if ($resql_usr) {
575  $userstatic = new User($this->db);
576 
577  while ($obj_usr = $this->db->fetch_object($resql_usr)) {
578  $userstatic->id = $obj_usr->rowid;
579  $userstatic->lastname = $obj_usr->lastname;
580  $userstatic->firstname = $obj_usr->firstname;
581  $userstatic->photo = $obj_usr->photo;
582  $userstatic->status = $obj_usr->status;
583  $userstatic->entity = $obj_usr->entity;
584  $userstatic->admin = $obj_usr->admin;
585 
586  $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
587  if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
588  $labeltoshow = $obj_usr->login;
589  }
590 
591  $out .= '<option value="'.$obj_usr->rowid.'"';
592  if ($obj_usr->rowid == $selected) {
593  $out .= ' selected';
594  }
595  $out .= ' data-html="';
596  $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
597  if ($showstatus >= 0 && $obj_usr->status == 0) {
598  $outhtml .= '<strike class="opacitymediumxxx">';
599  }
600  $outhtml .= $labeltoshow;
601  if ($showstatus >= 0 && $obj_usr->status == 0) {
602  $outhtml .= '</strike>';
603  }
604  $out .= dol_escape_htmltag($outhtml);
605  $out .= '">';
606 
607  $out .= $labeltoshow;
608  // Complete name with more info
609  $moreinfo = 0;
610  if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
611  $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
612  $moreinfo++;
613  }
614  if ($showstatus >= 0) {
615  if ($obj_usr->status == 1 && $showstatus == 1) {
616  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
617  $moreinfo++;
618  }
619  if ($obj_usr->status == 0) {
620  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
621  $moreinfo++;
622  }
623  }
624  $out .= ($moreinfo ? ')' : '');
625  $out .= '</option>';
626  }
627  $this->db->free($resql_usr);
628  } else {
629  dol_print_error($this->db);
630  }
631 
632  if ($norepresentative) {
633  $langs->load("companies");
634  $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
635  }
636 
637  $out .= '</select>';
638 
639  // Enhance with select2
640  if ($conf->use_javascript_ajax) {
641  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
642 
643  $comboenhancement = ajax_combobox($htmlname);
644  if ($comboenhancement) {
645  $out .= $comboenhancement;
646  }
647  }
648 
649  return $out;
650  }
651 
667  public function selectProjectTasks($selectedtask = 0, $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
668  {
669  global $user, $langs;
670 
671  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
672 
673  //print $modeproject.'-'.$modetask;
674  $task = new Task($this->db);
675  $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
676  if ($tasksarray) {
677  print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
678  if ($useempty) {
679  print '<option value="0">&nbsp;</option>';
680  }
681  $j = 0;
682  $level = 0;
683  $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
684  print '</select>';
685 
686  print ajax_combobox($htmlname);
687  } else {
688  print '<div class="warning">'.$langs->trans("NoProject").'</div>';
689  }
690  }
691 
704  private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
705  {
706  global $langs, $user, $conf;
707 
708  $lastprojectid = 0;
709 
710  $numlines = count($lines);
711  for ($i = 0; $i < $numlines; $i++) {
712  if ($lines[$i]->fk_task_parent == $parent) {
713  //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
714 
715  // Break on a new project
716  if ($parent == 0) { // We are on a task at first level
717  if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
718  if ($i > 0) {
719  print '<option value="0" disabled>----------</option>';
720  }
721  print '<option value="'.$lines[$i]->fk_project.'_0"';
722  if ($selectedproject == $lines[$i]->fk_project) {
723  print ' selected';
724  }
725 
726  $labeltoshow = $lines[$i]->projectref;
727  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
728  if (empty($lines[$i]->public)) {
729  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
730  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
731  } else {
732  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
733  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
734  }
735 
736  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
737  print '>'; // Project -> Task
738  print $labeltoshow;
739  print "</option>\n";
740 
741  $lastprojectid = $lines[$i]->fk_project;
742  $inc++;
743  }
744  }
745 
746  $newdisablechildoftaskid = $disablechildoftaskid;
747 
748  // Print task
749  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
750  // Check if we must disable entry
751  $disabled = 0;
752  if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
753  $disabled++;
754  if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
755  $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
756  }
757  }
758 
759  print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
760  if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
761  print ' selected';
762  }
763  if ($disabled) {
764  print ' disabled';
765  }
766 
767  $labeltoshow = $lines[$i]->projectref;
768  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
769  if (empty($lines[$i]->public)) {
770  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
771  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
772  } else {
773  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
774  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
775  }
776  if ($lines[$i]->id) {
777  $labeltoshow .= ' > ';
778  }
779  for ($k = 0; $k < $level; $k++) {
780  $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
781  }
782  $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
783 
784  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
785  print '>';
786  print $labeltoshow;
787  print "</option>\n";
788  $inc++;
789  }
790 
791  $level++;
792  if ($lines[$i]->id) {
793  $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
794  }
795  $level--;
796  }
797  }
798  }
799 
800 
809  public static function showColor($color, $textifnotdefined = '')
810  {
811  $textcolor = 'FFF';
812  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
813  if (colorIsLight($color)) {
814  $textcolor = '000';
815  }
816 
817  $color = colorArrayToHex(colorStringToArray($color, array()), '');
818 
819  if ($color) {
820  return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
821  } else {
822  return $textifnotdefined;
823  }
824  }
825 
826  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
839  public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [])
840  {
841  // phpcs:enable
842  print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
843  }
844 
859  public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = [], $morecss = '', $setpropertyonselect = '', $default = '')
860  {
861  // Deprecation warning
862  if ($form_name) {
863  dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
864  }
865 
866  global $langs, $conf;
867 
868  $out = '';
869 
870  if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
871  // Case of selection of any color
872  $langs->load("other");
873  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
874  $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
875  $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
876  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
877  jQuery(document).ready(function(){
878  var originalhex = null;
879  $(\'#colorpicker'.$prefix.'\').jPicker( {
880  window: {
881  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
882  effects:
883  {
884  type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
885  speed:
886  {
887  show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
888  hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
889  }
890  },
891  position:
892  {
893  x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
894  y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
895  },
896  },
897  images: {
898  clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
899  picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
900  },
901  localization: // alter these to change the text presented by the picker (e.g. different language)
902  {
903  text:
904  {
905  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
906  newColor: \''.dol_escape_js($langs->trans("New")).'\',
907  currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
908  ok: \''.dol_escape_js($langs->trans("Validate")).'\',
909  cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
910  }
911  }
912  },
913  function(color, context) { console.log("close color selector"); },
914  function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
915  if ($setpropertyonselect) {
916  $out .= 'if (originalhex == null) {';
917  $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
918  $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
919  $out .= '}';
920  $out .= 'if (hex != null) {';
921  $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
922  $out .= '}';
923  }
924  $out .= '},
925  function(color, context) {
926  console.log("cancel selection of color");';
927  if ($setpropertyonselect) {
928  $out .= 'if (originalhex != null) {
929  console.log("Restore old color "+originalhex);
930  document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
931  }';
932  }
933  $out .= '
934  }
935  );
936  });
937  </script>';
938  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
939  } else {
940  $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
941  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat input-nobottom colorselector valignmiddle '.($morecss ? ' '.$morecss : '').'" type="color" data-default="'.$default.'" value="'.dol_escape_htmltag(preg_match('/^#/', $color) ? $color : '#'.$color).'" />';
942  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
943  jQuery(document).ready(function(){
944  var originalhex = null;
945  jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
946  var hex = jQuery("#colorpicker'.$prefix.'").val();
947  console.log("new color selected in input color "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
948  if ($setpropertyonselect) {
949  $out .= 'if (originalhex == null) {';
950  $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
951  $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
952  $out .= '}';
953  $out .= 'if (hex != null) {';
954  $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
955  $out .= '}';
956  }
957  $out .= '
958  });
959  });
960  </script>';
961  }
962  } else {
963  // In most cases, this is not used. We used instead function with no specific list of colors
964  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
965  $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
966  $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
967  $out .= '<script nonce="'.getNonce().'" type="text/javascript">
968  jQuery(document).ready(function(){
969  jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
970  size: 14,
971  label: \'\',
972  hide: true
973  });
974  });
975  </script>';
976  }
977  $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
978  //print '<option value="-1">&nbsp;</option>';
979  foreach ($arrayofcolors as $val) {
980  $out .= '<option value="'.$val.'"';
981  if ($set_color == $val) {
982  $out .= ' selected';
983  }
984  $out .= '>'.$val.'</option>';
985  }
986  $out .= '</select>';
987  }
988 
989  return $out;
990  }
991 
992  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1003  public function CreateColorIcon($color, $module, $name, $x = 12, $y = 12)
1004  {
1005  // phpcs:enable
1006  global $conf;
1007 
1008  $file = $conf->$module->dir_temp.'/'.$name.'.png';
1009 
1010  // We create temp directory
1011  if (!file_exists($conf->$module->dir_temp)) {
1012  dol_mkdir($conf->$module->dir_temp);
1013  }
1014 
1015  // On cree l'image en vraies couleurs
1016  $image = imagecreatetruecolor($x, $y);
1017 
1018  $color = substr($color, 1, 6);
1019 
1020  $red = hexdec(substr($color, 0, 2)); // Red channel conversion
1021  $green = hexdec(substr($color, 2, 2)); // Green channel conversion
1022  $blue = hexdec(substr($color, 4, 2)); // Blue channel conversion
1023 
1024  $couleur = imagecolorallocate($image, $red, $green, $blue);
1025  //print $red.$green.$blue;
1026  imagefill($image, 0, 0, $couleur); // Fill the image
1027  // Create the colr and store it in a variable to maintain it
1028  imagepng($image, $file); // Returns an image in PNG format
1029  imagedestroy($image);
1030  }
1031 
1032  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1041  public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
1042  {
1043  // phpcs:enable
1044  global $langs;
1045 
1046  $week = array(
1047  0 => $langs->trans("Day0"),
1048  1 => $langs->trans("Day1"),
1049  2 => $langs->trans("Day2"),
1050  3 => $langs->trans("Day3"),
1051  4 => $langs->trans("Day4"),
1052  5 => $langs->trans("Day5"),
1053  6 => $langs->trans("Day6")
1054  );
1055 
1056  $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1057  if ($useempty) {
1058  $select_week .= '<option value="-1">&nbsp;</option>';
1059  }
1060  foreach ($week as $key => $val) {
1061  if ($selected == $key) {
1062  $select_week .= '<option value="'.$key.'" selected>';
1063  } else {
1064  $select_week .= '<option value="'.$key.'">';
1065  }
1066  $select_week .= $val;
1067  $select_week .= '</option>';
1068  }
1069  $select_week .= '</select>';
1070 
1071  $select_week .= ajax_combobox($htmlname);
1072 
1073  return $select_week;
1074  }
1075 
1076  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1088  public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1089  {
1090  // phpcs:enable
1091  global $langs;
1092 
1093  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1094 
1095  if ($longlabel) {
1096  $montharray = monthArray($langs, 0); // Get array
1097  } else {
1098  $montharray = monthArray($langs, 1);
1099  }
1100 
1101  $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1102  if ($useempty) {
1103  $select_month .= '<option value="0">&nbsp;</option>';
1104  }
1105  foreach ($montharray as $key => $val) {
1106  if ($selected == $key) {
1107  $select_month .= '<option value="'.$key.'" selected>';
1108  } else {
1109  $select_month .= '<option value="'.$key.'">';
1110  }
1111  $select_month .= $val;
1112  $select_month .= '</option>';
1113  }
1114  $select_month .= '</select>';
1115 
1116  // Add code for jquery to use multiselect
1117  if ($addjscombo) {
1118  // Enhance with select2
1119  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1120  $select_month .= ajax_combobox($htmlname);
1121  }
1122 
1123  return $select_month;
1124  }
1125 
1126  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1143  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)
1144  {
1145  // phpcs:enable
1146  print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1147  }
1148 
1164  public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1165  {
1166  $out = '';
1167 
1168  $currentyear = idate("Y") + $offset;
1169  $max_year = $currentyear + $max_year;
1170  $min_year = $currentyear - $min_year;
1171  if (empty($selected) && empty($useempty)) {
1172  $selected = $currentyear;
1173  }
1174 
1175  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1176  if ($useempty) {
1177  $selected_html = '';
1178  if ($selected == '') {
1179  $selected_html = ' selected';
1180  }
1181  $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1182  }
1183  if (!$invert) {
1184  for ($y = $max_year; $y >= $min_year; $y--) {
1185  $selected_html = '';
1186  if ($selected > 0 && $y == $selected) {
1187  $selected_html = ' selected';
1188  }
1189  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1190  }
1191  } else {
1192  for ($y = $min_year; $y <= $max_year; $y++) {
1193  $selected_html = '';
1194  if ($selected > 0 && $y == $selected) {
1195  $selected_html = ' selected';
1196  }
1197  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1198  }
1199  }
1200  $out .= "</select>\n";
1201 
1202  // Add code for jquery to use multiselect
1203  if ($addjscombo) {
1204  // Enhance with select2
1205  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1206  $out .= ajax_combobox($htmlname);
1207  }
1208 
1209  return $out;
1210  }
1211 
1212 
1221  public static function getBoxesArea($user, $areacode)
1222  {
1223  global $conf, $langs, $db;
1224 
1225  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1226 
1227  $confuserzone = 'MAIN_BOXES_'.$areacode;
1228 
1229  // $boxactivated will be array of boxes enabled into global setup
1230  // $boxidactivatedforuser will be array of boxes chose by user
1231 
1232  $selectboxlist = '';
1233  $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)
1234 
1235  $boxidactivatedforuser = array();
1236  foreach ($boxactivated as $box) {
1237  if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1238  $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1239  }
1240  }
1241 
1242  // Define selectboxlist
1243  $arrayboxtoactivatelabel = array();
1244  if (!empty($user->conf->$confuserzone)) {
1245  $boxorder = '';
1246  $langs->load("boxes"); // Load label of boxes
1247  foreach ($boxactivated as $box) {
1248  if (!empty($boxidactivatedforuser[$box->id])) {
1249  continue; // Already visible for user
1250  }
1251  $label = $langs->transnoentitiesnoconv($box->boxlabel);
1252  //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1253  if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1254  $label = $label.' <span class="fas fa-chart-bar"></span>';
1255  }
1256  $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
1257  }
1258  foreach ($boxidactivatedforuser as $boxid) {
1259  if (empty($boxorder)) {
1260  $boxorder .= 'A:';
1261  }
1262  $boxorder .= $boxid.',';
1263  }
1264 
1265  //var_dump($boxidactivatedforuser);
1266 
1267  // Class Form must have been already loaded
1268  $selectboxlist .= '<!-- Form with select box list -->'."\n";
1269  $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1270  $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1271  $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1272  $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1273  $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1274  $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1275  $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth300 hideonprint', 0, 'hidden selected', 0, 0);
1276  if (empty($conf->use_javascript_ajax)) {
1277  $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1278  }
1279  $selectboxlist .= '</form>';
1280  if (!empty($conf->use_javascript_ajax)) {
1281  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1282  $selectboxlist .= ajax_combobox("boxcombo");
1283  }
1284  }
1285 
1286  // Javascript code for dynamic actions
1287  if (!empty($conf->use_javascript_ajax)) {
1288  $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
1289 
1290  // To update list of activated boxes
1291  function updateBoxOrder(closing) {
1292  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1293  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1294  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1295  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
1296  {
1297  jQuery.ajax({
1298  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1299  async: false
1300  });
1301  // We force reload to be sure to get all boxes into list
1302  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1303  }
1304  else
1305  {
1306  jQuery.ajax({
1307  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1308  async: true
1309  });
1310  }
1311  }
1312 
1313  jQuery(document).ready(function() {
1314  jQuery("#boxcombo").change(function() {
1315  var boxid=jQuery("#boxcombo").val();
1316  if (boxid > 0) {
1317  console.log("A box widget has been selected for addition, we call ajax page to add it.")
1318  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1319  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1320  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1321  jQuery.ajax({
1322  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1323  }).done(function() {
1324  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1325  });
1326  }
1327  });';
1328  if (!count($arrayboxtoactivatelabel)) {
1329  $selectboxlist .= 'jQuery("#boxcombo").hide();';
1330  }
1331  $selectboxlist .= '
1332 
1333  jQuery("#boxhalfleft, #boxhalfright").sortable({
1334  handle: \'.boxhandle\',
1335  revert: \'invalid\',
1336  items: \'.boxdraggable\',
1337  containment: \'document\',
1338  connectWith: \'#boxhalfleft, #boxhalfright\',
1339  stop: function(event, ui) {
1340  console.log("We moved box so we call updateBoxOrder with ajax actions");
1341  updateBoxOrder(1); /* 1 to avoid message after a move */
1342  }
1343  });
1344 
1345  jQuery(".boxclose").click(function() {
1346  var self = this; // because JQuery can modify this
1347  var boxid = self.id.substring(8);
1348  if (boxid > 0) {
1349  var label = jQuery(\'#boxlabelentry\'+boxid).val();
1350  console.log("We close box "+boxid);
1351  jQuery(\'#boxto_\'+boxid).remove();
1352  jQuery(\'#boxcombo\').append(new Option(label, boxid));
1353  updateBoxOrder(1); /* 1 to avoid message after a remove */
1354  }
1355  });
1356 
1357  });'."\n";
1358 
1359  $selectboxlist .= '</script>'."\n";
1360  }
1361 
1362  // Define boxlista and boxlistb
1363  $boxlista = '';
1364  $boxlistb = '';
1365  $nbboxactivated = count($boxidactivatedforuser);
1366 
1367  if ($nbboxactivated) {
1368  // Load translation files required by the page
1369  $langs->loadLangs(array("boxes", "projects"));
1370 
1371  $emptybox = new ModeleBoxes($db);
1372 
1373  $boxlista .= "\n<!-- Box left container -->\n";
1374 
1375  // Define $box_max_lines
1376  $box_max_lines = getDolUserInt('MAIN_SIZE_SHORTLIST_LIMIT', getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5));
1377 
1378  $ii = 0;
1379  foreach ($boxactivated as $key => $box) {
1380  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1381  continue;
1382  }
1383  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1384  $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1385  }
1386  if (preg_match('/^A/i', $box->box_order)) { // column A
1387  $ii++;
1388  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1389  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1390  // Show box
1391  $box->loadBox($box_max_lines);
1392  $boxlista .= $box->showBox(null, null, 1);
1393  }
1394  }
1395 
1396  if ($conf->browser->layout != 'phone') {
1397  $emptybox->box_id = 'A';
1398  $emptybox->info_box_head = array();
1399  $emptybox->info_box_contents = array();
1400  $boxlista .= $emptybox->showBox(array(), array(), 1);
1401  }
1402  $boxlista .= "<!-- End box left container -->\n";
1403 
1404  $boxlistb .= "\n<!-- Box right container -->\n";
1405 
1406  $ii = 0;
1407  foreach ($boxactivated as $key => $box) {
1408  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1409  continue;
1410  }
1411  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1412  $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1413  }
1414  if (preg_match('/^B/i', $box->box_order)) { // colonne B
1415  $ii++;
1416  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1417  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1418  // Show box
1419  $box->loadBox($box_max_lines);
1420  $boxlistb .= $box->showBox(null, null, 1);
1421  }
1422  }
1423 
1424  if ($conf->browser->layout != 'phone') {
1425  $emptybox->box_id = 'B';
1426  $emptybox->info_box_head = array();
1427  $emptybox->info_box_contents = array();
1428  $boxlistb .= $emptybox->showBox(array(), array(), 1);
1429  }
1430 
1431  $boxlistb .= "<!-- End box right container -->\n";
1432  }
1433 
1434  return array('selectboxlist' => count($boxactivated) ? $selectboxlist : '', 'boxactivated' => $boxactivated, 'boxlista' => $boxlista, 'boxlistb' => $boxlistb);
1435  }
1436 
1437 
1438  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1451  public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1452  {
1453  // phpcs:enable
1454  global $langs, $conf;
1455 
1456  $langs->load("admin");
1457 
1458  $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1459  $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1460  $sql .= " ORDER BY ".$labelfield;
1461 
1462  dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1463  $result = $this->db->query($sql);
1464  if ($result) {
1465  $num = $this->db->num_rows($result);
1466  $i = 0;
1467  if ($num) {
1468  print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1469  if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1470  print '<option value="-1">&nbsp;</option>';
1471  }
1472 
1473  while ($i < $num) {
1474  $obj = $this->db->fetch_object($result);
1475  if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1476  print '<option value="'.$obj->{$keyfield}.'" selected>';
1477  } else {
1478  print '<option value="'.$obj->{$keyfield}.'">';
1479  }
1480  $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1481  print $label;
1482  print '</option>';
1483  $i++;
1484  }
1485  print "</select>";
1486  } else {
1487  print $langs->trans("DictionaryEmpty");
1488  }
1489  } else {
1490  dol_print_error($this->db);
1491  }
1492  }
1493 
1504  public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1505  {
1506  global $langs;
1507 
1508  $automatic = "automatic";
1509  $manual = "manual";
1510  if ($option) {
1511  $automatic = "1";
1512  $manual = "0";
1513  }
1514 
1515  $disabled = ($disabled ? ' disabled' : '');
1516 
1517  $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1518  if ($useempty) {
1519  $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1520  }
1521  if (("$value" == 'automatic') || ($value == 1)) {
1522  $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1523  $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1524  } else {
1525  $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1526  $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1527  $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1528  }
1529  $resultautomanual .= '</select>'."\n";
1530  return $resultautomanual;
1531  }
1532 
1533 
1544  public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1545  {
1546  global $langs, $extrafields, $form;
1547 
1548  $arrayofgroupbylabel = array();
1549  foreach ($arrayofgroupby as $key => $val) {
1550  $arrayofgroupbylabel[$key] = $val['label'];
1551  }
1552  $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1553 
1554  return $result;
1555  }
1556 
1567  public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1568  {
1569  global $form;
1570 
1571  $arrayofxaxislabel = array();
1572  foreach ($arrayofxaxis as $key => $val) {
1573  $arrayofxaxislabel[$key] = $val['label'];
1574  }
1575  $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1576 
1577  return $result;
1578  }
1579 }
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition: security.php:607
Class permettant la generation de composants html autre Only common components are here.
__construct($db)
Constructor.
getHTMLScannerForm($jstoexecuteonadd='barcodescannerjs', $mode='all', $warehouseselect=0)
Return the HTML code for scanner tool.
select_dictionary($htmlname, $dictionarytable, $keyfield='code', $labelfield='label', $selected='', $useempty=0, $moreattrib='')
Return a HTML select list of a dictionary.
Class with static methods for building HTML components related to products Only components common to ...
Class toolbox to validate values.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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:887
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:123
$conf db user
Active Directory does not allow anonymous connections.
Definition: repair.php:127