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

Revision 856, 170.9 KB checked in by niltonneto, 15 years ago (diff)

Ticket #509 - Correção de problema gerado em [766]. Busca de participantes com erro.

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