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

Revision 602, 166.6 KB checked in by niltonneto, 15 years ago (diff)

Resolve #390

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