source: branches/2.2/calendar/inc/class.uicalendar.inc.php @ 3193

Revision 3193, 192.0 KB checked in by rodsouza, 14 years ago (diff)

Ticket #553 - Adicionando anterior/próxima nas visões diária/semanal.

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