dolibarr  13.0.2
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 
59 
60  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
71  public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
72  {
73  // phpcs:enable
74  global $conf, $langs, $user;
75 
76  $sql = "SELECT rowid, label, fk_user";
77  $sql .= " FROM ".MAIN_DB_PREFIX."export_model";
78  $sql .= " WHERE type = '".$this->db->escape($type)."'";
79  if (!empty($fk_user)) $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
80  $sql .= " ORDER BY label";
81  $result = $this->db->query($sql);
82  if ($result)
83  {
84  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
85  if ($useempty)
86  {
87  print '<option value="-1">&nbsp;</option>';
88  }
89 
90  $num = $this->db->num_rows($result);
91  $i = 0;
92  while ($i < $num)
93  {
94  $obj = $this->db->fetch_object($result);
95 
96  $label = $obj->label;
97  if ($obj->fk_user == 0) {
98  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
99  } elseif (!empty($conf->global->EXPORTS_SHARE_MODELS) && empty($fk_user) && is_object($user) && $user->id != $obj->fk_user) {
100  $tmpuser = new User($this->db);
101  $tmpuser->fetch($obj->fk_user);
102  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
103  }
104 
105  if ($selected == $obj->rowid)
106  {
107  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
108  } else {
109  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
110  }
111  print $label;
112  print '</option>';
113  $i++;
114  }
115  print "</select>";
116  print ajax_combobox($htmlname);
117  } else {
118  dol_print_error($this->db);
119  }
120  }
121 
122 
123  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
134  public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
135  {
136  // phpcs:enable
137  global $conf, $langs, $user;
138 
139  $sql = "SELECT rowid, label, fk_user";
140  $sql .= " FROM ".MAIN_DB_PREFIX."import_model";
141  $sql .= " WHERE type = '".$this->db->escape($type)."'";
142  if (!empty($fk_user)) $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
143  $sql .= " ORDER BY rowid";
144  $result = $this->db->query($sql);
145  if ($result)
146  {
147  print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
148  if ($useempty)
149  {
150  print '<option value="-1">&nbsp;</option>';
151  }
152 
153  $num = $this->db->num_rows($result);
154  $i = 0;
155  while ($i < $num)
156  {
157  $obj = $this->db->fetch_object($result);
158 
159  $label = $obj->label;
160  if ($obj->fk_user == 0) {
161  $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
162  } elseif (!empty($conf->global->EXPORTS_SHARE_MODELS) && empty($fk_user) && is_object($user) && $user->id != $obj->fk_user) {
163  $tmpuser = new User($this->db);
164  $tmpuser->fetch($obj->fk_user);
165  $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
166  }
167 
168  if ($selected == $obj->rowid)
169  {
170  print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
171  } else {
172  print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
173  }
174  print $label;
175  print '</option>';
176  $i++;
177  }
178  print "</select>";
179  print ajax_combobox($htmlname);
180  } else {
181  dol_print_error($this->db);
182  }
183  }
184 
185 
186  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
194  public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
195  {
196  // phpcs:enable
197  global $langs;
198 
199  $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
200  $sql .= " c.label as country";
201  $sql .= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
202  $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
203  $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
204 
205  dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
206  $resql = $this->db->query($sql);
207  if ($resql)
208  {
209  print '<select class="flat" name="'.$htmlname.'">';
210  $num = $this->db->num_rows($resql);
211  $i = 0;
212  print '<option value="-1">&nbsp;</option>'."\n";
213  if ($num)
214  {
215  while ($i < $num)
216  {
217  $obj = $this->db->fetch_object($resql);
218  if ($selected && $selected == $obj->rowid)
219  {
220  print '<option value="'.$obj->rowid.'" selected>';
221  } else {
222  print '<option value="'.$obj->rowid.'">';
223  //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
224  }
225  $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
226  print $selectOptionValue;
227  print '</option>';
228  $i++;
229  }
230  }
231  print '</select>';
232  return 0;
233  } else {
234  dol_print_error($this->db);
235  return 1;
236  }
237  }
238 
239 
240  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
249  public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
250  {
251  // phpcs:enable
252  global $langs;
253 
254  $out = '';
255 
256  $sql = "SELECT r.taux, r.revenuestamp_type";
257  $sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
258  $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
259  $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
260 
261  dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
262  $resql = $this->db->query($sql);
263  if ($resql)
264  {
265  $out .= '<select class="flat" name="'.$htmlname.'">';
266  $num = $this->db->num_rows($resql);
267  $i = 0;
268  $out .= '<option value="0">&nbsp;</option>'."\n";
269  if ($num)
270  {
271  while ($i < $num)
272  {
273  $obj = $this->db->fetch_object($resql);
274  if (($selected && $selected == $obj->taux) || $num == 1)
275  {
276  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
277  } else {
278  $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
279  //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
280  }
281  $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
282  $out .= '</option>';
283  $i++;
284  }
285  }
286  $out .= '</select>';
287  return $out;
288  } else {
289  dol_print_error($this->db);
290  return '';
291  }
292  }
293 
294 
295  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
308  public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
309  {
310  // phpcs:enable
311  $return = '<select class="flat" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
312  if ($showempty) $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
313 
314  for ($i = $start; $i <= $end; $i += $increment)
315  {
316  if ($selected != '' && (int) $selected == $i)
317  {
318  $return .= '<option value="'.$i.'" selected>';
319  } else {
320  $return .= '<option value="'.$i.'">';
321  }
322  $return .= $i.' % ';
323  $return .= '</option>';
324  }
325 
326  $return .= '</select>';
327 
328  return $return;
329  }
330 
331  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
344  public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
345  {
346  // phpcs:enable
347  global $conf, $langs;
348  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
349 
350  // For backward compatibility
351  if (is_numeric($type))
352  {
353  dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
354  }
355 
356  // Load list of "categories"
357  $static_categs = new Categorie($this->db);
358  $tab_categs = $static_categs->get_full_arbo($type);
359 
360  $moreforfilter = '';
361  // Enhance with select2
362  if ($conf->use_javascript_ajax)
363  {
364  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
365  $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
366  $moreforfilter .= $comboenhancement;
367  }
368 
369  // Print a select with each of them
370  $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
371  if ($showempty) $moreforfilter .= '<option value="0">&nbsp;</option>'; // Should use -1 to say nothing
372 
373  if (is_array($tab_categs))
374  {
375  foreach ($tab_categs as $categ)
376  {
377  $moreforfilter .= '<option value="'.$categ['id'].'"';
378  if ($categ['id'] == $selected) $moreforfilter .= ' selected';
379  $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
380  }
381  }
382  if ($nocateg)
383  {
384  $langs->load("categories");
385  $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
386  }
387  $moreforfilter .= '</select>';
388 
389  return $moreforfilter;
390  }
391 
392 
393  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
406  public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
407  {
408  // phpcs:enable
409  global $conf, $langs, $hookmanager;
410 
411  $langs->load('users');
412 
413  $out = '';
414  // Enhance with select2
415  if ($conf->use_javascript_ajax)
416  {
417  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
418 
419  $comboenhancement = ajax_combobox($htmlname);
420  if ($comboenhancement)
421  {
422  $out .= $comboenhancement;
423  }
424  }
425 
426  $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
427 
428  // Select each sales and print them in a select input
429  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
430  if ($showempty) $out .= '<option value="0">&nbsp;</option>';
431 
432  // Get list of users allowed to be viewed
433  $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
434  $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u";
435 
436  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
437  {
438  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
439  $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
440  } else {
441  $sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('usergroup')."))";
442  $sql_usr .= " OR u.entity = 0"; // Show always superadmin
443  }
444  } else {
445  $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
446  }
447 
448  if (empty($user->rights->user->user->lire)) $sql_usr .= " AND u.rowid = ".$user->id;
449  if (!empty($user->socid)) $sql_usr .= " AND u.fk_soc = ".$user->socid;
450 
451  //Add hook to filter on user (for exemple on usergroup define in custom modules)
452  if (!empty($reshook)) $sql_usr .= $hookmanager->resArray[0];
453 
454  // Add existing sales representatives of thirdparty of external user
455  if (empty($user->rights->user->user->lire) && $user->socid)
456  {
457  $sql_usr .= " UNION ";
458  $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
459  $sql_usr .= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
460 
461  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
462  {
463  if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
464  $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
465  } else {
466  $sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('usergroup')."))";
467  }
468  } else {
469  $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
470  }
471 
472  $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->socid;
473 
474  //Add hook to filter on user (for exemple on usergroup define in custom modules)
475  if (!empty($reshook)) $sql_usr .= $hookmanager->resArray[1];
476  }
477  $sql_usr .= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
478  //print $sql_usr;exit;
479 
480  $resql_usr = $this->db->query($sql_usr);
481  if ($resql_usr)
482  {
483  $userstatic = new User($this->db);
484  $showstatus = 1;
485 
486  while ($obj_usr = $this->db->fetch_object($resql_usr))
487  {
488  $userstatic->id = $obj_usr->rowid;
489  $userstatic->lastname = $obj_usr->lastname;
490  $userstatic->firstname = $obj_usr->firstname;
491  $userstatic->photo = $obj_usr->photo;
492  $userstatic->statut = $obj_usr->status;
493  $userstatic->entity = $obj_usr->entity;
494  $userstatic->admin = $obj_usr->admin;
495 
496  $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
497  if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) $labeltoshow = $obj_usr->login;
498 
499  $out .= '<option value="'.$obj_usr->rowid.'"';
500  if ($obj_usr->rowid == $selected) $out .= ' selected';
501  $out .= ' data-html="';
502  $outhtml = '';
503  if (!empty($obj_usr->photo))
504  {
505  $outhtml .= $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
506  }
507  if ($showstatus >= 0 && $obj_usr->status == 0) $outhtml .= '<strike class="opacitymediumxxx">';
508  $outhtml .= $labeltoshow;
509  if ($showstatus >= 0 && $obj_usr->status == 0) $outhtml .= '</strike>';
510  $out .= dol_escape_htmltag($outhtml);
511  $out .= '">';
512 
513  $out .= $labeltoshow;
514  // Complete name with more info
515  $moreinfo = 0;
516  if (!empty($conf->global->MAIN_SHOW_LOGIN))
517  {
518  $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
519  $moreinfo++;
520  }
521  if ($showstatus >= 0)
522  {
523  if ($obj_usr->status == 1 && $showstatus == 1)
524  {
525  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
526  $moreinfo++;
527  }
528  if ($obj_usr->status == 0)
529  {
530  $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
531  $moreinfo++;
532  }
533  }
534  $out .= ($moreinfo ? ')' : '');
535  $out .= '</option>';
536  }
537  $this->db->free($resql_usr);
538  } else {
539  dol_print_error($this->db);
540  }
541 
542  if ($norepresentative)
543  {
544  $langs->load("companies");
545  $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
546  }
547 
548  $out .= '</select>';
549 
550  return $out;
551  }
552 
568  public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
569  {
570  global $user, $langs;
571 
572  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
573 
574  //print $modeproject.'-'.$modetask;
575  $task = new Task($this->db);
576  $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
577  if ($tasksarray)
578  {
579  print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
580  if ($useempty) print '<option value="0">&nbsp;</option>';
581  $j = 0;
582  $level = 0;
583  $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
584  print '</select>';
585 
586  print ajax_combobox($htmlname);
587  } else {
588  print '<div class="warning">'.$langs->trans("NoProject").'</div>';
589  }
590  }
591 
604  private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
605  {
606  global $langs, $user, $conf;
607 
608  $lastprojectid = 0;
609 
610  $numlines = count($lines);
611  for ($i = 0; $i < $numlines; $i++) {
612  if ($lines[$i]->fk_parent == $parent) {
613  //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
614 
615  // Break on a new project
616  if ($parent == 0) // We are on a task at first level
617  {
618  if ($lines[$i]->fk_project != $lastprojectid) // Break found on project
619  {
620  if ($i > 0) print '<option value="0" disabled>----------</option>';
621  print '<option value="'.$lines[$i]->fk_project.'_0"';
622  if ($selectedproject == $lines[$i]->fk_project) print ' selected';
623 
624  $labeltoshow = $langs->trans("Project").' '.$lines[$i]->projectref;
625  if (empty($lines[$i]->public)) {
626  $labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
627  } else {
628  $labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
629  }
630 
631  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
632  print '>'; // Project -> Task
633  print $labeltoshow;
634  print "</option>\n";
635 
636  $lastprojectid = $lines[$i]->fk_project;
637  $inc++;
638  }
639  }
640 
641  $newdisablechildoftaskid = $disablechildoftaskid;
642 
643  // Print task
644  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
645  {
646  // Check if we must disable entry
647  $disabled = 0;
648  if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
649  {
650  $disabled++;
651  if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
652  }
653 
654  print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
655  if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
656  if ($disabled) print ' disabled';
657 
658  $labeltoshow = $langs->trans("Project").' '.$lines[$i]->projectref;
659  $labeltoshow .= ' '.$lines[$i]->projectlabel;
660  if (empty($lines[$i]->public))
661  {
662  $labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
663  } else {
664  $labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
665  }
666  if ($lines[$i]->id) $labeltoshow .= ' > ';
667  for ($k = 0; $k < $level; $k++)
668  {
669  $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
670  }
671  $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
672 
673  print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
674  print '>';
675  print $labeltoshow;
676  print "</option>\n";
677  $inc++;
678  }
679 
680  $level++;
681  if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
682  $level--;
683  }
684  }
685  }
686 
687 
696  public static function showColor($color, $textifnotdefined = '')
697  {
698  $textcolor = 'FFF';
699  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
700  if (colorIsLight($color)) $textcolor = '000';
701 
702  $color = colorArrayToHex(colorStringToArray($color, array()), '');
703 
704  if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
705  else print $textifnotdefined;
706  }
707 
708  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
721  public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
722  {
723  // phpcs:enable
724  print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
725  }
726 
740  public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '')
741  {
742  // Deprecation warning
743  if ($form_name) {
744  dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
745  }
746 
747  global $langs, $conf;
748 
749  $out = '';
750 
751  if (!is_array($arrayofcolors) || count($arrayofcolors) < 1)
752  {
753  $langs->load("other");
754  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax))
755  {
756  $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
757  $out .= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
758  $out .= '<script type="text/javascript">
759  jQuery(document).ready(function(){
760  $(\'#colorpicker'.$prefix.'\').jPicker( {
761  window: {
762  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
763  effects:
764  {
765  type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
766  speed:
767  {
768  show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
769  hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
770  }
771  },
772  position:
773  {
774  x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
775  y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
776  },
777  },
778  images: {
779  clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
780  picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
781  },
782  localization: // alter these to change the text presented by the picker (e.g. different language)
783  {
784  text:
785  {
786  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
787  newColor: \''.dol_escape_js($langs->trans("New")).'\',
788  currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
789  ok: \''.dol_escape_js($langs->trans("Save")).'\',
790  cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
791  }
792  }
793  },
794  function(color, context) { console.log("close"); },
795  function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex);';
796  if ($setpropertyonselect) { $out .= ' if (hex != null) document.documentElement.style.setProperty(\'--'.$setpropertyonselect.'\', \'#\'+hex);'; }
797  $out .= '},
798  function(color, context) { console.log("cancel"); }
799  );
800  });
801  </script>';
802  }
803  $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
804  } else // In most cases, this is not used. We used instead function with no specific list of colors
805  {
806  if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax))
807  {
808  $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
809  $out .= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
810  $out .= '<script type="text/javascript">
811  jQuery(document).ready(function(){
812  jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
813  size: 14,
814  label: \'\',
815  hide: true
816  });
817  });
818  </script>';
819  }
820  $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
821  //print '<option value="-1">&nbsp;</option>';
822  foreach ($arrayofcolors as $val)
823  {
824  $out .= '<option value="'.$val.'"';
825  if ($set_color == $val) $out .= ' selected';
826  $out .= '>'.$val.'</option>';
827  }
828  $out .= '</select>';
829  }
830 
831  return $out;
832  }
833 
834  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
845  public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
846  {
847  // phpcs:enable
848  global $conf;
849 
850  $file = $conf->$module->dir_temp.'/'.$name.'.png';
851 
852  // On cree le repertoire contenant les icones
853  if (!file_exists($conf->$module->dir_temp))
854  {
855  dol_mkdir($conf->$module->dir_temp);
856  }
857 
858  // On cree l'image en vraies couleurs
859  $image = imagecreatetruecolor($x, $y);
860 
861  $color = substr($color, 1, 6);
862 
863  $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
864  $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
865  $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
866 
867  $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
868  //print $rouge.$vert.$bleu;
869  imagefill($image, 0, 0, $couleur); //on remplit l'image
870  // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
871  ImagePng($image, $file); //renvoie une image sous format png
872  ImageDestroy($image);
873  }
874 
875  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
884  public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
885  {
886  // phpcs:enable
887  global $langs;
888 
889  $week = array(
890  0=>$langs->trans("Day0"),
891  1=>$langs->trans("Day1"),
892  2=>$langs->trans("Day2"),
893  3=>$langs->trans("Day3"),
894  4=>$langs->trans("Day4"),
895  5=>$langs->trans("Day5"),
896  6=>$langs->trans("Day6")
897  );
898 
899  $select_week = '<select class="flat" name="'.$htmlname.'">';
900  if ($useempty)
901  {
902  $select_week .= '<option value="-1">&nbsp;</option>';
903  }
904  foreach ($week as $key => $val)
905  {
906  if ($selected == $key)
907  {
908  $select_week .= '<option value="'.$key.'" selected>';
909  } else {
910  $select_week .= '<option value="'.$key.'">';
911  }
912  $select_week .= $val;
913  $select_week .= '</option>';
914  }
915  $select_week .= '</select>';
916  return $select_week;
917  }
918 
919  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
931  public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
932  {
933  // phpcs:enable
934  global $langs;
935 
936  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
937 
938  if ($longlabel) $montharray = monthArray($langs, 0); // Get array
939  else $montharray = monthArray($langs, 1);
940 
941  $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
942  if ($useempty)
943  {
944  $select_month .= '<option value="0">&nbsp;</option>';
945  }
946  foreach ($montharray as $key => $val)
947  {
948  if ($selected == $key)
949  {
950  $select_month .= '<option value="'.$key.'" selected>';
951  } else {
952  $select_month .= '<option value="'.$key.'">';
953  }
954  $select_month .= $val;
955  $select_month .= '</option>';
956  }
957  $select_month .= '</select>';
958 
959  // Add code for jquery to use multiselect
960  if ($addjscombo)
961  {
962  // Enhance with select2
963  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
964  $select_month .= ajax_combobox($htmlname);
965  }
966 
967  return $select_month;
968  }
969 
970  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
985  public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp')
986  {
987  // phpcs:enable
988  print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss);
989  }
990 
1006  public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
1007  {
1008  $out = '';
1009 
1010  $currentyear = date("Y") + $offset;
1011  $max_year = $currentyear + $max_year;
1012  $min_year = $currentyear - $min_year;
1013  if (empty($selected) && empty($useempty)) $selected = $currentyear;
1014 
1015  $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
1016  if ($useempty)
1017  {
1018  $selected_html = '';
1019  if ($selected == '') $selected_html = ' selected';
1020  $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
1021  }
1022  if (!$invert)
1023  {
1024  for ($y = $max_year; $y >= $min_year; $y--)
1025  {
1026  $selected_html = '';
1027  if ($selected > 0 && $y == $selected) $selected_html = ' selected';
1028  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1029  }
1030  } else {
1031  for ($y = $min_year; $y <= $max_year; $y++)
1032  {
1033  $selected_html = '';
1034  if ($selected > 0 && $y == $selected) $selected_html = ' selected';
1035  $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
1036  }
1037  }
1038  $out .= "</select>\n";
1039 
1040  // Add code for jquery to use multiselect
1041  if ($addjscombo)
1042  {
1043  // Enhance with select2
1044  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1045  $out .= ajax_combobox($htmlname);
1046  }
1047 
1048  return $out;
1049  }
1050 
1051 
1060  public static function getBoxesArea($user, $areacode)
1061  {
1062  global $conf, $langs, $db;
1063 
1064  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
1065 
1066  $confuserzone = 'MAIN_BOXES_'.$areacode;
1067 
1068  // $boxactivated will be array of boxes enabled into global setup
1069  // $boxidactivatedforuser will be array of boxes choosed by user
1070 
1071  $selectboxlist = '';
1072  $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)
1073 
1074  $boxidactivatedforuser = array();
1075  foreach ($boxactivated as $box)
1076  {
1077  if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
1078  }
1079 
1080  // Define selectboxlist
1081  $arrayboxtoactivatelabel = array();
1082  if (!empty($user->conf->$confuserzone))
1083  {
1084  $boxorder = '';
1085  $langs->load("boxes"); // Load label of boxes
1086  foreach ($boxactivated as $box)
1087  {
1088  if (!empty($boxidactivatedforuser[$box->id])) continue; // Already visible for user
1089  $label = $langs->transnoentitiesnoconv($box->boxlabel);
1090  //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1091  if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone')
1092  {
1093  $label = $label.' <span class="fa fa-bar-chart"></span>';
1094  }
1095  $arrayboxtoactivatelabel[$box->id] = $label; // We keep only boxes not shown for user, to show into combo list
1096  }
1097  foreach ($boxidactivatedforuser as $boxid)
1098  {
1099  if (empty($boxorder)) $boxorder .= 'A:';
1100  $boxorder .= $boxid.',';
1101  }
1102 
1103  //var_dump($boxidactivatedforuser);
1104 
1105  // Class Form must have been already loaded
1106  $selectboxlist .= '<!-- Form with select box list -->'."\n";
1107  $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1108  $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
1109  $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
1110  $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
1111  $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
1112  $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1113  $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1114  if (empty($conf->use_javascript_ajax)) $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1115  $selectboxlist .= '</form>';
1116  if (!empty($conf->use_javascript_ajax))
1117  {
1118  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
1119  $selectboxlist .= ajax_combobox("boxcombo");
1120  }
1121  }
1122 
1123  // Javascript code for dynamic actions
1124  if (!empty($conf->use_javascript_ajax))
1125  {
1126  $selectboxlist .= '<script type="text/javascript" language="javascript">
1127 
1128  // To update list of activated boxes
1129  function updateBoxOrder(closing) {
1130  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1131  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1132  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1133  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
1134  {
1135  jQuery.ajax({
1136  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=0&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1137  async: false
1138  });
1139  // We force reload to be sure to get all boxes into list
1140  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox\';
1141  }
1142  else
1143  {
1144  jQuery.ajax({
1145  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1146  async: true
1147  });
1148  }
1149  }
1150 
1151  jQuery(document).ready(function() {
1152  jQuery("#boxcombo").change(function() {
1153  var boxid=jQuery("#boxcombo").val();
1154  if (boxid > 0) {
1155  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1156  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1157  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1158  jQuery.ajax({
1159  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
1160  async: false
1161  });
1162  window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=addbox&boxid=\'+boxid;
1163  }
1164  });';
1165  if (!count($arrayboxtoactivatelabel)) $selectboxlist .= 'jQuery("#boxcombo").hide();';
1166  $selectboxlist .= '
1167 
1168  jQuery("#boxhalfleft, #boxhalfright").sortable({
1169  handle: \'.boxhandle\',
1170  revert: \'invalid\',
1171  items: \'.boxdraggable\',
1172  containment: \'document\',
1173  connectWith: \'#boxhalfleft, #boxhalfright\',
1174  stop: function(event, ui) {
1175  updateBoxOrder(1); /* 1 to avoid message after a move */
1176  }
1177  });
1178 
1179  jQuery(".boxclose").click(function() {
1180  var self = this; // because JQuery can modify this
1181  var boxid=self.id.substring(8);
1182  var label=jQuery(\'#boxlabelentry\'+boxid).val();
1183  console.log("We close box "+boxid);
1184  jQuery(\'#boxto_\'+boxid).remove();
1185  if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid));
1186  updateBoxOrder(1); /* 1 to avoid message after a remove */
1187  });
1188 
1189  });'."\n";
1190 
1191  $selectboxlist .= '</script>'."\n";
1192  }
1193 
1194  // Define boxlista and boxlistb
1195  $boxlista = ''; $boxlistb = '';
1196  $nbboxactivated = count($boxidactivatedforuser);
1197 
1198  if ($nbboxactivated)
1199  {
1200  // Load translation files required by the page
1201  $langs->loadLangs(array("boxes", "projects"));
1202 
1203  $emptybox = new ModeleBoxes($db);
1204 
1205  $boxlista .= "\n<!-- Box left container -->\n";
1206 
1207  // Define $box_max_lines
1208  $box_max_lines = 5;
1209  if (!empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
1210 
1211  $ii = 0;
1212  foreach ($boxactivated as $key => $box)
1213  {
1214  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1215  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1216  if (preg_match('/^A/i', $box->box_order)) // column A
1217  {
1218  $ii++;
1219  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1220  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1221  // Show box
1222  $box->loadBox($box_max_lines);
1223  $boxlista .= $box->showBox(null, null, 1);
1224  }
1225  }
1226 
1227  if ($conf->browser->layout != 'phone')
1228  {
1229  $emptybox->box_id = 'A';
1230  $emptybox->info_box_head = array();
1231  $emptybox->info_box_contents = array();
1232  $boxlista .= $emptybox->showBox(array(), array(), 1);
1233  }
1234  $boxlista .= "<!-- End box left container -->\n";
1235 
1236  $boxlistb .= "\n<!-- Box right container -->\n";
1237 
1238  $ii = 0;
1239  foreach ($boxactivated as $key => $box)
1240  {
1241  if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1242  if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
1243  if (preg_match('/^B/i', $box->box_order)) // colonne B
1244  {
1245  $ii++;
1246  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1247  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1248  // Show box
1249  $box->loadBox($box_max_lines);
1250  $boxlistb .= $box->showBox(null, null, 1);
1251  }
1252  }
1253 
1254  if ($conf->browser->layout != 'phone')
1255  {
1256  $emptybox->box_id = 'B';
1257  $emptybox->info_box_head = array();
1258  $emptybox->info_box_contents = array();
1259  $boxlistb .= $emptybox->showBox(array(), array(), 1);
1260  }
1261 
1262  $boxlistb .= "<!-- End box right container -->\n";
1263  }
1264 
1265  return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1266  }
1267 
1268 
1269  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1282  public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
1283  {
1284  // phpcs:enable
1285  global $langs, $conf;
1286 
1287  $langs->load("admin");
1288 
1289  $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1290  $sql .= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
1291  $sql .= " ORDER BY ".$labelfield;
1292 
1293  dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1294  $result = $this->db->query($sql);
1295  if ($result)
1296  {
1297  $num = $this->db->num_rows($result);
1298  $i = 0;
1299  if ($num)
1300  {
1301  print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
1302  if ($useempty == 1 || ($useempty == 2 && $num > 1))
1303  {
1304  print '<option value="-1">&nbsp;</option>';
1305  }
1306 
1307  while ($i < $num)
1308  {
1309  $obj = $this->db->fetch_object($result);
1310  if ($selected == $obj->rowid || $selected == $obj->$keyfield)
1311  {
1312  print '<option value="'.$obj->$keyfield.'" selected>';
1313  } else {
1314  print '<option value="'.$obj->$keyfield.'">';
1315  }
1316  print $obj->$labelfield;
1317  print '</option>';
1318  $i++;
1319  }
1320  print "</select>";
1321  } else {
1322  print $langs->trans("DictionaryEmpty");
1323  }
1324  } else {
1325  dol_print_error($this->db);
1326  }
1327  }
1328 
1339  public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
1340  {
1341  global $langs;
1342 
1343  $automatic = "automatic"; $manual = "manual";
1344  if ($option)
1345  {
1346  $automatic = "1";
1347  $manual = "0";
1348  }
1349 
1350  $disabled = ($disabled ? ' disabled' : '');
1351 
1352  $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
1353  if ($useempty) $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
1354  if (("$value" == 'automatic') || ($value == 1))
1355  {
1356  $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
1357  $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
1358  } else {
1359  $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
1360  $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
1361  $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
1362  }
1363  $resultautomanual .= '</select>'."\n";
1364  return $resultautomanual;
1365  }
1366 
1367 
1377  public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250')
1378  {
1379  global $langs, $extrafields, $form;
1380 
1381  $YYYY = substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1);
1382  $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
1383  $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
1384  $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
1385  $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
1386  $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
1387 
1388  foreach ($object->fields as $key => $val) {
1389  if (!$val['measure']) {
1390  if (in_array($key, array(
1391  'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
1392  'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue;
1393  if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue;
1394  if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue;
1395  if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue;
1396  if (preg_match('/^pass/', $key)) continue;
1397  if (in_array($val['type'], array('html', 'text'))) continue;
1398  if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
1399  $arrayofgroupby['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.')</span>', 'position' => $val['position'].'-y');
1400  $arrayofgroupby['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.')</span>', 'position' => $val['position'].'-m');
1401  $arrayofgroupby['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' <span class="opacitymedium">('.$YYYY.'-'.$MM.'-'.$DD.')</span>', 'position' => $val['position'].'-d');
1402  } else {
1403  $arrayofgroupby['t.'.$key] = array('label' => $langs->trans($val['label']), 'position' => (int) $val['position']);
1404  }
1405  }
1406  }
1407  // Add extrafields to Group by
1408  if ($object->isextrafieldmanaged) {
1409  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
1410  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue;
1411  if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue;
1412  $arrayofgroupby['te.'.$key] = array('label' => $langs->trans($extrafields->attributes[$object->table_element]['label'][$key]), 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key]);
1413  }
1414  }
1415 
1416  $arrayofgroupby = dol_sort_array($arrayofgroupby, 'position', 'asc', 0, 0, 1);
1417  $arrayofgroupbylabel = array();
1418  foreach ($arrayofgroupby as $key => $val) {
1419  $arrayofgroupbylabel[$key] = $val['label'];
1420  }
1421  $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, 1, 0, 0, '', 0, 0, 0, '', $morecss, 1);
1422 
1423  return $result;
1424  }
1425 
1434  public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis)
1435  {
1436  global $langs, $extrafields, $form;
1437 
1438  $YYYY = substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1).substr($langs->trans("Year"), 0, 1);
1439  $MM = substr($langs->trans("Month"), 0, 1).substr($langs->trans("Month"), 0, 1);
1440  $DD = substr($langs->trans("Day"), 0, 1).substr($langs->trans("Day"), 0, 1);
1441  $HH = substr($langs->trans("Hour"), 0, 1).substr($langs->trans("Hour"), 0, 1);
1442  $MI = substr($langs->trans("Minute"), 0, 1).substr($langs->trans("Minute"), 0, 1);
1443  $SS = substr($langs->trans("Second"), 0, 1).substr($langs->trans("Second"), 0, 1);
1444 
1445 
1446  foreach ($object->fields as $key => $val) {
1447  if (!$val['measure']) {
1448  if (in_array($key, array(
1449  'id', 'ref_int', 'ref_ext', 'rowid', 'entity', 'last_main_doc', 'logo', 'logo_squarred', 'extraparams',
1450  'parent', 'photo', 'socialnetworks', 'webservices_url', 'webservices_key'))) continue;
1451  if (isset($val['enabled']) && !dol_eval($val['enabled'], 1)) continue;
1452  if (isset($val['visible']) && !dol_eval($val['visible'], 1)) continue;
1453  if (preg_match('/^fk_/', $key) && !preg_match('/^fk_statu/', $key)) continue;
1454  if (preg_match('/^pass/', $key)) continue;
1455  if (in_array($val['type'], array('html', 'text'))) continue;
1456  if (in_array($val['type'], array('timestamp', 'date', 'datetime'))) {
1457  $arrayofxaxis['t.'.$key.'-year'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.')', 'position' => $val['position'].'-y');
1458  $arrayofxaxis['t.'.$key.'-month'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.')', 'position' => $val['position'].'-m');
1459  $arrayofxaxis['t.'.$key.'-day'] = array('label' => $langs->trans($val['label']).' ('.$YYYY.'-'.$MM.'-'.$DD.')', 'position' => $val['position'].'-d');
1460  } else {
1461  $arrayofxaxis['t.'.$key] = array('label' => $langs->trans($val['label']), 'position' => (int) $val['position']);
1462  }
1463  }
1464  }
1465 
1466  // Add extrafields to X-Axis
1467  if ($object->isextrafieldmanaged) {
1468  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
1469  if ($extrafields->attributes[$object->table_element]['type'][$key] == 'separate') continue;
1470  if (!empty($extrafields->attributes[$object->table_element]['totalizable'][$key])) continue;
1471  $arrayofxaxis['te.'.$key] = array('label' => $langs->trans($extrafields->attributes[$object->table_element]['label'][$key]), 'position' => 1000 + (int) $extrafields->attributes[$object->table_element]['pos'][$key]);
1472  }
1473  }
1474 
1475  $arrayofxaxis = dol_sort_array($arrayofxaxis, 'position', 'asc', 0, 0, 1);
1476 
1477  $arrayofxaxislabel = array();
1478  foreach ($arrayofxaxis as $key => $val) {
1479  $arrayofxaxislabel[$key] = $val['label'];
1480  }
1481  $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, 1, 0, 0, '', 0, 0, 0, '', 'minwidth250', 1);
1482 
1483  return $result;
1484  }
1485 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
static selectarray($htmlname, $array, $id= '', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam= '', $translate=0, $maxlen=0, $disabled=0, $sort= '', $morecss= '', $addjscombo=0, $moreparamonempty= '', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
dol_eval($s, $returnvalue=0, $hideerrors=1)
Replace eval function to add more security.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
__construct($db)
Constructor.
select_export_model($selected= '', $htmlname= 'exportmodelid', $type= '', $useempty=0, $fk_user=null)
Return HTML select list of export models.
select_ecotaxes($selected= '', $htmlname= 'ecotaxe_id')
Return list of ecotaxes with label.
select_color($set_color= '', $prefix= 'f_color', $form_name= '', $showcolorbox=1, $arrayofcolors= '')
Output a HTML code to select a color.
Class to manage Dolibarr users.
Definition: user.class.php:44
select_revenue_stamp($selected= '', $htmlname= 'revenuestamp', $country_code= '')
Return list of revenue stamp for country.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete= 'resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:391
Class ModeleBoxes.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:108
selectyear($selected= '', $htmlname= 'yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option= '', $morecss= 'valignmiddle width75', $addjscombo=false)
Return HTML combo list of years.
$conf db
API class for accounts.
Definition: inc.php:54
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value (&#39;FFFFFF&#39;, &#39;255,255,255&#39;) into an array RGB array(255,255,255).
price($amount, $form=0, $outlangs= '', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code= '')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
selectProjectTasks($selectedtask= '', $projectid=0, $htmlname= 'task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0, $filteronprojstatus= '', $morecss= '')
Return list of project and tasks.
select_import_model($selected= '', $htmlname= 'importmodelid', $type= '', $useempty=0, $fk_user=null)
Return list of export models.
select_dictionary($htmlname, $dictionarytable, $keyfield= 'code', $labelfield= 'label', $selected= '', $useempty=0, $moreattrib= '')
Return a HTML select list of a dictionary.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Class to manage categories.
selectXAxisField($object, $search_xaxis, &$arrayofxaxis)
Return HTML select list to select a group by field.
selectAutoManual($htmlname, $value= '', $option=0, $disabled=false, $useempty=0)
Return an html string with a select combo box to choose yes or no.
_pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0)
Write lines of a project (all lines of a project if parent = 0)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Classe permettant la generation de composants html autre Only common components are here...
static listBoxes($db, $mode, $zone, $user=null, $excludelist=array(), $includehidden=1)
Return array of boxes qualified for area and user.
monthArray($outputlangs, $short=0)
Return array of translated months or selected month.
Definition: date.lib.php:911
dol_sort_array(&$array, $index, $order= 'asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print
Draft customers invoices.
Definition: index.php:89
Class to manage tasks.
Definition: task.class.php:35
static selectColor($set_color= '', $prefix= 'f_color', $form_name= '', $showcolorbox=1, $arrayofcolors= '', $morecss= '', $setpropertyonselect= '')
Output a HTML code to select a color.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
select_categories($type, $selected=0, $htmlname= 'search_categ', $nocateg=0, $showempty=1, $morecss= '')
Return select list for categories (to use in form search selectors)
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
select_year($selected= '', $htmlname= 'yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option= '', $morecss= 'valignmiddle maxwidth75imp')
Return HTML combo list of years.
select_month($selected= '', $htmlname= 'monthid', $useempty=0, $longlabel=0, $morecss= 'minwidth50 maxwidth75imp valignmiddle', $addjscombo=false)
Return HTML combo list of month.
static showColor($color, $textifnotdefined= '')
Output a HTML thumb of color or a text if not defined.
colorIsLight($stringcolor)
Return true if the color is light.
select_salesrepresentatives($selected, $htmlname, $user, $showstatus=0, $showempty=1, $morecss= '', $norepresentative=0)
Return select list for categories (to use in form search selectors)
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
select_percent($selected=0, $htmlname= 'percent', $disabled=0, $increment=5, $start=0, $end=100, $showempty=0)
Return a HTML select list to select a percent.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user...
select_dayofweek($selected= '', $htmlname= 'weekid', $useempty=0)
Return HTML combo list of week.
colorArrayToHex($arraycolor, $colorifnotfound= '888888')
Convert an array with RGB value into hex RGB value.
selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss= 'minwidth200 maxwidth250')
Return HTML select list to select a group by field.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...