dolibarr  17.0.0
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>';
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  // Enhance with select2
416  if ($conf->use_javascript_ajax) {
417  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
418  $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
419  $moreforfilter .= $comboenhancement;
420  }
421 
422  // Print a select with each of them
423  $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
424  if ($showempty) {
425  $textforempty = ' ';
426  if (!empty($conf->use_javascript_ajax)) {
427  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
428  }
429  if (!is_numeric($showempty)) {
430  $textforempty = $showempty;
431  }
432  $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').' data-html="'.dol_escape_htmltag($textforempty).'">'.dol_escape_htmltag($textforempty).'</option>'."\n";
433  }
434 
435  if (is_array($tab_categs)) {
436  foreach ($tab_categs as $categ) {
437  $moreforfilter .= '<option value="'.$categ['id'].'"';
438  if ($categ['id'] == $selected) {
439  $moreforfilter .= ' selected';
440  }
441  $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
442  $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
443  }
444  }
445  if ($nocateg) {
446  $langs->load("categories");
447  $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
448  }
449  $moreforfilter .= '</select>';
450 
451  return $moreforfilter;
452  }
453 
454 
455  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
468  public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
469  {
470  // phpcs:enable
471  global $conf, $langs, $hookmanager;
472 
473  $langs->load('users');
474 
475  $out = '';
476 
477  $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
478 
479  // Select each sales and print them in a select input
480  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
481  if ($showempty) {
482  $textforempty = ' ';
483  if (!is_numeric($showempty)) {
484  $textforempty = $showempty;
485  }
486  if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
487  $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
488  }
489  $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
490  }
491 
492  // Get list of users allowed to be viewed
493  $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
494  $sql_usr .= " FROM ".$this->db->prefix()."user as u";
495 
496  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
497  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
498  $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
499  } else {
500  $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')."))";
501  $sql_usr .= " OR u.entity = 0"; // Show always superadmin
502  }
503  } else {
504  $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
505  }
506 
507  if (empty($user->rights->user->user->lire)) {
508  $sql_usr .= " AND u.rowid = ".((int) $user->id);
509  }
510  if (!empty($user->socid)) {
511  $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
512  }
513 
514  //Add hook to filter on user (for exemple on usergroup define in custom modules)
515  if (!empty($reshook)) {
516  $sql_usr .= $hookmanager->resArray[0];
517  }
518 
519  // Add existing sales representatives of thirdparty of external user
520  if (empty($user->rights->user->user->lire) && $user->socid) {
521  $sql_usr .= " UNION ";
522  $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
523  $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
524 
525  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
526  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
527  $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
528  } else {
529  $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')."))";
530  }
531  } else {
532  $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
533  }
534 
535  $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
536 
537  //Add hook to filter on user (for exemple on usergroup define in custom modules)
538  if (!empty($reshook)) {
539  $sql_usr .= $hookmanager->resArray[1];
540  }
541  }
542 
543  if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
544  $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
545  } else {
546  $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
547  }
548  //print $sql_usr;exit;
549 
550  $resql_usr = $this->db->query($sql_usr);
551  if ($resql_usr) {
552  $userstatic = new User($this->db);
553 
554  while ($obj_usr = $this->db->fetch_object($resql_usr)) {
555  $userstatic->id = $obj_usr->rowid;
556  $userstatic->lastname = $obj_usr->lastname;
557  $userstatic->firstname = $obj_usr->firstname;
558  $userstatic->photo = $obj_usr->photo;
559  $userstatic->statut = $obj_usr->status;
560  $userstatic->entity = $obj_usr->entity;
561  $userstatic->admin = $obj_usr->admin;
562 
563  $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
564  if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
565  $labeltoshow = $obj_usr->login;
566  }
567 
568  $out .= '<option value="'.$obj_usr->rowid.'"';
569  if ($obj_usr->rowid == $selected) {
570  $out .= ' selected';
571  }
572  $out .= ' data-html="';
573  $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
574  if ($showstatus >= 0 && $obj_usr->status == 0) {
575  $outhtml .= '<strike class="opacitymediumxxx">';
576  }
577  $outhtml .= $labeltoshow;
578  if ($showstatus >= 0 && $obj_usr->status == 0) {
579  $outhtml .= '</strike>';
580  }
581  $out .= dol_escape_htmltag($outhtml);
582  $out .= '">';
583 
584  $out .= $labeltoshow;
585  // Complete name with more info
586  $moreinfo = 0;
587  if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
588  $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
589  $moreinfo++;
590  }
591  if ($showstatus >= 0) {
592  if ($obj_usr->status == 1 && $showstatus == 1) {
593  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
594  $moreinfo++;
595  }
596  if ($obj_usr->status == 0) {
597  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
598  $moreinfo++;
599  }
600  }
601  $out .= ($moreinfo ? ')' : '');
602  $out .= '</option>';
603  }
604  $this->db->free($resql_usr);
605  } else {
606  dol_print_error($this->db);
607  }
608 
609  if ($norepresentative) {
610  $langs->load("companies");
611  $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
612  }
613 
614  $out .= '</select>';
615 
616  // Enhance with select2
617  if ($conf->use_javascript_ajax) {
618  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
619 
620  $comboenhancement = ajax_combobox($htmlname);
621  if ($comboenhancement) {
622  $out .= $comboenhancement;
623  }
624  }
625 
626  return $out;
627  }
628 
644  public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
645  {
646  global $user, $langs;
647 
648  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
649 
650  //print $modeproject.'-'.$modetask;
651  $task = new Task($this->db);
652  $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
653  if ($tasksarray) {
654  print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
655  if ($useempty) {
656  print '<option value="0">&nbsp;</option>';
657  }
658  $j = 0;
659  $level = 0;
660  $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
661  print '</select>';
662 
663  print ajax_combobox($htmlname);
664  } else {
665  print '<div class="warning">'.$langs->trans("NoProject").'</div>';
666  }
667  }
668 
681  private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
682  {
683  global $langs, $user, $conf;
684 
685  $lastprojectid = 0;
686 
687  $numlines = count($lines);
688  for ($i = 0; $i < $numlines; $i++) {
689  if ($lines[$i]->fk_parent == $parent) {
690  //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
691 
692  // Break on a new project
693  if ($parent == 0) { // We are on a task at first level
694  if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
695  if ($i > 0) {
696  print '<option value="0" disabled>----------</option>';
697  }
698  print '<option value="'.$lines[$i]->fk_project.'_0"';
699  if ($selectedproject == $lines[$i]->fk_project) {
700  print ' selected';
701  }
702 
703  $labeltoshow = $lines[$i]->projectref;
704  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
705  if (empty($lines[$i]->public)) {
706  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
707  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
708  } else {
709  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
710  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
711  }
712 
713  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
714  print '>'; // Project -> Task
715  print $labeltoshow;
716  print "</option>\n";
717 
718  $lastprojectid = $lines[$i]->fk_project;
719  $inc++;
720  }
721  }
722 
723  $newdisablechildoftaskid = $disablechildoftaskid;
724 
725  // Print task
726  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
727  // Check if we must disable entry
728  $disabled = 0;
729  if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid))) {
730  $disabled++;
731  if ($lines[$i]->fk_parent == $disablechildoftaskid) {
732  $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
733  }
734  }
735 
736  print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
737  if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
738  print ' selected';
739  }
740  if ($disabled) {
741  print ' disabled';
742  }
743 
744  $labeltoshow = $lines[$i]->projectref;
745  //$labeltoshow .= ' '.$lines[$i]->projectlabel;
746  if (empty($lines[$i]->public)) {
747  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
748  $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
749  } else {
750  //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
751  $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
752  }
753  if ($lines[$i]->id) {
754  $labeltoshow .= ' > ';
755  }
756  for ($k = 0; $k < $level; $k++) {
757  $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
758  }
759  $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
760 
761  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
762  print '>';
763  print $labeltoshow;
764  print "</option>\n";
765  $inc++;
766  }
767 
768  $level++;
769  if ($lines[$i]->id) {
770  $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
771  }
772  $level--;
773  }
774  }
775  }
776 
777 
786  public static function showColor($color, $textifnotdefined = '')
787  {
788  $textcolor = 'FFF';
789  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
790  if (colorIsLight($color)) {
791  $textcolor = '000';
792  }
793 
794  $color = colorArrayToHex(colorStringToArray($color, array()), '');
795 
796  if ($color) {
797  print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
798  } else {
799  print $textifnotdefined;
800  }
801  }
802 
803  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
816  public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
817  {
818  // phpcs:enable
819  print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
820  }
821 
835  public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '')
836  {
837  // Deprecation warning
838  if ($form_name) {
839  dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
840  }
841 
842  global $langs, $conf;
843 
844  $out = '';
845 
846  if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
847  $langs->load("other");
848  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
849  $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
850  $out .= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
851  $out .= '<script type="text/javascript">
852  jQuery(document).ready(function(){
853  var originalhex = null;
854  $(\'#colorpicker'.$prefix.'\').jPicker( {
855  window: {
856  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
857  effects:
858  {
859  type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
860  speed:
861  {
862  show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
863  hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
864  }
865  },
866  position:
867  {
868  x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
869  y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
870  },
871  },
872  images: {
873  clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
874  picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
875  },
876  localization: // alter these to change the text presented by the picker (e.g. different language)
877  {
878  text:
879  {
880  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
881  newColor: \''.dol_escape_js($langs->trans("New")).'\',
882  currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
883  ok: \''.dol_escape_js($langs->trans("Validate")).'\',
884  cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
885  }
886  }
887  },
888  function(color, context) { console.log("close color selector"); },
889  function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
890  if ($setpropertyonselect) {
891  $out .= 'if (originalhex == null) {';
892  $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
893  $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
894  $out .= '}';
895  $out .= 'if (hex != null) {';
896  $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
897  $out .= '}';
898  }
899  $out .= '},
900  function(color, context) {
901  console.log("cancel selection of color");';
902  if ($setpropertyonselect) {
903  $out .= 'if (originalhex != null) {
904  console.log("Restore old color "+originalhex);
905  document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
906  }';
907  }
908  $out .= '
909  }
910  );
911  });
912  </script>';
913  }
914  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
915  } else { // In most cases, this is not used. We used instead function with no specific list of colors
916  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
917  $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
918  $out .= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
919  $out .= '<script type="text/javascript">
920  jQuery(document).ready(function(){
921  jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
922  size: 14,
923  label: \'\',
924  hide: true
925  });
926  });
927  </script>';
928  }
929  $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
930  //print '<option value="-1">&nbsp;</option>';
931  foreach ($arrayofcolors as $val) {
932  $out .= '<option value="'.$val.'"';
933  if ($set_color == $val) {
934  $out .= ' selected';
935  }
936  $out .= '>'.$val.'</option>';
937  }
938  $out .= '</select>';
939  }
940 
941  return $out;
942  }
943 
944  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
955  public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
956  {
957  // phpcs:enable
958  global $conf;
959 
960  $file = $conf->$module->dir_temp.'/'.$name.'.png';
961 
962  // On cree le repertoire contenant les icones
963  if (!file_exists($conf->$module->dir_temp)) {
964  dol_mkdir($conf->$module->dir_temp);
965  }
966 
967  // On cree l'image en vraies couleurs
968  $image = imagecreatetruecolor($x, $y);
969 
970  $color = substr($color, 1, 6);
971 
972  $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
973  $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
974  $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
975 
976  $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
977  //print $rouge.$vert.$bleu;
978  imagefill($image, 0, 0, $couleur); //on remplit l'image
979  // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
980  ImagePng($image, $file); //renvoie une image sous format png
981  ImageDestroy($image);
982  }
983 
984  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
993  public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
994  {
995  // phpcs:enable
996  global $langs;
997 
998  $week = array(
999  0=>$langs->trans("Day0"),
1000  1=>$langs->trans("Day1"),
1001  2=>$langs->trans("Day2"),
1002  3=>$langs->trans("Day3"),
1003  4=>$langs->trans("Day4"),
1004  5=>$langs->trans("Day5"),
1005  6=>$langs->trans("Day6")
1006  );
1007 
1008  $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
1009  if ($useempty) {
1010  $select_week .= '<option value="-1">&nbsp;</option>';
1011  }
1012  foreach ($week as $key => $val) {
1013  if ($selected == $key) {
1014  $select_week .= '<option value="'.$key.'" selected>';
1015  } else {
1016  $select_week .= '<option value="'.$key.'">';
1017  }
1018  $select_week .= $val;
1019  $select_week .= '</option>';
1020  }
1021  $select_week .= '</select>';
1022 
1023  $select_week .= ajax_combobox($htmlname);
1024 
1025  return $select_week;
1026  }
1027 
1028  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1040  public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
1041  {
1042  // phpcs:enable
1043  global $langs;
1044 
1045  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
1046 
1047  if ($longlabel) {
1048  $montharray = monthArray($langs, 0); // Get array
1049  } else {
1050  $montharray = monthArray($langs, 1);
1051  }
1052 
1053  $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
1054  if ($useempty) {
1055  $select_month .= '<option value="0">&nbsp;</option>';
1056  }
1057  foreach ($montharray as $key => $val) {
1058  if ($selected == $key) {
1059  $select_month .= '<option value="'.$key.'" selected>';
1060  } else {
1061  $select_month .= '<option value="'.$key.'">';
1062  }
1063  $select_month .= $val;
1064  $select_month .= '</option>';
1065  }
1066  $select_month .= '</select>';
1067 
1068  // Add code for jquery to use multiselect
1069  if ($addjscombo) {
1070  // Enhance with select2
1071  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1072  $select_month .= ajax_combobox($htmlname);
1073  }
1074 
1075  return $select_month;
1076  }
1077 
1078  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1095  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)
1096  {
1097  // phpcs:enable
1098  print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
1099  }
1100 
1116  public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1117  {
1118  $out = '';
1119 
1120  $currentyear = date("Y") + $offset;
1121  $max_year = $currentyear + $max_year;
1122  $min_year = $currentyear - $min_year;
1123  if (empty($selected) && empty($useempty)) {
1124  $selected = $currentyear;
1125  }
1126 
1127  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1128  if ($useempty) {
1129  $selected_html = '';
1130  if ($selected == '') {
1131  $selected_html = ' selected';
1132  }
1133  $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1134  }
1135  if (!$invert) {
1136  for ($y = $max_year; $y >= $min_year; $y--) {
1137  $selected_html = '';
1138  if ($selected > 0 && $y == $selected) {
1139  $selected_html = ' selected';
1140  }
1141  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1142  }
1143  } else {
1144  for ($y = $min_year; $y <= $max_year; $y++) {
1145  $selected_html = '';
1146  if ($selected > 0 && $y == $selected) {
1147  $selected_html = ' selected';
1148  }
1149  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1150  }
1151  }
1152  $out .= "</select>\n";
1153 
1154  // Add code for jquery to use multiselect
1155  if ($addjscombo) {
1156  // Enhance with select2
1157  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1158  $out .= ajax_combobox($htmlname);
1159  }
1160 
1161  return $out;
1162  }
1163 
1164 
1173  public static function getBoxesArea($user, $areacode)
1174  {
1175  global $conf, $langs, $db;
1176 
1177  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1178 
1179  $confuserzone = 'MAIN_BOXES_'.$areacode;
1180 
1181  // $boxactivated will be array of boxes enabled into global setup
1182  // $boxidactivatedforuser will be array of boxes choosed by user
1183 
1184  $selectboxlist = '';
1185  $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)
1186 
1187  $boxidactivatedforuser = array();
1188  foreach ($boxactivated as $box) {
1189  if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
1190  $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1191  }
1192  }
1193 
1194  // Define selectboxlist
1195  $arrayboxtoactivatelabel = array();
1196  if (!empty($user->conf->$confuserzone)) {
1197  $boxorder = '';
1198  $langs->load("boxes"); // Load label of boxes
1199  foreach ($boxactivated as $box) {
1200  if (!empty($boxidactivatedforuser[$box->id])) {
1201  continue; // Already visible for user
1202  }
1203  $label = $langs->transnoentitiesnoconv($box->boxlabel);
1204  //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1205  if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
1206  $label = $label.' <span class="fa fa-bar-chart"></span>';
1207  }
1208  $arrayboxtoactivatelabel[$box->id] = $label; // We keep only boxes not shown for user, to show into combo list
1209  }
1210  foreach ($boxidactivatedforuser as $boxid) {
1211  if (empty($boxorder)) {
1212  $boxorder .= 'A:';
1213  }
1214  $boxorder .= $boxid.',';
1215  }
1216 
1217  //var_dump($boxidactivatedforuser);
1218 
1219  // Class Form must have been already loaded
1220  $selectboxlist .= '<!-- Form with select box list -->'."\n";
1221  $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1222  $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1223  $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1224  $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1225  $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1226  $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1227  $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone hideonprint', 0, 'hidden selected', 0, 1);
1228  if (empty($conf->use_javascript_ajax)) {
1229  $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1230  }
1231  $selectboxlist .= '</form>';
1232  if (!empty($conf->use_javascript_ajax)) {
1233  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1234  $selectboxlist .= ajax_combobox("boxcombo");
1235  }
1236  }
1237 
1238  // Javascript code for dynamic actions
1239  if (!empty($conf->use_javascript_ajax)) {
1240  $selectboxlist .= '<script type="text/javascript">
1241 
1242  // To update list of activated boxes
1243  function updateBoxOrder(closing) {
1244  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1245  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1246  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1247  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
1248  {
1249  jQuery.ajax({
1250  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1251  async: false
1252  });
1253  // We force reload to be sure to get all boxes into list
1254  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
1255  }
1256  else
1257  {
1258  jQuery.ajax({
1259  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1260  async: true
1261  });
1262  }
1263  }
1264 
1265  jQuery(document).ready(function() {
1266  jQuery("#boxcombo").change(function() {
1267  var boxid=jQuery("#boxcombo").val();
1268  if (boxid > 0) {
1269  console.log("A box widget has been selected for addition, we call ajax page to add it.")
1270  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1271  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1272  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1273  jQuery.ajax({
1274  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
1275  }).done(function() {
1276  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
1277  });
1278  }
1279  });';
1280  if (!count($arrayboxtoactivatelabel)) {
1281  $selectboxlist .= 'jQuery("#boxcombo").hide();';
1282  }
1283  $selectboxlist .= '
1284 
1285  jQuery("#boxhalfleft, #boxhalfright").sortable({
1286  handle: \'.boxhandle\',
1287  revert: \'invalid\',
1288  items: \'.boxdraggable\',
1289  containment: \'document\',
1290  connectWith: \'#boxhalfleft, #boxhalfright\',
1291  stop: function(event, ui) {
1292  updateBoxOrder(1); /* 1 to avoid message after a move */
1293  }
1294  });
1295 
1296  jQuery(".boxclose").click(function() {
1297  var self = this; // because JQuery can modify this
1298  var boxid=self.id.substring(8);
1299  var label=jQuery(\'#boxlabelentry\'+boxid).val();
1300  console.log("We close box "+boxid);
1301  jQuery(\'#boxto_\'+boxid).remove();
1302  if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid));
1303  updateBoxOrder(1); /* 1 to avoid message after a remove */
1304  });
1305 
1306  });'."\n";
1307 
1308  $selectboxlist .= '</script>'."\n";
1309  }
1310 
1311  // Define boxlista and boxlistb
1312  $boxlista = '';
1313  $boxlistb = '';
1314  $nbboxactivated = count($boxidactivatedforuser);
1315 
1316  if ($nbboxactivated) {
1317  // Load translation files required by the page
1318  $langs->loadLangs(array("boxes", "projects"));
1319 
1320  $emptybox = new ModeleBoxes($db);
1321 
1322  $boxlista .= "\n<!-- Box left container -->\n";
1323 
1324  // Define $box_max_lines
1325  $box_max_lines = 5;
1326  if (!empty($conf->global->MAIN_BOXES_MAXLINES)) {
1327  $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1328  }
1329 
1330  $ii = 0;
1331  foreach ($boxactivated as $key => $box) {
1332  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1333  continue;
1334  }
1335  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1336  $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1337  }
1338  if (preg_match('/^A/i', $box->box_order)) { // column A
1339  $ii++;
1340  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1341  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1342  // Show box
1343  $box->loadBox($box_max_lines);
1344  $boxlista .= $box->showBox(null, null, 1);
1345  }
1346  }
1347 
1348  if ($conf->browser->layout != 'phone') {
1349  $emptybox->box_id = 'A';
1350  $emptybox->info_box_head = array();
1351  $emptybox->info_box_contents = array();
1352  $boxlista .= $emptybox->showBox(array(), array(), 1);
1353  }
1354  $boxlista .= "<!-- End box left container -->\n";
1355 
1356  $boxlistb .= "\n<!-- Box right container -->\n";
1357 
1358  $ii = 0;
1359  foreach ($boxactivated as $key => $box) {
1360  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
1361  continue;
1362  }
1363  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
1364  $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1365  }
1366  if (preg_match('/^B/i', $box->box_order)) { // colonne B
1367  $ii++;
1368  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1369  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1370  // Show box
1371  $box->loadBox($box_max_lines);
1372  $boxlistb .= $box->showBox(null, null, 1);
1373  }
1374  }
1375 
1376  if ($conf->browser->layout != 'phone') {
1377  $emptybox->box_id = 'B';
1378  $emptybox->info_box_head = array();
1379  $emptybox->info_box_contents = array();
1380  $boxlistb .= $emptybox->showBox(array(), array(), 1);
1381  }
1382 
1383  $boxlistb .= "<!-- End box right container -->\n";
1384  }
1385 
1386  return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1387  }
1388 
1389 
1390  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1403  public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1404  {
1405  // phpcs:enable
1406  global $langs, $conf;
1407 
1408  $langs->load("admin");
1409 
1410  $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1411  $sql .= " FROM ".$this->db->prefix().$dictionarytable;
1412  $sql .= " ORDER BY ".$labelfield;
1413 
1414  dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1415  $result = $this->db->query($sql);
1416  if ($result) {
1417  $num = $this->db->num_rows($result);
1418  $i = 0;
1419  if ($num) {
1420  print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1421  if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
1422  print '<option value="-1">&nbsp;</option>';
1423  }
1424 
1425  while ($i < $num) {
1426  $obj = $this->db->fetch_object($result);
1427  if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
1428  print '<option value="'.$obj->{$keyfield}.'" selected>';
1429  } else {
1430  print '<option value="'.$obj->{$keyfield}.'">';
1431  }
1432  $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != ($dictionarytable.$obj->{$labelfield}) ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
1433  print $label;
1434  print '</option>';
1435  $i++;
1436  }
1437  print "</select>";
1438  } else {
1439  print $langs->trans("DictionaryEmpty");
1440  }
1441  } else {
1442  dol_print_error($this->db);
1443  }
1444  }
1445 
1456  public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1457  {
1458  global $langs;
1459 
1460  $automatic = "automatic";
1461  $manual = "manual";
1462  if ($option) {
1463  $automatic = "1";
1464  $manual = "0";
1465  }
1466 
1467  $disabled = ($disabled ? ' disabled' : '');
1468 
1469  $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1470  if ($useempty) {
1471  $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1472  }
1473  if (("$value" == 'automatic') || ($value == 1)) {
1474  $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1475  $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1476  } else {
1477  $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1478  $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1479  $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1480  }
1481  $resultautomanual .= '</select>'."\n";
1482  return $resultautomanual;
1483  }
1484 
1485 
1496  public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
1497  {
1498  global $langs, $extrafields, $form;
1499 
1500  $arrayofgroupbylabel = array();
1501  foreach ($arrayofgroupby as $key => $val) {
1502  $arrayofgroupbylabel[$key] = $val['label'];
1503  }
1504  $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1505 
1506  return $result;
1507  }
1508 
1519  public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
1520  {
1521  global $form;
1522 
1523  $arrayofxaxislabel = array();
1524  foreach ($arrayofxaxis as $key => $val) {
1525  $arrayofxaxislabel[$key] = $val['label'];
1526  }
1527  $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1528 
1529  return $result;
1530  }
1531 }
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1493
FormOther\__construct
__construct($db)
Constructor.
Definition: html.formother.class.php:54
button
table tableforfield button
Definition: style.css.php:843
FormOther\select_dictionary
select_dictionary($htmlname, $dictionarytable, $keyfield='code', $labelfield='label', $selected='', $useempty=0, $moreattrib='')
Return a HTML select list of a dictionary.
Definition: html.formother.class.php:1403
rowid
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
Definition: email_expire_services_to_representatives.php:79
FormOther
Classe permettant la generation de composants html autre Only common components are here.
Definition: html.formother.class.php:39
FormOther\getHTMLScannerForm
getHTMLScannerForm($jstoexecuteonadd='barcodescannerjs', $mode='all')
Return the HTML code for scanner tool.
Definition: html.formother.class.php:67
dol_escape_js
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
Definition: functions.lib.php:1444
Validate
Class toolbox to validate values.
Definition: validate.class.php:28
user
$conf db user
Definition: repair.php:123
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119