source: trunk/calendar/inc/class.uicalendar.inc.php @ 1447

Revision 1447, 180.8 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #599 - Funcionalidade de mapa de disponibilidade.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Calendar                                                    *
4  * http://www.eGroupWare.org                                                *
5  * Maintained and further developed by RalfBecker@outdoor-training.de       *
6  * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net>               *
7  *          http://www.radix.net/~cknudsen                                  *
8  * Originaly modified by Mark Peters <skeeter@phpgroupware.org>             *
9  * --------------------------------------------                             *
10  *  This program is free software; you can redistribute it and/or modify it *
11  *  under the terms of the GNU General Public License as published by the   *
12  *  Free Software Foundation; either version 2 of the License, or (at your  *
13  *  option) any later version.                                              *
14  \**************************************************************************/
15
16
17        class uicalendar
18        {
19                var $template;
20                var $template_dir;
21
22                var $bo;
23                var $cat;
24
25                var $holidays;
26                var $holiday_color;
27
28                var $debug = False;
29                //var $debug = True;
30
31                var $cat_id;
32                var $theme;
33                var $link_tpl;
34
35                // planner related variables
36                var $planner_header;
37                var $planner_rows;
38
39                var $planner_group_members;
40
41                var $planner_firstday;
42                var $planner_lastday;
43                var $planner_days;
44
45                var $planner_end_month;
46                var $planner_end_year;
47                var $planner_days_in_end_month;
48
49                var $planner_intervals = array( // conversation hour and interval depending on intervals_per_day
50                                        //                                  1 1 1 1 1 1 1 1 1 1 2 2 2 2
51                                        //              0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
52                                                '1' => array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), // 0=0-23h
53                                                '2' => array(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0), // 0=0-12h, 1=12-23h
54                                                '3' => array(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,2), // 0=0-12h, 2=12-18h, 3=18-23h
55                                                '4' => array(0,0,0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,3,3)  // 0=0-7, 7-12h, 3=12-18h, 4=18-23h
56                                        );
57
58                var $public_functions = array(
59                        'mini_calendar' => True,
60                        'index' => True,
61                        'month' => True,
62                        'get_month' => True,
63                        'week'  => True,
64                        'get_week' => True,
65                        'year' => True,
66                        'view' => True,
67                        'edit' => True,
68                        'export'        => True,
69                        'export_all' => True,
70                        'reinstate_list'        => True,
71                        'reinstate'     => True,
72                        'add'  => True,
73                        'delete' => True,
74                        'preferences' => True,
75                        'day' => True,
76                        'edit_status' => True,
77                        'set_action' => True,
78                        'planner' => True,
79                        'modify_ext_partlist' => True,
80                        'matrixselect'  => True,
81                        'viewmatrix'    => True,
82                        'search' => True,
83                        'header' => True,
84                        'footer' => True,
85                        'css'           => True,
86                        'accounts_popup' => True,
87                        'disponibility' => True
88                );
89
90                function uicalendar()
91                {
92                        $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
93                        $GLOBALS['phpgw']->browser    = CreateObject('phpgwapi.browser');
94
95                        $this->theme = $GLOBALS['phpgw_info']['theme'];
96
97                        $this->bo = CreateObject('calendar.bocalendar',1);
98                        $this->cat = &$this->bo->cat;
99
100                        print_debug('BO Owner',$this->bo->owner);
101
102                        $this->template = $GLOBALS['phpgw']->template;
103                        $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir('calendar');
104
105                        $this->holiday_color = (substr($this->theme['bg06'],0,1)=='#'?'':'#').$this->theme['bg06'];
106
107                        $this->cat_id   = $this->bo->cat_id;
108
109                        $this->link_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
110                        $this->link_tpl->set_unknowns('remove');
111                        $this->link_tpl->set_file(
112                                Array(
113                                        'link_picture'  => 'link_pict.tpl'
114                                )
115                        );
116                        $this->link_tpl->set_block('link_picture','link_pict','link_pict');
117                        $this->link_tpl->set_block('link_picture','pict','pict');
118                        $this->link_tpl->set_block('link_picture','link_open','link_open');
119                        $this->link_tpl->set_block('link_picture','link_close','link_close');
120                        $this->link_tpl->set_block('link_picture','link_text','link_text');
121                       
122                        /*************** EVENTO **************************/
123/* Este bloco de codigo foi adicionado pois os eventos de agendamento (exibicao do mes) para impressao serao tratados em outro template
124(event_link.tpl) */
125
126                        $this->event_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
127                        $this->event_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
128                        $this->event_tpl->set_unknowns('remove');
129                        $this->event_tpl->set_file(
130                                Array(
131                                        'link_event'    => 'event_link.tpl'
132                                )
133                        );
134                        $this->event_tpl->set_block('link_event','link_event_pict','link_event_pict');
135                        $this->event_tpl->set_block('link_event','event_pict','event_pict');
136                        $this->event_tpl->set_block('link_event','link_event_open','link_event_open');
137                        $this->event_tpl->set_block('link_event','link_event_close','link_event_close');
138                        $this->event_tpl->set_block('link_event','link_event_text','link_event_text');
139
140
141/*************************************************/
142
143                        if($this->bo->use_session)
144                        {
145                                // save return-fkt for add, view, ...
146                                list(,,$fkt) = explode('.',$_GET['menuaction']);
147                                if ($fkt == 'day' || $fkt == 'week' || $fkt == 'month' || $fkt == 'year' || $fkt == 'planner')
148                                {
149                                        $this->bo->return_to = $_GET['menuaction'].
150                                                sprintf('&date=%04d%02d%02d',$this->bo->year,$this->bo->month,$this->bo->day);
151                                }
152                                $this->bo->save_sessiondata();
153                        }
154                        $this->always_app_header = $this->bo->prefs['common']['template_set'] == 'idots';
155
156                        print_debug('UI',$this->_debug_sqsof());
157
158                        if (!is_object($GLOBALS['phpgw']->html))
159                        {
160                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
161                        }
162                        $this->html = &$GLOBALS['phpgw']->html;
163                }
164
165                /* Public functions */
166
167                function mini_calendar($params)
168                {
169                        static $mini_cal_tpl;
170                        if(!is_array($params))
171                        {
172                                return;
173                        }
174
175                        if($params['month'] == 0)
176                        {
177                                $params['month'] = 12;
178                                $params['year'] = $params['year'] - 1;
179                        }
180                        elseif($params['month'] == 13)
181                        {
182                                $params['month'] = 1;
183                                $params['year'] = $params['year'] + 1;
184                        }
185
186                        $this->bo->store_to_cache(
187                                Array(
188                                        'smonth'        => $params['month'],
189                                        'sday'  => 1,
190                                        'syear' => $params['year']
191                                )
192                        );
193
194                        $params['link']                 = (!isset($params['link'])?'':$params['link']);
195                        $params['buttons']              = (!isset($params['buttons'])?'none':$params['buttons']);
196                        $params['outside_month']        = (!isset($params['outside_month'])?True:$params['outside_month']);
197
198                        $this->bo->read_holidays($params['year']);
199
200                        $date = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$params['month'],$params['day'],$params['year']);
201                        $month_ago = (int)(date('Ymd',mktime(0,0,0,$params['month'] - 1,$params['day'],$params['year'])));
202                        $month_ahead = (int)(date('Ymd',mktime(0,0,0,$params['month'] + 1,$params['day'],$params['year'])));
203                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$params['month'],1,$params['year'])));
204                        $monthend = (int)(date('Ymd',mktime(0,0,0,$params['month'] + 1,0,$params['year'])));
205
206                        $weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($params['year'],$params['month'],1);
207
208                        print_debug('mini_calendar:monthstart',$monthstart);
209                        print_debug('mini_calendar:weekstarttime',date('Ymd H:i:s',$weekstarttime));
210
211                        if(!is_object($mini_cal_tpl))
212                        {
213                                $mini_cal_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
214                                $mini_cal_tpl->set_unknowns('remove');
215                                $mini_cal_tpl->set_file(
216                                        Array(
217                                                'mini_calendar' => 'mini_cal.tpl'
218                                        )
219                                );
220                                $mini_cal_tpl->set_block('mini_calendar','mini_cal','mini_cal');
221                                $mini_cal_tpl->set_block('mini_calendar','mini_week','mini_week');
222                                $mini_cal_tpl->set_block('mini_calendar','mini_day','mini_day');
223                        }
224
225
226                        if($this->bo->printer_friendly == False)
227                        {
228//NDEE                          $month = '<a href="' . $this->page('month','&month='.$GLOBALS['phpgw']->common->show_date($date['raw'],'m').'&year='.$GLOBALS['phpgw']->common->show_date($date['raw'],'Y')). '" class="_minicalendar">' . lang($GLOBALS['phpgw']->common->show_date($date['raw'],'F')).' '.$GLOBALS['phpgw']->common->show_date($date['raw'],'Y').'</a>';
229                                $month = '<a href="' . $this->page('month','&month='.$GLOBALS['phpgw']->common->show_date($date['raw'],'m').'&year='.$GLOBALS['phpgw']->common->show_date($date['raw'],'Y')). '">' . lang($GLOBALS['phpgw']->common->show_date($date['raw'],'F')).' '.$GLOBALS['phpgw']->common->show_date($date['raw'],'Y').'</a>';
230                        }
231                        else
232                        {
233                                $month = lang($GLOBALS['phpgw']->common->show_date($date['raw'],'F')).' '.$GLOBALS['phpgw']->common->show_date($date['raw'],'Y');
234                        }
235
236                        $var = Array(
237                                'cal_img_root'          =>      $GLOBALS['phpgw']->common->image('calendar','mini-calendar-bar'),
238                                'bgcolor'                       =>      $this->theme['bg_color'],
239                                'bgcolor1'                      =>      $this->theme['bg_color'],
240                                'month'                         =>      $month,
241                                'bgcolor2'                      =>      $this->theme['cal_dayview'],
242                                'holiday_color' => $this->holiday_color
243                        );
244
245                        $mini_cal_tpl->set_var($var);
246
247                        switch(strtolower($params['buttons']))
248                        {
249                                case 'right':
250                                        $var = Array(
251                                                'nextmonth'                     =>      '<a href="'.$this->page('month','&date='.$month_ahead).'"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','right').'" border="0"></a>'
252                                        );
253                                        break;
254                                case 'left':
255                                        $var = Array(
256                                                'prevmonth'                     =>      '<a href="'.$this->page('month','&date='.$month_ago).'"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','left').'" border="0"></a>'
257                                        );
258                                        break;
259                                case 'both':
260                                        $var = Array(
261                                                'prevmonth'                     =>      '<a href="'.$this->page('month','&date='.$month_ago).'"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','left').'" border="0"></a>',
262                                                'nextmonth'                     =>      '<a href="'.$this->page('month','&date='.$month_ahead).'"><img src="'.$GLOBALS['phpgw']->common->image('phpgwapi','right').'" border="0"></a>'
263                                        );
264                                        break;
265                                case 'none':
266                                default:
267                                        $var = Array(
268                                                'prevmonth'                     =>      '',
269                                                'nextmonth'                     =>      ''
270                                        );
271                                        break;
272                        }
273                        $mini_cal_tpl->set_var($var);
274
275                        if(!$mini_cal_tpl->get_var('daynames'))
276                        {
277                                for($i=0;$i<7;$i++)
278                                {
279                                        $var = Array(
280                                                'dayname'       => '<b>' . lang($GLOBALS['phpgw']->datetime->days_short[$i]) . '</b>',
281                                                'day_image'     => ''
282                                        );
283                                        $this->output_template_array($mini_cal_tpl,'daynames','mini_day',$var);
284                                }
285                        }
286                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
287                        unset($date);
288                        for($i=$weekstarttime + $GLOBALS['phpgw']->datetime->tz_offset;date('Ymd',$i)<=$monthend;$i += (24 * 3600 * 7))
289                        {
290                                unset($var);
291                                $daily = $this->set_week_array($i - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
292                                foreach($daily as $date => $day_params)
293                                {
294                                        print_debug('Mini-Cal Date',$date);
295                                        $year = (int)(substr($date,0,4));
296                                        $month = (int)(substr($date,4,2));
297                                        $day = (int)(substr($date,6,2));
298                                        $str = '';
299                                        if(($date >= $monthstart && $date <= $monthend) || $params['outside_month'] == True)
300                                        {
301                                                if(!$this->bo->printer_friendly && $params['link'])
302                                                {
303//NDEE: class def what for?
304                                                        $str = '<a href="'.$this->page($params['link'],'&date='.$date).'" class="'.$day_params['class'].'">'.$day.'</a>';
305                                                }
306                                                else
307                                                {
308
309//NDEE: printer-friendly (mini-calendar)
310                                                        $str = $day;
311                                                }
312
313                                        }
314                                        else
315                                        {
316                                                $day_params['day_image'] = '';
317                                        }
318                                        $var[] = Array(
319                                                'day_image'     => $day_params['day_image'],
320                                                'dayname'       => $str
321                                        );
322                                }
323                                for($l=0;$l<count($var);$l++)
324                                {
325                                        $this->output_template_array($mini_cal_tpl,'monthweek_day','mini_day',$var[$l]);
326                                }
327                                $mini_cal_tpl->parse('display_monthweek','mini_week',True);
328                                $mini_cal_tpl->set_var('dayname','');
329                                $mini_cal_tpl->set_var('monthweek_day','');
330                        }
331
332                        $return_value = $mini_cal_tpl->fp('out','mini_cal');
333                        $mini_cal_tpl->set_var('display_monthweek','');
334//                      $mini_cal_tpl->set_var('daynames','');
335//                      unset($p);
336                        return $return_value;
337                }
338
339                function index($params='')
340                {
341                        if (!$params)
342                        {
343                                foreach(array('date','year','month','day') as $field)
344                                {
345                                        if (isset($_GET[$field]))
346                                        {
347                                                $params[$field] = $_GET[$field];
348                                        }
349                                }
350                        }
351                        $GLOBALS['phpgw']->redirect($this->page('',$params));
352                       
353                }
354
355
356
357// NDEE: printer-friendly
358
359                function printer_friendly($body,$app_header='')
360                {
361                        $_SESSION['calendar']['categories'] = $this->cat->formated_list('select','all',$this->bo->cat_id,'True');
362                        if((!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && count($this->bo->grants) > 0)
363                                $_SESSION['calendar']['cals'] = $this->bo->list_cals();
364
365                        if($this->bo->printer_friendly || $_GET['plain'] == 'True')
366                        {       
367                                $new_body = '<html>'."\n"
368                                        .'<head>'."\n"
369                                        .'<LINK href="'.$GLOBALS['phpgw_info']['server']['webserver_url'].'/calendar/templates/'.$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set'].'/app.css" type=text/css rel=StyleSheet>'."\n"
370                                        .'<LINK href="'.$GLOBALS['phpgw_info']['server']['webserver_url'].'/calendar/templates/'.$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set'].'/app_print.css" type=text/css rel=StyleSheet media="print">'."\n"
371                                        .'</head>
372                                        <table id="calendar_print_main" class="calendar_print_main">                                           
373                                                <tr>
374                                                        <td id="calendar_print_content" class="calendar_print_content">'.$body.'</td>
375                                                </tr>
376                                                <tr>
377                                                  <td>
378                                                        <div>
379                                                                <input class=button type="button" onClick="javascript:this.style.visibility=\'hidden\';window.print();window.close();" value="Imprimir esta p&aacute;gina">
380                                                        </div>
381                                                   </td>
382                                                 </tr>
383                                        </table></body>'."\n"
384                                        .'</html>'."\n";
385                                //$new_body = utf8_decode($new_body);
386                        }
387                        else
388                        {
389                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
390                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
391                                unset($GLOBALS['phpgw_info']['flags']['noappheader']);
392                                unset($GLOBALS['phpgw_info']['flags']['noappfooter']);
393                                if ($app_header && $this->always_app_header)
394                                {
395                                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.$app_header;
396                                }
397                               
398                                $GLOBALS['phpgw']->common->phpgw_header();
399                                $new_body = $this->bo->debug_string.$body;                             
400                               
401                        }
402                        return $new_body;
403                }
404
405                function month()
406                {
407                        echo $this->printer_friendly($this->get_month(),lang('Monthview'));
408                        $GLOBALS['phpgw']->common->phpgw_footer();
409                }
410
411                function get_month()
412                {
413                        $m = mktime(0,0,0,$this->bo->month,1,$this->bo->year);
414
415                        $next = $this->bo->month + 1;
416                        $prev = $this->bo->month - 1;
417                        $nextyear = $this->bo->year;
418                        $prevyear = $this->bo->year;
419                        if ($this->bo->month == 12)
420                        {
421                                $next = 1;
422                                $nextyear = $nextyear + 1;
423                        }
424                        elseif ($this->bo->month == 1)
425                        {
426                                $prev = 12;
427                                $prevyear = $prevyear - 1;
428                        }
429
430                        if (isset($this->bo->prefs['calendar']['display_minicals']) && $this->bo->prefs['calendar']['display_minicals'] == "1" && !$this->bo->printer_friendly)
431                        {
432                                $minical_prev = $this->mini_calendar(
433                                        Array(
434                                                'day'   => 1,
435                                                'month' => $this->bo->month - 1,
436                                                'year'  => $this->bo->year,
437                                                'link'  => 'day',
438                                                'outside_month' => False
439                                        )
440                                );
441
442                                $minical_next = $this->mini_calendar(
443                                        Array(
444                                                'day'   => 1,
445                                                'month' => $this->bo->month + 1,
446                                                'year'  => $this->bo->year,
447                                                'link'  => 'day',
448                                                'outside_month' => False
449                                        )
450                                );
451                        }
452                        else
453                        {
454                                $minical_prev = '';
455                                $minical_next = '';
456                        }
457
458                        if($_POST['year']) {                   
459       
460                        }
461                       
462                        $hoje = date('Ymd',$GLOBALS['phpgw']->datetime->gmtnow);
463                        $mes_hoje = (int)substr($hoje,4,2);
464                        $sday = 1;
465                        if($_POST['day']) {
466                                $day_ini = (int)$_POST['day'];
467                        }
468                        elseif($_GET['sday']){
469                                if($_GET['month'] == $mes_hoje)
470                                {
471                                        $day_ini = $this->bo->day;
472                                }
473                               
474                                else
475                                {
476                                        $day_ini = (int)$_GET['sday'];
477                                }
478                        }
479                        elseif( ($_POST['dia_ini']) && ($_POST['dia_ini'] == $this->bo->day) )
480                        {
481                                $day_ini = (int)substr($hoje,6,2);
482                        }
483                        else
484                        {
485                                $day_ini = $this->bo->day;
486                        }
487                        if($_POST['qtd_dias'])
488                        {
489                                $num_dias = (int)$_POST['qtd_dias'];
490                        }
491                        else
492                        {
493                                $num_dias = 0;
494                        }
495
496                        if (!$this->bo->printer_friendly)
497                        {
498                                $printer = '';
499                                $prev_month_link = '<a href="'.$this->page('month','&year='.$prevyear.'&month='.$prev.'&sday='.$sday).'">&lt;&lt;</a>';
500                                $next_month_link = '<a href="'.$this->page('month','&year='.$nextyear.'&month='.$next.'&sday='.$sday).'">&gt;&gt;</a>';
501                                $param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&friendly=1'.'&day_ini='.$day_ini.'&num_dias='.$num_dias;
502                                //$param = '&year='.$this->bo->year.'&month='.$this->bo->month.'&friendly=1';
503                                $print = "<a href='javascript:void(0)' onClick=\"javascript:window.open('".$this->page('month'.$param).
504                                                "','','width=600,height=600,toolbar=no,scrollbars=yes,resizable=no');\" onMouseOver=\"window.status = '".
505                                                lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
506                                //linha abaixo foi adicionada para exibir a pagina do mes em tela
507                                $large_month = $this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner);                           
508                        }
509                        else
510                        {
511                                $printer = '<body bgcolor="'.$phpgw_info['theme']['bg_color'].'">';
512                                $prev_month_link = '';
513                                $next_month_link = '';
514                                $print =        '';
515                                $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
516                                //linha abaixo foi adicionada para exibir a pagina do mes para impressao
517                                $large_month = $this->display_month_print($this->bo->month,$this->bo->year,True,$this->bo->owner);
518                        }
519
520                        $this->bo->read_holidays();
521
522                        $var = Array(
523                                'printer_friendly'              =>      $printer,
524                                'bg_text'                                       => $this->theme['bg_text'],
525                                'small_calendar_prev'   =>      $minical_prev,
526                                'prev_month_link'               =>      $prev_month_link,
527                                'month_identifier'              =>      lang(strftime("%B",$m)).' '.$this->bo->year,
528                                'username'                                      =>      $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner),
529                                'next_month_link'               =>      $next_month_link,
530                                'small_calendar_next'   =>      $minical_next,
531                                //'large_month'                         =>      $this->display_month($this->bo->month,$this->bo->year,True,$this->bo->owner),
532                                'large_month'           =>      $large_month,
533                                'print'                                         =>      $print
534                        );
535
536                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
537                        $p->set_unknowns('remove');
538                        // Alteracao que desvincula o template para tela do template de impressao do mes (month_print teve que ser criado);
539                        if($print != '')
540                        {
541                                $p->set_file(
542                                        Array(
543                                                'index_t'       =>      'index.tpl'
544                                        )
545                                );
546                        }else {
547                                $p->set_file(
548                                        Array(
549                                                'index_t'       =>      'month_print.tpl'
550                                        )
551                                );
552                        }
553                        $p->set_var($var);
554                        return $p->fp('out','index_t');
555                }
556
557                function week()
558                {
559                        echo $this->printer_friendly($this->get_week(),lang('Weekview'));
560                        $GLOBALS['phpgw']->common->phpgw_footer();
561                }
562
563                function get_week()
564                {
565                        $this->bo->read_holidays();
566
567                        $next = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day + 7,$this->bo->year);
568                        $prev = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day - 7,$this->bo->year);
569
570                        if (isset($this->bo->prefs['calendar']['display_minicals']) && $this->bo->prefs['calendar']['display_minicals'] == "1" && !$this->bo->printer_friendly)
571                        {
572                                $minical_this = $this->mini_calendar(
573                                        Array(
574                                                'day'   => $this->bo->day,
575                                                'month' => $this->bo->month,
576                                                'year'  => $this->bo->year,
577                                                'link'  => 'day',
578                                                'butons'        => 'none',
579                                                'outside_month' => False
580                                        )
581                                );
582                                $minical_prev = $this->mini_calendar(
583                                        Array(
584                                                'day'   => $this->bo->day,
585                                                'month' => $this->bo->month - 1,
586                                                'year'  => $this->bo->year,
587                                                'link'  => 'day',
588                                                'butons'        => 'left',
589                                                'outside_month' => False
590                                        )
591                                );
592                                $minical_next = $this->mini_calendar(
593                                        Array(
594                                                'day'   => $this->bo->day,
595                                                'month' => $this->bo->month + 1,
596                                                'year'  => $this->bo->year,
597                                                'link'  => 'day',
598                                                'butons'        => 'right',
599                                                'outside_month' => False
600                                        )
601                                );
602                        }
603                        else
604                        {
605
606//NDEE: printer-friendly what?
607                                $minical_this = '';
608                                $minical_prev = '';
609                                $minical_next = '';
610                        }
611
612                        if (!$this->bo->printer_friendly)
613                        {
614                                $printer = '';
615                                $prev_week_link = '<a href="'.$this->page('week','&date='.$prev['full']).'">&lt;&lt;</a>';
616                                $next_week_link = '<a href="'.$this->page('week','&date='.$next['full']).'">&gt;&gt;</a>';
617                                $print = '<a href="'.$this->page('week','&friendly=1&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day))."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window.status = '".lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
618                        }
619                        else
620                        {
621
622//NDEE: printer-friendly (weekly-view)
623                                $printer = '<body bgcolor="'.$this->theme['bg_color'].'">';
624                                $prev_week_link = '';
625                                $next_week_link = '';
626                                $print =        '';
627                                $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
628                        }
629
630                        $var = Array(
631                                'printer_friendly'      =>      $print,
632                                'bg_text'               => $this->theme['bg_text'],
633                                'small_calendar_prev'   =>      $minical_prev,
634                                'prev_week_link'        =>      $prev_week_link,
635                                'small_calendar_this'   =>      $minical_this,
636                                'week_identifier'       =>      $this->bo->get_week_label(),
637                                'next_week_link'        =>      $next_week_link,
638                                'username'              =>      $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner),
639                                'small_calendar_next'   =>      $minical_next,
640                                'week_display'          =>      $this->display_weekly(
641                                        Array(
642                                                'date'          => sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day),
643                                                'showyear'      => true,
644                                                'owners'        => $this->bo->owner
645                                        )
646                                ),
647                                'print'                 =>      $print
648                        );
649//todo
650                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
651                        $p->set_file(
652                                Array(
653                                        'week_t' => 'week.tpl'
654                                )
655                        );
656                        $p->set_var($var);
657                        return $p->fp('out','week_t');
658
659                }
660
661                function year()
662                {
663                        if ($_GET['plain'] == "True")
664                        {
665
666                                echo $this->printer_friendly($this->get_year(),lang('Yearview'));
667                        }
668                        else
669                        {
670
671                                if($this->bo->printer_friendly)
672                                {
673                                        $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
674                                }
675                                echo $this->printer_friendly($this->get_year(),lang('Yearview'));
676                                $GLOBALS['phpgw']->common->phpgw_footer();
677                        }
678                }
679
680                function get_year()
681                {
682                        if(!$this->bo->printer_friendly)
683                        {
684                                $print = '';
685                                $left_link = '<a href="'.$this->page('year','&year='.($this->bo->year - 1)).'">&lt;&lt;</a>';
686                                $right_link = '<a href="'.$this->page('year','&year='.($this->bo->year + 1)).'">&gt;&gt;</a>';
687                                $link = 'day';
688                                $printer = '<a href="'.$this->page('year','&friendly=1&year='.$this->bo->year).'" target="cal_printer_friendly" onMouseOver="window.status = '."'".lang('Generate printer-friendly version')."'".'">['.lang('Printer Friendly').']</a>';
689                        }
690                        else
691                        {
692//NDEE: printer-friendly (year-view)
693                                $print = '<body bgcolor="'.$this->theme['bg_color'].'">';
694                                $left_link = '';
695                                $right_link = '';
696                                $link = '';
697                                $printer = '';
698                        }
699
700                        $var = Array(
701                                'print'         => $print,
702                                'left_link' => $left_link,
703                                'font'          => $this->theme['font'],
704                                'year_text' => $this->bo->year,
705                                'right_link'=> $right_link,
706                                'printer_friendly'=> $printer
707                        );
708
709                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
710                        $p->set_file(
711                                Array(
712                                        'year_t' => 'year.tpl'
713                                )
714                        );
715                        $p->set_block('year_t','year','year');
716                        $p->set_block('year_t','month','month_handle');
717                        $p->set_block('year_t','month_sep','month_sep_handle');
718                        $p->set_var($var);
719
720                        for($i=1;$i<=12;$i++)
721                        {
722                                if(($i % 3) == 1)
723                                {
724                                        $p->parse('row','month_sep',True);
725                                }
726                                $p->set_var('mini_month',$this->mini_calendar(
727                                                Array(
728                                                        'day'   => 1,
729                                                        'month' => $i,
730                                                        'year'  => $this->bo->year,
731                                                        'link'  => $link,
732                                                        'buttons'       => 'none',
733                                                        'outside_month' => False
734                                                )
735                                        )
736                                );
737                                $p->parse('row','month',True);
738                                $p->set_var('mini_month','');
739                        }
740                        return $p->fp('out','year_t');
741                }
742
743                function view($vcal_id=0,$cal_date=0)
744                {
745                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
746                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
747                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('View');
748                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
749                        $GLOBALS['phpgw']->common->phpgw_header();
750
751                        $cal_id = get_var('cal_id',array('GET','POST'),$vcal_id);
752
753                        $date = $cal_date ? $cal_date : 0;
754                        $date = $date ? $date : (int)$_GET['date'];
755       
756                        // First, make sure they have permission to this entry
757                        if ($cal_id < 1)
758                        {
759                                echo '<center>'.lang('Invalid entry id.').'</center>'."\n";
760                                $GLOBALS['phpgw']->common->phpgw_exit(True);
761                        }
762
763                        if(!$this->bo->check_perms(PHPGW_ACL_READ,$cal_id))
764                        {
765                                echo '<center>'.lang('You do not have permission to read this record!').'</center>'."\n";
766                                $GLOBALS['phpgw']->common->phpgw_exit(True);
767                        }
768                       
769                        $event = $this->bo->read_entry($cal_id);
770
771                        if(!isset($event['id']))
772                        {
773                                echo '<center>'.lang('Sorry, this event does not exist').'.'.'</center>'."\n";
774                                $GLOBALS['phpgw']->common->phpgw_exit(True);
775                        }
776
777                        $this->bo->repeating_events = Array();
778                        $this->bo->cached_events = Array();
779                        $this->bo->repeating_events[0] = $event;
780                        $datetime = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
781                        $this->bo->check_repeating_events($datetime);
782                        $check_date = $GLOBALS['phpgw']->common->show_date($datetime,'Ymd');
783                        if(is_array($this->bo->cached_events[$check_date][0]) &&
784                                $this->bo->cached_events[$check_date][0]['id'] == $event['id'])
785                        {
786                                $starttime = $this->bo->maketime($event['start']);
787                                $endtime = $this->bo->maketime($event['end']);
788                                $event['start']['month'] = $this->bo->month;
789                                $event['start']['mday'] = $this->bo->day;
790                                $event['start']['year'] = $this->bo->year;
791                                $temp_end =  $this->bo->maketime($event['start']) + ($endtime - $starttime);
792                                $event['end']['month'] = date('m',$temp_end);
793                                $event['end']['mday'] = date('d',$temp_end);
794                                $event['end']['year'] = date('Y',$temp_end);
795                        }
796
797                        if(!$this->view_event($event,True))
798                        {
799                                echo '<center>'.lang('You do not have permission to read this record!').'</center>';
800                                $GLOBALS['phpgw']->common->phpgw_exit(True);
801                        }
802                                               
803                        $p = $GLOBALS['phpgw']->template;
804                        $p->set_file(
805                                Array(
806                                        'form_button'   => 'form_button_script.tpl'
807                                )
808                        );
809
810                        $button_left = $button_center = $button_right = '';
811
812                        if($this->bo->check_perms(PHPGW_ACL_EDIT,$event))
813                        {
814                                if($event['recur_type'] != MCAL_RECUR_NONE)
815                                {
816                                        $var = Array(
817                                                'action_url_button'     => $this->page('edit','&cal_id='.$cal_id),
818                                                'action_text_button'    => lang('Edit Single'),
819                                                'action_confirm_button' => '',
820                                                'action_extra_field'    => $this->html->input_hidden(array(
821                                                        'edit_type' => 'single',
822                                                        'date' => sprintf('%04d%02d%02d',$this->bo->year,$this->bo->month,$this->bo->day)
823                                                ))
824                                        );
825                                        $p->set_var($var);
826                                        $button_left .= '<td>'.$p->fp('button','form_button').'</td>';
827
828                                        $var = Array(
829                                                'action_url_button'     => $this->page('edit','&cal_id='.$cal_id),
830                                                'action_text_button'    => lang('Edit Series'),
831                                                'action_confirm_button' => '',
832                                                'action_extra_field'    => $this->html->input_hidden('edit_type','series')
833                                        );
834                                        $p->set_var($var);
835                                        $button_left .= '<td>'.$p->fp('button','form_button').'</td>';
836                                }
837                                else
838                                {
839                                        $var = Array(
840                                                'action_url_button'     => $this->page('edit','&cal_id='.$cal_id),
841                                                'action_text_button'    => lang('Edit'),
842                                                'action_confirm_button' => '',
843                                                'action_extra_field'    => ''
844                                        );
845                                        $p->set_var($var);
846                                        $button_left .= '<td>'.$p->fp('button','form_button').'</td>';
847                                }
848
849                                $var = Array(
850                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uialarm.manager'),
851                                        'action_text_button'    => lang('Alarm Management'),
852                                        'action_confirm_button' => '',
853                                        'action_extra_field'    => $this->html->input_hidden(array(
854                                                'cal_id' => $cal_id,
855                                                'return_to' => $this->bo->return_to
856                                        ))
857                                );
858                                $p->set_var($var);
859                                $button_center .= '<td>'.$p->fp('button','form_button').'</td>';
860                        }
861
862                        if ($this->bo->check_perms(PHPGW_ACL_DELETE,$event))
863                        {
864                                if($event['recur_type'] != MCAL_RECUR_NONE)
865                                {
866                                        $var = Array(
867                                                'action_url_button'     => $this->page('delete','&cal_id='.$cal_id),
868                                                'action_text_button'    => lang('Delete Single'),
869                                                'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this single occurence?\\nThis will delete this entry for all users.')."')\"",
870                                                'action_extra_field'    => $this->html->input_hidden(array(
871                                                        'delete_type' => 'single',
872                                                        'date' => sprintf('%04d%02d%02d',$this->bo->year,$this->bo->month,$this->bo->day)
873                                                ))
874                                        );
875                                        $p->set_var($var);
876                                        $button_right .= '<td>'.$p->fp('button','form_button').'</td>';
877
878                                        $var = Array(
879                                                'action_url_button'     => $this->page('delete','&cal_id='.$cal_id),
880                                                'action_text_button'    => lang('Delete Series'),
881                                                'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"",
882                                                'action_extra_field'    => $this->html->input_hidden('delete_type','series')
883                                        );
884                                        $p->set_var($var);
885                                        $button_right .= '<td>'.$p->fp('button','form_button').'</td>';
886
887                                        if($event['recur_exception'])
888                                        {
889                                                $var = Array(
890                                                        'action_url_button'     => $this->page('reinstate_list','&cal_id='.$cal_id),
891                                                        'action_text_button'    => lang('Reinstate'),
892                                                        'action_confirm_button' => '',
893                                                        'action_extra_field'    => ''
894                                                );
895                                                $p->set_var($var);
896                                                $button_center .= '<td>'.$p->fp('button','form_button').'</td>';
897                                        }
898                                }
899                                else
900                                {
901                                        $var = Array(
902                                                'action_url_button'     => $this->page('delete','&cal_id='.$cal_id),
903                                                'action_text_button'    => lang('Delete'),
904                                                'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"",
905                                                'action_extra_field'    => ''
906                                        );
907                                        $p->set_var($var);
908                                        $button_right .= '<td>'.$p->fp('button','form_button').'</td>';
909                                }
910                        }
911                        else
912                        {
913                                // allow me (who I am logged in as) to set up an alarm
914                                // if I am a participant, but not the owner
915                                reset($event['participants']);
916                                while (list($user,$short_status) = each($event['participants']))
917                                {
918                                        if ($GLOBALS['phpgw_info']['user']['account_id'] == $user)
919                                        {
920                                                $var = Array(
921                                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uialarm.manager'),
922                                                        'action_text_button'    => lang('Alarm Management'),
923                                                        'action_confirm_button' => '',
924                                                        'action_extra_field'    => $this->html->input_hidden(array(
925                                                                'cal_id'    => $cal_id,
926                                                                'return_to' => $this->bo->return_to
927                                                        ))
928                                                );
929                                                $p->set_var($var);
930                                                echo $p->fp('out','form_button');
931                                        }
932                                }
933                        }
934
935                        $var = Array(
936                                'action_url_button'     => $this->page('export'),
937                                'action_text_button'    => lang('Export'),
938                                'action_confirm_button' => '',
939                                'action_extra_field'    => $this->html->input_hidden('cal_id',$cal_id)
940                        );
941                        $p->set_var($var);
942                        $button_center .= '<td>'.$p->fp('button','form_button').'</td>';
943
944                        if ($this->bo->return_to)
945                        {
946                                $var = Array(
947                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
948                                        'action_text_button'    => lang('Done'),
949                                        'action_confirm_button' => '',
950                                        'action_extra_field'    => ''
951                                );
952                                $p->set_var($var);
953                                $button_left .= '<td>'.$p->fp('button','form_button').'</td>';
954                        }
955                        $p->set_var(array(
956                                'button_left'   => $button_left,
957                                'button_center' => $button_center,
958                                'button_right'  => $button_right
959                        ));
960                        $p->pfp('phpgw_body','view_event');
961
962                        $GLOBALS['phpgw']->hooks->process(array(
963                                'location' => 'calendar_view',
964                                'cal_id'   => $cal_id
965                        ));
966                       
967                        $GLOBALS['phpgw']->common->phpgw_footer();
968                }
969
970                function edit($params='')
971                {
972                        if($this->debug)
973                        {
974                                echo '<!-- params[readsess] = '.$params['readsess'].' -->'."\n";
975                                echo '<!-- params[cd] = '.$params['cd'].' -->'."\n";
976                        }
977
978                        if(isset($_GET['readsess']))
979                        {
980                                $params['readsess'] = $_GET['readsess'];
981                                $params['cd'] = 0;
982                        }
983
984                        if($this->debug)
985                        {
986                                echo '<!-- params[readsess] = '.$params['readsess'].' -->'."\n";
987                                echo '<!-- params[cd] = '.$params['cd'].' -->'."\n";
988                        }
989
990                        if($params != '' && @is_array($params) && @isset($params['readsess']))
991                        {
992                                $can_edit = True;
993                                $this->edit_form(
994                                        Array(
995                                                'event' => $this->bo->restore_from_appsession(),
996                                                'cd' => $params['cd']
997                                        )
998                                );
999                        }
1000                        elseif(isset($_GET['cal_id']))
1001                        {
1002                                $cal_id = (int)$_GET['cal_id'];
1003                                $event = $this->bo->read_entry($cal_id);
1004
1005                                if(!$this->bo->check_perms(PHPGW_ACL_EDIT,$event))
1006                                {
1007                                        Header('Location: '.$this->page('view','&cal_id='.$cal_id));
1008                                        $GLOBALS['phpgw']->common->phpgw_exit();
1009                                }
1010                                if(@isset($_POST['edit_type']) && $_POST['edit_type'] == 'single')
1011                                {
1012                                        $event['id'] = 0;
1013                                        $this->bo->set_recur_date($event,$_POST['date']);
1014                                        $event['recur_type'] = MCAL_RECUR_NONE;
1015                                        $event['recur_interval'] = 0;
1016                                        $event['recur_data'] = 0;
1017                                        $event['recur_enddate']['month'] = 0;
1018                                        $event['recur_enddate']['mday'] = 0;
1019                                        $event['recur_enddate']['year'] = 0;
1020                                        $event['recur_exception'] = array();
1021                                }
1022                                $plain = $_GET['plain'];
1023
1024                                $this->edit_form(
1025                                        Array(
1026                                                'event' => $event,
1027                                                'cd'    => $cd,
1028                                                'plain' => $plain
1029                                        )
1030                                );
1031                        }
1032                }
1033
1034                function export_all()
1035                {
1036                        $temp_path = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
1037                        srand((double)microtime()*1000000);
1038                        $random_number = rand(100000000,999999999);
1039                        $newfilename = md5(time() . getenv("REMOTE_ADDR") . $random_number );
1040                        $filename = $temp_path . $newfilename;
1041                        $attach_fd = fopen($filename,"w+");
1042                        $event_ids = $this->bo->search_keywords($_POST['keywords']);
1043                        foreach($event_ids as $key => $id)
1044                        {
1045                                $event[$key]=$this->bo->read_entry($id);
1046                        }
1047                        include_once('class.bocalendar.inc.php');
1048                        $cal = new bocalendar;
1049                        $tmpattach=$cal->create_vcard($event);
1050                        fwrite($attach_fd,$tmpattach);
1051                        header ("Content-Type: text/plain");
1052                        header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
1053                        header('Content-Length: ' . filesize($filename));
1054                        header("Content-disposition: attachment; filename="."export.vcard");
1055                        readfile($filename);
1056                        fclose($attach_fd);
1057                }
1058
1059                function export($vcal_id=0)
1060                {
1061                        $temp_path = $GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
1062                        srand((double)microtime()*1000000);
1063                        $random_number = rand(100000000,999999999);
1064                        $newfilename = md5(time() . getenv("REMOTE_ADDR") . $random_number );
1065                        $filename = $temp_path . $newfilename;
1066                        $attach_fd = fopen($filename,"w+");
1067                        $cal_id = get_var('cal_id',array('GET','POST'),$vcal_id);
1068                        $event[0] = $this->bo->read_entry($cal_id);
1069                        include_once('class.bocalendar.inc.php');
1070                        $cal = new bocalendar;
1071                        $tmpattach=$cal->create_vcard($event);
1072                        fwrite($attach_fd,$tmpattach);
1073                        header ("Content-Type: text/plain");
1074                        header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
1075                        header('Content-Length: ' . filesize($filename));
1076                        header("Content-disposition: attachment; filename="."export.vcard");
1077                        readfile($filename);
1078                        fclose($attach_fd);
1079                }
1080
1081                function reinstate_list($params='')
1082                {
1083                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1084                        {
1085                                $this->no_edit();
1086                        }
1087                        elseif(!$this->bo->check_perms(PHPGW_ACL_ADD))
1088                        {
1089                                $this->index();
1090                        }
1091
1092                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
1093                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1094                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Reinstate');
1095                        $GLOBALS['phpgw']->common->phpgw_header();
1096
1097                        $cal_id = get_var('cal_id',array('GET'),$params['cal_id']);
1098
1099                        if ($cal_id < 1)
1100                        {
1101                                echo '<center>'.lang('Invalid entry id.').'</center>'."\n";
1102                                $GLOBALS['phpgw']->common->phpgw_exit(True);
1103                        }
1104
1105                        if(!$this->bo->check_perms(PHPGW_ACL_READ))
1106                        {
1107                                echo '<center>'.lang('You do not have permission to read this record!').'</center>'."\n";
1108                                $GLOBALS['phpgw']->common->phpgw_exit(True);
1109                        }
1110
1111                        $event = $this->bo->read_entry($cal_id);
1112
1113                        if(!isset($event['id']))
1114                        {
1115                                echo '<center>'.lang('Sorry, this event does not exist').'.'.'</center>'."\n";
1116                                $GLOBALS['phpgw']->common->phpgw_exit(True);
1117                        }
1118                        elseif(!isset($event['recur_exception']))
1119                        {
1120                                echo '<center>'.lang('Sorry, this event does not have exceptions defined').'.'.'</center>'."\n";
1121                                $GLOBALS['phpgw']->common->phpgw_exit(True);
1122                        }
1123
1124                        if(!$this->view_event($event,True))
1125                        {
1126                                echo '<center>'.lang('You do not have permission to read this record!').'</center>';
1127                                $GLOBALS['phpgw']->common->phpgw_exit(True);
1128                        }
1129
1130                        $p = &$GLOBALS['phpgw']->template;
1131                        $p->set_file(
1132                                Array(
1133                                        'form_button'   => 'form_button_script.tpl'
1134                                )
1135                        );
1136
1137                        $str = '';
1138
1139                        for($i=0;$i<count($event['recur_exception']);$i++)
1140                        {
1141                                $str .= '    <option value="'.$i.'">'.$GLOBALS['phpgw']->common->show_date($event['recur_exception'][$i]).'</option>'."\n";
1142                        }
1143                        $this->output_template_array($p,'row','list',array(
1144                                'field' => lang('Exceptions'),
1145                                'data'  => '<select name="reinstate_index[]" multiple size="5">'."\n".$str.'</select>'
1146                        ));
1147
1148                        $var = Array(
1149                                'action_url_button'     => $this->page('reinstate','&cal_id='.$cal_id),
1150                                'action_text_button'    => lang('Reinstate'),
1151                                'action_confirm_button' => '',
1152                                'action_extra_field'    => ''
1153                        );
1154                        $p->set_var($var);
1155                        $button_left = '<td>'.$p->fp('out','form_button').'</td>';
1156
1157                        $var = Array(
1158                                'action_url_button'     => $this->bo->return_to ? $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to) : $this->page(''),
1159                                'action_text_button'    => lang('Cancel'),
1160                                'action_confirm_button' => '',
1161                                'action_extra_field'    => ''
1162                        );
1163                        $p->set_var($var);
1164                        $button_left .= '<td>'.$p->fp('out','form_button').'</td>';
1165
1166                        $p->set_var('button_left',$button_left);
1167                        $p->pfp('phpgw_body','view_event');
1168                }
1169
1170                function reinstate($params='')
1171                {
1172                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1173                        {
1174                                $this->no_edit();
1175                        }
1176                        elseif(!$this->bo->check_perms(PHPGW_ACL_ADD))
1177                        {
1178                                $this->index();
1179                        }
1180                        $cal_id = (isset($params['cal_id']) ? (int)$params['cal_id'] : '');
1181                        $cal_id = ($cal_id == '' ? (int)$_GET['cal_id'] : $cal_id);
1182
1183                        $reinstate_index = (isset($params['reinstate_index']) ? (int)$params['reinstate_index'] : '');
1184                        $reinstate_index = ($reinstate_index == '' ? (int)$_POST['reinstate_index'] : $reinstate_index);
1185                        if($this->debug)
1186                        {
1187                                echo '<!-- Calling bo->reinstate -->'."\n";
1188                        }
1189                        $cd = $this->bo->reinstate(
1190                                Array(
1191                                        'cal_id'        => $cal_id,
1192                                        'reinstate_index'       => $reinstate_index
1193                                )
1194                        );
1195                        if($this->debug)
1196                        {
1197                                echo '<!-- Return Value = '.$cd.' -->'."\n";
1198                        }
1199                        if ($this->bo->return_to)
1200                        {
1201                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
1202                        }
1203                        else
1204                        {
1205                                Header('Location: '.$this->page('',($cd?'&cd='.$cd:'')));
1206                        }
1207                        $GLOBALS['phpgw']->common->phpgw_exit();
1208                }
1209
1210                function add($cd=0,$readsess=0)
1211                {
1212                        if(!$this->bo->check_perms(PHPGW_ACL_ADD))
1213                        {
1214                                $this->index();
1215                        }
1216                       
1217                        if($readsess)
1218                        {
1219                                $event = $this->bo->restore_from_appsession;
1220                                if(!$event['owner'])
1221                                {
1222                                        $this->bo->add_attribute('owner',$this->bo->owner);
1223                                }
1224                                $can_edit = True;
1225                        }
1226                        else
1227                        {
1228                                $this->bo->event_init();
1229                                $this->bo->add_attribute('id',0);
1230
1231                                $can_edit = True;
1232                                $participants = (string)(get_var('participants',array('GET'),FALSE));
1233                                $starthour = (int)(get_var('hour',array('GET'),$this->bo->prefs['calendar']['workdaystarts']));
1234                                $startmin  = (int)(get_var('minute',array('GET'),0));
1235                                $endmin    = $startmin + (int)$this->bo->prefs['calendar']['defaultlength'];
1236                                $endhour   = $starthour + $this->bo->normalizeminutes($endmin);
1237                               
1238                                $subject        = (string)(get_var('title',array('GET'),0));
1239                                if ($subject != '0')
1240                                {
1241                                        $description    = (string)(get_var('description',array('GET'),0));
1242                                        $location       = (string)(get_var('location',array('GET'),0));
1243                                }
1244                                else
1245                                        unset($subject);
1246                               
1247                                $this->bo->set_start($this->bo->year,$this->bo->month,$this->bo->day,$starthour,$startmin,0);
1248                                $this->bo->set_end($this->bo->year,$this->bo->month,$this->bo->day,$endhour,$endmin,0);
1249                                $this->bo->set_title($subject);
1250                                $this->bo->set_description($description);
1251                                $this->bo->add_attribute('location',$location);
1252                                $this->bo->set_ex_participants('');
1253                                $this->bo->add_attribute('uid','');
1254                                $this->bo->add_attribute('priority',2);
1255                                if(@$this->bo->prefs['calendar']['default_private'])
1256                                {
1257                                        $this->bo->set_class(False);
1258                                }
1259                                else
1260                                {
1261                                        $this->bo->set_class(True);
1262                                }
1263                                // Add participants
1264                                //$participants = explode(";", $GLOBALS['phpgw']->session->appsession("participants") );
1265                                //for($_f_part=0; $_f_part<count($participants); $_f_part++)
1266                                //{
1267                                //      $this->bo->add_attribute('participants','A',$participants[$_f_part]);
1268                                //}
1269                                // Add misc
1270                                $this->bo->add_attribute('participants','A',$this->bo->owner);
1271                                $this->bo->set_recur_none();
1272                                $event = $this->bo->get_cached_event();
1273                               
1274                        }
1275                        $this->edit_form(
1276                                Array(
1277                                        'event' => $event,
1278                                        'cd' => $cd,
1279                                        'plain' => $_GET['plain']
1280                                )
1281                        );
1282                        $GLOBALS['phpgw']->common->phpgw_footer();
1283                }
1284
1285                function delete()
1286                {
1287                        if(!isset($_GET['cal_id']))
1288                        {
1289                                Header('Location: '.$this->page('','&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day)));
1290                                $GLOBALS['phpgw']->common->phpgw_exit();
1291                        }
1292
1293                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day);
1294                        if($this->bo->check_perms(PHPGW_ACL_DELETE,$cal_id = (int)$_GET['cal_id']))
1295                        {
1296                                if(isset($_POST['delete_type']) && $_POST['delete_type'] == 'single')
1297                                {
1298                                        $date = $_POST['date'];
1299                                        $cd = $this->bo->delete_single(
1300                                                Array(
1301                                                        'id'    => $cal_id,
1302                                                        'year'  => substr($date,0,4),
1303                                                        'month' => substr($date,4,2),
1304                                                        'day'   => substr($date,6,2)
1305                                                )
1306                                        );
1307                                }
1308                                elseif((isset($_POST['delete_type']) && $_POST['delete_type'] == 'series') || !isset($_POST['delete_type']))
1309                                {
1310                                        $cd = $this->bo->delete_entry($cal_id);
1311                                        $this->bo->expunge();
1312                                }
1313                        }
1314                        else
1315                        {
1316                                $cd = '';
1317                        }
1318                        if ($this->bo->return_to)
1319                        {
1320                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
1321                        }
1322                        else
1323                        {
1324                                Header('Location: '.$this->page('','&date='.$date.($cd?'&cd='.$cd:'')));
1325                        }
1326                        $GLOBALS['phpgw']->common->phpgw_exit();
1327                }
1328
1329                function disponibility($params) {
1330                       
1331                        if(!isset($_SESSION['phpgw_info']['expresso']['expressoAdmin'])) {
1332                                $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
1333                                $c->read_repository();
1334                                $current_config = $c->config_data;
1335                               
1336                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
1337               
1338                                $_SESSION['phpgw_info']['expresso']['user'] = $GLOBALS['phpgw_info']['user'];
1339                                $_SESSION['phpgw_info']['expresso']['server'] = $GLOBALS['phpgw_info']['server'];
1340                                $_SESSION['phpgw_info']['expresso']['cc_ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
1341                                $_SESSION['phpgw_info']['expresso']['expressoAdmin'] = $current_config;
1342                                $_SESSION['phpgw_info']['expresso']['global_denied_users'] = $GLOBALS['phpgw_info']['server']['global_denied_users'];
1343                                $_SESSION['phpgw_info']['expresso']['global_denied_groups'] = $GLOBALS['phpgw_info']['server']['global_denied_groups'];
1344                        }
1345                        $str_participants = substr($_GET['participants'],0,strlen($_GET['participants'])-1); //remove the last comma
1346                        $participants= array();
1347
1348                        $participants_splited = explode(",",$str_participants);
1349                        foreach($participants_splited as $participant) {
1350                                $participant = substr($participant,0,strlen($participant)-1);
1351                                $acct_type = $GLOBALS['phpgw']->accounts->get_type((int)$participant);
1352                                if($acct_type=='g') {
1353                                        $bo_groups = CreateObject('expressoAdmin1_2.group');
1354                                        $users = $bo_groups->get_info($participant);
1355                                        foreach($users['memberuid_info'] as $user) {
1356                                                if($user['type']==u)
1357                                                        $participants[$user['uidnumber']] = 'U';
1358                                        }
1359                                }
1360                                else {
1361                                        $participants[$participant] = 'U';
1362                                }
1363                        }
1364                       
1365                        $date = explode("/",$_GET['date']);
1366                        $freetime = $GLOBALS['phpgw']->datetime->localdates(mktime(0,0,0,$date[1],$date[0],$date[2]) - $GLOBALS['phpgw']->datetime->tz_offset);
1367
1368                        echo $this->print_disponibility(
1369                                Array(
1370                                        'date'          => $freetime,
1371                                        'starttime'     => $this->bo->splittime('000000',False),
1372                                        'endtime'       => 0,
1373                                        'participants'  => $participants
1374                                )
1375                        );
1376
1377
1378                }
1379
1380                function print_disponibility($param) {
1381
1382                        $str = "<html><head>
1383                        <script type='text/javascript'>
1384
1385                                var start = null;
1386                                var end = null;
1387                                function set_time(hour,minute) {
1388                                        //alert(start);
1389                                        if(start == null) {
1390                                                start = new Array();
1391                                                start[0] = hour;
1392                                                start[1] = minute;
1393                                                paint_interval(start,start,'#0000FF',true);
1394                                        }
1395                                        else if (end == null) {
1396                                                end = new Array();
1397                                                end[0] = hour;
1398                                                end[1] = minute;
1399                                                if(is_lower(start,end))
1400                                                        paint_interval(start,end,'#0000FF',true);
1401                                                else {
1402                                                        paint_interval(end,start,'#0000FF',true);
1403                                                        temp = start;
1404                                                        start = end;
1405                                                        end = temp;
1406                                                        paint_interval(end,end,'#FFFFFF',false);
1407                                                }
1408                                                parent.document.getElementById('start_hour').value=start[0];
1409                                                parent.document.getElementById('start_minute').value=start[1];                         
1410                                                parent.document.getElementById('end_hour').value=end[0];
1411                                                parent.document.getElementById('end_minute').value=end[1];
1412
1413                                        }
1414                                        else {
1415                                                end = null;
1416                                                start = new Array();
1417                                                start[0] = hour;
1418                                                start[1] = minute;
1419                                                repaint();
1420
1421                                                paint_interval(start,start,'#0000FF',true);
1422                                        }
1423                                }
1424                                function paint_column(name_array,color,force) {
1425                                        name = name_array[0]+'-'+name_array[1];
1426                                        if(navigator.userAgent.toLowerCase().indexOf('msie') == -1) {//firefox
1427                                                for(var i in document.getElementsByName(name)) {
1428                                                        document.getElementsByName(name)[i].bgColor=color;
1429                                                        if(document.getElementsByName(name)[i].nodeType==1) {
1430                                                                if(document.getElementsByName(name)[i].innerHTML.indexOf('>-<')==-1 || force==true)
1431                                                                        document.getElementsByName(name)[i].bgColor=color;
1432                                                                else
1433                                                                        document.getElementsByName(name)[i].bgColor='".$this->theme['bg01']."';                                                 
1434                                                        }
1435                                                }
1436                                        }
1437                                        else {//I.E
1438                                                cells = document.getElementsByTagName('td');
1439                                                for(var i=0;i<cells.length;i++) {
1440                                                                if(cells.item(i).name==name) { //getElementsByName in I.E is bugged
1441                                                                        cells.item(i).bgColor=color;
1442                                                                        if(cells.item(i).nodeType==1) {
1443                                                                                if(cells.item(i).innerHTML.indexOf('>-<')==-1 || force==true)
1444                                                                                        cells.item(i).bgColor=color;
1445                                                                                else
1446                                                                                        cells.item(i).bgColor='".$this->theme['bg01']."';                                                       
1447                                                                }
1448                                                        }
1449                                                }
1450                                        }
1451                                }
1452                               
1453                                function repaint() {
1454                                        temp_start = new Array();
1455                                        temp_start[0] = 8;
1456                                        temp_start[1] = 0;
1457                                        temp_end = new Array();
1458                                        temp_end[0] = 19;
1459                                        temp_end[1] = 0;
1460                                        paint_interval(temp_start,temp_end,'#FFFFFF',false);
1461                                }
1462                               
1463                                //Considera sempre name1 <= name2
1464                                function paint_interval(name1,name2,color,force) {
1465                                        paint_column(name1,color,force);
1466                                        if(name1[0]!=name2[0] || name1[1]!=name2[1]) {
1467                                                paint_column(name1,color,force);
1468                                                tempHour = name1[0];
1469                                                tempMinute = name1[1];
1470                                                while(tempHour<name2[0]) {
1471                                                        if(tempHour==name1[0] && tempMinute!=0)
1472                                                                temp_start = tempMinute/30;
1473                                                        else
1474                                                                temp_start = 0;
1475                                                        for(i=temp_start;i<60/30;i++) {
1476                                                                temp_column = new Array();
1477                                                                temp_column[0] = tempHour;
1478                                                                temp_column[1] = i*30;
1479                                                                paint_column(temp_column,color,force);
1480                                                        }
1481                                                        tempHour++;
1482                                                }
1483                                                for(i=0;i<name2[1];i+=30) {
1484                                                        temp_column = new Array();
1485                                                        temp_column[0] = name2[0];
1486                                                        temp_column[1] = i;
1487                                                        paint_column(temp_column,color,force);
1488                                                }
1489                                        }
1490                                }
1491                               
1492                                function is_lower(array1,array2) {
1493                                        if(array1[0]<array2[0])
1494                                                return true;
1495                                        else if(array1[0]>array2[0])
1496                                                return false;
1497                                        else {
1498                                                if(array1[1]<array2[1])
1499                                                        return true;
1500                                                else
1501                                                        return false;
1502                                        }
1503                                }
1504                        </script></head><body>
1505                        ";
1506                       
1507                        $str.= "<table border=\'1\' bgcolor=\"#FFFFFF\" width=\"100%\" height=\"100%\"><tr><td>";
1508
1509                       
1510                        if(!is_array($param))
1511                        {
1512                                $this->index();
1513                        }
1514
1515                        $date = $param['date'];
1516                        $starttime = $param['starttime'];
1517                        $endtime = $param['endtime'];
1518                        $participants = $param['participants'];
1519                        foreach($participants as $part => $nul)
1520                        {
1521                                $participants[$part] = $GLOBALS['phpgw']->common->grab_owner_name($part);
1522                                // Much better for processor  :)
1523                                $participants_id[]  .= $part;
1524                        }
1525                        uasort($participants,'strnatcasecmp');  // sort them after their fullname
1526
1527                        if(!isset($this->bo->prefs['calendar']['interval']))
1528                        {
1529                                $this->bo->prefs['calendar']['interval'] = 15;
1530                                $GLOBALS['phpgw']->preferences->add('calendar','interval',15);
1531                                $GLOBALS['phpgw']->preferences->save_repository();
1532                        }
1533                        $increment = $this->bo->prefs['calendar']['interval'];
1534                        $interval = (int)(60 / $increment);
1535
1536                        $pix = $GLOBALS['phpgw']->common->image('calendar','pix');
1537
1538                        $str .= '<center>'.lang($GLOBALS['phpgw']->common->show_date($date['raw'],'l'))
1539                                . ', '.$this->bo->long_date($date).'<br>'
1540                                . '<table width="85%" border="0" cellspacing="0" cellpadding="0" cols="'.((10 * $interval) + 1).'">'
1541                                . '<tr><td height="1" colspan="'.((11 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>'
1542                                . '<tr><td width="15%"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.lang('Participant').'</font></td>';
1543                        for($i=8;$i<19;$i++)
1544                        {
1545                                for($j=0;$j<$interval;$j++)
1546                                {
1547                                        $k = ($j == 0 ? sprintf('%02d',$i).'<br>':'').sprintf('%02d',$j*$increment);
1548
1549                                        $str .= '<td align="left" bgcolor="'.$this->theme['bg_color'].'" onclick="set_time('.$i.','.($j*$increment).')" style="cursor:hand;cursor:pointer">
1550                                                        <font color="'.$phpgw_info['theme']['bg_text'].'" face="'.$this->theme['font'].'" size="-2">' . $k."&nbsp;</font></td>\n";
1551                                }
1552                        }
1553                        $str .= '</tr>'
1554                                . '<tr><td height="1" colspan="'.((11 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>';
1555                        if(!$endtime)
1556                        {
1557                                $endtime = $starttime;
1558                        }
1559                        $owner = $this->bo->owner;
1560                        foreach($participants as $part => $fullname)
1561                        {
1562                                $str .= '<tr align="center">'
1563                                        . '<td width="15%" align="left"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$fullname.'</font></td>';
1564
1565                                $this->bo->cached_events = Array();
1566                                $this->bo->so->owner = $part;
1567                                $this->bo->so->open_box($part);
1568                                $this->bo->store_to_cache(
1569                                        Array(
1570                                                'syear' => $date['year'],
1571                                                'smonth'=> $date['month'],
1572                                                'sday'  => $date['day'],
1573                                                'eyear' => 0,
1574                                                'emonth'=> 0,
1575                                                'eday'  => $date['day'] + 1
1576                                        )
1577                                );
1578
1579                                if(!$this->bo->cached_events[$date['full']])
1580                                {
1581                                        for($j=8;$j<19;$j++)
1582                                        {
1583                                                for($k=0;$k<$interval;$k++)
1584                                                {
1585//                                                      $helper_name = $k*
1586                                                        $str .= '<td name="'.$j.'-'.($k*$increment).'" height="1" align="left" bgcolor="'.$this->theme['bg_color'].'" color="#999999">&nbsp;</td>';
1587                                                }
1588                                                $str .= "\n";
1589                                        }
1590                                }
1591                                else
1592                                {
1593                                        $time_slice = $this->bo->prepare_matrix($interval,$increment,$part,$date['full']);
1594                                        for($h=8;$h<19;$h++)
1595                                        {
1596                                                $hour = $h * 10000;
1597                                                for($m=0;$m<$interval;$m++)
1598                                                {
1599                                                        $index = ($hour + (($m * $increment) * 100));
1600                                                        switch($time_slice[$index]['marker'])
1601                                                        {
1602                                                                case '&nbsp':
1603                                                                        $time_slice[$index]['color'] = $this->theme['bg_color'];
1604                                                                        //$extra = '';
1605                                                                        break;
1606                                                                case '-':
1607                                                                        $time_slice[$index]['color'] = $this->theme['bg01'];
1608                                                                        $link = $this->page('view','&cal_id='.$time_slice[$index]['id'].'&date='.$date['full']);
1609                                                                        //$extra =' title="'.$time_slice[$index]['description'].'" onClick="location.href=\''.$link.'\';" style="cursor:pointer; cursor:hand;"';
1610                                                                        break;
1611                                                        }
1612                                                        $str .= '<td name="'.$h.'-'.($m*$increment).'" bgcolor="'.$time_slice[$index]['color'].'" color="#999999"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$time_slice[$index]['marker'].'</font></td>';
1613                                                }
1614                                                $str .= "\n";
1615                                        }
1616                                }
1617                                $str .= '</tr>'
1618                                        . '<tr><td height="1" colspan="'.((11 * $interval) + 1).'" bgcolor="#999999"><img src="'.$pix.'"></td></tr>';
1619                        }
1620                        $this->bo->owner = $owner;
1621                        $this->bo->so->owner = $owner;
1622                        $this->bo->so->open_box($owner);
1623                        $str.= "</table></center> \n </td></tr>
1624                        <tr><td onclick=\"parent.document.getElementById('disponibility').style.display='none'\" style='cursor:hand;cursor:pointer' align='center'>Fechar mapa</td></tr>
1625                        </table></body>";
1626                        return $str;
1627                }
1628
1629                function day()
1630                {
1631                       
1632                        $this->bo->read_holidays();
1633
1634                        if (!$this->bo->printer_friendly || ($this->bo->printer_friendly && @$this->bo->prefs['calendar']['display_minicals']))
1635                        {
1636                                $minical = $this->mini_calendar(
1637                                        Array(
1638                                                'day'   => $this->bo->day,
1639                                                'month' => $this->bo->month,
1640                                                'year'  => $this->bo->year,
1641                                                'link'  => 'day'
1642                                        )
1643                                );
1644                        }
1645                        else
1646                        {
1647
1648//NDEE: printer-friendly (what?)
1649                                $minical = '';
1650                        }
1651
1652                        if (!$this->bo->printer_friendly)
1653                        {
1654                                $printer = '';
1655                                $param = '&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day).'&friendly=1';
1656                                $print = '<a href="'.$this->page('day'.$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window.status = '".lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
1657                        }
1658                        else
1659                        {
1660
1661//NDEE: printer-friendly (daily-view)
1662                                $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
1663                                $printer = '<body bgcolor="'.$this->theme['bg_color'].'">';
1664                                $print =        '';
1665                        }
1666
1667                        $now    = $GLOBALS['phpgw']->datetime->makegmttime(0, 0, 0, $this->bo->month, $this->bo->day, $this->bo->year);
1668                        $now['raw'] += $GLOBALS['phpgw']->datetime->tz_offset;
1669
1670                        $p = $GLOBALS['phpgw']->template;
1671                        $p->set_file(
1672                                Array(
1673                                        'day_t' => 'day.tpl'
1674                                )
1675                        );
1676                        $p->set_block('day_t','day','day');
1677                        $p->set_block('day_t','day_event','day_event');
1678
1679                        $todos = $this->get_todos($todo_label);
1680                        $var = Array(
1681                                'printer_friendly'      => $printer,
1682                                'bg_text'                       => $this->theme['bg_text'],
1683                                'daily_events'          => $this->print_day(
1684                                        Array(
1685                                                'year'  => $this->bo->year,
1686                                                'month' => $this->bo->month,
1687                                                'day'   => $this->bo->day
1688                                        )
1689                                ),
1690                                'small_calendar'        => $minical,
1691                                'date'                          => $this->bo->long_date($now),
1692                                'username'                      => $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner),
1693                                'print'                         => $print,
1694                                'lang_todos'            => $todo_label,
1695                                'todos'                         => $this->bo->printer_friendly ? $todos :
1696
1697//NDEE: todo's layout
1698                                        "<div style=\"overflow: auto; max-height: 200px\">\n$todos</div>\n"
1699                        );
1700
1701                        $p->set_var($var);
1702                        $p->parse('day_events','day_event');
1703                        print $this->printer_friendly($p->fp('out','day'),lang('Dayview'));
1704                        $GLOBALS['phpgw']->common->phpgw_footer();
1705                }
1706
1707                function get_todos(&$todo_label)
1708                {
1709                        $todos_from_hook = $GLOBALS['phpgw']->hooks->process(array(
1710                                'location'  => 'calendar_include_todos',
1711                                'year'      => $this->bo->year,
1712                                'month'     => $this->bo->month,
1713                                'day'       => $this->bo->day,
1714                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
1715                        ));
1716
1717                        if(is_array($todo_label))
1718                        {
1719                                list($label,$showall)=$todo_label;
1720                        }
1721                        else
1722                        {
1723                                $label=$todo_label;
1724                                $showall=true;
1725                        }
1726                        $maxshow = (int)$GLOBALS['phpgw_info']['user']['preferences']['infolog']['mainscreen_maxshow'];
1727                        if($maxshow<=0)
1728                        {
1729                                $maxshow=10;
1730                        }
1731                        //print_debug("get_todos(): label=$label; showall=$showall; max=$maxshow");
1732
1733                        $content = $todo_label = '';
1734                        if (is_array($todos_from_hook) && count($todos_from_hook))
1735                        {
1736                                $todo_label = !empty($label)?$label:lang("open ToDo's:");
1737
1738                                foreach($todos_from_hook as $todos)
1739                                {
1740                                        $i = 0;
1741                                        if (is_array($todos) && count($todos))
1742                                        {
1743                                                foreach($todos as $todo)
1744                                                {
1745                                                        if(!$showall && ($i++>$maxshow))
1746                                                        {
1747                                                                break;
1748                                                        }
1749                                                        $icons = '';
1750                                                        foreach($todo['icons'] as $name => $app)
1751                                                        {
1752                                                                $icons .= ($icons?' ':'').$GLOBALS['phpgw']->html->image($app,$name,lang($name),'border="0" width="15" height="15"');
1753                                                        }
1754                                                        $class = $class == 'row_on' ? 'row_off' : 'row_on';
1755
1756//NDEE <tr starts here
1757                                                        $content .= " <tr id=\"debug\" class=\"$class\">\n  <td valign=\"top\" width=\"15%\"nowrap>".
1758                                                                ($this->bo->printer_friendly?$icons:$GLOBALS['phpgw']->html->a_href($icons,$todo['view'])).
1759                                                                "</td>\n  <td>".($this->bo->printer_friendly?$todo['title']:
1760                                                                $GLOBALS['phpgw']->html->a_href($todo['title'],$todo['view']))."</td>\n </tr>\n";
1761                                                }
1762                                        }
1763                                }
1764                        }
1765                        if (!empty($content))
1766                        {
1767                                return "<table border=\"0\" width=\"100%\">\n$content</table>\n";
1768                        }
1769                        return False;
1770                }
1771
1772                function edit_status()
1773                {
1774                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
1775                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1776                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
1777                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
1778                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Change Status');
1779                        $GLOBALS['phpgw']->common->phpgw_header();
1780
1781                        $event = $this->bo->read_entry($_GET['cal_id']);
1782
1783                        reset($event['participants']);
1784
1785                        if(!$event['participants'][$this->bo->owner])
1786                        {
1787                                echo '<center>'.lang('The user %1 is not participating in this event!',$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner)).'</center>';
1788                                return;
1789                        }
1790
1791                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1792                        {
1793                                $this->no_edit();
1794                                return;
1795                        }
1796
1797                        $freetime = $GLOBALS['phpgw']->datetime->localdates(mktime(0,0,0,$event['start']['month'],$event['start']['mday'],$event['start']['year']) - $GLOBALS['phpgw']->datetime->tz_offset);
1798                        echo $this->timematrix(
1799                                Array(
1800                                        'date'          => $freetime,
1801                                        'starttime'     => $this->bo->splittime('000000',False),
1802                                        'endtime'       => 0,
1803                                        'participants'  => $event['participants']
1804                                )
1805                        ).'<br>';
1806
1807                        $event = $this->bo->read_entry($_GET['cal_id']);
1808                        $this->view_event($event);
1809                        $GLOBALS['phpgw']->template->pfp('phpgw_body','view_event');
1810
1811                        echo $this->get_response($event['id']);
1812                }
1813               
1814                function confirm_action($duplicated_action)
1815                {
1816                                if($_GET['response'] == 1)
1817                                {
1818                                        if(!$duplicated_action)
1819                                                $notify_message = lang('The commitment was accepted successfully!');
1820                                        else
1821                                                $notify_message = lang('This commitment has already been accepted!');
1822                                }       
1823                                else
1824                                {                                       
1825                                        if(!$duplicated_action)                                         
1826                                                $notify_message = lang('The commitment was rejected successfully!');
1827                                        else
1828                                                $notify_message = lang('This commitment has already been rejected!');
1829                                }
1830                               
1831                                $body1 = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
1832                                $body1->set_file(Array('calendar' => 'confirm.tpl'));
1833                                $body1->set_block('calendar','list');
1834                                $var = Array( 'notify_message'  => $notify_message);
1835                                $body1->set_var($var);
1836                                $tmpbody1 = $body1->pfp('out','list');
1837                }
1838                function set_action()
1839                {
1840                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1841                        {
1842                                $this->no_edit();
1843                                return;
1844                        }
1845                       
1846                        $confirm_status = $this->bo->set_status((int)$_GET['cal_id'],(int)$_GET['action']);
1847
1848                        if(isset($_GET['response']))
1849                        {
1850                                        $this->confirm_action($confirm_status);
1851                                        $GLOBALS['phpgw']->common->phpgw_exit(False);
1852                        }
1853                        else
1854                        {
1855                                        if ($this->bo->return_to)
1856                                        {
1857                                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
1858                                        }
1859                                        else
1860                                        {
1861                                                Header('Location: '.$this->page('',''));
1862                                        }
1863                                        $GLOBALS['phpgw']->common->phpgw_exit();
1864                        }
1865                       
1866                }
1867                function planner()
1868                {
1869                        if(floor(phpversion()) < 4)
1870                        {
1871                                return;
1872                        }
1873                        $home = strstr($_SERVER['PHP_SELF'],'home') !== False;
1874                        // generate header and set global/member variables
1875                        //
1876                        $this->planner_prepare($home);
1877
1878                        // process events within selected interval
1879                        //
1880                        $this->planner_process_interval();
1881
1882                        // generate the planner view
1883                        //
1884                        if (!$home)
1885                        {
1886                                echo '<p>'.$this->planner_print_rows();
1887                        }
1888                        else
1889                        {
1890                                return $this->planner_print_rows();
1891                        }
1892                }
1893
1894                function set_planner_group_members()
1895                {
1896                        $type = $GLOBALS['phpgw']->accounts->get_type($this->bo->owner);
1897
1898                        if ($type == 'g') // display schedule of all group members
1899                        {
1900                                $members = array();
1901                                $ids = $GLOBALS['phpgw']->acl->get_ids_for_location($this->bo->owner, 1, 'phpgw_group');
1902                                while (list(,$id) = each($ids))
1903                                {
1904                                        if ($this->bo->check_perms(PHPGW_ACL_READ,0,$id))
1905                                        {
1906                                                $members[$GLOBALS['phpgw']->common->grab_owner_name($id)] = $id;
1907                                        }
1908                                }
1909                                ksort($members);
1910                                $this->planner_group_members = $members;
1911                        }
1912                        else
1913                        {
1914                                $this->planner_group_members = array(
1915                                        $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner) => $this->bo->owner
1916                                );
1917                        }
1918                }
1919
1920                /**
1921                 * planner_prepare - prepare the planner view
1922                 *
1923                 * - sets global environment variables
1924                 * - initializes class member variables used in multiple planner related functions
1925                 * - generates header lines for the planner view (month, calendar week, days)
1926                 */
1927                function planner_prepare($no_header = False)
1928                {
1929                        // set some globals
1930                        //
1931                        if (!$no_header)
1932                        {
1933                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
1934                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1935                                if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Group Planner');
1936                                $GLOBALS['phpgw']->common->phpgw_header();
1937                        }
1938
1939                        // intervals_per_day can be configured in preferences now :-)
1940                        //
1941                        if (! $this->bo->prefs['calendar']['planner_intervals_per_day'])
1942                        {
1943                                $GLOBALS['phpgw']->preferences->add('calendar','planner_intervals_per_day',3);
1944                                $GLOBALS['phpgw']->preferences->save_repository();
1945                                $this->bo->prefs['calendar']['planner_intervals_per_day'] = 3;
1946                        }
1947                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
1948                        $this->bo->save_sessiondata();  // need to save $this->bo->save_owner
1949
1950                        // set title for table and rows of planner view
1951                        //
1952                        if ($this->bo->sortby == 'category')
1953                        {
1954                                $title = lang('Category');
1955                        }
1956                        else
1957                        {
1958                                $title = lang('User');
1959
1960                                $this->set_planner_group_members();
1961                        }
1962
1963                        // create/initialize variables directly used for HTML code generation
1964                        //
1965                        $this->planner_header = array();
1966                        $this->planner_rows   = array();
1967
1968                        // generate header lines with days and associated months
1969                        //
1970                        $hdr = &$this->planner_header;
1971                        $hdr[0]['0']  = $title;
1972                        $hdr[0]['.0'] = 'rowspan="3"';
1973
1974                        $this->planner_days = 0; // reset
1975
1976                        $m = $this->bo->month;
1977                        $y = $this->bo->year;
1978                        $this->bo->read_holidays($y);
1979                        for ($i=1; $i<=$this->bo->num_months; $i++,$m++)
1980                        {
1981                                if ($m == 13)
1982                                {
1983                                        $m = 1; $y++; // "wrap-around" into new year
1984                                        $this->bo->read_holidays($y);
1985                                }
1986                                $days = $GLOBALS['phpgw']->datetime->days_in_month($m,$y);
1987
1988                                $d     = mktime(0,0,0,$m,1,$y);
1989                                $month = lang(date('F', $d)).strftime(' %Y', $d);
1990                                $color = $this->theme[$m % 2 || $this->bo->num_months == 1 ? 'th_bg' : 'row_on'];
1991                                $cols  = $days * $intervals_per_day;
1992
1993                                $hdr[0]['.'.$i] = 'bgcolor="'.$color.'" colspan="'.$cols.'" align="center"';
1994                                $prev_month = sprintf('%04d%02d01',$y-($m==1),$m > 1?$m-1:12);
1995                                $next_month = sprintf('%04d%02d01',$y+($m==12),$m < 12?$m+1:1);
1996                                $prev_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$prev_month");
1997                                $next_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$next_month");
1998                                $hdr[0][$i] = "<b><a href=\"$prev_link\">&lt;&lt;</a> &nbsp $month &nbsp <a href=\"$next_link\">&gt;&gt;</a></b>";
1999
2000                                $add_owner = array();   // if no add-rights on the showed cal use own cal
2001                                if (!$this->bo->save_owner && !$this->bo->check_perms(PHPGW_ACL_ADD) ||
2002                                        !$this->bo->check_perms(PHPGW_ACL_ADD,0,$this->bo->save_owner))
2003                                {
2004                                        $add_owner = array(
2005                                                'owner' => $GLOBALS['phpgw_info']['user']['account_id']
2006                                        );
2007                                }
2008                                for ($d=1; $d<=$days; $d++)
2009                                {
2010                                        $dayname = substr(lang(date('D',mktime(0,0,0,$m,$d,$y))),0,2);
2011                                        $index = $d + $this->planner_days;
2012
2013                                        $hdr[2]['.'.$index] = 'colspan="'.$intervals_per_day.'" align="center"';
2014
2015                                        // highlight today, saturday, sunday and holidays
2016                                        //
2017                                        $color = $this->theme['row_off'];
2018                                        $dow = $GLOBALS['phpgw']->datetime->day_of_week($y,$m,$d);
2019                                        $date = sprintf("%04d%02d%02d",$y,$m,$d);
2020                                        if ($date == date('Ymd'))
2021                                        {
2022                                                $color = $GLOBALS['phpgw_info']['theme']['cal_today'];
2023                                        }
2024                                        elseif ($this->bo->cached_holidays[$date])
2025                                        {
2026                                                $color = $this->bo->holiday_color;
2027                                                $hdr[2]['.'.$index] .= ' title="'.$this->bo->cached_holidays[$date][0]['name'].'"';
2028                                        }
2029                                        elseif ($dow == 0 || $dow == 6)
2030                                        {
2031                                                $color = $this->bo->theme['th_bg'];
2032                                        }
2033
2034                                        $hdr[2]['.'.$index] .= " bgcolor=\"$color\"";
2035
2036                                        $hdr[2][$index] = '<a href="'.$this->html->link('/index.php',
2037                                                                array(
2038                                                                        'menuaction' => 'calendar.uicalendar.add',
2039                                                                        'date' => $date
2040                                                                ) + $add_owner
2041                                                        ).'">'.$dayname.'<br>'.$d.'</a>';
2042                                }
2043                                $this->planner_days += $days;
2044                        }
2045
2046                        // create/initialize member variables describing the time interval to be displayed
2047                        //
2048                        $this->planner_end_month = $m - 1;
2049                        $this->planner_end_year  = $y;
2050                        $this->planner_days_in_end_month = $GLOBALS['phpgw']->datetime->days_in_month($this->planner_end_month,$this->planner_end_year);
2051                        $this->planner_firstday = (int)(date('Ymd',mktime(0,0,0,$this->bo->month,1,$this->bo->year)));
2052                        $this->planner_lastday  = (int)(date('Ymd',mktime(0,0,0,$this->planner_end_month,$this->planner_days_in_end_month,$this->planner_end_year)));
2053
2054                        // generate line with calendar weeks in observed interval
2055                        //
2056                        $d      = mktime(0,0,0,$this->bo->month,1,$this->bo->year);
2057                        $w      = date('W', $d);
2058                        if ($w == 'W')  // php < 4.1
2059                        {
2060                                $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
2061                        }
2062                        $offset = (7-date('w', $d)+1)%7;
2063                        $offset = $offset == 0 ? 7 : $offset;
2064                        $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
2065
2066                        $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$intervals_per_day * $offset.'" align="left"';
2067                        $hdr[1][$w] = '';
2068                        if ($offset >= 3)
2069                        {
2070
2071//NDEE: style! (groupplanner)
2072                                $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
2073                        }
2074                        $days_left = $this->planner_days - $offset;
2075
2076                        $colspan = 7 * $intervals_per_day;
2077                        while ($days_left > 0)
2078                        {
2079                                $colspan = ($days_left < 7) ? $days_left*$intervals_per_day : $colspan;
2080                                $d += 604800; // 7 days whith 24 hours (1h == 3600 seconds) each
2081                                $w = date('W', $d);
2082                                if ($w == 'W')  // php < 4.1
2083                                {
2084                                        $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
2085                                }
2086                                $w += (isset($hdr[1][$w]))?1:0; // bug in "date('W')" ?
2087
2088                                $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
2089                                $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$colspan.'" align="left"';
2090                                $hdr[1][$w] = '';
2091                                if ($days_left >= 3)
2092                                {
2093
2094//NDEE: style! (groupplanner)
2095                                        $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
2096                                }
2097
2098                                $days_left -= 7;
2099                        }
2100                        return $hdr;
2101                }
2102
2103                /**
2104                 * planner_update_row - update a row of the planner view
2105                 *
2106                 * parameters are:
2107                 *   - index (e.g. user id, category id, ...) of the row
2108                 *   - name/title of the row (e.g. user name, category name)
2109                 *   - the event to be integrated
2110                 *   - list of categories associated with the event
2111                 *   - first and last cell of the row
2112                 */
2113                function planner_update_row($index,$name,$event,$cat,$start_cell,$end_cell)
2114                {
2115                        $rows              = &$this->planner_rows;
2116                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2117                        $is_private        = !$this->bo->check_perms(PHPGW_ACL_READ,$event);
2118
2119                        $view = $this->html->link('/index.php',
2120                                array(
2121                                        'menuaction' => 'calendar.uicalendar.view',
2122                                        'cal_id' => $event['id'],
2123                                        'date' => date('Ymd',$this->bo->maketime($event['start']))
2124                                )
2125                        );
2126
2127                        // check how many lines are needed for this "row" (currently: user or category)
2128                        $i = 0;
2129                        do {
2130                                ++$i;
2131
2132                                $k = $index.'_'.$i;
2133                                $ka = '.nr_'.$k;
2134
2135                                if (!isset($rows[$k]))
2136                                {
2137                                        if ($i > 1)                             // further line - no name
2138                                        {
2139                                                $rows[$k] = array();
2140                                                $rows[$index.'_1']['._name'] = 'rowspan="'.$i.'"';
2141                                        }
2142                                        else
2143                                        {
2144                                                $rows[$k]['_name'] = $name;
2145                                        }
2146                                        $rows[$ka] = 0;
2147                                }
2148                                $rows[$index.'_1']['._name'] .= ' nowrap'; // title must be one row
2149
2150                                $row = &$rows[$k];
2151                                $akt_cell = &$rows[$ka];
2152                        } while ($akt_cell > $start_cell);
2153
2154                        $id = $event['id'].'-'.date('Ymd',$this->bo->maketime($event['start']));
2155                        if ($akt_cell < $start_cell)
2156                        {
2157                                $row[$id.'_1'] = '&nbsp;';
2158                                $row['.'.$id.'_1'] = 'colspan="'.($start_cell-$akt_cell).'"';
2159                        }
2160                        $opt = &$row['.'.$id.'_2'];
2161                        $cel = &$row[$id.'_2'];
2162
2163                        // if possible, display information about event within cells representing it
2164                        //
2165                        if ($start_cell < $end_cell)
2166                        {
2167                                $colspan = $end_cell - $start_cell;
2168                                $opt .= "colspan=".(1 + $colspan);
2169
2170                                if (!$is_private)
2171                                {
2172                                        $max_chars = (int)(3*$colspan/$intervals_per_day-2);
2173
2174                                        $min_chars = 3; // minimum for max_chars to display -> this should be configurable
2175                                        if ($max_chars >= $min_chars)
2176                                        {
2177                                                $len_title = strlen($event['title']);
2178
2179                                                if ($len_title <= $max_chars)
2180                                                {
2181                                                        $title = $event['title'];
2182                                                        $max_chars -= $len_title + 3; // 3 chars for separator: " - "
2183                                                        $len_descr = strlen($event['description']);
2184
2185                                                        if ($len_descr > 0 && $len_descr <= $max_chars)
2186                                                        {
2187                                                                $event['print_description'] = 'yes';
2188                                                        }
2189                                                }
2190                                                else
2191                                                {
2192                                                        $has_amp = strpos($event['title'],'&amp;');
2193                                                       
2194//NDEE: event title gets cut here                                                       
2195                                                        $title = substr($event['title'], 0 , $max_chars-1+($has_amp!==False&&$has_amp<$max_chars?4:0)).'...';
2196                                                }
2197                                                $event['print_title'] = 'yes';
2198                                        }
2199                                }
2200                        }
2201
2202                        if ($bgcolor=$cat['color'])
2203                        {
2204                                $opt .= ' bgcolor="'.$bgcolor.'"';
2205                        }
2206                        if (!$is_private)
2207                        {
2208                                $opt .= ' title="'.lang('Title').": ".$event['title'];
2209                                if ($event['description'])
2210                                {
2211                                        $opt .= "\n".lang('Description').": ".$event['description'];
2212                                }
2213                        }
2214                        else
2215                        {
2216                                $opt .= ' title="'.lang('You do not have permission to read this record!');
2217                        }
2218
2219                        $start = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset);
2220                        $end = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset);
2221                        $opt .= "\n".lang('Start Date/Time').": ".$start."\n".lang('End Date/Time').": ".$end;
2222
2223                        if ($event['location'] && !$is_private)
2224                        {
2225                                $opt .= " \n".lang('Location').": ".$event['location'];
2226                        }
2227
2228                        if (!$is_private)
2229                        {
2230                                $opt .= '" onClick="location=\''.$view.'\'"';
2231                                $cel = '<a href="'.$view.'">';
2232                        }
2233                        else
2234                        {
2235                                $opt .= '"';
2236                                $cel = '';
2237                        }
2238                        $opt .= ' class="planner-cell"';
2239
2240                        if ($event['priority'] == 3)
2241                        {
2242                                $cel .= $this->html->image('calendar','mini-calendar-bar.gif','','border="0"');
2243                        }
2244                        if ($event['recur_type'])
2245                        {
2246                                $cel .= $this->html->image('calendar','recur.gif','','border="0"');
2247                        }
2248                        $cel .= $this->html->image('calendar',count($event['participants'])>1?'multi_3.gif':'single.gif',$this->planner_participants($event['participants']),'border="0"');
2249                        $cel .= '</a>';
2250
2251                        if (isset($event['print_title']) && $event['print_title'] == 'yes')
2252                        {
2253
2254//NDEE: style! where?
2255                                $cel .= '<font size="-2"> '.$title.' </font>';
2256                        }
2257                        if (isset($event['print_description']) && $event['print_description'] == 'yes')
2258                        {
2259
2260//NDEE: style! where ?
2261                                $cel .= '<font size="-2"> - '.$event['description'].' </font>';
2262                        }
2263
2264                        $akt_cell = $end_cell + 1;
2265
2266                        return $rows;
2267                }
2268
2269                function planner_process_event($event)
2270                {
2271                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2272                        $interval = $this->planner_intervals[$intervals_per_day];
2273                        $last_cell = $intervals_per_day * $this->planner_days - 1;
2274
2275                        $rows = &$this->planner_rows;
2276
2277                        // caluculate start and end of event
2278                        //
2279                        $event_start = (int)(date('Ymd',mktime(
2280                                0,0,0,
2281                                $event['start']['month'],
2282                                $event['start']['mday'],
2283                                $event['start']['year']
2284                        )));
2285                        $event_end   = (int)(date('Ymd',mktime(
2286                                0,0,0,
2287                                $event['end']['month'],
2288                                $event['end']['mday'],
2289                                $event['end']['year']
2290                        )));
2291
2292                        // calculate first cell of event within observed interval
2293                        //
2294                        if ($event_start >= $this->planner_firstday)
2295                        {
2296                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['start']['month'],$event['start']['mday'],$event['start']['year']);
2297
2298                                $start_cell = $intervals_per_day * $days_between + $interval[$event['start']['hour']];
2299                        }
2300                        else
2301                        {
2302                                $start_cell = 0;
2303                        }
2304
2305                        // calculate last cell of event within observed interval
2306                        //
2307                        if ($event_end <= $this->planner_lastday)
2308                        {
2309                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['end']['month'],$event['end']['mday'],$event['end']['year']);
2310                                $end_cell = $intervals_per_day * $days_between + $interval[$event['end']['hour']];
2311                                if ($end_cell == $start_cell && $end_cell < $last_cell)
2312                                {
2313                                        $end_cell++;    // min. width 1 interval
2314                                }
2315                        }
2316                        else
2317                        {
2318                                $end_cell = $last_cell;
2319                        }
2320                        // get the categories associated with event
2321                        //
2322                        if ($c = $event['category'])
2323                        {
2324                                list($cat)   = $this->planner_category($event['category']);
2325                                if ($cat['parent'])
2326                                {
2327                                        list($pcat) = $this->planner_category($c = $cat['parent']);
2328                                }
2329                                else
2330                                {
2331                                        $pcat = $cat;
2332                                }
2333                        }
2334                        else
2335                        {
2336                                $cat = $pcat = array( 'name' => lang('none'));
2337                        }
2338
2339                        // add the event to it`s associated row(s)
2340                        //
2341                        if ($this->bo->sortby == 'category')
2342                        {
2343                                // event needs to show up in it`s category`s row
2344                                //
2345                                $this->planner_update_row($c,$pcat['name'],$event,$cat,$start_cell,$end_cell);
2346                        }
2347                        elseif ($this->bo->sortby == 'user')
2348                        {
2349                                // event needs to show up in rows of all participants that are also owners
2350                                //
2351                                reset($this->planner_group_members);
2352                                while(list($user_name,$id) = each($this->planner_group_members))
2353                                {
2354                                        $status = $event['participants'][$id];
2355
2356                                        if (isset($status) && $status != 'R')
2357                                        {
2358                                                $this->planner_update_row($user_name,$user_name,$event,$cat,$start_cell,$end_cell);
2359                                        }
2360                                }
2361                        }
2362                }
2363
2364                function planner_pad_rows()
2365                {
2366                        $rows = &$this->planner_rows;
2367
2368                        if ($this->bo->sortby == 'user')
2369                        {
2370                                // add empty rows for users that do not participante in any event
2371                                //
2372                                reset($this->planner_group_members);
2373                                while(list($user_name,$id) = each($this->planner_group_members))
2374                                {
2375                                        $k  = $user_name.'_1';
2376                                        $ka = '.nr_'.$k;
2377
2378                                        if (!isset($rows[$k]))
2379                                        {
2380                                                $rows[$k]['_name'] = $user_name;
2381                                                $rows[$k]['._name'] .= ' nowrap';
2382                                                $rows[$ka] = 0;
2383                                        }
2384                                }
2385                        }
2386
2387                        // fill the remaining cols
2388                        //
2389                        $last_cell = $this->bo->prefs['calendar']['planner_intervals_per_day'] * $this->planner_days - 1;
2390
2391                        ksort($rows);
2392                        while (list($k,$r) = each($rows))
2393                        {
2394                                if (is_array($r))
2395                                {
2396                                        $rows['.'.$k] = 'bgcolor="'.$GLOBALS['phpgw']->nextmatchs->alternate_row_color().'"';
2397                                        $row = &$rows[$k];
2398                                        $akt_cell = &$rows['.nr_'.$k];
2399                                        if ($akt_cell < $last_cell)
2400                                        {
2401                                                $row['3'] = '&nbsp';
2402                                                $row['.3'] = 'colspan="'.(1+$last_cell-$akt_cell).'"';
2403                                        }
2404                                }
2405                        }
2406                }
2407
2408                function planner_print_rows()
2409                {
2410                        $bgcolor = 'bgcolor="'.$this->theme['th_bg'].'"';
2411                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2412
2413                        if ($this->debug)
2414                        {
2415                                _debug_array($this->planner_rows);
2416                                reset($this->planner_rows);
2417                        }
2418                        return $this->html->table(
2419                                array(
2420                                        '_hdr0' => $this->planner_header[0],
2421                                        '._hdr0' => $bgcolor,
2422                                        '_hdr1' => $this->planner_header[1],
2423                                        '._hdr1' => $bgcolor,
2424                                        '_hdr2' => $this->planner_header[2],
2425                                        '._hdr2' => $bgcolor
2426                                )+$this->planner_rows,
2427                                'width="100%" cols="'.(1+$this->planner_days_in_end_month*$intervals_per_day).'"');
2428                }
2429
2430                function planner_process_interval()
2431                {
2432                        // generate duplicate free list of events within observed interval
2433                        //
2434                        $this->bo->store_to_cache(
2435                                Array(
2436                                        'syear' => $this->bo->year,
2437                                        'smonth'        => $this->bo->month,
2438                                        'sday'  => 1,
2439                                        'eyear' => $this->planner_end_year,
2440                                        'emonth'        => $this->planner_end_month,
2441                                        'eday'  => $this->planner_days_in_end_month
2442                                )
2443                        );
2444                        $this->bo->remove_doubles_in_cache($this->planner_firstday,$this->planner_lastday);
2445
2446                        // process all events within observed interval
2447                        //
2448                        for($v=$this->planner_firstday;$v<=$this->planner_lastday;$v++)
2449                        {
2450                                $daily = $this->bo->cached_events[$v];
2451
2452                                print_debug('For Date',$v);
2453                                print_debug('Count of items',count($daily));
2454
2455                                // process all events on day $v
2456                                //
2457                                if (is_array($daily)) foreach($daily as $event)
2458                                {
2459                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
2460                                        {
2461                                                $this->bo->set_recur_date($event,$v);
2462                                        }
2463                                        if (!$this->bo->rejected_no_show($event))
2464                                        {
2465                                                $this->planner_process_event($event);
2466                                        }
2467                                }
2468                        }
2469                        $this->planner_pad_rows();
2470                }
2471
2472                function matrixselect()
2473                {
2474                        $datetime = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
2475
2476                        $sb = CreateObject('phpgwapi.sbox');
2477
2478                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2479                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2480                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2481                        $GLOBALS['phpgw']->common->phpgw_header();
2482
2483                        $p = &$GLOBALS['phpgw']->template;
2484                        $p->set_file(
2485                                Array(
2486                                        'mq'            => 'matrix_query.tpl',
2487                                        'form_button'   => 'form_button_script.tpl'
2488                                )
2489                        );
2490                        $p->set_block('mq','matrix_query','matrix_query');
2491                        $p->set_block('mq','list','list');
2492
2493                        $p->set_var(array(
2494                                'title'                 => lang('Daily Matrix View'),
2495                                'th_bg'                 => $this->theme['th_bg'],
2496                                'action_url'    => $this->page('viewmatrix')
2497                        ));
2498
2499// Date
2500                        $var[] = Array(
2501                                'field' =>      lang('Date'),
2502                                'data'  =>      $GLOBALS['phpgw']->common->dateformatorder(
2503                                        $sb->getYears('year',(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y'),(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y')),
2504                                        $sb->getMonthText('month',(int)$GLOBALS['phpgw']->common->show_date($datetime,'n')),
2505                                        $sb->getDays('day',(int)$GLOBALS['phpgw']->common->show_date($datetime,'d'))
2506                                )
2507                        );
2508
2509// View type
2510                        $var[] = Array(
2511                                'field' =>      lang('View'),
2512                                'data'  =>      '<select name="matrixtype">'."\n"
2513                                        . '<option value="free/busy" selected>'.lang('free/busy').'</option>'."\n"
2514                                        . '<option value="weekly">'.lang('Weekly').'</option>'."\n"
2515                                        . '</select>'."\n"
2516                        );
2517
2518// Participants
2519                        $accounts = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,'calendar');
2520                        $users = Array();
2521                        for($i=0;$i<count($accounts);$i++)
2522                        {
2523                                $user = $accounts[$i];
2524                                if(!isset($users[$user]))
2525                                {
2526                                        $users[$user] = $GLOBALS['phpgw']->common->grab_owner_name($user);
2527                                        if($GLOBALS['phpgw']->accounts->get_type($user) == 'g')
2528                                        {
2529                                                $group_members = $GLOBALS['phpgw']->acl->get_ids_for_location($user,1,'phpgw_group');
2530                                                if($group_members != False)
2531                                                {
2532                                                        for($j=0;$j<count($group_members);$j++)
2533                                                        {
2534                                                                if(!isset($users[$group_members[$j]]))
2535                                                                {
2536                                                                        $users[$group_members[$j]] = $GLOBALS['phpgw']->common->grab_owner_name($group_members[$j]);
2537                                                                }
2538                                                        }
2539                                                }
2540                                        }
2541                                }
2542                        }
2543
2544                        $num_users = count($users);
2545
2546                        if ($num_users > 50)
2547                        {
2548                                $size = 15;
2549                        }
2550                        elseif ($num_users > 5)
2551                        {
2552                                $size = 5;
2553                        }
2554                        else
2555                        {
2556                                $size = $num_users;
2557                        }
2558                        $str = '';
2559                        @asort($users);
2560                        @reset($users);
2561                        while ($user = each($users))
2562                        {
2563                                if(($GLOBALS['phpgw']->accounts->exists($user[0]) && $this->bo->check_perms(PHPGW_ACL_READ,0,$user[0])) || $GLOBALS['phpgw']->accounts->get_type($user[0]) == 'g')
2564                                {
2565                                        $str .= '    <option value="'.$user[0].'">('.$GLOBALS['phpgw']->accounts->get_type($user[0]).') '.$user[1].'</option>'."\n";
2566                                }
2567                        }
2568                        $var[] = Array(
2569                                'field' =>      lang('Participants'),
2570                                'data'  =>      "\n".'   <select name="participants[]" multiple size="'.$size.'">'."\n".$str.'   </select>'."\n"
2571                        );
2572
2573                        for($i=0;$i<count($var);$i++)
2574                        {
2575                                $this->output_template_array($p,'rows','list',$var[$i]);
2576                        }
2577
2578                        $vars = Array(
2579                                'submit_button'         => lang('View'),
2580                                'action_url_button'     => $this->bo->return_to ? $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to) : $this->page(''),
2581                                'action_text_button'    => lang('Cancel'),
2582                                'action_confirm_button' => '',
2583                                'action_extra_field'    => ''
2584                        );
2585
2586                        $p->set_var($vars);
2587                        $p->parse('cancel_button','form_button');
2588                        $p->pparse('out','matrix_query');
2589                }
2590
2591                function viewmatrix()
2592                {
2593                        if ($_POST['cancel'])
2594                        {
2595                                $this->index();
2596                        }
2597                        $participants = $_POST['participants'];
2598                        $parts = Array();
2599                        $acct = CreateObject('phpgwapi.accounts',$this->bo->owner);
2600
2601                        if (is_array($participants))
2602                        {
2603                                foreach($participants as $participant)
2604                                {
2605                                        switch ($GLOBALS['phpgw']->accounts->get_type($participant))
2606                                        {
2607                                                case 'g':
2608                                                        if ($members = $acct->member((int)$participant))
2609                                                        {
2610                                                                foreach($members as $member)
2611                                                                {
2612                                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$member['account_id']))
2613                                                                        {
2614                                                                                $parts[$member['account_id']] = True;
2615                                                                        }
2616                                                                }
2617                                                        }
2618                                                        break;
2619                                                case 'u':
2620                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$participant))
2621                                                        {
2622                                                                $parts[$participant] = 1;
2623                                                        }
2624                                                        break;
2625                                        }
2626                                }
2627                                unset($acct);
2628                        }
2629                        $participants = array_keys($parts);     // get id's as values and a numeric index
2630
2631                        // Defined - into session - who participates
2632                        $GLOBALS['phpgw']->session->appsession("participants", NULL, implode(";", $participants));
2633
2634                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2635                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2636                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2637                        $GLOBALS['phpgw']->common->phpgw_header();
2638
2639                        switch($_POST['matrixtype'])
2640                        {
2641                                case 'free/busy':
2642                                        $freetime = $GLOBALS['phpgw']->datetime->gmtdate(mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year));
2643                                        echo '<br>'.$this->timematrix(
2644                                                Array(
2645                                                        'date'          => $freetime,
2646                                                        'starttime'     => $this->bo->splittime('000000',False),
2647                                                        'endtime'       => 0,
2648                                                        'participants'  => $parts
2649                                                )
2650                                        );
2651                                        break;
2652                                case 'weekly':
2653                                        echo '<br>'.$this->display_weekly(
2654                                                Array(
2655                                                        'date'          => sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day),
2656                                                        'showyear'      => true,
2657                                                        'owners'        => $participants
2658                                                )
2659                                        );
2660                                        break;
2661                        }
2662                        echo "\n<br>\n".'<form action="'.$this->page('viewmatrix').'" method="post" name="matrixform">'."\n";
2663                        echo ' <table cellpadding="5"><tr><td>'."\n";
2664                        echo '  <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
2665                        echo '  <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
2666                        echo '  <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
2667                        echo '  <input type="hidden" name="matrixtype" value="'.$_POST['matrixtype'].'">'."\n";
2668                        foreach($participants as $part)
2669                        {
2670                                echo '  <input type="hidden" name="participants[]" value="'.$part.'">'."\n";
2671                        }
2672                        echo '  <input type="submit" name="refresh" value="'.lang('Refresh').'">'."\n";
2673                        echo ' </td><td>'."\n";
2674                        echo '  <input type="submit" name="cancel" value="'.lang('Cancel').'">'."\n";
2675                        echo ' </td></tr></table>'."\n";
2676                        echo '</form>'."\n";
2677                }
2678
2679                function search()
2680                {
2681                        if (empty($_POST['keywords']))
2682                        {
2683                                // If we reach this, it is because they didn't search for anything
2684                                // or they used one of the selectboxes (year, month, week) in the search-result
2685                                // attempt to send them back to where they came from.
2686
2687                                $vars['menuaction'] = isset($_POST['from']) && $_POST['from'] != 'calendar.uicalendar.search' ?
2688                                        $_POST['from'] : 'calendar.uicalendar.index';
2689
2690                                foreach(array('date','year','month','day') as $field)
2691                                {
2692                                        if (isset($_POST[$field]))
2693                                        {
2694                                                $vars[$field] = $_POST[$field];
2695                                        }
2696                                }
2697                                $GLOBALS['phpgw']->redirect_link('/index.php',$vars);
2698                        }
2699
2700                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2701                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2702                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Search Results');
2703                        $GLOBALS['phpgw']->common->phpgw_header();
2704
2705                        $error = '';
2706
2707                        $matches = 0;
2708
2709                        // There is currently a problem searching in with repeated events.
2710                        // It spits back out the date it was entered.  I would like to to say that
2711                        // it is a repeated event.
2712
2713                        // This has been solved by the little icon indicator for recurring events.
2714
2715                        $event_ids = $this->bo->search_keywords($_POST['keywords']);
2716                        foreach($event_ids as $key => $id)
2717                        {
2718                                $event = $this->bo->read_entry($id);
2719
2720                                if(!$this->bo->check_perms(PHPGW_ACL_READ,$event))
2721                                {
2722                                        continue;
2723                                }
2724
2725                                $datetime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2726
2727                                $info[strval($event['id'])] = array(
2728                                        'tr_color'      => $GLOBALS['phpgw']->nextmatchs->alternate_row_color(),
2729                                        'date'          => $GLOBALS['phpgw']->common->show_date($datetime),
2730                                        'link'          => $this->link_to_entry($event,$event['start']['month'],$event['start']['mday'],$event['start']['year'])
2731                                );
2732
2733                        }
2734                        $matches = count($event_ids);
2735
2736                        if ($matches == 1)
2737                        {
2738                                $quantity = lang('1 match found').'.';
2739                        }
2740                        elseif ($matches > 0)
2741                        {
2742                                $quantity = lang('%1 matches found',$matches).'.';
2743                        }
2744                        else
2745                        {
2746                                echo '<b>'.lang('Error').':</b>'.lang('no matches found');
2747                                return;
2748                        }
2749
2750                        $p = $GLOBALS['phpgw']->template;
2751                        $p->set_file(
2752                                Array(
2753                                        'search_form'   => 'search.tpl'
2754                                )
2755                        );
2756                        $p->set_block('search_form','search','search');
2757                        $p->set_block('search_form','search_list_header','search_list_header');
2758                        $p->set_block('search_form','search_list','search_list');
2759                        $p->set_block('search_form','search_list_footer','search_list_footer');
2760
2761                        $var = Array(
2762                                'th_bg'         => $this->theme['th_bg'],
2763                                'search_text'   => lang('Search Results'),
2764                                'quantity'      => $quantity
2765                        );
2766                        $p->set_var($var);
2767
2768                        if($matches > 0)
2769                        {
2770                                $p->parse('rows','search_list_header',True);
2771                        }
2772                        foreach($info as $id => $data)
2773                        {
2774                                $p->set_var($data);
2775                                $p->parse('rows','search_list',True);
2776                        }
2777
2778                        if($matches > 0)
2779                        {
2780                                $p->parse('rows','search_list_footer',True);
2781                        }
2782
2783                        $p->pparse('out','search');
2784                }
2785
2786                /* Private functions */
2787                function _debug_sqsof()
2788                {
2789                        $data = array(
2790                                'filter'     => $this->bo->filter,
2791                                'cat_id'     => $this->bo->cat_id,
2792                                'owner'      => $this->bo->owner,
2793                                'year'       => $this->bo->year,
2794                                'month'      => $this->bo->month,
2795                                'day'        => $this->bo->day,
2796                                'sortby'     => $this->bo->sortby,
2797                                'num_months' => $this->bo->num_months
2798                        );
2799                        Return _debug_array($data,False);
2800                }
2801
2802                function output_template_array(&$p,$row,$list,$var)
2803                {
2804                        if (!isset($var['hidden_vars']))
2805                        {
2806                                $var['hidden_vars'] = '';
2807                        }
2808                        if (!isset($var['tr_color']))
2809                        {
2810                                $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color();
2811                        }
2812                        $p->set_var($var);
2813                        $p->parse($row,$list,True);
2814                }
2815
2816                function page($_page='',$params='')
2817                {
2818                        if($_page == '')
2819                        {
2820                                $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']);
2821                                $_page = $page_[0];
2822
2823                                if ($_page=='planner_cat' || $_page=='planner_user')
2824                                {
2825                                        $_page = 'planner';
2826                                }
2827                                elseif ($_page=='index' || ($_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner'))
2828                                {
2829                                        $_page = 'month';
2830                                        $GLOBALS['phpgw']->preferences->add('calendar','defaultcalendar','month');
2831                                        $GLOBALS['phpgw']->preferences->save_repository();
2832                                }
2833                        }
2834                        if($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' ||
2835                                strstr($GLOBALS['phpgw_info']['flags']['currentapp'],'mail'))   // email, felamimail, ...
2836                        {
2837                                $page_app = 'calendar';
2838                        }
2839                        else
2840                        {
2841                                $page_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
2842                        }
2843                        if (is_array($params))
2844                        {
2845                                $params['menuaction'] = $page_app.'.ui'.$page_app.'.'.$_page;
2846                        }
2847                        else
2848                        {
2849                                $params = 'menuaction='.$page_app.'.ui'.$page_app.'.'.$_page.$params;
2850                        }
2851                        return $GLOBALS['phpgw']->link('/index.php',$params);
2852                }
2853
2854                function header()
2855                {
2856                        $cols = 8;
2857                        if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True)
2858                        {
2859                                $cols++;
2860                        }
2861
2862                        $tpl = $GLOBALS['phpgw']->template;
2863                        $tpl->set_unknowns('remove');
2864
2865                        if (!file_exists($file = $this->template_dir.'/header.inc.php'))
2866                        {
2867                                $file = PHPGW_SERVER_ROOT . '/calendar/templates/default/header.inc.php';
2868                        }
2869                       
2870                        include($file);
2871                        $refer = explode('.',$GLOBALS['HTTP_GET_VARS']['menuaction']);
2872                        if($refer[2] != 'view') {
2873                        $header = $tpl->fp('out','head');
2874                        unset($tpl);
2875                        echo $header;
2876                }
2877                        unset($tpl);
2878                }
2879
2880                function footer()
2881                {
2882                        $menuaction = $_GET['menuaction'];
2883                        list(,,$method) = explode('.',$menuaction);
2884
2885                        if (@$this->bo->printer_friendly)
2886                        {
2887                                return;
2888                        }
2889
2890                        $p = $GLOBALS['phpgw']->template;
2891
2892                        $p->set_file(
2893                                Array(
2894                                        'footer'        => 'footer.tpl',
2895                                        'form_button'   => 'form_button_script.tpl'
2896                                )
2897                        );
2898                        $p->set_block('footer','footer_table','footer_table');
2899                        $p->set_block('footer','footer_row','footer_row');
2900                        $p->set_block('footer','blank_row','blank_row');
2901                        $p->set_block('footer','num_dias','num_dias');
2902
2903                        $m = $this->bo->month;
2904                        $y = $this->bo->year;
2905
2906                        $hoje = date('Ymd',$GLOBALS['phpgw']->datetime->gmtnow);
2907                        $mes_hoje = (int)substr($hoje,4,2);
2908                        $mes_footer = (int)substr($_POST['date'],4,2);
2909                        if($_GET['sday'])
2910                        {
2911                                if($_GET['month'] == $mes_hoje)
2912                                {
2913                                        $day = $this->bo->day;
2914                                }
2915                                else
2916                                {
2917                                        $day = $_GET['sday'];
2918                                }
2919                        }
2920                        else
2921                        {
2922                                $day = $this->bo->day;
2923                                $dia_ini = $day;
2924                        }
2925                        if($mes_footer == $mes_hoje)
2926                        {
2927                                $dia_ini = (int)substr($hoje,6,2);
2928                                $day = $dia_ini;
2929                        }
2930                        /********************************************************************************************/
2931                        /* Bloco adicionado para receber o dia a partir do qual a versao para impressao sera gerada */
2932                        $str_ini = '';
2933                        for ($i = 1; $i <= ($GLOBALS['phpgw']->datetime->days_in_month($m, $y)); $i++)
2934                        {
2935                                $str_ini .= '<option value="'.$i.'"'.($i == $day?' selected':'').'>'.$i.'</option>'."\n";
2936                        }
2937                        $str_qtd = '<option value="'.''.'"'.($i == $_POST['qtd_dias']?' selected':'').'>'.''.'</option>'."\n";
2938                        for ($i = 1; $i <= 45; $i++)
2939                        {
2940                                $str_qtd .= '<option value="'.$i.'"'.($i == $_POST['qtd_dias']?' selected':'').'>'.$i.'</option>'."\n";
2941                        }
2942                        $display = '';
2943                        $display_view = '';
2944                        if ( ($menuaction == 'calendar.uicalendar.week') || ($menuaction == 'calendar.uicalendar.day') )
2945                        {
2946                                $display = 'none';
2947                        }
2948                        else if( ($menuaction == 'calendar.uicalendar.view') )
2949                        {
2950                                $display = 'none';
2951                                $display_view = 'none';
2952                        }
2953                        $var = Array(
2954                                'acao'                  => $this->page($method,''),
2955                                'formname'              => 'SelectDay',
2956                                'formonchange'          => 'document.SelectDay.submit()',
2957                                'day_ini_label'         => lang('print starting in'),
2958                                'num_dias_label'        => lang('quantity of days'),
2959                                'tip'                   => lang('empty prints from the day chosen below to the end of the current month'),
2960                                'day_ini_name'          => 'day',
2961                                'num_dias_name'         => 'qtd_dias',
2962                                'row_ini'               => $str_ini,
2963                                'row_qtd'               => $str_qtd,
2964                                'display'               => $display,
2965                                'display_view'          => $display_view,
2966                                'go'                    => lang('Go!')
2967                                );
2968                        $this->output_template_array($p,'table_row','num_dias',$var);
2969                       
2970                        /********************************************************************************************/
2971
2972                        $thisdate = date('Ymd',mktime(0,0,0,$m,1,$y));
2973                        $y--;
2974
2975                        $str = '';
2976                        for ($i = 0; $i < 20; $i++)
2977                        {
2978                                $m++;
2979                                if ($m > 12)
2980                                {
2981                                        $m = 1;
2982                                        $y++;
2983                                }
2984                                $d = mktime(0,0,0,$m,1,$y);
2985                                $d_ymd = date('Ymd',$d);
2986                                $str .= '<option value="'.$d_ymd.'"'.($d_ymd == $thisdate?' selected':'').'>'.lang(date('F', $d)).strftime(' %Y', $d).'</option>'."\n";
2987                        }
2988
2989                        $var = Array(
2990                                'action_url'    => $this->page($method,''),
2991                                'form_name'     => 'SelectMonth',
2992                                'label'         => lang('Month'),
2993                                'form_label'    => 'date',
2994                                'form_onchange' => 'document.SelectMonth.submit()',
2995                                'row'           => $str,
2996                                'dia_ini'       => $dia_ini,
2997                                'go'            => lang('Go!')
2998                        );
2999                        $this->output_template_array($p,'table_row','footer_row',$var);
3000
3001                        if($menuaction == 'calendar.uicalendar.week')
3002                        {
3003                                unset($thisdate);
3004                                $thisdate = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
3005                                $sun = $GLOBALS['phpgw']->datetime->get_weekday_start($this->bo->year,$this->bo->month,$this->bo->day) - $GLOBALS['phpgw']->datetime->tz_offset;
3006
3007                                $str = '';
3008                                for ($i = -7; $i <= 7; $i++)
3009                                {
3010                                        $begin = $sun + (7*24*60*60 * $i) + 12*60*60;   // we use midday, that changes in daylight-saveing does not effect us
3011                                        $end = $begin + 6*24*60*60;
3012//                                      echo "<br>$i: ".date('d.m.Y H:i',$begin).' - '.date('d.m.Y H:i',$end);
3013                    $str .= '<option value="' . $GLOBALS['phpgw']->common->show_date($begin,'Ymd') . '"'.($begin <= $thisdate+12*60*60 && $end >= $thisdate+12*60*60 ? ' selected':'').'>'                   
3014                                                . $GLOBALS['phpgw']->common->show_date($begin,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) . ' - '
3015                        . $GLOBALS['phpgw']->common->show_date($end,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
3016                        . '</option>' . "\n";                       
3017                                }
3018
3019                                $var = Array(
3020                                        'action_url'    => $this->page($method,''),
3021                                        'form_name'     => 'SelectWeek',
3022                                        'label'         => lang('Week'),
3023                                        'form_label'    => 'date',
3024                                        'form_onchange' => 'document.SelectWeek.submit()',
3025                                        'row'           => $str,
3026                                        'go'            => lang('Go!')
3027                                );
3028
3029                                $this->output_template_array($p,'table_row','footer_row',$var);
3030                        }
3031
3032                        $str = '';
3033                        for ($i = ($this->bo->year - 3); $i < ($this->bo->year + 3); $i++)
3034                        {
3035                                $str .= '<option value="'.$i.'"'.($i == $this->bo->year?' selected':'').'>'.$i.'</option>'."\n";
3036                        }
3037
3038                        $var = Array(
3039                                'action_url'    => $this->page($method,''),
3040                                'form_name'     => 'SelectYear',
3041                                'label'         => lang('Year'),
3042                                'form_label'    => 'year',
3043                                'form_onchange' => 'document.SelectYear.submit()',
3044                                'row'           => $str,
3045                                'go'            => lang('Go!')
3046                        );
3047                        $this->output_template_array($p,'table_row','footer_row',$var);
3048
3049                        if($menuaction == 'calendar.uicalendar.planner')
3050                        {
3051                                $str = '';
3052                                $date_str = '';
3053
3054                                if(isset($_GET['date']) && $_GET['date'])
3055                                {
3056                                        $date_str .= '    <input type="hidden" name="date" value="'.$_GET['date'].'">'."\n";
3057                                }
3058                                $date_str .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
3059                                $date_str .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
3060                                $date_str .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
3061
3062                                for($i=1; $i<=6; $i++)
3063                                {
3064                                        $str .= '<option value="'.$i.'"'.($i == $this->bo->num_months?' selected':'').'>'.$i.'</option>'."\n";
3065                                }
3066
3067                                $var = Array(
3068                                        'action_url'    => $this->page($method,''),
3069                                        'form_name'     => 'SelectNumberOfMonths',
3070                                        'label'         => lang('Number of Months'),
3071                                        'hidden_vars' => $date_str,
3072                                        'form_label'    => 'num_months',
3073                                        'form_onchange' => 'document.SelectNumberOfMonths.submit()',
3074                                        'action_extra_field'    => $date_str,
3075                                        'row'           => $str,
3076                                        'go'            => lang('Go!')
3077                                );
3078                                $this->output_template_array($p,'table_row','footer_row',$var);
3079                        }
3080
3081                        $var = Array(
3082                                'submit_button'         => lang('Submit'),
3083                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uiicalendar.import'),
3084                                'action_text_button'    => lang('Import'),
3085                                'action_confirm_button' => '',
3086                                'action_extra_field'    => ''
3087                        );
3088                        $this->output_template_array($p,'b_row','form_button',$var);
3089                       
3090                        $var = Array(
3091                                'submit_button'         => lang('Submit'),
3092                                'action_url'    => $this->page($method,''),
3093                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.export_all'),
3094                                'action_text_button'    => lang('Export all'),
3095                                'action_confirm_button' => '',
3096                                'action_extra_field'    => ''
3097                        );
3098                        $this->output_template_array($p,'b_row2','form_button',$var);
3099                                       
3100                        $p->parse('table_row','blank_row',True);
3101
3102                        $p->pparse('out','footer_table');
3103                        unset($p);
3104                }
3105
3106                function css()
3107                {
3108                        $GLOBALS['phpgw']->browser->browser();
3109                        if($GLOBALS['phpgw']->browser->get_agent() == 'MOZILLA')
3110                        {
3111                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?12:8);
3112                        }
3113                        else
3114                        {
3115                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?10:7);
3116                        }
3117
3118// moved to app.css in templates/default for future separation of code and style [NDEE 10.03.04]
3119/*
3120                         return 'A.minicalendar { color: #000000; font-size: 72%; font-family: '.$this->theme['font'].' }'."\n"
3121                                . '  A.bminicalendar { color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3122                                . '  A.minicalendargrey { color: #999999; font-size: 8px; font-family: '.$this->theme['font'].' }'."\n"
3123                                . '  A.bminicalendargrey { color: #336699; font-style: italic; font-size:8px; font-family '.$this->theme['font'].' }'."\n"
3124                                . '  A.minicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #000000; font: x-small '.$this->theme['font'].' }'."\n"
3125                                . '  A.bminicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3126                                . '  A.minicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: x-small '.$this->theme['font'].' }'."\n"
3127                                . '  A.bminicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3128                                . '  .event-on { background: '.$this->theme['row_on'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3129                                . '  .event-off { background: '.$this->theme['row_off'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3130                                . '  .event-holiday { background: '.$this->theme['bg04'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3131                                . '  .time { background: '.$this->theme['th_bg'].'; color: '.$this->theme['bg_text'].'; font: bold 100% '.$this->theme['font'].'; width: '.$time_width.'%; vertical-align: middle; text-align: right; }'."\n"
3132                                . '  .tablecell { width: 80px; height: 80px }'."\n"
3133                                . '  .planner-cell { cursor:pointer; cursor:hand; border: thin solid black; }';
3134*/
3135                }
3136
3137                function no_edit()
3138                {
3139                        if(!isset($GLOBALS['phpgw_info']['flags']['noheader']))
3140                        {
3141                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
3142                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3143                                $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3144                                $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3145                                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Permission denied');
3146                                $GLOBALS['phpgw']->common->phpgw_header();
3147                        }
3148                        echo '<center>You do not have permission to edit this appointment!</center>';
3149                        return;
3150                }
3151
3152                function link_to_entry($event,$month,$day,$year)
3153                {
3154                        $str = '';
3155                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
3156                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
3157
3158                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
3159                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3160                        $rawdate = mktime(0,0,0,$month,$day,$year);
3161                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
3162                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3163                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
3164                        {
3165                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3166                        }
3167                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
3168                        {
3169                                $time = '[ '.lang('All Day').' ]';
3170                        }
3171                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
3172                        {
3173                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
3174                                {
3175                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
3176                                }
3177                                else
3178                                {
3179                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3180                                }
3181
3182                                if($endtime >= ($rawdate_offset + 86400))
3183                                {
3184                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
3185                                }
3186                                else
3187                                {
3188                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
3189                                }
3190                                $time = $start_time.'-'.$end_time;
3191                        }
3192                        else
3193                        {
3194                                $time = '';
3195                        }
3196                       
3197                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
3198
3199                       
3200                       
3201                        if(!$is_private)
3202                        {
3203                                //$text .= $this->bo->display_status($event['users_status']);
3204                               
3205                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
3206                                $textstatus=$this->bo->display_status($event['users_status']);
3207                               
3208                        }
3209
3210                        /*
3211                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
3212                                (!$is_private && $event['description'] ? ': <i>'.$this->bo->get_short_field($event,$is_private,'description').'</i>':'').
3213                                $GLOBALS['phpgw']->browser->br;
3214                        */
3215                       
3216                        $texttime=$time;
3217                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
3218                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
3219                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
3220                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
3221
3222                        if ($viewable)
3223                        {
3224                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
3225                                $this->link_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
3226                                $this->link_tpl->set_var('lang_view',lang('View this entry'));
3227                                $this->link_tpl->set_var('desc', $textdesc);
3228                                $this->link_tpl->set_var('location', $textlocation);
3229                                $this->link_tpl->parse('picture','link_open',True);
3230                        }
3231                        if (!$is_private)
3232                        {
3233                                if($event['priority'] == 3)
3234                                {
3235                                        $picture[] = Array(
3236                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
3237                                                'width' => 16,
3238                                                'height'=> 16,
3239                                                'title' => lang('high priority')
3240                                        );
3241                                }
3242                                if($event['recur_type'] == MCAL_RECUR_NONE)
3243                                {
3244                                        $picture[] = Array(
3245                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
3246                                                'width' => 9,
3247                                                'height'=> 9,
3248                                                'title' => lang('single event')
3249                                        );
3250                                }
3251                                else
3252                                {
3253                                        $picture[] = Array(
3254                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
3255                                                'width' => 12,
3256                                                'height'=> 12,
3257                                                'title' => lang('recurring event')
3258                                        );
3259                                }
3260                        }
3261                        $participants = $this->planner_participants($event['participants']);
3262                        if(count($event['participants']) > 1)
3263                        {
3264                                $picture[] = Array(
3265                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
3266                                        'width' => 14,
3267                                        'height'=> 14,
3268                                        'title' => $participants
3269                                );
3270                        }
3271                        else
3272                        {
3273                                $picture[] = Array(
3274                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
3275                                        'width' => 14,
3276                                        'height'=> 14,
3277                                        'title' => $participants
3278                                );
3279                        }
3280                        if($event['public'] == 0)
3281                        {
3282                                $picture[] = Array(
3283                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
3284                                        'width' => 13,
3285                                        'height'=> 13,
3286                                        'title' => lang('private')
3287                                );
3288                        }
3289                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
3290                        {
3291                                // if the alarm is to go off the day before the event
3292                                // the icon does not show up because of 'alarm_today'
3293                                // - TOM
3294                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
3295                                {
3296                                        $picture[] = Array(
3297                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
3298                                                'width' => 13,
3299                                                'height'=> 13,
3300                                                'title' => lang('alarm')
3301                                        );
3302                                }
3303                        }
3304
3305                        $description = $this->bo->get_short_field($event,$is_private,'description');
3306                        for($i=0;$i<count($picture);$i++)
3307                        {
3308                                $var = Array(
3309                                        'pic_image' => $picture[$i]['pict'],
3310                                        'width'     => $picture[$i]['width'],
3311                                        'height'    => $picture[$i]['height'],
3312                                        'title'     => $picture[$i]['title']
3313                                );
3314                                $this->output_template_array($this->link_tpl,'picture','pict',$var);
3315                        }
3316                        if ($texttitle)
3317                        {
3318                                $var = Array(
3319                        //              'text' => $text,
3320                                        'time'=> $texttime,
3321                                        'title'=> $texttitle,
3322                                        'users_status'=>$textstatus,
3323                                        'desc'=> $textdesc,
3324                                        'location'=> "<br><b>Local:</b> ".$textlocation
3325                                );
3326                                $this->output_template_array($this->link_tpl,'picture','link_text',$var);
3327                        }
3328
3329                        if ($viewable)
3330                        {
3331                                $this->link_tpl->parse('picture','link_close',True);
3332                        }
3333                        $str = $this->link_tpl->fp('out','link_pict');
3334                        $this->link_tpl->set_var('picture','');
3335                        $this->link_tpl->set_var('out','');
3336//                      unset($p);
3337                        return $str;
3338                }
3339
3340/*****************************************************************************************/
3341/*Funcao foi duplicada e alterada para tratar os eventos de agendamento (exibicao do mes) para impressao;
3342utiliza o template event_link.tpl*/
3343
3344                function link_to_month_entry($event,$month,$day,$year)
3345                {
3346                        $str = '';
3347                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
3348                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
3349
3350                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
3351                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3352                        $rawdate = mktime(0,0,0,$month,$day,$year);
3353                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
3354                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3355                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
3356                        {
3357                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3358                        }
3359                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
3360                        {
3361                                $time = '[ '.lang('All Day').' ]';
3362                        }
3363                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
3364                        {
3365                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
3366                                {
3367                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
3368                                }
3369                                else
3370                                {
3371                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3372                                }
3373
3374                                if($endtime >= ($rawdate_offset + 86400))
3375                                {
3376                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
3377                                }
3378                                else
3379                                {
3380                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
3381                                }
3382                                $time = $start_time.' - '.$end_time;
3383                        }
3384                        else
3385                        {
3386                                $time = '';
3387                        }
3388                       
3389                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
3390
3391                       
3392                       
3393                        if(!$is_private)
3394                        {
3395                                //$text .= $this->bo->display_status($event['users_status']);
3396                               
3397                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
3398                                $textstatus=$this->bo->display_status($event['users_status']);
3399                               
3400                        }
3401
3402                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
3403                       
3404                        $texttime=$time;
3405                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
3406                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
3407                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
3408                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
3409
3410                        if ($viewable)
3411                        {
3412                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
3413                                $this->event_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
3414                                $this->event_tpl->set_var('lang_view',lang('View this entry'));
3415                                $this->event_tpl->set_var('desc', $textdesc);
3416                                $this->event_tpl->set_var('location', $textlocation);
3417                                $this->event_tpl->parse('picture','link_event_open',True);
3418                        }
3419                        if (!$is_private)
3420                        {
3421                                if($event['priority'] == 3)
3422                                {
3423                                        $picture[] = Array(
3424                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
3425                                                'width' => 16,
3426                                                'height'=> 16,
3427                                                'title' => lang('high priority')
3428                                        );
3429                                }
3430                                if($event['recur_type'] == MCAL_RECUR_NONE)
3431                                {
3432                                        $picture[] = Array(
3433                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
3434                                                'width' => 9,
3435                                                'height'=> 9,
3436                                                'title' => lang('single event')
3437                                        );
3438                                }
3439                                else
3440                                {
3441                                        $picture[] = Array(
3442                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
3443                                                'width' => 12,
3444                                                'height'=> 12,
3445                                                'title' => lang('recurring event')
3446                                        );
3447                                }
3448                        }
3449                        $participants = $this->planner_participants($event['participants']);
3450                        if(count($event['participants']) > 1)
3451                        {
3452                                $picture[] = Array(
3453                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
3454                                        'width' => 14,
3455                                        'height'=> 14,
3456                                        'title' => $participants
3457                                );
3458                        }
3459                        else
3460                        {
3461                                $picture[] = Array(
3462                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
3463                                        'width' => 14,
3464                                        'height'=> 14,
3465                                        'title' => $participants
3466                                );
3467                        }
3468                        if($event['public'] == 0)
3469                        {
3470                                $picture[] = Array(
3471                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
3472                                        'width' => 13,
3473                                        'height'=> 13,
3474                                        'title' => lang('private')
3475                                );
3476                        }
3477                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
3478                        {
3479                                // if the alarm is to go off the day before the event
3480                                // the icon does not show up because of 'alarm_today'
3481                                // - TOM
3482                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
3483                                {
3484                                        $picture[] = Array(
3485                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
3486                                                'width' => 13,
3487                                                'height'=> 13,
3488                                                'title' => lang('alarm')
3489                                        );
3490                                }
3491                        }
3492
3493                        $description = $this->bo->get_short_field($event,$is_private,'description');
3494                        for($i=0;$i<count($picture);$i++)
3495                        {
3496                                $var = Array(
3497                                        'pic_image' => $picture[$i]['pict'],
3498                                        'width'     => $picture[$i]['width'],
3499                                        'height'    => $picture[$i]['height'],
3500                                        'title'     => $picture[$i]['title']
3501                                );
3502                                $this->output_template_array($this->event_tpl,'picture','event_pict',$var);
3503                        }
3504                        if ($texttitle)
3505                        {
3506                                $var = Array(
3507                        //              'text' => $text,
3508                                        'time'=> $texttime,
3509                                        'title'=> $texttitle,
3510                                        'users_status'=>$textstatus,
3511                                        'desc'=> $textdesc,
3512                                        'location'=> "<br><b>Local:</b> ".$textlocation
3513                                );
3514                                $this->output_template_array($this->event_tpl,'picture','link_event_text',$var);
3515                        }
3516
3517                        if ($viewable)
3518                        {
3519                                $this->event_tpl->parse('picture','link_event_close',True);
3520                        }
3521                        $str = $this->event_tpl->fp('out','link_event_pict');
3522                        $this->event_tpl->set_var('picture','');
3523                        $this->event_tpl->set_var('out','');
3524//                      unset($p);
3525                        return $str;
3526                }
3527
3528/*****************************************************************************************/
3529                function normDec($num)
3530                {
3531                        if ($num > 9)
3532                                return $num;
3533                        else
3534                                return "0".$num;
3535                }
3536                function overlap($params)
3537                {
3538                        if(!is_array($params))
3539                        {
3540                        }
3541                        else
3542                        {
3543                                $overlapping_events = $params['o_events'];
3544                                $event = $params['this_event'];
3545                        }
3546
3547                        $month = $event['start']['month'];
3548                        $mday = $event['start']['mday'];
3549                        $year = $event['start']['year'];
3550
3551                        $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3552                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3553
3554                        $overlap = '';
3555                        for($i=0;$i<count($overlapping_events);$i++)
3556                        {
3557                                $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True);
3558                                foreach($overlapped_event['participants'] as $id => $status)
3559                                {
3560                                        $conflict = isset($event['participants'][$id]);
3561                                        $overlap .= '<li>'.($conflict?'<b>':'').
3562                                                $GLOBALS['phpgw']->common->grab_owner_name($id).
3563                                                ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>";
3564                                }
3565                         if ($this->bo->prefs['calendar']['hide_event_conflict'])
3566                                 $overlap .= '<ul><font size="1"><span>'.
3567                                         $this->normDec($overlapped_event['start']['hour']).":".
3568                                         $this->normDec($overlapped_event['start']['min'])."-".
3569                                         $this->normDec($overlapped_event['end']['hour']).":".
3570                                         $this->normDec($overlapped_event['end']['min']).
3571                                         '<br><b>'.lang('title').": ".lang("Hidden").
3572                                         '</b><br>'.lang('description').": ".lang("Hidden").'<br></span></ul><br>';
3573                         else
3574                                 $overlap .= '<ul>'.$this->link_to_entry($overlapped_event,$month,$mday,$year)."</ul><br>";     
3575                        }
3576
3577                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
3578                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3579                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3580                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3581                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict');
3582                        $GLOBALS['phpgw']->common->phpgw_header();
3583
3584                        $p = $GLOBALS['phpgw']->template;
3585                        $p->set_file(
3586                                Array(
3587                                        'overlap'       => 'overlap.tpl',
3588                                        'form_button'   => 'form_button_script.tpl'
3589                                )
3590                        );
3591
3592                        $var = Array(
3593                                'color'         => $this->theme['bg_text'],
3594                                'overlap_title' => lang('Scheduling Conflict'),
3595                                'overlap_text'  => lang('Your suggested time of <B> %1 - %2 </B> conflicts with the following existing calendar entries:',$GLOBALS['phpgw']->common->show_date($start),$GLOBALS['phpgw']->common->show_date($end)),
3596                                'overlap_list'  => $overlap
3597                        );
3598                        $p->set_var($var);
3599
3600                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday);
3601                        $var = Array(
3602                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update','readsess'=>1)),
3603                                'action_text_button'    => lang('Ignore Conflict'),
3604                                'action_confirm_button' => '',
3605                                'action_extra_field'    => '',
3606                                'button_id'             => 'ignore_button'
3607                        );
3608                        $this->output_template_array($p,'resubmit_button','form_button',$var);
3609
3610                        $var = Array(
3611                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.edit','readsess'=>1,'date'=>$date)),
3612                                'action_text_button'    => lang('Re-Edit Event'),
3613                                'action_confirm_button' => '',
3614                                'action_extra_field'    => '',
3615                                'button_id'             => 'redit_button'
3616                        );
3617                        $this->output_template_array($p,'reedit_button','form_button',$var);
3618                        $p->pparse('out','overlap');
3619                }
3620
3621                function planner_participants($parts)
3622                {
3623                        static $id2lid;
3624
3625                        $names = '';
3626                        while (list($id,$status) = each($parts))
3627                        {
3628                                $status = substr($this->bo->get_long_status($status),0,1);
3629
3630                                if (!isset($id2lid[$id]))
3631                                {
3632                                        $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id);
3633                                }
3634                                if (strlen($names))
3635                                {
3636                                        $names .= ",\n";
3637                                }
3638                                $names .= $id2lid[$id]." ($status)";
3639                        }
3640                        if($this->debug)
3641                        {
3642                                echo '<!-- Inside participants() : '.$names.' -->'."\n";
3643                        }
3644                        return $names;
3645                }
3646
3647                function planner_category($ids)
3648                {
3649                        static $cats;
3650                        if(!is_array($ids))
3651                        {
3652                                if (strpos($ids,','))
3653                                {
3654                                        $id_array = explode(',',$ids);
3655                                }
3656                                else
3657                                {
3658                                        $id_array[0] = $ids;
3659                                }
3660                        }
3661                        @reset($id_array);
3662                        $ret_val = Array();
3663                        while(list($index,$id) = each($id_array))
3664                        {
3665                                if (!isset($cats[$id]))
3666                                {
3667                                        $cat_arr = $this->cat->return_single( $id );
3668                                        $cats[$id] = $cat_arr[0];
3669                                        $cats[$id]['color'] = strstr($cats[$id]['description'],'#');
3670                                }
3671                                $ret_val[] = $cats[$id];
3672                        }
3673                        return $ret_val;
3674                }
3675
3676                function week_header($month,$year,$display_name = False)
3677                {
3678                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3679
3680                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3681                        $p->set_unknowns('remove');
3682                        $p->set_file(
3683                                Array (
3684                                        'month_header' => 'month_header.tpl'
3685                                )
3686                        );
3687                        $p->set_block('month_header','monthly_header','monthly_header');
3688                        $p->set_block('month_header','column_title','column_title');
3689
3690                        $var = Array(
3691                                'bgcolor'       => $this->theme['th_bg'],
3692                                'font_color'    => $this->theme['th_text']
3693                        );
3694                        if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
3695                        {
3696                                $var = Array(
3697                                        'bgcolor'       => '',
3698                                        'font_color'    => ''
3699                                );
3700                        }
3701                        $p->set_var($var);
3702
3703                        $p->set_var('col_width','14');
3704                        if($display_name == True)
3705                        {
3706                                $p->set_var('col_title',lang('name'));
3707                                $p->parse('column_header','column_title',True);
3708                                $p->set_var('col_width','12');
3709                        }
3710
3711                        for($i=0;$i<7;$i++)
3712                        {
3713                                $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
3714                                $p->parse('column_header','column_title',True);
3715                        }
3716                        return $p->fp('out','monthly_header');
3717                }
3718
3719                function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3720                {
3721                        if($owner == 0)
3722                        {
3723                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3724                        }
3725
3726                        $temp_owner = $this->bo->owner;
3727
3728                        $str = '';
3729                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3730                        $p->set_unknowns('keep');
3731
3732                        $p->set_file(
3733                                Array(
3734                                        'month_header'  => 'month_header.tpl',
3735                                        'month_day'     => 'month_day.tpl'
3736                                )
3737                        );
3738                        $p->set_block('month_header','monthly_header','monthly_header');
3739                        $p->set_block('month_header','month_column','month_column');
3740                        $p->set_block('month_day','month_daily','month_daily');
3741                        $p->set_block('month_day','day_event','day_event');
3742                        $p->set_block('month_day','event','event');
3743
3744                        $p->set_var('extra','');
3745                        $p->set_var('col_width','14');
3746                        if($display_name)
3747                        {
3748                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
3749                                $p->parse('column_header','month_column',True);
3750                                $p->set_var('col_width','12');
3751                        }
3752                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3753                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3754                        foreach($daily as $date => $day_params)
3755                        {
3756                                $year  = (int)substr($date,0,4);
3757                                $month = (int)substr($date,4,2);
3758                                $day   = (int)substr($date,6,2);
3759                                $var   = Array(
3760                                        'column_data' => '',
3761                                        'extra' => ''
3762                                );
3763                                $p->set_var($var);
3764                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
3765                                {
3766                                        if ($day_params['new_event'])
3767                                        {
3768                                                $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
3769                                                        . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
3770                                                        . '</a>';
3771                                                $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
3772                                        }
3773                                        else
3774                                        {
3775                                                $new_event_link = '';
3776                                                $day_number = $day;
3777                                        }
3778
3779                                        $var = Array(
3780                                                'extra'         => $day_params['extra'],
3781                                                'new_event_link'=> $new_event_link,
3782                                                'day_number'    => $day_number
3783                                        );
3784                                        if($day_params['week'])
3785                                        {
3786
3787//NDEE: style! m_w_table in month_day.tpl
3788// week-hilite
3789                                                //$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
3790                                                $var['new_event_link'] .= ' &nbsp; '.
3791                                                        (!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'"><span id="calendar_weekinfo" class="calendar_weekinfo">' .$day_params['week'].'</span></a>' : '<span id="calendar_weekinfo" class="calendar_weekinfo">'.$day_params['week'].'</span>');
3792                                        }
3793
3794                                        $p->set_var($var);
3795
3796                                        if(@$day_params['holidays'])
3797                                        {
3798                                                foreach($day_params['holidays'] as $key => $value)
3799                                                {
3800                                                        $var = Array(
3801                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
3802                                                        );
3803                                                        $this->output_template_array($p,'daily_events','event',$var);
3804                                                }
3805                                        }
3806
3807                                        if($day_params['appts'])
3808                                        {
3809                                                $var = Array(
3810                                                        'week_day_font_size'    => '2',
3811                                                        'events'                => ''
3812                                                );
3813                                                $p->set_var($var);
3814                                                $events = $this->bo->cached_events[$date];
3815                                                foreach($events as $event)
3816                                                {
3817                                                        if ($this->bo->rejected_no_show($event))
3818                                                        {
3819                                                                continue;       // user does not want to see rejected events
3820                                                        }
3821                                                        $p->set_var('day_events',$this->link_to_entry($event,$month,$day,$year));
3822                                                        $p->parse('events','event',True);
3823                                                        $p->set_var('day_events','');
3824                                                }
3825                                        }
3826                                        $p->parse('daily_events','day_event',True);
3827                                        $p->parse('column_data','month_daily',True);
3828                                        $p->set_var('daily_events','');
3829                                        $p->set_var('events','');
3830/*                                      if($day_params['week'])
3831                                        {
3832                                                $var = Array(
3833                                                        'week_day_font_size'    => '-2',
3834                                                        'events'                => (!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'">' .$day_params['week'].'</a>':$day_params['week'])
3835                                                );
3836                                                $this->output_template_array($p,'column_data','day_event',$var);
3837                                                $p->set_var('events','');
3838                                        } */
3839                                }
3840                                $p->parse('column_header','month_column',True);
3841                                $p->set_var('column_data','');
3842                        }
3843                        $this->bo->owner = $temp_owner;
3844                        return $p->fp('out','monthly_header');
3845                }
3846
3847/***************************************************************************************/
3848/*As funcoes abaixo
3849        month_week_header()
3850        month_display_week()
3851        display_month_print()
3852        month_day_of_week() - esta foi criada mas parte do codigo e de outra funcao da API (day_of_week());
3853
3854  foram duplicadas e modificadas para atender aas modificacoes do layout de impressao mensal da agenda de eventos;
3855  TODO: otimizar o codigo
3856
3857  Rommel Cysne
3858*/
3859
3860                function month_week_header($month,$year,$display_name = False)
3861                {
3862                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3863                        $p->set_unknowns('remove');
3864                }
3865
3866
3867                function month_day_of_week($year,$month,$day)
3868                {
3869                        $dia = Array(
3870                                0 => 'Domingo',
3871                                1 => 'Segunda',
3872                                2 => 'Ter&ccedil;a',
3873                                3 => 'Quarta',
3874                                4 => 'Quinta',
3875                                5 => 'Sexta',
3876                                6 => 'S&aacute;bado'
3877                        );
3878
3879                        if($month > 2)
3880                        {
3881                                $month -= 2;
3882                        }
3883                                else
3884                        {
3885                                $month += 10;
3886                                $year--;
3887                        }
3888                        $day = (floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * floor($year / 100) + 77);
3889
3890                        $month_day = ($day - 7 * floor($day / 7)); //retorna o numero do dia da semana (Ex: domingo eh dia 0, terca eh 2);
3891                        $weekday = $dia[$month_day]; //retorna o nome do dia da semana de acordo com seu numero;
3892
3893                        return ($weekday);
3894
3895                }
3896
3897                function month_display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3898                {
3899                        if($owner == 0)
3900                        {
3901                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3902                        }
3903
3904                        $temp_owner = $this->bo->owner;
3905
3906                        $str = '';
3907                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3908                        $p->set_unknowns('keep');
3909
3910                        $p->set_file(
3911                                Array(
3912                                        'month_header'  => 'month_header_print.tpl',
3913                                        'month_day'     => 'month_day_print.tpl'
3914                                )
3915                        );
3916                        $p->set_block('month_header','monthly_header','monthly_header');
3917                        $p->set_block('month_header','month_column','month_column');
3918                        $p->set_block('month_day','month_daily','month_daily');
3919                        $p->set_block('month_day','day_event','day_event');
3920                        $p->set_block('month_day','event','event');
3921
3922                        $p->set_var('extra','');
3923                        $p->set_var('col_width','14');
3924                       
3925                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3926                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3927
3928                        foreach($daily as $date => $day_params)
3929                        {
3930                                $year  = (int)substr($date,0,4);
3931                                $month = (int)substr($date,4,2);
3932                                $day   = (int)substr($date,6,2);
3933                                $var   = Array(
3934                                        'column_data' => '',
3935                                        'extra' => ''
3936                                );
3937                                $p->set_var($var);
3938                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
3939                                {
3940                                        $new_event_link = '';
3941                                        $day_num = $day;
3942                                        $dia_semana = $this->month_day_of_week($year,$month,$day_num);
3943                                        $id_aux = mktime(0,0,0,$month,$day,$year);
3944                                        $month_identifier = substr(lang(strftime("%B",$id_aux)),0,3);
3945                                        $day_number = $month_identifier . " - " . $dia_semana . ",  " . $day_num;
3946
3947                                        $var = Array(
3948                                                'extra'         => $day_params['extra'],
3949                                                'new_event_link'=> $new_event_link,
3950                                                'day_number'    => $day_number
3951                                        );
3952
3953                                        $p->set_var($var);
3954
3955                                        if($day_params['appts'])
3956                                        {
3957                                                $var = Array(
3958                                                        'week_day_font_size'    => '2',
3959                                                        'events'                => ''
3960                                                );
3961                                                $p->set_var($var);
3962                                                $events = $this->bo->cached_events[$date];
3963                                                foreach($events as $event)
3964                                                {
3965                                                        if ($this->bo->rejected_no_show($event))
3966                                                        {
3967                                                                continue;       // user does not want to see rejected events
3968                                                        }
3969                                                        $p->set_var('day_events',$this->link_to_month_entry($event,$month,$day,$year));
3970                                                        $p->parse('events','event',True);
3971                                                        $p->set_var('day_events','');
3972                                                }
3973                                        }
3974                                        $p->parse('daily_events','day_event',True);
3975                                        $p->parse('column_data','month_daily',True);
3976                                        $p->set_var('daily_events','');
3977                                        $p->set_var('events','');
3978                                }
3979                                $p->parse('column_header','month_column',True);
3980                                $p->set_var('column_data','');
3981                        }
3982                        $this->bo->owner = $temp_owner;
3983                        return $p->fp('out','monthly_header');
3984
3985                }
3986
3987                function display_month_print($month,$year,$showyear,$owner=0)
3988                {
3989                        if($this->debug)
3990                        {
3991                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
3992                        }
3993
3994/*                      $this->bo->store_to_cache(
3995                                Array(
3996                                        'syear' => $year,
3997                                        'smonth'=> $month,
3998                                        'sday'  => 1
3999                                )
4000                        );
4001*/
4002                        $day_ini = $_GET['day_ini'];// dia do inicio da impressao; o padrao e o dia atual;
4003                        $num_dias = $_GET['num_dias'];// quantidade de dias a partir do dia inicial;
4004
4005                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
4006//                      $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4007
4008                        if($num_dias != 0)
4009                        {
4010                                //se a qtde de dias for informada, a data final para impressao considera a soma $day_ini+$num_dias;
4011                                $monthend   = (int)(date('Ymd',mktime(0,0,0,$month,$day_ini+$num_dias,$year)));
4012                        }
4013                        else
4014                        {
4015                                //se a qtde de dias nao for informada, a data final para impressao vai ate o fim do mes corrente;
4016                                $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4017                        }
4018                       
4019                        if($day_ini != 0)
4020                        {
4021                                //o dia de inicio para impressao passa a ser o informado em $day_ini do mes corrente;
4022                                $start = mktime(0,0,0,$month,$day_ini,$year);
4023                        }
4024                        else
4025                        {
4026                                //se nao for informado o dia para inicio da impressao, esta comeca no dia 1 do mes corrente;
4027                                $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
4028                        }
4029                        //$start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 15);
4030                        $start_d = (int)(date('Ymd',$start));//variavel auxiliar que recebe a data inicial de impressao no formato 'Ymd';
4031                        $saux = (int)(substr($start_d,4,2));//variavel auxiliar que recebe o mes do inicio da impressao;
4032                        $eaux = (int)(substr($monthend,4,2)) + 1;//variavel auxiliar que recebe o mes do fim da impressao;
4033                        //A funcao store_to_cache devolve todos os eventos existentes de determinado usuario em um periodo de tempo
4034                        //especifico. Originalmente, na impressao mensal, esse periodo de tempo era o mes corrente exibido na tela.
4035                        //A mudanca consiste no fato de que uma nova variavel ($saux) e enviada com o mes de inicio do periodo
4036                        //atraves do indice 'smonth' e uma segunda variavel ($eaux) envia o mes final do periodo de tempo atraves
4037                        //do indice 'emonth'. Vide mais comentarios sobre esses valores em class.bocalendar.inc.php,
4038                        //function store_to_cache($params);
4039                        $this->bo->store_to_cache(
4040                        Array(
4041                                'syear' => $year,//ano atual
4042                                'smonth'=> $saux,//mes inicial
4043                                'emonth'=> $eaux,//mes final
4044                                'sday'  => 1
4045                        ));
4046
4047                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4048                        $p->set_unknowns('keep');
4049
4050                        $p->set_file(
4051                                Array(
4052                                        'week' => 'month_day_print.tpl'
4053                                )
4054                        );
4055                        $p->set_block('week','m_w_table','m_w_table');
4056                        $p->set_block('week','event','event');
4057
4058                        $var = Array(
4059                                'cols'      => 1,
4060                                'day_events'=> '' //$this->month_week_header($month,$year,False)
4061                        );
4062//                      $this->output_template_array($p,'row','event',$var);
4063
4064                        $cellcolor = $this->theme['row_on'];
4065
4066                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
4067                        {
4068                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
4069                                $var = Array(
4070                                        'day_events' => $this->month_display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
4071                                );
4072                                $this->output_template_array($p,'row','event',$var);
4073                        }
4074                        return $p->fp('out','m_w_table');
4075                }
4076
4077
4078/***************************************************************************************/
4079
4080                function display_month($month,$year,$showyear,$owner=0)
4081                {
4082                        if($this->debug)
4083                        {
4084                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
4085                        }
4086
4087                        $this->bo->store_to_cache(
4088                                Array(
4089                                        'syear' => $year,
4090                                        'smonth'=> $month,
4091                                        'sday'  => 1
4092                                )
4093                        );
4094
4095                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
4096                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4097
4098                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
4099
4100                        if($this->debug)
4101                        {
4102                                echo '<!-- display_month:monthstart = '.$monthstart.' -->'."\n";
4103                                echo '<!-- display_month:start = '.date('Ymd H:i:s',$start).' -->'."\n";
4104                        }
4105
4106                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4107                        $p->set_unknowns('keep');
4108
4109                        $p->set_file(
4110                                Array(
4111                                        'week' => 'month_day.tpl'
4112                                )
4113                        );
4114                        $p->set_block('week','m_w_table','m_w_table');
4115                        $p->set_block('week','event','event');
4116
4117                        $var = Array(
4118                                'cols'      => 1,
4119                                'day_events'=> $this->week_header($month,$year,False)
4120                        );
4121                        $this->output_template_array($p,'row','event',$var);
4122
4123                        $cellcolor = $this->theme['row_on'];
4124
4125                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
4126                        {
4127                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
4128                                $var = Array(
4129                                        'day_events' => $this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
4130                                );
4131                                $this->output_template_array($p,'row','event',$var);
4132                        }
4133                        return $p->fp('out','m_w_table');
4134                }
4135
4136                function display_weekly($params)
4137                {
4138                        if(!is_array($params))
4139                        {
4140                                $this->index();
4141                        }
4142
4143                        $year = substr($params['date'],0,4);
4144                        $month = substr($params['date'],4,2);
4145                        $day = substr($params['date'],6,2);
4146                        $showyear = $params['showyear'];
4147                        $owners = $params['owners'];
4148
4149                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4150                        $p->set_unknowns('keep');
4151
4152                        $p->set_file(
4153                                Array(
4154                                        'week'  => 'month_day.tpl'
4155                                )
4156                        );
4157                        $p->set_block('week','m_w_table','m_w_table');
4158                        $p->set_block('week','event','event');
4159
4160                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
4161
4162                        $cellcolor = $this->theme['row_off'];
4163
4164                        $true_printer_friendly = $this->bo->printer_friendly;
4165
4166                        if(is_array($owners))
4167                        {
4168                                $display_name = True;
4169                                $counter = count($owners);
4170                                $owners_array = $owners;
4171                                $cols = 8;
4172                        }
4173                        else
4174                        {
4175                                $display_name = False;
4176                                $counter = 1;
4177                                $owners_array[0] = $owners;
4178                                $cols = 7;
4179                        }
4180                        $var = Array(
4181                                'cols'         => $cols,
4182                                'day_events'   => $this->week_header($month,$year,$display_name)
4183                        );
4184                        $this->output_template_array($p,'row','event',$var);
4185
4186                        $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
4187                        $tstop = $tstart + 604800;
4188                        $original_owner = $this->bo->so->owner;
4189                        for($i=0;$i<$counter;$i++)
4190                        {
4191                                $this->bo->so->owner = $owners_array[$i];
4192                                $this->bo->so->open_box($owners_array[$i]);
4193                                $this->bo->store_to_cache(
4194                                        Array(
4195                                                'syear'  => date('Y',$tstart),
4196                                                'smonth' => date('m',$tstart),
4197                                                'sday'   => date('d',$tstart),
4198                                                'eyear'  => date('Y',$tstop),
4199                                                'emonth' => date('m',$tstop),
4200                                                'eday'   => date('d',$tstop)
4201                                        )
4202                                );
4203                                $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$owners_array[$i]));
4204                                $p->parse('row','event',True);
4205                        }
4206                        $this->bo->so->owner = $original_owner;
4207                        $this->bo->printer_friendly = $true_printer_friendly;
4208                        return $p->fp('out','m_w_table');
4209                }
4210
4211                function view_event($event,$alarms=False)
4212                {
4213                        if((!$event['participants'][$this->bo->owner] && !$this->bo->check_perms(PHPGW_ACL_READ,$event)))
4214                        {
4215                                return False;
4216                        }
4217
4218                        $p = &$GLOBALS['phpgw']->template;
4219
4220                        $p->set_file(
4221                                Array(
4222                                        'view'  => 'view.tpl'
4223                                )
4224                        );
4225                        $p->set_block('view','view_event','view_event');
4226                        $p->set_block('view','list','list');
4227                        $p->set_block('view','hr','hr');
4228
4229                        $vars = $this->bo->event2array($event);
4230
4231                        $vars['title']['tr_color'] = $this->theme['th_bg'];
4232
4233                        foreach($vars['participants']['data'] as $user => $str)
4234                        {
4235                        if ($this->bo->check_perms(PHPGW_ACL_EDIT,0,$user) && ereg('^(.*) \((.*)\)$',$str,$parts))
4236                                {
4237                                        $vars['participants']['data'][$user] = $parts[1].' (<a href="'.$this->page('edit_status','&cal_id='.$event['id'].'&owner='.$user).'">'.$parts[2].'</a>)';
4238                                }
4239                        }
4240                        $vars['participants']['data'] = implode("<br>\n",$vars['participants']['data']);
4241                        foreach($vars as $var)
4242                        {
4243                                if (strlen($var['data']))
4244                                {
4245                                        $this->output_template_array($p,'row','list',$var);
4246                                }
4247                        }
4248
4249                        if($alarms && count($event['alarm']))
4250                        {
4251                                $p->set_var('th_bg',$this->theme['th_bg']);
4252                                $p->set_var('hr_text',lang('Alarms'));
4253                                $p->parse('row','hr',True);
4254                                foreach($event['alarm'] as $key => $alarm)
4255                                {
4256                                        if (($this->bo->so->owner == $alarm['owner']) || ($this->bo->so->cal->event['owner'] == $this->bo->so->owner)) // Show only alert from user who is requesting or alert owner
4257                                        {       
4258                                                $icon = '<img src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled':'disabled')).'" width="13" height="13">';
4259                                                $var = Array(                                   
4260                                                        'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']),
4261                                                        'data'  => lang('Email Notification for %1',$GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']))
4262                                                );
4263                                                $this->output_template_array($p,'row','list',$var);
4264                                        }
4265                                }
4266                        }
4267                        return True;
4268                }
4269
4270                function nm_on_off()
4271                {
4272                        if($GLOBALS['phpgw']->nextmatchs->alternate_row_color() == $this->theme['row_on'])
4273                        {
4274                                return '_on';
4275                        }
4276                        return '_off';
4277                }
4278
4279                function slot_num($time,$set_day_start=0,$set_day_end=0)
4280                {
4281                        static $day_start, $day_end, $interval=0;
4282
4283                        if ($set_day_start) $day_start = $set_day_start;
4284                        if ($set_day_end)   $day_end   = $set_day_end;
4285                        if (!$interval)     $interval  = 60*$this->bo->prefs['calendar']['interval'];
4286
4287                        if ($time > $day_end)
4288                        {
4289                                $time = $day_end;
4290                        }
4291                        $slot = (int)(($time - $day_start) / $interval);
4292
4293                        return $slot < 0 ? 0 : 1+$slot;
4294                }
4295
4296                function print_day($params)
4297                {
4298                        if(!is_array($params))
4299                        {
4300                                $this->index();
4301                        }
4302
4303                        print_debug('in print_day()');
4304
4305                        $this->bo->store_to_cache(
4306                                Array(
4307                                        'syear'  => $params['year'],
4308                                        'smonth' => $params['month'],
4309                                        'sday'   => $params['day'],
4310                                        'eyear'  => $params['year'],
4311                                        'emonth' => $params['month'],
4312                                        'eday'   => $params['day']
4313                                )
4314                        );
4315
4316                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4317                        $p->set_unknowns('keep');
4318
4319                        $tpl = 'day_cal.tpl';
4320                        if((int)($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents'])==2 &&
4321                                $GLOBALS['phpgw_info']['flags']['currentapp'] == 'home')
4322                        {
4323                                $tpl = 'day_list.tpl';
4324                        }
4325                        $templates = Array(
4326                                'day_cal'   => $tpl
4327                        );
4328
4329                        $p->set_file($templates);
4330                        $p->set_block('day_cal','day','day');
4331                        $p->set_block('day_cal','day_row','day_row');
4332                        $p->set_block('day_cal','day_event_on','day_event_on');
4333                        $p->set_block('day_cal','day_event_off','day_event_off');
4334                        $p->set_block('day_cal','day_event_holiday','day_event_holiday');
4335                        $p->set_block('day_cal','day_time','day_time');
4336
4337                        $date_to_eval = sprintf("%04d%02d%02d",$params['year'],$params['month'],$params['day']);
4338
4339                        $day_start = mktime((int)($this->bo->prefs['calendar']['workdaystarts']),0,0,$params['month'],$params['day'],$params['year']);
4340                        $day_end = mktime((int)($this->bo->prefs['calendar']['workdayends']),0,1,$params['month'],$params['day'],$params['year']);
4341                        $daily = $this->set_week_array($GLOBALS['phpgw']->datetime->get_weekday_start($params['year'],$params['month'],$params['day']),$this->theme['row_on'],True);
4342                        print_debug('Date to Eval',$date_to_eval);
4343                        $events_to_show = array();
4344                        if($daily[$date_to_eval]['appts'])
4345                        {
4346                                $events = $this->bo->cached_events[$date_to_eval];
4347                                print_debug('Date',$date_to_eval);
4348                                print_debug('Count',count($events));
4349                                foreach($events as $event)
4350                                {
4351                                        if ($this->bo->rejected_no_show($event))
4352                                        {
4353                                                continue;       // user does not want to see rejected events
4354                                        }
4355                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
4356                                        {
4357                                                $this->bo->set_recur_date($event,$date_to_eval);
4358                                        }
4359                                        $events_to_show[] = array(
4360                                                'starttime' => $this->bo->maketime($event['start']),
4361                                                'endtime'   => $this->bo->maketime($event['end']),
4362                                                'content'   => $this->link_to_entry($event,$params['month'],$params['day'],$params['year'])
4363                                        );
4364                                }
4365                        }
4366                        //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4367                        $other = $GLOBALS['phpgw']->hooks->process(array(
4368                                'location'  => 'calendar_include_events',
4369                                'year'      => $params['year'],
4370                                'month'     => $params['month'],
4371                                'day'       => $params['day'],
4372                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
4373                        ));
4374
4375                        if (is_array($other))
4376                        {
4377                                foreach($other as $evts)
4378                                {
4379                                        if (is_array($evts))
4380                                        {
4381                                                $events_to_show = array_merge($events_to_show,$evts);
4382                                        }
4383                                }
4384                                usort($events_to_show,create_function('$a,$b','return $a[\'starttime\']-$b[\'starttime\'];'));
4385                                //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4386                        }
4387
4388                        if (count($events_to_show))
4389                        {
4390                                $last_slot_end = -1;
4391                                foreach($events_to_show as $event)
4392                                {
4393                                        $slot = $this->slot_num($event['starttime'],$day_start,$day_end);
4394                                        $slot_end = isset($event['endtime']) ? $this->slot_num($event['endtime']-1) : $slot;    // -1 to not occupy eg. the 18.00 slot for a 17-18h date
4395
4396                                        if ($slot <= $last_slot_end)
4397                                        {
4398                                                $slot = $last_slot;
4399                                                $slot_end = max($last_slot_end,$slot_end);
4400                                        }
4401                                        $rows[$slot] .= $event['content'];
4402
4403                                        print_debug('slot',$slot);
4404                                        print_debug('row',$rows[$slot]);
4405
4406                                        $row_span[$slot] = 1 + $slot_end - $slot;
4407
4408                                        $last_slot = $slot;
4409                                        $last_slot_end = $slot_end;
4410                                        print_debug('Time',$GLOBALS['phpgw']->common->show_date($this->bo->maketime($events[$i]['start']) - $GLOBALS['phpgw']->datetime->tz_offset).' - '.$GLOBALS['phpgw']->common->show_date($this->bo->maketime($events[$i]['end']) - $GLOBALS['phpgw']->datetime->tz_offset));
4411                                        print_debug('Slot',$slot);
4412                                }
4413                                //echo "rows=<pre>"; print_r($rows); echo "<br>row_span="; print_r($row_span); echo "</pre>\n";
4414                        }
4415                        $holiday_names = $daily[$date_to_eval]['holidays'];
4416                        if(!$holiday_names)
4417                        {
4418                                $row_to_print = $this->nm_on_off();
4419                        }
4420                        else
4421                        {
4422                                $row_to_print = '_holiday';
4423                                foreach($holiday_names as $name)
4424                                {
4425                                        $rows[0] = '<center>'.$name.'</center>' . $rows[0];
4426                                }
4427                        }
4428                        $last_slot = $this->slot_num($day_end,$day_start,$day_end);
4429                        $rowspan = 0;
4430                        for ($slot = 0; $slot <= $last_slot; ++$slot)
4431                        {
4432                                $p->set_var('extras','');
4433                                if ($rowspan > 1)
4434                                {
4435                                        $p->set_var('event','');
4436                                        $rowspan--;
4437                                }
4438                                elseif (!isset($rows[$slot]))
4439                                {
4440                                        $p->set_var('event','&nbsp;');
4441                                        $row_to_print = $this->nm_on_off();
4442                                        $p->parse('event','day_event'.$row_to_print);
4443                                }
4444                                else
4445                                {
4446                                        $rowspan = (int)$row_span[$slot];
4447                                        if ($rowspan > 1)
4448                                        {
4449                                                $p->set_var('extras',' rowspan="'.$rowspan.'"');
4450                                        }
4451                                        $p->set_var('event',$rows[$slot]);
4452                                        $row_to_print = $this->nm_on_off();
4453                                        $p->parse('event','day_event'.$row_to_print);
4454                                }
4455                                $open_link = $close_link = '';
4456                                $time = '&nbsp;';
4457
4458                                if (0 < $slot && $slot < $last_slot)    // normal time-slot not before or after day_start/end
4459                                {
4460                                        $time = $day_start + ($slot-1) * 60 * $this->bo->prefs['calendar']['interval'];
4461                                        $hour = date('H',$time);
4462                                        $min  = date('i',$time);
4463                                        $time = $GLOBALS['phpgw']->common->formattime($hour,$min);
4464
4465                                        if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
4466                                        {
4467                                                $open_link = ' <a href="'.$this->page('add',"&date=$date_to_eval&hour=$hour&minute=$min").'">';
4468                                                $close_link = '</a> ';
4469                                        }
4470                                }
4471                                $p->set_var(Array(
4472                                        'open_link'  => $open_link,
4473                                        'time'       => $time,
4474                                        'close_link' => $close_link,
4475                                        'tr_color'   => ''      // dummy to stop output_template_array to set it
4476                                ));
4477                                $p->parse('time','day_time');
4478
4479                                $p->parse('row','day_row',True);
4480                        }
4481                        return $p->fp('out','day');
4482                }       // end function
4483
4484                function timematrix($param)
4485                {
4486                        if(!is_array($param))
4487                        {
4488                                $this->index();
4489                        }
4490
4491                        $date = $param['date'];
4492                        $starttime = $param['starttime'];
4493                        $endtime = $param['endtime'];
4494                        $participants = $param['participants'];
4495                        foreach($participants as $part => $nul)
4496                        {
4497                                $participants[$part] = $GLOBALS['phpgw']->common->grab_owner_name($part);
4498                                // Much better for processor  :)
4499                                $participants_id[]  .= $part;
4500                        }
4501                        uasort($participants,'strnatcasecmp');  // sort them after their fullname
4502
4503                        if(!isset($this->bo->prefs['calendar']['interval']))
4504                        {
4505                                $this->bo->prefs['calendar']['interval'] = 15;
4506                                $GLOBALS['phpgw']->preferences->add('calendar','interval',15);
4507                                $GLOBALS['phpgw']->preferences->save_repository();
4508                        }
4509                        $increment = $this->bo->prefs['calendar']['interval'];
4510                        $interval = (int)(60 / $increment);
4511
4512                        $pix = $GLOBALS['phpgw']->common->image('calendar','pix');
4513
4514                        $str = '<center>'.lang($GLOBALS['phpgw']->common->show_date($date['raw'],'l'))
4515                                . ', '.$this->bo->long_date($date).'<br>'
4516                                . '<table width="85%" border="0" cellspacing="0" cellpadding="0" cols="'.((24 * $interval) + 1).'">'
4517                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>'
4518                                . '<tr><td width="15%"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.lang('Participant').'</font></td>';
4519                        for($i=0;$i<24;$i++)
4520                        {
4521                                for($j=0;$j<$interval;$j++)
4522                                {
4523                                        $k = ($j == 0 ? sprintf('%02d',$i).'<br>':'').sprintf('%02d',$j*$increment);
4524
4525                                        $str .= '<td align="left" bgcolor="'.$this->theme['bg_color'].'"><font color="'.$phpgw_info['theme']['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'
4526                                                . '<a href="'.$this->page('add','&date='.$date['full'].'&hour='.$i.'&minute='.($increment * $j))."\" onMouseOver=\"window.status='".$i.':'.(($increment * $j)<=9?'0':'').($increment * $j)."'; return true;\">"
4527                                                . $k."</a>&nbsp;</font></td>\n";
4528                                }
4529                        }
4530                        $str .= '</tr>'
4531                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>';
4532                        if(!$endtime)
4533                        {
4534                                $endtime = $starttime;
4535                        }
4536                        $owner = $this->bo->owner;
4537                        foreach($participants as $part => $fullname)
4538                        {
4539                                $str .= '<tr align="center">'
4540                                        . '<td width="15%" align="left"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$fullname.'</font></td>';
4541
4542                                $this->bo->cached_events = Array();
4543                                $this->bo->so->owner = $part;
4544                                $this->bo->so->open_box($part);
4545                                $this->bo->store_to_cache(
4546                                        Array(
4547                                                'syear' => $date['year'],
4548                                                'smonth'=> $date['month'],
4549                                                'sday'  => $date['day'],
4550                                                'eyear' => 0,
4551                                                'emonth'=> 0,
4552                                                'eday'  => $date['day'] + 1
4553                                        )
4554                                );
4555
4556                                if(!$this->bo->cached_events[$date['full']])
4557                                {
4558                                        for($j=0;$j<24;$j++)
4559                                        {
4560                                                for($k=0;$k<$interval;$k++)
4561                                                {
4562                                                        $str .= '<td height="1" align="left" bgcolor="'.$this->theme['bg_color'].'" color="#999999">&nbsp;</td>';
4563                                                }
4564                                                $str .= "\n";
4565                                        }
4566                                }
4567                                else
4568                                {
4569                                        $time_slice = $this->bo->prepare_matrix($interval,$increment,$part,$date['full']);
4570                                        for($h=0;$h<24;$h++)
4571                                        {
4572                                                $hour = $h * 10000;
4573                                                for($m=0;$m<$interval;$m++)
4574                                                {
4575                                                        $index = ($hour + (($m * $increment) * 100));
4576                                                        switch($time_slice[$index]['marker'])
4577                                                        {
4578                                                                case '&nbsp':
4579                                                                        $time_slice[$index]['color'] = $this->theme['bg_color'];
4580                                                                        $extra = '';
4581                                                                        break;
4582                                                                case '-':
4583                                                                        $time_slice[$index]['color'] = $this->theme['bg01'];
4584                                                                        $link = $this->page('view','&cal_id='.$time_slice[$index]['id'].'&date='.$date['full']);
4585                                                                        $extra =' title="'.$time_slice[$index]['description'].'" onClick="location.href=\''.$link.'\';" style="cursor:pointer; cursor:hand;"';
4586                                                                        break;
4587                                                        }
4588                                                        $str .= '<td bgcolor="'.$time_slice[$index]['color'].'" color="#999999"'.$extra.'><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$time_slice[$index]['marker'].'</font></td>';
4589                                                }
4590                                                $str .= "\n";
4591                                        }
4592                                }
4593                                $str .= '</tr>'
4594                                        . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="#999999"><img src="'.$pix.'"></td></tr>';
4595                        }
4596                        $this->bo->owner = $owner;
4597                        $this->bo->so->owner = $owner;
4598                        $this->bo->so->open_box($owner);
4599                        return $str.'</table></center>'."\n";
4600                }
4601
4602                function get_response($cal_id)
4603                {
4604                        $p = &$GLOBALS['phpgw']->template;
4605                        $p->set_file(
4606                                Array(
4607                                        'form_button'   => 'form_button_script.tpl'
4608                                )
4609                        );
4610
4611                        $ev = $this->bo->get_cached_event();
4612                        $response_choices = Array(
4613                                ACCEPTED        => lang('Accept'),
4614                                REJECTED        => lang('Reject'),
4615                                TENTATIVE       => lang('Tentative')                           
4616                        );
4617                        $str = '';
4618                        while(list($param,$text) = each($response_choices))
4619                        {
4620                                $var = Array(
4621                                        'action_url_button'     => $this->page('set_action','&cal_id='.$cal_id.'&action='.$param),
4622                                        'action_text_button'    => '  '.$text.'  ',
4623                                        'action_confirm_button' => '',
4624                                        'action_extra_field'    => ''
4625                                );
4626                                $p->set_var($var);
4627                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4628                        }
4629                        if ($this->bo->return_to)
4630                        {
4631                                $var = Array(
4632                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
4633                                        'action_text_button'    => lang('cancel'),
4634                                        'action_confirm_button' => '',
4635                                        'action_extra_field'    => ''
4636                                );
4637                                $p->set_var($var);
4638                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4639                        }
4640                        $str = '<td><b>'.$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner).":</b></td>\n".$str;
4641
4642                        return '<table width="100%"><tr align="center">'."\n".$str.'</tr></table>'."\n";
4643                }
4644
4645                function accounts_popup()
4646                {
4647                        $GLOBALS['phpgw']->accounts->accounts_popup('calendar');
4648                       
4649                }
4650
4651                function edit_form($param)
4652                {
4653                        if(!is_array($param))
4654                        {
4655                                $this->index();
4656                        }
4657                       
4658                        if(isset($param['event']))
4659                        {
4660                                $event = $param['event'];
4661                        }
4662                       
4663                        $hourformat = substr($this->bo->users_timeformat,0,1);
4664                       
4665                        // $sb = CreateObject('phpgwapi.sbox');
4666                        $sb = CreateObject('phpgwapi.sbox2');
4667                        $jscal = CreateObject('phpgwapi.jscalendar');   // before phpgw_header() !!!
4668                       
4669                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
4670                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
4671                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
4672                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
4673                        $GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Editing event') : lang('Adding event');
4674                        if ($param['plain'] != "True"){
4675                                $GLOBALS['phpgw']->common->phpgw_header();
4676                        }
4677                        else{
4678                                $GLOBALS['phpgw_info']['theme']['row_on'] = "F8F8F8";
4679                                $GLOBALS['phpgw_info']['theme']['row_off'] = "F8F8F8";
4680                        }
4681
4682                        $p = &$GLOBALS['phpgw']->template;
4683                        $p->set_file(
4684                                Array(
4685                                        'edit'          => 'edit.tpl',
4686                                        'form_button'   => 'form_button_script.tpl'
4687                                )
4688                        );
4689                        $p->set_block('edit','edit_entry','edit_entry');
4690                        $p->set_block('edit','list','list');
4691                        $p->set_block('edit','hr','hr');
4692                       
4693                        $vars = Array(
4694                                'font'                  => $this->theme['font'],
4695                                'bg_color'              => $this->theme['bg_text'],
4696                                'action_url'            => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update')),
4697                                'accounts_link'         => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.accounts_popup'),
4698                                'common_hidden' => '<input type="hidden" name="cal[id]" value="'.$event['id'].'">'."\n"
4699                                        . '<input type="hidden" name="cal[owner]" value="'.$event['owner'].'">'."\n"
4700                                        . '<input type="hidden" name="cal[uid]" value="'.$event['uid'].'">'."\n"
4701                                        . ($_GET['cal_id'] && $event['id'] == 0?'<input type="hidden" name="cal[reference]" value="'.$_GET['cal_id'].'">'."\n":
4702                                        (@isset($event['reference'])?'<input type="hidden" name="cal[reference]" value="'.$event['reference'].'">'."\n":''))
4703                                        . (@isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && $GLOBALS['phpgw_info']['server']['deny_user_grants_access']?
4704                                        '<input type="hidden" name="participants[]" value="'.$this->bo->owner.'">'."\n":''),
4705                                'errormsg'              => ($param['cd']?$GLOBALS['phpgw']->common->check_code($param['cd']):'')
4706                        );
4707                       
4708                        $p->set_var($vars);
4709
4710// Brief Description
4711                        $var['title'] = Array(
4712                                'tr_color' => $this->theme['th_bg'],
4713                                'field' => lang('Title'),
4714                                'data'  => '<input name="cal[title]" size="45" maxlength="80" value="'.$event['title'].'">'
4715                        );
4716
4717// Full Description
4718                        $var['description'] = Array(
4719                                'field' => lang('Full Description'),
4720                                'data'  => '<textarea name="cal[description]" rows="5" cols="40" wrap="virtual" maxlength="2048">'.$event['description'].'</textarea>'
4721                        );
4722
4723// Display Categories
4724                        if(strpos($event['category'],','))
4725                        {
4726                                $temp_cats = explode(',',$event['category']);
4727                                @reset($temp_cats);
4728                                while(list($key,$value) = each($temp_cats))
4729                                {
4730                                        $check_cats[] = (int)$value;
4731                                }
4732                        }
4733                        elseif($event['category'])
4734                        {
4735                                $check_cats[] = (int)$event['category'];
4736                        }
4737                        else
4738                        {
4739                                $check_cats[] = 0;
4740                        }
4741                        $var['category'] = Array(
4742                                'field' => lang('Category'),
4743                                'data'  => '<select name="categories[]" onchange="javascript:updateTitleField(this)" multiple size="5">'.$this->cat->formated_list('select','all',$check_cats,True).'</select>'
4744                        );
4745
4746// Location
4747                        $var['location'] = Array(
4748                                'field' => lang('Location'),
4749                                'data'  => '<input name="cal[location]" size="45" maxlength="255" value="'.$event['location'].'">'
4750                        );
4751
4752// Date
4753
4754                        $start = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
4755                        $var['startdate'] = Array(
4756                                'field' => lang('Start Date'),
4757/*
4758                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
4759                                   $sb->getYears('start[year]',(int)$GLOBALS['phpgw']->common->show_date($start,'Y')),
4760                                   $sb->getMonthText('start[month]',(int)$GLOBALS['phpgw']->common->show_date($start,'n')),
4761                                   $sb->getDays('start[mday]',(int)$GLOBALS['phpgw']->common->show_date($start,'d'))
4762                                )
4763*/
4764                                'data' => $jscal->input('start[str]',$start)
4765                        );
4766
4767// Time
4768                        if ($this->bo->prefs['common']['timeformat'] == '12')
4769                        {
4770                                $str .= '<input type="radio" name="start[ampm]" value="am"'.($event['start']['hour'] >= 12?'':' checked').'>am'."\n"
4771                                        . '<input type="radio" name="start[ampm]" value="pm"'.($event['start']['hour'] >= 12?' checked':'').'>pm'."\n";
4772                        }
4773                        $var['starttime'] = Array(
4774                                'field' => lang('Start Time'),
4775                                'data'  => '<input name="start[hour]" id="start_hour" size="2" VALUE="'.$GLOBALS['phpgw']->common->show_date($start,$hourformat).'" maxlength="2">:<input name="start[min]" id="start_minute" size="2" value="'.$GLOBALS['phpgw']->common->show_date($start,'i').'" maxlength="2">'."\n".$str
4776                        );
4777
4778// End Date
4779                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
4780                        $var['enddate'] = Array(
4781                                'field' => lang('End Date'),
4782/*
4783                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
4784                                   $sb->getYears('end[year]',(int)$GLOBALS['phpgw']->common->show_date($end,'Y')),
4785                                   $sb->getMonthText('end[month]',(int)$GLOBALS['phpgw']->common->show_date($end,'n')),
4786                                   $sb->getDays('end[mday]',(int)$GLOBALS['phpgw']->common->show_date($end,'d'))
4787                                )
4788*/
4789                                'data' => $jscal->input('end[str]',$end)
4790                        );
4791
4792// End Time
4793                        if ($this->bo->prefs['common']['timeformat'] == '12')
4794                        {
4795                                $str = '<input type="radio" name="end[ampm]" value="am"'.($event['end']['hour'] >= 12?'':' checked').'>am'."\n"
4796                                        . '<input type="radio" name="end[ampm]" value="pm"'.($event['end']['hour'] >= 12?' checked':'').'>pm'."\n";
4797                        }
4798                        $var['endtime'] = Array(
4799                                'field' => lang('End Time'),
4800                                'data'  => '<input name="end[hour]" id="end_hour" size="2" VALUE="'.$GLOBALS['phpgw']->common->show_date($end,$hourformat).'" maxlength="2">:<input name="end[min]" id="end_minute" size="2" value="'.$GLOBALS['phpgw']->common->show_date($end,'i').'" maxlength="2">'."\n".$str
4801                        );
4802
4803// Priority
4804                        $var['priority'] = Array(
4805                                'field' => lang('Priority'),
4806                                'data'  => $sb->getPriority('cal[priority]',$event['priority'])
4807                        );
4808
4809                        // Access
4810                        $var['access'] = Array(
4811                        'field' => lang('Type'),
4812                        'data'  => '<select onchange="javascript:changeViewMode(this.value);" id="cal[type]" name="cal[type]" '.($event['type'] == 'H'?'DISABLED':'').'><option value="normal">'.lang('Normal').'</option><option value="private" '.(!$event['public']?'SELECTED':'').' >'. lang('Restrict').'</option><option value="privateHiddenFields" '.(!$event['public']?'SELECTED':'').' >'. lang('Private').'</option><option value="hourAppointment" '.($event['type'] == 'H'?'SELECTED':'').' >'.lang('Hours Appointment').'</option></select>'
4813                        ); //event['public']
4814
4815                        // Participants
4816                        if(!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access'])
4817                        {
4818                                switch($GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection'])
4819                                {
4820                                        case 'popup':
4821                                                while (is_array($event['participants']) && list($id) = each($event['participants']))
4822                                                {
4823                                                        if($id != (int)$event['owner'])
4824                                                        {
4825                                                                $str .= '<option value="' . $id.$event['participants'][$id] . '"'.($event['participants'][$id]?' selected':'').'>('.$GLOBALS['phpgw']->accounts->get_type($id)
4826                                                                                .') ' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '</option>' . "\n";
4827                                                        }
4828                                                }
4829                                                $var['participants'] = array
4830                                                (
4831                                                        'field' => '<input type="button" value="' . lang('Participants') . '" onClick="accounts_popup();">' . "\n"
4832                                                                        . '<input type="hidden" name="accountid" value="' . $accountid . '">',
4833                                                        'data'  => "\n".'   <select name="participants[]" multiple size="7">' . "\n" . $str . '</select>'
4834                                                );
4835                                                break;
4836                                        default:
4837                                                foreach($event['participants'] as $id => $participant)
4838                                                {
4839                                                        if (($id != $event['owner']) && ($id != ""))
4840                                                        {
4841                                                                $GLOBALS['phpgw']->accounts->get_account_name($id, $lid, $fname, $lname);
4842                                                                $cn = $fname.' '.$lname;                                                       
4843                                                                $option = '    <option  value="' . $id.$participant . '">'.$cn.'</option>'."\n";
4844                                                                $str .= $option;
4845                                                        }                                                               
4846                                                }
4847                                                $str = utf8_decode($str);
4848                                                $footer_ext_participantes =     '<br>&nbsp;&nbsp;'.lang("The email addresses must be separated by ','");                                               
4849                                               
4850                                                $var['participants'] = array
4851                                                (
4852                                                        'field' => lang('Participants'),                                                       
4853                                                        'data'  => "
4854                                                                        <table width='100%' border='0'>
4855                                                                                <tr>
4856                                                                                        <td width='30%'>                                                                               
4857                                                                                                <center>Participantes</center>                                                                                         
4858                                                                                        </td>
4859                                                                                        <td width='8%' >&nbsp;</td>
4860                                                                                        <td width='40%'>&nbsp;</td>
4861                                                                                </tr>                                                                                                                                           
4862                                                                                <tr>           
4863                                                                                        <td width='30%'>                                                                                       
4864                                                                                                <center><select id='user_list' name='participants[]' style='width: 220px' multiple size='7'>".$str."</select></center>                                                                         
4865                                                                                        </td>                           
4866                                                                                        <td width='8%'>
4867                                                                                        <center>
4868                                                                                                <table width='100%' border='0'>                                                                 
4869                                                                                                        <tr height='5'><td>&nbsp;</td></tr>                                                                     
4870                                                                                                        <tr><td align='center'>                                                                 
4871                                                                                                                <button type='button' onClick='javascript:openListUsers(340,533, "
4872                                                                                                                .$event['owner'].
4873                                                                                                                ")'><img src='calendar/templates/".$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set']."/images/add.png' style='vertical-align: middle;' >&nbsp;Adicionar</button>
4874                                                                                                                </td>
4875                                                                                                        </tr>                                                   
4876                                                                                                        <tr height='5'><td>&nbsp;</td></tr>
4877                                                                                                        <tr><td  align='center'>
4878                                                                                                                <button type='button' onClick='javascript:rem()'><img src='calendar/templates/".$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set']."/images/rem.png' style='vertical-align: middle;' >&nbsp;Remover</button>
4879                                                                                                                </td>
4880                                                                                                        </tr>
4881                                                                                                </table>
4882                                                                                        </center>
4883                                                                                        </td>
4884                                                                                        <td width='40%'>&nbsp;</td>
4885                                                                                </tr>
4886                                                                                </table>
4887                                                                        "
4888                                                );
4889                                                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
4890                                                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {                                                     
4891                                                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
4892
4893                                                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
4894                                                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
4895                                                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
4896                                                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $event['owner'];
4897                                                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
4898                                                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
4899                                                                $context = $GLOBALS['phpgw_info']['server']['ldap_context'];
4900                                                                $user_context = array();
4901                                                                foreach(explode(",",$GLOBALS['phpgw_info']['user']['account_dn']) as $i => $dn_part){
4902                                                                        if($i)
4903                                                                                $user_context[] = $dn_part;
4904                                                                }
4905                                                                // Prepara o contexto do usuario com sua OU raiz, pois ele pode pertencer a uma OU de nivel N.
4906                                                                $user_ou = explode(",",str_replace($context,"",implode(",",$user_context)));                                                           
4907                                                                $user_context = trim(strtolower($user_ou[count($user_ou) - 2].",".$context));
4908                                                                // Fim         
4909                                                                // Verifica o tipo da visualização da árvore LDAP, configurado no admin da Agenda
4910                                                                $recursive = $GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '1' ? true : false;
4911                                                                //$combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
4912                                                                $footer_ext_participantes = lang("Tip: To search in the <b>Global Catalog</b>, type the <b>F9</b> key, like the ExpressoMail.");
4913                                                                //Caso o minimo de caracteres para a busca nao tenha sido preenchido ele sera por padrao = 3
4914                                                                if(!$GLOBALS['phpgw_info']['server']['min_num_characters']){
4915                                                                        $GLOBALS['phpgw_info']['server']['min_num_characters'] = 0;
4916                                                                }
4917
4918                                                                if ($GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '3'){
4919                                                                        $combo_org = '<option value='.$context.'>'.strtoupper($context).'</option>';
4920                                                                }else{
4921                                                                        $combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
4922                                                                }
4923
4924                                                                if ($param['plain'] != "True"){
4925
4926                                                                        // Begin load array lang
4927                                                                        ob_start();
4928                                                                        //@include($module_name.'/inc/load_lang.php');
4929                                                                        $load_lang_vars = ob_get_contents();
4930                                                                        ob_end_clean();
4931                                                                        // End load array_lang
4932                                                                }
4933
4934                                                                $var['participants'] = array
4935                                                                (
4936                                                                        'field' => '
4937                                                                        <script src="calendar/templates/'.$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set'].'/js/edit.js" type="text/javascript"></script><div id=\'disponibility\' style=\'display:none;position:absolute\' bgcolor=\'#FFFFFF\'>
4938        <iframe src=\'#\' id=\'frame_disponibility\' width=\'500\' marginHeight=\'0\' marginWidth=\'0\'></iframe>
4939</div>
4940                                                                        '.lang('Participants'),                                                 
4941                                                                        'data'  => '
4942                                                                                        <font color="#000088"><span onclick=\'show_disponibility()\' style="cursor:hand;cursor:pointer">Mapa de disponibilidade</span></font><br>
4943                                                                                        <input type="hidden" id="txt_loading" value="'.lang("Loading").'">' .
4944                                                                                        '<input type="hidden" id="txt_searching" value="'.lang("Searching").'">' .
4945                                                                                        '<input type="hidden" id="txt_users" value="'.lang("Users").'">' .                                                     
4946                                                                                        '<input type="hidden" id="txt_groups" value="'.lang("Groups").'">' .
4947                                                                                        '<table width="100%" border="0">'.
4948                                                                                        '<tr>'.
4949                                                                                        '<td width="25%"><br>'.
4950                                                                                        '<button type="button" onClick="javascript:add_user();"><img src="calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images/add.png" style="vertical-align: middle;" >&nbsp;'.lang("Add").'</button>'.
4951                                                                                        '&nbsp;&nbsp;<button type="button" onClick="javascript:remove_user();"><img src="calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images/rem.png" style="vertical-align: middle;" >&nbsp;'.lang("Remove").'</button>'.
4952                                                                                        '<br><br>&nbsp;&nbsp;<b>'.lang("Event's participants").'</b><br>'.
4953                                                                                        '       <select id="user_list" name="participants[]" style="width: 300px" multiple size="13">'.$str.'</select>'.
4954                                                                                        '</td>'.
4955                                                                                        '<td width="30px" valign="middle" align="center">&nbsp;'.
4956                                                                                        '</td>'.
4957                                                                                        '<td valign="bottom">'.
4958                                                                                        '       '.lang("Organization").': '.
4959                                                                                        '       <select name="org_context" id="combo_org" onchange="javascript:get_available_users(\''.$module_name.'\',\''.$GLOBALS['phpgw_info']['server']['auto_search'].'\',\''.($recursive ? "" : "search").'\');">'.$combo_org.'</select>'.
4960                                                                                        '       <br>'.
4961                                                                                        '       <font color="red"><span id="cal_span_searching">&nbsp;</span></font>'.                                                                 
4962                                                                                        '       <br>'.lang("Search for").':'.
4963                                                                                        '       <input value="" id="cal_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this,'.$GLOBALS['phpgw_info']['server']['min_num_characters'].')"><br>'.
4964                                                                                        '       <b>'.lang("Available users and groups").'</b><br>'.
4965                                                                                        '       <select id="user_list_in" style="width: 300px" multiple size="13"></select>'.
4966                                                                                        '</td>'.
4967                                                                                        '</tr>'.
4968                                                                                        '</table>'.
4969                                                                                        '<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>'.
4970                                                                                        '<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>'.         
4971                                                                                        "<script src='calendar/templates/".$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set']."/js/edit_exmail.js' type='text/javascript'></script>" .
4972                                                                                        $load_lang_vars.                                                                                                                                                       
4973                                                                                        "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
4974                                                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
4975                                                                                        "<script type='text/javascript'>" .
4976                                                                                        "var timeout_get_available_users = setTimeout('get_available_users(\"".$module_name."\",\'".$GLOBALS['phpgw_info']['server']['auto_search']."\',\'".$user_context."\',\'".($recursive ? "" : "search")."\')',1000);".
4977                                                                                        "</script> "
4978                                                                );
4979                                                        }                                               
4980                                                }                                               
4981                                               
4982                                                $var['participants']['data'] .= '<a id="a_ext_participants" title="'.lang("It types below the email addresses, if you want to invite other people out" .
4983                                                        " of this system").'" name="a_ext_participants" onClick="javascript:showExParticipants(this,\''.$module_name.'\')" href="#a_ext_participants"><b>'.lang("Inform").' '.lang("external participants").'</b>&nbsp;<img align="top" ' .
4984                                                        'src="calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images/sent.gif"></a><table id="tbl_ext_participants" width="100%" border="0" style="display:none">'.
4985                                                        '<tr>'.
4986                                                        '<td>'.
4987                                                        '&nbsp;&nbsp;<b>'.lang("external participants").'</b>&nbsp;<img align="top" src="calendar/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/images/sent.gif">' .
4988                                                        '&nbsp;&nbsp;<a title="'.lang("Close").'" name="b_ext_participants" onClick="javascript:hideExParticipants(this,\''.$module_name.'\')" href="#a_ext_participants">['.lang("Close").']</a>&nbsp;'.                                                                                                               
4989                                                        '</td>'.
4990                                                        '</tr>'.
4991                                                        '<tr>'.
4992                                                        '<td>'.
4993                                                        '&nbsp;&nbsp;>> '.lang("It types below the email addresses, if you want to invite other people out of this system").':'.
4994                                                        '&nbsp;&nbsp;<br><textarea name="ex_participants" id="ex_participants" cols="70" rows="2">'.$event['ex_participants'].'</textarea><br>&nbsp;&nbsp;'.
4995                                                        $footer_ext_participantes.
4996                                                        '</tr>'.                                                       
4997                                                        '</table>';
4998                                                break;
4999                                               
5000                                }
5001                                if((($event['id'] > 0) && isset($event['participants'][$event['owner']])) || !$event['id'])
5002                                {
5003                                        $checked = ' checked';
5004                                }
5005                                else
5006                                {
5007                                        $checked = '';
5008                                }
5009                                $var['owner'] = Array(
5010                                        'field' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']).' '.lang('Participates'),
5011                                        'data'  => '<input type="checkbox" id="usuarioParticipa" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'"'.$checked.'>'
5012                                );
5013                        }
5014
5015// Reminder
5016                        // The user must use "Alarm Management" to change/modify an alarm
5017                        // so only display the email reminder fields if this is a new event
5018                        // i.e. not editing an existing event
5019
5020                        if ($event['id'] == 0) {
5021                                // get defaults
5022                                $days = $this->bo->prefs['calendar']['default_email_days'];
5023                                $hours = $this->bo->prefs['calendar']['default_email_hours'];
5024                                $min = $this->bo->prefs['calendar']['default_email_min'];
5025                                if (count($event['alarm']) > 1)
5026                                {
5027                                        // this should not happen because when creating a new event
5028                                        // only 1 alarm is displayed on the screen
5029                                        // if the user wants more than 1 alarm they should
5030                                        // use "Alarm Management"
5031                                        echo '<!-- how did this happen, too many alarms -->'."\n";
5032                                }
5033                                // if there was an error pick up what the user entered
5034                                if (@isset($event['alarm']))
5035                                {
5036                                        @reset($event['alarm']);
5037                                        // just get the first one see above!!!
5038                                        list($key,$alarm) = @each($event['alarm']);
5039
5040
5041                                        //if abaixo trata o caso de um evento repetido nao ter uma data final;
5042                                        //se isto acontecer, nao havera alarmes definidos;
5043                                        //$alarm['time'] recebe $start para $days, $hours e $min ficarem iguais a 0
5044                                        if(!$alarm['time']) {
5045                                                $alarm['time'] = $start;
5046                                        }
5047
5048                                        $diff  = $start - $alarm['time'];
5049                                        $days  = (int)($diff / (24*3600));
5050                                        $hours = (int)(($diff - ($days * 24 * 3600))/3600);
5051                                        $min   = (int)(($diff - ($days * 24 * 3600) - ($hours * 3600))/60);
5052
5053                                        if(@isset($_POST['edit_type']) && $_POST['edit_type'] == 'single') {
5054                                                $days = $diff;
5055                                        }
5056                                }
5057
5058                                // days
5059                                $dout = '<select name="cal[alarmdays]">'."\n";
5060                                for($i=0;$i<32;$i++)
5061                                {
5062                                        $dout .= '<option value="'.$i.'"'.($i==$days?' selected':'').'>'.$i.'</option>'."\n";
5063                                }
5064                                $dout .= '</select>'."\n".' '.lang('days').' ';
5065                                // hours
5066                                $hout = '<select name="cal[alarmhours]">'."\n";
5067                                for($i=0;$i<25;$i++)
5068                                {
5069                                        $hout .= '<option value="'.$i.'"'.($i==$hours?' selected':'').'>'.$i.'</option>'."\n";
5070                                }
5071                                $hout .= '</select>'."\n".' '.lang('hours').' ';
5072                                // minutes
5073                                $mout = '<select name="cal[alarmminutes]">'."\n";
5074                                for($i=0;$i<61;$i++)
5075                                {
5076                                        $mout .= '<option value="'.$i.'"'.($i==$min?' selected':'').'>'.$i.'</option>'."\n";
5077                                }
5078                                $mout .= '</select>'."\n".' '.lang('minutes').' ';
5079
5080                                $var['alarm'] = Array(
5081                                        'field' => lang('Alarm'),
5082                                        'data'  => $dout.$hout.$mout.lang('before the event')
5083                                );
5084
5085                        }
5086
5087// Repeat Type
5088                        $str = '';
5089                        foreach($this->bo->rpt_type as $type => $label)
5090                        {
5091                                $str .= '<option value="'.$type.'"'.($event['recur_type']==$type?' selected':'').'>'.lang($label).'</option>';
5092                        }
5093                        $var['recure_type'] = Array(
5094                                'field' => lang('Repeat Type'),
5095                                'data'  => '<select name="cal[recur_type]">'."\n".$str.'</select>'."\n"
5096                        );
5097
5098                        if($event['recur_enddate']['year'] != 0 && $event['recur_enddate']['month'] != 0 && $event['recur_enddate']['mday'] != 0)
5099                        {
5100                                $checked = ' checked';
5101                                $recur_end = $this->bo->maketime($event['recur_enddate']) - $GLOBALS['phpgw']->datetime->tz_offset;
5102                        }
5103                        else
5104                        {
5105                                $checked = '';
5106                                $recur_end = $this->bo->maketime($event['start']) + 86400 - $GLOBALS['phpgw']->datetime->tz_offset;
5107                        }
5108
5109                        $var['recure_enddate'] = Array(
5110                                'field' => lang('Repeat End Date'),
5111                                'data'  => '<input type="checkbox" name="cal[rpt_use_end]" value="y"'.$checked.'>'.lang('Use End Date').'  '.
5112/*
5113                                        $GLOBALS['phpgw']->common->dateformatorder(
5114                                                $sb->getYears('recur_enddate[year]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'Y')),
5115                                                $sb->getMonthText('recur_enddate[month]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'n')),
5116                                                $sb->getDays('recur_enddate[mday]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'d'))
5117                                        )
5118*/
5119                                        $jscal->input('recur_enddate[str]',$recur_end)
5120                        );
5121
5122                        $i = 0; $boxes = '';
5123                        foreach ($this->bo->rpt_day as $mask => $name)
5124                        {
5125                                $boxes .= '<input type="checkbox" name="cal[rpt_day][]" value="'.$mask.'"'.($event['recur_data'] & $mask ? ' checked' : '').'>&nbsp;'.lang($name)."\n";
5126                                if (++$i == 5) $boxes .= '<br>';
5127                        }
5128                        $var['recure_day'] = Array(
5129                                'field' => lang('Repeat Day').'<br>'.lang('(required for weekly recursivity)'),
5130                                'data'  => $boxes
5131                        );
5132
5133                        $var['recure_interval'] = Array(
5134                                'field' => lang('Interval'),
5135                                'data'  => '<input name="cal[recur_interval]" size="4" maxlength="4" value="'.$event['recur_interval'].'">'
5136                        );
5137//                      $this->output_template_array($p,'row','list',Array('data' => '<script src="simple_show_hide.js" type="text/javascript"></script>'));
5138
5139                        if (!isset($this->fields))
5140                        {
5141                                $this->custom_fields = CreateObject('calendar.bocustom_fields');
5142                                $this->fields = &$this->custom_fields->fields;
5143                                $this->stock_fields = &$this->custom_fields->stock_fields;
5144                        }
5145                        $this->output_template_array($p,'row','list',$var['access']);
5146                        unset($var['access']);
5147
5148                        $preserved = False;
5149                        foreach($this->fields as $field => $data)
5150                        {
5151                                if (!$data['disabled'])
5152                                {
5153                                        if (isset($var[$field]))
5154                                        {
5155                                                switch($field)
5156                                                {
5157                                                        case 'startdate':
5158                                                                $this->output_template_array($p,'row','list',$var['startdate']);
5159                                                                $this->output_template_array($p,'row','list',$var['starttime']);
5160                                                                break;
5161                                                        case 'enddate':
5162                                                                $this->output_template_array($p,'row','list',$var['enddate']);
5163                                                                $this->output_template_array($p,'row','list',$var['endtime']);
5164                                                                break;
5165                                                        case 'recure_type':
5166                                                                $p->set_var('tr_color',$this->theme['th_bg']);
5167                                                                $p->set_var('hr_text','<center name="cal[rpt_label]"><b>'.lang('Repeating Event Information').'</b></center>');
5168                                                                $p->parse('row','hr',True);
5169                                                                $this->output_template_array($p,'row','list',$var['recure_type']);
5170                                                                $this->output_template_array($p,'row','list',$var['recure_enddate']);
5171                                                                $this->output_template_array($p,'row','list',$var['recure_day']);
5172                                                                $this->output_template_array($p,'row','list',$var['recure_interval']);
5173                                                                break;
5174                                                        default:
5175                                                                $this->output_template_array($p,'row','list',$var[$field]);
5176                                                }
5177                                        }
5178                                        elseif (!isset($this->stock_fields[$field]))    // Custom field
5179                                        {
5180                                                $lang = lang($name = substr($field,1));
5181                                                $size = 'SIZE='.($data['shown'] ? $data['shown'] : ($data['length'] ? $data['length'] : 30)).
5182                                                        ' MAXLENGTH='.($data['length'] ? $data['length'] : 255);
5183                                                $v = array(
5184                                                        'field' => $lang == $name.'*' ? $name : $lang,
5185                                                        'data'  => '<input name="cal['.htmlspecialchars($field).']" '.$size.' value="'.$event['#'.$name].'">'
5186                                                );
5187                                                if ($data['title'])
5188                                                {
5189                                                        $v['tr_color'] = $this->theme['th_bg'];
5190                                                }
5191                                                if (!$data['length'] && $data['title'])
5192                                                {
5193                                                        $p->set_var('tr_color',$this->theme['th_bg']);
5194                                                        $p->set_var('hr_text','<center><b>'.$v['field'].'</b></center>');
5195                                                        $p->parse('row','hr',True);
5196                                                }
5197                                                else
5198                                                {
5199                                                        $this->output_template_array($p,'row','list',$v);
5200                                                }
5201                                        }
5202                                }
5203                                else    // preserve disabled fields
5204                                {
5205                                        switch ($field)
5206                                        {
5207                                                case 'owner':
5208                                                        $preserved[$field] = $event['id'] ? $event['participants'][$event['owner']] : 'A';
5209                                                        break;
5210                                                case 'recure_type':
5211                                                        foreach(array('recur_type','recur_enddate','recur_data','recur_interval') as $field)
5212                                                        {
5213                                                                $preserved[$field] = $event[$field];
5214                                                        }
5215                                                        break;
5216                                                case 'startdate':
5217                                                case 'enddate':
5218                                                        $field = substr($field,0,-4);
5219                                                default:
5220                                                        $preserved[$field] = $event[$field];
5221                                        }
5222                                }
5223                        }
5224                        unset($var);
5225                        if (is_array($preserved))
5226                        {
5227                                //echo "preserving<pre>"; print_r($preserved); echo "</pre>\n";
5228                                $p->set_var('common_hidden',$p->get_var('common_hidden').'<input type="hidden" name="preserved" value="'.htmlspecialchars(serialize($preserved)).'">'."\n");
5229                        }
5230                        $p->set_var('submit_button',lang('Save'));
5231
5232                        $delete_button = $cancel_button = '';
5233                        if ($event['id'] > 0)
5234                        {
5235                                $var = Array(
5236                                        'action_url_button'     => $this->page('delete','&cal_id='.$event['id']),
5237                                        'action_text_button'    => lang('Delete'),
5238                                        'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"",
5239                                        'action_extra_field'    => '',
5240                                        'button_id'     =>      'delete_button'
5241                                );
5242                                $p->set_var($var);
5243                                $delete_button = $p->fp('out','form_button');
5244                        }
5245                        $p->set_var('delete_button',$delete_button);
5246                        $p->set_var('alert_msg',lang('Required field (category) is empty'));
5247
5248                        if ($this->bo->return_to)
5249                        {
5250                                $var = Array(
5251                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
5252                                        'action_text_button'    => lang('Cancel'),
5253                                        'action_confirm_button' => '',
5254                                        'action_extra_field'    => '',
5255                                        'button_id'     =>      'cancel_button'
5256                                );
5257                                $p->set_var($var);
5258                                $cancel_button = $p->fp('out','form_button');
5259                        }
5260                        $p->set_var('cancel_button',$cancel_button);
5261                        $p->pparse('out','edit_entry');
5262                }
5263               
5264                // modify list of an event's external participants (i.e. non pgpgw users)
5265                //
5266                function modify_ext_partlist()
5267                {
5268                        $GLOBALS['phpgw_info']['flags']['noheader'] = True;
5269                        $GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
5270                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
5271                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
5272
5273                        $total_contacts = 0;
5274                        $participant = array();
5275                        $control_data= array();
5276
5277                        $control_data['action'] = '';
5278                        $control_data['delete'] = array();
5279                        $control_data['part'] = array();
5280
5281                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
5282                        $p->set_file(
5283                                Array(
5284                                        'T_edit_partlist' => 'edit_partlist.tpl',
5285                                        'T_edit_partlist_blocks' => 'edit_partlist_blocks.tpl'
5286                                )
5287                        );
5288
5289                        $p->set_block('T_edit_partlist_blocks','B_alert_msg','V_alert_msg');
5290                        $p->set_block('T_edit_partlist_blocks','B_partlist','V_partlist');
5291                        $p->set_block('T_edit_partlist_blocks','B_participants_none','V_participants_none');
5292                        $p->set_block('T_edit_partlist_blocks','B_delete_btn','V_delete_btn');
5293
5294                        global $query_addr;
5295                        $sb = CreateObject('phpgwapi.sbox2');
5296                        $addy = $sb->getAddress('addr','',$query_addr);
5297
5298                        $add_ext  = $addy['doSearchFkt'];
5299                        $add_ext .= $addy['addr_title']!=lang('Address Book')?$addy['addr_title']:'';
5300                        $add_ext .= "&nbsp;".$addy['addr'].$addy['addr_nojs'];
5301
5302                        $p->set_var('text_add_name',$add_ext);
5303
5304                        if(isset($_GET['part']) && $_GET['part'])
5305                        {
5306                                $control_data['part'] = split(",", $_GET['part']);
5307                        }
5308                        else
5309                        {
5310                                $control_data['part'] = $_POST['participant'];
5311                                $control_data['action'] = $_POST['action'];
5312                                $control_data['delete'] = $_POST['delete'];
5313                        }
5314
5315                        for ($i=0; $i<count($control_data['part']); $i++)
5316                        {
5317                                $id = $control_data['part'][$i];
5318                                list($contact) = $this->read_contact($id);
5319
5320                                $participant[$id] = array();
5321                                $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
5322                        }
5323
5324                        if ($control_data['action'] == lang('Delete selected contacts'))
5325                        {
5326                                for ($i=0; $i<count($control_data['delete']); $i++)
5327                                {
5328                                        $id = $control_data['delete'][$i];
5329                                        unset($participant[$id]);
5330                                }
5331                        }
5332
5333                        if ($control_data['action'] == lang('Add Contact'))
5334                        {
5335                                $id = $_POST['id_addr'];
5336                                if (isset($id) && (int)$id != 0)
5337                                {
5338                                        list($contact) = $this->read_contact($id);
5339                                        $participant[$id] = array();
5340                                        $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
5341                                }
5342                        }
5343
5344                        // create list of currently selected contacts
5345                        //
5346                        while(list($id,$contact) = each($participant))
5347                        {
5348                                $p->set_var('hidden_delete_name','participant[]');
5349                                $p->set_var('hidden_delete_value',$id);
5350                                $p->set_var('ckbox_delete_name','delete[]');
5351                                $p->set_var('ckbox_delete_value',$id);
5352                                $p->set_var('ckbox_delete_participant',$contact['name']);
5353                                $p->parse('V_partlist','B_partlist',True);
5354                                $total_contacts++;
5355                        }
5356
5357                        if ($total_contacts == 0)
5358                        {
5359                                // no contacts have been selected
5360                                // => clear the delete form, remove delete button and show the none block
5361                                //
5362                                $p->set_var('V_partlist','');
5363                                $p->set_var('V_delete_btn','');
5364                                $p->set_var('text_none',lang('None'));
5365                                $p->parse('V_participants_none','B_participants_none');
5366                        }
5367                        else
5368                        {
5369                                // at least one contact has been selected
5370                                // => clear the none block, fill the delete form and add delete button
5371                                //
5372                                $p->set_var('V_participants_none','');
5373                                $p->set_var('btn_delete_name','action');
5374                                $p->set_var('btn_delete_value',lang('Delete selected contacts'));
5375                                $p->parse('V_delete_btn','B_delete_btn');
5376                        }
5377
5378                        $body_tags  = 'bgcolor="'.$GLOBALS['phpgw_info']['theme']['bg_color']
5379                                                        . '" alink="'.$GLOBALS['phpgw_info']['theme']['alink']
5380                                                        . '" link="'.$GLOBALS['phpgw_info']['theme']['link']
5381                                                        .'" vlink="'.$GLOBALS['phpgw_info']['theme']['vlink'].'"';
5382
5383                        $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.modify'));
5384
5385                        $charset = lang('charset');
5386                        $p->set_var('charset',$charset);
5387                        $p->set_var('page_title',$GLOBALS['phpgw_flags']['currentapp']
5388                                . ' - ' .lang('External Participants'));
5389                        $p->set_var('font_family',$GLOBALS['phpgw_info']['theme']['font']);
5390                        $p->set_var('body_tags',$body_tags);
5391                        $p->set_var('form_method','POST');
5392                        $p->set_var('form_action',$form_action);
5393                        $p->set_var('text_add_contact',lang('External Participants'));
5394                        $p->set_var('text_contacts_selected',lang('Selected contacts (%1)',$total_contacts));
5395                        $p->set_var('btn_add_name','action');
5396                        $p->set_var('btn_add_value',lang('Add Contact'));
5397                        $p->set_var('btn_done_name','done');
5398                        $p->set_var('btn_done_value',lang('Done'));
5399                        $p->set_var('btn_done_js','copyback()');
5400                        $p->set_var('form1_name','ext_form');
5401
5402                        $p->pfp('out','T_edit_partlist');
5403                }
5404
5405                function read_contact($id)
5406                {
5407                        $query_fields = Array(
5408                                'n_given' => 'n_given',
5409                                'n_family' => 'n_family',
5410                                'email' => 'email',
5411                                'email_home' => 'email_home'
5412                        );
5413
5414                        /*
5415                        if ($this->rights & PHPGW_ACL_READ)
5416                        {
5417                                return $this->contacts->read_single_entry($id,$fields);
5418                        }
5419                        else
5420                        {
5421                                $rtrn = array(0 => array('No access' => 'No access'));
5422                                return $rtrn;
5423                        }
5424                        */
5425
5426                        $contacts = CreateObject('phpgwapi.contacts', False);
5427                        return $contacts->read_single_entry($id,$query_fields);
5428                }
5429
5430                function build_part_list(&$users,$accounts,$owner)
5431                {
5432                        if(!is_array($accounts))
5433                        {
5434                                return;
5435                        }
5436                        foreach($accounts as $id)
5437                        {
5438                                $id = (int)$id;
5439                                if($id == $owner)
5440                                {
5441                                        continue;
5442                                }
5443                                elseif(!isset($users[$id]))
5444                                {
5445                                        if($GLOBALS['phpgw']->accounts->exists($id) == True)
5446                                        {
5447                                                $users[$id] = Array(
5448                                                        'name'  => $GLOBALS['phpgw']->common->grab_owner_name($id),
5449                                                        'type'  => $GLOBALS['phpgw']->accounts->get_type($id)
5450                                                );
5451                                        }
5452                                        if($GLOBALS['phpgw']->accounts->get_type($id) == 'g')
5453                                        {
5454                                                //$this->build_part_list($users,$GLOBALS['phpgw']->acl->get_ids_for_location($id,1,'phpgw_group'),$owner);
5455                                        }
5456                                }
5457                        }
5458                        if (!function_exists('strcmp_name'))
5459                        {
5460                                function strcmp_name($arr1,$arr2)
5461                                {
5462                                        if ($diff = strcmp($arr1['type'],$arr2['type']))
5463                                        {
5464                                                return $diff;   // groups before users
5465                                        }
5466                                        return strnatcasecmp($arr1['name'],$arr2['name']);
5467                                }
5468                        }
5469                        uasort($users,'strcmp_name');
5470                }
5471
5472                function set_week_array($startdate,$cellcolor,$weekly)
5473                {
5474                        $data = date("m");
5475                        for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
5476                        {
5477                                $date = date('Ymd',$datetime + (60 * 60 * 2)); // +2h to be save when switching to and from dst, $datetime is alreay + TZ-Offset
5478                                print_debug('set_week_array : Date ',$date);
5479
5480                                if($events = $this->bo->cached_events[$date])
5481                                {
5482                                        print_debug('Date',$date);
5483                                        print_debug('Appointments Found',count($events));
5484
5485                                        if (!$this->bo->prefs['calendar']['show_rejected'])
5486                                        {
5487                                                $appts = False;
5488                                                foreach($events as $event)      // check for a not-rejected event
5489                                                {
5490                                                        if (!$this->bo->rejected_no_show($event))
5491                                                        {
5492                                                                $appts = True;
5493                                                                break;
5494                                                        }
5495                                                }
5496                                        }
5497                                        else
5498                                        {
5499                                                $appts = True;
5500                                        }
5501                                }
5502                                else
5503                                {
5504                                        $appts = False;
5505                                }
5506
5507                                $holidays = $this->bo->cached_holidays[$date];
5508                                if($weekly)
5509                                {
5510                                        $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
5511                                }
5512
5513                                $day_image = '';
5514                                if($holidays)
5515                                {
5516                                        $extra = ' bgcolor="'.$this->bo->holiday_color.'"';
5517                                        $class = ($appts?'b':'').'minicalhol';
5518                                        if ($date == $this->bo->today)
5519                                        {
5520                                                $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5521                                        }
5522                                }
5523                                elseif ($date != $this->bo->today)
5524                                {
5525                                        $extra = ' bgcolor="'.$cellcolor.'"';
5526                                        $class = ($appts?'b':'').'minicalendar';
5527                                }
5528                                else
5529                                {
5530                                        $extra = ' bgcolor="'.$GLOBALS['phpgw_info']['theme']['cal_today'].'"';
5531                                        $class = ($appts?'b':'').'minicalendar';
5532                                        $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5533                                }
5534
5535                                if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
5536                                {
5537                                        $extra = '';
5538                                }
5539
5540                                if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
5541                                {
5542                                        $new_event = True;
5543                                }
5544                                else
5545                                {
5546                                        $new_event = False;
5547                                }
5548                                $holiday_name = Array();
5549                                if($holidays)
5550                                {
5551                                        for($k=0;$k<count($holidays);$k++)
5552                                        {
5553                                                $holiday_name[] = $holidays[$k]['name'];
5554                                        }
5555                                }
5556                                $week = '';
5557                                if (!$j || (!$weekly && $j && substr($date,6,2) == '01'))
5558                                {
5559                                        $week = lang('week').' '.(int)((date('z',($startdate+(24*3600*4)))+7)/7);
5560                                }
5561                                $daily[$date] = Array(
5562                                        'extra'         => $extra,
5563                                        'new_event'     => $new_event,
5564                                        'holidays'      => $holiday_name,
5565                                        'appts'         => $appts,
5566                                        'week'          => $week,
5567                                        'day_image'     => $day_image,
5568                                        'class'         => $class
5569                                );
5570                        }
5571
5572                        if($this->debug)
5573                        {
5574                                _debug_array($daily);
5575                        }
5576
5577                        return $daily;
5578                }
5579               
5580                function get_organizations($context, $selected='', $recursive = false)
5581                {
5582                        $s = CreateObject('phpgwapi.sector_search_ldap');
5583                                               
5584                        return ($recursive ?
5585                                $s->get_organizations($context, $selected, false ,false) :
5586                                $s->get_sectors($selected, false, false));
5587                }               
5588        }
5589?>
Note: See TracBrowser for help on using the repository browser.