source: branches/2.2.0.1/calendar/inc/class.uicalendar.inc.php @ 4119

Revision 4119, 220.5 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1726 - Adição do dia da semana na visão diária. r4074

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