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

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