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

Revision 204, 149.5 KB checked in by niltonneto, 16 years ago (diff)

Ver Ticket #148:

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