noalyss Version-9
calendar.class.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18*/
19
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief Display the calendar
25 */
26
27/*!
28 * \class Calendar
29 * \brief Display the calendar
30 */
32{
34 private static $nb_day=array(31,28,31,30,31,30,31,31,30,31,30,31);
35 var $month; // current month
36 var $day ; // day
37 var $year; // year
38 var $action_div; // array of action
39
40 // following are completed by fill_from_action
41 var $action; // array of event - follow-up (T: action_gestion)
42 var $str_name; // array of tiers for event - follow-up (T: action_gestion)
43 var $title; // array of title for each event - follow-up (T: action_gestion)
44 var $hour ; // array of hour for each event - follow-up (T: action_gestion)
45 var $default_periode; //default periode
46
47 function __construct()
48 {
49 /* get the current month */
50 $this->current_date=getdate();
51 $this->month=$this->current_date['mon'];
52 $this->day=self::$nb_day[$this->month-1];
53 $this->year=$this->current_date['year'];
54 $this->action_div=array();
55 $this->action=array();
56 $this->title=array();
57
58 if ( $this->year % 4 == 0 && $this->month=2)
59 $this->day=29;
60 }
61
62 /*!
63 * \brief fill the array given as parameter with the data from action_gestion
64 *\param $p_array array of the date of the month
65 * \param $p_style is either short or long, short: for a small title, long for a complete one
66 */
67 function fill_from_action(&$p_array,$p_style)
68 {
69 global $g_user;
70 $profile=$g_user->get_profile();
71
73 $sql="select ag_id,to_char(ag_remind_date,'DD')::integer as ag_timestamp_day,ag_title,ag_hour,
74 coalesce(name,'interne') as str_name
75 ".
76 " from action_gestion ".
77 " left join vw_fiche_name on (f_id=f_id_dest) ".
78 " where ".
79 " to_char(ag_remind_date,'MM')::integer=$1 ".
80 " and to_char(ag_remind_date,'YYYY')::integer=$2 ".
81 " and ag_dest in (select p_granted from user_sec_action_profile where p_id =$3)
82 and ag_state IN (2, 3)
83 ";
84
85 $array=$cn->get_array($sql,array($this->month,$this->year,$profile));
86 for ($i=0;$i<count($array);$i++)
87 {
88 $ind=$array[$i]['ag_timestamp_day'];
89 $this->action[$ind][]=$array[$i]['ag_id'];
90 $this->title[$ind][]=$array[$i]['ag_title'];
91 $this->hour[$ind][]=$array[$i]['ag_hour'];
92 $this->str_name[$ind][]=$array[$i]['str_name'];
93
94 }
95 /*
96 * Fill foreach day
97 */
98 if ( $p_style == "short")
99 {
100 foreach ($this->action as $day=>$aAction)
101 {
102 if ($p_array[$day]=="") {
103 $p_array[$day]='<span class="smallbutton" onclick="display_task(\'tsk'.$day.'\');">'." [ ".count($aAction)." ] ".'</span>';
104 }
105 $this->action_div[$day]='<div id="tsk'.$day.'" class="inner_box" style="width:200;display:none">';
106 $this->action_div[$day].=HtmlInput::title_box($day."/".$this->month."/".$this->year, "tsk".$day, "hide");
107 $this->action_div[$day].="<ol>";
108 for ($i=0;$i<count($aAction);$i++)
109 {
110 $this->action_div[$day].='<li>'.HtmlInput::detail_action($aAction[$i],
111 $this->hour[$day][$i]." ".
112 $this->str_name[$day][$i]." ".
113 $this->title[$day][$i]).'</li>';
114 }
115 $this->action_div[$day].='</ol>';
116 $this->action_div[$day].=' <p style="text-align: center">';
117 $this->action_div[$day].=HtmlInput::button_hide('tsk'.$day);
118 $this->action_div[$day].='</p>';
119 $this->action_div[$day].='</div>';
120 }
121 }
122 else if ( $p_style == "long")
123 {
124 foreach ($this->action as $day=>$aAction)
125 {
126 $p_array[$day].="<ol>";
127 for ($i=0;$i<count($aAction);$i++)
128 {
129 $p_array[$day].='<li>'.$this->hour[$day][$i]." ".hb($this->str_name[$day][$i]).'&rarr;'.HtmlInput::detail_action($aAction[$i], $this->hour[$day][$i]." ".$this->title[$day][$i]).'</li>';
130 }
131 $p_array[$day].='</ol>';
132 }
133 }
134 }
135 /*!
136 * \brief fill the array given as parameter with the data from todo
137 *\param $p_array array of the date of the month
138 * \param $p_style is either short or long, short: for a small title, long for a complete one
139 */
140 function fill_from_todo(&$p_array,$p_style)
141 {
142 $cn=Dossier::connect();
143 if ($p_style=="short")
144 {
145 $sql="select count(*) as nb,to_char(tl_date,'DD')::integer as tl_date_day ".
146 " from todo_list ".
147 " where ".
148 " to_char(tl_date,'MM')::integer=$1 ".
149 " and to_char(tl_date,'YYYY')::integer=$2 ".
150 " and use_login=$3 group by to_char(tl_date,'DD')::integer ";
151 $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION[SESSION_KEY.'g_user']));
152 for ($i=0;$i<count($array);$i++)
153 {
154 $ind=$array[$i]['tl_date_day'];
155 $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['nb'])." "._('Notes').'</span>';
156 }
157 } else if ($p_style=="long")
158 {
159 $sql="select to_char(tl_date,'DD')::integer as tl_date_day,tl_title ".
160 " from todo_list ".
161 " where ".
162 " to_char(tl_date,'MM')::integer=$1 ".
163 " and to_char(tl_date,'YYYY')::integer=$2 ".
164 " and use_login=$3 ";
165 $array=$cn->get_array($sql,array($this->month,$this->year,$_SESSION[SESSION_KEY.'g_user']));
166 for ($i=0;$i<count($array);$i++)
167 {
168 $ind=$array[$i]['tl_date_day'];
169
170 $p_array[$ind].="<span style=\"display:block\" class=\"todo\">".h($array[$i]['tl_title']).'</span>';
171 }
172 }
173 }
174 /*!
175 *\brief display a calendar after a call to Calendar::fill
176 *\param $p_type long or short
177 *
178 *\return HTML String
179 */
180 function display($p_type,$p_notitle)
181 {
182 global $g_user;
183 if ($p_type != 'long' && $p_type != 'short') {
184 throw new Exception("Calendar::display, unknow type");
185 }
186 $exercice_user=$g_user->get_exercice();
187 /* day */
188 $cell=array();
189 for ($i=0;$i<42;$i++)
190 {
191 $cell[$i]="";
192 }
193 $this->set_month_year();
194 /* weekday */
195 $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
196
197 $notitle=$p_notitle;
198
199 $this->fill_from_action($cell,$p_type);
200 $this->fill_from_todo($cell,$p_type);
201 $wMonth=new ISelect('per');
203 $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");
204 $wMonth->selected=$this->default_periode;
205 $wMonth->javascript="onchange=change_month(this)";
206 $wMonth->set_attribute('gDossier',dossier::id());
207 $wMonth->set_attribute('type_display',$p_type);
208 $wMonth->set_attribute('notitle',$notitle);
209 $month_year=$wMonth->input().$wMonth->get_js_attr();
210 ob_start();
211 $zoom=($p_type=='short')?0:1;
212
213 require_once NOALYSS_TEMPLATE.'/calendar.php';
214
215 if (count($this->action_div) > 0)
216 {
217 foreach ($this->action_div as $day)
218 {
219 echo $day;
220 }
221 }
222 $ret=ob_get_contents();
223 ob_end_clean();
224 return $ret;
225 }
226 /**
227 *@brief set correctly the month and the year with the default_periode
228 */
229 function set_month_year()
230 {
232 $array=$cn->get_array("select to_char(p_start,'MM') as month, to_char(p_start,'YYYY') as year ".
233 " from parm_periode where p_id=$1",array($this->default_periode));
234 $this->month=(int)$array[0]['month'];
235 $this->year=(int)$array[0]['year'];
236 $this->day=self::$nb_day[$this->month-1];
237 if ( $this->year % 4 == 0 && $this->month==2)
238 $this->day=29;
239 }
240 /**
241 *@brief get the periode from the preference of the current user
242 * change the value of default_periode to today
243 *@return $this->default_periode
244 */
245 function get_preference()
246 {
247 global $g_user;
249 $today=date('d.m.Y');
250 $p_id=$cn->get_value("
251 select p_id from parm_periode
252 where
253 p_start <= to_date($1,'DD.MM.YYYY')
254 and
255 p_end >= to_date($1,'DD.MM.YYYY')",
256 array($today));
257 if ( $p_id == '')
258 {
259 $p_id=$g_user->get_periode();
260 }
261 $this->default_periode=$p_id;
262 return $p_id;
263 }
264 /**
265 *@brief set the periode to the parameter, change the value of $this->default_periode
266 * there is no check on the periode
267 */
268 function set_periode($p_per)
269 {
270 $this->default_periode=$p_per;
271 }
272 /**
273 * @brief zoom the calendar
274 */
276 {
277 global $g_user;
278 $exercice_user=$g_user->get_exercice();
279 /* day */
280 $cell=array();
281 for ($i=0;$i<42;$i++)
282 {
283 $cell[$i]="";
284 }
285 $this->set_month_year();
286 /* weekday */
287 $week=array(_('Dimanche'),_('Lundi'),_('Mardi'),_('Mercredi'),_('Jeudi'),_('Vendredi'),_('Samedi'));
288
289 $this->fill_from_action($cell,"long");
290 $this->fill_from_todo($cell,"long");
291 $wMonth=new ISelect('per_div');
293 $wMonth->value=$cn->make_array("select p_id,to_char(p_start,'MM/YYYY') from parm_periode where p_exercice = $1 order by p_start"
294 ,0,array($exercice_user));
295 $wMonth->selected=$this->default_periode;
296 $wMonth->javascript=sprintf("onchange=calendar_zoom({gDossier:%d,invalue:'%s',outvalue:'%s',distype:'%s',notitle:%d})",
297 dossier::id(),'per_div','calendar_zoom_div','cal',$notitle);
298 $wMonth->set_attribute('gDossier',dossier::id());
299 $month_year=$wMonth->input().$wMonth->get_js_attr();
300 ob_start();
301 $zoom=1;
302 require_once NOALYSS_TEMPLATE.'/calendar.php';
303
304 if (count($this->action_div) > 0)
305 {
306 foreach ($this->action_div as $day)
307 {
308 echo $day;
309 }
310 }
311 $ret=ob_get_contents();
312 ob_end_clean();
313 return $ret;
314 }
315 /**
316 * Display the next events for 30 days
317 * todo list + action to remind
318 */
320 {
321 global $g_user;
323 $profile=$g_user->get_profile();
324
325 // Get the event from now and before 30 before
326 // union the TODO list
327 $sql = "
328 select ag_id,ag_remind_date,to_char(ag_remind_date,'DD.MM.YY') as str_date,ag_title,ag_hour,
329 coalesce(name,'interne') as str_name,
330 case when ag_remind_date < now() then 'R'
331 when ag_remind_date = now() then 'N'
332 else 'F'
333 end as status,
334 coalesce (ag_remind_date::date,current_date) - current_date as delta_days
335 from action_gestion
336 left join vw_fiche_name on (f_id=f_id_dest)
337 where
338 ag_dest in (select p_granted from user_sec_action_profile where p_id =$1)
339 and ag_state IN (2, 3)
340 and ag_remind_date is not null
341 order by ag_remind_date,ag_hour
342 ";
343 $a_event=$cn->get_array($sql,array($profile));
344 ob_start();
345 require_once NOALYSS_TEMPLATE.'/calendar-list.php';
346 $ret=ob_get_clean();
347 return $ret;
348
349
350 }
351
352 function zoom($p_type,$p_notitle)
353 {
354 switch ($p_type)
355 {
356 case 'cal':
357 return $this->zoom_calendar($p_notitle);
358 break;
359 case 'list':
360 return $this->zoom_list($p_notitle);
361 break;
362 }
363 }
364
365 static function test_me() {
366
367 }
368
369}
nb($p_number)
format the number for the CSV export
Definition: ac_common.php:107
global $g_user
if no group available , then stop
return false Description text align
for( $i=0; $i< $nb_row; $i++)
$anc_grandlivre from
$input_from id
Definition: balance.inc.php:63
$cal default_periode
for($i=0;$i<=6;$i++) $ind
Definition: calendar.php:34
$week
Definition: calendar.php:35
Display the calendar.
zoom_calendar($notitle)
zoom the calendar
get_preference()
get the periode from the preference of the current user change the value of default_periode to today
set_periode($p_per)
set the periode to the parameter, change the value of $this->default_periode there is no check on the...
display($p_type, $p_notitle)
display a calendar after a call to Calendar::fill
static $nb_day
fill_from_action(&$p_array, $p_style)
fill the array given as parameter with the data from action_gestion
fill_from_todo(&$p_array, $p_style)
fill the array given as parameter with the data from todo
zoom($p_type, $p_notitle)
static test_me()
set_month_year()
set correctly the month and the year with the default_periode
zoom_list($notitle)
Display the next events for 30 days todo list + action to remind.
static connect()
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
$anc_filter title
$desc width