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

Revision 4707, 227.3 KB checked in by roberto.santosjunior, 13 years ago (diff)

Ticket #1820 - Itens ausentes na agenda - preferencia da agenda. r4557

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