source: branches/2.2/calendar/inc/class.uicalendar.inc.php @ 4700

Revision 4700, 193.1 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #2106 - Corrigido erro no módulo calendar para aceitar o novo compromisso

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