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

Revision 4167, 221.2 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1798 - Destacar nos mini-calendários o dia que está em exibição.

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