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

Revision 36, 149.0 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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