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

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

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

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