html.formadmin.class.php 13 KB

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