source: companies/serpro/calendar/inc/class.uicalendar.inc.php @ 903

Revision 903, 171.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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