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 class Calendar
00026 {
00027 var $current_date;
00028 private static $nb_day=array(31,28,31,30,31,30,31,31,30,31,30,31);
00029
00030 function __construct()
00031 {
00032
00033 $this->current_date=getdate();
00034 $this->month=$this->current_date['mon'];
00035 $this->day=self::$nb_day[$this->month-1];
00036 $this->year=$this->current_date['year'];
00037 $this->action_div=array();
00038 $this->action=array();
00039 $this->title=array();
00040
00041 if ( $this->year % 4 == 0 && $this->month=2)
00042 $this->day=29;
00043 }
00044
00045
00046
00047
00048
00049 function fill_from_action(&$p_array,$p_style)
00050 {
00051 global $g_user;
00052 $profile=$g_user->get_profile();
00053
00054 $cn=new Database(dossier::id());
00055 $sql="select ag_id,to_char(ag_remind_date,'DD')::integer as ag_timestamp_day,ag_title,ag_hour,
00056 coalesce(name,'interne') as str_name
00057 ".
00058 " from action_gestion ".
00059 " left join vw_fiche_name on (f_id=f_id_dest) ".
00060 " where ".
00061 " to_char(ag_remind_date,'MM')::integer=$1 ".
00062 " and to_char(ag_remind_date,'YYYY')::integer=$2 ".
00063 " and ag_dest in (select p_granted from user_sec_action_profile where p_id =$3)
00064 and ag_state IN (2, 3)
00065 ";
00066
00067 $array=$cn->get_array($sql,array($this->month,$this->year,$profile));
00068 for ($i=0;$i<count($array);$i++)
00069 {
00070 $ind=$array[$i]['ag_timestamp_day'];
00071 $this->action[$ind][]=$array[$i]['ag_id'];
00072 $this->title[$ind][]=$array[$i]['ag_title'];
00073 $this->hour[$ind][]=$array[$i]['ag_hour'];
00074 $this->str_name[$ind][]=$array[$i]['str_name'];
00075
00076 }
00077
00078
00079
00080 if ( $p_style == "short")
00081 {
00082 foreach ($this->action as $day=>$aAction)
00083 {
00084 if ($p_array[$day]=="") {
00085 $p_array[$day]='<span class="input_text" onclick="display_task(\'tsk'.$day.'\');">'." ".count($aAction)." "._("Tâches").'</span>';
00086 }
00087 $this->action_div[$day]='<div id="tsk'.$day.'" class="inner_box" style="width:200;display:none">';
00088 $this->action_div[$day].=HtmlInput::title_box($day."/".$this->month."/".$this->year, "tsk".$day, "hide");
00089 $this->action_div[$day].="<ol>";
00090 for ($i=0;$i<count($aAction);$i++)
00091 {
00092 $this->action_div[$day].='<li>'.HtmlInput::detail_action($aAction[$i], $this->title[$day][$i]).'</li>';
00093 }
00094 $this->action_div[$day].='</ol></div>';
00095 }
00096 }
00097 else if ( $p_style == "long")
00098 {
00099 foreach ($this->action as $day=>$aAction)
00100 {
00101 $p_array[$day].="<ol>";
00102 for ($i=0;$i<count($aAction);$i++)
00103 {
00104 $p_array[$day].='<li>'.hb($this->str_name[$day][$i]).'→'.HtmlInput::detail_action($aAction[$i], $this->hour[$day][$i]." ".$this->title[$day][$i]).'</li>';
00105 }
00106 $p_array[$day].='</ol>';
00107 }
00108 }
00109 }
00110
00111
00112
00113
00114 function fill_from_todo(&$p_array,$p_style)
00115 {
00116 $cn=new Database(dossier::id());
00117 if ($p_style=="short")
00118 {
00119 $sql="select count(*) as nb,to_char(tl_date,'DD')::integer as tl_date_day ".
00120 " from todo_list ".
00121 " where ".
00122 " to_char(tl_date,'MM')::integer=$1 ".
00123 " and to_char(tl_date,'YYYY')::integer=$2 ".
00124 " and use_login=$3 group by to_char(tl_date,'DD')::integer ";
00125 $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
00126 for ($i=0;$i<count($array);$i++)
00127 {
00128 $ind=$array[$i]['tl_date_day'];
00129 $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['nb'])." "._('Notes').'</span>';
00130 }
00131 } else if ($p_style=="long")
00132 {
00133 $sql="select to_char(tl_date,'DD')::integer as tl_date_day,tl_title ".
00134 " from todo_list ".
00135 " where ".
00136 " to_char(tl_date,'MM')::integer=$1 ".
00137 " and to_char(tl_date,'YYYY')::integer=$2 ".
00138 " and use_login=$3 ";
00139 $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION['g_user']));
00140 for ($i=0;$i<count($array);$i++)
00141 {
00142 $ind=$array[$i]['tl_date_day'];
00143
00144 $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['tl_title']).'</span>';
00145 }
00146 }
00147 }
00148
00149
00150
00151
00152
00153 function display($p_type)
00154 {
00155 global $g_user;
00156 if ($p_type != 'long' && $p_type != 'short') {
00157 throw new Exception("Calendar::display, unknow type");
00158 }
00159 $exercice_user=$g_user->get_exercice();
00160
00161 $cell=array();
00162 for ($i=0;$i<42;$i++)
00163 {
00164 $cell[$i]="";
00165 }
00166 $this->set_month_year();
00167
00168 $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
00169
00170 $this->fill_from_action($cell,$p_type);
00171 $this->fill_from_todo($cell,$p_type);
00172 $wMonth=new ISelect('per');
00173 $cn=new Database(dossier::id());
00174 $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode where p_exercice = '$exercice_user' order by p_start");
00175 $wMonth->selected=$this->default_periode;
00176 $wMonth->javascript="onchange=change_month(this)";
00177 $wMonth->set_attribute('gDossier',dossier::id());
00178 $wMonth->set_attribute('type_display',$p_type);
00179 $month_year=$wMonth->input().$wMonth->get_js_attr();
00180 ob_start();
00181 $zoom=($p_type=='short')?0:1;
00182 require_once('template/calendar.php');
00183
00184 if (count($this->action_div) > 0)
00185 {
00186 foreach ($this->action_div as $day)
00187 {
00188 echo $day;
00189 }
00190 }
00191 $ret=ob_get_contents();
00192 ob_end_clean();
00193 return $ret;
00194 }
00195
00196
00197
00198 function set_month_year()
00199 {
00200 $cn=new Database(dossier::id());
00201 $array=$cn->get_array("select to_char(p_start,'MM') as month, to_char(p_start,'YYYY') as year ".
00202 " from parm_periode where p_id=$1",array($this->default_periode));
00203 $this->month=(int)$array[0]['month'];
00204 $this->year=(int)$array[0]['year'];
00205 $this->day=self::$nb_day[$this->month-1];
00206 if ( $this->year % 4 == 0 && $this->month==2)
00207 $this->day=29;
00208 }
00209
00210
00211
00212
00213
00214 function get_preference()
00215 {
00216 global $g_user;
00217 $cn=new Database(dossier::id());
00218 $today=date('d.m.Y');
00219 $p_id=$cn->get_value("
00220 select p_id from parm_periode
00221 where
00222 p_start <= to_date($1,'DD.MM.YYYY')
00223 and
00224 p_end >= to_date($1,'DD.MM.YYYY')",
00225 array($today));
00226 if ( $p_id == '')
00227 {
00228 $p_id=$g_user->get_periode();
00229 }
00230 $this->default_periode=$p_id;
00231 return $p_id;
00232 }
00233
00234
00235
00236
00237 function set_periode($p_per)
00238 {
00239 $this->default_periode=$p_per;
00240 }
00241
00242
00243
00244 function zoom()
00245 {
00246 global $g_user;
00247 $exercice_user=$g_user->get_exercice();
00248
00249 $cell=array();
00250 for ($i=0;$i<42;$i++)
00251 {
00252 $cell[$i]="";
00253 }
00254 $this->set_month_year();
00255
00256 $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
00257
00258 $this->fill_from_action($cell,"long");
00259 $this->fill_from_todo($cell,"long");
00260 $wMonth=new ISelect('per_div');
00261 $cn=new Database(dossier::id());
00262 $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode where p_exercice = '$exercice_user' order by p_start");
00263 $wMonth->selected=$this->default_periode;
00264 $wMonth->javascript=sprintf("onchange=calendar_zoom({gDossier:%d,invalue:'%s',outvalue:'%s'})",
00265 dossier::id(),'per_div','calendar_zoom_div');
00266 $wMonth->set_attribute('gDossier',dossier::id());
00267 $month_year=$wMonth->input().$wMonth->get_js_attr();
00268 $zoom=1;
00269 ob_start();
00270 require_once('template/calendar.php');
00271
00272 if (count($this->action_div) > 0)
00273 {
00274 foreach ($this->action_div as $day)
00275 {
00276 echo $day;
00277 }
00278 }
00279 $ret=ob_get_contents();
00280 ob_end_clean();
00281 return $ret;
00282 }
00283 static function test_me() {
00284
00285 }
00286
00287 }