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