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

Revision 360, 165.3 KB checked in by rafaelraymundo, 16 years ago (diff)

Melhoria no layout da impreao mensal.

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