dolibarr  7.0.0-beta
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@capnetworks.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  return 1;
45  }
46 
61  function select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0)
62  {
63  global $langs;
64 
65  $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
66 
67  $out='';
68 
69  $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled':'').'>';
70  if ($showempty)
71  {
72  $out.= '<option value="0"';
73  if ($selected == '') $out.= ' selected';
74  $out.= '>';
75  if ($showempty != '1') $out.=$showempty;
76  else $out.='&nbsp;';
77  $out.='</option>';
78  }
79  if ($showauto)
80  {
81  $out.= '<option value="auto"';
82  if ($selected == 'auto') $out.= ' selected';
83  $out.= '>'.$langs->trans("AutoDetectLang").'</option>';
84  }
85 
86  asort($langs_available);
87 
88  foreach ($langs_available as $key => $value)
89  {
90  $valuetoshow=$value;
91  if ($showcode) $valuetoshow=$key.' - '.$value;
92 
93  if ($filter && is_array($filter))
94  {
95  if ( ! array_key_exists($key, $filter))
96  {
97  $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
98  }
99  }
100  else if ($selected == $key)
101  {
102  $out.= '<option value="'.$key.'" selected>'.$valuetoshow.'</option>';
103  }
104  else
105  {
106  $out.= '<option value="'.$key.'">'.$valuetoshow.'</option>';
107  }
108  }
109  $out.= '</select>';
110 
111  // Make select dynamic
112  include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
113  $out.= ajax_combobox($htmlname);
114 
115  return $out;
116  }
117 
127  function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
128  {
129  global $langs,$conf;
130 
131  // Clean parameters
132 
133 
134  // Check parameters
135  if (! is_array($dirmenuarray)) return -1;
136 
137  $menuarray=array();
138  foreach ($conf->file->dol_document_root as $dirroot)
139  {
140  foreach($dirmenuarray as $dirtoscan)
141  {
142  $dir=$dirroot.$dirtoscan;
143  //print $dir.'<br>';
144  if (is_dir($dir))
145  {
146  $handle=opendir($dir);
147  if (is_resource($handle))
148  {
149  while (($file = readdir($handle))!==false)
150  {
151  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
152  {
153  if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files
154  if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
155  if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
156  if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i',$file)) continue; // We exclude all menu manager files
157 
158  $filelib=preg_replace('/\.php$/i','',$file);
159  $prefix='';
160  // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
161  if (preg_match('/^eldy/i',$file)) $prefix='0';
162  else if (preg_match('/^smartphone/i',$file)) $prefix='2';
163  else $prefix='3';
164 
165  if ($file == $selected)
166  {
167  $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected>'.$filelib.'</option>';
168  }
169  else
170  {
171  $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
172  }
173  }
174  }
175  closedir($handle);
176  }
177  }
178  }
179  }
180  ksort($menuarray);
181 
182  // Output combo list of menus
183  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
184  $oldprefix='';
185  foreach ($menuarray as $key => $val)
186  {
187  $tab=explode('_',$key);
188  $newprefix=$tab[0];
189  if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
190  if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
191  if ($newprefix != $oldprefix) // Add separators
192  {
193  // Affiche titre
194  print '<option value="-1" disabled>';
195  if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
196  if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
197  if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
198  if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
199  print '</option>';
200  $oldprefix=$newprefix;
201  }
202  print $val."\n"; // Show menu entry
203  }
204  print '</select>';
205  }
206 
215  function select_menu_families($selected, $htmlname, $dirmenuarray)
216  {
217  global $langs,$conf;
218 
219  //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
220  $expdevmenu=array();
221 
222  $menuarray=array();
223 
224  foreach($dirmenuarray as $dirmenu)
225  {
226  foreach ($conf->file->dol_document_root as $dirroot)
227  {
228  $dir=$dirroot.$dirmenu;
229  if (is_dir($dir))
230  {
231  $handle=opendir($dir);
232  if (is_resource($handle))
233  {
234  while (($file = readdir($handle))!==false)
235  {
236  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
237  {
238  $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
239  if (preg_match('/^index/i',$filelib)) continue;
240  if (preg_match('/^default/i',$filelib)) continue;
241  if (preg_match('/^empty/i',$filelib)) continue;
242  if (preg_match('/\.lib/i',$filelib)) continue;
243  if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
244 
245  $menuarray[$filelib]=1;
246  }
247  $menuarray['all']=1;
248  }
249  closedir($handle);
250  }
251  }
252  }
253  }
254 
255  ksort($menuarray);
256 
257  // Affichage liste deroulante des menus
258  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
259  $oldprefix='';
260  foreach ($menuarray as $key => $val)
261  {
262  $tab=explode('_',$key);
263  $newprefix=$tab[0];
264  print '<option value="'.$key.'"';
265  if ($key == $selected)
266  {
267  print ' selected';
268  }
269  print '>';
270  if ($key == 'all') print $langs->trans("AllMenus");
271  else print $key;
272  print '</option>'."\n";
273  }
274  print '</select>';
275  }
276 
277 
285  function select_timezone($selected,$htmlname)
286  {
287  global $langs,$conf;
288 
289  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
290  print '<option value="-1">&nbsp;</option>';
291 
292  $arraytz=array(
293  "Pacific/Midway"=>"GMT-11:00",
294  "Pacific/Fakaofo"=>"GMT-10:00",
295  "America/Anchorage"=>"GMT-09:00",
296  "America/Los_Angeles"=>"GMT-08:00",
297  "America/Dawson_Creek"=>"GMT-07:00",
298  "America/Chicago"=>"GMT-06:00",
299  "America/Bogota"=>"GMT-05:00",
300  "America/Anguilla"=>"GMT-04:00",
301  "America/Araguaina"=>"GMT-03:00",
302  "America/Noronha"=>"GMT-02:00",
303  "Atlantic/Azores"=>"GMT-01:00",
304  "Africa/Abidjan"=>"GMT+00:00",
305  "Europe/Paris"=>"GMT+01:00",
306  "Europe/Helsinki"=>"GMT+02:00",
307  "Europe/Moscow"=>"GMT+03:00",
308  "Asia/Dubai"=>"GMT+04:00",
309  "Asia/Karachi"=>"GMT+05:00",
310  "Indian/Chagos"=>"GMT+06:00",
311  "Asia/Jakarta"=>"GMT+07:00",
312  "Asia/Hong_Kong"=>"GMT+08:00",
313  "Asia/Tokyo"=>"GMT+09:00",
314  "Australia/Sydney"=>"GMT+10:00",
315  "Pacific/Noumea"=>"GMT+11:00",
316  "Pacific/Auckland"=>"GMT+12:00",
317  "Pacific/Enderbury"=>"GMT+13:00"
318  );
319  foreach ($arraytz as $lib => $gmt)
320  {
321  print '<option value="'.$lib.'"';
322  if ($selected == $lib || $selected == $gmt) print ' selected';
323  print '>'.$gmt.'</option>'."\n";
324  }
325  print '</select>';
326  }
327 
328 
329 
339  function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$showempty=0)
340  {
341  global $langs;
342 
343  $langs->load("dict");
344 
345  $sql = "SELECT code, label, width, height, unit";
346  $sql.= " FROM ".MAIN_DB_PREFIX."c_paper_format";
347  $sql.= " WHERE active=1";
348  if ($filter) $sql.=" AND code LIKE '%".$this->db->escape($filter)."%'";
349 
350  $resql=$this->db->query($sql);
351  if ($resql)
352  {
353  $num=$this->db->num_rows($resql);
354  $i=0;
355  while ($i < $num)
356  {
357  $obj=$this->db->fetch_object($resql);
358  $unitKey = $langs->trans('SizeUnit'.$obj->unit);
359 
360  $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
361 
362  $i++;
363  }
364  }
365  else
366  {
367  dol_print_error($this->db);
368  return '';
369  }
370  $out='';
371 
372  $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
373  if ($showempty)
374  {
375  $out.= '<option value=""';
376  if ($selected == '') $out.= ' selected';
377  $out.= '>&nbsp;</option>';
378  }
379  foreach ($paperformat as $key => $value)
380  {
381  if ($selected == $key)
382  {
383  $out.= '<option value="'.$key.'" selected>'.$value.'</option>';
384  }
385  else
386  {
387  $out.= '<option value="'.$key.'">'.$value.'</option>';
388  }
389  }
390  $out.= '</select>';
391 
392  return $out;
393  }
394 }
__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:392
select_language($selected='', $htmlname='lang_id', $showauto=0, $filter=null, $showempty='', $showwarning=0, $disabled=0, $morecss='', $showcode=0)
Return html select list with available languages (key='en_US', value='United States' for example) ...
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='en_US', value='United States' 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, ...)
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:1013