dolibarr  7.0.0-beta
html.formother.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
5  * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
6  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
7  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.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  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
38 class FormOther
39 {
40  private $db;
41  public $error;
42 
43 
49  function __construct($db)
50  {
51  $this->db = $db;
52 
53  return 1;
54  }
55 
56 
66  function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
67  {
68  $sql = "SELECT rowid, label";
69  $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
70  $sql.= " WHERE type = '".$type."'";
71  $sql.= " ORDER BY rowid";
72  $result = $this->db->query($sql);
73  if ($result)
74  {
75  print '<select class="flat minwidth200" name="'.$htmlname.'">';
76  if ($useempty)
77  {
78  print '<option value="-1">&nbsp;</option>';
79  }
80 
81  $num = $this->db->num_rows($result);
82  $i = 0;
83  while ($i < $num)
84  {
85  $obj = $this->db->fetch_object($result);
86  if ($selected == $obj->rowid)
87  {
88  print '<option value="'.$obj->rowid.'" selected>';
89  }
90  else
91  {
92  print '<option value="'.$obj->rowid.'">';
93  }
94  print $obj->label;
95  print '</option>';
96  $i++;
97  }
98  print "</select>";
99  }
100  else {
101  dol_print_error($this->db);
102  }
103  }
104 
105 
115  function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0)
116  {
117  $sql = "SELECT rowid, label";
118  $sql.= " FROM ".MAIN_DB_PREFIX."import_model";
119  $sql.= " WHERE type = '".$type."'";
120  $sql.= " ORDER BY rowid";
121  $result = $this->db->query($sql);
122  if ($result)
123  {
124  print '<select class="flat minwidth200" name="'.$htmlname.'">';
125  if ($useempty)
126  {
127  print '<option value="-1">&nbsp;</option>';
128  }
129 
130  $num = $this->db->num_rows($result);
131  $i = 0;
132  while ($i < $num)
133  {
134  $obj = $this->db->fetch_object($result);
135  if ($selected == $obj->rowid)
136  {
137  print '<option value="'.$obj->rowid.'" selected>';
138  }
139  else
140  {
141  print '<option value="'.$obj->rowid.'">';
142  }
143  print $obj->label;
144  print '</option>';
145  $i++;
146  }
147  print "</select>";
148  }
149  else {
150  dol_print_error($this->db);
151  }
152  }
153 
154 
162  function select_ecotaxes($selected='',$htmlname='ecotaxe_id')
163  {
164  global $langs;
165 
166  $sql = "SELECT e.rowid, e.code, e.libelle, e.price, e.organization,";
167  $sql.= " c.label as country";
168  $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
169  $sql.= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
170  $sql.= " ORDER BY country, e.organization ASC, e.code ASC";
171 
172  dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
173  $resql=$this->db->query($sql);
174  if ($resql)
175  {
176  print '<select class="flat" name="'.$htmlname.'">';
177  $num = $this->db->num_rows($resql);
178  $i = 0;
179  print '<option value="-1">&nbsp;</option>'."\n";
180  if ($num)
181  {
182  while ($i < $num)
183  {
184  $obj = $this->db->fetch_object($resql);
185  if ($selected && $selected == $obj->rowid)
186  {
187  print '<option value="'.$obj->rowid.'" selected>';
188  }
189  else
190  {
191  print '<option value="'.$obj->rowid.'">';
192  //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
193  }
194  $selectOptionValue = $obj->code.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
195  print $selectOptionValue;
196  print '</option>';
197  $i++;
198  }
199  }
200  print '</select>';
201  return 0;
202  }
203  else
204  {
205  dol_print_error($this->db);
206  return 1;
207  }
208  }
209 
210 
219  function select_revenue_stamp($selected='',$htmlname='revenuestamp',$country_code='')
220  {
221  global $langs;
222 
223  $out='';
224 
225  $sql = "SELECT r.taux, r.revenuestamp_type";
226  $sql.= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
227  $sql.= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
228  $sql.= " AND c.code = '".$country_code."'";
229 
230  dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
231  $resql=$this->db->query($sql);
232  if ($resql)
233  {
234  $out.='<select class="flat" name="'.$htmlname.'">';
235  $num = $this->db->num_rows($resql);
236  $i = 0;
237  $out.='<option value="0">&nbsp;</option>'."\n";
238  if ($num)
239  {
240  while ($i < $num)
241  {
242  $obj = $this->db->fetch_object($resql);
243  if (($selected && $selected == $obj->taux) || $num == 1)
244  {
245  $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
246  }
247  else
248  {
249  $out.='<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
250  //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
251  }
252  $out.=$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
253  $out.='</option>';
254  $i++;
255  }
256  }
257  $out.='</select>';
258  return $out;
259  }
260  else
261  {
262  dol_print_error($this->db);
263  return '';
264  }
265  }
266 
267 
280  function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100,$showempty=0)
281  {
282  $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled':'').'>';
283  if ($showempty) $return.='<option value="-1"'.(($selected == -1 || $selected == '')?' selected':'').'>&nbsp;</option>';
284 
285  for ($i = $start ; $i <= $end ; $i += $increment)
286  {
287  if ($selected != '' && (int) $selected == $i)
288  {
289  $return.= '<option value="'.$i.'" selected>';
290  }
291  else
292  {
293  $return.= '<option value="'.$i.'">';
294  }
295  $return.= $i.' % ';
296  $return.= '</option>';
297  }
298 
299  $return.= '</select>';
300 
301  return $return;
302  }
303 
316  function select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='')
317  {
318  global $conf, $langs;
319  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
320 
321  // For backward compatibility
322  if (is_numeric($type))
323  {
324  dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
325  }
326 
327  // Load list of "categories"
328  $static_categs = new Categorie($this->db);
329  $tab_categs = $static_categs->get_full_arbo($type);
330 
331  $moreforfilter = '';
332  // Enhance with select2
333  if ($conf->use_javascript_ajax)
334  {
335  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
336  $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
337  $moreforfilter.=$comboenhancement;
338  }
339 
340  // Print a select with each of them
341  $moreforfilter.='<select class="flat minwidth100'.($morecss?' '.$morecss:'').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
342  if ($showempty) $moreforfilter.='<option value="0">&nbsp;</option>'; // Should use -1 to say nothing
343 
344  if (is_array($tab_categs))
345  {
346  foreach ($tab_categs as $categ)
347  {
348  $moreforfilter.='<option value="'.$categ['id'].'"';
349  if ($categ['id'] == $selected) $moreforfilter.=' selected';
350  $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
351  }
352  }
353  if ($nocateg)
354  {
355  $langs->load("categories");
356  $moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NotCategorized").' -</option>';
357  }
358  $moreforfilter.='</select>';
359 
360  return $moreforfilter;
361  }
362 
363 
375  function select_salesrepresentatives($selected,$htmlname,$user,$showstatus=0,$showempty=1,$morecss='')
376  {
377  global $conf,$langs;
378  $langs->load('users');
379 
380  $out = '';
381  // Enhance with select2
382  if ($conf->use_javascript_ajax)
383  {
384  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
385 
386  $comboenhancement = ajax_combobox($htmlname);
387  if ($comboenhancement)
388  {
389  $out.=$comboenhancement;
390  }
391  }
392  // Select each sales and print them in a select input
393  $out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
394  if ($showempty) $out.='<option value="0">&nbsp;</option>';
395 
396  // Get list of users allowed to be viewed
397  $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
398  $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
399  $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
400  if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
401  if (! empty($user->societe_id)) $sql_usr.=" AND u.fk_soc = ".$user->societe_id;
402  // Add existing sales representatives of thirdparty of external user
403  if (empty($user->rights->user->user->lire) && $user->societe_id)
404  {
405  $sql_usr.=" UNION ";
406  $sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
407  $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
408  $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
409  $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
410  }
411  $sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
412  //print $sql_usr;exit;
413 
414  $resql_usr = $this->db->query($sql_usr);
415  if ($resql_usr)
416  {
417  while ($obj_usr = $this->db->fetch_object($resql_usr))
418  {
419 
420  $out.='<option value="'.$obj_usr->rowid.'"';
421 
422  if ($obj_usr->rowid == $selected) $out.=' selected';
423 
424  $out.='>';
425  $out.=dolGetFirstLastname($obj_usr->firstname,$obj_usr->lastname);
426  // Complete name with more info
427  $moreinfo=0;
428  if (! empty($conf->global->MAIN_SHOW_LOGIN))
429  {
430  $out.=($moreinfo?' - ':' (').$obj_usr->login;
431  $moreinfo++;
432  }
433  if ($showstatus >= 0)
434  {
435  if ($obj_usr->statut == 1 && $showstatus == 1)
436  {
437  $out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
438  $moreinfo++;
439  }
440  if ($obj_usr->statut == 0)
441  {
442  $out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
443  $moreinfo++;
444  }
445  }
446  $out.=($moreinfo?')':'');
447  $out.='</option>';
448  }
449  $this->db->free($resql_usr);
450  }
451  else
452  {
453  dol_print_error($this->db);
454  }
455  $out.='</select>';
456 
457  return $out;
458  }
459 
473  function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0)
474  {
475  global $user, $langs;
476 
477  require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
478 
479  //print $modeproject.'-'.$modetask;
480  $task=new Task($this->db);
481  $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
482  if ($tasksarray)
483  {
484  print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
485  if ($useempty) print '<option value="0">&nbsp;</option>';
486  $j=0;
487  $level=0;
488  $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
489  print '</select>';
490 
491  print ajax_combobox($htmlname);
492  }
493  else
494  {
495  print '<div class="warning">'.$langs->trans("NoProject").'</div>';
496  }
497  }
498 
511  private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0, $disablechildoftaskid=0)
512  {
513  global $langs, $user, $conf;
514 
515  $lastprojectid=0;
516 
517  $numlines=count($lines);
518  for ($i = 0 ; $i < $numlines ; $i++)
519  {
520  if ($lines[$i]->fk_parent == $parent)
521  {
522  $var = !$var;
523 
524  //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
525 
526  // Break on a new project
527  if ($parent == 0) // We are on a task at first level
528  {
529  if ($lines[$i]->fk_project != $lastprojectid) // Break found on project
530  {
531  if ($i > 0) print '<option value="0" disabled>----------</option>';
532  print '<option value="'.$lines[$i]->fk_project.'_0"';
533  if ($selectedproject == $lines[$i]->fk_project) print ' selected';
534  print '>'; // Project -> Task
535  print $langs->trans("Project").' '.$lines[$i]->projectref;
536  if (empty($lines[$i]->public))
537  {
538  print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
539  }
540  else
541  {
542  print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
543  }
544  //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
545  print "</option>\n";
546 
547  $lastprojectid=$lines[$i]->fk_project;
548  $inc++;
549  }
550  }
551 
552  $newdisablechildoftaskid=$disablechildoftaskid;
553 
554  // Print task
555  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
556  {
557  // Check if we must disable entry
558  $disabled=0;
559  if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
560  {
561  $disabled++;
562  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
563  }
564 
565  print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
566  if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
567  if ($disabled) print ' disabled';
568  print '>';
569  print $langs->trans("Project").' '.$lines[$i]->projectref;
570  if (empty($lines[$i]->public))
571  {
572  print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
573  }
574  else
575  {
576  print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
577  }
578  if ($lines[$i]->id) print ' > ';
579  for ($k = 0 ; $k < $level ; $k++)
580  {
581  print "&nbsp;&nbsp;&nbsp;";
582  }
583  print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n";
584  $inc++;
585  }
586 
587  $level++;
588  if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
589  $level--;
590  }
591  }
592  }
593 
594 
603  static function showColor($color, $textifnotdefined='')
604  {
605  $textcolor='FFF';
606  include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
607  if(colorIsLight($color)) $textcolor='000';
608 
609  $color = colorArrayToHex(colorStringToArray($color,array()),'');
610 
611  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.'">';
612  else print $textifnotdefined;
613  }
614 
627  function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
628  {
629  print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
630  }
631 
644  static function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
645  {
646  // Deprecation warning
647  if ($form_name) {
648  dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING);
649  }
650 
651  global $langs,$conf;
652 
653  $out='';
654 
655  if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
656  {
657  $langs->load("other");
658  if (empty($conf->dol_use_jmobile))
659  {
660  $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
661  $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
662  $out.= '<script type="text/javascript">
663  jQuery(document).ready(function(){
664  $(\'#colorpicker'.$prefix.'\').jPicker( {
665  window: {
666  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
667  effects:
668  {
669  type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
670  speed:
671  {
672  show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
673  hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
674  }
675  },
676  position:
677  {
678  x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
679  y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
680  },
681  },
682  images: {
683  clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
684  picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
685  },
686  localization: // alter these to change the text presented by the picker (e.g. different language)
687  {
688  text:
689  {
690  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
691  newColor: \''.dol_escape_js($langs->trans("New")).'\',
692  currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
693  ok: \''.dol_escape_js($langs->trans("Save")).'\',
694  cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
695  }
696  }
697  } ); });
698  </script>';
699  }
700  $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss?' '.$morecss:'').'" type="text" value="'.$set_color.'" />';
701  }
702  else // In most cases, this is not used. We used instead function with no specific list of colors
703  {
704  if (empty($conf->dol_use_jmobile))
705  {
706  $out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
707  $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
708  $out.= '<script type="text/javascript">
709  jQuery(document).ready(function(){
710  jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
711  size: 14,
712  label: \'\',
713  hide: true
714  });
715  });
716  </script>';
717  }
718  $out.= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss?' '.$morecss:'').'" name="'.$prefix.'">';
719  //print '<option value="-1">&nbsp;</option>';
720  foreach ($arrayofcolors as $val)
721  {
722  $out.= '<option value="'.$val.'"';
723  if ($set_color == $val) $out.= ' selected';
724  $out.= '>'.$val.'</option>';
725  }
726  $out.= '</select>';
727  }
728 
729  return $out;
730  }
731 
742  function CreateColorIcon($color,$module,$name,$x='12',$y='12')
743  {
744  global $conf;
745 
746  $file = $conf->$module->dir_temp.'/'.$name.'.png';
747 
748  // On cree le repertoire contenant les icones
749  if (! file_exists($conf->$module->dir_temp))
750  {
751  dol_mkdir($conf->$module->dir_temp);
752  }
753 
754  // On cree l'image en vraies couleurs
755  $image = imagecreatetruecolor($x,$y);
756 
757  $color = substr($color,1,6);
758 
759  $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
760  $vert = hexdec(substr($color,2,2)); //conversion du canal vert
761  $bleu = hexdec(substr($color,4,2)); //conversion du canal bleu
762 
763  $couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
764  //print $rouge.$vert.$bleu;
765  imagefill($image,0,0,$couleur); //on remplit l'image
766  // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
767  ImagePng($image,$file); //renvoie une image sous format png
768  ImageDestroy($image);
769  }
770 
779  function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
780  {
781  global $langs;
782 
783  $week = array( 0=>$langs->trans("Day0"),
784  1=>$langs->trans("Day1"),
785  2=>$langs->trans("Day2"),
786  3=>$langs->trans("Day3"),
787  4=>$langs->trans("Day4"),
788  5=>$langs->trans("Day5"),
789  6=>$langs->trans("Day6"));
790 
791  $select_week = '<select class="flat" name="'.$htmlname.'">';
792  if ($useempty)
793  {
794  $select_week .= '<option value="-1">&nbsp;</option>';
795  }
796  foreach ($week as $key => $val)
797  {
798  if ($selected == $key)
799  {
800  $select_week .= '<option value="'.$key.'" selected>';
801  }
802  else
803  {
804  $select_week .= '<option value="'.$key.'">';
805  }
806  $select_week .= $val;
807  $select_week .= '</option>';
808  }
809  $select_week .= '</select>';
810  return $select_week;
811  }
812 
822  function select_month($selected='',$htmlname='monthid',$useempty=0,$longlabel=0)
823  {
824  global $langs;
825 
826  require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
827 
828  if ($longlabel) $montharray = monthArray($langs, 0); // Get array
829  else $montharray = monthArray($langs, 1);
830 
831  $select_month = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
832  if ($useempty)
833  {
834  $select_month .= '<option value="0">&nbsp;</option>';
835  }
836  foreach ($montharray as $key => $val)
837  {
838  if ($selected == $key)
839  {
840  $select_month .= '<option value="'.$key.'" selected>';
841  }
842  else
843  {
844  $select_month .= '<option value="'.$key.'">';
845  }
846  $select_month .= $val;
847  $select_month .= '</option>';
848  }
849  $select_month .= '</select>';
850  return $select_month;
851  }
852 
866  function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
867  {
868  print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option);
869  }
870 
884  function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
885  {
886  $out='';
887 
888  $currentyear = date("Y")+$offset;
889  $max_year = $currentyear+$max_year;
890  $min_year = $currentyear-$min_year;
891  if(empty($selected) && empty($useempty)) $selected = $currentyear;
892 
893  $out.= '<select class="flat" placeholder="aa" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
894  if($useempty)
895  {
896  $selected_html='';
897  if ($selected == '') $selected_html = ' selected';
898  $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
899  }
900  if (! $invert)
901  {
902  for ($y = $max_year; $y >= $min_year; $y--)
903  {
904  $selected_html='';
905  if ($selected > 0 && $y == $selected) $selected_html = ' selected';
906  $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
907  }
908  }
909  else
910  {
911  for ($y = $min_year; $y <= $max_year; $y++)
912  {
913  $selected_html='';
914  if ($selected > 0 && $y == $selected) $selected_html = ' selected';
915  $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
916  }
917  }
918  $out.= "</select>\n";
919 
920  return $out;
921  }
922 
934  function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
935  {
936  global $langs,$conf;
937  global $form;
938 
939  if ($htmlname != "none")
940  {
941  print '<form method="post" action="'.$page.'">';
942  print '<input type="hidden" name="action" value="setaddress">';
943  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
944  $form->select_address($selected, $socid, $htmlname, 1);
945  print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
946  $langs->load("companies");
947  print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
948  print '</form>';
949  }
950  else
951  {
952  if ($selected)
953  {
954  require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
955  $address=new Address($this->db);
956  $result=$address->fetch_address($selected);
957  print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
958  }
959  else
960  {
961  print "&nbsp;";
962  }
963  }
964  }
965 
966 
967 
976  static function getBoxesArea($user,$areacode)
977  {
978  global $conf,$langs,$db;
979 
980  include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
981 
982  $confuserzone='MAIN_BOXES_'.$areacode;
983 
984  // $boxactivated will be array of boxes enabled into global setup
985  // $boxidactivatedforuser will be array of boxes choosed by user
986 
987  $selectboxlist='';
988  $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)
989 
990  $boxidactivatedforuser=array();
991  foreach($boxactivated as $box)
992  {
993  if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) $boxidactivatedforuser[$box->id]=$box->id; // We keep only boxes to show for user
994  }
995 
996  // Define selectboxlist
997  $arrayboxtoactivatelabel=array();
998  if (! empty($user->conf->$confuserzone))
999  {
1000  $boxorder='';
1001  $langs->load("boxes"); // Load label of boxes
1002  foreach($boxactivated as $box)
1003  {
1004  if (! empty($boxidactivatedforuser[$box->id])) continue; // Already visible for user
1005  $label=$langs->transnoentitiesnoconv($box->boxlabel);
1006  //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
1007  if (preg_match('/graph/',$box->class) && empty($conf->browser->phone))
1008  {
1009  $label=$label.' <span class="fa fa-bar-chart"></span>';
1010  }
1011  $arrayboxtoactivatelabel[$box->id]=$label; // We keep only boxes not shown for user, to show into combo list
1012  }
1013  foreach($boxidactivatedforuser as $boxid)
1014  {
1015  if (empty($boxorder)) $boxorder.='A:';
1016  $boxorder.=$boxid.',';
1017  }
1018 
1019  //var_dump($boxidactivatedforuser);
1020 
1021  // Class Form must have been already loaded
1022  $selectboxlist.='<!-- Form with select box list -->'."\n";
1023  $selectboxlist.='<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
1024  $selectboxlist.='<input type="hidden" name="addbox" value="addbox">';
1025  $selectboxlist.='<input type="hidden" name="userid" value="'.$user->id.'">';
1026  $selectboxlist.='<input type="hidden" name="areacode" value="'.$areacode.'">';
1027  $selectboxlist.='<input type="hidden" name="boxorder" value="'.$boxorder.'">';
1028  $selectboxlist.=Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone', 0, 'hidden selected', 0, 1);
1029  if (empty($conf->use_javascript_ajax)) $selectboxlist.=' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
1030  $selectboxlist.='</form>';
1031  if (! empty($conf->use_javascript_ajax))
1032  {
1033  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
1034  $selectboxlist.=ajax_combobox("boxcombo");
1035  }
1036  }
1037 
1038  // Javascript code for dynamic actions
1039  if (! empty($conf->use_javascript_ajax))
1040  {
1041  $selectboxlist.='<script type="text/javascript" language="javascript">
1042 
1043  // To update list of activated boxes
1044  function updateBoxOrder(closing) {
1045  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1046  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1047  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1048  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
1049  {
1050  jQuery.ajax({
1051  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=0&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1052  async: false
1053  });
1054  // We force reload to be sure to get all boxes into list
1055  window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=delbox\';
1056  }
1057  else
1058  {
1059  jQuery.ajax({
1060  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
1061  async: true
1062  });
1063  }
1064  }
1065 
1066  jQuery(document).ready(function() {
1067  jQuery("#boxcombo").change(function() {
1068  var boxid=jQuery("#boxcombo").val();
1069  if (boxid > 0) {
1070  var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
1071  var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
1072  var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
1073  jQuery.ajax({
1074  url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
1075  async: false
1076  });
1077  window.location.search=\'mainmenu='.GETPOST("mainmenu","aZ09").'&leftmenu='.GETPOST('leftmenu',"aZ09").'&action=addbox&boxid=\'+boxid;
1078  }
1079  });';
1080  if (! count($arrayboxtoactivatelabel)) $selectboxlist.='jQuery("#boxcombo").hide();';
1081  $selectboxlist.='
1082 
1083  jQuery("#boxhalfleft, #boxhalfright").sortable({
1084  handle: \'.boxhandle\',
1085  revert: \'invalid\',
1086  items: \'.boxdraggable\',
1087  containment: \'document\',
1088  connectWith: \'#boxhalfleft, #boxhalfright\',
1089  stop: function(event, ui) {
1090  updateBoxOrder(1); /* 1 to avoid message after a move */
1091  }
1092  });
1093 
1094  jQuery(".boxclose").click(function() {
1095  var self = this; // because JQuery can modify this
1096  var boxid=self.id.substring(8);
1097  var label=jQuery(\'#boxlabelentry\'+boxid).val();
1098  console.log("We close box "+boxid);
1099  jQuery(\'#boxto_\'+boxid).remove();
1100  if (boxid > 0) jQuery(\'#boxcombo\').append(new Option(label, boxid));
1101  updateBoxOrder(1); /* 1 to avoid message after a remove */
1102  });
1103 
1104  });'."\n";
1105 
1106  $selectboxlist.='</script>'."\n";
1107  }
1108 
1109  // Define boxlista and boxlistb
1110  $nbboxactivated=count($boxidactivatedforuser);
1111 
1112  if ($nbboxactivated)
1113  {
1114  $langs->load("boxes");
1115  $langs->load("projects");
1116 
1117  $emptybox=new ModeleBoxes($db);
1118 
1119  $boxlista.="\n<!-- Box left container -->\n";
1120 
1121  // Define $box_max_lines
1122  $box_max_lines=5;
1123  if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
1124 
1125  $ii=0;
1126  foreach ($boxactivated as $key => $box)
1127  {
1128  if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1129  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
1130  if (preg_match('/^A/i',$box->box_order)) // column A
1131  {
1132  $ii++;
1133  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1134  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1135  // Show box
1136  $box->loadBox($box_max_lines);
1137  $boxlista.= $box->outputBox();
1138  }
1139  }
1140 
1141  if (empty($conf->browser->phone))
1142  {
1143  $emptybox->box_id='A';
1144  $emptybox->info_box_head=array();
1145  $emptybox->info_box_contents=array();
1146  $boxlista.= $emptybox->outputBox(array(),array());
1147  }
1148  $boxlista.= "<!-- End box left container -->\n";
1149 
1150  $boxlistb.= "\n<!-- Box right container -->\n";
1151 
1152  $ii=0;
1153  foreach ($boxactivated as $key => $box)
1154  {
1155  if ((! empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) continue;
1156  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
1157  if (preg_match('/^B/i',$box->box_order)) // colonne B
1158  {
1159  $ii++;
1160  //print 'box_id '.$boxactivated[$ii]->box_id.' ';
1161  //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
1162  // Show box
1163  $box->loadBox($box_max_lines);
1164  $boxlistb.= $box->outputBox();
1165  }
1166  }
1167 
1168  if (empty($conf->browser->phone))
1169  {
1170  $emptybox->box_id='B';
1171  $emptybox->info_box_head=array();
1172  $emptybox->info_box_contents=array();
1173  $boxlistb.= $emptybox->outputBox(array(),array());
1174  }
1175 
1176  $boxlistb.= "<!-- End box right container -->\n";
1177 
1178  }
1179 
1180  return array('selectboxlist'=>count($boxactivated)?$selectboxlist:'', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
1181  }
1182 
1183 
1196  function select_dictionary($htmlname,$dictionarytable,$keyfield='code',$labelfield='label',$selected='',$useempty=0,$moreattrib='')
1197  {
1198  global $langs, $conf;
1199 
1200  $langs->load("admin");
1201 
1202  $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
1203  $sql.= " FROM ".MAIN_DB_PREFIX.$dictionarytable;
1204  $sql.= " ORDER BY ".$labelfield;
1205 
1206  dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
1207  $result = $this->db->query($sql);
1208  if ($result)
1209  {
1210  $num = $this->db->num_rows($result);
1211  $i = 0;
1212  if ($num)
1213  {
1214  print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
1215  if ($useempty == 1 || ($useempty == 2 && $num > 1))
1216  {
1217  print '<option value="-1">&nbsp;</option>';
1218  }
1219 
1220  while ($i < $num)
1221  {
1222  $obj = $this->db->fetch_object($result);
1223  if ($selected == $obj->rowid || $selected == $obj->$keyfield)
1224  {
1225  print '<option value="'.$obj->$keyfield.'" selected>';
1226  }
1227  else
1228  {
1229  print '<option value="'.$obj->$keyfield.'">';
1230  }
1231  print $obj->$labelfield;
1232  print '</option>';
1233  $i++;
1234  }
1235  print "</select>";
1236  }
1237  else
1238  {
1239  print $langs->trans("DictionaryEmpty");
1240  }
1241  }
1242  else {
1243  dol_print_error($this->db);
1244  }
1245  }
1246 
1247 }
1248 
select_export_model($selected='', $htmlname='exportmodelid', $type='', $useempty=0)
Return HTML select list of export models.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:392
static showColor($color, $textifnotdefined='')
Output a HTML thumb of color or a text if not defined.
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.
form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
Show form to select address.
select_ecotaxes($selected='', $htmlname='ecotaxe_id')
Return list of ecotaxes with label.
select_dictionary($htmlname, $dictionarytable, $keyfield='code', $labelfield='label', $selected='', $useempty=0, $moreattrib='')
Return a HTML select list of bank accounts.
static selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='')
Output a HTML code to select a color.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into javascript code.
__construct($db)
Constructor.
select_revenue_stamp($selected='', $htmlname='revenuestamp', $country_code='')
Return list of revenue stamp for country.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class ModeleBoxes.
if(empty($reshook)) $form
View.
Definition: perms.php:103
select_month($selected='', $htmlname='monthid', $useempty=0, $longlabel=0)
Return HTML combo list of month.
colorStringToArray($stringcolor, $colorifnotfound=array(88, 88, 88))
Convert a string RGB value ('FFFFFF', '255,255,255') into an array RGB array(255,255,255).
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
select_dayofweek($selected='', $htmlname='weekid', $useempty=0)
Return HTML combo list of week.
select_import_model($selected='', $htmlname='importmodelid', $type='', $useempty=0)
Return list of export models.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage categories.
_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)
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:907
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
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...
print
Draft customers invoices.
Definition: index.php:91
Class to manage tasks.
Definition: task.class.php:32
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='')
Output a HTML code to select a color.
colorArrayToHex($arraycolor, $colorifnotfound='888888')
Convert an array with RGB value into hex RGB value.
select_salesrepresentatives($selected, $htmlname, $user, $showstatus=0, $showempty=1, $morecss='')
Return select list for categories (to use in form search selectors)
selectyear($selected='', $htmlname='yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
Return HTML combo list of years.
colorIsLight($stringcolor)
Return true if the color is light.
select_year($selected='', $htmlname='yearid', $useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
Return HTML combo list of years.
selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0, $disablechildoftaskid=0)
Return list of project and tasks.
type
Definition: viewcat.php:283
Class to manage addresses.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
select_categories($type, $selected=0, $htmlname='search_categ', $nocateg=0, $showempty=1, $morecss='')
Return select list for categories (to use in form search selectors)