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

Revision 663, 167.6 KB checked in by niltonneto, 15 years ago (diff)

Alteração que não impacta na Agenda atual, mas será utilizado pelo expressoCalendar (nova agenda).

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