Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 require_once('class_html_input.php');
00035 class IPeriod extends HtmlInput
00036 {
00037 var $type;
00038 var $cn;
00039 var $show_end_date;
00040 var $show_start_date;
00041 var $filter_year;
00042 var $user;
00043 function __construct($p_name="",$p_value="",$p_exercice='')
00044 {
00045 $this->name=$p_name;
00046 $this->readOnly=false;
00047 $this->size=20;
00048 $this->width=50;
00049 $this->heigh=20;
00050 $this->value=$p_value;
00051 $this->selected="";
00052 $this->table=0;
00053 $this->disabled=false;
00054 $this->javascript="";
00055 $this->extra2="all";
00056 $this->show_start_date=true;
00057 $this->show_end_date=true;
00058 $this->exercice=$p_exercice;
00059 }
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 public function input($p_name=null,$p_value=null)
00070 {
00071 foreach (array('type','cn') as $a)
00072 {
00073 if ( ! isset ($this->$a) ) throw new Exception('Variable non définie [ '.$a.']');
00074 }
00075 $this->name=($p_name==null)?$this->name:$p_name;
00076 $this->value=($p_value==null)?$this->value:$p_value;
00077 if ( $this->readOnly==true) return $this->display();
00078
00079 switch ($this->type)
00080 {
00081 case CLOSED:
00082 $sql_closed="where p_closed=true and p_central = false ";
00083 break;
00084 case OPEN:
00085 $sql_closed="where p_closed=false";
00086 break;
00087 case NOTCENTRALIZED:
00088 $sql_closed="where p_closed=true and p_central = false ";
00089 break;
00090 case ALL:
00091 $sql_closed="";
00092 break;
00093 default:
00094 throw new Exception("invalide p_type in ".__FILE__.':'.__LINE__);
00095 }
00096 $sql="select p_id,to_char(p_start,'DD.MM.YYYY') as p_start_string,
00097 to_char(p_end,'DD.MM.YYYY') as p_end_string
00098 from parm_periode
00099 $sql_closed ";
00100
00101 $cond="";
00102
00103
00104
00105 if ( ! isset($this->filter_year) || (isset($this->filter_year) && $this->filter_year==true))
00106 {
00107 if ( $this->exercice=='')
00108 {
00109 if (! isset($this->user) ) throw new Exception (__FILE__.':'.__LINE__.' user is not set');
00110 $this->exercice=$this->user->get_exercice();
00111 }
00112
00113 $cond='';
00114 if ( $sql_closed=="") $and=" where " ; else $and=" and ";
00115 if ($this->type == 'all' ) $cond=$and.' true ';
00116 $cond.=" $and p_exercice='".sql_string($this->exercice)."'";
00117 }
00118
00119 $sql.=$cond." order by p_start,p_end";
00120
00121 $Res=$this->cn->exec_sql($sql);
00122 $Max=$this->cn->size($Res);
00123 if ( $Max == 0 ) throw new Exception(_('Aucune periode trouvée'),1);
00124 $ret='<SELECT NAME="'.$this->name.'" '.$this->javascript.'>';
00125 for ( $i = 0; $i < $Max;$i++)
00126 {
00127 $l_line=$this->cn->fetch($i);
00128 if ( $this->value==$l_line['p_id'] )
00129 $sel="SELECTED";
00130 else
00131 $sel="";
00132
00133 if ( $this->show_start_date == true && $this->show_end_date==true )
00134 {
00135 $ret.=sprintf('<OPTION VALUE="%s" %s>%s - %s',$l_line['p_id']
00136 ,$sel
00137 ,$l_line['p_start_string']
00138 ,$l_line['p_end_string']);
00139 }
00140 else if ($this->show_start_date == true )
00141 {
00142 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
00143 ,$sel
00144 ,$l_line['p_start_string']
00145 );
00146 }
00147 else if ( $this->show_end_date == true )
00148 {
00149 $ret.=sprintf('<OPTION VALUE="%s" %s>%s ',$l_line['p_id']
00150 ,$sel
00151 ,$l_line['p_end_string']
00152 );
00153 }
00154
00155 }
00156 $ret.="</SELECT>";
00157 return $ret;
00158
00159
00160 }
00161
00162 public function display()
00163 {
00164 $r="not implemented ".__FILE__.":".__LINE__;
00165 return $r;
00166
00167 }
00168 static public function test_me()
00169 {
00170 }
00171 }