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

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