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

Revision 362, 165.5 KB checked in by niltonneto, 16 years ago (diff)

Resolvido bug 134.

  • 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                       
2578                        include($file);
2579                        $refer = explode('.',$GLOBALS['HTTP_GET_VARS']['menuaction']);
2580                        if($refer[2] != 'view') {
2581                        $header = $tpl->fp('out','head');
2582                        unset($tpl);
2583                        echo $header;
2584                }
2585                        unset($tpl);
2586                }
2587
2588                function footer()
2589                {
2590                        $menuaction = $_GET['menuaction'];
2591                        list(,,$method) = explode('.',$menuaction);
2592
2593                        if (@$this->bo->printer_friendly)
2594                        {
2595                                return;
2596                        }
2597
2598                        $p = $GLOBALS['phpgw']->template;
2599
2600                        $p->set_file(
2601                                Array(
2602                                        'footer'        => 'footer.tpl',
2603                                        'form_button'   => 'form_button_script.tpl'
2604                                )
2605                        );
2606                        $p->set_block('footer','footer_table','footer_table');
2607                        $p->set_block('footer','footer_row','footer_row');
2608                        $p->set_block('footer','blank_row','blank_row');
2609
2610                        $m = $this->bo->month;
2611                        $y = $this->bo->year;
2612
2613                        $thisdate = date('Ymd',mktime(0,0,0,$m,1,$y));
2614                        $y--;
2615
2616                        $str = '';
2617                        for ($i = 0; $i < 25; $i++)
2618                        {
2619                                $m++;
2620                                if ($m > 12)
2621                                {
2622                                        $m = 1;
2623                                        $y++;
2624                                }
2625                                $d = mktime(0,0,0,$m,1,$y);
2626                                $d_ymd = date('Ymd',$d);
2627                                $str .= '<option value="'.$d_ymd.'"'.($d_ymd == $thisdate?' selected':'').'>'.lang(date('F', $d)).strftime(' %Y', $d).'</option>'."\n";
2628                        }
2629
2630                        $var = Array(
2631                                'action_url'    => $this->page($method,''),
2632                                'form_name'     => 'SelectMonth',
2633                                'label'         => lang('Month'),
2634                                'form_label'    => 'date',
2635                                'form_onchange' => 'document.SelectMonth.submit()',
2636                                'row'           => $str,
2637                                'go'            => lang('Go!')
2638                        );
2639                        $this->output_template_array($p,'table_row','footer_row',$var);
2640
2641                        if($menuaction == 'calendar.uicalendar.week')
2642                        {
2643                                unset($thisdate);
2644                                $thisdate = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
2645                                $sun = $GLOBALS['phpgw']->datetime->get_weekday_start($this->bo->year,$this->bo->month,$this->bo->day) - $GLOBALS['phpgw']->datetime->tz_offset;
2646
2647                                $str = '';
2648                                for ($i = -7; $i <= 7; $i++)
2649                                {
2650                                        $begin = $sun + (7*24*60*60 * $i) + 12*60*60;   // we use midday, that changes in daylight-saveing does not effect us
2651                                        $end = $begin + 6*24*60*60;
2652//                                      echo "<br>$i: ".date('d.m.Y H:i',$begin).' - '.date('d.m.Y H:i',$end);
2653                    $str .= '<option value="' . $GLOBALS['phpgw']->common->show_date($begin,'Ymd') . '"'.($begin <= $thisdate+12*60*60 && $end >= $thisdate+12*60*60 ? ' selected':'').'>'                   
2654                                                . $GLOBALS['phpgw']->common->show_date($begin,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) . ' - '
2655                        . $GLOBALS['phpgw']->common->show_date($end,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
2656                        . '</option>' . "\n";                       
2657                                }
2658
2659                                $var = Array(
2660                                        'action_url'    => $this->page($method,''),
2661                                        'form_name'     => 'SelectWeek',
2662                                        'label'         => lang('Week'),
2663                                        'form_label'    => 'date',
2664                                        'form_onchange' => 'document.SelectWeek.submit()',
2665                                        'row'           => $str,
2666                                        'go'            => lang('Go!')
2667                                );
2668
2669                                $this->output_template_array($p,'table_row','footer_row',$var);
2670                        }
2671
2672                        $str = '';
2673                        for ($i = ($this->bo->year - 3); $i < ($this->bo->year + 3); $i++)
2674                        {
2675                                $str .= '<option value="'.$i.'"'.($i == $this->bo->year?' selected':'').'>'.$i.'</option>'."\n";
2676                        }
2677
2678                        $var = Array(
2679                                'action_url'    => $this->page($method,''),
2680                                'form_name'     => 'SelectYear',
2681                                'label'         => lang('Year'),
2682                                'form_label'    => 'year',
2683                                'form_onchange' => 'document.SelectYear.submit()',
2684                                'row'           => $str,
2685                                'go'            => lang('Go!')
2686                        );
2687                        $this->output_template_array($p,'table_row','footer_row',$var);
2688
2689                        if($menuaction == 'calendar.uicalendar.planner')
2690                        {
2691                                $str = '';
2692                                $date_str = '';
2693
2694                                if(isset($_GET['date']) && $_GET['date'])
2695                                {
2696                                        $date_str .= '    <input type="hidden" name="date" value="'.$_GET['date'].'">'."\n";
2697                                }
2698                                $date_str .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
2699                                $date_str .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
2700                                $date_str .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
2701
2702                                for($i=1; $i<=6; $i++)
2703                                {
2704                                        $str .= '<option value="'.$i.'"'.($i == $this->bo->num_months?' selected':'').'>'.$i.'</option>'."\n";
2705                                }
2706
2707                                $var = Array(
2708                                        'action_url'    => $this->page($method,''),
2709                                        'form_name'     => 'SelectNumberOfMonths',
2710                                        'label'         => lang('Number of Months'),
2711                                        'hidden_vars' => $date_str,
2712                                        'form_label'    => 'num_months',
2713                                        'form_onchange' => 'document.SelectNumberOfMonths.submit()',
2714                                        'action_extra_field'    => $date_str,
2715                                        'row'           => $str,
2716                                        'go'            => lang('Go!')
2717                                );
2718                                $this->output_template_array($p,'table_row','footer_row',$var);
2719                        }
2720
2721                        $var = Array(
2722                                'submit_button'         => lang('Submit'),
2723                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uiicalendar.import'),
2724                                'action_text_button'    => lang('Import'),
2725                                'action_confirm_button' => '',
2726                                'action_extra_field'    => ''
2727                        );
2728                        $this->output_template_array($p,'b_row','form_button',$var);
2729                       
2730                        $var = Array(
2731                                'submit_button'         => lang('Submit'),
2732                                'action_url'    => $this->page($method,''),
2733                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.export_all'),
2734                                'action_text_button'    => lang('Export all'),
2735                                'action_confirm_button' => '',
2736                                'action_extra_field'    => ''
2737                        );
2738                        $this->output_template_array($p,'b_row2','form_button',$var);
2739                                       
2740                        $p->parse('table_row','blank_row',True);
2741
2742                        $p->pparse('out','footer_table');
2743                        unset($p);
2744                }
2745
2746                function css()
2747                {
2748                        $GLOBALS['phpgw']->browser->browser();
2749                        if($GLOBALS['phpgw']->browser->get_agent() == 'MOZILLA')
2750                        {
2751                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?12:8);
2752                        }
2753                        else
2754                        {
2755                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?10:7);
2756                        }
2757
2758// moved to app.css in templates/default for future separation of code and style [NDEE 10.03.04]
2759/*
2760                         return 'A.minicalendar { color: #000000; font-size: 72%; font-family: '.$this->theme['font'].' }'."\n"
2761                                . '  A.bminicalendar { color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2762                                . '  A.minicalendargrey { color: #999999; font-size: 8px; font-family: '.$this->theme['font'].' }'."\n"
2763                                . '  A.bminicalendargrey { color: #336699; font-style: italic; font-size:8px; font-family '.$this->theme['font'].' }'."\n"
2764                                . '  A.minicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #000000; font: x-small '.$this->theme['font'].' }'."\n"
2765                                . '  A.bminicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2766                                . '  A.minicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: x-small '.$this->theme['font'].' }'."\n"
2767                                . '  A.bminicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2768                                . '  .event-on { background: '.$this->theme['row_on'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2769                                . '  .event-off { background: '.$this->theme['row_off'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2770                                . '  .event-holiday { background: '.$this->theme['bg04'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2771                                . '  .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"
2772                                . '  .tablecell { width: 80px; height: 80px }'."\n"
2773                                . '  .planner-cell { cursor:pointer; cursor:hand; border: thin solid black; }';
2774*/
2775                }
2776
2777                function no_edit()
2778                {
2779                        if(!isset($GLOBALS['phpgw_info']['flags']['noheader']))
2780                        {
2781                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
2782                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2783                                $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
2784                                $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
2785                                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Permission denied');
2786                                $GLOBALS['phpgw']->common->phpgw_header();
2787                        }
2788                        echo '<center>You do not have permission to edit this appointment!</center>';
2789                        return;
2790                }
2791
2792                function link_to_entry($event,$month,$day,$year)
2793                {
2794                        $str = '';
2795                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
2796                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
2797
2798                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2799                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
2800                        $rawdate = mktime(0,0,0,$month,$day,$year);
2801                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
2802                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
2803                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
2804                        {
2805                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
2806                        }
2807                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
2808                        {
2809                                $time = '[ '.lang('All Day').' ]';
2810                        }
2811                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
2812                        {
2813                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
2814                                {
2815                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
2816                                }
2817                                else
2818                                {
2819                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
2820                                }
2821
2822                                if($endtime >= ($rawdate_offset + 86400))
2823                                {
2824                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
2825                                }
2826                                else
2827                                {
2828                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
2829                                }
2830                                $time = $start_time.'-'.$end_time;
2831                        }
2832                        else
2833                        {
2834                                $time = '';
2835                        }
2836                       
2837                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
2838
2839                       
2840                       
2841                        if(!$is_private)
2842                        {
2843                                //$text .= $this->bo->display_status($event['users_status']);
2844                               
2845                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
2846                                $textstatus=$this->bo->display_status($event['users_status']);
2847                               
2848                        }
2849
2850                        /*
2851                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
2852                                (!$is_private && $event['description'] ? ': <i>'.$this->bo->get_short_field($event,$is_private,'description').'</i>':'').
2853                                $GLOBALS['phpgw']->browser->br;
2854                        */
2855                       
2856                        $texttime=$time;
2857                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
2858                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
2859                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
2860                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
2861
2862                        if ($viewable)
2863                        {
2864                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
2865                                $this->link_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
2866                                $this->link_tpl->set_var('lang_view',lang('View this entry'));
2867                                $this->link_tpl->set_var('desc', $textdesc);
2868                                $this->link_tpl->set_var('location', $textlocation);
2869                                $this->link_tpl->parse('picture','link_open',True);
2870                        }
2871                        if (!$is_private)
2872                        {
2873                                if($event['priority'] == 3)
2874                                {
2875                                        $picture[] = Array(
2876                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
2877                                                'width' => 16,
2878                                                'height'=> 16,
2879                                                'title' => lang('high priority')
2880                                        );
2881                                }
2882                                if($event['recur_type'] == MCAL_RECUR_NONE)
2883                                {
2884                                        $picture[] = Array(
2885                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
2886                                                'width' => 9,
2887                                                'height'=> 9,
2888                                                'title' => lang('single event')
2889                                        );
2890                                }
2891                                else
2892                                {
2893                                        $picture[] = Array(
2894                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
2895                                                'width' => 12,
2896                                                'height'=> 12,
2897                                                'title' => lang('recurring event')
2898                                        );
2899                                }
2900                        }
2901                        $participants = $this->planner_participants($event['participants']);
2902                        if(count($event['participants']) > 1)
2903                        {
2904                                $picture[] = Array(
2905                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
2906                                        'width' => 14,
2907                                        'height'=> 14,
2908                                        'title' => $participants
2909                                );
2910                        }
2911                        else
2912                        {
2913                                $picture[] = Array(
2914                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
2915                                        'width' => 14,
2916                                        'height'=> 14,
2917                                        'title' => $participants
2918                                );
2919                        }
2920                        if($event['public'] == 0)
2921                        {
2922                                $picture[] = Array(
2923                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
2924                                        'width' => 13,
2925                                        'height'=> 13,
2926                                        'title' => lang('private')
2927                                );
2928                        }
2929                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
2930                        {
2931                                // if the alarm is to go off the day before the event
2932                                // the icon does not show up because of 'alarm_today'
2933                                // - TOM
2934                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
2935                                {
2936                                        $picture[] = Array(
2937                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
2938                                                'width' => 13,
2939                                                'height'=> 13,
2940                                                'title' => lang('alarm')
2941                                        );
2942                                }
2943                        }
2944
2945                        $description = $this->bo->get_short_field($event,$is_private,'description');
2946                        for($i=0;$i<count($picture);$i++)
2947                        {
2948                                $var = Array(
2949                                        'pic_image' => $picture[$i]['pict'],
2950                                        'width'     => $picture[$i]['width'],
2951                                        'height'    => $picture[$i]['height'],
2952                                        'title'     => $picture[$i]['title']
2953                                );
2954                                $this->output_template_array($this->link_tpl,'picture','pict',$var);
2955                        }
2956                        if ($texttitle)
2957                        {
2958                                $var = Array(
2959                        //              'text' => $text,
2960                                        'time'=> $texttime,
2961                                        'title'=> $texttitle,
2962                                        'users_status'=>$textstatus,
2963                                        'desc'=> $textdesc,
2964                                        'location'=> "<br><b>Local:</b> ".$textlocation
2965                                );
2966                                $this->output_template_array($this->link_tpl,'picture','link_text',$var);
2967                        }
2968
2969                        if ($viewable)
2970                        {
2971                                $this->link_tpl->parse('picture','link_close',True);
2972                        }
2973                        $str = $this->link_tpl->fp('out','link_pict');
2974                        $this->link_tpl->set_var('picture','');
2975                        $this->link_tpl->set_var('out','');
2976//                      unset($p);
2977                        return $str;
2978                }
2979
2980/*****************************************************************************************/
2981/*Funcao foi duplicada e alterada para tratar os eventos de agendamento (exibicao do mes) para impressao;
2982utiliza o template event_lik.tpl*/
2983
2984                function link_to_month_entry($event,$month,$day,$year)
2985                {
2986                        $str = '';
2987                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
2988                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
2989
2990                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2991                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
2992                        $rawdate = mktime(0,0,0,$month,$day,$year);
2993                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
2994                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
2995                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
2996                        {
2997                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
2998                        }
2999                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
3000                        {
3001                                $time = '[ '.lang('All Day').' ]';
3002                        }
3003                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
3004                        {
3005                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
3006                                {
3007                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
3008                                }
3009                                else
3010                                {
3011                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3012                                }
3013
3014                                if($endtime >= ($rawdate_offset + 86400))
3015                                {
3016                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
3017                                }
3018                                else
3019                                {
3020                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
3021                                }
3022                                $time = $start_time.' - '.$end_time;
3023                        }
3024                        else
3025                        {
3026                                $time = '';
3027                        }
3028                       
3029                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
3030
3031                       
3032                       
3033                        if(!$is_private)
3034                        {
3035                                //$text .= $this->bo->display_status($event['users_status']);
3036                               
3037                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
3038                                $textstatus=$this->bo->display_status($event['users_status']);
3039                               
3040                        }
3041
3042                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
3043                       
3044                        $texttime=$time;
3045                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
3046                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
3047                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
3048                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
3049
3050                        if ($viewable)
3051                        {
3052                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
3053                                $this->event_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
3054                                $this->event_tpl->set_var('lang_view',lang('View this entry'));
3055                                $this->event_tpl->set_var('desc', $textdesc);
3056                                $this->event_tpl->set_var('location', $textlocation);
3057                                $this->event_tpl->parse('picture','link_event_open',True);
3058                        }
3059                        if (!$is_private)
3060                        {
3061                                if($event['priority'] == 3)
3062                                {
3063                                        $picture[] = Array(
3064                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
3065                                                'width' => 16,
3066                                                'height'=> 16,
3067                                                'title' => lang('high priority')
3068                                        );
3069                                }
3070                                if($event['recur_type'] == MCAL_RECUR_NONE)
3071                                {
3072                                        $picture[] = Array(
3073                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
3074                                                'width' => 9,
3075                                                'height'=> 9,
3076                                                'title' => lang('single event')
3077                                        );
3078                                }
3079                                else
3080                                {
3081                                        $picture[] = Array(
3082                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
3083                                                'width' => 12,
3084                                                'height'=> 12,
3085                                                'title' => lang('recurring event')
3086                                        );
3087                                }
3088                        }
3089                        $participants = $this->planner_participants($event['participants']);
3090                        if(count($event['participants']) > 1)
3091                        {
3092                                $picture[] = Array(
3093                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
3094                                        'width' => 14,
3095                                        'height'=> 14,
3096                                        'title' => $participants
3097                                );
3098                        }
3099                        else
3100                        {
3101                                $picture[] = Array(
3102                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
3103                                        'width' => 14,
3104                                        'height'=> 14,
3105                                        'title' => $participants
3106                                );
3107                        }
3108                        if($event['public'] == 0)
3109                        {
3110                                $picture[] = Array(
3111                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
3112                                        'width' => 13,
3113                                        'height'=> 13,
3114                                        'title' => lang('private')
3115                                );
3116                        }
3117                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
3118                        {
3119                                // if the alarm is to go off the day before the event
3120                                // the icon does not show up because of 'alarm_today'
3121                                // - TOM
3122                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
3123                                {
3124                                        $picture[] = Array(
3125                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
3126                                                'width' => 13,
3127                                                'height'=> 13,
3128                                                'title' => lang('alarm')
3129                                        );
3130                                }
3131                        }
3132
3133                        $description = $this->bo->get_short_field($event,$is_private,'description');
3134                        for($i=0;$i<count($picture);$i++)
3135                        {
3136                                $var = Array(
3137                                        'pic_image' => $picture[$i]['pict'],
3138                                        'width'     => $picture[$i]['width'],
3139                                        'height'    => $picture[$i]['height'],
3140                                        'title'     => $picture[$i]['title']
3141                                );
3142                                $this->output_template_array($this->event_tpl,'picture','event_pict',$var);
3143                        }
3144                        if ($texttitle)
3145                        {
3146                                $var = Array(
3147                        //              'text' => $text,
3148                                        'time'=> $texttime,
3149                                        'title'=> $texttitle,
3150                                        'users_status'=>$textstatus,
3151                                        'desc'=> $textdesc,
3152                                        'location'=> "<br><b>Local:</b> ".$textlocation
3153                                );
3154                                $this->output_template_array($this->event_tpl,'picture','link_event_text',$var);
3155                        }
3156
3157                        if ($viewable)
3158                        {
3159                                $this->event_tpl->parse('picture','link_event_close',True);
3160                        }
3161                        $str = $this->event_tpl->fp('out','link_event_pict');
3162                        $this->event_tpl->set_var('picture','');
3163                        $this->event_tpl->set_var('out','');
3164//                      unset($p);
3165                        return $str;
3166                }
3167
3168/*****************************************************************************************/
3169
3170                function overlap($params)
3171                {
3172                        if(!is_array($params))
3173                        {
3174                        }
3175                        else
3176                        {
3177                                $overlapping_events = $params['o_events'];
3178                                $event = $params['this_event'];
3179                        }
3180
3181                        $month = $event['start']['month'];
3182                        $mday = $event['start']['mday'];
3183                        $year = $event['start']['year'];
3184
3185                        $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3186                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3187
3188                        $overlap = '';
3189                        for($i=0;$i<count($overlapping_events);$i++)
3190                        {
3191                                $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True);
3192                                $overlap .= '<li>'.$this->link_to_entry($overlapped_event,$month,$mday,$year);
3193                                $overlap .= '<ul>';
3194                                foreach($overlapped_event['participants'] as $id => $status)
3195                                {
3196                                        $conflict = isset($event['participants'][$id]);
3197                                        $overlap .= '<li>'.($conflict?'<b>':'').
3198                                                $GLOBALS['phpgw']->common->grab_owner_name($id).
3199                                                ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>\n";
3200                                }
3201                                $overlap .= "</ul>\n";
3202                        }
3203
3204                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
3205                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3206                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3207                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3208                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict');
3209                        $GLOBALS['phpgw']->common->phpgw_header();
3210
3211                        $p = $GLOBALS['phpgw']->template;
3212                        $p->set_file(
3213                                Array(
3214                                        'overlap'       => 'overlap.tpl',
3215                                        'form_button'   => 'form_button_script.tpl'
3216                                )
3217                        );
3218
3219                        $var = Array(
3220                                'color'         => $this->theme['bg_text'],
3221                                'overlap_title' => lang('Scheduling Conflict'),
3222                                '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)),
3223                                'overlap_list'  => $overlap
3224                        );
3225                        $p->set_var($var);
3226
3227                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday);
3228                        $var = Array(
3229                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update','readsess'=>1)),
3230                                'action_text_button'    => lang('Ignore Conflict'),
3231                                'action_confirm_button' => '',
3232                                'action_extra_field'    => ''
3233                        );
3234                        $this->output_template_array($p,'resubmit_button','form_button',$var);
3235
3236                        $var = Array(
3237                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.edit','readsess'=>1,'date'=>$date)),
3238                                'action_text_button'    => lang('Re-Edit Event'),
3239                                'action_confirm_button' => '',
3240                                'action_extra_field'    => ''
3241                        );
3242                        $this->output_template_array($p,'reedit_button','form_button',$var);
3243                        $p->pparse('out','overlap');
3244                }
3245
3246                function planner_participants($parts)
3247                {
3248                        static $id2lid;
3249
3250                        $names = '';
3251                        while (list($id,$status) = each($parts))
3252                        {
3253                                $status = substr($this->bo->get_long_status($status),0,1);
3254
3255                                if (!isset($id2lid[$id]))
3256                                {
3257                                        $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id);
3258                                }
3259                                if (strlen($names))
3260                                {
3261                                        $names .= ",\n";
3262                                }
3263                                $names .= $id2lid[$id]." ($status)";
3264                        }
3265                        if($this->debug)
3266                        {
3267                                echo '<!-- Inside participants() : '.$names.' -->'."\n";
3268                        }
3269                        return $names;
3270                }
3271
3272                function planner_category($ids)
3273                {
3274                        static $cats;
3275                        if(!is_array($ids))
3276                        {
3277                                if (strpos($ids,','))
3278                                {
3279                                        $id_array = explode(',',$ids);
3280                                }
3281                                else
3282                                {
3283                                        $id_array[0] = $ids;
3284                                }
3285                        }
3286                        @reset($id_array);
3287                        $ret_val = Array();
3288                        while(list($index,$id) = each($id_array))
3289                        {
3290                                if (!isset($cats[$id]))
3291                                {
3292                                        $cat_arr = $this->cat->return_single( $id );
3293                                        $cats[$id] = $cat_arr[0];
3294                                        $cats[$id]['color'] = strstr($cats[$id]['description'],'#');
3295                                }
3296                                $ret_val[] = $cats[$id];
3297                        }
3298                        return $ret_val;
3299                }
3300
3301                function week_header($month,$year,$display_name = False)
3302                {
3303                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3304
3305                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3306                        $p->set_unknowns('remove');
3307                        $p->set_file(
3308                                Array (
3309                                        'month_header' => 'month_header.tpl'
3310                                )
3311                        );
3312                        $p->set_block('month_header','monthly_header','monthly_header');
3313                        $p->set_block('month_header','column_title','column_title');
3314
3315                        $var = Array(
3316                                'bgcolor'       => $this->theme['th_bg'],
3317                                'font_color'    => $this->theme['th_text']
3318                        );
3319                        if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
3320                        {
3321                                $var = Array(
3322                                        'bgcolor'       => '',
3323                                        'font_color'    => ''
3324                                );
3325                        }
3326                        $p->set_var($var);
3327
3328                        $p->set_var('col_width','14');
3329                        if($display_name == True)
3330                        {
3331                                $p->set_var('col_title',lang('name'));
3332                                $p->parse('column_header','column_title',True);
3333                                $p->set_var('col_width','12');
3334                        }
3335
3336                        for($i=0;$i<7;$i++)
3337                        {
3338                                $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
3339                                $p->parse('column_header','column_title',True);
3340                        }
3341                        return $p->fp('out','monthly_header');
3342                }
3343
3344                function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3345                {
3346                        if($owner == 0)
3347                        {
3348                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3349                        }
3350
3351                        $temp_owner = $this->bo->owner;
3352
3353                        $str = '';
3354                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3355                        $p->set_unknowns('keep');
3356
3357                        $p->set_file(
3358                                Array(
3359                                        'month_header'  => 'month_header.tpl',
3360                                        'month_day'     => 'month_day.tpl'
3361                                )
3362                        );
3363                        $p->set_block('month_header','monthly_header','monthly_header');
3364                        $p->set_block('month_header','month_column','month_column');
3365                        $p->set_block('month_day','month_daily','month_daily');
3366                        $p->set_block('month_day','day_event','day_event');
3367                        $p->set_block('month_day','event','event');
3368
3369                        $p->set_var('extra','');
3370                        $p->set_var('col_width','14');
3371                        if($display_name)
3372                        {
3373                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
3374                                $p->parse('column_header','month_column',True);
3375                                $p->set_var('col_width','12');
3376                        }
3377                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3378                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3379                        foreach($daily as $date => $day_params)
3380                        {
3381                                $year  = (int)substr($date,0,4);
3382                                $month = (int)substr($date,4,2);
3383                                $day   = (int)substr($date,6,2);
3384                                $var   = Array(
3385                                        'column_data' => '',
3386                                        'extra' => ''
3387                                );
3388                                $p->set_var($var);
3389                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
3390                                {
3391                                        if ($day_params['new_event'])
3392                                        {
3393                                                $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
3394                                                        . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
3395                                                        . '</a>';
3396                                                $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
3397                                        }
3398                                        else
3399                                        {
3400                                                $new_event_link = '';
3401                                                $day_number = $day;
3402                                        }
3403
3404                                        $var = Array(
3405                                                'extra'         => $day_params['extra'],
3406                                                'new_event_link'=> $new_event_link,
3407                                                'day_number'    => $day_number
3408                                        );
3409                                        if($day_params['week'])
3410                                        {
3411
3412//NDEE: style! m_w_table in month_day.tpl
3413// week-hilite
3414                                                //$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
3415                                                $var['new_event_link'] .= ' &nbsp; '.
3416                                                        (!$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>');
3417                                        }
3418
3419                                        $p->set_var($var);
3420
3421                                        if(@$day_params['holidays'])
3422                                        {
3423                                                foreach($day_params['holidays'] as $key => $value)
3424                                                {
3425                                                        $var = Array(
3426                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
3427                                                        );
3428                                                        $this->output_template_array($p,'daily_events','event',$var);
3429                                                }
3430                                        }
3431
3432                                        if($day_params['appts'])
3433                                        {
3434                                                $var = Array(
3435                                                        'week_day_font_size'    => '2',
3436                                                        'events'                => ''
3437                                                );
3438                                                $p->set_var($var);
3439                                                $events = $this->bo->cached_events[$date];
3440                                                foreach($events as $event)
3441                                                {
3442                                                        if ($this->bo->rejected_no_show($event))
3443                                                        {
3444                                                                continue;       // user does not want to see rejected events
3445                                                        }
3446                                                        $p->set_var('day_events',$this->link_to_entry($event,$month,$day,$year));
3447                                                        $p->parse('events','event',True);
3448                                                        $p->set_var('day_events','');
3449                                                }
3450                                        }
3451                                        $p->parse('daily_events','day_event',True);
3452                                        $p->parse('column_data','month_daily',True);
3453                                        $p->set_var('daily_events','');
3454                                        $p->set_var('events','');
3455/*                                      if($day_params['week'])
3456                                        {
3457                                                $var = Array(
3458                                                        'week_day_font_size'    => '-2',
3459                                                        'events'                => (!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'">' .$day_params['week'].'</a>':$day_params['week'])
3460                                                );
3461                                                $this->output_template_array($p,'column_data','day_event',$var);
3462                                                $p->set_var('events','');
3463                                        } */
3464                                }
3465                                $p->parse('column_header','month_column',True);
3466                                $p->set_var('column_data','');
3467                        }
3468                        $this->bo->owner = $temp_owner;
3469                        return $p->fp('out','monthly_header');
3470                }
3471
3472/***************************************************************************************/
3473/*As funcoes abaixo
3474        month_week_header()
3475        month_display_week()
3476        display_month_print()
3477        month_day_of_week() - esta foi criada mas parte do codigo e de outra funcao da API (day_of_week());
3478
3479  foram duplicadas e modificadas para atender aas modificacoes do layout de impressao mensal da agenda de eventos;
3480  TODO: otimizar o codigo
3481
3482  Rommel Cysne
3483*/
3484
3485                function month_week_header($month,$year,$display_name = False)
3486                {
3487                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3488
3489                //      $p = CreateObject('phpgwapi.Template',$this->template_dir);
3490                        $p->set_unknowns('remove');
3491                //      $p->set_file(
3492                //              Array (
3493                //                      'month_header' => 'month_header_print.tpl'
3494                //              )
3495                //      );
3496        //              $p->set_block('month_header','monthly_header','monthly_header');
3497        //              $p->set_block('month_header','column_title','column_title');
3498
3499/*                      $var = Array(
3500                                'bgcolor'       => $this->theme['th_bg'],
3501                                'font_color'    => $this->theme['th_text']
3502                        );
3503                        /*if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
3504                        {
3505                                $var = Array(
3506                                        'bgcolor'       => '',
3507                                        'font_color'    => ''
3508                                );
3509                        }*/
3510        /*              $p->set_var($var);
3511
3512                        $p->set_var('col_width','14');
3513                /*      if($display_name == True)
3514                        {
3515                                $p->set_var('col_title',lang('name'));
3516                                $p->parse('column_header','column_title',True);
3517                                $p->set_var('col_width','12');
3518                        }
3519*/
3520                        //for($i=0;$i<7;$i++)
3521                        //{
3522                        //      $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
3523                        //      $p->parse('column_header','column_title',True);
3524                        //}
3525//                      return $p->fp('out','monthly_header');
3526                }
3527
3528
3529                function month_day_of_week($year,$month,$day)
3530                {
3531                        $dia = Array(
3532                                0 => 'Domingo',
3533                                1 => 'Segunda',
3534                                2 => 'Ter&ccedil;a',
3535                                3 => 'Quarta',
3536                                4 => 'Quinta',
3537                                5 => 'Sexta',
3538                                6 => 'S&aacute;bado'
3539                        );
3540
3541                        if($month > 2)
3542                        {
3543                                $month -= 2;
3544                        }
3545                                else
3546                        {
3547                                $month += 10;
3548                                $year--;
3549                        }
3550                        $day = (floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * floor($year / 100) + 77);
3551
3552                        $month_day = ($day - 7 * floor($day / 7)); //retorna o numero do dia da semana (Ex: domingo eh dia 0, terca eh 2);
3553                        $weekday = $dia[$month_day]; //retorna o nome do dia da semana de acordo com seu numero;
3554
3555                        return ($weekday);
3556
3557                }
3558
3559                function month_display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3560                {
3561                        if($owner == 0)
3562                        {
3563                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3564                        }
3565
3566                        $temp_owner = $this->bo->owner;
3567
3568                        $str = '';
3569                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3570                        $p->set_unknowns('keep');
3571
3572                        $p->set_file(
3573                                Array(
3574                                        'month_header'  => 'month_header_print.tpl',
3575                                        'month_day'     => 'month_day_print.tpl'
3576                                )
3577                        );
3578                        $p->set_block('month_header','monthly_header','monthly_header');
3579                        $p->set_block('month_header','month_column','month_column');
3580                        $p->set_block('month_day','month_daily','month_daily');
3581                        $p->set_block('month_day','day_event','day_event');
3582                        $p->set_block('month_day','event','event');
3583
3584                        $p->set_var('extra','');
3585                        $p->set_var('col_width','14');
3586                /*      if($display_name)
3587                        {
3588                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
3589                                $p->parse('column_header','month_column',True);
3590                                $p->set_var('col_width','12');
3591                        }*/
3592                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3593                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3594                        foreach($daily as $date => $day_params)
3595                        {
3596                                $year  = (int)substr($date,0,4);
3597                                $month = (int)substr($date,4,2);
3598                                $day   = (int)substr($date,6,2);
3599                                $var   = Array(
3600                                        'column_data' => '',
3601                                        'extra' => ''
3602                                );
3603                                $p->set_var($var);
3604                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
3605                                {
3606                                        //if ($day_params['new_event'])
3607                                        //{
3608                                        //      $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
3609                                        //              . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
3610                                        //              . '</a>';
3611                                        //      $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
3612                                        //}
3613                                        //else
3614                                        //{
3615                                                $new_event_link = '';
3616                                                $day_num = $day;
3617                                                $dia_semana = $this->month_day_of_week($year,$month,$day_num);
3618                                                $day_number = $dia_semana . ",  " . $day_num;
3619                                        //}
3620
3621                                        $var = Array(
3622                                                'extra'         => $day_params['extra'],
3623                                                'new_event_link'=> $new_event_link,
3624                                                'day_number'    => $day_number
3625                                        );
3626        /*                              if($day_params['week'])
3627                                        {
3628
3629//NDEE: style! m_w_table in month_day.tpl
3630// week-hilite
3631                                                //$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
3632        //                                      $var['new_event_link'] .= ' &nbsp; '.
3633        //                                              (!$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>');
3634                                        }
3635        */
3636                       
3637
3638                                        $p->set_var($var);
3639
3640        /*                              if(@$day_params['holidays'])
3641                                        {
3642                                                foreach($day_params['holidays'] as $key => $value)
3643                                                {
3644                                                        $var = Array(
3645                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
3646                                                        );
3647                                                        $this->output_template_array($p,'daily_events','event',$var);
3648                                               
3649                                        }
3650        */
3651
3652                                        if($day_params['appts'])
3653                                        {
3654                                                $var = Array(
3655                                                        'week_day_font_size'    => '2',
3656                                                        'events'                => ''
3657                                                );
3658                                                $p->set_var($var);
3659                                                $events = $this->bo->cached_events[$date];
3660                                                //eventos
3661                                                //print_r($events);
3662                                                foreach($events as $event)
3663                                                {
3664                                                        if ($this->bo->rejected_no_show($event))
3665                                                        {
3666                                                                continue;       // user does not want to see rejected events
3667                                                        }
3668                                                        $p->set_var('day_events',$this->link_to_month_entry($event,$month,$day,$year));
3669                                                        $p->parse('events','event',True);
3670                                                        $p->set_var('day_events','');
3671                                                }
3672                                        }
3673                                        $p->parse('daily_events','day_event',True);
3674                                        $p->parse('column_data','month_daily',True);
3675                                        $p->set_var('daily_events','');
3676                                        $p->set_var('events','');
3677                                }
3678                                $p->parse('column_header','month_column',True);
3679                                $p->set_var('column_data','');
3680                        }
3681                        $this->bo->owner = $temp_owner;
3682                        return $p->fp('out','monthly_header');
3683
3684                }
3685
3686                function display_month_print($month,$year,$showyear,$owner=0)
3687                {
3688                        if($this->debug)
3689                        {
3690                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
3691                        }
3692
3693                        $this->bo->store_to_cache(
3694                                Array(
3695                                        'syear' => $year,
3696                                        'smonth'=> $month,
3697                                        'sday'  => 1
3698                                )
3699                        );
3700
3701                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
3702                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
3703
3704                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
3705
3706                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3707                        $p->set_unknowns('keep');
3708
3709                        $p->set_file(
3710                                Array(
3711                                        'week' => 'month_day_print.tpl'
3712                                )
3713                        );
3714                        $p->set_block('week','m_w_table','m_w_table');
3715                        $p->set_block('week','event','event');
3716
3717                        $var = Array(
3718                                'cols'      => 1,
3719                                'day_events'=> '' //$this->month_week_header($month,$year,False)
3720                        );
3721//                      $this->output_template_array($p,'row','event',$var);
3722
3723                        $cellcolor = $this->theme['row_on'];
3724
3725                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
3726                        {
3727                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
3728                                $var = Array(
3729                                        'day_events' => $this->month_display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
3730                                );
3731                                $this->output_template_array($p,'row','event',$var);
3732                        }
3733                        return $p->fp('out','m_w_table');
3734                }
3735
3736
3737/***************************************************************************************/
3738
3739                function display_month($month,$year,$showyear,$owner=0)
3740                {
3741                        if($this->debug)
3742                        {
3743                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
3744                        }
3745
3746                        $this->bo->store_to_cache(
3747                                Array(
3748                                        'syear' => $year,
3749                                        'smonth'=> $month,
3750                                        'sday'  => 1
3751                                )
3752                        );
3753
3754                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
3755                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
3756
3757                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
3758
3759                        if($this->debug)
3760                        {
3761                                echo '<!-- display_month:monthstart = '.$monthstart.' -->'."\n";
3762                                echo '<!-- display_month:start = '.date('Ymd H:i:s',$start).' -->'."\n";
3763                        }
3764
3765                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3766                        $p->set_unknowns('keep');
3767
3768                        $p->set_file(
3769                                Array(
3770                                        'week' => 'month_day.tpl'
3771                                )
3772                        );
3773                        $p->set_block('week','m_w_table','m_w_table');
3774                        $p->set_block('week','event','event');
3775
3776                        $var = Array(
3777                                'cols'      => 1,
3778                                'day_events'=> $this->week_header($month,$year,False)
3779                        );
3780                        $this->output_template_array($p,'row','event',$var);
3781
3782                        $cellcolor = $this->theme['row_on'];
3783
3784                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
3785                        {
3786                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
3787                                $var = Array(
3788                                        'day_events' => $this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
3789                                );
3790                                $this->output_template_array($p,'row','event',$var);
3791                        }
3792                        return $p->fp('out','m_w_table');
3793                }
3794
3795                function display_weekly($params)
3796                {
3797                        if(!is_array($params))
3798                        {
3799                                $this->index();
3800                        }
3801
3802                        $year = substr($params['date'],0,4);
3803                        $month = substr($params['date'],4,2);
3804                        $day = substr($params['date'],6,2);
3805                        $showyear = $params['showyear'];
3806                        $owners = $params['owners'];
3807
3808                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3809                        $p->set_unknowns('keep');
3810
3811                        $p->set_file(
3812                                Array(
3813                                        'week'  => 'month_day.tpl'
3814                                )
3815                        );
3816                        $p->set_block('week','m_w_table','m_w_table');
3817                        $p->set_block('week','event','event');
3818
3819                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
3820
3821                        $cellcolor = $this->theme['row_off'];
3822
3823                        $true_printer_friendly = $this->bo->printer_friendly;
3824
3825                        if(is_array($owners))
3826                        {
3827                                $display_name = True;
3828                                $counter = count($owners);
3829                                $owners_array = $owners;
3830                                $cols = 8;
3831                        }
3832                        else
3833                        {
3834                                $display_name = False;
3835                                $counter = 1;
3836                                $owners_array[0] = $owners;
3837                                $cols = 7;
3838                        }
3839                        $var = Array(
3840                                'cols'         => $cols,
3841                                'day_events'   => $this->week_header($month,$year,$display_name)
3842                        );
3843                        $this->output_template_array($p,'row','event',$var);
3844
3845                        $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
3846                        $tstop = $tstart + 604800;
3847                        $original_owner = $this->bo->so->owner;
3848                        for($i=0;$i<$counter;$i++)
3849                        {
3850                                $this->bo->so->owner = $owners_array[$i];
3851                                $this->bo->so->open_box($owners_array[$i]);
3852                                $this->bo->store_to_cache(
3853                                        Array(
3854                                                'syear'  => date('Y',$tstart),
3855                                                'smonth' => date('m',$tstart),
3856                                                'sday'   => date('d',$tstart),
3857                                                'eyear'  => date('Y',$tstop),
3858                                                'emonth' => date('m',$tstop),
3859                                                'eday'   => date('d',$tstop)
3860                                        )
3861                                );
3862                                $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$owners_array[$i]));
3863                                $p->parse('row','event',True);
3864                        }
3865                        $this->bo->so->owner = $original_owner;
3866                        $this->bo->printer_friendly = $true_printer_friendly;
3867                        return $p->fp('out','m_w_table');
3868                }
3869
3870                function view_event($event,$alarms=False)
3871                {
3872                        if((!$event['participants'][$this->bo->owner] && !$this->bo->check_perms(PHPGW_ACL_READ,$event)))
3873                        {
3874                                return False;
3875                        }
3876
3877                        $p = &$GLOBALS['phpgw']->template;
3878
3879                        $p->set_file(
3880                                Array(
3881                                        'view'  => 'view.tpl'
3882                                )
3883                        );
3884                        $p->set_block('view','view_event','view_event');
3885                        $p->set_block('view','list','list');
3886                        $p->set_block('view','hr','hr');
3887
3888                        $vars = $this->bo->event2array($event);
3889
3890                        $vars['title']['tr_color'] = $this->theme['th_bg'];
3891
3892                        foreach($vars['participants']['data'] as $user => $str)
3893                        {
3894                        if ($this->bo->check_perms(PHPGW_ACL_EDIT,0,$user) && ereg('^(.*) \((.*)\)$',$str,$parts))
3895                                {
3896                                        $vars['participants']['data'][$user] = $parts[1].' (<a href="'.$this->page('edit_status','&cal_id='.$event['id'].'&owner='.$user).'">'.$parts[2].'</a>)';
3897                                }
3898                        }
3899                        $vars['participants']['data'] = implode("<br>\n",$vars['participants']['data']);
3900                        foreach($vars as $var)
3901                        {
3902                                if (strlen($var['data']))
3903                                {
3904                                        $this->output_template_array($p,'row','list',$var);
3905                                }
3906                        }
3907
3908                        if($alarms && count($event['alarm']))
3909                        {
3910                                $p->set_var('th_bg',$this->theme['th_bg']);
3911                                $p->set_var('hr_text',lang('Alarms'));
3912                                $p->parse('row','hr',True);
3913                                foreach($event['alarm'] as $key => $alarm)
3914                                {
3915                                        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
3916                                        {       
3917                                                $icon = '<img src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled':'disabled')).'" width="13" height="13">';
3918                                                $var = Array(
3919                                                        'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']),
3920                                                        'data'  => lang('Email Notification for %1',$GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']))
3921                                                );
3922                                                $this->output_template_array($p,'row','list',$var);
3923                                        }
3924                                }
3925                        }
3926                        return True;
3927                }
3928
3929                function nm_on_off()
3930                {
3931                        if($GLOBALS['phpgw']->nextmatchs->alternate_row_color() == $this->theme['row_on'])
3932                        {
3933                                return '_on';
3934                        }
3935                        return '_off';
3936                }
3937
3938                function slot_num($time,$set_day_start=0,$set_day_end=0)
3939                {
3940                        static $day_start, $day_end, $interval=0;
3941
3942                        if ($set_day_start) $day_start = $set_day_start;
3943                        if ($set_day_end)   $day_end   = $set_day_end;
3944                        if (!$interval)     $interval  = 60*$this->bo->prefs['calendar']['interval'];
3945
3946                        if ($time > $day_end)
3947                        {
3948                                $time = $day_end;
3949                        }
3950                        $slot = (int)(($time - $day_start) / $interval);
3951
3952                        return $slot < 0 ? 0 : 1+$slot;
3953                }
3954
3955                function print_day($params)
3956                {
3957                        if(!is_array($params))
3958                        {
3959                                $this->index();
3960                        }
3961
3962                        print_debug('in print_day()');
3963
3964                        $this->bo->store_to_cache(
3965                                Array(
3966                                        'syear'  => $params['year'],
3967                                        'smonth' => $params['month'],
3968                                        'sday'   => $params['day'],
3969                                        'eyear'  => $params['year'],
3970                                        'emonth' => $params['month'],
3971                                        'eday'   => $params['day']
3972                                )
3973                        );
3974
3975                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3976                        $p->set_unknowns('keep');
3977
3978                        $tpl = 'day_cal.tpl';
3979                        if((int)($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents'])==2 &&
3980                                $GLOBALS['phpgw_info']['flags']['currentapp'] == 'home')
3981                        {
3982                                $tpl = 'day_list.tpl';
3983                        }
3984                        $templates = Array(
3985                                'day_cal'   => $tpl
3986                        );
3987
3988                        $p->set_file($templates);
3989                        $p->set_block('day_cal','day','day');
3990                        $p->set_block('day_cal','day_row','day_row');
3991                        $p->set_block('day_cal','day_event_on','day_event_on');
3992                        $p->set_block('day_cal','day_event_off','day_event_off');
3993                        $p->set_block('day_cal','day_event_holiday','day_event_holiday');
3994                        $p->set_block('day_cal','day_time','day_time');
3995
3996                        $date_to_eval = sprintf("%04d%02d%02d",$params['year'],$params['month'],$params['day']);
3997
3998                        $day_start = mktime((int)($this->bo->prefs['calendar']['workdaystarts']),0,0,$params['month'],$params['day'],$params['year']);
3999                        $day_end = mktime((int)($this->bo->prefs['calendar']['workdayends']),0,1,$params['month'],$params['day'],$params['year']);
4000                        $daily = $this->set_week_array($GLOBALS['phpgw']->datetime->get_weekday_start($params['year'],$params['month'],$params['day']),$this->theme['row_on'],True);
4001                        print_debug('Date to Eval',$date_to_eval);
4002                        $events_to_show = array();
4003                        if($daily[$date_to_eval]['appts'])
4004                        {
4005                                $events = $this->bo->cached_events[$date_to_eval];
4006                                print_debug('Date',$date_to_eval);
4007                                print_debug('Count',count($events));
4008                                foreach($events as $event)
4009                                {
4010                                        if ($this->bo->rejected_no_show($event))
4011                                        {
4012                                                continue;       // user does not want to see rejected events
4013                                        }
4014                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
4015                                        {
4016                                                $this->bo->set_recur_date($event,$date_to_eval);
4017                                        }
4018                                        $events_to_show[] = array(
4019                                                'starttime' => $this->bo->maketime($event['start']),
4020                                                'endtime'   => $this->bo->maketime($event['end']),
4021                                                'content'   => $this->link_to_entry($event,$params['month'],$params['day'],$params['year'])
4022                                        );
4023                                }
4024                        }
4025                        //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4026                        $other = $GLOBALS['phpgw']->hooks->process(array(
4027                                'location'  => 'calendar_include_events',
4028                                'year'      => $params['year'],
4029                                'month'     => $params['month'],
4030                                'day'       => $params['day'],
4031                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
4032                        ));
4033
4034                        if (is_array($other))
4035                        {
4036                                foreach($other as $evts)
4037                                {
4038                                        if (is_array($evts))
4039                                        {
4040                                                $events_to_show = array_merge($events_to_show,$evts);
4041                                        }
4042                                }
4043                                usort($events_to_show,create_function('$a,$b','return $a[\'starttime\']-$b[\'starttime\'];'));
4044                                //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4045                        }
4046
4047                        if (count($events_to_show))
4048                        {
4049                                $last_slot_end = -1;
4050                                foreach($events_to_show as $event)
4051                                {
4052                                        $slot = $this->slot_num($event['starttime'],$day_start,$day_end);
4053                                        $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
4054
4055                                        if ($slot <= $last_slot_end)
4056                                        {
4057                                                $slot = $last_slot;
4058                                                $slot_end = max($last_slot_end,$slot_end);
4059                                        }
4060                                        $rows[$slot] .= $event['content'];
4061
4062                                        print_debug('slot',$slot);
4063                                        print_debug('row',$rows[$slot]);
4064
4065                                        $row_span[$slot] = 1 + $slot_end - $slot;
4066
4067                                        $last_slot = $slot;
4068                                        $last_slot_end = $slot_end;
4069                                        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));
4070                                        print_debug('Slot',$slot);
4071                                }
4072                                //echo "rows=<pre>"; print_r($rows); echo "<br>row_span="; print_r($row_span); echo "</pre>\n";
4073                        }
4074                        $holiday_names = $daily[$date_to_eval]['holidays'];
4075                        if(!$holiday_names)
4076                        {
4077                                $row_to_print = $this->nm_on_off();
4078                        }
4079                        else
4080                        {
4081                                $row_to_print = '_holiday';
4082                                foreach($holiday_names as $name)
4083                                {
4084                                        $rows[0] = '<center>'.$name.'</center>' . $rows[0];
4085                                }
4086                        }
4087                        $last_slot = $this->slot_num($day_end,$day_start,$day_end);
4088                        $rowspan = 0;
4089                        for ($slot = 0; $slot <= $last_slot; ++$slot)
4090                        {
4091                                $p->set_var('extras','');
4092                                if ($rowspan > 1)
4093                                {
4094                                        $p->set_var('event','');
4095                                        $rowspan--;
4096                                }
4097                                elseif (!isset($rows[$slot]))
4098                                {
4099                                        $p->set_var('event','&nbsp;');
4100                                        $row_to_print = $this->nm_on_off();
4101                                        $p->parse('event','day_event'.$row_to_print);
4102                                }
4103                                else
4104                                {
4105                                        $rowspan = (int)$row_span[$slot];
4106                                        if ($rowspan > 1)
4107                                        {
4108                                                $p->set_var('extras',' rowspan="'.$rowspan.'"');
4109                                        }
4110                                        $p->set_var('event',$rows[$slot]);
4111                                        $row_to_print = $this->nm_on_off();
4112                                        $p->parse('event','day_event'.$row_to_print);
4113                                }
4114                                $open_link = $close_link = '';
4115                                $time = '&nbsp;';
4116
4117                                if (0 < $slot && $slot < $last_slot)    // normal time-slot not before or after day_start/end
4118                                {
4119                                        $time = $day_start + ($slot-1) * 60 * $this->bo->prefs['calendar']['interval'];
4120                                        $hour = date('H',$time);
4121                                        $min  = date('i',$time);
4122                                        $time = $GLOBALS['phpgw']->common->formattime($hour,$min);
4123
4124                                        if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
4125                                        {
4126                                                $open_link = ' <a href="'.$this->page('add',"&date=$date_to_eval&hour=$hour&minute=$min").'">';
4127                                                $close_link = '</a> ';
4128                                        }
4129                                }
4130                                $p->set_var(Array(
4131                                        'open_link'  => $open_link,
4132                                        'time'       => $time,
4133                                        'close_link' => $close_link,
4134                                        'tr_color'   => ''      // dummy to stop output_template_array to set it
4135                                ));
4136                                $p->parse('time','day_time');
4137
4138                                $p->parse('row','day_row',True);
4139                        }
4140                        return $p->fp('out','day');
4141                }       // end function
4142
4143                function timematrix($param)
4144                {
4145                        if(!is_array($param))
4146                        {
4147                                $this->index();
4148                        }
4149
4150                        $date = $param['date'];
4151                        $starttime = $param['starttime'];
4152                        $endtime = $param['endtime'];
4153                        $participants = $param['participants'];
4154                        foreach($participants as $part => $nul)
4155                        {
4156                                $participants[$part] = $GLOBALS['phpgw']->common->grab_owner_name($part);
4157                                // Much better for processor  :)
4158                                $participants_id[]  .= $part;
4159                        }
4160                        uasort($participants,'strnatcasecmp');  // sort them after their fullname
4161
4162                        if(!isset($this->bo->prefs['calendar']['interval']))
4163                        {
4164                                $this->bo->prefs['calendar']['interval'] = 15;
4165                                $GLOBALS['phpgw']->preferences->add('calendar','interval',15);
4166                                $GLOBALS['phpgw']->preferences->save_repository();
4167                        }
4168                        $increment = $this->bo->prefs['calendar']['interval'];
4169                        $interval = (int)(60 / $increment);
4170
4171                        $pix = $GLOBALS['phpgw']->common->image('calendar','pix');
4172
4173                        $str = '<center>'.lang($GLOBALS['phpgw']->common->show_date($date['raw'],'l'))
4174                                . ', '.$this->bo->long_date($date).'<br>'
4175                                . '<table width="85%" border="0" cellspacing="0" cellpadding="0" cols="'.((24 * $interval) + 1).'">'
4176                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>'
4177                                . '<tr><td width="15%"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.lang('Participant').'</font></td>';
4178                        for($i=0;$i<24;$i++)
4179                        {
4180                                for($j=0;$j<$interval;$j++)
4181                                {
4182                                        $k = ($j == 0 ? sprintf('%02d',$i).'<br>':'').sprintf('%02d',$j*$increment);
4183
4184                                        $str .= '<td align="left" bgcolor="'.$this->theme['bg_color'].'"><font color="'.$phpgw_info['theme']['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'
4185                                                . '<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;\">"
4186                                                . $k."</a>&nbsp;</font></td>\n";
4187                                }
4188                        }
4189                        $str .= '</tr>'
4190                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>';
4191                        if(!$endtime)
4192                        {
4193                                $endtime = $starttime;
4194                        }
4195                        $owner = $this->bo->owner;
4196                        foreach($participants as $part => $fullname)
4197                        {
4198                                $str .= '<tr align="center">'
4199                                        . '<td width="15%" align="left"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$fullname.'</font></td>';
4200
4201                                $this->bo->cached_events = Array();
4202                                $this->bo->so->owner = $part;
4203                                $this->bo->so->open_box($part);
4204                                $this->bo->store_to_cache(
4205                                        Array(
4206                                                'syear' => $date['year'],
4207                                                'smonth'=> $date['month'],
4208                                                'sday'  => $date['day'],
4209                                                'eyear' => 0,
4210                                                'emonth'=> 0,
4211                                                'eday'  => $date['day'] + 1
4212                                        )
4213                                );
4214
4215                                if(!$this->bo->cached_events[$date['full']])
4216                                {
4217                                        for($j=0;$j<24;$j++)
4218                                        {
4219                                                for($k=0;$k<$interval;$k++)
4220                                                {
4221                                                        $str .= '<td height="1" align="left" bgcolor="'.$this->theme['bg_color'].'" color="#999999">&nbsp;</td>';
4222                                                }
4223                                                $str .= "\n";
4224                                        }
4225                                }
4226                                else
4227                                {
4228                                        $time_slice = $this->bo->prepare_matrix($interval,$increment,$part,$date['full']);
4229                                        for($h=0;$h<24;$h++)
4230                                        {
4231                                                $hour = $h * 10000;
4232                                                for($m=0;$m<$interval;$m++)
4233                                                {
4234                                                        $index = ($hour + (($m * $increment) * 100));
4235                                                        switch($time_slice[$index]['marker'])
4236                                                        {
4237                                                                case '&nbsp':
4238                                                                        $time_slice[$index]['color'] = $this->theme['bg_color'];
4239                                                                        $extra = '';
4240                                                                        break;
4241                                                                case '-':
4242                                                                        $time_slice[$index]['color'] = $this->theme['bg01'];
4243                                                                        $link = $this->page('view','&cal_id='.$time_slice[$index]['id'].'&date='.$date['full']);
4244                                                                        $extra =' title="'.$time_slice[$index]['description'].'" onClick="location.href=\''.$link.'\';" style="cursor:pointer; cursor:hand;"';
4245                                                                        break;
4246                                                        }
4247                                                        $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>';
4248                                                }
4249                                                $str .= "\n";
4250                                        }
4251                                }
4252                                $str .= '</tr>'
4253                                        . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="#999999"><img src="'.$pix.'"></td></tr>';
4254                        }
4255                        $this->bo->owner = $owner;
4256                        $this->bo->so->owner = $owner;
4257                        $this->bo->so->open_box($owner);
4258                        return $str.'</table></center>'."\n";
4259                }
4260
4261                function get_response($cal_id)
4262                {
4263                        $p = &$GLOBALS['phpgw']->template;
4264                        $p->set_file(
4265                                Array(
4266                                        'form_button'   => 'form_button_script.tpl'
4267                                )
4268                        );
4269
4270                        $ev = $this->bo->get_cached_event();
4271                        $response_choices = Array(
4272                                ACCEPTED        => lang('Accept'),
4273                                REJECTED        => lang('Reject'),
4274                                TENTATIVE       => lang('Tentative')                           
4275                        );
4276                        $str = '';
4277                        while(list($param,$text) = each($response_choices))
4278                        {
4279                                $var = Array(
4280                                        'action_url_button'     => $this->page('set_action','&cal_id='.$cal_id.'&action='.$param),
4281                                        'action_text_button'    => '  '.$text.'  ',
4282                                        'action_confirm_button' => '',
4283                                        'action_extra_field'    => ''
4284                                );
4285                                $p->set_var($var);
4286                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4287                        }
4288                        if ($this->bo->return_to)
4289                        {
4290                                $var = Array(
4291                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
4292                                        'action_text_button'    => lang('cancel'),
4293                                        'action_confirm_button' => '',
4294                                        'action_extra_field'    => ''
4295                                );
4296                                $p->set_var($var);
4297                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4298                        }
4299                        $str = '<td><b>'.$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner).":</b></td>\n".$str;
4300
4301                        return '<table width="100%"><tr align="center">'."\n".$str.'</tr></table>'."\n";
4302                }
4303
4304                function accounts_popup()
4305                {
4306                        $GLOBALS['phpgw']->accounts->accounts_popup('calendar');
4307                       
4308                }
4309
4310                function edit_form($param)
4311                {
4312                        if(!is_array($param))
4313                        {
4314                                $this->index();
4315                        }
4316                       
4317                        if(isset($param['event']))
4318                        {
4319                                $event = $param['event'];
4320                        }
4321                       
4322                        $hourformat = substr($this->bo->users_timeformat,0,1);
4323                       
4324                        // $sb = CreateObject('phpgwapi.sbox');
4325                        $sb = CreateObject('phpgwapi.sbox2');
4326                        $jscal = CreateObject('phpgwapi.jscalendar');   // before phpgw_header() !!!
4327                       
4328                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
4329                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
4330                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
4331                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
4332                        $GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Editing event') : lang('Adding event');
4333                        $GLOBALS['phpgw']->common->phpgw_header();
4334
4335                        $p = &$GLOBALS['phpgw']->template;
4336                        $p->set_file(
4337                                Array(
4338                                        'edit'          => 'edit.tpl',
4339                                        'form_button'   => 'form_button_script.tpl'
4340                                )
4341                        );
4342                        $p->set_block('edit','edit_entry','edit_entry');
4343                        $p->set_block('edit','list','list');
4344                        $p->set_block('edit','hr','hr');
4345                       
4346                        $vars = Array(
4347                                'font'                  => $this->theme['font'],
4348                                'bg_color'              => $this->theme['bg_text'],
4349                                'action_url'            => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update')),
4350                                'accounts_link'         => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.accounts_popup'),
4351                                'common_hidden' => '<input type="hidden" name="cal[id]" value="'.$event['id'].'">'."\n"
4352                                        . '<input type="hidden" name="cal[owner]" value="'.$event['owner'].'">'."\n"
4353                                        . '<input type="hidden" name="cal[uid]" value="'.$event['uid'].'">'."\n"
4354                                        . ($_GET['cal_id'] && $event['id'] == 0?'<input type="hidden" name="cal[reference]" value="'.$_GET['cal_id'].'">'."\n":
4355                                        (@isset($event['reference'])?'<input type="hidden" name="cal[reference]" value="'.$event['reference'].'">'."\n":''))
4356                                        . (@isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && $GLOBALS['phpgw_info']['server']['deny_user_grants_access']?
4357                                        '<input type="hidden" name="participants[]" value="'.$this->bo->owner.'">'."\n":''),
4358                                'errormsg'              => ($param['cd']?$GLOBALS['phpgw']->common->check_code($param['cd']):'')
4359                        );
4360                       
4361                        $p->set_var($vars);
4362
4363// Brief Description
4364                        $var['title'] = Array(
4365                                'tr_color' => $this->theme['th_bg'],
4366                                'field' => lang('Title'),
4367                                'data'  => '<input name="cal[title]" size="45" maxlength="80" value="'.$event['title'].'">'
4368                        );
4369
4370// Full Description
4371                        $var['description'] = Array(
4372                                'field' => lang('Full Description'),
4373                                'data'  => '<textarea name="cal[description]" rows="5" cols="40" wrap="virtual" maxlength="2048">'.$event['description'].'</textarea>'
4374                        );
4375
4376// Display Categories
4377                        if(strpos($event['category'],','))
4378                        {
4379                                $temp_cats = explode(',',$event['category']);
4380                                @reset($temp_cats);
4381                                while(list($key,$value) = each($temp_cats))
4382                                {
4383                                        $check_cats[] = (int)$value;
4384                                }
4385                        }
4386                        elseif($event['category'])
4387                        {
4388                                $check_cats[] = (int)$event['category'];
4389                        }
4390                        else
4391                        {
4392                                $check_cats[] = 0;
4393                        }
4394                        $var['category'] = Array(
4395                                'field' => lang('Category'),
4396                                'data'  => '<select name="categories[]" multiple size="5">'.$this->cat->formated_list('select','all',$check_cats,True).'</select>'
4397                        );
4398
4399// Location
4400                        $var['location'] = Array(
4401                                'field' => lang('Location'),
4402                                'data'  => '<input name="cal[location]" size="45" maxlength="255" value="'.$event['location'].'">'
4403                        );
4404
4405// Date
4406
4407                        $start = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
4408                        $var['startdate'] = Array(
4409                                'field' => lang('Start Date'),
4410/*
4411                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
4412                                   $sb->getYears('start[year]',(int)$GLOBALS['phpgw']->common->show_date($start,'Y')),
4413                                   $sb->getMonthText('start[month]',(int)$GLOBALS['phpgw']->common->show_date($start,'n')),
4414                                   $sb->getDays('start[mday]',(int)$GLOBALS['phpgw']->common->show_date($start,'d'))
4415                                )
4416*/
4417                                'data' => $jscal->input('start[str]',$start)
4418                        );
4419
4420// Time
4421                        if ($this->bo->prefs['common']['timeformat'] == '12')
4422                        {
4423                                $str .= '<input type="radio" name="start[ampm]" value="am"'.($event['start']['hour'] >= 12?'':' checked').'>am'."\n"
4424                                        . '<input type="radio" name="start[ampm]" value="pm"'.($event['start']['hour'] >= 12?' checked':'').'>pm'."\n";
4425                        }
4426                        $var['starttime'] = Array(
4427                                'field' => lang('Start Time'),
4428                                '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
4429                        );
4430
4431// End Date
4432                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
4433                        $var['enddate'] = Array(
4434                                'field' => lang('End Date'),
4435/*
4436                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
4437                                   $sb->getYears('end[year]',(int)$GLOBALS['phpgw']->common->show_date($end,'Y')),
4438                                   $sb->getMonthText('end[month]',(int)$GLOBALS['phpgw']->common->show_date($end,'n')),
4439                                   $sb->getDays('end[mday]',(int)$GLOBALS['phpgw']->common->show_date($end,'d'))
4440                                )
4441*/
4442                                'data' => $jscal->input('end[str]',$end)
4443                        );
4444
4445// End Time
4446                        if ($this->bo->prefs['common']['timeformat'] == '12')
4447                        {
4448                                $str = '<input type="radio" name="end[ampm]" value="am"'.($event['end']['hour'] >= 12?'':' checked').'>am'."\n"
4449                                        . '<input type="radio" name="end[ampm]" value="pm"'.($event['end']['hour'] >= 12?' checked':'').'>pm'."\n";
4450                        }
4451                        $var['endtime'] = Array(
4452                                'field' => lang('End Time'),
4453                                '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
4454                        );
4455
4456// Priority
4457                        $var['priority'] = Array(
4458                                'field' => lang('Priority'),
4459                                'data'  => $sb->getPriority('cal[priority]',$event['priority'])
4460                        );
4461
4462// Access
4463                        $var['access'] = Array(
4464                                'field' => lang('Private'),
4465                                'data'  => '<input type="checkbox" name="cal[private]" value="private"'.(!$event['public']?' checked':'').'>'
4466                        );
4467
4468// Participants
4469                        if(!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access'])
4470                        {
4471                                switch($GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection'])
4472                                {
4473                                        case 'popup':
4474                                                while (is_array($event['participants']) && list($id) = each($event['participants']))
4475                                                {
4476                                                        if($id != (int)$event['owner'])
4477                                                        {
4478                                                                $str .= '<option value="' . $id.$event['participants'][$id] . '"'.($event['participants'][$id]?' selected':'').'>('.$GLOBALS['phpgw']->accounts->get_type($id)
4479                                                                                .') ' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '</option>' . "\n";
4480                                                        }
4481                                                }
4482                                                $var['participants'] = array
4483                                                (
4484                                                        'field' => '<input type="button" value="' . lang('Participants') . '" onClick="accounts_popup();">' . "\n"
4485                                                                        . '<input type="hidden" name="accountid" value="' . $accountid . '">',
4486                                                        'data'  => "\n".'   <select name="participants[]" multiple size="7">' . "\n" . $str . '</select>'
4487                                                );
4488                                                break;
4489                                        default:
4490                                                foreach($event['participants'] as $id => $participant)
4491                                                {
4492                                                        if (($id != $event['owner']) && ($id != ""))
4493                                                        {
4494                                                                $GLOBALS['phpgw']->accounts->get_account_name($id, $lid, $fname, $lname);
4495                                                                $cn = $fname.' '.$lname;                                                       
4496                                                                $option = '    <option  value="' . $id.$participant . '">'.$cn.'</option>'."\n";
4497                                                                $str .= $option;
4498                                                        }                                                               
4499                                                }
4500                                                $str = utf8_decode($str);
4501                                                $footer_ext_participantes =     '<br>&nbsp;&nbsp;'.lang("The email addresses must be separated by ','");                                               
4502                                               
4503                                                $var['participants'] = array
4504                                                (
4505                                                        'field' => lang('Participants'),                                                       
4506                                                        'data'  => "
4507                                                                        <table width='100%' border='0'>
4508                                                                                <tr>
4509                                                                                        <td width='30%'>                                                                               
4510                                                                                                <center>Participantes</center>                                                                                         
4511                                                                                        </td>
4512                                                                                        <td width='8%' >&nbsp;</td>
4513                                                                                        <td width='40%'>&nbsp;</td>
4514                                                                                </tr>                                                                                                                                           
4515                                                                                <tr>           
4516                                                                                        <td width='30%'>                                                                                       
4517                                                                                                <center><select id='user_list' name='participants[]' style='width: 220px' multiple size='7'>".$str."</select></center>                                                                         
4518                                                                                        </td>                           
4519                                                                                        <td width='8%'>
4520                                                                                        <center>
4521                                                                                                <table width='100%' border='0'>                                                                 
4522                                                                                                        <tr height='5'><td>&nbsp;</td></tr>                                                                     
4523                                                                                                        <tr><td align='center'>                                                                 
4524                                                                                                                <button type='button' onClick='javascript:openListUsers(340,533, "
4525                                                                                                                .$event['owner'].
4526                                                                                                                ")'><img src='calendar/templates/celepar/images/add.png' style='vertical-align: middle;' >&nbsp;Adicionar</button>
4527                                                                                                                </td>
4528                                                                                                        </tr>                                                   
4529                                                                                                        <tr height='5'><td>&nbsp;</td></tr>
4530                                                                                                        <tr><td  align='center'>
4531                                                                                                                        <button type='button' onClick='javascript:rem()'><img src='calendar/templates/celepar/images/rem.png' style='vertical-align: middle;' >&nbsp;Remover</button>
4532                                                                                                                </td>
4533                                                                                                        </tr>
4534                                                                                                </table>
4535                                                                                        </center>
4536                                                                                        </td>
4537                                                                                        <td width='40%'>&nbsp;</td>
4538                                                                                </tr>
4539                                                                                </table>
4540                                                                        <script src='calendar/templates/celepar/js/edit.js' type='text/javascript'></script>
4541                                                                        "
4542                                                );
4543                                                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
4544                                                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {                                                     
4545                                                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
4546
4547                                                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
4548                                                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
4549                                                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
4550                                                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $event['owner'];
4551                                                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
4552                                                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
4553                                                                $context = $GLOBALS['phpgw_info']['server']['ldap_context'];
4554                                                                $user_context = array();
4555                                                                foreach(explode(",",$GLOBALS['phpgw_info']['user']['account_dn']) as $i => $dn_part){
4556                                                                        if($i)
4557                                                                                $user_context[] = $dn_part;
4558                                                                }
4559                                                                // Prepara o contexto do usuario com sua OU raiz, pois ele pode pertencer a uma OU de nivel N.
4560                                                                $user_ou = explode(",",str_replace($context,"",implode(",",$user_context)));                                                           
4561                                                                $user_context = trim(strtolower($user_ou[count($user_ou) - 2].",".$context));
4562                                                                // Fim         
4563                                                                // Verifica o tipo da visualização da árvore LDAP, configurado no admin da Agenda
4564                                                                $recursive = $GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '1' ? true : false;
4565                                                                $combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
4566                                                                $footer_ext_participantes = lang("Tip: To search in the <b>Global Catalog</b>, type the <b>F9</b> key, like the ExpressoMail.");
4567                                                               
4568                                                                $var['participants'] = array
4569                                                                (
4570                                                                        'field' => lang('Participants'),                                                       
4571                                                                        'data'  => '<input type="hidden" id="txt_loading" value="'.lang("Loading").'">' .
4572                                                                                        '<input type="hidden" id="txt_searching" value="'.lang("Searching").'">' .
4573                                                                                        '<input type="hidden" id="txt_users" value="'.lang("Users").'">' .                                                     
4574                                                                                        '<input type="hidden" id="txt_groups" value="'.lang("Groups").'">' .
4575                                                                                        '<table width="100%" border="0">'.
4576                                                                                        '<tr>'.
4577                                                                                        '<td width="25%"><br>'.
4578                                                                                        '<button type="button" onClick="javascript:add_user();"><img src="calendar/templates/celepar/images/add.png" style="vertical-align: middle;" >&nbsp;'.lang("Add").'</button>'.
4579                                                                                        '&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>'.
4580                                                                                        '<br><br>&nbsp;&nbsp;<b>'.lang("Event's participants").'</b><br>'.
4581                                                                                        '       <select id="user_list" name="participants[]" style="width: 300px" multiple size="13">'.$str.'</select>'.
4582                                                                                        '</td>'.
4583                                                                                        '<td width="30px" valign="middle" align="center">&nbsp;'.
4584                                                                                        '</td>'.
4585                                                                                        '<td valign="bottom">'.
4586                                                                                        '       '.lang("Organization").': '.
4587                                                                                        '       <select name="org_context" id="combo_org" onchange="javascript:get_available_users(\''.$module_name.'\',this.value,\''.($recursive ? "" : "search").'\');">'.$combo_org.'</select>'.
4588                                                                                        '       <br>'.
4589                                                                                        '       <font color="red"><span id="cal_span_searching">&nbsp;</span></font>'.                                                                 
4590                                                                                        '       <br>'.lang("Search for").':'.
4591                                                                                        '       <input value="" id="cal_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this)"><br>'.
4592                                                                                        '       <b>'.lang("Available users and groups").'</b>'.
4593                                                                                        '       <select id="user_list_in" style="width: 300px" multiple size="13"></select>'.
4594                                                                                        '</td>'.
4595                                                                                        '</tr>'.
4596                                                                                        '</table>'.
4597                                                                                        '<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>'.
4598                                                                                        '<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>'.         
4599                                                                                        "<script src='calendar/templates/celepar/js/edit_exmail.js' type='text/javascript'></script>" .
4600                                                                                        "<script src='".$module_name."/inc/load_lang.php' type='text/javascript'></script>".
4601                                                                                        "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
4602                                                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
4603                                                                                        "<script type='text/javascript'>" .
4604                                                                                        "setTimeout('get_available_users(\"".$module_name."\",\'".$user_context."\',\'".($recursive ? "" : "search")."\')',1000);".
4605                                                                                        "</script> "
4606                                                                                               
4607                                                                );
4608                                                        }                                               
4609                                                }                                               
4610                                               
4611                                                $var['participants']['data'] .= '<a id="a_ext_participants" title="'.lang("It types below the email addresses, if you want to invite other people out" .
4612                                                        " 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" ' .
4613                                                        'src="calendar/templates/celepar/images/sent.gif"></a><table id="tbl_ext_participants" width="100%" border="0" style="display:none">'.
4614                                                        '<tr>'.
4615                                                        '<td>'.
4616                                                        '&nbsp;&nbsp;<b>'.lang("external participants").'</b>&nbsp;<img align="top" src="calendar/templates/celepar/images/sent.gif">' .
4617                                                        '&nbsp;&nbsp;<a title="'.lang("Close").'" name="b_ext_participants" onClick="javascript:hideExParticipants(this,\''.$module_name.'\')" href="#a_ext_participants">['.lang("Close").']</a>&nbsp;'.                                                                                                               
4618                                                        '</td>'.
4619                                                        '</tr>'.
4620                                                        '<tr>'.
4621                                                        '<td>'.
4622                                                        '&nbsp;&nbsp;>> '.lang("It types below the email addresses, if you want to invite other people out of this system").':'.
4623                                                        '&nbsp;&nbsp;<br><textarea name="ex_participants" id="ex_participants" cols="70" rows="2">'.$event['ex_participants'].'</textarea><br>&nbsp;&nbsp;'.
4624                                                        $footer_ext_participantes.
4625                                                        '</tr>'.                                                       
4626                                                        '</table>';
4627                                                break;
4628                                               
4629                                }
4630                                if((($event['id'] > 0) && isset($event['participants'][$event['owner']])) || !$event['id'])
4631                                {
4632                                        $checked = ' checked';
4633                                }
4634                                else
4635                                {
4636                                        $checked = '';
4637                                }
4638                                $var['owner'] = Array(
4639                                        'field' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']).' '.lang('Participates'),
4640                                        'data'  => '<input type="checkbox" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'"'.$checked.'>'
4641                                );
4642                        }
4643
4644// Reminder
4645                        // The user must use "Alarm Management" to change/modify an alarm
4646                        // so only display the email reminder fields if this is a new event
4647                        // i.e. not editing an existing event
4648
4649                        if ($event['id'] == 0) {
4650                                // get defaults
4651                                $days = $this->bo->prefs['calendar']['default_email_days'];
4652                                $hours = $this->bo->prefs['calendar']['default_email_hours'];
4653                                $min = $this->bo->prefs['calendar']['default_email_min'];
4654                                if (count($event['alarm']) > 1)
4655                                {
4656                                        // this should not happen because when creating a new event
4657                                        // only 1 alarm is displayed on the screen
4658                                        // if the user wants more than 1 alarm they should
4659                                        // use "Alarm Management"
4660                                        echo '<!-- how did this happen, too many alarms -->'."\n";
4661                                }
4662                                // if there was an error pick up what the user entered
4663                                if (@isset($event['alarm']))
4664                                {
4665                                        @reset($event['alarm']);
4666                                        // just get the first one see above!!!
4667                                        list($key,$alarm) = @each($event['alarm']);
4668                                        $diff  = $start - $alarm['time'];
4669                                        $days  = (int)($diff / (24*3600));
4670                                        $hours = (int)(($diff - ($days * 24 * 3600))/3600);
4671                                        $min   = (int)(($diff - ($days * 24 * 3600) - ($hours * 3600))/60);
4672                                }
4673
4674                                // days
4675                                $dout = '<select name="cal[alarmdays]">'."\n";
4676                                for($i=0;$i<32;$i++)
4677                                {
4678                                        $dout .= '<option value="'.$i.'"'.($i==$days?' selected':'').'>'.$i.'</option>'."\n";
4679                                }
4680                                $dout .= '</select>'."\n".' '.lang('days').' ';
4681                                // hours
4682                                $hout = '<select name="cal[alarmhours]">'."\n";
4683                                for($i=0;$i<25;$i++)
4684                                {
4685                                        $hout .= '<option value="'.$i.'"'.($i==$hours?' selected':'').'>'.$i.'</option>'."\n";
4686                                }
4687                                $hout .= '</select>'."\n".' '.lang('hours').' ';
4688                                // minutes
4689                                $mout = '<select name="cal[alarmminutes]">'."\n";
4690                                for($i=0;$i<61;$i++)
4691                                {
4692                                        $mout .= '<option value="'.$i.'"'.($i==$min?' selected':'').'>'.$i.'</option>'."\n";
4693                                }
4694                                $mout .= '</select>'."\n".' '.lang('minutes').' ';
4695
4696                                $var['alarm'] = Array(
4697                                        'field' => lang('Alarm'),
4698                                        'data'  => $dout.$hout.$mout.lang('before the event')
4699                                );
4700
4701                        }
4702
4703// Repeat Type
4704                        $str = '';
4705                        foreach($this->bo->rpt_type as $type => $label)
4706                        {
4707                                $str .= '<option value="'.$type.'"'.($event['recur_type']==$type?' selected':'').'>'.lang($label).'</option>';
4708                        }
4709                        $var['recure_type'] = Array(
4710                                'field' => lang('Repeat Type'),
4711                                'data'  => '<select name="cal[recur_type]">'."\n".$str.'</select>'."\n"
4712                        );
4713
4714                        if($event['recur_enddate']['year'] != 0 && $event['recur_enddate']['month'] != 0 && $event['recur_enddate']['mday'] != 0)
4715                        {
4716                                $checked = ' checked';
4717                                $recur_end = $this->bo->maketime($event['recur_enddate']) - $GLOBALS['phpgw']->datetime->tz_offset;
4718                        }
4719                        else
4720                        {
4721                                $checked = '';
4722                                $recur_end = $this->bo->maketime($event['start']) + 86400 - $GLOBALS['phpgw']->datetime->tz_offset;
4723                        }
4724
4725                        $var['recure_enddate'] = Array(
4726                                'field' => lang('Repeat End Date'),
4727                                'data'  => '<input type="checkbox" name="cal[rpt_use_end]" value="y"'.$checked.'>'.lang('Use End Date').'  '.
4728/*
4729                                        $GLOBALS['phpgw']->common->dateformatorder(
4730                                                $sb->getYears('recur_enddate[year]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'Y')),
4731                                                $sb->getMonthText('recur_enddate[month]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'n')),
4732                                                $sb->getDays('recur_enddate[mday]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'d'))
4733                                        )
4734*/
4735                                        $jscal->input('recur_enddate[str]',$recur_end)
4736                        );
4737
4738                        $i = 0; $boxes = '';
4739                        foreach ($this->bo->rpt_day as $mask => $name)
4740                        {
4741                                $boxes .= '<input type="checkbox" name="cal[rpt_day][]" value="'.$mask.'"'.($event['recur_data'] & $mask ? ' checked' : '').'>&nbsp;'.lang($name)."\n";
4742                                if (++$i == 5) $boxes .= '<br>';
4743                        }
4744                        $var['recure_day'] = Array(
4745                                'field' => lang('Repeat Day').'<br>'.lang('(for weekly)'),
4746                                'data'  => $boxes
4747                        );
4748
4749                        $var['recure_interval'] = Array(
4750                                'field' => lang('Interval'),
4751                                'data'  => '<input name="cal[recur_interval]" size="4" maxlength="4" value="'.$event['recur_interval'].'">'
4752                        );
4753
4754                        if (!isset($this->fields))
4755                        {
4756                                $this->custom_fields = CreateObject('calendar.bocustom_fields');
4757                                $this->fields = &$this->custom_fields->fields;
4758                                $this->stock_fields = &$this->custom_fields->stock_fields;
4759                        }
4760                        $preserved = False;
4761                        foreach($this->fields as $field => $data)
4762                        {
4763                                if (!$data['disabled'])
4764                                {
4765                                        if (isset($var[$field]))
4766                                        {
4767                                                switch($field)
4768                                                {
4769                                                        case 'startdate':
4770                                                                $this->output_template_array($p,'row','list',$var['startdate']);
4771                                                                $this->output_template_array($p,'row','list',$var['starttime']);
4772                                                                break;
4773                                                        case 'enddate':
4774                                                                $this->output_template_array($p,'row','list',$var['enddate']);
4775                                                                $this->output_template_array($p,'row','list',$var['endtime']);
4776                                                                break;
4777                                                        case 'recure_type':
4778                                                                $p->set_var('tr_color',$this->theme['th_bg']);
4779                                                                $p->set_var('hr_text','<center><b>'.lang('Repeating Event Information').'</b></center>');
4780                                                                $p->parse('row','hr',True);
4781                                                                $this->output_template_array($p,'row','list',$var['recure_type']);
4782                                                                $this->output_template_array($p,'row','list',$var['recure_enddate']);
4783                                                                $this->output_template_array($p,'row','list',$var['recure_day']);
4784                                                                $this->output_template_array($p,'row','list',$var['recure_interval']);
4785                                                                break;
4786                                                        default:
4787                                                                $this->output_template_array($p,'row','list',$var[$field]);
4788                                                }
4789                                        }
4790                                        elseif (!isset($this->stock_fields[$field]))    // Custom field
4791                                        {
4792                                                $lang = lang($name = substr($field,1));
4793                                                $size = 'SIZE='.($data['shown'] ? $data['shown'] : ($data['length'] ? $data['length'] : 30)).
4794                                                        ' MAXLENGTH='.($data['length'] ? $data['length'] : 255);
4795                                                $v = array(
4796                                                        'field' => $lang == $name.'*' ? $name : $lang,
4797                                                        'data'  => '<input name="cal['.htmlspecialchars($field).']" '.$size.' value="'.$event['#'.$name].'">'
4798                                                );
4799                                                if ($data['title'])
4800                                                {
4801                                                        $v['tr_color'] = $this->theme['th_bg'];
4802                                                }
4803                                                if (!$data['length'] && $data['title'])
4804                                                {
4805                                                        $p->set_var('tr_color',$this->theme['th_bg']);
4806                                                        $p->set_var('hr_text','<center><b>'.$v['field'].'</b></center>');
4807                                                        $p->parse('row','hr',True);
4808                                                }
4809                                                else
4810                                                {
4811                                                        $this->output_template_array($p,'row','list',$v);
4812                                                }
4813                                        }
4814                                }
4815                                else    // preserve disabled fields
4816                                {
4817                                        switch ($field)
4818                                        {
4819                                                case 'owner':
4820                                                        $preserved[$field] = $event['id'] ? $event['participants'][$event['owner']] : 'A';
4821                                                        break;
4822                                                case 'recure_type':
4823                                                        foreach(array('recur_type','recur_enddate','recur_data','recur_interval') as $field)
4824                                                        {
4825                                                                $preserved[$field] = $event[$field];
4826                                                        }
4827                                                        break;
4828                                                case 'startdate':
4829                                                case 'enddate':
4830                                                        $field = substr($field,0,-4);
4831                                                default:
4832                                                        $preserved[$field] = $event[$field];
4833                                        }
4834                                }
4835                        }
4836                        unset($var);
4837                        if (is_array($preserved))
4838                        {
4839                                //echo "preserving<pre>"; print_r($preserved); echo "</pre>\n";
4840                                $p->set_var('common_hidden',$p->get_var('common_hidden').'<input type="hidden" name="preserved" value="'.htmlspecialchars(serialize($preserved)).'">'."\n");
4841                        }
4842                        $p->set_var('submit_button',lang('Save'));
4843
4844                        $delete_button = $cancel_button = '';
4845                        if ($event['id'] > 0)
4846                        {
4847                                $var = Array(
4848                                        'action_url_button'     => $this->page('delete','&cal_id='.$event['id']),
4849                                        'action_text_button'    => lang('Delete'),
4850                                        'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"",
4851                                        'action_extra_field'    => ''
4852                                );
4853                                $p->set_var($var);
4854                                $delete_button = $p->fp('out','form_button');
4855                        }
4856                        $p->set_var('delete_button',$delete_button);
4857
4858                        if ($this->bo->return_to)
4859                        {
4860                                $var = Array(
4861                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
4862                                        'action_text_button'    => lang('Cancel'),
4863                                        'action_confirm_button' => '',
4864                                        'action_extra_field'    => ''
4865                                );
4866                                $p->set_var($var);
4867                                $cancel_button = $p->fp('out','form_button');
4868                        }
4869                        $p->set_var('cancel_button',$cancel_button);
4870                        $p->pparse('out','edit_entry');
4871                       
4872                }
4873               
4874                // modify list of an event's external participants (i.e. non pgpgw users)
4875                //
4876                function modify_ext_partlist()
4877                {
4878                        $GLOBALS['phpgw_info']['flags']['noheader'] = True;
4879                        $GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
4880                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
4881                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
4882
4883                        $total_contacts = 0;
4884                        $participant = array();
4885                        $control_data= array();
4886
4887                        $control_data['action'] = '';
4888                        $control_data['delete'] = array();
4889                        $control_data['part'] = array();
4890
4891                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4892                        $p->set_file(
4893                                Array(
4894                                        'T_edit_partlist' => 'edit_partlist.tpl',
4895                                        'T_edit_partlist_blocks' => 'edit_partlist_blocks.tpl'
4896                                )
4897                        );
4898
4899                        $p->set_block('T_edit_partlist_blocks','B_alert_msg','V_alert_msg');
4900                        $p->set_block('T_edit_partlist_blocks','B_partlist','V_partlist');
4901                        $p->set_block('T_edit_partlist_blocks','B_participants_none','V_participants_none');
4902                        $p->set_block('T_edit_partlist_blocks','B_delete_btn','V_delete_btn');
4903
4904                        global $query_addr;
4905                        $sb = CreateObject('phpgwapi.sbox2');
4906                        $addy = $sb->getAddress('addr','',$query_addr);
4907
4908                        $add_ext  = $addy['doSearchFkt'];
4909                        $add_ext .= $addy['addr_title']!=lang('Address Book')?$addy['addr_title']:'';
4910                        $add_ext .= "&nbsp;".$addy['addr'].$addy['addr_nojs'];
4911
4912                        $p->set_var('text_add_name',$add_ext);
4913
4914                        if(isset($_GET['part']) && $_GET['part'])
4915                        {
4916                                $control_data['part'] = split(",", $_GET['part']);
4917                        }
4918                        else
4919                        {
4920                                $control_data['part'] = $_POST['participant'];
4921                                $control_data['action'] = $_POST['action'];
4922                                $control_data['delete'] = $_POST['delete'];
4923                        }
4924
4925                        for ($i=0; $i<count($control_data['part']); $i++)
4926                        {
4927                                $id = $control_data['part'][$i];
4928                                list($contact) = $this->read_contact($id);
4929
4930                                $participant[$id] = array();
4931                                $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
4932                        }
4933
4934                        if ($control_data['action'] == lang('Delete selected contacts'))
4935                        {
4936                                for ($i=0; $i<count($control_data['delete']); $i++)
4937                                {
4938                                        $id = $control_data['delete'][$i];
4939                                        unset($participant[$id]);
4940                                }
4941                        }
4942
4943                        if ($control_data['action'] == lang('Add Contact'))
4944                        {
4945                                $id = $_POST['id_addr'];
4946                                if (isset($id) && (int)$id != 0)
4947                                {
4948                                        list($contact) = $this->read_contact($id);
4949                                        $participant[$id] = array();
4950                                        $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
4951                                }
4952                        }
4953
4954                        // create list of currently selected contacts
4955                        //
4956                        while(list($id,$contact) = each($participant))
4957                        {
4958                                $p->set_var('hidden_delete_name','participant[]');
4959                                $p->set_var('hidden_delete_value',$id);
4960                                $p->set_var('ckbox_delete_name','delete[]');
4961                                $p->set_var('ckbox_delete_value',$id);
4962                                $p->set_var('ckbox_delete_participant',$contact['name']);
4963                                $p->parse('V_partlist','B_partlist',True);
4964                                $total_contacts++;
4965                        }
4966
4967                        if ($total_contacts == 0)
4968                        {
4969                                // no contacts have been selected
4970                                // => clear the delete form, remove delete button and show the none block
4971                                //
4972                                $p->set_var('V_partlist','');
4973                                $p->set_var('V_delete_btn','');
4974                                $p->set_var('text_none',lang('None'));
4975                                $p->parse('V_participants_none','B_participants_none');
4976                        }
4977                        else
4978                        {
4979                                // at least one contact has been selected
4980                                // => clear the none block, fill the delete form and add delete button
4981                                //
4982                                $p->set_var('V_participants_none','');
4983                                $p->set_var('btn_delete_name','action');
4984                                $p->set_var('btn_delete_value',lang('Delete selected contacts'));
4985                                $p->parse('V_delete_btn','B_delete_btn');
4986                        }
4987
4988                        $body_tags  = 'bgcolor="'.$GLOBALS['phpgw_info']['theme']['bg_color']
4989                                                        . '" alink="'.$GLOBALS['phpgw_info']['theme']['alink']
4990                                                        . '" link="'.$GLOBALS['phpgw_info']['theme']['link']
4991                                                        .'" vlink="'.$GLOBALS['phpgw_info']['theme']['vlink'].'"';
4992
4993                        $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.modify'));
4994
4995                        $charset = lang('charset');
4996                        $p->set_var('charset',$charset);
4997                        $p->set_var('page_title',$GLOBALS['phpgw_flags']['currentapp']
4998                                . ' - ' .lang('External Participants'));
4999                        $p->set_var('font_family',$GLOBALS['phpgw_info']['theme']['font']);
5000                        $p->set_var('body_tags',$body_tags);
5001                        $p->set_var('form_method','POST');
5002                        $p->set_var('form_action',$form_action);
5003                        $p->set_var('text_add_contact',lang('External Participants'));
5004                        $p->set_var('text_contacts_selected',lang('Selected contacts (%1)',$total_contacts));
5005                        $p->set_var('btn_add_name','action');
5006                        $p->set_var('btn_add_value',lang('Add Contact'));
5007                        $p->set_var('btn_done_name','done');
5008                        $p->set_var('btn_done_value',lang('Done'));
5009                        $p->set_var('btn_done_js','copyback()');
5010                        $p->set_var('form1_name','ext_form');
5011
5012                        $p->pfp('out','T_edit_partlist');
5013                }
5014
5015                function read_contact($id)
5016                {
5017                        $query_fields = Array(
5018                                'n_given' => 'n_given',
5019                                'n_family' => 'n_family',
5020                                'email' => 'email',
5021                                'email_home' => 'email_home'
5022                        );
5023
5024                        /*
5025                        if ($this->rights & PHPGW_ACL_READ)
5026                        {
5027                                return $this->contacts->read_single_entry($id,$fields);
5028                        }
5029                        else
5030                        {
5031                                $rtrn = array(0 => array('No access' => 'No access'));
5032                                return $rtrn;
5033                        }
5034                        */
5035
5036                        $contacts = CreateObject('phpgwapi.contacts', False);
5037                        return $contacts->read_single_entry($id,$query_fields);
5038                }
5039
5040                function build_part_list(&$users,$accounts,$owner)
5041                {
5042                        if(!is_array($accounts))
5043                        {
5044                                return;
5045                        }
5046                        foreach($accounts as $id)
5047                        {
5048                                $id = (int)$id;
5049                                if($id == $owner)
5050                                {
5051                                        continue;
5052                                }
5053                                elseif(!isset($users[$id]))
5054                                {
5055                                        if($GLOBALS['phpgw']->accounts->exists($id) == True)
5056                                        {
5057                                                $users[$id] = Array(
5058                                                        'name'  => $GLOBALS['phpgw']->common->grab_owner_name($id),
5059                                                        'type'  => $GLOBALS['phpgw']->accounts->get_type($id)
5060                                                );
5061                                        }
5062                                        if($GLOBALS['phpgw']->accounts->get_type($id) == 'g')
5063                                        {
5064                                                //$this->build_part_list($users,$GLOBALS['phpgw']->acl->get_ids_for_location($id,1,'phpgw_group'),$owner);
5065                                        }
5066                                }
5067                        }
5068                        if (!function_exists('strcmp_name'))
5069                        {
5070                                function strcmp_name($arr1,$arr2)
5071                                {
5072                                        if ($diff = strcmp($arr1['type'],$arr2['type']))
5073                                        {
5074                                                return $diff;   // groups before users
5075                                        }
5076                                        return strnatcasecmp($arr1['name'],$arr2['name']);
5077                                }
5078                        }
5079                        uasort($users,'strcmp_name');
5080                }
5081
5082                function set_week_array($startdate,$cellcolor,$weekly)
5083                {
5084                        $data = date("m");
5085                        for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
5086                        {
5087                                $date = date('Ymd',$datetime + (60 * 60 * 2)); // +2h to be save when switching to and from dst, $datetime is alreay + TZ-Offset
5088                                print_debug('set_week_array : Date ',$date);
5089
5090                                if($events = $this->bo->cached_events[$date])
5091                                {
5092                                        print_debug('Date',$date);
5093                                        print_debug('Appointments Found',count($events));
5094
5095                                        if (!$this->bo->prefs['calendar']['show_rejected'])
5096                                        {
5097                                                $appts = False;
5098                                                foreach($events as $event)      // check for a not-rejected event
5099                                                {
5100                                                        if (!$this->bo->rejected_no_show($event))
5101                                                        {
5102                                                                $appts = True;
5103                                                                break;
5104                                                        }
5105                                                }
5106                                        }
5107                                        else
5108                                        {
5109                                                $appts = True;
5110                                        }
5111                                }
5112                                else
5113                                {
5114                                        $appts = False;
5115                                }
5116
5117                                $holidays = $this->bo->cached_holidays[$date];
5118                                if($weekly)
5119                                {
5120                                        $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
5121                                }
5122
5123                                $day_image = '';
5124                                if($holidays)
5125                                {
5126                                        $extra = ' bgcolor="'.$this->bo->holiday_color.'"';
5127                                        $class = ($appts?'b':'').'minicalhol';
5128                                        if ($date == $this->bo->today)
5129                                        {
5130                                                $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5131                                        }
5132                                }
5133                                elseif ($date != $this->bo->today)
5134                                {
5135                                        $extra = ' bgcolor="'.$cellcolor.'"';
5136                                        $class = ($appts?'b':'').'minicalendar';
5137                                }
5138                                else
5139                                {
5140                                        $extra = ' bgcolor="'.$GLOBALS['phpgw_info']['theme']['cal_today'].'"';
5141                                        $class = ($appts?'b':'').'minicalendar';
5142                                        $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5143                                }
5144
5145                                if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
5146                                {
5147                                        $extra = '';
5148                                }
5149
5150                                if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
5151                                {
5152                                        $new_event = True;
5153                                }
5154                                else
5155                                {
5156                                        $new_event = False;
5157                                }
5158                                $holiday_name = Array();
5159                                if($holidays)
5160                                {
5161                                        for($k=0;$k<count($holidays);$k++)
5162                                        {
5163                                                $holiday_name[] = $holidays[$k]['name'];
5164                                        }
5165                                }
5166                                $week = '';
5167                                if (!$j || (!$weekly && $j && substr($date,6,2) == '01'))
5168                                {
5169                                        $week = lang('week').' '.(int)((date('z',($startdate+(24*3600*4)))+7)/7);
5170                                }
5171                                $daily[$date] = Array(
5172                                        'extra'         => $extra,
5173                                        'new_event'     => $new_event,
5174                                        'holidays'      => $holiday_name,
5175                                        'appts'         => $appts,
5176                                        'week'          => $week,
5177                                        'day_image'     => $day_image,
5178                                        'class'         => $class
5179                                );
5180                        }
5181
5182                        if($this->debug)
5183                        {
5184                                _debug_array($daily);
5185                        }
5186
5187                        return $daily;
5188                }
5189               
5190                function get_organizations($context, $selected='', $recursive = false)
5191                {
5192                        $s = CreateObject('phpgwapi.sector_search_ldap');
5193                                               
5194                        return ($recursive ?
5195                                $s->get_organizations($context, $selected, false ,false) :
5196                                $s->get_sectors($selected, false, false));
5197                }               
5198        }
5199?>
Note: See TracBrowser for help on using the repository browser.