dolibarr  9.0.0
html.formadmin.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
30 class FormAdmin
31 {
32  var $db;
33  var $error;
34 
35 
41  function __construct($db)
42  {
43  $this->db = $db;
44  }
45 
46  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
62  function select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0, $forcecombo=0)
63  {
64  // phpcs:enable
65  global $langs;
66 
67  $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
68 
69  $out='';
70 
71  $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>';
72  if ($showempty)
73  {
74  $out.= '<option value="0"';
75  if ($selected == '') $out.= ' selected';
76  $out.= '>';
77  if ($showempty != '1') $out.=$showempty;
78  else $out.='&nbsp;';
79  $out.='</option>';
80  }
81  if ($showauto)
82  {
83  $out.= '<option value="auto"';
84  if ($selected == 'auto') $out.= ' selected';
85  $out.= '>'.$langs->trans("AutoDetectLang").'</option>';
86  }
87 
88  asort($langs_available);
89 
90  foreach ($langs_available as $key => $value)
91  {
92  $valuetoshow=$value;
93  if ($showcode == 1) $valuetoshow=$key.' - '.$value;
94  if ($showcode == 2) $valuetoshow=$value.' ('.$key.')';
95 
96  if ($filter && is_array($filter))
97  {
98  if ( ! array_key_exists($key, $filter))
99  {
100  $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
101  }
102  }
103  else if ($selected == $key)
104  {
105  $out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
106  }
107  else
108  {
109  $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
110  }
111  }
112  $out.= '</select>';
113 
114  // Make select dynamic
115  if (! $forcecombo)
116  {
117  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
118  $out.= ajax_combobox($htmlname);
119  }
120 
121  return $out;
122  }
123 
124  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
134  function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
135  {
136  // phpcs:enable
137  global $langs,$conf;
138 
139  // Clean parameters
140 
141 
142  // Check parameters
143  if (! is_array($dirmenuarray)) return -1;
144 
145  $menuarray=array();
146  foreach ($conf->file->dol_document_root as $dirroot)
147  {
148  foreach($dirmenuarray as $dirtoscan)
149  {
150  $dir=$dirroot.$dirtoscan;
151  //print $dir.'<br>';
152  if (is_dir($dir))
153  {
154  $handle=opendir($dir);
155  if (is_resource($handle))
156  {
157  while (($file = readdir($handle))!==false)
158  {
159  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
160  {
161  if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files
162  if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
163  if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
164  if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
165 
166  $filelib=preg_replace('/\.php$/i','',$file);
167  $prefix='';
168  // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
169  if (preg_match('/^eldy/i',$file)) $prefix='0';
170  else if (preg_match('/^smartphone/i',$file)) $prefix='2';
171  else $prefix='3';
172 
173  if ($file == $selected)
174  {
175  $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
176  }
177  else
178  {
179  $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
180  }
181  }
182  }
183  closedir($handle);
184  }
185  }
186  }
187  }
188  ksort($menuarray);
189 
190  // Output combo list of menus
191  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
192  $oldprefix='';
193  foreach ($menuarray as $key => $val)
194  {
195  $tab=explode('_',$key);
196  $newprefix=$tab[0];
197  if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
198  if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
199  if ($newprefix != $oldprefix) // Add separators
200  {
201  // Affiche titre
202  print '<option value="-1" disabled>';
203  if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
204  if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
205  if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
206  if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
207  print '</option>';
208  $oldprefix=$newprefix;
209  }
210  print $val."\n"; // Show menu entry
211  }
212  print '</select>';
213  }
214 
215  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
224  function select_menu_families($selected, $htmlname, $dirmenuarray)
225  {
226  // phpcs:enable
227  global $langs,$conf;
228 
229  //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
230  $expdevmenu=array();
231 
232  $menuarray=array();
233 
234  foreach($dirmenuarray as $dirmenu)
235  {
236  foreach ($conf->file->dol_document_root as $dirroot)
237  {
238  $dir=$dirroot.$dirmenu;
239  if (is_dir($dir))
240  {
241  $handle=opendir($dir);
242  if (is_resource($handle))
243  {
244  while (($file = readdir($handle))!==false)
245  {
246  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
247  {
248  $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
249  if (preg_match('/^index/i',$filelib)) continue;
250  if (preg_match('/^default/i',$filelib)) continue;
251  if (preg_match('/^empty/i',$filelib)) continue;
252  if (preg_match('/\.lib/i',$filelib)) continue;
253  if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
254 
255  $menuarray[$filelib]=1;
256  }
257  $menuarray['all']=1;
258  }
259  closedir($handle);
260  }
261  }
262  }
263  }
264 
265  ksort($menuarray);
266 
267  // Affichage liste deroulante des menus
268  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
269  $oldprefix='';
270  foreach ($menuarray as $key => $val)
271  {
272  $tab=explode('_',$key);
273  $newprefix=$tab[0];
274  print '<option value="'.$key.'"';
275  if ($key == $selected)
276  {
277  print ' selected';
278  }
279  print '>';
280  if ($key == 'all') print $langs->trans("AllMenus");
281  else print $key;
282  print '</option>'."\n";
283  }
284  print '</select>';
285  }
286 
287 
288  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
296  function select_timezone($selected,$htmlname)
297  {
298  // phpcs:enable
299  global $langs,$conf;
300 
301  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
302  print '<option value="-1">&nbsp;</option>';
303 
304  $arraytz=array(
305  "Pacific/Midway"=>"GMT-11:00",
306  "Pacific/Fakaofo"=>"GMT-10:00",
307  "America/Anchorage"=>"GMT-09:00",
308  "America/Los_Angeles"=>"GMT-08:00",
309  "America/Dawson_Creek"=>"GMT-07:00",
310  "America/Chicago"=>"GMT-06:00",
311  "America/Bogota"=>"GMT-05:00",
312  "America/Anguilla"=>"GMT-04:00",
313  "America/Araguaina"=>"GMT-03:00",
314  "America/Noronha"=>"GMT-02:00",
315  "Atlantic/Azores"=>"GMT-01:00",
316  "Africa/Abidjan"=>"GMT+00:00",
317  "Europe/Paris"=>"GMT+01:00",
318  "Europe/Helsinki"=>"GMT+02:00",
319  "Europe/Moscow"=>"GMT+03:00",
320  "Asia/Dubai"=>"GMT+04:00",
321  "Asia/Karachi"=>"GMT+05:00",
322  "Indian/Chagos"=>"GMT+06:00",
323  "Asia/Jakarta"=>"GMT+07:00",
324  "Asia/Hong_Kong"=>"GMT+08:00",
325  "Asia/Tokyo"=>"GMT+09:00",
326  "Australia/Sydney"=>"GMT+10:00",
327  "Pacific/Noumea"=>"GMT+11:00",
328  "Pacific/Auckland"=>"GMT+12:00",
329  "Pacific/Enderbury"=>"GMT+13:00"
330  );
331  foreach ($arraytz as $lib => $gmt)
332  {
333  print '<option value="'.$lib.'"';
334  if ($selected == $lib || $selected == $gmt) print ' selected';
335  print '>'.$gmt.'</option>'."\n";
336  }
337  print '</select>';
338  }
339 
340 
341 
342  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
352  function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$showempty=0)
353  {
354  // phpcs:enable
355  global $langs;
356 
357  $langs->load("dict");
358 
359  $sql = "SELECT code, label, width, height, unit";
360  $sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format";
361  $sql.= " WHERE active=1";
362  if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
363 
364  $resql=$this->db->query($sql);
365  if ($resql)
366  {
367  $num=$this->db->num_rows($resql);
368  $i=0;
369  while ($i < $num)
370  {
371  $obj=$this->db->fetch_object($resql);
372  $unitKey = $langs->trans('SizeUnit'.$obj->unit);
373 
374  $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
375 
376  $i++;
377  }
378  }
379  else
380  {
381  dol_print_error($this->db);
382  return '';
383  }
384  $out='';
385 
386  $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
387  if ($showempty)
388  {
389  $out.= '<option value=""';
390  if ($selected == '') $out.= ' selected';
391  $out.= '>&nbsp;</option>';
392  }
393  foreach ($paperformat as $key => $value)
394  {
395  if ($selected == $key)
396  {
397  $out.= '<option value="'.$key.'" selected>'.$value.'</option>';
398  }
399  else
400  {
401  $out.= '<option value="'.$key.'">'.$value.'</option>';
402  }
403  }
404  $out.= '</select>';
405 
406  return $out;
407  }
408 }
select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0, $forcecombo=0)
Return html select list with available languages (key=&#39;en_US&#39;, value=&#39;United States&#39; for example) ...
__construct($db)
Constructor.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
print
Draft customers invoices.
Definition: index.php:91
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:1053
select_timezone($selected, $htmlname)
Return a HTML select list of timezones.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to generate html code for admin pages.
select_paper_format($selected='', $htmlname='paperformat_id', $filter=0, $showempty=0)
Return html select list with available languages (key=&#39;en_US&#39;, value=&#39;United States&#39; for example) ...
select_menu_families($selected, $htmlname, $dirmenuarray)
Return combo list of available menu families.
select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
Return list of available menus (eldy_backoffice, ...)