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

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

Ticket #1058 - Corrigindo problema no calendario para adicionar evento e na visao diaria.

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