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

Revision 22, 149.4 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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