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

Revision 212, 149.8 KB checked in by niltonneto, 16 years ago (diff)

Ver ticket #46:
Não permitir mais de um clique no botão 'aceitar' na mensagem

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