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

Revision 5132, 199.5 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo calendar.

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