PageRenderTime 130ms CodeModel.GetById 60ms app.highlight 39ms RepoModel.GetById 21ms app.codeStats 1ms

/htdocs/core/class/html.formother.class.php

https://github.com/asterix14/dolibarr
PHP | 729 lines | 467 code | 68 blank | 194 comment | 77 complexity | 373bf514077d8976f26803f530fedc1b MD5 | raw file
  1<?php
  2/* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3 * Copyright (C) 2004-2011 Laurent Destailleur  <eldy@users.sourceforge.net>
  4 * Copyright (C) 2004      Benoit Mortier       <benoit.mortier@opensides.be>
  5 * Copyright (C) 2004      Sebastien Di Cintio  <sdicintio@ressource-toi.org>
  6 * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
  7 * Copyright (C) 2005-2011 Regis Houssin        <regis@dolibarr.fr>
  8 * Copyright (C) 2006      Andre Cianfarani     <acianfa@free.fr>
  9 * Copyright (C) 2006      Marc Barilley/Ocebo  <marc@ocebo.com>
 10 * Copyright (C) 2007      Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
 11 * Copyright (C) 2007      Patrick Raguin 		<patrick.raguin@gmail.com>
 12 *
 13 * This program is free software; you can redistribute it and/or modify
 14 * it under the terms of the GNU General Public License as published by
 15 * the Free Software Foundation; either version 2 of the License, or
 16 * (at your option) any later version.
 17 *
 18 * This program is distributed in the hope that it will be useful,
 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 21 * GNU General Public License for more details.
 22 *
 23 * You should have received a copy of the GNU General Public License
 24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 25 */
 26
 27/**
 28 *	\file       htdocs/core/class/html.formother.class.php
 29 *  \ingroup    core
 30 *	\brief      Fichier de la classe des fonctions predefinie de composants html autre
 31 */
 32
 33
 34/**
 35 *	\class      FormOther
 36 *	\brief      Classe permettant la generation de composants html autre
 37 *	\remarks	Only common components must be here.
 38 */
 39class FormOther
 40{
 41	var $db;
 42	var $error;
 43
 44
 45	/**
 46	 *	Constructeur
 47	 *	@param     DB      Database handler
 48	 */
 49	function FormOther($DB)
 50	{
 51		$this->db = $DB;
 52
 53		return 1;
 54	}
 55
 56
 57	/**
 58     *    Return HTML select list of export models
 59	 *    @param      selected          Id modele pre-selectionne
 60	 *    @param      htmlname          Nom de la zone select
 61	 *    @param      type              Type des modeles recherches
 62	 *    @param      useempty          Affiche valeur vide dans liste
 63	 */
 64	function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
 65	{
 66		$sql = "SELECT rowid, label";
 67		$sql.= " FROM ".MAIN_DB_PREFIX."export_model";
 68		$sql.= " WHERE type = '".$type."'";
 69		$sql.= " ORDER BY rowid";
 70		$result = $this->db->query($sql);
 71		if ($result)
 72		{
 73			print '<select class="flat" name="'.$htmlname.'">';
 74			if ($useempty)
 75			{
 76				print '<option value="-1">&nbsp;</option>';
 77			}
 78
 79			$num = $this->db->num_rows($result);
 80			$i = 0;
 81			while ($i < $num)
 82			{
 83				$obj = $this->db->fetch_object($result);
 84				if ($selected == $obj->rowid)
 85				{
 86					print '<option value="'.$obj->rowid.'" selected="selected">';
 87				}
 88				else
 89				{
 90					print '<option value="'.$obj->rowid.'">';
 91				}
 92				print $obj->label;
 93				print '</option>';
 94				$i++;
 95			}
 96			print "</select>";
 97		}
 98		else {
 99			dol_print_error($this->db);
100		}
101	}
102
103
104	/**
105     *    Return list of export models
106	 *    @param      selected          Id modele pre-selectionne
107	 *    @param      htmlname          Nom de la zone select
108	 *    @param      type              Type des modeles recherches
109	 *    @param      useempty          Affiche valeur vide dans liste
110	 */
111	function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0)
112	{
113		$sql = "SELECT rowid, label";
114		$sql.= " FROM ".MAIN_DB_PREFIX."import_model";
115		$sql.= " WHERE type = '".$type."'";
116		$sql.= " ORDER BY rowid";
117		$result = $this->db->query($sql);
118		if ($result)
119		{
120			print '<select class="flat" name="'.$htmlname.'">';
121			if ($useempty)
122			{
123				print '<option value="-1">&nbsp;</option>';
124			}
125
126			$num = $this->db->num_rows($result);
127			$i = 0;
128			while ($i < $num)
129			{
130				$obj = $this->db->fetch_object($result);
131				if ($selected == $obj->rowid)
132				{
133					print '<option value="'.$obj->rowid.'" selected="selected">';
134				}
135				else
136				{
137					print '<option value="'.$obj->rowid.'">';
138				}
139				print $obj->label;
140				print '</option>';
141				$i++;
142			}
143			print "</select>";
144		}
145		else {
146			dol_print_error($this->db);
147		}
148	}
149
150
151	/**
152	 *    Retourne la liste des ecotaxes avec tooltip sur le libelle
153	 *    @param     selected    code ecotaxes pre-selectionne
154	 *    @param     htmlname    nom de la liste deroulante
155	 */
156	function select_ecotaxes($selected='',$htmlname='ecotaxe_id')
157	{
158		global $langs;
159
160		$sql = "SELECT e.rowid, e.code, e.libelle, e.price, e.organization,";
161		$sql.= " p.libelle as pays";
162		$sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_pays as p";
163		$sql.= " WHERE e.active = 1 AND e.fk_pays = p.rowid";
164		$sql.= " ORDER BY pays, e.organization ASC, e.code ASC";
165
166        $resql=$this->db->query($sql);
167		if ($resql)
168		{
169			print '<select class="flat" name="'.$htmlname.'">';
170			$num = $this->db->num_rows($resql);
171			$i = 0;
172			print '<option value="-1">&nbsp;</option>'."\n";
173			if ($num)
174			{
175				while ($i < $num)
176				{
177					$obj = $this->db->fetch_object($resql);
178					if ($selected && $selected == $obj->rowid)
179					{
180						print '<option value="'.$obj->rowid.'" selected="selected">';
181					}
182					else
183					{
184						print '<option value="'.$obj->rowid.'">';
185						//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
186					}
187					$selectOptionValue = $obj->code.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
188					print $selectOptionValue;
189					print '</option>';
190					$i++;
191				}
192			}
193			print '</select>';
194			return 0;
195		}
196		else
197		{
198			dol_print_error($this->db);
199			return 1;
200		}
201	}
202
203	/**
204	 *    Return a HTML select list to select a percent
205	 *    @param     selected      pourcentage pre-selectionne
206	 *    @param     htmlname      nom de la liste deroulante
207	 *    @param     increment     increment value
208	 *    @param     start         start value
209	 *    @param     end           end value
210	 *    @return    return        combo
211	 */
212	function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100)
213	{
214		$return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled="disabled"':'').'>';
215
216		for ($i = $start ; $i <= $end ; $i += $increment)
217		{
218			if ($selected == $i)
219			{
220				$return.= '<option value="'.$i.'" selected="selected">';
221			}
222			else
223			{
224				$return.= '<option value="'.$i.'">';
225			}
226			$return.= $i.' % ';
227			$return.= '</option>';
228		}
229
230		$return.= '</select>';
231
232		return $return;
233	}
234
235	/**
236	 *  Return select list for categories (to use in form search selectors)
237	 *	@param    	type			Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
238	 *  @param     	selected     	Preselected value
239	 *  @param     	htmlname      	Name of combo list
240	 *  @return    	return        	Html combo list code
241	 */
242	function select_categories($type,$selected=0,$htmlname='search_categ')
243	{
244		global $langs;
245	 	require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
246
247	 	// Load list of "categories"
248	 	$static_categs = new Categorie($this->db);
249	 	$tab_categs = $static_categs->get_full_arbo($type);
250
251	 	// Print a select with each of them
252	 	$moreforfilter ='<select class="flat" name="'.$htmlname.'">';
253	 	$moreforfilter.='<option value="">&nbsp;</option>';
254
255	 	if (is_array($tab_categs))
256	 	{
257	 		foreach ($tab_categs as $categ)
258	 		{
259	 			$moreforfilter.='<option value="'.$categ['id'].'"';
260	 			if ($categ['id'] == $selected) $moreforfilter.=' selected="selected"';
261	 			$moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
262	 		}
263	 	}
264	 	$moreforfilter.='</select>';
265
266		return $moreforfilter;
267	}
268
269
270	/**
271	 *  Return select list for categories (to use in form search selectors)
272	 *  @param     	selected     	Preselected value
273	 *  @param     	htmlname      	Name of combo list
274	 *  @param      user            Object user
275	 *  @return    	return        	Html combo list code
276	 */
277	function select_salesrepresentatives($selected=0,$htmlname='search_sale',$user)
278	{
279		global $conf;
280
281	 	// Select each sales and print them in a select input
282 		$moreforfilter ='<select class="flat" name="'.$htmlname.'">';
283 		$moreforfilter.='<option value="">&nbsp;</option>';
284
285 		// Get list of users allowed to be viewed
286 		$sql_usr = "SELECT u.rowid, u.name as name, u.firstname, u.login";
287 		$sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
288 		$sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
289 		if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.fk_societe = ".($user->societe_id?$user->societe_id:0);
290        // Add existing sales representatives of company
291 		if (empty($user->rights->user->user->lire) && $user->societe_id)
292 		{
293            $sql_usr.=" UNION ";
294            $sql_usr.= "SELECT u2.rowid, u2.name as name, u2.firstname, u2.login";
295            $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
296            $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
297            $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
298 		}
299        $sql_usr.= " ORDER BY name ASC";
300        //print $sql_usr;exit;
301
302        $resql_usr = $this->db->query($sql_usr);
303 		if ($resql_usr)
304 		{
305 			while ($obj_usr = $this->db->fetch_object($resql_usr))
306 			{
307 				$moreforfilter.='<option value="'.$obj_usr->rowid.'"';
308
309 				if ($obj_usr->rowid == $selected) $moreforfilter.=' selected="selected"';
310
311 				$moreforfilter.='>';
312 				$moreforfilter.=$obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
313 				$moreforfilter.='</option>';
314 				$i++;
315 			}
316 			$this->db->free($resql_usr);
317 		}
318 		else
319 		{
320 			dol_print_error($this->db);
321 		}
322 		$moreforfilter.='</select>';
323
324 		return $moreforfilter;
325	}
326
327	/**
328	 *	Return list of project and tasks
329	 *	@param     	selectedtask   	Pre-selected task
330	 *  @param      projectid       Project id
331	 * 	@param     	htmlname    	Name of html select
332	 * 	@param		modeproject		1 to restrict on projects owned by user
333	 * 	@param		modetask		1 to restrict on tasks associated to user
334	 * 	@param		mode			0=Return list of tasks and their projects, 1=Return projects and tasks if exists
335	 *  @param      useempty        0=Allow empty values
336	 */
337	function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0)
338	{
339		global $user, $langs;
340
341		require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
342
343		//print $modeproject.'-'.$modetask;
344		$task=new Task($this->db);
345		$tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
346		if ($tasksarray)
347		{
348		    print '<select class="flat" name="'.$htmlname.'">';
349			if ($useempty) print '<option value="0">&nbsp;</option>';
350			$j=0;
351			$level=0;
352			PLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid);
353			print '</select>';
354		}
355		else
356		{
357			print '<div class="warning">'.$langs->trans("NoProject").'</div>';
358		}
359	}
360
361
362	/**
363	 *		Output a HTML code to select a color
364	 *		@param	set_color		Pre-selected color
365	 *		@param	prefix			Name of HTML field
366	 *		@param	form_name		Name of form
367	 * 		@param	showcolorbox	1=Show color code and color box, 0=Show only color code
368	 * 		@param 	arrayofcolors	Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
369	 */
370	function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
371	{
372	    global $langs;
373		if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
374		{
375			$langs->load("other");
376		    print '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
377            print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
378            print '<script type="text/javascript">
379             jQuery(document).ready(function(){
380                $(\'#colorpicker'.$prefix.'\').jPicker( {
381                window: {
382                  title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
383                  effects:
384                    {
385                    type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
386                    speed:
387                    {
388                      show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
389                      hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
390                    }
391                    },
392                  position:
393                    {
394                    x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
395                    y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
396                    },
397                },
398                images: {
399                    clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
400                    picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
401          		},
402                localization: // alter these to change the text presented by the picker (e.g. different language)
403                  {
404                    text:
405                    {
406                      title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
407                      newColor: \''.dol_escape_js($langs->trans("New")).'\',
408                      currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
409                      ok: \''.dol_escape_js($langs->trans("Change")).'\',
410                      cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
411                    }
412                  }
413		        } ); });
414             </script>';
415            print '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat" type="text" value="'.$set_color.'" />';
416
417            /*
418			// No list of colors forced, we can suggest any color
419			print "\n".'<table class="nobordernopadding"><tr><td valign="middle">';
420			print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/lib/lib_colorpicker.js"></script>'."\n";
421			print '<script type="text/javascript">
422		           window.onload = function()
423		           {
424		             fctLoad();
425		           }
426		           window.onscroll = function()
427		           {
428		             fctShow();
429		           }
430		           window.onresize = function()
431		           {
432		             fctShow();
433		           }
434		         </script>'."\n";
435			print '<input type="text" size="10" name="'.$prefix.'" value="'.$set_color.'" maxlength="7" class="flat">'."\n";
436			print '</td><td valign="middle">';
437			print '<img src="'.DOL_URL_ROOT.'/theme/common/colorpicker.png" width="21" height="18" border="0" onClick="fctShow(document.'.$form_name.'.'.$prefix.');" style="cursor:pointer;">'."\n";
438			print '</td>';
439
440			if ($showcolorbox)
441			{
442				print '<td style="padding-left: 4px" nowrap="nowrap">';
443				print '<!-- Box color '.$set_color.' -->';
444				print '<table style="border-collapse: collapse; margin:0px; padding: 0px; border: 1px solid #888888; background: #'.(preg_replace('/#/','',$set_color)).';" width="12" height="10">';
445				print '<tr class="nocellnopadd"><td></td></tr>';
446				print '</table>';
447				print '</td>';
448			}
449
450			print '</tr></table>';
451			*/
452		}
453		else  // In most cases, this is not used. We used instead function with no specific list of colors
454		{
455            print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
456            print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
457		    print '<script type="text/javascript">
458             jQuery(document).ready(function(){
459                 jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
460                     size: 14,
461                     label: \'\',
462                     hide: true
463                 });
464             });
465             </script>';
466
467			print '<select id="colorpicker'.$prefix.'" class="flat" name="'.$prefix.'">';
468			//print '<option value="-1">&nbsp;</option>';
469			foreach ($arrayofcolors as $val)
470			{
471				print '<option value="'.$val.'"';
472				if ($set_color == $val) print ' selected="selected"';
473				print '>'.$val.'</option>';
474			}
475			print '</select>';
476		}
477	}
478
479	/**
480	 *		Creation d'un icone de couleur
481	 *		@param	color		Couleur de l'image
482	 *		@param	module  Nom du module
483	 *		@param	name	  Nom de l'image
484	 *		@param	x       Largeur de l'image en pixels
485	 *		@param	y       Hauteur de l'image en pixels
486	 */
487	function CreateColorIcon($color,$module,$name,$x='12',$y='12')
488	{
489		global $conf;
490
491		$file = $conf->$module->dir_temp.'/'.$name.'.png';
492
493		// On cree le repertoire contenant les icones
494		if (! file_exists($conf->$module->dir_temp))
495		{
496			create_exdir($conf->$module->dir_temp);
497		}
498
499		// On cree l'image en vraies couleurs
500		$image = imagecreatetruecolor($x,$y);
501
502		$color = substr($color,1,6);
503
504		$rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
505		$vert  = hexdec(substr($color,2,2)); //conversion du canal vert
506		$bleu  = hexdec(substr($color,4,2)); //conversion du canal bleu
507
508		$couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
509		//print $rouge.$vert.$bleu;
510		imagefill($image,0,0,$couleur); //on remplit l'image
511		// On cree la couleur et on l'attribue a une variable pour ne pas la perdre
512		ImagePng($image,$file); //renvoie une image sous format png
513		ImageDestroy($image);
514	}
515
516    /**
517     *    	Return HTML combo list of week
518     *    	@param      selected          Preselected value
519     *    	@param      htmlname          Nom de la zone select
520     *    	@param      useempty          Affiche valeur vide dans liste
521     */
522    function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
523    {
524        global $langs;
525
526        $week = array(	0=>$langs->trans("Day0"),
527        1=>$langs->trans("Day1"),
528        2=>$langs->trans("Day2"),
529        3=>$langs->trans("Day3"),
530        4=>$langs->trans("Day4"),
531        5=>$langs->trans("Day5"),
532        6=>$langs->trans("Day6"));
533
534        $select_week = '<select class="flat" name="'.$htmlname.'">';
535        if ($useempty)
536        {
537            $select_week .= '<option value="-1">&nbsp;</option>';
538        }
539        foreach ($week as $key => $val)
540        {
541            if ($selected == $key)
542            {
543                $select_week .= '<option value="'.$key.'" selected="selected">';
544            }
545            else
546            {
547                $select_week .= '<option value="'.$key.'">';
548            }
549            $select_week .= $val;
550        }
551        $select_week .= '</select>';
552        return $select_week;
553    }
554
555    /**
556     *    	Return HTML combo list of month
557     *    	@param      selected          Preselected value
558     *    	@param      htmlname          Nom de la zone select
559     *    	@param      useempty          Affiche valeur vide dans liste
560     */
561    function select_month($selected='',$htmlname='monthid',$useempty=0)
562    {
563        require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
564
565        $month = monthArrayOrSelected(-1);	// Get array
566
567        $select_month = '<select class="flat" name="'.$htmlname.'">';
568        if ($useempty)
569        {
570            $select_month .= '<option value="0">&nbsp;</option>';
571        }
572        foreach ($month as $key => $val)
573        {
574            if ($selected == $key)
575            {
576                $select_month .= '<option value="'.$key.'" selected="selected">';
577            }
578            else
579            {
580                $select_month .= '<option value="'.$key.'">';
581            }
582            $select_month .= $val;
583        }
584        $select_month .= '</select>';
585        return $select_month;
586    }
587
588    /**
589     *    	Return HTML combo list of years
590     *      @param      selected          Preselected value (''=current year, -1=none, year otherwise)
591     *    	@param      htmlname          Name of HTML select object
592     *    	@param      useempty          Affiche valeur vide dans liste
593     *    	@param      $min_year         Offset of minimum year into list (by default current year -10)
594     *    	@param      $max_year         Offset of maximum year into list (by default current year + 5)
595     */
596	function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
597    {
598    	print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option);
599    }
600
601    /**
602     *    	Return HTML combo list of years
603     *      @param      selected          Preselected value (''=current year, -1=none, year otherwise)
604     *    	@param      htmlname          Name of HTML select object
605     *    	@param      useempty          Affiche valeur vide dans liste
606     *    	@param      $min_year         Offset of minimum year into list (by default current year -10)
607     *    	@param      $max_year         Offset of maximum year into list (by default current year + 5)
608     */
609	function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
610    {
611    	$out='';
612
613        $currentyear = date("Y")+$offset;
614    	$max_year = $currentyear+$max_year;
615        $min_year = $currentyear-$min_year;
616        if(empty($selected)) $selected = $currentyear;
617
618        $out.= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
619        if($useempty)
620        {
621            if ($selected == '') $selected_html = ' selected="selected"';
622            $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
623        }
624        if (! $invert)
625        {
626	        for ($y = $max_year; $y >= $min_year; $y--)
627	        {
628	            $selected_html='';
629	            if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
630	            $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
631	        }
632        }
633        else
634        {
635        	for ($y = $min_year; $y <= $max_year; $y++)
636	        {
637	            $selected_html='';
638	            if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
639	            $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
640	        }
641        }
642        $out.= "</select>\n";
643
644        return $out;
645    }
646
647}
648
649
650/**
651 * Write all lines of a project (if parent = 0)
652 * @param 	$inc
653 * @param 	$parent
654 * @param 	$lines
655 * @param 	$level
656 * @param 	$selectedtask
657 * @param 	$selectedproject
658 */
659function PLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0)
660{
661	global $langs, $user, $conf;
662
663	$lastprojectid=0;
664
665	$numlines=count($lines);
666	for ($i = 0 ; $i < $numlines ; $i++)
667	{
668		if ($lines[$i]->fk_parent == $parent)
669		{
670			$var = !$var;
671
672			// Break on a new project
673			if ($parent == 0)
674			{
675				if ($lines[$i]->fk_project != $lastprojectid)
676				{
677					if ($i > 0 && $conf->browser->firefox) print '<option value="0" disabled="disabled">----------</option>';
678					print '<option value="'.$lines[$i]->fk_project.'_0"';
679					if ($selectedproject == $lines[$i]->fk_project) print ' selected="selected"';
680					print '>';	// Project -> Task
681					print $langs->trans("Project").' '.$lines[$i]->projectref;
682					if (empty($lines[$i]->public))
683					{
684						print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
685					}
686					else
687					{
688						print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
689					}
690					//print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
691					print "</option>\n";
692
693					$lastprojectid=$lines[$i]->fk_project;
694					$inc++;
695				}
696			}
697
698			// Print task
699			if ($lines[$i]->id > 0)
700			{
701				print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
702				if ($lines[$i]->id == $selectedtask) print ' selected="selected"';
703				print '>';
704				print $langs->trans("Project").' '.$lines[$i]->projectref;
705				if (empty($lines[$i]->public))
706				{
707					print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
708				}
709				else
710				{
711					print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
712				}
713				if ($lines[$i]->id) print ' > ';
714				for ($k = 0 ; $k < $level ; $k++)
715				{
716					print "&nbsp;&nbsp;&nbsp;";
717				}
718				print $lines[$i]->label."</option>\n";
719				$inc++;
720			}
721
722			$level++;
723			if ($lines[$i]->id) PLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject);
724			$level--;
725		}
726	}
727}
728
729?>