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

Revision 4217, 223.4 KB checked in by brunocosta, 13 years ago (diff)

Ticket #1802 - Opção nos agendamentos para enviar notificações como dono.

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