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

Revision 4008, 212.1 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1615 - Componente novo para agenda. Correcao de erro gerado com merge.

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