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

Revision 29, 148.5 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                                $this->bo->set_start($this->bo->year,$this->bo->month,$this->bo->day,$starthour,$startmin,0);
1185                                $this->bo->set_end($this->bo->year,$this->bo->month,$this->bo->day,$endhour,$endmin,0);
1186                                $this->bo->set_title('');
1187                                $this->bo->set_description('');
1188                                $this->bo->set_ex_participants('');
1189                                $this->bo->add_attribute('location','');
1190                                $this->bo->add_attribute('uid','');
1191                                $this->bo->add_attribute('priority',2);
1192                                if(@$this->bo->prefs['calendar']['default_private'])
1193                                {
1194                                        $this->bo->set_class(False);
1195                                }
1196                                else
1197                                {
1198                                        $this->bo->set_class(True);
1199                                }
1200                                // Add participants
1201                                //$participants = explode(";", $GLOBALS['phpgw']->session->appsession("participants") );
1202                                //for($_f_part=0; $_f_part<count($participants); $_f_part++)
1203                                //{
1204                                //      $this->bo->add_attribute('participants','A',$participants[$_f_part]);
1205                                //}
1206                                // Add misc
1207                                $this->bo->add_attribute('participants','A',$this->bo->owner);
1208                                $this->bo->set_recur_none();
1209                                $event = $this->bo->get_cached_event();
1210                               
1211                        }
1212                        $this->edit_form(
1213                                Array(
1214                                        'event' => $event,
1215                                        'cd' => $cd
1216                                )
1217                        );
1218                        $GLOBALS['phpgw']->common->phpgw_footer();
1219                }
1220
1221                function delete()
1222                {
1223                        if(!isset($_GET['cal_id']))
1224                        {
1225                                Header('Location: '.$this->page('','&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day)));
1226                                $GLOBALS['phpgw']->common->phpgw_exit();
1227                        }
1228
1229                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day);
1230                        if($this->bo->check_perms(PHPGW_ACL_DELETE,$cal_id = (int)$_GET['cal_id']))
1231                        {
1232                                if(isset($_POST['delete_type']) && $_POST['delete_type'] == 'single')
1233                                {
1234                                        $date = $_POST['date'];
1235                                        $cd = $this->bo->delete_single(
1236                                                Array(
1237                                                        'id'    => $cal_id,
1238                                                        'year'  => substr($date,0,4),
1239                                                        'month' => substr($date,4,2),
1240                                                        'day'   => substr($date,6,2)
1241                                                )
1242                                        );
1243                                }
1244                                elseif((isset($_POST['delete_type']) && $_POST['delete_type'] == 'series') || !isset($_POST['delete_type']))
1245                                {
1246                                        $cd = $this->bo->delete_entry($cal_id);
1247                                        $this->bo->expunge();
1248                                }
1249                        }
1250                        else
1251                        {
1252                                $cd = '';
1253                        }
1254                        if ($this->bo->return_to)
1255                        {
1256                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
1257                        }
1258                        else
1259                        {
1260                                Header('Location: '.$this->page('','&date='.$date.($cd?'&cd='.$cd:'')));
1261                        }
1262                        $GLOBALS['phpgw']->common->phpgw_exit();
1263                }
1264
1265                function day()
1266                {
1267                       
1268                        $this->bo->read_holidays();
1269
1270                        if (!$this->bo->printer_friendly || ($this->bo->printer_friendly && @$this->bo->prefs['calendar']['display_minicals']))
1271                        {
1272                                $minical = $this->mini_calendar(
1273                                        Array(
1274                                                'day'   => $this->bo->day,
1275                                                'month' => $this->bo->month,
1276                                                'year'  => $this->bo->year,
1277                                                'link'  => 'day'
1278                                        )
1279                                );
1280                        }
1281                        else
1282                        {
1283
1284//NDEE: printer-friendly (what?)
1285                                $minical = '';
1286                        }
1287
1288                        if (!$this->bo->printer_friendly)
1289                        {
1290                                $printer = '';
1291                                $param = '&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day).'&friendly=1';
1292                                $print = '<a href="'.$this->page('day'.$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window.status = '".lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
1293                        }
1294                        else
1295                        {
1296
1297//NDEE: printer-friendly (daily-view)
1298                                $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
1299                                $printer = '<body bgcolor="'.$this->theme['bg_color'].'">';
1300                                $print =        '';
1301                        }
1302
1303                        $now    = $GLOBALS['phpgw']->datetime->makegmttime(0, 0, 0, $this->bo->month, $this->bo->day, $this->bo->year);
1304                        $now['raw'] += $GLOBALS['phpgw']->datetime->tz_offset;
1305
1306                        $p = $GLOBALS['phpgw']->template;
1307                        $p->set_file(
1308                                Array(
1309                                        'day_t' => 'day.tpl'
1310                                )
1311                        );
1312                        $p->set_block('day_t','day','day');
1313                        $p->set_block('day_t','day_event','day_event');
1314
1315                        $todos = $this->get_todos($todo_label);
1316                        $var = Array(
1317                                'printer_friendly'      => $printer,
1318                                'bg_text'                       => $this->theme['bg_text'],
1319                                'daily_events'          => $this->print_day(
1320                                        Array(
1321                                                'year'  => $this->bo->year,
1322                                                'month' => $this->bo->month,
1323                                                'day'   => $this->bo->day
1324                                        )
1325                                ),
1326                                'small_calendar'        => $minical,
1327                                'date'                          => $this->bo->long_date($now),
1328                                'username'                      => $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner),
1329                                'print'                         => $print,
1330                                'lang_todos'            => $todo_label,
1331                                'todos'                         => $this->bo->printer_friendly ? $todos :
1332
1333//NDEE: todo's layout
1334                                        "<div style=\"overflow: auto; max-height: 200px\">\n$todos</div>\n"
1335                        );
1336
1337                        $p->set_var($var);
1338                        $p->parse('day_events','day_event');
1339                        print $this->printer_friendly($p->fp('out','day'),lang('Dayview'));
1340                        $GLOBALS['phpgw']->common->phpgw_footer();
1341                }
1342
1343                function get_todos(&$todo_label)
1344                {
1345                        $todos_from_hook = $GLOBALS['phpgw']->hooks->process(array(
1346                                'location'  => 'calendar_include_todos',
1347                                'year'      => $this->bo->year,
1348                                'month'     => $this->bo->month,
1349                                'day'       => $this->bo->day,
1350                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
1351                        ));
1352
1353                        if(is_array($todo_label))
1354                        {
1355                                list($label,$showall)=$todo_label;
1356                        }
1357                        else
1358                        {
1359                                $label=$todo_label;
1360                                $showall=true;
1361                        }
1362                        $maxshow = (int)$GLOBALS['phpgw_info']['user']['preferences']['infolog']['mainscreen_maxshow'];
1363                        if($maxshow<=0)
1364                        {
1365                                $maxshow=10;
1366                        }
1367                        //print_debug("get_todos(): label=$label; showall=$showall; max=$maxshow");
1368
1369                        $content = $todo_label = '';
1370                        if (is_array($todos_from_hook) && count($todos_from_hook))
1371                        {
1372                                $todo_label = !empty($label)?$label:lang("open ToDo's:");
1373
1374                                foreach($todos_from_hook as $todos)
1375                                {
1376                                        $i = 0;
1377                                        if (is_array($todos) && count($todos))
1378                                        {
1379                                                foreach($todos as $todo)
1380                                                {
1381                                                        if(!$showall && ($i++>$maxshow))
1382                                                        {
1383                                                                break;
1384                                                        }
1385                                                        $icons = '';
1386                                                        foreach($todo['icons'] as $name => $app)
1387                                                        {
1388                                                                $icons .= ($icons?' ':'').$GLOBALS['phpgw']->html->image($app,$name,lang($name),'border="0" width="15" height="15"');
1389                                                        }
1390                                                        $class = $class == 'row_on' ? 'row_off' : 'row_on';
1391
1392//NDEE <tr starts here
1393                                                        $content .= " <tr id=\"debug\" class=\"$class\">\n  <td valign=\"top\" width=\"15%\"nowrap>".
1394                                                                ($this->bo->printer_friendly?$icons:$GLOBALS['phpgw']->html->a_href($icons,$todo['view'])).
1395                                                                "</td>\n  <td>".($this->bo->printer_friendly?$todo['title']:
1396                                                                $GLOBALS['phpgw']->html->a_href($todo['title'],$todo['view']))."</td>\n </tr>\n";
1397                                                }
1398                                        }
1399                                }
1400                        }
1401                        if (!empty($content))
1402                        {
1403                                return "<table border=\"0\" width=\"100%\">\n$content</table>\n";
1404                        }
1405                        return False;
1406                }
1407
1408                function edit_status()
1409                {
1410                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
1411                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1412                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
1413                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
1414                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Change Status');
1415                        $GLOBALS['phpgw']->common->phpgw_header();
1416
1417                        $event = $this->bo->read_entry($_GET['cal_id']);
1418
1419                        reset($event['participants']);
1420
1421                        if(!$event['participants'][$this->bo->owner])
1422                        {
1423                                echo '<center>'.lang('The user %1 is not participating in this event!',$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner)).'</center>';
1424                                return;
1425                        }
1426
1427                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1428                        {
1429                                $this->no_edit();
1430                                return;
1431                        }
1432
1433                        $freetime = $GLOBALS['phpgw']->datetime->localdates(mktime(0,0,0,$event['start']['month'],$event['start']['mday'],$event['start']['year']) - $GLOBALS['phpgw']->datetime->tz_offset);
1434                        echo $this->timematrix(
1435                                Array(
1436                                        'date'          => $freetime,
1437                                        'starttime'     => $this->bo->splittime('000000',False),
1438                                        'endtime'       => 0,
1439                                        'participants'  => $event['participants']
1440                                )
1441                        ).'<br>';
1442
1443                        $event = $this->bo->read_entry($_GET['cal_id']);
1444                        $this->view_event($event);
1445                        $GLOBALS['phpgw']->template->pfp('phpgw_body','view_event');
1446
1447                        echo $this->get_response($event['id']);
1448                }
1449               
1450                function confirm_action()
1451                {
1452                                if($_GET['response'] == 1)
1453                                {
1454                                        $notify_message = lang('The commitment was accepted successfully!');;
1455                                }       
1456                                else
1457                                {                               
1458                                        $notify_message = lang('The commitment was rejected successfully!');
1459                                }
1460                               
1461                                $body1 = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
1462                                $body1->set_file(Array('calendar' => 'confirm.tpl'));
1463                                $body1->set_block('calendar','list');
1464                                $var = Array( 'notify_message'  => $notify_message);
1465                                $body1->set_var($var);
1466                                $tmpbody1 = $body1->pfp('out','list');
1467                }
1468                function set_action()
1469                {
1470                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1471                        {
1472                                $this->no_edit();
1473                                return;
1474                        }
1475                        $this->bo->set_status((int)$_GET['cal_id'],(int)$_GET['action']);
1476                       
1477                        if(isset($_GET['response']))
1478                        {
1479                                        $this->confirm_action();
1480                                        $GLOBALS['phpgw']->common->phpgw_exit(False);
1481                        }
1482                        else
1483                        {
1484                                        if ($this->bo->return_to)
1485                                        {
1486                                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
1487                                        }
1488                                        else
1489                                        {
1490                                                Header('Location: '.$this->page('',''));
1491                                        }
1492                                        $GLOBALS['phpgw']->common->phpgw_exit();
1493                        }
1494                       
1495                }
1496                function planner()
1497                {
1498                        if(floor(phpversion()) < 4)
1499                        {
1500                                return;
1501                        }
1502                        $home = strstr($_SERVER['PHP_SELF'],'home') !== False;
1503                        // generate header and set global/member variables
1504                        //
1505                        $this->planner_prepare($home);
1506
1507                        // process events within selected interval
1508                        //
1509                        $this->planner_process_interval();
1510
1511                        // generate the planner view
1512                        //
1513                        if (!$home)
1514                        {
1515                                echo '<p>'.$this->planner_print_rows();
1516                        }
1517                        else
1518                        {
1519                                return $this->planner_print_rows();
1520                        }
1521                }
1522
1523                function set_planner_group_members()
1524                {
1525                        $type = $GLOBALS['phpgw']->accounts->get_type($this->bo->owner);
1526
1527                        if ($type == 'g') // display schedule of all group members
1528                        {
1529                                $members = array();
1530                                $ids = $GLOBALS['phpgw']->acl->get_ids_for_location($this->bo->owner, 1, 'phpgw_group');
1531                                while (list(,$id) = each($ids))
1532                                {
1533                                        if ($this->bo->check_perms(PHPGW_ACL_READ,0,$id))
1534                                        {
1535                                                $members[$GLOBALS['phpgw']->common->grab_owner_name($id)] = $id;
1536                                        }
1537                                }
1538                                ksort($members);
1539                                $this->planner_group_members = $members;
1540                        }
1541                        else
1542                        {
1543                                $this->planner_group_members = array(
1544                                        $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner) => $this->bo->owner
1545                                );
1546                        }
1547                }
1548
1549                /**
1550                 * planner_prepare - prepare the planner view
1551                 *
1552                 * - sets global environment variables
1553                 * - initializes class member variables used in multiple planner related functions
1554                 * - generates header lines for the planner view (month, calendar week, days)
1555                 */
1556                function planner_prepare($no_header = False)
1557                {
1558                        // set some globals
1559                        //
1560                        if (!$no_header)
1561                        {
1562                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
1563                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1564                                if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Group Planner');
1565                                $GLOBALS['phpgw']->common->phpgw_header();
1566                        }
1567
1568                        // intervals_per_day can be configured in preferences now :-)
1569                        //
1570                        if (! $this->bo->prefs['calendar']['planner_intervals_per_day'])
1571                        {
1572                                $GLOBALS['phpgw']->preferences->add('calendar','planner_intervals_per_day',3);
1573                                $GLOBALS['phpgw']->preferences->save_repository();
1574                                $this->bo->prefs['calendar']['planner_intervals_per_day'] = 3;
1575                        }
1576                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
1577                        $this->bo->save_sessiondata();  // need to save $this->bo->save_owner
1578
1579                        // set title for table and rows of planner view
1580                        //
1581                        if ($this->bo->sortby == 'category')
1582                        {
1583                                $title = lang('Category');
1584                        }
1585                        else
1586                        {
1587                                $title = lang('User');
1588
1589                                $this->set_planner_group_members();
1590                        }
1591
1592                        // create/initialize variables directly used for HTML code generation
1593                        //
1594                        $this->planner_header = array();
1595                        $this->planner_rows   = array();
1596
1597                        // generate header lines with days and associated months
1598                        //
1599                        $hdr = &$this->planner_header;
1600                        $hdr[0]['0']  = $title;
1601                        $hdr[0]['.0'] = 'rowspan="3"';
1602
1603                        $this->planner_days = 0; // reset
1604
1605                        $m = $this->bo->month;
1606                        $y = $this->bo->year;
1607                        $this->bo->read_holidays($y);
1608                        for ($i=1; $i<=$this->bo->num_months; $i++,$m++)
1609                        {
1610                                if ($m == 13)
1611                                {
1612                                        $m = 1; $y++; // "wrap-around" into new year
1613                                        $this->bo->read_holidays($y);
1614                                }
1615                                $days = $GLOBALS['phpgw']->datetime->days_in_month($m,$y);
1616
1617                                $d     = mktime(0,0,0,$m,1,$y);
1618                                $month = lang(date('F', $d)).strftime(' %Y', $d);
1619                                $color = $this->theme[$m % 2 || $this->bo->num_months == 1 ? 'th_bg' : 'row_on'];
1620                                $cols  = $days * $intervals_per_day;
1621
1622                                $hdr[0]['.'.$i] = 'bgcolor="'.$color.'" colspan="'.$cols.'" align="center"';
1623                                $prev_month = sprintf('%04d%02d01',$y-($m==1),$m > 1?$m-1:12);
1624                                $next_month = sprintf('%04d%02d01',$y+($m==12),$m < 12?$m+1:1);
1625                                $prev_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$prev_month");
1626                                $next_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$next_month");
1627                                $hdr[0][$i] = "<b><a href=\"$prev_link\">&lt;&lt;</a> &nbsp $month &nbsp <a href=\"$next_link\">&gt;&gt;</a></b>";
1628
1629                                $add_owner = array();   // if no add-rights on the showed cal use own cal
1630                                if (!$this->bo->save_owner && !$this->bo->check_perms(PHPGW_ACL_ADD) ||
1631                                        !$this->bo->check_perms(PHPGW_ACL_ADD,0,$this->bo->save_owner))
1632                                {
1633                                        $add_owner = array(
1634                                                'owner' => $GLOBALS['phpgw_info']['user']['account_id']
1635                                        );
1636                                }
1637                                for ($d=1; $d<=$days; $d++)
1638                                {
1639                                        $dayname = substr(lang(date('D',mktime(0,0,0,$m,$d,$y))),0,2);
1640                                        $index = $d + $this->planner_days;
1641
1642                                        $hdr[2]['.'.$index] = 'colspan="'.$intervals_per_day.'" align="center"';
1643
1644                                        // highlight today, saturday, sunday and holidays
1645                                        //
1646                                        $color = $this->theme['row_off'];
1647                                        $dow = $GLOBALS['phpgw']->datetime->day_of_week($y,$m,$d);
1648                                        $date = sprintf("%04d%02d%02d",$y,$m,$d);
1649                                        if ($date == date('Ymd'))
1650                                        {
1651                                                $color = $GLOBALS['phpgw_info']['theme']['cal_today'];
1652                                        }
1653                                        elseif ($this->bo->cached_holidays[$date])
1654                                        {
1655                                                $color = $this->bo->holiday_color;
1656                                                $hdr[2]['.'.$index] .= ' title="'.$this->bo->cached_holidays[$date][0]['name'].'"';
1657                                        }
1658                                        elseif ($dow == 0 || $dow == 6)
1659                                        {
1660                                                $color = $this->bo->theme['th_bg'];
1661                                        }
1662
1663                                        $hdr[2]['.'.$index] .= " bgcolor=\"$color\"";
1664
1665                                        $hdr[2][$index] = '<a href="'.$this->html->link('/index.php',
1666                                                                array(
1667                                                                        'menuaction' => 'calendar.uicalendar.add',
1668                                                                        'date' => $date
1669                                                                ) + $add_owner
1670                                                        ).'">'.$dayname.'<br>'.$d.'</a>';
1671                                }
1672                                $this->planner_days += $days;
1673                        }
1674
1675                        // create/initialize member variables describing the time interval to be displayed
1676                        //
1677                        $this->planner_end_month = $m - 1;
1678                        $this->planner_end_year  = $y;
1679                        $this->planner_days_in_end_month = $GLOBALS['phpgw']->datetime->days_in_month($this->planner_end_month,$this->planner_end_year);
1680                        $this->planner_firstday = (int)(date('Ymd',mktime(0,0,0,$this->bo->month,1,$this->bo->year)));
1681                        $this->planner_lastday  = (int)(date('Ymd',mktime(0,0,0,$this->planner_end_month,$this->planner_days_in_end_month,$this->planner_end_year)));
1682
1683                        // generate line with calendar weeks in observed interval
1684                        //
1685                        $d      = mktime(0,0,0,$this->bo->month,1,$this->bo->year);
1686                        $w      = date('W', $d);
1687                        if ($w == 'W')  // php < 4.1
1688                        {
1689                                $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
1690                        }
1691                        $offset = (7-date('w', $d)+1)%7;
1692                        $offset = $offset == 0 ? 7 : $offset;
1693                        $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
1694
1695                        $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$intervals_per_day * $offset.'" align="left"';
1696                        $hdr[1][$w] = '';
1697                        if ($offset >= 3)
1698                        {
1699
1700//NDEE: style! (groupplanner)
1701                                $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
1702                        }
1703                        $days_left = $this->planner_days - $offset;
1704
1705                        $colspan = 7 * $intervals_per_day;
1706                        while ($days_left > 0)
1707                        {
1708                                $colspan = ($days_left < 7) ? $days_left*$intervals_per_day : $colspan;
1709                                $d += 604800; // 7 days whith 24 hours (1h == 3600 seconds) each
1710                                $w = date('W', $d);
1711                                if ($w == 'W')  // php < 4.1
1712                                {
1713                                        $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
1714                                }
1715                                $w += (isset($hdr[1][$w]))?1:0; // bug in "date('W')" ?
1716
1717                                $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
1718                                $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$colspan.'" align="left"';
1719                                $hdr[1][$w] = '';
1720                                if ($days_left >= 3)
1721                                {
1722
1723//NDEE: style! (groupplanner)
1724                                        $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
1725                                }
1726
1727                                $days_left -= 7;
1728                        }
1729                        return $hdr;
1730                }
1731
1732                /**
1733                 * planner_update_row - update a row of the planner view
1734                 *
1735                 * parameters are:
1736                 *   - index (e.g. user id, category id, ...) of the row
1737                 *   - name/title of the row (e.g. user name, category name)
1738                 *   - the event to be integrated
1739                 *   - list of categories associated with the event
1740                 *   - first and last cell of the row
1741                 */
1742                function planner_update_row($index,$name,$event,$cat,$start_cell,$end_cell)
1743                {
1744                        $rows              = &$this->planner_rows;
1745                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
1746                        $is_private        = !$this->bo->check_perms(PHPGW_ACL_READ,$event);
1747
1748                        $view = $this->html->link('/index.php',
1749                                array(
1750                                        'menuaction' => 'calendar.uicalendar.view',
1751                                        'cal_id' => $event['id'],
1752                                        'date' => date('Ymd',$this->bo->maketime($event['start']))
1753                                )
1754                        );
1755
1756                        // check how many lines are needed for this "row" (currently: user or category)
1757                        $i = 0;
1758                        do {
1759                                ++$i;
1760
1761                                $k = $index.'_'.$i;
1762                                $ka = '.nr_'.$k;
1763
1764                                if (!isset($rows[$k]))
1765                                {
1766                                        if ($i > 1)                             // further line - no name
1767                                        {
1768                                                $rows[$k] = array();
1769                                                $rows[$index.'_1']['._name'] = 'rowspan="'.$i.'"';
1770                                        }
1771                                        else
1772                                        {
1773                                                $rows[$k]['_name'] = $name;
1774                                        }
1775                                        $rows[$ka] = 0;
1776                                }
1777                                $rows[$index.'_1']['._name'] .= ' nowrap'; // title must be one row
1778
1779                                $row = &$rows[$k];
1780                                $akt_cell = &$rows[$ka];
1781                        } while ($akt_cell > $start_cell);
1782
1783                        $id = $event['id'].'-'.date('Ymd',$this->bo->maketime($event['start']));
1784                        if ($akt_cell < $start_cell)
1785                        {
1786                                $row[$id.'_1'] = '&nbsp;';
1787                                $row['.'.$id.'_1'] = 'colspan="'.($start_cell-$akt_cell).'"';
1788                        }
1789                        $opt = &$row['.'.$id.'_2'];
1790                        $cel = &$row[$id.'_2'];
1791
1792                        // if possible, display information about event within cells representing it
1793                        //
1794                        if ($start_cell < $end_cell)
1795                        {
1796                                $colspan = $end_cell - $start_cell;
1797                                $opt .= "colspan=".(1 + $colspan);
1798
1799                                if (!$is_private)
1800                                {
1801                                        $max_chars = (int)(3*$colspan/$intervals_per_day-2);
1802
1803                                        $min_chars = 3; // minimum for max_chars to display -> this should be configurable
1804                                        if ($max_chars >= $min_chars)
1805                                        {
1806                                                $len_title = strlen($event['title']);
1807
1808                                                if ($len_title <= $max_chars)
1809                                                {
1810                                                        $title = $event['title'];
1811                                                        $max_chars -= $len_title + 3; // 3 chars for separator: " - "
1812                                                        $len_descr = strlen($event['description']);
1813
1814                                                        if ($len_descr > 0 && $len_descr <= $max_chars)
1815                                                        {
1816                                                                $event['print_description'] = 'yes';
1817                                                        }
1818                                                }
1819                                                else
1820                                                {
1821                                                        $has_amp = strpos($event['title'],'&amp;');
1822                                                       
1823//NDEE: event title gets cut here                                                       
1824                                                        $title = substr($event['title'], 0 , $max_chars-1+($has_amp!==False&&$has_amp<$max_chars?4:0)).'...';
1825                                                }
1826                                                $event['print_title'] = 'yes';
1827                                        }
1828                                }
1829                        }
1830
1831                        if ($bgcolor=$cat['color'])
1832                        {
1833                                $opt .= ' bgcolor="'.$bgcolor.'"';
1834                        }
1835                        if (!$is_private)
1836                        {
1837                                $opt .= ' title="'.lang('Title').": ".$event['title'];
1838                                if ($event['description'])
1839                                {
1840                                        $opt .= "\n".lang('Description').": ".$event['description'];
1841                                }
1842                        }
1843                        else
1844                        {
1845                                $opt .= ' title="'.lang('You do not have permission to read this record!');
1846                        }
1847
1848                        $start = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset);
1849                        $end = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset);
1850                        $opt .= "\n".lang('Start Date/Time').": ".$start."\n".lang('End Date/Time').": ".$end;
1851
1852                        if ($event['location'] && !$is_private)
1853                        {
1854                                $opt .= " \n".lang('Location').": ".$event['location'];
1855                        }
1856
1857                        if (!$is_private)
1858                        {
1859                                $opt .= '" onClick="location=\''.$view.'\'"';
1860                                $cel = '<a href="'.$view.'">';
1861                        }
1862                        else
1863                        {
1864                                $opt .= '"';
1865                                $cel = '';
1866                        }
1867                        $opt .= ' class="planner-cell"';
1868
1869                        if ($event['priority'] == 3)
1870                        {
1871                                $cel .= $this->html->image('calendar','mini-calendar-bar.gif','','border="0"');
1872                        }
1873                        if ($event['recur_type'])
1874                        {
1875                                $cel .= $this->html->image('calendar','recur.gif','','border="0"');
1876                        }
1877                        $cel .= $this->html->image('calendar',count($event['participants'])>1?'multi_3.gif':'single.gif',$this->planner_participants($event['participants']),'border="0"');
1878                        $cel .= '</a>';
1879
1880                        if (isset($event['print_title']) && $event['print_title'] == 'yes')
1881                        {
1882
1883//NDEE: style! where?
1884                                $cel .= '<font size="-2"> '.$title.' </font>';
1885                        }
1886                        if (isset($event['print_description']) && $event['print_description'] == 'yes')
1887                        {
1888
1889//NDEE: style! where ?
1890                                $cel .= '<font size="-2"> - '.$event['description'].' </font>';
1891                        }
1892
1893                        $akt_cell = $end_cell + 1;
1894
1895                        return $rows;
1896                }
1897
1898                function planner_process_event($event)
1899                {
1900                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
1901                        $interval = $this->planner_intervals[$intervals_per_day];
1902                        $last_cell = $intervals_per_day * $this->planner_days - 1;
1903
1904                        $rows = &$this->planner_rows;
1905
1906                        // caluculate start and end of event
1907                        //
1908                        $event_start = (int)(date('Ymd',mktime(
1909                                0,0,0,
1910                                $event['start']['month'],
1911                                $event['start']['mday'],
1912                                $event['start']['year']
1913                        )));
1914                        $event_end   = (int)(date('Ymd',mktime(
1915                                0,0,0,
1916                                $event['end']['month'],
1917                                $event['end']['mday'],
1918                                $event['end']['year']
1919                        )));
1920
1921                        // calculate first cell of event within observed interval
1922                        //
1923                        if ($event_start >= $this->planner_firstday)
1924                        {
1925                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['start']['month'],$event['start']['mday'],$event['start']['year']);
1926
1927                                $start_cell = $intervals_per_day * $days_between + $interval[$event['start']['hour']];
1928                        }
1929                        else
1930                        {
1931                                $start_cell = 0;
1932                        }
1933
1934                        // calculate last cell of event within observed interval
1935                        //
1936                        if ($event_end <= $this->planner_lastday)
1937                        {
1938                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['end']['month'],$event['end']['mday'],$event['end']['year']);
1939                                $end_cell = $intervals_per_day * $days_between + $interval[$event['end']['hour']];
1940                                if ($end_cell == $start_cell && $end_cell < $last_cell)
1941                                {
1942                                        $end_cell++;    // min. width 1 interval
1943                                }
1944                        }
1945                        else
1946                        {
1947                                $end_cell = $last_cell;
1948                        }
1949                        // get the categories associated with event
1950                        //
1951                        if ($c = $event['category'])
1952                        {
1953                                list($cat)   = $this->planner_category($event['category']);
1954                                if ($cat['parent'])
1955                                {
1956                                        list($pcat) = $this->planner_category($c = $cat['parent']);
1957                                }
1958                                else
1959                                {
1960                                        $pcat = $cat;
1961                                }
1962                        }
1963                        else
1964                        {
1965                                $cat = $pcat = array( 'name' => lang('none'));
1966                        }
1967
1968                        // add the event to it`s associated row(s)
1969                        //
1970                        if ($this->bo->sortby == 'category')
1971                        {
1972                                // event needs to show up in it`s category`s row
1973                                //
1974                                $this->planner_update_row($c,$pcat['name'],$event,$cat,$start_cell,$end_cell);
1975                        }
1976                        elseif ($this->bo->sortby == 'user')
1977                        {
1978                                // event needs to show up in rows of all participants that are also owners
1979                                //
1980                                reset($this->planner_group_members);
1981                                while(list($user_name,$id) = each($this->planner_group_members))
1982                                {
1983                                        $status = $event['participants'][$id];
1984
1985                                        if (isset($status) && $status != 'R')
1986                                        {
1987                                                $this->planner_update_row($user_name,$user_name,$event,$cat,$start_cell,$end_cell);
1988                                        }
1989                                }
1990                        }
1991                }
1992
1993                function planner_pad_rows()
1994                {
1995                        $rows = &$this->planner_rows;
1996
1997                        if ($this->bo->sortby == 'user')
1998                        {
1999                                // add empty rows for users that do not participante in any event
2000                                //
2001                                reset($this->planner_group_members);
2002                                while(list($user_name,$id) = each($this->planner_group_members))
2003                                {
2004                                        $k  = $user_name.'_1';
2005                                        $ka = '.nr_'.$k;
2006
2007                                        if (!isset($rows[$k]))
2008                                        {
2009                                                $rows[$k]['_name'] = $user_name;
2010                                                $rows[$k]['._name'] .= ' nowrap';
2011                                                $rows[$ka] = 0;
2012                                        }
2013                                }
2014                        }
2015
2016                        // fill the remaining cols
2017                        //
2018                        $last_cell = $this->bo->prefs['calendar']['planner_intervals_per_day'] * $this->planner_days - 1;
2019
2020                        ksort($rows);
2021                        while (list($k,$r) = each($rows))
2022                        {
2023                                if (is_array($r))
2024                                {
2025                                        $rows['.'.$k] = 'bgcolor="'.$GLOBALS['phpgw']->nextmatchs->alternate_row_color().'"';
2026                                        $row = &$rows[$k];
2027                                        $akt_cell = &$rows['.nr_'.$k];
2028                                        if ($akt_cell < $last_cell)
2029                                        {
2030                                                $row['3'] = '&nbsp';
2031                                                $row['.3'] = 'colspan="'.(1+$last_cell-$akt_cell).'"';
2032                                        }
2033                                }
2034                        }
2035                }
2036
2037                function planner_print_rows()
2038                {
2039                        $bgcolor = 'bgcolor="'.$this->theme['th_bg'].'"';
2040                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2041
2042                        if ($this->debug)
2043                        {
2044                                _debug_array($this->planner_rows);
2045                                reset($this->planner_rows);
2046                        }
2047                        return $this->html->table(
2048                                array(
2049                                        '_hdr0' => $this->planner_header[0],
2050                                        '._hdr0' => $bgcolor,
2051                                        '_hdr1' => $this->planner_header[1],
2052                                        '._hdr1' => $bgcolor,
2053                                        '_hdr2' => $this->planner_header[2],
2054                                        '._hdr2' => $bgcolor
2055                                )+$this->planner_rows,
2056                                'width="100%" cols="'.(1+$this->planner_days_in_end_month*$intervals_per_day).'"');
2057                }
2058
2059                function planner_process_interval()
2060                {
2061                        // generate duplicate free list of events within observed interval
2062                        //
2063                        $this->bo->store_to_cache(
2064                                Array(
2065                                        'syear' => $this->bo->year,
2066                                        'smonth'        => $this->bo->month,
2067                                        'sday'  => 1,
2068                                        'eyear' => $this->planner_end_year,
2069                                        'emonth'        => $this->planner_end_month,
2070                                        'eday'  => $this->planner_days_in_end_month
2071                                )
2072                        );
2073                        $this->bo->remove_doubles_in_cache($this->planner_firstday,$this->planner_lastday);
2074
2075                        // process all events within observed interval
2076                        //
2077                        for($v=$this->planner_firstday;$v<=$this->planner_lastday;$v++)
2078                        {
2079                                $daily = $this->bo->cached_events[$v];
2080
2081                                print_debug('For Date',$v);
2082                                print_debug('Count of items',count($daily));
2083
2084                                // process all events on day $v
2085                                //
2086                                if (is_array($daily)) foreach($daily as $event)
2087                                {
2088                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
2089                                        {
2090                                                $this->bo->set_recur_date($event,$v);
2091                                        }
2092                                        if (!$this->bo->rejected_no_show($event))
2093                                        {
2094                                                $this->planner_process_event($event);
2095                                        }
2096                                }
2097                        }
2098                        $this->planner_pad_rows();
2099                }
2100
2101                function matrixselect()
2102                {
2103                        $datetime = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
2104
2105                        $sb = CreateObject('phpgwapi.sbox');
2106
2107                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2108                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2109                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2110                        $GLOBALS['phpgw']->common->phpgw_header();
2111
2112                        $p = &$GLOBALS['phpgw']->template;
2113                        $p->set_file(
2114                                Array(
2115                                        'mq'            => 'matrix_query.tpl',
2116                                        'form_button'   => 'form_button_script.tpl'
2117                                )
2118                        );
2119                        $p->set_block('mq','matrix_query','matrix_query');
2120                        $p->set_block('mq','list','list');
2121
2122                        $p->set_var(array(
2123                                'title'                 => lang('Daily Matrix View'),
2124                                'th_bg'                 => $this->theme['th_bg'],
2125                                'action_url'    => $this->page('viewmatrix')
2126                        ));
2127
2128// Date
2129                        $var[] = Array(
2130                                'field' =>      lang('Date'),
2131                                'data'  =>      $GLOBALS['phpgw']->common->dateformatorder(
2132                                        $sb->getYears('year',(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y'),(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y')),
2133                                        $sb->getMonthText('month',(int)$GLOBALS['phpgw']->common->show_date($datetime,'n')),
2134                                        $sb->getDays('day',(int)$GLOBALS['phpgw']->common->show_date($datetime,'d'))
2135                                )
2136                        );
2137
2138// View type
2139                        $var[] = Array(
2140                                'field' =>      lang('View'),
2141                                'data'  =>      '<select name="matrixtype">'."\n"
2142                                        . '<option value="free/busy" selected>'.lang('free/busy').'</option>'."\n"
2143                                        . '<option value="weekly">'.lang('Weekly').'</option>'."\n"
2144                                        . '</select>'."\n"
2145                        );
2146
2147// Participants
2148                        $accounts = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,'calendar');
2149                        $users = Array();
2150                        for($i=0;$i<count($accounts);$i++)
2151                        {
2152                                $user = $accounts[$i];
2153                                if(!isset($users[$user]))
2154                                {
2155                                        $users[$user] = $GLOBALS['phpgw']->common->grab_owner_name($user);
2156                                        if($GLOBALS['phpgw']->accounts->get_type($user) == 'g')
2157                                        {
2158                                                $group_members = $GLOBALS['phpgw']->acl->get_ids_for_location($user,1,'phpgw_group');
2159                                                if($group_members != False)
2160                                                {
2161                                                        for($j=0;$j<count($group_members);$j++)
2162                                                        {
2163                                                                if(!isset($users[$group_members[$j]]))
2164                                                                {
2165                                                                        $users[$group_members[$j]] = $GLOBALS['phpgw']->common->grab_owner_name($group_members[$j]);
2166                                                                }
2167                                                        }
2168                                                }
2169                                        }
2170                                }
2171                        }
2172
2173                        $num_users = count($users);
2174
2175                        if ($num_users > 50)
2176                        {
2177                                $size = 15;
2178                        }
2179                        elseif ($num_users > 5)
2180                        {
2181                                $size = 5;
2182                        }
2183                        else
2184                        {
2185                                $size = $num_users;
2186                        }
2187                        $str = '';
2188                        @asort($users);
2189                        @reset($users);
2190                        while ($user = each($users))
2191                        {
2192                                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')
2193                                {
2194                                        $str .= '    <option value="'.$user[0].'">('.$GLOBALS['phpgw']->accounts->get_type($user[0]).') '.$user[1].'</option>'."\n";
2195                                }
2196                        }
2197                        $var[] = Array(
2198                                'field' =>      lang('Participants'),
2199                                'data'  =>      "\n".'   <select name="participants[]" multiple size="'.$size.'">'."\n".$str.'   </select>'."\n"
2200                        );
2201
2202                        for($i=0;$i<count($var);$i++)
2203                        {
2204                                $this->output_template_array($p,'rows','list',$var[$i]);
2205                        }
2206
2207                        $vars = Array(
2208                                'submit_button'         => lang('View'),
2209                                'action_url_button'     => $this->bo->return_to ? $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to) : $this->page(''),
2210                                'action_text_button'    => lang('Cancel'),
2211                                'action_confirm_button' => '',
2212                                'action_extra_field'    => ''
2213                        );
2214
2215                        $p->set_var($vars);
2216                        $p->parse('cancel_button','form_button');
2217                        $p->pparse('out','matrix_query');
2218                }
2219
2220                function viewmatrix()
2221                {
2222                        if ($_POST['cancel'])
2223                        {
2224                                $this->index();
2225                        }
2226                        $participants = $_POST['participants'];
2227                        $parts = Array();
2228                        $acct = CreateObject('phpgwapi.accounts',$this->bo->owner);
2229
2230                        if (is_array($participants))
2231                        {
2232                                foreach($participants as $participant)
2233                                {
2234                                        switch ($GLOBALS['phpgw']->accounts->get_type($participant))
2235                                        {
2236                                                case 'g':
2237                                                        if ($members = $acct->member((int)$participant))
2238                                                        {
2239                                                                foreach($members as $member)
2240                                                                {
2241                                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$member['account_id']))
2242                                                                        {
2243                                                                                $parts[$member['account_id']] = True;
2244                                                                        }
2245                                                                }
2246                                                        }
2247                                                        break;
2248                                                case 'u':
2249                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$participant))
2250                                                        {
2251                                                                $parts[$participant] = 1;
2252                                                        }
2253                                                        break;
2254                                        }
2255                                }
2256                                unset($acct);
2257                        }
2258                        $participants = array_keys($parts);     // get id's as values and a numeric index
2259
2260                        // Defined - into session - who participates
2261                        $GLOBALS['phpgw']->session->appsession("participants", NULL, implode(";", $participants));
2262
2263                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2264                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2265                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2266                        $GLOBALS['phpgw']->common->phpgw_header();
2267
2268                        switch($_POST['matrixtype'])
2269                        {
2270                                case 'free/busy':
2271                                        $freetime = $GLOBALS['phpgw']->datetime->gmtdate(mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year));
2272                                        echo '<br>'.$this->timematrix(
2273                                                Array(
2274                                                        'date'          => $freetime,
2275                                                        'starttime'     => $this->bo->splittime('000000',False),
2276                                                        'endtime'       => 0,
2277                                                        'participants'  => $parts
2278                                                )
2279                                        );
2280                                        break;
2281                                case 'weekly':
2282                                        echo '<br>'.$this->display_weekly(
2283                                                Array(
2284                                                        'date'          => sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day),
2285                                                        'showyear'      => true,
2286                                                        'owners'        => $participants
2287                                                )
2288                                        );
2289                                        break;
2290                        }
2291                        echo "\n<br>\n".'<form action="'.$this->page('viewmatrix').'" method="post" name="matrixform">'."\n";
2292                        echo ' <table cellpadding="5"><tr><td>'."\n";
2293                        echo '  <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
2294                        echo '  <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
2295                        echo '  <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
2296                        echo '  <input type="hidden" name="matrixtype" value="'.$_POST['matrixtype'].'">'."\n";
2297                        foreach($participants as $part)
2298                        {
2299                                echo '  <input type="hidden" name="participants[]" value="'.$part.'">'."\n";
2300                        }
2301                        echo '  <input type="submit" name="refresh" value="'.lang('Refresh').'">'."\n";
2302                        echo ' </td><td>'."\n";
2303                        echo '  <input type="submit" name="cancel" value="'.lang('Cancel').'">'."\n";
2304                        echo ' </td></tr></table>'."\n";
2305                        echo '</form>'."\n";
2306                }
2307
2308                function search()
2309                {
2310                        if (empty($_POST['keywords']))
2311                        {
2312                                // If we reach this, it is because they didn't search for anything
2313                                // or they used one of the selectboxes (year, month, week) in the search-result
2314                                // attempt to send them back to where they came from.
2315
2316                                $vars['menuaction'] = isset($_POST['from']) && $_POST['from'] != 'calendar.uicalendar.search' ?
2317                                        $_POST['from'] : 'calendar.uicalendar.index';
2318
2319                                foreach(array('date','year','month','day') as $field)
2320                                {
2321                                        if (isset($_POST[$field]))
2322                                        {
2323                                                $vars[$field] = $_POST[$field];
2324                                        }
2325                                }
2326                                $GLOBALS['phpgw']->redirect_link('/index.php',$vars);
2327                        }
2328
2329                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2330                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2331                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Search Results');
2332                        $GLOBALS['phpgw']->common->phpgw_header();
2333
2334                        $error = '';
2335
2336                        $matches = 0;
2337
2338                        // There is currently a problem searching in with repeated events.
2339                        // It spits back out the date it was entered.  I would like to to say that
2340                        // it is a repeated event.
2341
2342                        // This has been solved by the little icon indicator for recurring events.
2343
2344                        $event_ids = $this->bo->search_keywords($_POST['keywords']);
2345                        foreach($event_ids as $key => $id)
2346                        {
2347                                $event = $this->bo->read_entry($id);
2348
2349                                if(!$this->bo->check_perms(PHPGW_ACL_READ,$event))
2350                                {
2351                                        continue;
2352                                }
2353
2354                                $datetime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2355
2356                                $info[strval($event['id'])] = array(
2357                                        'tr_color'      => $GLOBALS['phpgw']->nextmatchs->alternate_row_color(),
2358                                        'date'          => $GLOBALS['phpgw']->common->show_date($datetime),
2359                                        'link'          => $this->link_to_entry($event,$event['start']['month'],$event['start']['mday'],$event['start']['year'])
2360                                );
2361
2362                        }
2363                        $matches = count($event_ids);
2364
2365                        if ($matches == 1)
2366                        {
2367                                $quantity = lang('1 match found').'.';
2368                        }
2369                        elseif ($matches > 0)
2370                        {
2371                                $quantity = lang('%1 matches found',$matches).'.';
2372                        }
2373                        else
2374                        {
2375                                echo '<b>'.lang('Error').':</b>'.lang('no matches found');
2376                                return;
2377                        }
2378
2379                        $p = $GLOBALS['phpgw']->template;
2380                        $p->set_file(
2381                                Array(
2382                                        'search_form'   => 'search.tpl'
2383                                )
2384                        );
2385                        $p->set_block('search_form','search','search');
2386                        $p->set_block('search_form','search_list_header','search_list_header');
2387                        $p->set_block('search_form','search_list','search_list');
2388                        $p->set_block('search_form','search_list_footer','search_list_footer');
2389
2390                        $var = Array(
2391                                'th_bg'         => $this->theme['th_bg'],
2392                                'search_text'   => lang('Search Results'),
2393                                'quantity'      => $quantity
2394                        );
2395                        $p->set_var($var);
2396
2397                        if($matches > 0)
2398                        {
2399                                $p->parse('rows','search_list_header',True);
2400                        }
2401                        foreach($info as $id => $data)
2402                        {
2403                                $p->set_var($data);
2404                                $p->parse('rows','search_list',True);
2405                        }
2406
2407                        if($matches > 0)
2408                        {
2409                                $p->parse('rows','search_list_footer',True);
2410                        }
2411
2412                        $p->pparse('out','search');
2413                }
2414
2415                /* Private functions */
2416                function _debug_sqsof()
2417                {
2418                        $data = array(
2419                                'filter'     => $this->bo->filter,
2420                                'cat_id'     => $this->bo->cat_id,
2421                                'owner'      => $this->bo->owner,
2422                                'year'       => $this->bo->year,
2423                                'month'      => $this->bo->month,
2424                                'day'        => $this->bo->day,
2425                                'sortby'     => $this->bo->sortby,
2426                                'num_months' => $this->bo->num_months
2427                        );
2428                        Return _debug_array($data,False);
2429                }
2430
2431                function output_template_array(&$p,$row,$list,$var)
2432                {
2433                        if (!isset($var['hidden_vars']))
2434                        {
2435                                $var['hidden_vars'] = '';
2436                        }
2437                        if (!isset($var['tr_color']))
2438                        {
2439                                $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color();
2440                        }
2441                        $p->set_var($var);
2442                        $p->parse($row,$list,True);
2443                }
2444
2445                function page($_page='',$params='')
2446                {
2447                        if($_page == '')
2448                        {
2449                                $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']);
2450                                $_page = $page_[0];
2451
2452                                if ($_page=='planner_cat' || $_page=='planner_user')
2453                                {
2454                                        $_page = 'planner';
2455                                }
2456                                elseif ($_page=='index' || ($_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner'))
2457                                {
2458                                        $_page = 'month';
2459                                        $GLOBALS['phpgw']->preferences->add('calendar','defaultcalendar','month');
2460                                        $GLOBALS['phpgw']->preferences->save_repository();
2461                                }
2462                        }
2463                        if($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' ||
2464                                strstr($GLOBALS['phpgw_info']['flags']['currentapp'],'mail'))   // email, felamimail, ...
2465                        {
2466                                $page_app = 'calendar';
2467                        }
2468                        else
2469                        {
2470                                $page_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
2471                        }
2472                        if (is_array($params))
2473                        {
2474                                $params['menuaction'] = $page_app.'.ui'.$page_app.'.'.$_page;
2475                        }
2476                        else
2477                        {
2478                                $params = 'menuaction='.$page_app.'.ui'.$page_app.'.'.$_page.$params;
2479                        }
2480                        return $GLOBALS['phpgw']->link('/index.php',$params);
2481                }
2482
2483                function header()
2484                {
2485                        $cols = 8;
2486                        if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True)
2487                        {
2488                                $cols++;
2489                        }
2490
2491                        $tpl = $GLOBALS['phpgw']->template;
2492                        $tpl->set_unknowns('remove');
2493
2494                        if (!file_exists($file = $this->template_dir.'/header.inc.php'))
2495                        {
2496                                $file = PHPGW_SERVER_ROOT . '/calendar/templates/default/header.inc.php';
2497                        }
2498                        include($file);
2499                        $header = $tpl->fp('out','head');
2500                        unset($tpl);
2501                        echo $header;
2502                }
2503
2504                function footer()
2505                {
2506                        $menuaction = $_GET['menuaction'];
2507                        list(,,$method) = explode('.',$menuaction);
2508
2509                        if (@$this->bo->printer_friendly)
2510                        {
2511                                return;
2512                        }
2513
2514                        $p = $GLOBALS['phpgw']->template;
2515
2516                        $p->set_file(
2517                                Array(
2518                                        'footer'        => 'footer.tpl',
2519                                        'form_button'   => 'form_button_script.tpl'
2520                                )
2521                        );
2522                        $p->set_block('footer','footer_table','footer_table');
2523                        $p->set_block('footer','footer_row','footer_row');
2524                        $p->set_block('footer','blank_row','blank_row');
2525
2526                        $m = $this->bo->month;
2527                        $y = $this->bo->year;
2528
2529                        $thisdate = date('Ymd',mktime(0,0,0,$m,1,$y));
2530                        $y--;
2531
2532                        $str = '';
2533                        for ($i = 0; $i < 25; $i++)
2534                        {
2535                                $m++;
2536                                if ($m > 12)
2537                                {
2538                                        $m = 1;
2539                                        $y++;
2540                                }
2541                                $d = mktime(0,0,0,$m,1,$y);
2542                                $d_ymd = date('Ymd',$d);
2543                                $str .= '<option value="'.$d_ymd.'"'.($d_ymd == $thisdate?' selected':'').'>'.lang(date('F', $d)).strftime(' %Y', $d).'</option>'."\n";
2544                        }
2545
2546                        $var = Array(
2547                                'action_url'    => $this->page($method,''),
2548                                'form_name'     => 'SelectMonth',
2549                                'label'         => lang('Month'),
2550                                'form_label'    => 'date',
2551                                'form_onchange' => 'document.SelectMonth.submit()',
2552                                'row'           => $str,
2553                                'go'            => lang('Go!')
2554                        );
2555                        $this->output_template_array($p,'table_row','footer_row',$var);
2556
2557                        if($menuaction == 'calendar.uicalendar.week')
2558                        {
2559                                unset($thisdate);
2560                                $thisdate = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
2561                                $sun = $GLOBALS['phpgw']->datetime->get_weekday_start($this->bo->year,$this->bo->month,$this->bo->day) - $GLOBALS['phpgw']->datetime->tz_offset;
2562
2563                                $str = '';
2564                                for ($i = -7; $i <= 7; $i++)
2565                                {
2566                                        $begin = $sun + (7*24*60*60 * $i) + 12*60*60;   // we use midday, that changes in daylight-saveing does not effect us
2567                                        $end = $begin + 6*24*60*60;
2568//                                      echo "<br>$i: ".date('d.m.Y H:i',$begin).' - '.date('d.m.Y H:i',$end);
2569                    $str .= '<option value="' . $GLOBALS['phpgw']->common->show_date($begin,'Ymd') . '"'.($begin <= $thisdate+12*60*60 && $end >= $thisdate+12*60*60 ? ' selected':'').'>'                   
2570                                                . $GLOBALS['phpgw']->common->show_date($begin,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) . ' - '
2571                        . $GLOBALS['phpgw']->common->show_date($end,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
2572                        . '</option>' . "\n";                       
2573                                }
2574
2575                                $var = Array(
2576                                        'action_url'    => $this->page($method,''),
2577                                        'form_name'     => 'SelectWeek',
2578                                        'label'         => lang('Week'),
2579                                        'form_label'    => 'date',
2580                                        'form_onchange' => 'document.SelectWeek.submit()',
2581                                        'row'           => $str,
2582                                        'go'            => lang('Go!')
2583                                );
2584
2585                                $this->output_template_array($p,'table_row','footer_row',$var);
2586                        }
2587
2588                        $str = '';
2589                        for ($i = ($this->bo->year - 3); $i < ($this->bo->year + 3); $i++)
2590                        {
2591                                $str .= '<option value="'.$i.'"'.($i == $this->bo->year?' selected':'').'>'.$i.'</option>'."\n";
2592                        }
2593
2594                        $var = Array(
2595                                'action_url'    => $this->page($method,''),
2596                                'form_name'     => 'SelectYear',
2597                                'label'         => lang('Year'),
2598                                'form_label'    => 'year',
2599                                'form_onchange' => 'document.SelectYear.submit()',
2600                                'row'           => $str,
2601                                'go'            => lang('Go!')
2602                        );
2603                        $this->output_template_array($p,'table_row','footer_row',$var);
2604
2605                        if($menuaction == 'calendar.uicalendar.planner')
2606                        {
2607                                $str = '';
2608                                $date_str = '';
2609
2610                                if(isset($_GET['date']) && $_GET['date'])
2611                                {
2612                                        $date_str .= '    <input type="hidden" name="date" value="'.$_GET['date'].'">'."\n";
2613                                }
2614                                $date_str .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
2615                                $date_str .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
2616                                $date_str .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
2617
2618                                for($i=1; $i<=6; $i++)
2619                                {
2620                                        $str .= '<option value="'.$i.'"'.($i == $this->bo->num_months?' selected':'').'>'.$i.'</option>'."\n";
2621                                }
2622
2623                                $var = Array(
2624                                        'action_url'    => $this->page($method,''),
2625                                        'form_name'     => 'SelectNumberOfMonths',
2626                                        'label'         => lang('Number of Months'),
2627                                        'hidden_vars' => $date_str,
2628                                        'form_label'    => 'num_months',
2629                                        'form_onchange' => 'document.SelectNumberOfMonths.submit()',
2630                                        'action_extra_field'    => $date_str,
2631                                        'row'           => $str,
2632                                        'go'            => lang('Go!')
2633                                );
2634                                $this->output_template_array($p,'table_row','footer_row',$var);
2635                        }
2636
2637                        $var = Array(
2638                                'submit_button'         => lang('Submit'),
2639                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uiicalendar.import'),
2640                                'action_text_button'    => lang('Import'),
2641                                'action_confirm_button' => '',
2642                                'action_extra_field'    => ''
2643                        );
2644                        $this->output_template_array($p,'b_row','form_button',$var);
2645                        $p->parse('table_row','blank_row',True);
2646
2647                        $p->pparse('out','footer_table');
2648                        unset($p);
2649                }
2650
2651                function css()
2652                {
2653                        $GLOBALS['phpgw']->browser->browser();
2654                        if($GLOBALS['phpgw']->browser->get_agent() == 'MOZILLA')
2655                        {
2656                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?12:8);
2657                        }
2658                        else
2659                        {
2660                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?10:7);
2661                        }
2662
2663// moved to app.css in templates/default for future separation of code and style [NDEE 10.03.04]
2664/*
2665                         return 'A.minicalendar { color: #000000; font-size: 72%; font-family: '.$this->theme['font'].' }'."\n"
2666                                . '  A.bminicalendar { color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2667                                . '  A.minicalendargrey { color: #999999; font-size: 8px; font-family: '.$this->theme['font'].' }'."\n"
2668                                . '  A.bminicalendargrey { color: #336699; font-style: italic; font-size:8px; font-family '.$this->theme['font'].' }'."\n"
2669                                . '  A.minicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #000000; font: x-small '.$this->theme['font'].' }'."\n"
2670                                . '  A.bminicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2671                                . '  A.minicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: x-small '.$this->theme['font'].' }'."\n"
2672                                . '  A.bminicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: italic bold x-small '.$this->theme['font'].' }'."\n"
2673                                . '  .event-on { background: '.$this->theme['row_on'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2674                                . '  .event-off { background: '.$this->theme['row_off'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2675                                . '  .event-holiday { background: '.$this->theme['bg04'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
2676                                . '  .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"
2677                                . '  .tablecell { width: 80px; height: 80px }'."\n"
2678                                . '  .planner-cell { cursor:pointer; cursor:hand; border: thin solid black; }';
2679*/
2680                }
2681
2682                function no_edit()
2683                {
2684                        if(!isset($GLOBALS['phpgw_info']['flags']['noheader']))
2685                        {
2686                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
2687                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2688                                $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
2689                                $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
2690                                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Permission denied');
2691                                $GLOBALS['phpgw']->common->phpgw_header();
2692                        }
2693                        echo '<center>You do not have permission to edit this appointment!</center>';
2694                        return;
2695                }
2696
2697                function link_to_entry($event,$month,$day,$year)
2698                {
2699                        $str = '';
2700                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
2701                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
2702
2703                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2704                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
2705                        $rawdate = mktime(0,0,0,$month,$day,$year);
2706                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
2707                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
2708                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
2709                        {
2710                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
2711                        }
2712                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
2713                        {
2714                                $time = '[ '.lang('All Day').' ]';
2715                        }
2716                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
2717                        {
2718                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
2719                                {
2720                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
2721                                }
2722                                else
2723                                {
2724                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
2725                                }
2726
2727                                if($endtime >= ($rawdate_offset + 86400))
2728                                {
2729                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
2730                                }
2731                                else
2732                                {
2733                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
2734                                }
2735                                $time = $start_time.'-'.$end_time;
2736                        }
2737                        else
2738                        {
2739                                $time = '';
2740                        }
2741                       
2742                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
2743
2744                       
2745                       
2746                        if(!$is_private)
2747                        {
2748                                //$text .= $this->bo->display_status($event['users_status']);
2749                               
2750                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
2751                                $textstatus=$this->bo->display_status($event['users_status']);
2752                               
2753                        }
2754
2755                        /*
2756                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
2757                                (!$is_private && $event['description'] ? ': <i>'.$this->bo->get_short_field($event,$is_private,'description').'</i>':'').
2758                                $GLOBALS['phpgw']->browser->br;
2759                        */
2760                       
2761                        $texttime=$time;
2762                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
2763                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
2764                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
2765                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
2766
2767                        if ($viewable)
2768                        {
2769                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
2770                                $this->link_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
2771                                $this->link_tpl->set_var('lang_view',lang('View this entry'));
2772                                $this->link_tpl->set_var('desc', $textdesc);
2773                                $this->link_tpl->set_var('location', $textlocation);
2774                                $this->link_tpl->parse('picture','link_open',True);
2775                        }
2776                        if (!$is_private)
2777                        {
2778                                if($event['priority'] == 3)
2779                                {
2780                                        $picture[] = Array(
2781                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
2782                                                'width' => 16,
2783                                                'height'=> 16,
2784                                                'title' => lang('high priority')
2785                                        );
2786                                }
2787                                if($event['recur_type'] == MCAL_RECUR_NONE)
2788                                {
2789                                        $picture[] = Array(
2790                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
2791                                                'width' => 9,
2792                                                'height'=> 9,
2793                                                'title' => lang('single event')
2794                                        );
2795                                }
2796                                else
2797                                {
2798                                        $picture[] = Array(
2799                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
2800                                                'width' => 12,
2801                                                'height'=> 12,
2802                                                'title' => lang('recurring event')
2803                                        );
2804                                }
2805                        }
2806                        $participants = $this->planner_participants($event['participants']);
2807                        if(count($event['participants']) > 1)
2808                        {
2809                                $picture[] = Array(
2810                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
2811                                        'width' => 14,
2812                                        'height'=> 14,
2813                                        'title' => $participants
2814                                );
2815                        }
2816                        else
2817                        {
2818                                $picture[] = Array(
2819                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
2820                                        'width' => 14,
2821                                        'height'=> 14,
2822                                        'title' => $participants
2823                                );
2824                        }
2825                        if($event['public'] == 0)
2826                        {
2827                                $picture[] = Array(
2828                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
2829                                        'width' => 13,
2830                                        'height'=> 13,
2831                                        'title' => lang('private')
2832                                );
2833                        }
2834                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
2835                        {
2836                                // if the alarm is to go off the day before the event
2837                                // the icon does not show up because of 'alarm_today'
2838                                // - TOM
2839                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
2840                                {
2841                                        $picture[] = Array(
2842                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
2843                                                'width' => 13,
2844                                                'height'=> 13,
2845                                                'title' => lang('alarm')
2846                                        );
2847                                }
2848                        }
2849
2850                        $description = $this->bo->get_short_field($event,$is_private,'description');
2851                        for($i=0;$i<count($picture);$i++)
2852                        {
2853                                $var = Array(
2854                                        'pic_image' => $picture[$i]['pict'],
2855                                        'width'     => $picture[$i]['width'],
2856                                        'height'    => $picture[$i]['height'],
2857                                        'title'     => $picture[$i]['title']
2858                                );
2859                                $this->output_template_array($this->link_tpl,'picture','pict',$var);
2860                        }
2861                        if ($texttitle)
2862                        {
2863                                $var = Array(
2864                        //              'text' => $text,
2865                                        'time'=> $texttime,
2866                                        'title'=> $texttitle,
2867                                        'users_status'=>$textstatus,
2868                                        'desc'=> $textdesc,
2869                                        'location'=> "<br><b>Local:</b> ".$textlocation
2870                                );
2871                                $this->output_template_array($this->link_tpl,'picture','link_text',$var);
2872                        }
2873
2874                        if ($viewable)
2875                        {
2876                                $this->link_tpl->parse('picture','link_close',True);
2877                        }
2878                        $str = $this->link_tpl->fp('out','link_pict');
2879                        $this->link_tpl->set_var('picture','');
2880                        $this->link_tpl->set_var('out','');
2881//                      unset($p);
2882                        return $str;
2883                }
2884
2885                function overlap($params)
2886                {
2887                        if(!is_array($params))
2888                        {
2889                        }
2890                        else
2891                        {
2892                                $overlapping_events = $params['o_events'];
2893                                $event = $params['this_event'];
2894                        }
2895
2896                        $month = $event['start']['month'];
2897                        $mday = $event['start']['mday'];
2898                        $year = $event['start']['year'];
2899
2900                        $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
2901                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
2902
2903                        $overlap = '';
2904                        for($i=0;$i<count($overlapping_events);$i++)
2905                        {
2906                                $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True);
2907                                $overlap .= '<li>'.$this->link_to_entry($overlapped_event,$month,$mday,$year);
2908                                $overlap .= '<ul>';
2909                                foreach($overlapped_event['participants'] as $id => $status)
2910                                {
2911                                        $conflict = isset($event['participants'][$id]);
2912                                        $overlap .= '<li>'.($conflict?'<b>':'').
2913                                                $GLOBALS['phpgw']->common->grab_owner_name($id).
2914                                                ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>\n";
2915                                }
2916                                $overlap .= "</ul>\n";
2917                        }
2918
2919                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2920                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2921                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
2922                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
2923                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict');
2924                        $GLOBALS['phpgw']->common->phpgw_header();
2925
2926                        $p = $GLOBALS['phpgw']->template;
2927                        $p->set_file(
2928                                Array(
2929                                        'overlap'       => 'overlap.tpl',
2930                                        'form_button'   => 'form_button_script.tpl'
2931                                )
2932                        );
2933
2934                        $var = Array(
2935                                'color'         => $this->theme['bg_text'],
2936                                'overlap_title' => lang('Scheduling Conflict'),
2937                                '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)),
2938                                'overlap_list'  => $overlap
2939                        );
2940                        $p->set_var($var);
2941
2942                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday);
2943                        $var = Array(
2944                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update','readsess'=>1)),
2945                                'action_text_button'    => lang('Ignore Conflict'),
2946                                'action_confirm_button' => '',
2947                                'action_extra_field'    => ''
2948                        );
2949                        $this->output_template_array($p,'resubmit_button','form_button',$var);
2950
2951                        $var = Array(
2952                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.edit','readsess'=>1,'date'=>$date)),
2953                                'action_text_button'    => lang('Re-Edit Event'),
2954                                'action_confirm_button' => '',
2955                                'action_extra_field'    => ''
2956                        );
2957                        $this->output_template_array($p,'reedit_button','form_button',$var);
2958                        $p->pparse('out','overlap');
2959                }
2960
2961                function planner_participants($parts)
2962                {
2963                        static $id2lid;
2964
2965                        $names = '';
2966                        while (list($id,$status) = each($parts))
2967                        {
2968                                $status = substr($this->bo->get_long_status($status),0,1);
2969
2970                                if (!isset($id2lid[$id]))
2971                                {
2972                                        $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id);
2973                                }
2974                                if (strlen($names))
2975                                {
2976                                        $names .= ",\n";
2977                                }
2978                                $names .= $id2lid[$id]." ($status)";
2979                        }
2980                        if($this->debug)
2981                        {
2982                                echo '<!-- Inside participants() : '.$names.' -->'."\n";
2983                        }
2984                        return $names;
2985                }
2986
2987                function planner_category($ids)
2988                {
2989                        static $cats;
2990                        if(!is_array($ids))
2991                        {
2992                                if (strpos($ids,','))
2993                                {
2994                                        $id_array = explode(',',$ids);
2995                                }
2996                                else
2997                                {
2998                                        $id_array[0] = $ids;
2999                                }
3000                        }
3001                        @reset($id_array);
3002                        $ret_val = Array();
3003                        while(list($index,$id) = each($id_array))
3004                        {
3005                                if (!isset($cats[$id]))
3006                                {
3007                                        $cat_arr = $this->cat->return_single( $id );
3008                                        $cats[$id] = $cat_arr[0];
3009                                        $cats[$id]['color'] = strstr($cats[$id]['description'],'#');
3010                                }
3011                                $ret_val[] = $cats[$id];
3012                        }
3013                        return $ret_val;
3014                }
3015
3016                function week_header($month,$year,$display_name = False)
3017                {
3018                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3019
3020                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3021                        $p->set_unknowns('remove');
3022                        $p->set_file(
3023                                Array (
3024                                        'month_header' => 'month_header.tpl'
3025                                )
3026                        );
3027                        $p->set_block('month_header','monthly_header','monthly_header');
3028                        $p->set_block('month_header','column_title','column_title');
3029
3030                        $var = Array(
3031                                'bgcolor'       => $this->theme['th_bg'],
3032                                'font_color'    => $this->theme['th_text']
3033                        );
3034                        if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
3035                        {
3036                                $var = Array(
3037                                        'bgcolor'       => '',
3038                                        'font_color'    => ''
3039                                );
3040                        }
3041                        $p->set_var($var);
3042
3043                        $p->set_var('col_width','14');
3044                        if($display_name == True)
3045                        {
3046                                $p->set_var('col_title',lang('name'));
3047                                $p->parse('column_header','column_title',True);
3048                                $p->set_var('col_width','12');
3049                        }
3050
3051                        for($i=0;$i<7;$i++)
3052                        {
3053                                $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
3054                                $p->parse('column_header','column_title',True);
3055                        }
3056                        return $p->fp('out','monthly_header');
3057                }
3058
3059                function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3060                {
3061                        if($owner == 0)
3062                        {
3063                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3064                        }
3065
3066                        $temp_owner = $this->bo->owner;
3067
3068                        $str = '';
3069                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3070                        $p->set_unknowns('keep');
3071
3072                        $p->set_file(
3073                                Array(
3074                                        'month_header'  => 'month_header.tpl',
3075                                        'month_day'     => 'month_day.tpl'
3076                                )
3077                        );
3078                        $p->set_block('month_header','monthly_header','monthly_header');
3079                        $p->set_block('month_header','month_column','month_column');
3080                        $p->set_block('month_day','month_daily','month_daily');
3081                        $p->set_block('month_day','day_event','day_event');
3082                        $p->set_block('month_day','event','event');
3083
3084                        $p->set_var('extra','');
3085                        $p->set_var('col_width','14');
3086                        if($display_name)
3087                        {
3088                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
3089                                $p->parse('column_header','month_column',True);
3090                                $p->set_var('col_width','12');
3091                        }
3092                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3093                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3094                        foreach($daily as $date => $day_params)
3095                        {
3096                                $year  = (int)substr($date,0,4);
3097                                $month = (int)substr($date,4,2);
3098                                $day   = (int)substr($date,6,2);
3099                                $var   = Array(
3100                                        'column_data' => '',
3101                                        'extra' => ''
3102                                );
3103                                $p->set_var($var);
3104                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
3105                                {
3106                                        if ($day_params['new_event'])
3107                                        {
3108                                                $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
3109                                                        . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
3110                                                        . '</a>';
3111                                                $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
3112                                        }
3113                                        else
3114                                        {
3115                                                $new_event_link = '';
3116                                                $day_number = $day;
3117                                        }
3118
3119                                        $var = Array(
3120                                                'extra'         => $day_params['extra'],
3121                                                'new_event_link'=> $new_event_link,
3122                                                'day_number'    => $day_number
3123                                        );
3124                                        if($day_params['week'])
3125                                        {
3126
3127//NDEE: style! m_w_table in month_day.tpl
3128// week-hilite
3129                                                //$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
3130                                                $var['new_event_link'] .= ' &nbsp; '.
3131                                                        (!$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>');
3132                                        }
3133
3134                                        $p->set_var($var);
3135
3136                                        if(@$day_params['holidays'])
3137                                        {
3138                                                foreach($day_params['holidays'] as $key => $value)
3139                                                {
3140                                                        $var = Array(
3141                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
3142                                                        );
3143                                                        $this->output_template_array($p,'daily_events','event',$var);
3144                                                }
3145                                        }
3146
3147                                        if($day_params['appts'])
3148                                        {
3149                                                $var = Array(
3150                                                        'week_day_font_size'    => '2',
3151                                                        'events'                => ''
3152                                                );
3153                                                $p->set_var($var);
3154                                                $events = $this->bo->cached_events[$date];
3155                                                foreach($events as $event)
3156                                                {
3157                                                        if ($this->bo->rejected_no_show($event))
3158                                                        {
3159                                                                continue;       // user does not want to see rejected events
3160                                                        }
3161                                                        $p->set_var('day_events',$this->link_to_entry($event,$month,$day,$year));
3162                                                        $p->parse('events','event',True);
3163                                                        $p->set_var('day_events','');
3164                                                }
3165                                        }
3166                                        $p->parse('daily_events','day_event',True);
3167                                        $p->parse('column_data','month_daily',True);
3168                                        $p->set_var('daily_events','');
3169                                        $p->set_var('events','');
3170/*                                      if($day_params['week'])
3171                                        {
3172                                                $var = Array(
3173                                                        'week_day_font_size'    => '-2',
3174                                                        'events'                => (!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'">' .$day_params['week'].'</a>':$day_params['week'])
3175                                                );
3176                                                $this->output_template_array($p,'column_data','day_event',$var);
3177                                                $p->set_var('events','');
3178                                        } */
3179                                }
3180                                $p->parse('column_header','month_column',True);
3181                                $p->set_var('column_data','');
3182                        }
3183                        $this->bo->owner = $temp_owner;
3184                        return $p->fp('out','monthly_header');
3185                }
3186
3187                function display_month($month,$year,$showyear,$owner=0)
3188                {
3189                        if($this->debug)
3190                        {
3191                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
3192                        }
3193
3194                        $this->bo->store_to_cache(
3195                                Array(
3196                                        'syear' => $year,
3197                                        'smonth'=> $month,
3198                                        'sday'  => 1
3199                                )
3200                        );
3201
3202                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
3203                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
3204
3205                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
3206
3207                        if($this->debug)
3208                        {
3209                                echo '<!-- display_month:monthstart = '.$monthstart.' -->'."\n";
3210                                echo '<!-- display_month:start = '.date('Ymd H:i:s',$start).' -->'."\n";
3211                        }
3212
3213                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3214                        $p->set_unknowns('keep');
3215
3216                        $p->set_file(
3217                                Array(
3218                                        'week' => 'month_day.tpl'
3219                                )
3220                        );
3221                        $p->set_block('week','m_w_table','m_w_table');
3222                        $p->set_block('week','event','event');
3223
3224                        $var = Array(
3225                                'cols'      => 7,
3226                                'day_events'=> $this->week_header($month,$year,False)
3227                        );
3228                        $this->output_template_array($p,'row','event',$var);
3229
3230                        $cellcolor = $this->theme['row_on'];
3231
3232                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
3233                        {
3234                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
3235                                $var = Array(
3236                                        'day_events' => $this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
3237                                );
3238                                $this->output_template_array($p,'row','event',$var);
3239                        }
3240                        return $p->fp('out','m_w_table');
3241                }
3242
3243                function display_weekly($params)
3244                {
3245                        if(!is_array($params))
3246                        {
3247                                $this->index();
3248                        }
3249
3250                        $year = substr($params['date'],0,4);
3251                        $month = substr($params['date'],4,2);
3252                        $day = substr($params['date'],6,2);
3253                        $showyear = $params['showyear'];
3254                        $owners = $params['owners'];
3255
3256                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3257                        $p->set_unknowns('keep');
3258
3259                        $p->set_file(
3260                                Array(
3261                                        'week'  => 'month_day.tpl'
3262                                )
3263                        );
3264                        $p->set_block('week','m_w_table','m_w_table');
3265                        $p->set_block('week','event','event');
3266
3267                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
3268
3269                        $cellcolor = $this->theme['row_off'];
3270
3271                        $true_printer_friendly = $this->bo->printer_friendly;
3272
3273                        if(is_array($owners))
3274                        {
3275                                $display_name = True;
3276                                $counter = count($owners);
3277                                $owners_array = $owners;
3278                                $cols = 8;
3279                        }
3280                        else
3281                        {
3282                                $display_name = False;
3283                                $counter = 1;
3284                                $owners_array[0] = $owners;
3285                                $cols = 7;
3286                        }
3287                        $var = Array(
3288                                'cols'         => $cols,
3289                                'day_events'   => $this->week_header($month,$year,$display_name)
3290                        );
3291                        $this->output_template_array($p,'row','event',$var);
3292
3293                        $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
3294                        $tstop = $tstart + 604800;
3295                        $original_owner = $this->bo->so->owner;
3296                        for($i=0;$i<$counter;$i++)
3297                        {
3298                                $this->bo->so->owner = $owners_array[$i];
3299                                $this->bo->so->open_box($owners_array[$i]);
3300                                $this->bo->store_to_cache(
3301                                        Array(
3302                                                'syear'  => date('Y',$tstart),
3303                                                'smonth' => date('m',$tstart),
3304                                                'sday'   => date('d',$tstart),
3305                                                'eyear'  => date('Y',$tstop),
3306                                                'emonth' => date('m',$tstop),
3307                                                'eday'   => date('d',$tstop)
3308                                        )
3309                                );
3310                                $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$owners_array[$i]));
3311                                $p->parse('row','event',True);
3312                        }
3313                        $this->bo->so->owner = $original_owner;
3314                        $this->bo->printer_friendly = $true_printer_friendly;
3315                        return $p->fp('out','m_w_table');
3316                }
3317
3318                function view_event($event,$alarms=False)
3319                {
3320                        if((!$event['participants'][$this->bo->owner] && !$this->bo->check_perms(PHPGW_ACL_READ,$event)))
3321                        {
3322                                return False;
3323                        }
3324
3325                        $p = &$GLOBALS['phpgw']->template;
3326
3327                        $p->set_file(
3328                                Array(
3329                                        'view'  => 'view.tpl'
3330                                )
3331                        );
3332                        $p->set_block('view','view_event','view_event');
3333                        $p->set_block('view','list','list');
3334                        $p->set_block('view','hr','hr');
3335
3336                        $vars = $this->bo->event2array($event);
3337
3338                        $vars['title']['tr_color'] = $this->theme['th_bg'];
3339
3340                        foreach($vars['participants']['data'] as $user => $str)
3341                        {
3342                        if ($this->bo->check_perms(PHPGW_ACL_EDIT,0,$user) && ereg('^(.*) \((.*)\)$',$str,$parts))
3343                                {
3344                                        $vars['participants']['data'][$user] = $parts[1].' (<a href="'.$this->page('edit_status','&cal_id='.$event['id'].'&owner='.$user).'">'.$parts[2].'</a>)';
3345                                }
3346                        }
3347                        $vars['participants']['data'] = implode("<br>\n",$vars['participants']['data']);
3348                        foreach($vars as $var)
3349                        {
3350                                if (strlen($var['data']))
3351                                {
3352                                        $this->output_template_array($p,'row','list',$var);
3353                                }
3354                        }
3355
3356                        if($alarms && count($event['alarm']))
3357                        {
3358                                $p->set_var('th_bg',$this->theme['th_bg']);
3359                                $p->set_var('hr_text',lang('Alarms'));
3360                                $p->parse('row','hr',True);
3361                                foreach($event['alarm'] as $key => $alarm)
3362                                {
3363                                        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
3364                                        {       
3365                                                $icon = '<img src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled':'disabled')).'" width="13" height="13">';
3366                                                $var = Array(
3367                                                        'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']),
3368                                                        'data'  => lang('Email Notification for %1',$GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']))
3369                                                );
3370                                                $this->output_template_array($p,'row','list',$var);
3371                                        }
3372                                }
3373                        }
3374                        return True;
3375                }
3376
3377                function nm_on_off()
3378                {
3379                        if($GLOBALS['phpgw']->nextmatchs->alternate_row_color() == $this->theme['row_on'])
3380                        {
3381                                return '_on';
3382                        }
3383                        return '_off';
3384                }
3385
3386                function slot_num($time,$set_day_start=0,$set_day_end=0)
3387                {
3388                        static $day_start, $day_end, $interval=0;
3389
3390                        if ($set_day_start) $day_start = $set_day_start;
3391                        if ($set_day_end)   $day_end   = $set_day_end;
3392                        if (!$interval)     $interval  = 60*$this->bo->prefs['calendar']['interval'];
3393
3394                        if ($time > $day_end)
3395                        {
3396                                $time = $day_end;
3397                        }
3398                        $slot = (int)(($time - $day_start) / $interval);
3399
3400                        return $slot < 0 ? 0 : 1+$slot;
3401                }
3402
3403                function print_day($params)
3404                {
3405                        if(!is_array($params))
3406                        {
3407                                $this->index();
3408                        }
3409
3410                        print_debug('in print_day()');
3411
3412                        $this->bo->store_to_cache(
3413                                Array(
3414                                        'syear'  => $params['year'],
3415                                        'smonth' => $params['month'],
3416                                        'sday'   => $params['day'],
3417                                        'eyear'  => $params['year'],
3418                                        'emonth' => $params['month'],
3419                                        'eday'   => $params['day']
3420                                )
3421                        );
3422
3423                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3424                        $p->set_unknowns('keep');
3425
3426                        $tpl = 'day_cal.tpl';
3427                        if((int)($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents'])==2 &&
3428                                $GLOBALS['phpgw_info']['flags']['currentapp'] == 'home')
3429                        {
3430                                $tpl = 'day_list.tpl';
3431                        }
3432                        $templates = Array(
3433                                'day_cal'   => $tpl
3434                        );
3435
3436                        $p->set_file($templates);
3437                        $p->set_block('day_cal','day','day');
3438                        $p->set_block('day_cal','day_row','day_row');
3439                        $p->set_block('day_cal','day_event_on','day_event_on');
3440                        $p->set_block('day_cal','day_event_off','day_event_off');
3441                        $p->set_block('day_cal','day_event_holiday','day_event_holiday');
3442                        $p->set_block('day_cal','day_time','day_time');
3443
3444                        $date_to_eval = sprintf("%04d%02d%02d",$params['year'],$params['month'],$params['day']);
3445
3446                        $day_start = mktime((int)($this->bo->prefs['calendar']['workdaystarts']),0,0,$params['month'],$params['day'],$params['year']);
3447                        $day_end = mktime((int)($this->bo->prefs['calendar']['workdayends']),0,1,$params['month'],$params['day'],$params['year']);
3448                        $daily = $this->set_week_array($GLOBALS['phpgw']->datetime->get_weekday_start($params['year'],$params['month'],$params['day']),$this->theme['row_on'],True);
3449                        print_debug('Date to Eval',$date_to_eval);
3450                        $events_to_show = array();
3451                        if($daily[$date_to_eval]['appts'])
3452                        {
3453                                $events = $this->bo->cached_events[$date_to_eval];
3454                                print_debug('Date',$date_to_eval);
3455                                print_debug('Count',count($events));
3456                                foreach($events as $event)
3457                                {
3458                                        if ($this->bo->rejected_no_show($event))
3459                                        {
3460                                                continue;       // user does not want to see rejected events
3461                                        }
3462                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
3463                                        {
3464                                                $this->bo->set_recur_date($event,$date_to_eval);
3465                                        }
3466                                        $events_to_show[] = array(
3467                                                'starttime' => $this->bo->maketime($event['start']),
3468                                                'endtime'   => $this->bo->maketime($event['end']),
3469                                                'content'   => $this->link_to_entry($event,$params['month'],$params['day'],$params['year'])
3470                                        );
3471                                }
3472                        }
3473                        //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
3474                        $other = $GLOBALS['phpgw']->hooks->process(array(
3475                                'location'  => 'calendar_include_events',
3476                                'year'      => $params['year'],
3477                                'month'     => $params['month'],
3478                                'day'       => $params['day'],
3479                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
3480                        ));
3481
3482                        if (is_array($other))
3483                        {
3484                                foreach($other as $evts)
3485                                {
3486                                        if (is_array($evts))
3487                                        {
3488                                                $events_to_show = array_merge($events_to_show,$evts);
3489                                        }
3490                                }
3491                                usort($events_to_show,create_function('$a,$b','return $a[\'starttime\']-$b[\'starttime\'];'));
3492                                //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
3493                        }
3494
3495                        if (count($events_to_show))
3496                        {
3497                                $last_slot_end = -1;
3498                                foreach($events_to_show as $event)
3499                                {
3500                                        $slot = $this->slot_num($event['starttime'],$day_start,$day_end);
3501                                        $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
3502
3503                                        if ($slot <= $last_slot_end)
3504                                        {
3505                                                $slot = $last_slot;
3506                                                $slot_end = max($last_slot_end,$slot_end);
3507                                        }
3508                                        $rows[$slot] .= $event['content'];
3509
3510                                        print_debug('slot',$slot);
3511                                        print_debug('row',$rows[$slot]);
3512
3513                                        $row_span[$slot] = 1 + $slot_end - $slot;
3514
3515                                        $last_slot = $slot;
3516                                        $last_slot_end = $slot_end;
3517                                        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));
3518                                        print_debug('Slot',$slot);
3519                                }
3520                                //echo "rows=<pre>"; print_r($rows); echo "<br>row_span="; print_r($row_span); echo "</pre>\n";
3521                        }
3522                        $holiday_names = $daily[$date_to_eval]['holidays'];
3523                        if(!$holiday_names)
3524                        {
3525                                $row_to_print = $this->nm_on_off();
3526                        }
3527                        else
3528                        {
3529                                $row_to_print = '_holiday';
3530                                foreach($holiday_names as $name)
3531                                {
3532                                        $rows[0] = '<center>'.$name.'</center>' . $rows[0];
3533                                }
3534                        }
3535                        $last_slot = $this->slot_num($day_end,$day_start,$day_end);
3536                        $rowspan = 0;
3537                        for ($slot = 0; $slot <= $last_slot; ++$slot)
3538                        {
3539                                $p->set_var('extras','');
3540                                if ($rowspan > 1)
3541                                {
3542                                        $p->set_var('event','');
3543                                        $rowspan--;
3544                                }
3545                                elseif (!isset($rows[$slot]))
3546                                {
3547                                        $p->set_var('event','&nbsp;');
3548                                        $row_to_print = $this->nm_on_off();
3549                                        $p->parse('event','day_event'.$row_to_print);
3550                                }
3551                                else
3552                                {
3553                                        $rowspan = (int)$row_span[$slot];
3554                                        if ($rowspan > 1)
3555                                        {
3556                                                $p->set_var('extras',' rowspan="'.$rowspan.'"');
3557                                        }
3558                                        $p->set_var('event',$rows[$slot]);
3559                                        $row_to_print = $this->nm_on_off();
3560                                        $p->parse('event','day_event'.$row_to_print);
3561                                }
3562                                $open_link = $close_link = '';
3563                                $time = '&nbsp;';
3564
3565                                if (0 < $slot && $slot < $last_slot)    // normal time-slot not before or after day_start/end
3566                                {
3567                                        $time = $day_start + ($slot-1) * 60 * $this->bo->prefs['calendar']['interval'];
3568                                        $hour = date('H',$time);
3569                                        $min  = date('i',$time);
3570                                        $time = $GLOBALS['phpgw']->common->formattime($hour,$min);
3571
3572                                        if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
3573                                        {
3574                                                $open_link = ' <a href="'.$this->page('add',"&date=$date_to_eval&hour=$hour&minute=$min").'">';
3575                                                $close_link = '</a> ';
3576                                        }
3577                                }
3578                                $p->set_var(Array(
3579                                        'open_link'  => $open_link,
3580                                        'time'       => $time,
3581                                        'close_link' => $close_link,
3582                                        'tr_color'   => ''      // dummy to stop output_template_array to set it
3583                                ));
3584                                $p->parse('time','day_time');
3585
3586                                $p->parse('row','day_row',True);
3587                        }
3588                        return $p->fp('out','day');
3589                }       // end function
3590
3591                function timematrix($param)
3592                {
3593                        if(!is_array($param))
3594                        {
3595                                $this->index();
3596                        }
3597
3598                        $date = $param['date'];
3599                        $starttime = $param['starttime'];
3600                        $endtime = $param['endtime'];
3601                        $participants = $param['participants'];
3602                        foreach($participants as $part => $nul)
3603                        {
3604                                $participants[$part] = $GLOBALS['phpgw']->common->grab_owner_name($part);
3605                                // Much better for processor  :)
3606                                $participants_id[]  .= $part;
3607                        }
3608                        uasort($participants,'strnatcasecmp');  // sort them after their fullname
3609
3610                        if(!isset($this->bo->prefs['calendar']['interval']))
3611                        {
3612                                $this->bo->prefs['calendar']['interval'] = 15;
3613                                $GLOBALS['phpgw']->preferences->add('calendar','interval',15);
3614                                $GLOBALS['phpgw']->preferences->save_repository();
3615                        }
3616                        $increment = $this->bo->prefs['calendar']['interval'];
3617                        $interval = (int)(60 / $increment);
3618
3619                        $pix = $GLOBALS['phpgw']->common->image('calendar','pix');
3620
3621                        $str = '<center>'.lang($GLOBALS['phpgw']->common->show_date($date['raw'],'l'))
3622                                . ', '.$this->bo->long_date($date).'<br>'
3623                                . '<table width="85%" border="0" cellspacing="0" cellpadding="0" cols="'.((24 * $interval) + 1).'">'
3624                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>'
3625                                . '<tr><td width="15%"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.lang('Participant').'</font></td>';
3626                        for($i=0;$i<24;$i++)
3627                        {
3628                                for($j=0;$j<$interval;$j++)
3629                                {
3630                                        $k = ($j == 0 ? sprintf('%02d',$i).'<br>':'').sprintf('%02d',$j*$increment);
3631
3632                                        $str .= '<td align="left" bgcolor="'.$this->theme['bg_color'].'"><font color="'.$phpgw_info['theme']['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'
3633                                                . '<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;\">"
3634                                                . $k."</a>&nbsp;</font></td>\n";
3635                                }
3636                        }
3637                        $str .= '</tr>'
3638                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>';
3639                        if(!$endtime)
3640                        {
3641                                $endtime = $starttime;
3642                        }
3643                        $owner = $this->bo->owner;
3644                        foreach($participants as $part => $fullname)
3645                        {
3646                                $str .= '<tr align="center">'
3647                                        . '<td width="15%" align="left"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$fullname.'</font></td>';
3648
3649                                $this->bo->cached_events = Array();
3650                                $this->bo->so->owner = $part;
3651                                $this->bo->so->open_box($part);
3652                                $this->bo->store_to_cache(
3653                                        Array(
3654                                                'syear' => $date['year'],
3655                                                'smonth'=> $date['month'],
3656                                                'sday'  => $date['day'],
3657                                                'eyear' => 0,
3658                                                'emonth'=> 0,
3659                                                'eday'  => $date['day'] + 1
3660                                        )
3661                                );
3662
3663                                if(!$this->bo->cached_events[$date['full']])
3664                                {
3665                                        for($j=0;$j<24;$j++)
3666                                        {
3667                                                for($k=0;$k<$interval;$k++)
3668                                                {
3669                                                        $str .= '<td height="1" align="left" bgcolor="'.$this->theme['bg_color'].'" color="#999999">&nbsp;</td>';
3670                                                }
3671                                                $str .= "\n";
3672                                        }
3673                                }
3674                                else
3675                                {
3676                                        $time_slice = $this->bo->prepare_matrix($interval,$increment,$part,$date['full']);
3677                                        for($h=0;$h<24;$h++)
3678                                        {
3679                                                $hour = $h * 10000;
3680                                                for($m=0;$m<$interval;$m++)
3681                                                {
3682                                                        $index = ($hour + (($m * $increment) * 100));
3683                                                        switch($time_slice[$index]['marker'])
3684                                                        {
3685                                                                case '&nbsp':
3686                                                                        $time_slice[$index]['color'] = $this->theme['bg_color'];
3687                                                                        $extra = '';
3688                                                                        break;
3689                                                                case '-':
3690                                                                        $time_slice[$index]['color'] = $this->theme['bg01'];
3691                                                                        $link = $this->page('view','&cal_id='.$time_slice[$index]['id'].'&date='.$date['full']);
3692                                                                        $extra =' title="'.$time_slice[$index]['description'].'" onClick="location.href=\''.$link.'\';" style="cursor:pointer; cursor:hand;"';
3693                                                                        break;
3694                                                        }
3695                                                        $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>';
3696                                                }
3697                                                $str .= "\n";
3698                                        }
3699                                }
3700                                $str .= '</tr>'
3701                                        . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="#999999"><img src="'.$pix.'"></td></tr>';
3702                        }
3703                        $this->bo->owner = $owner;
3704                        $this->bo->so->owner = $owner;
3705                        $this->bo->so->open_box($owner);
3706                        return $str.'</table></center>'."\n";
3707                }
3708
3709                function get_response($cal_id)
3710                {
3711                        $p = &$GLOBALS['phpgw']->template;
3712                        $p->set_file(
3713                                Array(
3714                                        'form_button'   => 'form_button_script.tpl'
3715                                )
3716                        );
3717
3718                        $ev = $this->bo->get_cached_event();
3719                        $response_choices = Array(
3720                                ACCEPTED        => lang('Accept'),
3721                                REJECTED        => lang('Reject'),
3722                                TENTATIVE       => lang('Tentative')                           
3723                        );
3724                        $str = '';
3725                        while(list($param,$text) = each($response_choices))
3726                        {
3727                                $var = Array(
3728                                        'action_url_button'     => $this->page('set_action','&cal_id='.$cal_id.'&action='.$param),
3729                                        'action_text_button'    => '  '.$text.'  ',
3730                                        'action_confirm_button' => '',
3731                                        'action_extra_field'    => ''
3732                                );
3733                                $p->set_var($var);
3734                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
3735                        }
3736                        if ($this->bo->return_to)
3737                        {
3738                                $var = Array(
3739                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
3740                                        'action_text_button'    => lang('cancel'),
3741                                        'action_confirm_button' => '',
3742                                        'action_extra_field'    => ''
3743                                );
3744                                $p->set_var($var);
3745                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
3746                        }
3747                        $str = '<td><b>'.$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner).":</b></td>\n".$str;
3748
3749                        return '<table width="100%"><tr align="center">'."\n".$str.'</tr></table>'."\n";
3750                }
3751
3752                function accounts_popup()
3753                {
3754                        $GLOBALS['phpgw']->accounts->accounts_popup('calendar');
3755                       
3756                }
3757
3758                function edit_form($param)
3759                {
3760                        if(!is_array($param))
3761                        {
3762                                $this->index();
3763                        }
3764                       
3765                        if(isset($param['event']))
3766                        {
3767                                $event = $param['event'];
3768                        }
3769                       
3770                        $hourformat = substr($this->bo->users_timeformat,0,1);
3771                       
3772                        // $sb = CreateObject('phpgwapi.sbox');
3773                        $sb = CreateObject('phpgwapi.sbox2');
3774                        $jscal = CreateObject('phpgwapi.jscalendar');   // before phpgw_header() !!!
3775                       
3776                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
3777                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3778                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3779                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3780                        $GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Calendar - Edit') : lang('Calendar - Add');
3781                        $GLOBALS['phpgw']->common->phpgw_header();
3782
3783                        $p = &$GLOBALS['phpgw']->template;
3784                        $p->set_file(
3785                                Array(
3786                                        'edit'          => 'edit.tpl',
3787                                        'form_button'   => 'form_button_script.tpl'
3788                                )
3789                        );
3790                        $p->set_block('edit','edit_entry','edit_entry');
3791                        $p->set_block('edit','list','list');
3792                        $p->set_block('edit','hr','hr');
3793                       
3794                        $vars = Array(
3795                                'font'                  => $this->theme['font'],
3796                                'bg_color'              => $this->theme['bg_text'],
3797                                'action_url'            => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update')),
3798                                'accounts_link'         => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.accounts_popup'),
3799                                'common_hidden' => '<input type="hidden" name="cal[id]" value="'.$event['id'].'">'."\n"
3800                                        . '<input type="hidden" name="cal[owner]" value="'.$event['owner'].'">'."\n"
3801                                        . '<input type="hidden" name="cal[uid]" value="'.$event['uid'].'">'."\n"
3802                                        . ($_GET['cal_id'] && $event['id'] == 0?'<input type="hidden" name="cal[reference]" value="'.$_GET['cal_id'].'">'."\n":
3803                                        (@isset($event['reference'])?'<input type="hidden" name="cal[reference]" value="'.$event['reference'].'">'."\n":''))
3804                                        . (@isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && $GLOBALS['phpgw_info']['server']['deny_user_grants_access']?
3805                                        '<input type="hidden" name="participants[]" value="'.$this->bo->owner.'">'."\n":''),
3806                                'errormsg'              => ($param['cd']?$GLOBALS['phpgw']->common->check_code($param['cd']):'')
3807                        );
3808                       
3809                        $p->set_var($vars);
3810
3811// Brief Description
3812                        $var['title'] = Array(
3813                                'tr_color' => $this->theme['th_bg'],
3814                                'field' => lang('Title'),
3815                                'data'  => '<input name="cal[title]" size="45" maxlength="80" value="'.$event['title'].'">'
3816                        );
3817
3818// Full Description
3819                        $var['description'] = Array(
3820                                'field' => lang('Full Description'),
3821                                'data'  => '<textarea name="cal[description]" rows="5" cols="40" wrap="virtual" maxlength="2048">'.$event['description'].'</textarea>'
3822                        );
3823
3824// Display Categories
3825                        if(strpos($event['category'],','))
3826                        {
3827                                $temp_cats = explode(',',$event['category']);
3828                                @reset($temp_cats);
3829                                while(list($key,$value) = each($temp_cats))
3830                                {
3831                                        $check_cats[] = (int)$value;
3832                                }
3833                        }
3834                        elseif($event['category'])
3835                        {
3836                                $check_cats[] = (int)$event['category'];
3837                        }
3838                        else
3839                        {
3840                                $check_cats[] = 0;
3841                        }
3842                        $var['category'] = Array(
3843                                'field' => lang('Category'),
3844                                'data'  => '<select name="categories[]" multiple size="5">'.$this->cat->formated_list('select','all',$check_cats,True).'</select>'
3845                        );
3846
3847// Location
3848                        $var['location'] = Array(
3849                                'field' => lang('Location'),
3850                                'data'  => '<input name="cal[location]" size="45" maxlength="255" value="'.$event['location'].'">'
3851                        );
3852
3853// Date
3854
3855                        $start = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
3856                        $var['startdate'] = Array(
3857                                'field' => lang('Start Date'),
3858/*
3859                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
3860                                   $sb->getYears('start[year]',(int)$GLOBALS['phpgw']->common->show_date($start,'Y')),
3861                                   $sb->getMonthText('start[month]',(int)$GLOBALS['phpgw']->common->show_date($start,'n')),
3862                                   $sb->getDays('start[mday]',(int)$GLOBALS['phpgw']->common->show_date($start,'d'))
3863                                )
3864*/
3865                                'data' => $jscal->input('start[str]',$start)
3866                        );
3867
3868// Time
3869                        if ($this->bo->prefs['common']['timeformat'] == '12')
3870                        {
3871                                $str .= '<input type="radio" name="start[ampm]" value="am"'.($event['start']['hour'] >= 12?'':' checked').'>am'."\n"
3872                                        . '<input type="radio" name="start[ampm]" value="pm"'.($event['start']['hour'] >= 12?' checked':'').'>pm'."\n";
3873                        }
3874                        $var['starttime'] = Array(
3875                                'field' => lang('Start Time'),
3876                                '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
3877                        );
3878
3879// End Date
3880                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3881                        $var['enddate'] = Array(
3882                                'field' => lang('End Date'),
3883/*
3884                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
3885                                   $sb->getYears('end[year]',(int)$GLOBALS['phpgw']->common->show_date($end,'Y')),
3886                                   $sb->getMonthText('end[month]',(int)$GLOBALS['phpgw']->common->show_date($end,'n')),
3887                                   $sb->getDays('end[mday]',(int)$GLOBALS['phpgw']->common->show_date($end,'d'))
3888                                )
3889*/
3890                                'data' => $jscal->input('end[str]',$end)
3891                        );
3892
3893// End Time
3894                        if ($this->bo->prefs['common']['timeformat'] == '12')
3895                        {
3896                                $str = '<input type="radio" name="end[ampm]" value="am"'.($event['end']['hour'] >= 12?'':' checked').'>am'."\n"
3897                                        . '<input type="radio" name="end[ampm]" value="pm"'.($event['end']['hour'] >= 12?' checked':'').'>pm'."\n";
3898                        }
3899                        $var['endtime'] = Array(
3900                                'field' => lang('End Time'),
3901                                '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
3902                        );
3903
3904// Priority
3905                        $var['priority'] = Array(
3906                                'field' => lang('Priority'),
3907                                'data'  => $sb->getPriority('cal[priority]',$event['priority'])
3908                        );
3909
3910// Access
3911                        $var['access'] = Array(
3912                                'field' => lang('Private'),
3913                                'data'  => '<input type="checkbox" name="cal[private]" value="private"'.(!$event['public']?' checked':'').'>'
3914                        );
3915
3916// Participants
3917                        if(!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access'])
3918                        {
3919                                switch($GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection'])
3920                                {
3921                                        case 'popup':
3922                                                while (is_array($event['participants']) && list($id) = each($event['participants']))
3923                                                {
3924                                                        if($id != (int)$event['owner'])
3925                                                        {
3926                                                                $str .= '<option value="' . $id.$event['participants'][$id] . '"'.($event['participants'][$id]?' selected':'').'>('.$GLOBALS['phpgw']->accounts->get_type($id)
3927                                                                                .') ' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '</option>' . "\n";
3928                                                        }
3929                                                }
3930                                                $var['participants'] = array
3931                                                (
3932                                                        'field' => '<input type="button" value="' . lang('Participants') . '" onClick="accounts_popup();">' . "\n"
3933                                                                        . '<input type="hidden" name="accountid" value="' . $accountid . '">',
3934                                                        'data'  => "\n".'   <select name="participants[]" multiple size="7">' . "\n" . $str . '</select>'
3935                                                );
3936                                                break;
3937                                        default:
3938                                                foreach($event['participants'] as $id => $participant)
3939                                                {
3940                                                        if (($id != $event['owner']) && ($id != ""))
3941                                                        {
3942                                                                $GLOBALS['phpgw']->accounts->get_account_name($id, $lid, $fname, $lname);
3943                                                                $cn = $fname.' '.$lname;                                                       
3944                                                                $option = '    <option  value="' . $id.$participant . '">'.$cn.'</option>'."\n";
3945                                                                $str .= $option;
3946                                                        }                                                               
3947                                                }
3948                                                $str = utf8_decode($str);
3949                                                $footer_ext_participantes =     '<br>&nbsp;&nbsp;'.lang("The email addresses must be separated by ','");                                               
3950                                               
3951                                                $var['participants'] = array
3952                                                (
3953                                                        'field' => lang('Participants'),                                                       
3954                                                        'data'  => "
3955                                                                        <table width='100%' border='0'>
3956                                                                                <tr>
3957                                                                                        <td width='30%'>                                                                               
3958                                                                                                <center>Participantes</center>                                                                                         
3959                                                                                        </td>
3960                                                                                        <td width='8%' >&nbsp;</td>
3961                                                                                        <td width='40%'>&nbsp;</td>
3962                                                                                </tr>                                                                                                                                           
3963                                                                                <tr>           
3964                                                                                        <td width='30%'>                                                                                       
3965                                                                                                <center><select id='user_list' name='participants[]' style='width: 220px' multiple size='7'>".$str."</select></center>                                                                         
3966                                                                                        </td>                           
3967                                                                                        <td width='8%'>
3968                                                                                        <center>
3969                                                                                                <table width='100%' border='0'>                                                                 
3970                                                                                                        <tr height='5'><td>&nbsp;</td></tr>                                                                     
3971                                                                                                        <tr><td align='center'>                                                                 
3972                                                                                                                <button type='button' onClick='javascript:openListUsers(340,533, "
3973                                                                                                                .$event['owner'].
3974                                                                                                                ")'><img src='calendar/templates/celepar/images/add.png' style='vertical-align: middle;' >&nbsp;Adicionar</button>
3975                                                                                                                </td>
3976                                                                                                        </tr>                                                   
3977                                                                                                        <tr height='5'><td>&nbsp;</td></tr>
3978                                                                                                        <tr><td  align='center'>
3979                                                                                                                        <button type='button' onClick='javascript:rem()'><img src='calendar/templates/celepar/images/rem.png' style='vertical-align: middle;' >&nbsp;Remover</button>
3980                                                                                                                </td>
3981                                                                                                        </tr>
3982                                                                                                </table>
3983                                                                                        </center>
3984                                                                                        </td>
3985                                                                                        <td width='40%'>&nbsp;</td>
3986                                                                                </tr>
3987                                                                                </table>
3988                                                                        <script src='calendar/templates/celepar/js/edit.js' type='text/javascript'></script>
3989                                                                        "
3990                                                );
3991                                                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
3992                                                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {                                                     
3993                                                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
3994
3995                                                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
3996                                                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
3997                                                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
3998                                                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $event['owner'];
3999                                                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
4000                                                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
4001                                                                $context = $GLOBALS['phpgw_info']['server']['ldap_context'];
4002                                                                $user_context = array();
4003                                                                foreach(explode(",",$GLOBALS['phpgw_info']['user']['account_dn']) as $i => $dn_part){
4004                                                                        if($i)
4005                                                                                $user_context[] = $dn_part;
4006                                                                }
4007                                                                $user_context = implode(",",$user_context);
4008                                                                $combo_org = $this->get_organizations($context, trim(strtolower($user_context)));
4009                                                                $footer_ext_participantes = lang("Tip: To search in the <b>Global Catalog</b>, type the <b>F9</b> key, like the ExpressoMail.");
4010                                                               
4011                                                                $var['participants'] = array
4012                                                                (
4013                                                                        'field' => lang('Participants'),                                                       
4014                                                                        'data'  => '<input type="hidden" id="txt_loading" value="'.lang("Loading").'">' .
4015                                                                                        '<input type="hidden" id="txt_searching" value="'.lang("Searching").'">' .
4016                                                                                        '<input type="hidden" id="txt_users" value="'.lang("Users").'">' .                                                     
4017                                                                                        '<input type="hidden" id="txt_groups" value="'.lang("Groups").'">' .
4018                                                                                        '<table width="100%" border="0">'.
4019                                                                                        '<tr>'.
4020                                                                                        '<td width="25%"><br>'.
4021                                                                                        '<button type="button" onClick="javascript:add_user();"><img src="calendar/templates/celepar/images/add.png" style="vertical-align: middle;" >&nbsp;'.lang("Add").'</button>'.
4022                                                                                        '&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>'.
4023                                                                                        '<br><br>&nbsp;&nbsp;<b>'.lang("Event's participants").'</b><br>'.
4024                                                                                        '       <select id="user_list" name="participants[]" style="width: 300px" multiple size="13">'.$str.'</select>'.
4025                                                                                        '</td>'.
4026                                                                                        '<td width="30px" valign="middle" align="center">&nbsp;'.
4027                                                                                        '</td>'.
4028                                                                                        '<td valign="bottom">'.
4029                                                                                        '       '.lang("Organization").': '.
4030                                                                                        '       <select name="org_context" id="combo_org" onchange="javascript:get_available_users(\''.$module_name.'\',this.value);">'.$combo_org.'</select>'.
4031                                                                                        '       <br>'.
4032                                                                                        '       <font color="red"><span id="cal_span_searching">&nbsp;</span></font>'.                                                                 
4033                                                                                        '       <br>'.lang("Search for").':'.
4034                                                                                        '       <input value="" id="cal_input_searchUser" size="35" autocomplete="off" onkeyup="javascript:optionFinderTimeout(this)"><br>'.
4035                                                                                        '       <b>'.lang("Available Users and Groups").'</b>'.
4036                                                                                        '       <select id="user_list_in" style="width: 300px" multiple size="13"></select>'.
4037                                                                                        '</td>'.
4038                                                                                        '</tr>'.
4039                                                                                        '</table>'.
4040                                                                                        '<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>'.
4041                                                                                        '<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>'.         
4042                                                                                        "<script src='calendar/templates/celepar/js/edit_exmail.js' type='text/javascript'></script>" .
4043                                                                                        "<script src='".$module_name."/inc/load_lang.php' type='text/javascript'></script>".
4044                                                                                        "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
4045                                                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
4046                                                                                        "<script type='text/javascript'>" .
4047                                                                                        "setTimeout('get_available_users(\"".$module_name."\",\'".$user_context."\')',1000);" .
4048                                                                                        "</script> "
4049                                                                                               
4050                                                                );
4051                                                        }                                               
4052                                                }                                               
4053                                               
4054                                                $var['participants']['data'] .= '<a id="a_ext_participants" title="'.lang("It types below the email addresses, if you want to invite other people out" .
4055                                                        " 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" ' .
4056                                                        'src="calendar/templates/celepar/images/sent.gif"></a><table id="tbl_ext_participants" width="100%" border="0" style="display:none">'.
4057                                                        '<tr>'.
4058                                                        '<td>'.
4059                                                        '&nbsp;&nbsp;<b>'.lang("external participants").'</b>&nbsp;<img align="top" src="calendar/templates/celepar/images/sent.gif">' .
4060                                                        '&nbsp;&nbsp;<a title="'.lang("Close").'" name="b_ext_participants" onClick="javascript:hideExParticipants(this,\''.$module_name.'\')" href="#a_ext_participants">['.lang("Close").']</a>&nbsp;'.                                                                                                               
4061                                                        '</td>'.
4062                                                        '</tr>'.
4063                                                        '<tr>'.
4064                                                        '<td>'.
4065                                                        '&nbsp;&nbsp;>> '.lang("It types below the email addresses, if you want to invite other people out of this system").':'.
4066                                                        '&nbsp;&nbsp;<br><textarea name="ex_participants" id="ex_participants" cols="70" rows="2">'.$event['ex_participants'].'</textarea><br>&nbsp;&nbsp;'.
4067                                                        $footer_ext_participantes.
4068                                                        '</tr>'.                                                       
4069                                                        '</table>';
4070                                                break;
4071                                               
4072                                }
4073                                if((($event['id'] > 0) && isset($event['participants'][$event['owner']])) || !$event['id'])
4074                                {
4075                                        $checked = ' checked';
4076                                }
4077                                else
4078                                {
4079                                        $checked = '';
4080                                }
4081                                $var['owner'] = Array(
4082                                        'field' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']).' '.lang('Participates'),
4083                                        'data'  => '<input type="checkbox" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'"'.$checked.'>'
4084                                );
4085                        }
4086
4087// Reminder
4088                        // The user must use "Alarm Management" to change/modify an alarm
4089                        // so only display the email reminder fields if this is a new event
4090                        // i.e. not editing an existing event
4091
4092                        if ($event['id'] == 0) {
4093                                // get defaults
4094                                $days = $this->bo->prefs['calendar']['default_email_days'];
4095                                $hours = $this->bo->prefs['calendar']['default_email_hours'];
4096                                $min = $this->bo->prefs['calendar']['default_email_min'];
4097                                if (count($event['alarm']) > 1)
4098                                {
4099                                        // this should not happen because when creating a new event
4100                                        // only 1 alarm is displayed on the screen
4101                                        // if the user wants more than 1 alarm they should
4102                                        // use "Alarm Management"
4103                                        echo '<!-- how did this happen, too many alarms -->'."\n";
4104                                }
4105                                // if there was an error pick up what the user entered
4106                                if (@isset($event['alarm']))
4107                                {
4108                                        @reset($event['alarm']);
4109                                        // just get the first one see above!!!
4110                                        list($key,$alarm) = @each($event['alarm']);
4111                                        $diff  = $start - $alarm['time'];
4112                                        $days  = (int)($diff / (24*3600));
4113                                        $hours = (int)(($diff - ($days * 24 * 3600))/3600);
4114                                        $min   = (int)(($diff - ($days * 24 * 3600) - ($hours * 3600))/60);
4115                                }
4116
4117                                // days
4118                                $dout = '<select name="cal[alarmdays]">'."\n";
4119                                for($i=0;$i<32;$i++)
4120                                {
4121                                        $dout .= '<option value="'.$i.'"'.($i==$days?' selected':'').'>'.$i.'</option>'."\n";
4122                                }
4123                                $dout .= '</select>'."\n".' '.lang('days').' ';
4124                                // hours
4125                                $hout = '<select name="cal[alarmhours]">'."\n";
4126                                for($i=0;$i<25;$i++)
4127                                {
4128                                        $hout .= '<option value="'.$i.'"'.($i==$hours?' selected':'').'>'.$i.'</option>'."\n";
4129                                }
4130                                $hout .= '</select>'."\n".' '.lang('hours').' ';
4131                                // minutes
4132                                $mout = '<select name="cal[alarmminutes]">'."\n";
4133                                for($i=0;$i<61;$i++)
4134                                {
4135                                        $mout .= '<option value="'.$i.'"'.($i==$min?' selected':'').'>'.$i.'</option>'."\n";
4136                                }
4137                                $mout .= '</select>'."\n".' '.lang('minutes').' ';
4138
4139                                $var['alarm'] = Array(
4140                                        'field' => lang('Alarm'),
4141                                        'data'  => $dout.$hout.$mout.lang('before the event')
4142                                );
4143
4144                        }
4145
4146// Repeat Type
4147                        $str = '';
4148                        foreach($this->bo->rpt_type as $type => $label)
4149                        {
4150                                $str .= '<option value="'.$type.'"'.($event['recur_type']==$type?' selected':'').'>'.lang($label).'</option>';
4151                        }
4152                        $var['recure_type'] = Array(
4153                                'field' => lang('Repeat Type'),
4154                                'data'  => '<select name="cal[recur_type]">'."\n".$str.'</select>'."\n"
4155                        );
4156
4157                        if($event['recur_enddate']['year'] != 0 && $event['recur_enddate']['month'] != 0 && $event['recur_enddate']['mday'] != 0)
4158                        {
4159                                $checked = ' checked';
4160                                $recur_end = $this->bo->maketime($event['recur_enddate']) - $GLOBALS['phpgw']->datetime->tz_offset;
4161                        }
4162                        else
4163                        {
4164                                $checked = '';
4165                                $recur_end = $this->bo->maketime($event['start']) + 86400 - $GLOBALS['phpgw']->datetime->tz_offset;
4166                        }
4167
4168                        $var['recure_enddate'] = Array(
4169                                'field' => lang('Repeat End Date'),
4170                                'data'  => '<input type="checkbox" name="cal[rpt_use_end]" value="y"'.$checked.'>'.lang('Use End Date').'  '.
4171/*
4172                                        $GLOBALS['phpgw']->common->dateformatorder(
4173                                                $sb->getYears('recur_enddate[year]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'Y')),
4174                                                $sb->getMonthText('recur_enddate[month]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'n')),
4175                                                $sb->getDays('recur_enddate[mday]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'d'))
4176                                        )
4177*/
4178                                        $jscal->input('recur_enddate[str]',$recur_end)
4179                        );
4180
4181                        $i = 0; $boxes = '';
4182                        foreach ($this->bo->rpt_day as $mask => $name)
4183                        {
4184                                $boxes .= '<input type="checkbox" name="cal[rpt_day][]" value="'.$mask.'"'.($event['recur_data'] & $mask ? ' checked' : '').'>&nbsp;'.lang($name)."\n";
4185                                if (++$i == 5) $boxes .= '<br>';
4186                        }
4187                        $var['recure_day'] = Array(
4188                                'field' => lang('Repeat Day').'<br>'.lang('(for weekly)'),
4189                                'data'  => $boxes
4190                        );
4191
4192                        $var['recure_interval'] = Array(
4193                                'field' => lang('Interval'),
4194                                'data'  => '<input name="cal[recur_interval]" size="4" maxlength="4" value="'.$event['recur_interval'].'">'
4195                        );
4196
4197                        if (!isset($this->fields))
4198                        {
4199                                $this->custom_fields = CreateObject('calendar.bocustom_fields');
4200                                $this->fields = &$this->custom_fields->fields;
4201                                $this->stock_fields = &$this->custom_fields->stock_fields;
4202                        }
4203                        $preserved = False;
4204                        foreach($this->fields as $field => $data)
4205                        {
4206                                if (!$data['disabled'])
4207                                {
4208                                        if (isset($var[$field]))
4209                                        {
4210                                                switch($field)
4211                                                {
4212                                                        case 'startdate':
4213                                                                $this->output_template_array($p,'row','list',$var['startdate']);
4214                                                                $this->output_template_array($p,'row','list',$var['starttime']);
4215                                                                break;
4216                                                        case 'enddate':
4217                                                                $this->output_template_array($p,'row','list',$var['enddate']);
4218                                                                $this->output_template_array($p,'row','list',$var['endtime']);
4219                                                                break;
4220                                                        case 'recure_type':
4221                                                                $p->set_var('tr_color',$this->theme['th_bg']);
4222                                                                $p->set_var('hr_text','<center><b>'.lang('Repeating Event Information').'</b></center>');
4223                                                                $p->parse('row','hr',True);
4224                                                                $this->output_template_array($p,'row','list',$var['recure_type']);
4225                                                                $this->output_template_array($p,'row','list',$var['recure_enddate']);
4226                                                                $this->output_template_array($p,'row','list',$var['recure_day']);
4227                                                                $this->output_template_array($p,'row','list',$var['recure_interval']);
4228                                                                break;
4229                                                        default:
4230                                                                $this->output_template_array($p,'row','list',$var[$field]);
4231                                                }
4232                                        }
4233                                        elseif (!isset($this->stock_fields[$field]))    // Custom field
4234                                        {
4235                                                $lang = lang($name = substr($field,1));
4236                                                $size = 'SIZE='.($data['shown'] ? $data['shown'] : ($data['length'] ? $data['length'] : 30)).
4237                                                        ' MAXLENGTH='.($data['length'] ? $data['length'] : 255);
4238                                                $v = array(
4239                                                        'field' => $lang == $name.'*' ? $name : $lang,
4240                                                        'data'  => '<input name="cal['.htmlspecialchars($field).']" '.$size.' value="'.$event['#'.$name].'">'
4241                                                );
4242                                                if ($data['title'])
4243                                                {
4244                                                        $v['tr_color'] = $this->theme['th_bg'];
4245                                                }
4246                                                if (!$data['length'] && $data['title'])
4247                                                {
4248                                                        $p->set_var('tr_color',$this->theme['th_bg']);
4249                                                        $p->set_var('hr_text','<center><b>'.$v['field'].'</b></center>');
4250                                                        $p->parse('row','hr',True);
4251                                                }
4252                                                else
4253                                                {
4254                                                        $this->output_template_array($p,'row','list',$v);
4255                                                }
4256                                        }
4257                                }
4258                                else    // preserve disabled fields
4259                                {
4260                                        switch ($field)
4261                                        {
4262                                                case 'owner':
4263                                                        $preserved[$field] = $event['id'] ? $event['participants'][$event['owner']] : 'A';
4264                                                        break;
4265                                                case 'recure_type':
4266                                                        foreach(array('recur_type','recur_enddate','recur_data','recur_interval') as $field)
4267                                                        {
4268                                                                $preserved[$field] = $event[$field];
4269                                                        }
4270                                                        break;
4271                                                case 'startdate':
4272                                                case 'enddate':
4273                                                        $field = substr($field,0,-4);
4274                                                default:
4275                                                        $preserved[$field] = $event[$field];
4276                                        }
4277                                }
4278                        }
4279                        unset($var);
4280                        if (is_array($preserved))
4281                        {
4282                                //echo "preserving<pre>"; print_r($preserved); echo "</pre>\n";
4283                                $p->set_var('common_hidden',$p->get_var('common_hidden').'<input type="hidden" name="preserved" value="'.htmlspecialchars(serialize($preserved)).'">'."\n");
4284                        }
4285                        $p->set_var('submit_button',lang('Save'));
4286
4287                        $delete_button = $cancel_button = '';
4288                        if ($event['id'] > 0)
4289                        {
4290                                $var = Array(
4291                                        'action_url_button'     => $this->page('delete','&cal_id='.$event['id']),
4292                                        'action_text_button'    => lang('Delete'),
4293                                        '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.")."')\"",
4294                                        'action_extra_field'    => ''
4295                                );
4296                                $p->set_var($var);
4297                                $delete_button = $p->fp('out','form_button');
4298                        }
4299                        $p->set_var('delete_button',$delete_button);
4300
4301                        if ($this->bo->return_to)
4302                        {
4303                                $var = Array(
4304                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
4305                                        'action_text_button'    => lang('Cancel'),
4306                                        'action_confirm_button' => '',
4307                                        'action_extra_field'    => ''
4308                                );
4309                                $p->set_var($var);
4310                                $cancel_button = $p->fp('out','form_button');
4311                        }
4312                        $p->set_var('cancel_button',$cancel_button);
4313                        $p->pparse('out','edit_entry');
4314                       
4315                }
4316               
4317                // modify list of an event's external participants (i.e. non pgpgw users)
4318                //
4319                function modify_ext_partlist()
4320                {
4321                        $GLOBALS['phpgw_info']['flags']['noheader'] = True;
4322                        $GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
4323                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
4324                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
4325
4326                        $total_contacts = 0;
4327                        $participant = array();
4328                        $control_data= array();
4329
4330                        $control_data['action'] = '';
4331                        $control_data['delete'] = array();
4332                        $control_data['part'] = array();
4333
4334                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4335                        $p->set_file(
4336                                Array(
4337                                        'T_edit_partlist' => 'edit_partlist.tpl',
4338                                        'T_edit_partlist_blocks' => 'edit_partlist_blocks.tpl'
4339                                )
4340                        );
4341
4342                        $p->set_block('T_edit_partlist_blocks','B_alert_msg','V_alert_msg');
4343                        $p->set_block('T_edit_partlist_blocks','B_partlist','V_partlist');
4344                        $p->set_block('T_edit_partlist_blocks','B_participants_none','V_participants_none');
4345                        $p->set_block('T_edit_partlist_blocks','B_delete_btn','V_delete_btn');
4346
4347                        global $query_addr;
4348                        $sb = CreateObject('phpgwapi.sbox2');
4349                        $addy = $sb->getAddress('addr','',$query_addr);
4350
4351                        $add_ext  = $addy['doSearchFkt'];
4352                        $add_ext .= $addy['addr_title']!=lang('Address Book')?$addy['addr_title']:'';
4353                        $add_ext .= "&nbsp;".$addy['addr'].$addy['addr_nojs'];
4354
4355                        $p->set_var('text_add_name',$add_ext);
4356
4357                        if(isset($_GET['part']) && $_GET['part'])
4358                        {
4359                                $control_data['part'] = split(",", $_GET['part']);
4360                        }
4361                        else
4362                        {
4363                                $control_data['part'] = $_POST['participant'];
4364                                $control_data['action'] = $_POST['action'];
4365                                $control_data['delete'] = $_POST['delete'];
4366                        }
4367
4368                        for ($i=0; $i<count($control_data['part']); $i++)
4369                        {
4370                                $id = $control_data['part'][$i];
4371                                list($contact) = $this->read_contact($id);
4372
4373                                $participant[$id] = array();
4374                                $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
4375                        }
4376
4377                        if ($control_data['action'] == lang('Delete selected contacts'))
4378                        {
4379                                for ($i=0; $i<count($control_data['delete']); $i++)
4380                                {
4381                                        $id = $control_data['delete'][$i];
4382                                        unset($participant[$id]);
4383                                }
4384                        }
4385
4386                        if ($control_data['action'] == lang('Add Contact'))
4387                        {
4388                                $id = $_POST['id_addr'];
4389                                if (isset($id) && (int)$id != 0)
4390                                {
4391                                        list($contact) = $this->read_contact($id);
4392                                        $participant[$id] = array();
4393                                        $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
4394                                }
4395                        }
4396
4397                        // create list of currently selected contacts
4398                        //
4399                        while(list($id,$contact) = each($participant))
4400                        {
4401                                $p->set_var('hidden_delete_name','participant[]');
4402                                $p->set_var('hidden_delete_value',$id);
4403                                $p->set_var('ckbox_delete_name','delete[]');
4404                                $p->set_var('ckbox_delete_value',$id);
4405                                $p->set_var('ckbox_delete_participant',$contact['name']);
4406                                $p->parse('V_partlist','B_partlist',True);
4407                                $total_contacts++;
4408                        }
4409
4410                        if ($total_contacts == 0)
4411                        {
4412                                // no contacts have been selected
4413                                // => clear the delete form, remove delete button and show the none block
4414                                //
4415                                $p->set_var('V_partlist','');
4416                                $p->set_var('V_delete_btn','');
4417                                $p->set_var('text_none',lang('None'));
4418                                $p->parse('V_participants_none','B_participants_none');
4419                        }
4420                        else
4421                        {
4422                                // at least one contact has been selected
4423                                // => clear the none block, fill the delete form and add delete button
4424                                //
4425                                $p->set_var('V_participants_none','');
4426                                $p->set_var('btn_delete_name','action');
4427                                $p->set_var('btn_delete_value',lang('Delete selected contacts'));
4428                                $p->parse('V_delete_btn','B_delete_btn');
4429                        }
4430
4431                        $body_tags  = 'bgcolor="'.$GLOBALS['phpgw_info']['theme']['bg_color']
4432                                                        . '" alink="'.$GLOBALS['phpgw_info']['theme']['alink']
4433                                                        . '" link="'.$GLOBALS['phpgw_info']['theme']['link']
4434                                                        .'" vlink="'.$GLOBALS['phpgw_info']['theme']['vlink'].'"';
4435
4436                        $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.modify'));
4437
4438                        $charset = lang('charset');
4439                        $p->set_var('charset',$charset);
4440                        $p->set_var('page_title',$GLOBALS['phpgw_flags']['currentapp']
4441                                . ' - ' .lang('External Participants'));
4442                        $p->set_var('font_family',$GLOBALS['phpgw_info']['theme']['font']);
4443                        $p->set_var('body_tags',$body_tags);
4444                        $p->set_var('form_method','POST');
4445                        $p->set_var('form_action',$form_action);
4446                        $p->set_var('text_add_contact',lang('External Participants'));
4447                        $p->set_var('text_contacts_selected',lang('Selected contacts (%1)',$total_contacts));
4448                        $p->set_var('btn_add_name','action');
4449                        $p->set_var('btn_add_value',lang('Add Contact'));
4450                        $p->set_var('btn_done_name','done');
4451                        $p->set_var('btn_done_value',lang('Done'));
4452                        $p->set_var('btn_done_js','copyback()');
4453                        $p->set_var('form1_name','ext_form');
4454
4455                        $p->pfp('out','T_edit_partlist');
4456                }
4457
4458                function read_contact($id)
4459                {
4460                        $query_fields = Array(
4461                                'n_given' => 'n_given',
4462                                'n_family' => 'n_family',
4463                                'email' => 'email',
4464                                'email_home' => 'email_home'
4465                        );
4466
4467                        /*
4468                        if ($this->rights & PHPGW_ACL_READ)
4469                        {
4470                                return $this->contacts->read_single_entry($id,$fields);
4471                        }
4472                        else
4473                        {
4474                                $rtrn = array(0 => array('No access' => 'No access'));
4475                                return $rtrn;
4476                        }
4477                        */
4478
4479                        $contacts = CreateObject('phpgwapi.contacts', False);
4480                        return $contacts->read_single_entry($id,$query_fields);
4481                }
4482
4483                function build_part_list(&$users,$accounts,$owner)
4484                {
4485                        if(!is_array($accounts))
4486                        {
4487                                return;
4488                        }
4489                        foreach($accounts as $id)
4490                        {
4491                                $id = (int)$id;
4492                                if($id == $owner)
4493                                {
4494                                        continue;
4495                                }
4496                                elseif(!isset($users[$id]))
4497                                {
4498                                        if($GLOBALS['phpgw']->accounts->exists($id) == True)
4499                                        {
4500                                                $users[$id] = Array(
4501                                                        'name'  => $GLOBALS['phpgw']->common->grab_owner_name($id),
4502                                                        'type'  => $GLOBALS['phpgw']->accounts->get_type($id)
4503                                                );
4504                                        }
4505                                        if($GLOBALS['phpgw']->accounts->get_type($id) == 'g')
4506                                        {
4507                                                //$this->build_part_list($users,$GLOBALS['phpgw']->acl->get_ids_for_location($id,1,'phpgw_group'),$owner);
4508                                        }
4509                                }
4510                        }
4511                        if (!function_exists('strcmp_name'))
4512                        {
4513                                function strcmp_name($arr1,$arr2)
4514                                {
4515                                        if ($diff = strcmp($arr1['type'],$arr2['type']))
4516                                        {
4517                                                return $diff;   // groups before users
4518                                        }
4519                                        return strnatcasecmp($arr1['name'],$arr2['name']);
4520                                }
4521                        }
4522                        uasort($users,'strcmp_name');
4523                }
4524
4525                function set_week_array($startdate,$cellcolor,$weekly)
4526                {
4527                        for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
4528                        {
4529                                $date = date('Ymd',$datetime + (60 * 60 * 2)); // +2h to be save when switching to and from dst, $datetime is alreay + TZ-Offset
4530                                print_debug('set_week_array : Date ',$date);
4531
4532                                if($events = $this->bo->cached_events[$date])
4533                                {
4534                                        print_debug('Date',$date);
4535                                        print_debug('Appointments Found',count($events));
4536
4537                                        if (!$this->bo->prefs['calendar']['show_rejected'])
4538                                        {
4539                                                $appts = False;
4540                                                foreach($events as $event)      // check for a not-rejected event
4541                                                {
4542                                                        if (!$this->bo->rejected_no_show($event))
4543                                                        {
4544                                                                $appts = True;
4545                                                                break;
4546                                                        }
4547                                                }
4548                                        }
4549                                        else
4550                                        {
4551                                                $appts = True;
4552                                        }
4553                                }
4554                                else
4555                                {
4556                                        $appts = False;
4557                                }
4558
4559                                $holidays = $this->bo->cached_holidays[$date];
4560                                if($weekly)
4561                                {
4562                                        $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
4563                                }
4564
4565                                $day_image = '';
4566                                if($holidays)
4567                                {
4568                                        $extra = ' bgcolor="'.$this->bo->holiday_color.'"';
4569                                        $class = ($appts?'b':'').'minicalhol';
4570                                        if ($date == $this->bo->today)
4571                                        {
4572                                                $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
4573                                        }
4574                                }
4575                                elseif ($date != $this->bo->today)
4576                                {
4577                                        $extra = ' bgcolor="'.$cellcolor.'"';
4578                                        $class = ($appts?'b':'').'minicalendar';
4579                                }
4580                                else
4581                                {
4582                                        $extra = ' bgcolor="'.$GLOBALS['phpgw_info']['theme']['cal_today'].'"';
4583                                        $class = ($appts?'b':'').'minicalendar';
4584                                        $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
4585                                }
4586
4587                                if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
4588                                {
4589                                        $extra = '';
4590                                }
4591
4592                                if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
4593                                {
4594                                        $new_event = True;
4595                                }
4596                                else
4597                                {
4598                                        $new_event = False;
4599                                }
4600                                $holiday_name = Array();
4601                                if($holidays)
4602                                {
4603                                        for($k=0;$k<count($holidays);$k++)
4604                                        {
4605                                                $holiday_name[] = $holidays[$k]['name'];
4606                                        }
4607                                }
4608                                $week = '';
4609                                if (!$j || (!$weekly && $j && substr($date,6,2) == '01'))
4610                                {
4611                                        $week = lang('week').' '.(int)((date('z',($startdate+(24*3600*4)))+7)/7);
4612                                }
4613                                $daily[$date] = Array(
4614                                        'extra'         => $extra,
4615                                        'new_event'     => $new_event,
4616                                        'holidays'      => $holiday_name,
4617                                        'appts'         => $appts,
4618                                        'week'          => $week,
4619                                        'day_image'     => $day_image,
4620                                        'class'         => $class
4621                                );
4622                        }
4623
4624                        if($this->debug)
4625                        {
4626                                _debug_array($daily);
4627                        }
4628
4629                        return $daily;
4630                }
4631
4632                function get_organizations($context, $selected='')
4633                {
4634                        $s = CreateObject('phpgwapi.sector_search_ldap');
4635                        $sectors_info = $s->get_organizations($context, $selected, false, false);
4636                        return $sectors_info;
4637                }
4638                /*
4639                function get_organizations($context, $selected='')
4640                {
4641                        $first_sector_ufn = ldap_dn2ufn($context);
4642                        $first_sector_string = split(",", $first_sector_ufn);
4643
4644                        $s = CreateObject('phpgwapi.sector_search_ldap');
4645                        $sectors_info = $s->sector_search($context);
4646
4647                        $sector_select = "";
4648                        $sector_select .= "<option value='" .$context . "'";
4649                        $sector_select .= ">".$first_sector_string[0]."</option>\n";
4650                       
4651                        foreach($sectors_info as $sector)
4652                        {
4653                                if ($sector->sector_level == 1)
4654                                {
4655                                        $sector->sector_name = '+ '.$sector->sector_name;
4656                                }
4657                                else
4658                                {
4659                                        $sector_space = '';
4660                                        for ($i=1; $i < $sector->sector_level; $i++)
4661                                                $sector_space = '---'.$sector_space;
4662                                        $sector->sector_name = $sector_space.' '.$sector->sector_name;
4663                                }
4664                                $sector_select .= '<option value="' . $sector->sector_context . '"';
4665                               
4666                                if (trim(strtolower($sector->sector_context)) == $selected)
4667                                        $sector_select .= ' selected>' . $sector->sector_name . "</option>\n";
4668                                else
4669                                        $sector_select .= '>' . $sector->sector_name . "</option>\n";
4670                        }
4671                        //$sector_select .= "</select>";
4672                        return $sector_select; 
4673                }
4674                */
4675        }
4676?>
Note: See TracBrowser for help on using the repository browser.