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

Revision 5110, 193.5 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2279 - Corrigido bug de Exportar todos contendo agenda compartilhada

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