source: companies/celepar/calendar/inc/class.uicalendar.inc.php @ 763

Revision 763, 167.8 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

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