PageRenderTime 1062ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

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

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