source: sandbox/2.2.0.2/calendar/inc/class.uicalendar.inc.php @ 4554

Revision 4554, 227.2 KB checked in by airton, 13 years ago (diff)

Ticket #1820 - Itens ausentes na agenda - tooltip visoes semanal e mensal - r4529

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