dolibarr  13.0.2
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 <https://www.gnu.org/licenses/>.
18  */
19 
30 class FormAdmin
31 {
32  public $db;
33  public $error;
34 
35 
41  public function __construct($db)
42  {
43  $this->db = $db;
44  }
45 
46  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
65  public function select_language($selected = '', $htmlname = 'lang_id', $showauto = 0, $filter = null, $showempty = '', $showwarning = 0, $disabled = 0, $morecss = '', $showcode = 0, $forcecombo = 0, $multiselect = 0, $onlykeys = null, $mainlangonly = 0)
66  {
67  // phpcs:enable
68  global $conf, $langs;
69 
70  if (!empty($conf->global->MAIN_DEFAULT_LANGUAGE_FILTER)) $filter[$conf->global->MAIN_DEFAULT_LANGUAGE_FILTER] = 1;
71 
72  $langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 12, 0, $mainlangonly);
73 
74  $out = '';
75 
76  $out .= '<select '.($multiselect ? 'multiple="multiple" ' : '').'class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.($multiselect ? '[]' : '').'"'.($disabled ? ' disabled' : '').'>';
77  if ($showempty && !$multiselect)
78  {
79  $out .= '<option value="0"';
80  if ($selected == '') $out .= ' selected';
81  $out .= '>';
82  if ($showempty != '1') $out .= $showempty;
83  else $out .= '&nbsp;';
84  $out .= '</option>';
85  }
86  if ($showauto)
87  {
88  $out .= '<option value="auto"';
89  if ($selected == 'auto') $out .= ' selected';
90  $out .= '>'.$langs->trans("AutoDetectLang").'</option>';
91  }
92 
93  asort($langs_available);
94 
95  foreach ($langs_available as $key => $value)
96  {
97  $valuetoshow = $value;
98  if ($showcode == 1) {
99  if ($mainlangonly) $valuetoshow = '<span class="opacitymedium">'.preg_replace('/[_-].*$/', '', $key).'</span> - '.$value;
100  else $valuetoshow = '<span class="opacitymedium">'.$key.'</span> - '.$value;
101  }
102  if ($showcode == 2) {
103  if ($mainlangonly) $valuetoshow = $value.' <span class="opacitymedium">('.preg_replace('/[_-].*$/', '', $key).')</span>';
104  else $valuetoshow = $value.' <span class="opacitymedium">('.$key.')</span>';
105  }
106 
107  $keytouse = $key;
108  if ($mainlangonly) $keytouse = preg_replace('/[_-].*$/', '', $key);
109 
110  if ($filter && is_array($filter) && array_key_exists($keytouse, $filter)) {
111  continue;
112  }
113  if ($onlykeys && is_array($onlykeys) && !array_key_exists($keytouse, $onlykeys)) {
114  continue;
115  }
116 
117  $valuetoshow .= ' '.picto_from_langcode($key, 'class="saturatemedium"');
118  if ($selected == $keytouse) {
119  $out .= '<option value="'.$keytouse.'" selected data-html="'.dol_escape_htmltag($valuetoshow).'">'.$valuetoshow.'</option>';
120  } else {
121  $out .= '<option value="'.$keytouse.'" data-html="'.dol_escape_htmltag($valuetoshow).'">'.$valuetoshow.'</option>';
122  }
123  }
124  $out .= '</select>';
125 
126  // Make select dynamic
127  if (!$forcecombo)
128  {
129  include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
130  $out .= ajax_combobox($htmlname);
131  }
132 
133  return $out;
134  }
135 
136  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
146  public function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib = '')
147  {
148  // phpcs:enable
149  global $langs, $conf;
150 
151  // Clean parameters
152 
153 
154  // Check parameters
155  if (!is_array($dirmenuarray)) return -1;
156 
157  $menuarray = array();
158  foreach ($conf->file->dol_document_root as $dirroot)
159  {
160  foreach ($dirmenuarray as $dirtoscan)
161  {
162  $dir = $dirroot.$dirtoscan;
163  //print $dir.'<br>';
164  if (is_dir($dir))
165  {
166  $handle = opendir($dir);
167  if (is_resource($handle))
168  {
169  while (($file = readdir($handle)) !== false)
170  {
171  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
172  {
173  if (preg_match('/lib\.php$/i', $file)) continue; // We exclude library files
174  if (preg_match('/eldy_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
175  if (preg_match('/auguria_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
176  if (preg_match('/smartphone_(backoffice|frontoffice)\.php$/i', $file)) continue; // We exclude all menu manager files
177 
178  $filelib = preg_replace('/\.php$/i', '', $file);
179  $prefix = '';
180  // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
181  if (preg_match('/^eldy/i', $file)) $prefix = '0';
182  elseif (preg_match('/^smartphone/i', $file)) $prefix = '2';
183  else $prefix = '3';
184 
185  if ($file == $selected)
186  {
187  $menuarray[$prefix.'_'.$file] = '<option value="'.$file.'" selected>'.$filelib.'</option>';
188  } else {
189  $menuarray[$prefix.'_'.$file] = '<option value="'.$file.'">'.$filelib.'</option>';
190  }
191  }
192  }
193  closedir($handle);
194  }
195  }
196  }
197  }
198  ksort($menuarray);
199 
200  // Output combo list of menus
201  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
202  $oldprefix = '';
203  foreach ($menuarray as $key => $val)
204  {
205  $tab = explode('_', $key);
206  $newprefix = $tab[0];
207  if ($newprefix == '1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
208  if ($newprefix == '2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
209  if ($newprefix != $oldprefix) // Add separators
210  {
211  // Affiche titre
212  print '<option value="-1" disabled>';
213  if ($newprefix == '0') print '-- '.$langs->trans("VersionRecommanded").' --';
214  if ($newprefix == '1') print '-- '.$langs->trans("VersionExperimental").' --';
215  if ($newprefix == '2') print '-- '.$langs->trans("VersionDevelopment").' --';
216  if ($newprefix == '3') print '-- '.$langs->trans("Other").' --';
217  print '</option>';
218  $oldprefix = $newprefix;
219  }
220  print $val."\n"; // Show menu entry
221  }
222  print '</select>';
223  }
224 
225  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
234  public function select_menu_families($selected, $htmlname, $dirmenuarray)
235  {
236  // phpcs:enable
237  global $langs, $conf;
238 
239  //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
240  $expdevmenu = array();
241 
242  $menuarray = array();
243 
244  foreach ($dirmenuarray as $dirmenu)
245  {
246  foreach ($conf->file->dol_document_root as $dirroot)
247  {
248  $dir = $dirroot.$dirmenu;
249  if (is_dir($dir))
250  {
251  $handle = opendir($dir);
252  if (is_resource($handle))
253  {
254  while (($file = readdir($handle)) !== false)
255  {
256  if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
257  {
258  $filelib = preg_replace('/(_backoffice|_frontoffice)?\.php$/i', '', $file);
259  if (preg_match('/^index/i', $filelib)) continue;
260  if (preg_match('/^default/i', $filelib)) continue;
261  if (preg_match('/^empty/i', $filelib)) continue;
262  if (preg_match('/\.lib/i', $filelib)) continue;
263  if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file, $expdevmenu)) continue;
264 
265  $menuarray[$filelib] = 1;
266  }
267  $menuarray['all'] = 1;
268  }
269  closedir($handle);
270  }
271  }
272  }
273  }
274 
275  ksort($menuarray);
276 
277  // Affichage liste deroulante des menus
278  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
279  $oldprefix = '';
280  foreach ($menuarray as $key => $val)
281  {
282  $tab = explode('_', $key);
283  $newprefix = $tab[0];
284  print '<option value="'.$key.'"';
285  if ($key == $selected)
286  {
287  print ' selected';
288  }
289  print '>';
290  if ($key == 'all') print $langs->trans("AllMenus");
291  else print $key;
292  print '</option>'."\n";
293  }
294  print '</select>';
295  }
296 
297 
298  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
306  public function select_timezone($selected, $htmlname)
307  {
308  // phpcs:enable
309  global $langs, $conf;
310 
311  print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
312  print '<option value="-1">&nbsp;</option>';
313 
314  $arraytz = array(
315  "Pacific/Midway"=>"GMT-11:00",
316  "Pacific/Fakaofo"=>"GMT-10:00",
317  "America/Anchorage"=>"GMT-09:00",
318  "America/Los_Angeles"=>"GMT-08:00",
319  "America/Dawson_Creek"=>"GMT-07:00",
320  "America/Chicago"=>"GMT-06:00",
321  "America/Bogota"=>"GMT-05:00",
322  "America/Anguilla"=>"GMT-04:00",
323  "America/Araguaina"=>"GMT-03:00",
324  "America/Noronha"=>"GMT-02:00",
325  "Atlantic/Azores"=>"GMT-01:00",
326  "Africa/Abidjan"=>"GMT+00:00",
327  "Europe/Paris"=>"GMT+01:00",
328  "Europe/Helsinki"=>"GMT+02:00",
329  "Europe/Moscow"=>"GMT+03:00",
330  "Asia/Dubai"=>"GMT+04:00",
331  "Asia/Karachi"=>"GMT+05:00",
332  "Indian/Chagos"=>"GMT+06:00",
333  "Asia/Jakarta"=>"GMT+07:00",
334  "Asia/Hong_Kong"=>"GMT+08:00",
335  "Asia/Tokyo"=>"GMT+09:00",
336  "Australia/Sydney"=>"GMT+10:00",
337  "Pacific/Noumea"=>"GMT+11:00",
338  "Pacific/Auckland"=>"GMT+12:00",
339  "Pacific/Enderbury"=>"GMT+13:00"
340  );
341  foreach ($arraytz as $lib => $gmt) {
342  print '<option value="'.$lib.'"';
343  if ($selected == $lib || $selected == $gmt) print ' selected';
344  print '>'.$gmt.'</option>'."\n";
345  }
346  print '</select>';
347  }
348 
349 
350 
351  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
361  public function select_paper_format($selected = '', $htmlname = 'paperformat_id', $filter = 0, $showempty = 0)
362  {
363  // phpcs:enable
364  global $langs;
365 
366  $langs->load("dict");
367 
368  $sql = "SELECT code, label, width, height, unit";
369  $sql .= " FROM ".MAIN_DB_PREFIX."c_paper_format";
370  $sql .= " WHERE active=1";
371  if ($filter) $sql .= " AND code LIKE '%".$this->db->escape($filter)."%'";
372 
373  $resql = $this->db->query($sql);
374  if ($resql)
375  {
376  $num = $this->db->num_rows($resql);
377  $i = 0;
378  while ($i < $num)
379  {
380  $obj = $this->db->fetch_object($resql);
381  $unitKey = $langs->trans('SizeUnit'.$obj->unit);
382 
383  $paperformat[$obj->code] = $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
384 
385  $i++;
386  }
387  } else {
388  dol_print_error($this->db);
389  return '';
390  }
391  $out = '';
392 
393  $out .= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
394  if ($showempty)
395  {
396  $out .= '<option value=""';
397  if ($selected == '') $out .= ' selected';
398  $out .= '>&nbsp;</option>';
399  }
400  foreach ($paperformat as $key => $value)
401  {
402  if ($selected == $key)
403  {
404  $out .= '<option value="'.$key.'" selected>'.$value.'</option>';
405  } else {
406  $out .= '<option value="'.$key.'">'.$value.'</option>';
407  }
408  }
409  $out .= '</select>';
410 
411  return $out;
412  }
413 }
__construct($db)
Constructor.
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_timezone($selected, $htmlname)
Return a HTML select list of timezones.
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
$conf db
API class for accounts.
Definition: inc.php:54
Class to generate html code for admin pages.
select_menu_families($selected, $htmlname, $dirmenuarray)
Return combo list of available menu families.
print
Draft customers invoices.
Definition: index.php:89
select_language($selected= '', $htmlname= 'lang_id', $showauto=0, $filter=null, $showempty= '', $showwarning=0, $disabled=0, $morecss= '', $showcode=0, $forcecombo=0, $multiselect=0, $onlykeys=null, $mainlangonly=0)
Return html select list with available languages (key=&#39;en_US&#39;, value=&#39;United States&#39; for example) ...
select_menu($selected, $htmlname, $dirmenuarray, $moreattrib= '')
Return list of available menus (eldy_backoffice, ...)
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
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...