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

Revision 870, 169.1 KB checked in by niltonneto, 15 years ago (diff)

Ticket #515 - Melhorado tempo de resposta ao visualizar agenda semanal e mensal de compromissos.

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