PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/class/html.formadmin.class.php

https://bitbucket.org/speedealing/speedealing
PHP | 375 lines | 254 code | 38 blank | 83 comment | 74 complexity | 913e540f818500bc6ab2ecc575ad06e2 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2013 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. /**
  20. * \file htdocs/core/class/html.formadmin.class.php
  21. * \ingroup core
  22. * \brief File of class for html functions for admin pages
  23. */
  24. /**
  25. * Class to generate html code for admin pages
  26. */
  27. class FormAdmin
  28. {
  29. var $db;
  30. var $error;
  31. /**
  32. * Constructor
  33. *
  34. * @param DoliDB $db Database handler
  35. */
  36. function __construct($db = '')
  37. {
  38. $this->db = $db;
  39. return 1;
  40. }
  41. /**
  42. * Return html select list with available languages (key='en_US', value='United States' for example)
  43. *
  44. * @param string $selected Langue pre-selectionnee
  45. * @param string $htmlname Nom de la zone select
  46. * @param int $showauto Affiche choix auto
  47. * @param array $filter Array of keys to exclude in list
  48. * @param int $showempty Add empty value
  49. * @param int $showwarning Show a warning if language is not complete
  50. * @return string Return HTML select string with list of languages
  51. */
  52. function select_language($selected='',$htmlname='lang_id',$showauto=0,$filter=0,$showempty=0,$showwarning=0)
  53. {
  54. global $langs;
  55. $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12);
  56. $out='';
  57. $out.= '<select class="select" id="'.$htmlname.'" name="'.$htmlname.'">';
  58. if ($showempty)
  59. {
  60. $out.= '<option value=""';
  61. if ($selected == '') $out.= ' selected="selected"';
  62. $out.= '>&nbsp;</option>';
  63. }
  64. if ($showauto)
  65. {
  66. $out.= '<option value="auto"';
  67. if ($selected == 'auto') $out.= ' selected="selected"';
  68. $out.= '>'.$langs->trans("AutoDetectLang").'</option>';
  69. }
  70. asort($langs_available);
  71. $uncompletelanguages=array('da_DA','fi_FI','hu_HU','is_IS','pl_PL','ro_RO','ru_RU','sv_SV','tr_TR','zh_CN');
  72. foreach ($langs_available as $key => $value)
  73. {
  74. if ($showwarning && in_array($key,$uncompletelanguages))
  75. {
  76. //$value.=' - '.$langs->trans("TranslationUncomplete",$key);
  77. }
  78. if ($filter && is_array($filter))
  79. {
  80. if ( ! array_key_exists($key, $filter))
  81. {
  82. $out.= '<option value="'.$key.'">'.$value.'</option>';
  83. }
  84. }
  85. else if ($selected == $key)
  86. {
  87. $out.= '<option value="'.$key.'" selected="selected">'.$value.'</option>';
  88. }
  89. else
  90. {
  91. $out.= '<option value="'.$key.'">'.$value.'</option>';
  92. }
  93. }
  94. $out.= '</select>';
  95. return $out;
  96. }
  97. /**
  98. * Return list of available menus (eldy_backoffice, ...)
  99. *
  100. * @param string $selected Preselected menu value
  101. * @param string $htmlname Name of html select
  102. * @param array $dirmenuarray Array of directories to scan
  103. * @param string $moreattrib More attributes on html select tag
  104. * @return void
  105. */
  106. function select_menu($selected, $htmlname, $dirmenuarray, $moreattrib='')
  107. {
  108. global $langs,$conf;
  109. // Clean parameters
  110. if ($selected == 'eldy.php') $selected='eldy_backoffice.php'; // For compatibility
  111. // Check parameters
  112. if (! is_array($dirmenuarray)) return -1;
  113. $menuarray=array();
  114. foreach ($conf->file->dol_document_root as $dirroot)
  115. {
  116. foreach($dirmenuarray as $dirtoscan)
  117. {
  118. $dir=$dirroot.$dirtoscan;
  119. //print $dir.'<br>';
  120. if (is_dir($dir))
  121. {
  122. $handle=opendir($dir);
  123. if (is_resource($handle))
  124. {
  125. while (($file = readdir($handle))!==false)
  126. {
  127. if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && substr($file, 0, 5) != 'index')
  128. {
  129. if (preg_match('/lib\.php$/i',$file)) continue; // We exclude library files
  130. $filelib=preg_replace('/\.php$/i','',$file);
  131. $prefix='';
  132. // 0=Recommanded, 1=Experimental, 2=Developpement, 3=Other
  133. if (preg_match('/^eldy/i',$file)) $prefix='0';
  134. else if (preg_match('/^smartphone/i',$file)) $prefix='2';
  135. else $prefix='3';
  136. if ($file == $selected)
  137. {
  138. $menuarray[$prefix.'_'.$file]='<option value="'.$file.'" selected="selected">'.$filelib.'</option>';
  139. }
  140. else
  141. {
  142. $menuarray[$prefix.'_'.$file]='<option value="'.$file.'">'.$filelib.'</option>';
  143. }
  144. }
  145. }
  146. closedir($handle);
  147. }
  148. }
  149. }
  150. }
  151. ksort($menuarray);
  152. // Output combo list of menus
  153. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
  154. $oldprefix='';
  155. foreach ($menuarray as $key => $val)
  156. {
  157. $tab=explode('_',$key);
  158. $newprefix=$tab[0];
  159. if ($newprefix=='1' && ($conf->global->MAIN_FEATURES_LEVEL < 1)) continue;
  160. if ($newprefix=='2' && ($conf->global->MAIN_FEATURES_LEVEL < 2)) continue;
  161. if (! empty($conf->browser->firefox) && $newprefix != $oldprefix) // Add separators
  162. {
  163. // Affiche titre
  164. print '<option value="-1" disabled="disabled">';
  165. if ($newprefix=='0') print '-- '.$langs->trans("VersionRecommanded").' --';
  166. if ($newprefix=='1') print '-- '.$langs->trans("VersionExperimental").' --';
  167. if ($newprefix=='2') print '-- '.$langs->trans("VersionDevelopment").' --';
  168. if ($newprefix=='3') print '-- '.$langs->trans("Other").' --';
  169. print '</option>';
  170. $oldprefix=$newprefix;
  171. }
  172. print $val."\n"; // Show menu entry
  173. }
  174. print '</select>';
  175. }
  176. /**
  177. * Return combo list of available menu families
  178. *
  179. * @param string $selected Menu pre-selected
  180. * @param string $htmlname Name of html select
  181. * @param string $dirmenuarray Directories to scan
  182. * @return void
  183. */
  184. function select_menu_families($selected, $htmlname, $dirmenuarray)
  185. {
  186. global $langs,$conf;
  187. //$expdevmenu=array('smartphone_backoffice.php','smartphone_frontoffice.php'); // Menu to disable if $conf->global->MAIN_FEATURES_LEVEL is not set
  188. $expdevmenu=array();
  189. $menuarray=array();
  190. foreach($dirmenuarray as $dirmenu)
  191. {
  192. foreach ($conf->file->dol_document_root as $dirroot)
  193. {
  194. $dir=$dirroot.$dirmenu;
  195. if (is_dir($dir))
  196. {
  197. $handle=opendir($dir);
  198. if (is_resource($handle))
  199. {
  200. while (($file = readdir($handle))!==false)
  201. {
  202. if (is_file($dir."/".$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
  203. {
  204. $filelib=preg_replace('/(_backoffice|_frontoffice)?\.php$/i','',$file);
  205. if (preg_match('/^index/i',$filelib)) continue;
  206. if (preg_match('/^default/i',$filelib)) continue;
  207. if (preg_match('/^empty/i',$filelib)) continue;
  208. if (preg_match('/\.lib/i',$filelib)) continue;
  209. if (empty($conf->global->MAIN_FEATURES_LEVEL) && in_array($file,$expdevmenu)) continue;
  210. $menuarray[$filelib]=1;
  211. }
  212. $menuarray['all']=1;
  213. }
  214. closedir($handle);
  215. }
  216. }
  217. }
  218. }
  219. ksort($menuarray);
  220. // Affichage liste deroulante des menus
  221. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  222. $oldprefix='';
  223. foreach ($menuarray as $key => $val)
  224. {
  225. $tab=explode('_',$key);
  226. $newprefix=$tab[0];
  227. print '<option value="'.$key.'"';
  228. if ($key == $selected)
  229. {
  230. print ' selected="selected"';
  231. }
  232. print '>';
  233. if ($key == 'all') print $langs->trans("AllMenus");
  234. else print $key;
  235. print '</option>'."\n";
  236. }
  237. print '</select>';
  238. }
  239. /**
  240. * Return a HTML select list of timezones
  241. *
  242. * @param string $selected Menu pre-selectionnee
  243. * @param string $htmlname Nom de la zone select
  244. * @return void
  245. */
  246. function select_timezone($selected,$htmlname)
  247. {
  248. global $langs,$conf;
  249. print '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  250. print '<option value="-1">&nbsp;</option>';
  251. $arraytz=array(
  252. "Pacific/Midway"=>"GMT-11:00",
  253. "Pacific/Fakaofo"=>"GMT-10:00",
  254. "America/Anchorage"=>"GMT-09:00",
  255. "America/Los_Angeles"=>"GMT-08:00",
  256. "America/Dawson_Creek"=>"GMT-07:00",
  257. "America/Chicago"=>"GMT-06:00",
  258. "America/Bogota"=>"GMT-05:00",
  259. "America/Anguilla"=>"GMT-04:00",
  260. "America/Araguaina"=>"GMT-03:00",
  261. "America/Noronha"=>"GMT-02:00",
  262. "Atlantic/Azores"=>"GMT-01:00",
  263. "Africa/Abidjan"=>"GMT+00:00",
  264. "Europe/Paris"=>"GMT+01:00",
  265. "Europe/Helsinki"=>"GMT+02:00",
  266. "Europe/Moscow"=>"GMT+03:00",
  267. "Asia/Dubai"=>"GMT+04:00",
  268. "Asia/Karachi"=>"GMT+05:00",
  269. "Indian/Chagos"=>"GMT+06:00",
  270. "Asia/Jakarta"=>"GMT+07:00",
  271. "Asia/Hong_Kong"=>"GMT+08:00",
  272. "Asia/Tokyo"=>"GMT+09:00",
  273. "Australia/Sydney"=>"GMT+10:00",
  274. "Pacific/Noumea"=>"GMT+11:00",
  275. "Pacific/Auckland"=>"GMT+12:00",
  276. "Pacific/Enderbury"=>"GMT+13:00"
  277. );
  278. foreach ($arraytz as $lib => $gmt)
  279. {
  280. print '<option value="'.$lib.'"';
  281. if ($selected == $lib || $selected == $gmt) print ' selected="selected"';
  282. print '>'.$gmt.'</option>'."\n";
  283. }
  284. print '</select>';
  285. }
  286. /**
  287. * Return html select list with available languages (key='en_US', value='United States' for example)
  288. *
  289. * @param string $selected Paper format pre-selected
  290. * @param string $htmlname Name of HTML select field
  291. * @param string $filter Key to filter
  292. * @param int $showempty Add empty value
  293. * @return string Return HTML output
  294. */
  295. function select_paper_format($selected='',$htmlname='paperformat_id',$filter=0,$showempty=0)
  296. {
  297. global $langs;
  298. $sql="SELECT code, label, width, height, unit FROM ".MAIN_DB_PREFIX."c_paper_format where active=1";
  299. if ($filter) $sql.=" WHERE code LIKE '%".$filter."%'";
  300. $resql=$this->db->query($sql);
  301. if ($resql)
  302. {
  303. $num=$this->db->num_rows($resql);
  304. $i=0;
  305. while ($i < $num)
  306. {
  307. $obj=$this->db->fetch_object($resql);
  308. $unitKey = $langs->trans('SizeUnit'.$obj->unit);
  309. $paperformat[$obj->code]= $langs->trans('PaperFormat'.strtoupper($obj->code)).' - '.round($obj->width).'x'.round($obj->height).' '.($unitKey == 'SizeUnit'.$obj->unit ? $obj->unit : $unitKey);
  310. $i++;
  311. }
  312. }
  313. else dol_print_error($this->db);
  314. $out='';
  315. $out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">';
  316. if ($showempty)
  317. {
  318. $out.= '<option value=""';
  319. if ($selected == '') $out.= ' selected="selected"';
  320. $out.= '>&nbsp;</option>';
  321. }
  322. foreach ($paperformat as $key => $value)
  323. {
  324. if ($selected == $key)
  325. {
  326. $out.= '<option value="'.$key.'" selected="selected">'.$value.'</option>';
  327. }
  328. else
  329. {
  330. $out.= '<option value="'.$key.'">'.$value.'</option>';
  331. }
  332. }
  333. $out.= '</select>';
  334. return $out;
  335. }
  336. }
  337. ?>