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

Revision 4100, 193.6 KB checked in by niltonneto, 13 years ago (diff)

Ticket #1781 - Correção do número de dias para impressão mensal por linhas

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