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

Revision 2230, 191.8 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #799 - Correcao de erro ao delegar um evento sem selecionar usuário

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