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

Revision 4114, 220.0 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1745 - Padronizar a impressão diária, semanal e mensal da agenda.

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