source: trunk/calendar/inc/class.uicalendar.inc.php @ 1949

Revision 1949, 191.5 KB checked in by eduardoalex, 14 years ago (diff)

Ticket #715 - Corrigido a montagem do combo tipo de evento e alterado o tipo do compromisso privado de e para P

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