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

Revision 3244, 192.5 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #799 - Erro ao delegar um evento sem selecionar usuario

  • 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                        $this->bo->read_holidays();
1722
1723                        $next = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day + 1,$this->bo->year);
1724                        $prev = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day - 1,$this->bo->year);
1725
1726                        if (!$this->bo->printer_friendly || ($this->bo->printer_friendly && @$this->bo->prefs['calendar']['display_minicals']))
1727                        {
1728                                $minical = $this->mini_calendar(
1729                                        Array(
1730                                                'day'   => $this->bo->day,
1731                                                'month' => $this->bo->month,
1732                                                'year'  => $this->bo->year,
1733                                                'link'  => 'day'
1734                                        )
1735                                );
1736                        }
1737                        else
1738                        {
1739
1740                                //NDEE: printer-friendly (what?)
1741                                $minical = '';
1742                        }
1743
1744                        if (!$this->bo->printer_friendly)
1745                        {
1746                                $printer = '';
1747                                $prev_day_link = '<a href="'.$this->page('day','&date='.$prev['full']).'">&lt;&lt;</a>';
1748                                $next_day_link = '<a href="'.$this->page('day','&date='.$next['full']).'">&gt;&gt;</a>';
1749                                $param = '&date='.sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day).'&friendly=1';
1750                                $print = '<a href="'.$this->page('day'.$param)."\" TARGET=\"cal_printer_friendly\" onMouseOver=\"window.status = '".lang('Generate printer-friendly version')."'\">[".lang('Printer Friendly').']</a>';
1751                        }
1752                        else
1753                        {
1754
1755                                //NDEE: printer-friendly (daily-view)
1756                                $GLOBALS['phpgw_info']['flags']['nofooter'] = True;
1757                                $printer = '<body bgcolor="'.$this->theme['bg_color'].'">';
1758                                $print =        '';
1759                        }
1760
1761                        $now    = $GLOBALS['phpgw']->datetime->makegmttime(0, 0, 0, $this->bo->month, $this->bo->day, $this->bo->year);
1762                        $now['raw'] += $GLOBALS['phpgw']->datetime->tz_offset;
1763
1764                        $p = $GLOBALS['phpgw']->template;
1765                        $p->set_file(
1766                                Array(
1767                                        'day_t' => 'day.tpl'
1768                                )
1769                        );
1770                        $p->set_block('day_t','day','day');
1771                        $p->set_block('day_t','day_event','day_event');
1772
1773                        $todos = $this->get_todos($todo_label);
1774                        $var = Array(
1775                                'printer_friendly'      => $printer,
1776                                'bg_text'                       => $this->theme['bg_text'],
1777                                'daily_events'          => $this->print_day(
1778                                        Array(
1779                                                'year'  => $this->bo->year,
1780                                                'month' => $this->bo->month,
1781                                                'day'   => $this->bo->day
1782                                        )
1783                                ),
1784                                'small_calendar'        => $minical,
1785                                'date'                          => $this->bo->long_date($now),
1786                                'username'                      => $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner),
1787                                'prev_day_link'         => $prev_day_link,
1788                                'next_day_link'         => $next_day_link,
1789                                'print'                         => $print,
1790                                'lang_todos'            => $todo_label,
1791                                'todos'                         => $this->bo->printer_friendly ? $todos :
1792
1793                                        //NDEE: todo's layout
1794                                        "<div style=\"overflow: auto; max-height: 200px\">\n$todos</div>\n"
1795                        );
1796
1797                        $p->set_var($var);
1798                        $p->parse('day_events','day_event');
1799                        print $this->printer_friendly($p->fp('out','day'),lang('Dayview'));
1800                        $GLOBALS['phpgw']->common->phpgw_footer();
1801                }
1802
1803                function get_todos(&$todo_label)
1804                {
1805                        $todos_from_hook = $GLOBALS['phpgw']->hooks->process(array(
1806                                'location'  => 'calendar_include_todos',
1807                                'year'      => $this->bo->year,
1808                                'month'     => $this->bo->month,
1809                                'day'       => $this->bo->day,
1810                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
1811                        ));
1812
1813                        if(is_array($todo_label))
1814                        {
1815                                list($label,$showall)=$todo_label;
1816                        }
1817                        else
1818                        {
1819                                $label=$todo_label;
1820                                $showall=true;
1821                        }
1822                        $maxshow = (int)$GLOBALS['phpgw_info']['user']['preferences']['infolog']['mainscreen_maxshow'];
1823                        if($maxshow<=0)
1824                        {
1825                                $maxshow=10;
1826                        }
1827                        //print_debug("get_todos(): label=$label; showall=$showall; max=$maxshow");
1828
1829                        $content = $todo_label = '';
1830                        if (is_array($todos_from_hook) && count($todos_from_hook))
1831                        {
1832                                $todo_label = !empty($label)?$label:lang("open ToDo's:");
1833
1834                                foreach($todos_from_hook as $todos)
1835                                {
1836                                        $i = 0;
1837                                        if (is_array($todos) && count($todos))
1838                                        {
1839                                                foreach($todos as $todo)
1840                                                {
1841                                                        if(!$showall && ($i++>$maxshow))
1842                                                        {
1843                                                                break;
1844                                                        }
1845                                                        $icons = '';
1846                                                        foreach($todo['icons'] as $name => $app)
1847                                                        {
1848                                                                $icons .= ($icons?' ':'').$GLOBALS['phpgw']->html->image($app,$name,lang($name),'border="0" width="15" height="15"');
1849                                                        }
1850                                                        $class = $class == 'row_on' ? 'row_off' : 'row_on';
1851
1852//NDEE <tr starts here
1853                                                        $content .= " <tr id=\"debug\" class=\"$class\">\n  <td valign=\"top\" width=\"15%\"nowrap>".
1854                                                                ($this->bo->printer_friendly?$icons:$GLOBALS['phpgw']->html->a_href($icons,$todo['view'])).
1855                                                                "</td>\n  <td>".($this->bo->printer_friendly?$todo['title']:
1856                                                                $GLOBALS['phpgw']->html->a_href($todo['title'],$todo['view']))."</td>\n </tr>\n";
1857                                                }
1858                                        }
1859                                }
1860                        }
1861                        if (!empty($content))
1862                        {
1863                                return "<table border=\"0\" width=\"100%\">\n$content</table>\n";
1864                        }
1865                        return False;
1866                }
1867
1868                function edit_status()
1869                {
1870                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
1871                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1872                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
1873                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
1874                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Change Status');
1875                        $GLOBALS['phpgw']->common->phpgw_header();
1876
1877                        $event = $this->bo->read_entry($_GET['cal_id']);
1878
1879                        reset($event['participants']);
1880
1881                        if(!$event['participants'][$this->bo->owner])
1882                        {
1883                                echo '<center>'.lang('The user %1 is not participating in this event!',$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner)).'</center>';
1884                                return;
1885                        }
1886
1887                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
1888                        {
1889                                $this->no_edit();
1890                                return;
1891                        }
1892
1893                        $freetime = $GLOBALS['phpgw']->datetime->localdates(mktime(0,0,0,$event['start']['month'],$event['start']['mday'],$event['start']['year']) - $GLOBALS['phpgw']->datetime->tz_offset);
1894                        echo $this->timematrix(
1895                                Array(
1896                                        'date'          => $freetime,
1897                                        'starttime'     => $this->bo->splittime('000000',False),
1898                                        'endtime'       => 0,
1899                                        'participants'  => $event['participants']
1900                                )
1901                        ).'<br>';
1902
1903                        $event = $this->bo->read_entry($_GET['cal_id']);
1904                        $this->view_event($event);
1905                        $GLOBALS['phpgw']->template->pfp('phpgw_body','view_event');
1906
1907                        echo $this->get_response($event['id']);
1908                }
1909               
1910                function confirm_action($duplicated_action)
1911                {
1912                                if($_GET['response'] == 1)
1913                                {
1914                                        if(!$duplicated_action)
1915                                                $notify_message = lang('The commitment was accepted successfully!');
1916                                        else
1917                                                $notify_message = lang('This commitment has already been accepted!');
1918                                }       
1919                                else
1920                                {                                       
1921                                        if(!$duplicated_action)                                         
1922                                                $notify_message = lang('The commitment was rejected successfully!');
1923                                        else
1924                                                $notify_message = lang('This commitment has already been rejected!');
1925                                }
1926                               
1927                                $body1 = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
1928                                $body1->set_file(Array('calendar' => 'confirm.tpl'));
1929                                $body1->set_block('calendar','list');
1930                                $var = Array( 'notify_message'  => $notify_message);
1931                                $body1->set_var($var);
1932                                $tmpbody1 = $body1->pfp('out','list');
1933                }
1934               
1935                function confirm_conflict($user_id,$event,$overlapping_events)
1936                {
1937                        if(!$overlapping_events){                                       
1938                                $notify_message = lang('Este evento entra em conflito com outro que você participa.');
1939       
1940                                $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));
1941                                $action_reject = $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.set_action','cal_id' => $event[id], 'action' => 0, 'response' => 0));
1942       
1943                                $body1 = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
1944                                $body1->set_file(Array('calendar' => 'conflict.tpl'));
1945                                $body1->set_block('calendar','list');
1946                                $var = Array( 'notify_message'  => $notify_message,
1947                                                        'action_url' => $action_url,
1948                                                        'ignore_conflict' => 'Ignorar Conflito',
1949                                                        'reject_event' => 'Rejeitar Evento',
1950                                                        'action_reject' => $action_reject,
1951                                                        'action_ignore' => $action_ignore);
1952                                $body1->set_var($var);
1953                                $tmpbody1 = $body1->pfp('out','list');
1954                        }
1955                        else
1956                        {                               
1957                                $month = $event['start']['month'];
1958                                $mday = $event['start']['mday'];
1959                                $year = $event['start']['year'];
1960       
1961                                $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
1962                                $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
1963       
1964                                $overlap = '';
1965                                for($i=0;$i<count($overlapping_events);$i++)
1966                                {
1967                                        $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True);
1968                                        foreach($overlapped_event['participants'] as $id => $status)
1969                                        {
1970                                                $conflict = isset($event['participants'][$user_id]);
1971                                                $overlap .= '<li>'.($conflict?'<b>':'').
1972                                                        $GLOBALS['phpgw']->common->grab_owner_name($id).
1973                                                        ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>";
1974                                        }
1975                                 if ($this->bo->prefs['calendar']['hide_event_conflict'])
1976                                         $overlap .= '<ul><font size="1"><span>'.
1977                                                 $this->normDec($overlapped_event['start']['hour']).":".
1978                                                 $this->normDec($overlapped_event['start']['min'])."-".
1979                                                 $this->normDec($overlapped_event['end']['hour']).":".
1980                                                 $this->normDec($overlapped_event['end']['min']).
1981                                                 '<br><b>'.lang('title').": ".lang("Hidden").
1982                                                 '</b><br>'.lang('description').": ".lang("Hidden").'<br></span></ul><br>';
1983                                 else
1984                                         $overlap .= '<ul>'.$this->link_to_entry($overlapped_event,$month,$mday,$year)."</ul><br>";     
1985                                }
1986       
1987                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
1988                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1989                                $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
1990                                $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
1991                                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict');
1992                                $GLOBALS['phpgw']->common->phpgw_header();
1993       
1994                                $p = $GLOBALS['phpgw']->template;
1995                                $p->set_file(
1996                                        Array(
1997                                                'overlap'       => 'overlap.tpl',
1998                                                'form_button'   => 'form_button_script.tpl'
1999                                        )
2000                                );
2001       
2002                                $var = Array(
2003                                        'color'         => $this->theme['bg_text'],
2004                                        'overlap_title' => lang('Scheduling Conflict'),
2005                                        '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)),
2006                                        'overlap_list'  => $overlap
2007                                );
2008                                $p->set_var($var);
2009       
2010                                $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday);
2011                                $var = Array(
2012                                        '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)),
2013                                        'action_text_button'    => lang('Ignore Conflict'),
2014                                        'action_confirm_button' => '',
2015                                        'action_extra_field'    => '',
2016                                        'button_id'             => 'ignore_button'
2017                                );                             
2018                                $action_reject = $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.set_action','cal_id' => $event[id], 'action' => 0, 'response' => 0));
2019       
2020                                $this->output_template_array($p,'resubmit_button','form_button',$var);
2021       
2022                                $var = Array(
2023                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.set_action','cal_id' => $event[id], 'action' => 0)),
2024                                        'action_text_button'    => lang('Reject'),
2025                                        'action_confirm_button' => '',
2026                                        'action_extra_field'    => '',
2027                                        'button_id'             => 'redit_button'
2028                                );
2029                                $this->output_template_array($p,'reedit_button','form_button',$var);
2030                                $p->pparse('out','overlap');
2031                        }
2032                }
2033               
2034                function set_action()
2035                {
2036                        if(!$this->bo->check_perms(PHPGW_ACL_EDIT))
2037                        {
2038                                $this->no_edit();
2039                                return;
2040                        }
2041                       
2042                        $overlapping_events = false;
2043                        $event = $this->bo->read_entry((int)$_GET['cal_id']);
2044                        if((!$_GET['response'] == 0 && !$_GET['ignore_conflict'] == 1) ||
2045                                (!isset($_GET['response']) && $_GET['action'] == 3 && !$_GET['ignore_conflict'] == 1))
2046                        {
2047                                if($event['reference'])
2048                                {
2049                                        $event_ids[] = $event['reference'];
2050                                }
2051                                $event['participants'] = Array($_GET['user_id'] => $event['participants'][$_GET['user_id']]);
2052                                $overlapping_events = $this->bo->overlap(
2053                                        $this->bo->maketime($event['start']),
2054                                        $this->bo->maketime($event['end']),
2055                                        $event['participants'],
2056                                        $event['owner'],
2057                                        $event_ids
2058                                );
2059                        }
2060
2061                        if(isset($_GET['response']))
2062                        {
2063                                if($overlapping_events)
2064                                {
2065                                        $this->confirm_conflict($_GET['user_id'],$event);
2066                                }else
2067                                {
2068                                        $confirm_status = $this->bo->set_status((int)$_GET['cal_id'],(int)$_GET['action']);
2069                                        $this->confirm_action($confirm_status);
2070                                        $GLOBALS['phpgw']->common->phpgw_exit(False);
2071                                }
2072                        }else
2073                        {
2074                                if($overlapping_events)
2075                                {                                       
2076                                        $this->confirm_conflict($_GET['user_id'],$event,$overlapping_events);
2077                                }else
2078                                {
2079                                $confirm_status = $this->bo->set_status((int)$_GET['cal_id'],(int)$_GET['action']);
2080                                        if ($this->bo->return_to)
2081                                        {
2082                                                Header('Location: '.$GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to));
2083                                        }
2084                                        else
2085                                        {
2086                                                Header('Location: '.$this->page('',''));
2087                                        }
2088                                        $GLOBALS['phpgw']->common->phpgw_exit();
2089                                }
2090                        }
2091                       
2092                       
2093                }
2094                function planner()
2095                {
2096                        if(floor(phpversion()) < 4)
2097                        {
2098                                return;
2099                        }
2100                        $home = strstr($_SERVER['PHP_SELF'],'home') !== False;
2101                        // generate header and set global/member variables
2102                        //
2103                        $this->planner_prepare($home);
2104
2105                        // process events within selected interval
2106                        //
2107                        $this->planner_process_interval();
2108
2109                        // generate the planner view
2110                        //
2111                        if (!$home)
2112                        {
2113                                echo '<p>'.$this->planner_print_rows();
2114                        }
2115                        else
2116                        {
2117                                return $this->planner_print_rows();
2118                        }
2119                }
2120
2121                function set_planner_group_members()
2122                {
2123                        $type = $GLOBALS['phpgw']->accounts->get_type($this->bo->owner);
2124
2125                        if ($type == 'g') // display schedule of all group members
2126                        {
2127                                $members = array();
2128                                $ids = $GLOBALS['phpgw']->acl->get_ids_for_location($this->bo->owner, 1, 'phpgw_group');
2129                                while (list(,$id) = each($ids))
2130                                {
2131                                        if ($this->bo->check_perms(PHPGW_ACL_READ,0,$id))
2132                                        {
2133                                                $members[$GLOBALS['phpgw']->common->grab_owner_name($id)] = $id;
2134                                        }
2135                                }
2136                                ksort($members);
2137                                $this->planner_group_members = $members;
2138                        }
2139                        else
2140                        {
2141                                $this->planner_group_members = array(
2142                                        $GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner) => $this->bo->owner
2143                                );
2144                        }
2145                }
2146
2147                /**
2148                 * planner_prepare - prepare the planner view
2149                 *
2150                 * - sets global environment variables
2151                 * - initializes class member variables used in multiple planner related functions
2152                 * - generates header lines for the planner view (month, calendar week, days)
2153                 */
2154                function planner_prepare($no_header = False)
2155                {
2156                        // set some globals
2157                        //
2158                        if (!$no_header)
2159                        {
2160                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
2161                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2162                                if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Group Planner');
2163                                $GLOBALS['phpgw']->common->phpgw_header();
2164                        }
2165
2166                        // intervals_per_day can be configured in preferences now :-)
2167                        //
2168                        if (! $this->bo->prefs['calendar']['planner_intervals_per_day'])
2169                        {
2170                                $GLOBALS['phpgw']->preferences->add('calendar','planner_intervals_per_day',3);
2171                                $GLOBALS['phpgw']->preferences->save_repository();
2172                                $this->bo->prefs['calendar']['planner_intervals_per_day'] = 3;
2173                        }
2174                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2175                        $this->bo->save_sessiondata();  // need to save $this->bo->save_owner
2176
2177                        // set title for table and rows of planner view
2178                        //
2179                        if ($this->bo->sortby == 'category')
2180                        {
2181                                $title = lang('Category');
2182                        }
2183                        else
2184                        {
2185                                $title = lang('User');
2186
2187                                $this->set_planner_group_members();
2188                        }
2189
2190                        // create/initialize variables directly used for HTML code generation
2191                        //
2192                        $this->planner_header = array();
2193                        $this->planner_rows   = array();
2194
2195                        // generate header lines with days and associated months
2196                        //
2197                        $hdr = &$this->planner_header;
2198                        $hdr[0]['0']  = $title;
2199                        $hdr[0]['.0'] = 'rowspan="3"';
2200
2201                        $this->planner_days = 0; // reset
2202
2203                        $m = $this->bo->month;
2204                        $y = $this->bo->year;
2205                        $this->bo->read_holidays($y);
2206                        for ($i=1; $i<=$this->bo->num_months; $i++,$m++)
2207                        {
2208                                if ($m == 13)
2209                                {
2210                                        $m = 1; $y++; // "wrap-around" into new year
2211                                        $this->bo->read_holidays($y);
2212                                }
2213                                $days = $GLOBALS['phpgw']->datetime->days_in_month($m,$y);
2214
2215                                $d     = mktime(0,0,0,$m,1,$y);
2216                                $month = lang(date('F', $d)).strftime(' %Y', $d);
2217                                $color = $this->theme[$m % 2 || $this->bo->num_months == 1 ? 'th_bg' : 'row_on'];
2218                                $cols  = $days * $intervals_per_day;
2219
2220                                $hdr[0]['.'.$i] = 'bgcolor="'.$color.'" colspan="'.$cols.'" align="center"';
2221                                $prev_month = sprintf('%04d%02d01',$y-($m==1),$m > 1?$m-1:12);
2222                                $next_month = sprintf('%04d%02d01',$y+($m==12),$m < 12?$m+1:1);
2223                                $prev_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$prev_month");
2224                                $next_link = $GLOBALS['phpgw']->link('/index.php',"menuaction=calendar.uicalendar.planner&date=$next_month");
2225                                $hdr[0][$i] = "<b><a href=\"$prev_link\">&lt;&lt;</a> &nbsp $month &nbsp <a href=\"$next_link\">&gt;&gt;</a></b>";
2226
2227                                $add_owner = array();   // if no add-rights on the showed cal use own cal
2228                                if (!$this->bo->save_owner && !$this->bo->check_perms(PHPGW_ACL_ADD) ||
2229                                        !$this->bo->check_perms(PHPGW_ACL_ADD,0,$this->bo->save_owner))
2230                                {
2231                                        $add_owner = array(
2232                                                'owner' => $GLOBALS['phpgw_info']['user']['account_id']
2233                                        );
2234                                }
2235                                for ($d=1; $d<=$days; $d++)
2236                                {
2237                                        $dayname = substr(lang(date('D',mktime(0,0,0,$m,$d,$y))),0,2);
2238                                        $index = $d + $this->planner_days;
2239
2240                                        $hdr[2]['.'.$index] = 'colspan="'.$intervals_per_day.'" align="center"';
2241
2242                                        // highlight today, saturday, sunday and holidays
2243                                        //
2244                                        $color = $this->theme['row_off'];
2245                                        $dow = $GLOBALS['phpgw']->datetime->day_of_week($y,$m,$d);
2246                                        $date = sprintf("%04d%02d%02d",$y,$m,$d);
2247                                        if ($date == date('Ymd'))
2248                                        {
2249                                                $color = $GLOBALS['phpgw_info']['theme']['cal_today'];
2250                                        }
2251                                        elseif ($this->bo->cached_holidays[$date])
2252                                        {
2253                                                $color = $this->bo->holiday_color;
2254                                                $hdr[2]['.'.$index] .= ' title="'.$this->bo->cached_holidays[$date][0]['name'].'"';
2255                                        }
2256                                        elseif ($dow == 0 || $dow == 6)
2257                                        {
2258                                                $color = $this->bo->theme['th_bg'];
2259                                        }
2260
2261                                        $hdr[2]['.'.$index] .= " bgcolor=\"$color\"";
2262
2263                                        $hdr[2][$index] = '<a href="'.$this->html->link('/index.php',
2264                                                                array(
2265                                                                        'menuaction' => 'calendar.uicalendar.add',
2266                                                                        'date' => $date
2267                                                                ) + $add_owner
2268                                                        ).'">'.$dayname.'<br>'.$d.'</a>';
2269                                }
2270                                $this->planner_days += $days;
2271                        }
2272
2273                        // create/initialize member variables describing the time interval to be displayed
2274                        //
2275                        $this->planner_end_month = $m - 1;
2276                        $this->planner_end_year  = $y;
2277                        $this->planner_days_in_end_month = $GLOBALS['phpgw']->datetime->days_in_month($this->planner_end_month,$this->planner_end_year);
2278                        $this->planner_firstday = (int)(date('Ymd',mktime(0,0,0,$this->bo->month,1,$this->bo->year)));
2279                        $this->planner_lastday  = (int)(date('Ymd',mktime(0,0,0,$this->planner_end_month,$this->planner_days_in_end_month,$this->planner_end_year)));
2280
2281                        // generate line with calendar weeks in observed interval
2282                        //
2283                        $d      = mktime(0,0,0,$this->bo->month,1,$this->bo->year);
2284                        $w      = date('W', $d);
2285                        if ($w == 'W')  // php < 4.1
2286                        {
2287                                $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
2288                        }
2289                        $offset = (7-date('w', $d)+1)%7;
2290                        $offset = $offset == 0 ? 7 : $offset;
2291                        $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
2292
2293                        $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$intervals_per_day * $offset.'" align="left"';
2294                        $hdr[1][$w] = '';
2295                        if ($offset >= 3)
2296                        {
2297
2298//NDEE: style! (groupplanner)
2299                                $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
2300                        }
2301                        $days_left = $this->planner_days - $offset;
2302
2303                        $colspan = 7 * $intervals_per_day;
2304                        while ($days_left > 0)
2305                        {
2306                                $colspan = ($days_left < 7) ? $days_left*$intervals_per_day : $colspan;
2307                                $d += 604800; // 7 days whith 24 hours (1h == 3600 seconds) each
2308                                $w = date('W', $d);
2309                                if ($w == 'W')  // php < 4.1
2310                                {
2311                                        $w = 1 + (int)(date('z',$d) / 7);       // a bit simplistic
2312                                }
2313                                $w += (isset($hdr[1][$w]))?1:0; // bug in "date('W')" ?
2314
2315                                $color = $this->theme[$w % 2 ? 'th_bg' : 'row_on'];
2316                                $hdr[1]['.'.$w] = 'bgcolor="'.$color.'" colspan="'.$colspan.'" align="left"';
2317                                $hdr[1][$w] = '';
2318                                if ($days_left >= 3)
2319                                {
2320
2321//NDEE: style! (groupplanner)
2322                                        $hdr[1][$w] .= '<font size="-2"> '.lang('week').' '.$w.' </font>';
2323                                }
2324
2325                                $days_left -= 7;
2326                        }
2327                        return $hdr;
2328                }
2329
2330                /**
2331                 * planner_update_row - update a row of the planner view
2332                 *
2333                 * parameters are:
2334                 *   - index (e.g. user id, category id, ...) of the row
2335                 *   - name/title of the row (e.g. user name, category name)
2336                 *   - the event to be integrated
2337                 *   - list of categories associated with the event
2338                 *   - first and last cell of the row
2339                 */
2340                function planner_update_row($index,$name,$event,$cat,$start_cell,$end_cell)
2341                {
2342                        $rows              = &$this->planner_rows;
2343                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2344                        $is_private        = !$this->bo->check_perms(PHPGW_ACL_READ,$event);
2345
2346                        $view = $this->html->link('/index.php',
2347                                array(
2348                                        'menuaction' => 'calendar.uicalendar.view',
2349                                        'cal_id' => $event['id'],
2350                                        'date' => date('Ymd',$this->bo->maketime($event['start']))
2351                                )
2352                        );
2353
2354                        // check how many lines are needed for this "row" (currently: user or category)
2355                        $i = 0;
2356                        do {
2357                                ++$i;
2358
2359                                $k = $index.'_'.$i;
2360                                $ka = '.nr_'.$k;
2361
2362                                if (!isset($rows[$k]))
2363                                {
2364                                        if ($i > 1)                             // further line - no name
2365                                        {
2366                                                $rows[$k] = array();
2367                                                $rows[$index.'_1']['._name'] = 'rowspan="'.$i.'"';
2368                                        }
2369                                        else
2370                                        {
2371                                                $rows[$k]['_name'] = $name;
2372                                        }
2373                                        $rows[$ka] = 0;
2374                                }
2375                                $rows[$index.'_1']['._name'] .= ' nowrap'; // title must be one row
2376
2377                                $row = &$rows[$k];
2378                                $akt_cell = &$rows[$ka];
2379                        } while ($akt_cell > $start_cell);
2380
2381                        $id = $event['id'].'-'.date('Ymd',$this->bo->maketime($event['start']));
2382                        if ($akt_cell < $start_cell)
2383                        {
2384                                $row[$id.'_1'] = '&nbsp;';
2385                                $row['.'.$id.'_1'] = 'colspan="'.($start_cell-$akt_cell).'"';
2386                        }
2387                        $opt = &$row['.'.$id.'_2'];
2388                        $cel = &$row[$id.'_2'];
2389
2390                        // if possible, display information about event within cells representing it
2391                        //
2392                        if ($start_cell < $end_cell)
2393                        {
2394                                $colspan = $end_cell - $start_cell;
2395                                $opt .= "colspan=".(1 + $colspan);
2396
2397                                if (!$is_private)
2398                                {
2399                                        $max_chars = (int)(3*$colspan/$intervals_per_day-2);
2400
2401                                        $min_chars = 3; // minimum for max_chars to display -> this should be configurable
2402                                        if ($max_chars >= $min_chars)
2403                                        {
2404                                                $len_title = strlen($event['title']);
2405
2406                                                if ($len_title <= $max_chars)
2407                                                {
2408                                                        $title = $event['title'];
2409                                                        $max_chars -= $len_title + 3; // 3 chars for separator: " - "
2410                                                        $len_descr = strlen($event['description']);
2411
2412                                                        if ($len_descr > 0 && $len_descr <= $max_chars)
2413                                                        {
2414                                                                $event['print_description'] = 'yes';
2415                                                        }
2416                                                }
2417                                                else
2418                                                {
2419                                                        $has_amp = strpos($event['title'],'&amp;');
2420                                                       
2421//NDEE: event title gets cut here                                                       
2422                                                        $title = substr($event['title'], 0 , $max_chars-1+($has_amp!==False&&$has_amp<$max_chars?4:0)).'...';
2423                                                }
2424                                                $event['print_title'] = 'yes';
2425                                        }
2426                                }
2427                        }
2428
2429                        if ($bgcolor=$cat['color'])
2430                        {
2431                                $opt .= ' bgcolor="'.$bgcolor.'"';
2432                        }
2433                        if (!$is_private)
2434                        {
2435                                $opt .= ' title="'.lang('Title').": ".$event['title'];
2436                                if ($event['description'])
2437                                {
2438                                        $opt .= "\n".lang('Description').": ".$event['description'];
2439                                }
2440                        }
2441                        else
2442                        {
2443                                $opt .= ' title="'.lang('You do not have permission to read this record!');
2444                        }
2445
2446                        $start = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset);
2447                        $end = $GLOBALS['phpgw']->common->show_date($this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset);
2448                        $opt .= "\n".lang('Start Date/Time').": ".$start."\n".lang('End Date/Time').": ".$end;
2449
2450                        if ($event['location'] && !$is_private)
2451                        {
2452                                $opt .= " \n".lang('Location').": ".$event['location'];
2453                        }
2454
2455                        if (!$is_private)
2456                        {
2457                                $opt .= '" onClick="location=\''.$view.'\'"';
2458                                $cel = '<a href="'.$view.'">';
2459                        }
2460                        else
2461                        {
2462                                $opt .= '"';
2463                                $cel = '';
2464                        }
2465                        $opt .= ' class="planner-cell"';
2466
2467                        if ($event['priority'] == 3)
2468                        {
2469                                $cel .= $this->html->image('calendar','mini-calendar-bar.gif','','border="0"');
2470                        }
2471                        if ($event['recur_type'])
2472                        {
2473                                $cel .= $this->html->image('calendar','recur.gif','','border="0"');
2474                        }
2475                        $cel .= $this->html->image('calendar',count($event['participants'])>1?'multi_3.gif':'single.gif',$this->planner_participants($event['participants']),'border="0"');
2476                        $cel .= '</a>';
2477
2478                        if (isset($event['print_title']) && $event['print_title'] == 'yes')
2479                        {
2480
2481//NDEE: style! where?
2482                                $cel .= '<font size="-2"> '.$title.' </font>';
2483                        }
2484                        if (isset($event['print_description']) && $event['print_description'] == 'yes')
2485                        {
2486
2487//NDEE: style! where ?
2488                                $cel .= '<font size="-2"> - '.$event['description'].' </font>';
2489                        }
2490
2491                        $akt_cell = $end_cell + 1;
2492
2493                        return $rows;
2494                }
2495
2496                function planner_process_event($event)
2497                {
2498                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2499                        $interval = $this->planner_intervals[$intervals_per_day];
2500                        $last_cell = $intervals_per_day * $this->planner_days - 1;
2501
2502                        $rows = &$this->planner_rows;
2503
2504                        // caluculate start and end of event
2505                        //
2506                        $event_start = (int)(date('Ymd',mktime(
2507                                0,0,0,
2508                                $event['start']['month'],
2509                                $event['start']['mday'],
2510                                $event['start']['year']
2511                        )));
2512                        $event_end   = (int)(date('Ymd',mktime(
2513                                0,0,0,
2514                                $event['end']['month'],
2515                                $event['end']['mday'],
2516                                $event['end']['year']
2517                        )));
2518
2519                        // calculate first cell of event within observed interval
2520                        //
2521                        if ($event_start >= $this->planner_firstday)
2522                        {
2523                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['start']['month'],$event['start']['mday'],$event['start']['year']);
2524
2525                                $start_cell = $intervals_per_day * $days_between + $interval[$event['start']['hour']];
2526                        }
2527                        else
2528                        {
2529                                $start_cell = 0;
2530                        }
2531
2532                        // calculate last cell of event within observed interval
2533                        //
2534                        if ($event_end <= $this->planner_lastday)
2535                        {
2536                                $days_between = $GLOBALS['phpgw']->datetime->days_between($this->bo->month,1,$this->bo->year,$event['end']['month'],$event['end']['mday'],$event['end']['year']);
2537                                $end_cell = $intervals_per_day * $days_between + $interval[$event['end']['hour']];
2538                                if ($end_cell == $start_cell && $end_cell < $last_cell)
2539                                {
2540                                        $end_cell++;    // min. width 1 interval
2541                                }
2542                        }
2543                        else
2544                        {
2545                                $end_cell = $last_cell;
2546                        }
2547                        // get the categories associated with event
2548                        //
2549                        if ($c = $event['category'])
2550                        {
2551                                list($cat)   = $this->planner_category($event['category']);
2552                                if ($cat['parent'])
2553                                {
2554                                        list($pcat) = $this->planner_category($c = $cat['parent']);
2555                                }
2556                                else
2557                                {
2558                                        $pcat = $cat;
2559                                }
2560                        }
2561                        else
2562                        {
2563                                $cat = $pcat = array( 'name' => lang('none'));
2564                        }
2565
2566                        // add the event to it`s associated row(s)
2567                        //
2568                        if ($this->bo->sortby == 'category')
2569                        {
2570                                // event needs to show up in it`s category`s row
2571                                //
2572                                $this->planner_update_row($c,$pcat['name'],$event,$cat,$start_cell,$end_cell);
2573                        }
2574                        elseif ($this->bo->sortby == 'user')
2575                        {
2576                                // event needs to show up in rows of all participants that are also owners
2577                                //
2578                                reset($this->planner_group_members);
2579                                while(list($user_name,$id) = each($this->planner_group_members))
2580                                {
2581                                        $status = $event['participants'][$id];
2582
2583                                        if (isset($status) && $status != 'R')
2584                                        {
2585                                                $this->planner_update_row($user_name,$user_name,$event,$cat,$start_cell,$end_cell);
2586                                        }
2587                                }
2588                        }
2589                }
2590
2591                function planner_pad_rows()
2592                {
2593                        $rows = &$this->planner_rows;
2594
2595                        if ($this->bo->sortby == 'user')
2596                        {
2597                                // add empty rows for users that do not participante in any event
2598                                //
2599                                reset($this->planner_group_members);
2600                                while(list($user_name,$id) = each($this->planner_group_members))
2601                                {
2602                                        $k  = $user_name.'_1';
2603                                        $ka = '.nr_'.$k;
2604
2605                                        if (!isset($rows[$k]))
2606                                        {
2607                                                $rows[$k]['_name'] = $user_name;
2608                                                $rows[$k]['._name'] .= ' nowrap';
2609                                                $rows[$ka] = 0;
2610                                        }
2611                                }
2612                        }
2613
2614                        // fill the remaining cols
2615                        //
2616                        $last_cell = $this->bo->prefs['calendar']['planner_intervals_per_day'] * $this->planner_days - 1;
2617
2618                        ksort($rows);
2619                        while (list($k,$r) = each($rows))
2620                        {
2621                                if (is_array($r))
2622                                {
2623                                        $rows['.'.$k] = 'bgcolor="'.$GLOBALS['phpgw']->nextmatchs->alternate_row_color().'"';
2624                                        $row = &$rows[$k];
2625                                        $akt_cell = &$rows['.nr_'.$k];
2626                                        if ($akt_cell < $last_cell)
2627                                        {
2628                                                $row['3'] = '&nbsp';
2629                                                $row['.3'] = 'colspan="'.(1+$last_cell-$akt_cell).'"';
2630                                        }
2631                                }
2632                        }
2633                }
2634
2635                function planner_print_rows()
2636                {
2637                        $bgcolor = 'bgcolor="'.$this->theme['th_bg'].'"';
2638                        $intervals_per_day = $this->bo->prefs['calendar']['planner_intervals_per_day'];
2639
2640                        if ($this->debug)
2641                        {
2642                                _debug_array($this->planner_rows);
2643                                reset($this->planner_rows);
2644                        }
2645                        return $this->html->table(
2646                                array(
2647                                        '_hdr0' => $this->planner_header[0],
2648                                        '._hdr0' => $bgcolor,
2649                                        '_hdr1' => $this->planner_header[1],
2650                                        '._hdr1' => $bgcolor,
2651                                        '_hdr2' => $this->planner_header[2],
2652                                        '._hdr2' => $bgcolor
2653                                )+$this->planner_rows,
2654                                'width="100%" cols="'.(1+$this->planner_days_in_end_month*$intervals_per_day).'"');
2655                }
2656
2657                function planner_process_interval()
2658                {
2659                        // generate duplicate free list of events within observed interval
2660                        //
2661                        $this->bo->store_to_cache(
2662                                Array(
2663                                        'syear' => $this->bo->year,
2664                                        'smonth'        => $this->bo->month,
2665                                        'sday'  => 1,
2666                                        'eyear' => $this->planner_end_year,
2667                                        'emonth'        => $this->planner_end_month,
2668                                        'eday'  => $this->planner_days_in_end_month
2669                                )
2670                        );
2671                        $this->bo->remove_doubles_in_cache($this->planner_firstday,$this->planner_lastday);
2672
2673                        // process all events within observed interval
2674                        //
2675                        for($v=$this->planner_firstday;$v<=$this->planner_lastday;$v++)
2676                        {
2677                                $daily = $this->bo->cached_events[$v];
2678
2679                                print_debug('For Date',$v);
2680                                print_debug('Count of items',count($daily));
2681
2682                                // process all events on day $v
2683                                //
2684                                if (is_array($daily)) foreach($daily as $event)
2685                                {
2686                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
2687                                        {
2688                                                $this->bo->set_recur_date($event,$v);
2689                                        }
2690                                        if (!$this->bo->rejected_no_show($event))
2691                                        {
2692                                                $this->planner_process_event($event);
2693                                        }
2694                                }
2695                        }
2696                        $this->planner_pad_rows();
2697                }
2698
2699                function matrixselect()
2700                {
2701                        $datetime = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
2702
2703                        $sb = CreateObject('phpgwapi.sbox');
2704
2705                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2706                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2707                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2708                        $GLOBALS['phpgw']->common->phpgw_header();
2709
2710                        $p = &$GLOBALS['phpgw']->template;
2711                        $p->set_file(
2712                                Array(
2713                                        'mq'            => 'matrix_query.tpl',
2714                                        'form_button'   => 'form_button_script.tpl'
2715                                )
2716                        );
2717                        $p->set_block('mq','matrix_query','matrix_query');
2718                        $p->set_block('mq','list','list');
2719
2720                        $p->set_var(array(
2721                                'title'                 => lang('Daily Matrix View'),
2722                                'th_bg'                 => $this->theme['th_bg'],
2723                                'action_url'    => $this->page('viewmatrix')
2724                        ));
2725
2726// Date
2727                        $var[] = Array(
2728                                'field' =>      lang('Date'),
2729                                'data'  =>      $GLOBALS['phpgw']->common->dateformatorder(
2730                                        $sb->getYears('year',(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y'),(int)$GLOBALS['phpgw']->common->show_date($datetime,'Y')),
2731                                        $sb->getMonthText('month',(int)$GLOBALS['phpgw']->common->show_date($datetime,'n')),
2732                                        $sb->getDays('day',(int)$GLOBALS['phpgw']->common->show_date($datetime,'d'))
2733                                )
2734                        );
2735
2736// View type
2737                        $var[] = Array(
2738                                'field' =>      lang('View'),
2739                                'data'  =>      '<select name="matrixtype">'."\n"
2740                                        . '<option value="free/busy" selected>'.lang('free/busy').'</option>'."\n"
2741                                        . '<option value="weekly">'.lang('Weekly').'</option>'."\n"
2742                                        . '</select>'."\n"
2743                        );
2744
2745// Participants
2746                        $accounts = $GLOBALS['phpgw']->acl->get_ids_for_location('run',1,'calendar');
2747                        $users = Array();
2748                        for($i=0;$i<count($accounts);$i++)
2749                        {
2750                                $user = $accounts[$i];
2751                                if(!isset($users[$user]))
2752                                {
2753                                        $users[$user] = $GLOBALS['phpgw']->common->grab_owner_name($user);
2754                                        if($GLOBALS['phpgw']->accounts->get_type($user) == 'g')
2755                                        {
2756                                                $group_members = $GLOBALS['phpgw']->acl->get_ids_for_location($user,1,'phpgw_group');
2757                                                if($group_members != False)
2758                                                {
2759                                                        for($j=0;$j<count($group_members);$j++)
2760                                                        {
2761                                                                if(!isset($users[$group_members[$j]]))
2762                                                                {
2763                                                                        $users[$group_members[$j]] = $GLOBALS['phpgw']->common->grab_owner_name($group_members[$j]);
2764                                                                }
2765                                                        }
2766                                                }
2767                                        }
2768                                }
2769                        }
2770
2771                        $num_users = count($users);
2772
2773                        if ($num_users > 50)
2774                        {
2775                                $size = 15;
2776                        }
2777                        elseif ($num_users > 5)
2778                        {
2779                                $size = 5;
2780                        }
2781                        else
2782                        {
2783                                $size = $num_users;
2784                        }
2785                        $str = '';
2786                        @asort($users);
2787                        @reset($users);
2788                        while ($user = each($users))
2789                        {
2790                                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')
2791                                {
2792                                        $str .= '    <option value="'.$user[0].'">('.$GLOBALS['phpgw']->accounts->get_type($user[0]).') '.$user[1].'</option>'."\n";
2793                                }
2794                        }
2795                        $var[] = Array(
2796                                'field' =>      lang('Participants'),
2797                                'data'  =>      "\n".'   <select name="participants[]" multiple size="'.$size.'">'."\n".$str.'   </select>'."\n"
2798                        );
2799
2800                        for($i=0;$i<count($var);$i++)
2801                        {
2802                                $this->output_template_array($p,'rows','list',$var[$i]);
2803                        }
2804
2805                        $vars = Array(
2806                                'submit_button'         => lang('View'),
2807                                'action_url_button'     => $this->bo->return_to ? $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to) : $this->page(''),
2808                                'action_text_button'    => lang('Cancel'),
2809                                'action_confirm_button' => '',
2810                                'action_extra_field'    => ''
2811                        );
2812
2813                        $p->set_var($vars);
2814                        $p->parse('cancel_button','form_button');
2815                        $p->pparse('out','matrix_query');
2816                }
2817
2818                function viewmatrix()
2819                {
2820                        if ($_POST['cancel'])
2821                        {
2822                                $this->index();
2823                        }
2824                        $participants = $_POST['participants'];
2825                        $parts = Array();
2826                        $acct = CreateObject('phpgwapi.accounts',$this->bo->owner);
2827
2828                        if (is_array($participants))
2829                        {
2830                                foreach($participants as $participant)
2831                                {
2832                                        switch ($GLOBALS['phpgw']->accounts->get_type($participant))
2833                                        {
2834                                                case 'g':
2835                                                        if ($members = $acct->member((int)$participant))
2836                                                        {
2837                                                                foreach($members as $member)
2838                                                                {
2839                                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$member['account_id']))
2840                                                                        {
2841                                                                                $parts[$member['account_id']] = True;
2842                                                                        }
2843                                                                }
2844                                                        }
2845                                                        break;
2846                                                case 'u':
2847                                                        if($this->bo->check_perms(PHPGW_ACL_READ,0,$participant))
2848                                                        {
2849                                                                $parts[$participant] = 1;
2850                                                        }
2851                                                        break;
2852                                        }
2853                                }
2854                                unset($acct);
2855                        }
2856                        $participants = array_keys($parts);     // get id's as values and a numeric index
2857
2858                        // Defined - into session - who participates
2859                        $GLOBALS['phpgw']->session->appsession("participants", NULL, implode(";", $participants));
2860
2861                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2862                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2863                        if ($this->always_app_header) $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Matrixview');
2864                        $GLOBALS['phpgw']->common->phpgw_header();
2865
2866                        switch($_POST['matrixtype'])
2867                        {
2868                                case 'free/busy':
2869                                        $freetime = $GLOBALS['phpgw']->datetime->gmtdate(mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year));
2870                                        echo '<br>'.$this->timematrix(
2871                                                Array(
2872                                                        'date'          => $freetime,
2873                                                        'starttime'     => $this->bo->splittime('000000',False),
2874                                                        'endtime'       => 0,
2875                                                        'participants'  => $parts
2876                                                )
2877                                        );
2878                                        break;
2879                                case 'weekly':
2880                                        echo '<br>'.$this->display_weekly(
2881                                                Array(
2882                                                        'date'          => sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day),
2883                                                        'showyear'      => true,
2884                                                        'owners'        => $participants
2885                                                )
2886                                        );
2887                                        break;
2888                        }
2889                        echo "\n<br>\n".'<form action="'.$this->page('viewmatrix').'" method="post" name="matrixform">'."\n";
2890                        echo ' <table cellpadding="5"><tr><td>'."\n";
2891                        echo '  <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
2892                        echo '  <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
2893                        echo '  <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
2894                        echo '  <input type="hidden" name="matrixtype" value="'.$_POST['matrixtype'].'">'."\n";
2895                        foreach($participants as $part)
2896                        {
2897                                echo '  <input type="hidden" name="participants[]" value="'.$part.'">'."\n";
2898                        }
2899                        echo '  <input type="submit" name="refresh" value="'.lang('Refresh').'">'."\n";
2900                        echo ' </td><td>'."\n";
2901                        echo '  <input type="submit" name="cancel" value="'.lang('Cancel').'">'."\n";
2902                        echo ' </td></tr></table>'."\n";
2903                        echo '</form>'."\n";
2904                }
2905
2906                function search()
2907                {
2908                        if (empty($_POST['keywords']))
2909                        {
2910                                // If we reach this, it is because they didn't search for anything
2911                                // or they used one of the selectboxes (year, month, week) in the search-result
2912                                // attempt to send them back to where they came from.
2913
2914                                $vars['menuaction'] = isset($_POST['from']) && $_POST['from'] != 'calendar.uicalendar.search' ?
2915                                        $_POST['from'] : 'calendar.uicalendar.index';
2916
2917                                foreach(array('date','year','month','day') as $field)
2918                                {
2919                                        if (isset($_POST[$field]))
2920                                        {
2921                                                $vars[$field] = $_POST[$field];
2922                                        }
2923                                }
2924                                $GLOBALS['phpgw']->redirect_link('/index.php',$vars);
2925                        }
2926
2927                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
2928                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
2929                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Search Results');
2930                        $GLOBALS['phpgw']->common->phpgw_header();
2931
2932                        $error = '';
2933
2934                        $matches = 0;
2935
2936                        // There is currently a problem searching in with repeated events.
2937                        // It spits back out the date it was entered.  I would like to to say that
2938                        // it is a repeated event.
2939
2940                        // This has been solved by the little icon indicator for recurring events.
2941
2942                        $event_ids = $this->bo->search_keywords($_POST['keywords']);
2943                        foreach($event_ids as $key => $id)
2944                        {
2945                                $event = $this->bo->read_entry($id);
2946
2947                                if(!$this->bo->check_perms(PHPGW_ACL_READ,$event))
2948                                {
2949                                        continue;
2950                                }
2951
2952                                $datetime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
2953
2954                                $info[strval($event['id'])] = array(
2955                                        'tr_color'      => $GLOBALS['phpgw']->nextmatchs->alternate_row_color(),
2956                                        'date'          => $GLOBALS['phpgw']->common->show_date($datetime),
2957                                        'link'          => $this->link_to_entry($event,$event['start']['month'],$event['start']['mday'],$event['start']['year'])
2958                                );
2959
2960                        }
2961                        $matches = count($event_ids);
2962
2963                        if ($matches == 1)
2964                        {
2965                                $quantity = lang('1 match found').'.';
2966                        }
2967                        elseif ($matches > 0)
2968                        {
2969                                $quantity = lang('%1 matches found',$matches).'.';
2970                        }
2971                        else
2972                        {
2973                                echo '<b>'.lang('Error').':</b>'.lang('no matches found');
2974                                return;
2975                        }
2976
2977                        $p = $GLOBALS['phpgw']->template;
2978                        $p->set_file(
2979                                Array(
2980                                        'search_form'   => 'search.tpl'
2981                                )
2982                        );
2983                        $p->set_block('search_form','search','search');
2984                        $p->set_block('search_form','search_list_header','search_list_header');
2985                        $p->set_block('search_form','search_list','search_list');
2986                        $p->set_block('search_form','search_list_footer','search_list_footer');
2987
2988                        $var = Array(
2989                                'th_bg'         => $this->theme['th_bg'],
2990                                'search_text'   => lang('Search Results'),
2991                                'quantity'      => $quantity
2992                        );
2993                        $p->set_var($var);
2994
2995                        if($matches > 0)
2996                        {
2997                                $p->parse('rows','search_list_header',True);
2998                        }
2999                        foreach($info as $id => $data)
3000                        {
3001                                $p->set_var($data);
3002                                $p->parse('rows','search_list',True);
3003                        }
3004
3005                        if($matches > 0)
3006                        {
3007                                $p->parse('rows','search_list_footer',True);
3008                        }
3009
3010                        $p->pparse('out','search');
3011                }
3012
3013                /* Private functions */
3014                function _debug_sqsof()
3015                {
3016                        $data = array(
3017                                'filter'     => $this->bo->filter,
3018                                'cat_id'     => $this->bo->cat_id,
3019                                'owner'      => $this->bo->owner,
3020                                'year'       => $this->bo->year,
3021                                'month'      => $this->bo->month,
3022                                'day'        => $this->bo->day,
3023                                'sortby'     => $this->bo->sortby,
3024                                'num_months' => $this->bo->num_months
3025                        );
3026                        Return _debug_array($data,False);
3027                }
3028
3029                function output_template_array(&$p,$row,$list,$var)
3030                {
3031                        if (!isset($var['hidden_vars']))
3032                        {
3033                                $var['hidden_vars'] = '';
3034                        }
3035                        if (!isset($var['tr_color']))
3036                        {
3037                                $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color();
3038                        }
3039                        $p->set_var($var);
3040                        $p->parse($row,$list,True);
3041                }
3042
3043                function page($_page='',$params='')
3044                {
3045                        if($_page == '')
3046                        {
3047                                $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']);
3048                                $_page = $page_[0];
3049
3050                                if ($_page=='planner_cat' || $_page=='planner_user')
3051                                {
3052                                        $_page = 'planner';
3053                                }
3054                                elseif ($_page=='index' || ($_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner'))
3055                                {
3056                                        $_page = 'month';
3057                                        $GLOBALS['phpgw']->preferences->add('calendar','defaultcalendar','month');
3058                                        $GLOBALS['phpgw']->preferences->save_repository();
3059                                }
3060                        }
3061                        if($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' ||
3062                                strstr($GLOBALS['phpgw_info']['flags']['currentapp'],'mail'))   // email, felamimail, ...
3063                        {
3064                                $page_app = 'calendar';
3065                        }
3066                        else
3067                        {
3068                                $page_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
3069                        }
3070                        if (is_array($params))
3071                        {
3072                                $params['menuaction'] = $page_app.'.ui'.$page_app.'.'.$_page;
3073                        }
3074                        else
3075                        {
3076                                $params = 'menuaction='.$page_app.'.ui'.$page_app.'.'.$_page.$params;
3077                        }
3078                        return $GLOBALS['phpgw']->link('/index.php',$params);
3079                }
3080
3081                function header()
3082                {
3083                        $cols = 8;
3084                        if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True)
3085                        {
3086                                $cols++;
3087                        }
3088
3089                        $tpl = $GLOBALS['phpgw']->template;
3090                        $tpl->set_unknowns('remove');
3091
3092                        if (!file_exists($file = $this->template_dir.'/header.inc.php'))
3093                        {
3094                                $file = PHPGW_SERVER_ROOT . '/calendar/templates/default/header.inc.php';
3095                        }
3096                       
3097                        include($file);
3098                        $refer = explode('.',$GLOBALS['HTTP_GET_VARS']['menuaction']);
3099                        if($refer[2] != 'view') {
3100                        $header = $tpl->fp('out','head');
3101                        unset($tpl);
3102                        echo $header;
3103                }
3104                        unset($tpl);
3105                }
3106
3107                function footer()
3108                {
3109                        $menuaction = $_GET['menuaction'];
3110                        list(,,$method) = explode('.',$menuaction);
3111
3112                        if (@$this->bo->printer_friendly)
3113                        {
3114                                return;
3115                        }
3116
3117                        $p = $GLOBALS['phpgw']->template;
3118
3119                        $p->set_file(
3120                                Array(
3121                                        'footer'        => 'footer.tpl',
3122                                        'form_button'   => 'form_button_script.tpl'
3123                                )
3124                        );
3125                        $p->set_block('footer','footer_table','footer_table');
3126                        $p->set_block('footer','footer_row','footer_row');
3127                        $p->set_block('footer','blank_row','blank_row');
3128                        $p->set_block('footer','num_dias','num_dias');
3129
3130                        $m = $this->bo->month;
3131                        $y = $this->bo->year;
3132
3133                        $hoje = date('Ymd',$GLOBALS['phpgw']->datetime->gmtnow);
3134                        $mes_hoje = (int)substr($hoje,4,2);
3135                        $mes_footer = (int)substr($_POST['date'],4,2);
3136                        if($_GET['sday'])
3137                        {
3138                                if($_GET['month'] == $mes_hoje)
3139                                {
3140                                        $day = $this->bo->day;
3141                                }
3142                                else
3143                                {
3144                                        $day = $_GET['sday'];
3145                                }
3146                        }
3147                        else
3148                        {
3149                                $day = $this->bo->day;
3150                                $dia_ini = $day;
3151                        }
3152                        if($mes_footer == $mes_hoje)
3153                        {
3154                                $dia_ini = (int)substr($hoje,6,2);
3155                                $day = $dia_ini;
3156                        }
3157                        /********************************************************************************************/
3158                        /* Bloco adicionado para receber o dia a partir do qual a versao para impressao sera gerada */
3159                        $str_ini = '';
3160                        for ($i = 1; $i <= ($GLOBALS['phpgw']->datetime->days_in_month($m, $y)); $i++)
3161                        {
3162                                $str_ini .= '<option value="'.$i.'"'.($i == $day?' selected':'').'>'.$i.'</option>'."\n";
3163                        }
3164                        $str_qtd = '<option value="'.''.'"'.($i == $_POST['qtd_dias']?' selected':'').'>'.''.'</option>'."\n";
3165                        for ($i = 1; $i <= 45; $i++)
3166                        {
3167                                $str_qtd .= '<option value="'.$i.'"'.($i == $_POST['qtd_dias']?' selected':'').'>'.$i.'</option>'."\n";
3168                        }
3169                        $display = '';
3170                        $display_view = '';
3171                        if ( ($menuaction == 'calendar.uicalendar.week') || ($menuaction == 'calendar.uicalendar.day') )
3172                        {
3173                                $display = 'none';
3174                        }
3175                        else if( ($menuaction == 'calendar.uicalendar.view') )
3176                        {
3177                                $display = 'none';
3178                                $display_view = 'none';
3179                        }
3180                        $var = Array(
3181                                'acao'                  => $this->page($method,''),
3182                                'formname'              => 'SelectDay',
3183                                'formonchange'          => 'document.SelectDay.submit()',
3184                                'day_ini_label'         => lang('print starting in'),
3185                                'num_dias_label'        => lang('quantity of days'),
3186                                'tip'                   => lang('empty prints from the day chosen below to the end of the current month'),
3187                                'day_ini_name'          => 'day',
3188                                'num_dias_name'         => 'qtd_dias',
3189                                'row_ini'               => $str_ini,
3190                                'row_qtd'               => $str_qtd,
3191                                'display'               => $display,
3192                                'display_view'          => $display_view,
3193                                'go'                    => lang('Go!')
3194                                );
3195                        $this->output_template_array($p,'table_row','num_dias',$var);
3196                       
3197                        /********************************************************************************************/
3198
3199                        $thisdate = date('Ymd',mktime(0,0,0,$m,1,$y));
3200                        $y--;
3201
3202                        $str = '';
3203                        for ($i = 0; $i < 20; $i++)
3204                        {
3205                                $m++;
3206                                if ($m > 12)
3207                                {
3208                                        $m = 1;
3209                                        $y++;
3210                                }
3211                                $d = mktime(0,0,0,$m,1,$y);
3212                                $d_ymd = date('Ymd',$d);
3213                                $str .= '<option value="'.$d_ymd.'"'.($d_ymd == $thisdate?' selected':'').'>'.lang(date('F', $d)).strftime(' %Y', $d).'</option>'."\n";
3214                        }
3215
3216                        $var = Array(
3217                                'action_url'    => $this->page($method,''),
3218                                'form_name'     => 'SelectMonth',
3219                                'label'         => lang('Month'),
3220                                'form_label'    => 'date',
3221                                'form_onchange' => 'document.SelectMonth.submit()',
3222                                'row'           => $str,
3223                                'dia_ini'       => $dia_ini,
3224                                'go'            => lang('Go!')
3225                        );
3226                        $this->output_template_array($p,'table_row','footer_row',$var);
3227
3228                        if($menuaction == 'calendar.uicalendar.week')
3229                        {
3230                                unset($thisdate);
3231                                $thisdate = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
3232                                $sun = $GLOBALS['phpgw']->datetime->get_weekday_start($this->bo->year,$this->bo->month,$this->bo->day) - $GLOBALS['phpgw']->datetime->tz_offset;
3233
3234                                $str = '';
3235                                for ($i = -7; $i <= 7; $i++)
3236                                {
3237                                        $begin = $sun + (7*24*60*60 * $i) + 12*60*60;   // we use midday, that changes in daylight-saveing does not effect us
3238                                        $end = $begin + 6*24*60*60;
3239//                                      echo "<br>$i: ".date('d.m.Y H:i',$begin).' - '.date('d.m.Y H:i',$end);
3240                    $str .= '<option value="' . $GLOBALS['phpgw']->common->show_date($begin,'Ymd') . '"'.($begin <= $thisdate+12*60*60 && $end >= $thisdate+12*60*60 ? ' selected':'').'>'                   
3241                                                . $GLOBALS['phpgw']->common->show_date($begin,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) . ' - '
3242                        . $GLOBALS['phpgw']->common->show_date($end,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
3243                        . '</option>' . "\n";                       
3244                                }
3245
3246                                $var = Array(
3247                                        'action_url'    => $this->page($method,''),
3248                                        'form_name'     => 'SelectWeek',
3249                                        'label'         => lang('Week'),
3250                                        'form_label'    => 'date',
3251                                        'form_onchange' => 'document.SelectWeek.submit()',
3252                                        'row'           => $str,
3253                                        'go'            => lang('Go!')
3254                                );
3255
3256                                $this->output_template_array($p,'table_row','footer_row',$var);
3257                        }
3258
3259                        $str = '';
3260                        for ($i = ($this->bo->year - 3); $i < ($this->bo->year + 3); $i++)
3261                        {
3262                                $str .= '<option value="'.$i.'"'.($i == $this->bo->year?' selected':'').'>'.$i.'</option>'."\n";
3263                        }
3264
3265                        $var = Array(
3266                                'action_url'    => $this->page($method,''),
3267                                'form_name'     => 'SelectYear',
3268                                'label'         => lang('Year'),
3269                                'form_label'    => 'year',
3270                                'form_onchange' => 'document.SelectYear.submit()',
3271                                'row'           => $str,
3272                                'go'            => lang('Go!')
3273                        );
3274                        $this->output_template_array($p,'table_row','footer_row',$var);
3275
3276                        if($menuaction == 'calendar.uicalendar.planner')
3277                        {
3278                                $str = '';
3279                                $date_str = '';
3280
3281                                if(isset($_GET['date']) && $_GET['date'])
3282                                {
3283                                        $date_str .= '    <input type="hidden" name="date" value="'.$_GET['date'].'">'."\n";
3284                                }
3285                                $date_str .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
3286                                $date_str .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
3287                                $date_str .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
3288
3289                                for($i=1; $i<=6; $i++)
3290                                {
3291                                        $str .= '<option value="'.$i.'"'.($i == $this->bo->num_months?' selected':'').'>'.$i.'</option>'."\n";
3292                                }
3293
3294                                $var = Array(
3295                                        'action_url'    => $this->page($method,''),
3296                                        'form_name'     => 'SelectNumberOfMonths',
3297                                        'label'         => lang('Number of Months'),
3298                                        'hidden_vars' => $date_str,
3299                                        'form_label'    => 'num_months',
3300                                        'form_onchange' => 'document.SelectNumberOfMonths.submit()',
3301                                        'action_extra_field'    => $date_str,
3302                                        'row'           => $str,
3303                                        'go'            => lang('Go!')
3304                                );
3305                                $this->output_template_array($p,'table_row','footer_row',$var);
3306                        }
3307
3308                        $var = Array(
3309                                'submit_button'         => lang('Submit'),
3310                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uiicalendar.import'),
3311                                'action_text_button'    => lang('Import'),
3312                                'action_confirm_button' => '',
3313                                'action_extra_field'    => ''
3314                        );
3315                        $this->output_template_array($p,'b_row','form_button',$var);
3316                       
3317                        $var = Array(
3318                                'submit_button'         => lang('Submit'),
3319                                'action_url'    => $this->page($method,''),
3320                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.export_all'),
3321                                'action_text_button'    => lang('Export all'),
3322                                'action_confirm_button' => '',
3323                                'action_extra_field'    => ''
3324                        );
3325                        $this->output_template_array($p,'b_row2','form_button',$var);
3326                                       
3327                        $p->parse('table_row','blank_row',True);
3328
3329                        $p->pparse('out','footer_table');
3330                        unset($p);
3331                }
3332
3333                function css()
3334                {
3335                        $GLOBALS['phpgw']->browser->browser();
3336                        if($GLOBALS['phpgw']->browser->get_agent() == 'MOZILLA')
3337                        {
3338                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?12:8);
3339                        }
3340                        else
3341                        {
3342                                $time_width = ((int)($this->bo->prefs['common']['time_format']) == 12?10:7);
3343                        }
3344
3345// moved to app.css in templates/default for future separation of code and style [NDEE 10.03.04]
3346/*
3347                         return 'A.minicalendar { color: #000000; font-size: 72%; font-family: '.$this->theme['font'].' }'."\n"
3348                                . '  A.bminicalendar { color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3349                                . '  A.minicalendargrey { color: #999999; font-size: 8px; font-family: '.$this->theme['font'].' }'."\n"
3350                                . '  A.bminicalendargrey { color: #336699; font-style: italic; font-size:8px; font-family '.$this->theme['font'].' }'."\n"
3351                                . '  A.minicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #000000; font: x-small '.$this->theme['font'].' }'."\n"
3352                                . '  A.bminicalhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #336699; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3353                                . '  A.minicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: x-small '.$this->theme['font'].' }'."\n"
3354                                . '  A.bminicalgreyhol { padding-left:3px; padding-right:3px; background: '.$this->holiday_color.'; color: #999999; font: italic bold x-small '.$this->theme['font'].' }'."\n"
3355                                . '  .event-on { background: '.$this->theme['row_on'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3356                                . '  .event-off { background: '.$this->theme['row_off'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3357                                . '  .event-holiday { background: '.$this->theme['bg04'].'; color: '.$this->theme['bg_text'].'; font: 100% '.$this->theme['font'].'; vertical-align: middle }'."\n"
3358                                . '  .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"
3359                                . '  .tablecell { width: 80px; height: 80px }'."\n"
3360                                . '  .planner-cell { cursor:pointer; cursor:hand; border: thin solid black; }';
3361*/
3362                }
3363
3364                function no_edit()
3365                {
3366                        if(!isset($GLOBALS['phpgw_info']['flags']['noheader']))
3367                        {
3368                                unset($GLOBALS['phpgw_info']['flags']['noheader']);
3369                                unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3370                                $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3371                                $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3372                                $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Permission denied');
3373                                $GLOBALS['phpgw']->common->phpgw_header();
3374                        }
3375                        echo '<center>You do not have permission to edit this appointment!</center>';
3376                        return;
3377                }
3378
3379                function link_to_entry($event,$month,$day,$year)
3380                {
3381                        $str = '';
3382                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
3383                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
3384
3385                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
3386                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3387                        $rawdate = mktime(0,0,0,$month,$day,$year);
3388                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
3389                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3390                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
3391                        {
3392                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3393                        }
3394                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
3395                        {
3396                                $time = '[ '.lang('All Day').' ]';
3397                        }
3398                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
3399                        {
3400                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
3401                                {
3402                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
3403                                }
3404                                else
3405                                {
3406                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3407                                }
3408
3409                                if($endtime >= ($rawdate_offset + 86400))
3410                                {
3411                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
3412                                }
3413                                else
3414                                {
3415                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
3416                                }
3417                                $time = $start_time.'-'.$end_time;
3418                        }
3419                        else
3420                        {
3421                                $time = '';
3422                        }
3423                       
3424                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
3425
3426                       
3427                       
3428                        if(!$is_private)
3429                        {
3430                                //$text .= $this->bo->display_status($event['users_status']);
3431                               
3432                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
3433                                $textstatus=$this->bo->display_status($event['users_status']);
3434                               
3435                        }
3436
3437                        /*
3438                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
3439                                (!$is_private && $event['description'] ? ': <i>'.$this->bo->get_short_field($event,$is_private,'description').'</i>':'').
3440                                $GLOBALS['phpgw']->browser->br;
3441                        */
3442                       
3443                        $texttime=$time;
3444                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
3445
3446                        $account_name = $_POST['user'] ?
3447                                                        $_POST['user'] :
3448                                                        ($_GET['account_name'] ?
3449                                                         $_GET['account_name'] : '');
3450
3451                        $accounts = CreateObject('phpgwapi.accounts');
3452                        $accountId = $accounts->name2id($account_name);
3453
3454                        $prefs = CreateObject('phpgwapi.preferences', $accountId);
3455                        $account_prefs = $prefs->read();
3456
3457                        $titleView = $account_prefs['calendar']['title_view'];
3458                        if($titleView == "1"){
3459                                $textdesc = '';
3460                        }else{
3461                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
3462                        }
3463
3464                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
3465                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
3466
3467                        if ($viewable)
3468                        {
3469                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
3470                                $this->link_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
3471                                $this->link_tpl->set_var('lang_view',lang('View this entry'));
3472                                $this->link_tpl->set_var('desc', $textdesc);
3473                                $this->link_tpl->set_var('location', $textlocation);
3474                                $this->link_tpl->parse('picture','link_open',True);
3475                        }
3476                        if (!$is_private)
3477                        {
3478                                if($event['priority'] == 3)
3479                                {
3480                                        $picture[] = Array(
3481                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
3482                                                'width' => 16,
3483                                                'height'=> 16,
3484                                                'title' => lang('high priority')
3485                                        );
3486                                }
3487                                if($event['recur_type'] == MCAL_RECUR_NONE)
3488                                {
3489                                        $picture[] = Array(
3490                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
3491                                                'width' => 9,
3492                                                'height'=> 9,
3493                                                'title' => lang('single event')
3494                                        );
3495                                }
3496                                else
3497                                {
3498                                        $picture[] = Array(
3499                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
3500                                                'width' => 12,
3501                                                'height'=> 12,
3502                                                'title' => lang('recurring event')
3503                                        );
3504                                }
3505                        }
3506                        $participants = $this->planner_participants($event['participants']);
3507                        if(count($event['participants']) > 1)
3508                        {
3509                                $picture[] = Array(
3510                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
3511                                        'width' => 14,
3512                                        'height'=> 14,
3513                                        'title' => $participants
3514                                );
3515                        }
3516                        else
3517                        {
3518                                $picture[] = Array(
3519                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
3520                                        'width' => 14,
3521                                        'height'=> 14,
3522                                        'title' => $participants
3523                                );
3524                        }
3525                        if($event['public'] == 0)
3526                        {
3527                                $picture[] = Array(
3528                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
3529                                        'width' => 13,
3530                                        'height'=> 13,
3531                                        'title' => lang('private')
3532                                );
3533                        }
3534                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
3535                        {
3536                                // if the alarm is to go off the day before the event
3537                                // the icon does not show up because of 'alarm_today'
3538                                // - TOM
3539                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
3540                                {
3541                                        $picture[] = Array(
3542                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
3543                                                'width' => 13,
3544                                                'height'=> 13,
3545                                                'title' => lang('alarm')
3546                                        );
3547                                }
3548                        }
3549
3550                        $description = $this->bo->get_short_field($event,$is_private,'description');
3551                        for($i=0;$i<count($picture);$i++)
3552                        {
3553                                $var = Array(
3554                                        'pic_image' => $picture[$i]['pict'],
3555                                        'width'     => $picture[$i]['width'],
3556                                        'height'    => $picture[$i]['height'],
3557                                        'title'     => $picture[$i]['title']
3558                                );
3559                                $this->output_template_array($this->link_tpl,'picture','pict',$var);
3560                        }
3561                        if ($texttitle)
3562                        {
3563                                $var = Array(
3564                        //              'text' => $text,
3565                                        'time'=> $texttime,
3566                                        'title'=> $texttitle,
3567                                        'users_status'=>$textstatus,
3568                                        'desc'=> $textdesc,
3569                                        'location'=> "<br><b>Local:</b> ".$textlocation
3570                                );
3571                                $this->output_template_array($this->link_tpl,'picture','link_text',$var);
3572                        }
3573
3574                        if ($viewable)
3575                        {
3576                                $this->link_tpl->parse('picture','link_close',True);
3577                        }
3578                        $str = $this->link_tpl->fp('out','link_pict');
3579                        $this->link_tpl->set_var('picture','');
3580                        $this->link_tpl->set_var('out','');
3581//                      unset($p);
3582                        return $str;
3583                }
3584
3585/*****************************************************************************************/
3586/*Funcao foi duplicada e alterada para tratar os eventos de agendamento (exibicao do mes) para impressao;
3587utiliza o template event_link.tpl*/
3588
3589                function link_to_month_entry($event,$month,$day,$year)
3590                {
3591                        $str = '';
3592                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
3593                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
3594
3595                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
3596                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3597                        $rawdate = mktime(0,0,0,$month,$day,$year);
3598                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
3599                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3600                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
3601                        {
3602                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3603                        }
3604                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
3605                        {
3606                                $time = '[ '.lang('All Day').' ]';
3607                        }
3608                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
3609                        {
3610                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
3611                                {
3612                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
3613                                }
3614                                else
3615                                {
3616                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
3617                                }
3618
3619                                if($endtime >= ($rawdate_offset + 86400))
3620                                {
3621                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
3622                                }
3623                                else
3624                                {
3625                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
3626                                }
3627                                $time = $start_time.' - '.$end_time;
3628                        }
3629                        else
3630                        {
3631                                $time = '';
3632                        }
3633                       
3634                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
3635
3636                       
3637                       
3638                        if(!$is_private)
3639                        {
3640                                //$text .= $this->bo->display_status($event['users_status']);
3641                               
3642                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
3643                                $textstatus=$this->bo->display_status($event['users_status']);
3644                               
3645                        }
3646
3647                        $text = '<nobr>&nbsp;'.$time.'&nbsp;</nobr> '.$this->bo->get_short_field($event,$is_private,'title').$text.
3648                       
3649                        $texttime=$time;
3650                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
3651                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
3652                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
3653                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
3654
3655                        if ($viewable)
3656                        {
3657                                $date = sprintf('%04d%02d%02d',$year,$month,$day);
3658                                $this->event_tpl->set_var('link_link',$this->page('view','&cal_id='.$event['id'].'&date='.$date));
3659                                $this->event_tpl->set_var('lang_view',lang('View this entry'));
3660                                $this->event_tpl->set_var('desc', $textdesc);
3661                                $this->event_tpl->set_var('location', $textlocation);
3662                                $this->event_tpl->parse('picture','link_event_open',True);
3663                        }
3664                        if (!$is_private)
3665                        {
3666                                if($event['priority'] == 3)
3667                                {
3668                                        $picture[] = Array(
3669                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
3670                                                'width' => 16,
3671                                                'height'=> 16,
3672                                                'title' => lang('high priority')
3673                                        );
3674                                }
3675                                if($event['recur_type'] == MCAL_RECUR_NONE)
3676                                {
3677                                        $picture[] = Array(
3678                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
3679                                                'width' => 9,
3680                                                'height'=> 9,
3681                                                'title' => lang('single event')
3682                                        );
3683                                }
3684                                else
3685                                {
3686                                        $picture[] = Array(
3687                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
3688                                                'width' => 12,
3689                                                'height'=> 12,
3690                                                'title' => lang('recurring event')
3691                                        );
3692                                }
3693                        }
3694                        $participants = $this->planner_participants($event['participants']);
3695                        if(count($event['participants']) > 1)
3696                        {
3697                                $picture[] = Array(
3698                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
3699                                        'width' => 14,
3700                                        'height'=> 14,
3701                                        'title' => $participants
3702                                );
3703                        }
3704                        else
3705                        {
3706                                $picture[] = Array(
3707                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
3708                                        'width' => 14,
3709                                        'height'=> 14,
3710                                        'title' => $participants
3711                                );
3712                        }
3713                        if($event['public'] == 0)
3714                        {
3715                                $picture[] = Array(
3716                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
3717                                        'width' => 13,
3718                                        'height'=> 13,
3719                                        'title' => lang('private')
3720                                );
3721                        }
3722                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
3723                        {
3724                                // if the alarm is to go off the day before the event
3725                                // the icon does not show up because of 'alarm_today'
3726                                // - TOM
3727                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
3728                                {
3729                                        $picture[] = Array(
3730                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
3731                                                'width' => 13,
3732                                                'height'=> 13,
3733                                                'title' => lang('alarm')
3734                                        );
3735                                }
3736                        }
3737
3738                        $description = $this->bo->get_short_field($event,$is_private,'description');
3739                        for($i=0;$i<count($picture);$i++)
3740                        {
3741                                $var = Array(
3742                                        'pic_image' => $picture[$i]['pict'],
3743                                        'width'     => $picture[$i]['width'],
3744                                        'height'    => $picture[$i]['height'],
3745                                        'title'     => $picture[$i]['title']
3746                                );
3747                                $this->output_template_array($this->event_tpl,'picture','event_pict',$var);
3748                        }
3749                        if ($texttitle)
3750                        {
3751                                $var = Array(
3752                        //              'text' => $text,
3753                                        'time'=> $texttime,
3754                                        'title'=> $texttitle,
3755                                        'users_status'=>$textstatus,
3756                                        'desc'=> $textdesc,
3757                                        'location'=> "<br><b>Local:</b> ".$textlocation
3758                                );
3759                                $this->output_template_array($this->event_tpl,'picture','link_event_text',$var);
3760                        }
3761
3762                        if ($viewable)
3763                        {
3764                                $this->event_tpl->parse('picture','link_event_close',True);
3765                        }
3766                        $str = $this->event_tpl->fp('out','link_event_pict');
3767                        $this->event_tpl->set_var('picture','');
3768                        $this->event_tpl->set_var('out','');
3769//                      unset($p);
3770                        return $str;
3771                }
3772
3773/*****************************************************************************************/
3774                function normDec($num)
3775                {
3776                        if ($num > 9)
3777                                return $num;
3778                        else
3779                                return "0".$num;
3780                }
3781                function overlap($params)
3782                {
3783                        if(!is_array($params))
3784                        {
3785                        }
3786                        else
3787                        {
3788                                $overlapping_events = $params['o_events'];
3789                                $event = $params['this_event'];
3790                        }
3791
3792                        $month = $event['start']['month'];
3793                        $mday = $event['start']['mday'];
3794                        $year = $event['start']['year'];
3795
3796                        $start = mktime($event['start']['hour'],$event['start']['min'],$event['start']['sec'],$month,$mday,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
3797                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
3798
3799                        $overlap = '';
3800                        for($i=0;$i<count($overlapping_events);$i++)
3801                        {
3802                                $overlapped_event = $this->bo->read_entry($overlapping_events[$i],True);
3803                                foreach($overlapped_event['participants'] as $id => $status)
3804                                {
3805                                        $conflict = isset($event['participants'][$id]);
3806                                        $overlap .= '<li>'.($conflict?'<b>':'').
3807                                                $GLOBALS['phpgw']->common->grab_owner_name($id).
3808                                                ($conflict?'</b> - '.lang('Scheduling conflict'):'')."</li>";
3809                                }
3810                         if ($this->bo->prefs['calendar']['hide_event_conflict'])
3811                                 $overlap .= '<ul><font size="1"><span>'.
3812                                         $this->normDec($overlapped_event['start']['hour']).":".
3813                                         $this->normDec($overlapped_event['start']['min'])."-".
3814                                         $this->normDec($overlapped_event['end']['hour']).":".
3815                                         $this->normDec($overlapped_event['end']['min']).
3816                                         '<br><b>'.lang('title').": ".lang("Hidden").
3817                                         '</b><br>'.lang('description').": ".lang("Hidden").'<br></span></ul><br>';
3818                         else
3819                                 $overlap .= '<ul>'.$this->link_to_entry($overlapped_event,$month,$mday,$year)."</ul><br>";     
3820                        }
3821
3822                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
3823                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
3824                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
3825                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
3826                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['calendar']['title'].' - '.lang('Scheduling Conflict');
3827                        $GLOBALS['phpgw']->common->phpgw_header();
3828
3829                        $p = $GLOBALS['phpgw']->template;
3830                        $p->set_file(
3831                                Array(
3832                                        'overlap'       => 'overlap.tpl',
3833                                        'form_button'   => 'form_button_script.tpl'
3834                                )
3835                        );
3836
3837                        $var = Array(
3838                                'color'         => $this->theme['bg_text'],
3839                                'overlap_title' => lang('Scheduling Conflict'),
3840                                '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)),
3841                                'overlap_list'  => $overlap
3842                        );
3843                        $p->set_var($var);
3844
3845                        $date = sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->mday);
3846                        $var = Array(
3847                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update','readsess'=>1)),
3848                                'action_text_button'    => lang('Ignore Conflict'),
3849                                'action_confirm_button' => '',
3850                                'action_extra_field'    => '',
3851                                'button_id'             => 'ignore_button'
3852                        );
3853                        $this->output_template_array($p,'resubmit_button','form_button',$var);
3854
3855                        $var = Array(
3856                                'action_url_button'     => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.uicalendar.edit','readsess'=>1,'date'=>$date)),
3857                                'action_text_button'    => lang('Re-Edit Event'),
3858                                'action_confirm_button' => '',
3859                                'action_extra_field'    => '',
3860                                'button_id'             => 'redit_button'
3861                        );
3862                        $this->output_template_array($p,'reedit_button','form_button',$var);
3863                        $p->pparse('out','overlap');
3864                }
3865
3866                function planner_participants($parts)
3867                {
3868                        static $id2lid;
3869
3870                        $names = '';
3871                        while (list($id,$status) = each($parts))
3872                        {
3873                                $status = substr($this->bo->get_long_status($status),0,1);
3874
3875                                if (!isset($id2lid[$id]))
3876                                {
3877                                        $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id);
3878                                }
3879                                if (strlen($names))
3880                                {
3881                                        $names .= ",\n";
3882                                }
3883                                $names .= $id2lid[$id]." ($status)";
3884                        }
3885                        if($this->debug)
3886                        {
3887                                echo '<!-- Inside participants() : '.$names.' -->'."\n";
3888                        }
3889                        return $names;
3890                }
3891
3892                function planner_category($ids)
3893                {
3894                        static $cats;
3895                        if(!is_array($ids))
3896                        {
3897                                if (strpos($ids,','))
3898                                {
3899                                        $id_array = explode(',',$ids);
3900                                }
3901                                else
3902                                {
3903                                        $id_array[0] = $ids;
3904                                }
3905                        }
3906                        @reset($id_array);
3907                        $ret_val = Array();
3908                        while(list($index,$id) = each($id_array))
3909                        {
3910                                if (!isset($cats[$id]))
3911                                {
3912                                        $cat_arr = $this->cat->return_single( $id );
3913                                        $cats[$id] = $cat_arr[0];
3914                                        $cats[$id]['color'] = strstr($cats[$id]['description'],'#');
3915                                }
3916                                $ret_val[] = $cats[$id];
3917                        }
3918                        return $ret_val;
3919                }
3920
3921                function week_header($month,$year,$display_name = False)
3922                {
3923                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
3924
3925                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3926                        $p->set_unknowns('remove');
3927                        $p->set_file(
3928                                Array (
3929                                        'month_header' => 'month_header.tpl'
3930                                )
3931                        );
3932                        $p->set_block('month_header','monthly_header','monthly_header');
3933                        $p->set_block('month_header','column_title','column_title');
3934
3935                        $var = Array(
3936                                'bgcolor'       => $this->theme['th_bg'],
3937                                'font_color'    => $this->theme['th_text']
3938                        );
3939                        if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
3940                        {
3941                                $var = Array(
3942                                        'bgcolor'       => '',
3943                                        'font_color'    => ''
3944                                );
3945                        }
3946                        $p->set_var($var);
3947
3948                        $p->set_var('col_width','14');
3949                        if($display_name == True)
3950                        {
3951                                $p->set_var('col_title',lang('name'));
3952                                $p->parse('column_header','column_title',True);
3953                                $p->set_var('col_width','12');
3954                        }
3955
3956                        for($i=0;$i<7;$i++)
3957                        {
3958                                $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
3959                                $p->parse('column_header','column_title',True);
3960                        }
3961                        return $p->fp('out','monthly_header');
3962                }
3963
3964                function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
3965                {
3966                        if($owner == 0)
3967                        {
3968                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
3969                        }
3970
3971                        $temp_owner = $this->bo->owner;
3972
3973                        $str = '';
3974                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
3975                        $p->set_unknowns('keep');
3976
3977                        $p->set_file(
3978                                Array(
3979                                        'month_header'  => 'month_header.tpl',
3980                                        'month_day'     => 'month_day.tpl'
3981                                )
3982                        );
3983                        $p->set_block('month_header','monthly_header','monthly_header');
3984                        $p->set_block('month_header','month_column','month_column');
3985                        $p->set_block('month_day','month_daily','month_daily');
3986                        $p->set_block('month_day','day_event','day_event');
3987                        $p->set_block('month_day','event','event');
3988
3989                        $p->set_var('extra','');
3990                        $p->set_var('col_width','14');
3991                        if($display_name)
3992                        {
3993                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
3994                                $p->parse('column_header','month_column',True);
3995                                $p->set_var('col_width','12');
3996                        }
3997                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
3998                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
3999                        foreach($daily as $date => $day_params)
4000                        {
4001                                $year  = (int)substr($date,0,4);
4002                                $month = (int)substr($date,4,2);
4003                                $day   = (int)substr($date,6,2);
4004                                $var   = Array(
4005                                        'column_data' => '',
4006                                        'extra' => ''
4007                                );
4008                                $p->set_var($var);
4009                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
4010                                {
4011                                        if ($day_params['new_event'])
4012                                        {
4013                                                $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
4014                                                        . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
4015                                                        . '</a>';
4016                                                $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
4017                                        }
4018                                        else
4019                                        {
4020                                                $new_event_link = '';
4021                                                $day_number = $day;
4022                                        }
4023
4024                                        $var = Array(
4025                                                'extra'         => $day_params['extra'],
4026                                                'new_event_link'=> $new_event_link,
4027                                                'day_number'    => $day_number
4028                                        );
4029                                        if($day_params['week'])
4030                                        {
4031
4032//NDEE: style! m_w_table in month_day.tpl
4033// week-hilite
4034                                                //$var['new_event_link'] .= '<font size="-2"> &nbsp; '.
4035                                                $var['new_event_link'] .= ' &nbsp; '.
4036                                                        (!$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>');
4037                                        }
4038
4039                                        $p->set_var($var);
4040
4041                                        if(@$day_params['holidays'])
4042                                        {
4043                                                foreach($day_params['holidays'] as $key => $value)
4044                                                {
4045                                                        $var = Array(
4046                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
4047                                                        );
4048                                                        $this->output_template_array($p,'daily_events','event',$var);
4049                                                }
4050                                        }
4051
4052                                        if($day_params['appts'])
4053                                        {
4054                                                $var = Array(
4055                                                        'week_day_font_size'    => '2',
4056                                                        'events'                => ''
4057                                                );
4058                                                $p->set_var($var);
4059                                                $events = $this->bo->cached_events[$date];
4060                                                foreach($events as $event)
4061                                                {
4062                                                        if ($this->bo->rejected_no_show($event))
4063                                                        {
4064                                                                continue;       // user does not want to see rejected events
4065                                                        }
4066                                                        $p->set_var('day_events',$this->link_to_entry($event,$month,$day,$year));
4067                                                        $p->parse('events','event',True);
4068                                                        $p->set_var('day_events','');
4069                                                }
4070                                        }
4071                                        $p->parse('daily_events','day_event',True);
4072                                        $p->parse('column_data','month_daily',True);
4073                                        $p->set_var('daily_events','');
4074                                        $p->set_var('events','');
4075/*                                      if($day_params['week'])
4076                                        {
4077                                                $var = Array(
4078                                                        'week_day_font_size'    => '-2',
4079                                                        'events'                => (!$this->bo->printer_friendly?'<a href="'.$this->page('week','&date='.$date).'">' .$day_params['week'].'</a>':$day_params['week'])
4080                                                );
4081                                                $this->output_template_array($p,'column_data','day_event',$var);
4082                                                $p->set_var('events','');
4083                                        } */
4084                                }
4085                                $p->parse('column_header','month_column',True);
4086                                $p->set_var('column_data','');
4087                        }
4088                        $this->bo->owner = $temp_owner;
4089                        return $p->fp('out','monthly_header');
4090                }
4091
4092/***************************************************************************************/
4093/*As funcoes abaixo
4094        month_week_header()
4095        month_display_week()
4096        display_month_print()
4097        month_day_of_week() - esta foi criada mas parte do codigo e de outra funcao da API (day_of_week());
4098
4099  foram duplicadas e modificadas para atender aas modificacoes do layout de impressao mensal da agenda de eventos;
4100  TODO: otimizar o codigo
4101
4102  Rommel Cysne
4103*/
4104
4105                function month_week_header($month,$year,$display_name = False)
4106                {
4107                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
4108                        $p->set_unknowns('remove');
4109                }
4110
4111
4112                function month_day_of_week($year,$month,$day)
4113                {
4114                        $dia = Array(
4115                                0 => 'Domingo',
4116                                1 => 'Segunda',
4117                                2 => 'Ter&ccedil;a',
4118                                3 => 'Quarta',
4119                                4 => 'Quinta',
4120                                5 => 'Sexta',
4121                                6 => 'S&aacute;bado'
4122                        );
4123
4124                        if($month > 2)
4125                        {
4126                                $month -= 2;
4127                        }
4128                                else
4129                        {
4130                                $month += 10;
4131                                $year--;
4132                        }
4133                        $day = (floor((13 * $month - 1) / 5) + $day + ($year % 100) + floor(($year % 100) / 4) + floor(($year / 100) / 4) - 2 * floor($year / 100) + 77);
4134
4135                        $month_day = ($day - 7 * floor($day / 7)); //retorna o numero do dia da semana (Ex: domingo eh dia 0, terca eh 2);
4136                        $weekday = $dia[$month_day]; //retorna o nome do dia da semana de acordo com seu numero;
4137
4138                        return ($weekday);
4139
4140                }
4141
4142                function month_display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
4143                {
4144                        if($owner == 0)
4145                        {
4146                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
4147                        }
4148
4149                        $temp_owner = $this->bo->owner;
4150
4151                        $str = '';
4152                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4153                        $p->set_unknowns('keep');
4154
4155                        $p->set_file(
4156                                Array(
4157                                        'month_header'  => 'month_header_print.tpl',
4158                                        'month_day'     => 'month_day_print.tpl'
4159                                )
4160                        );
4161                        $p->set_block('month_header','monthly_header','monthly_header');
4162                        $p->set_block('month_header','month_column','month_column');
4163                        $p->set_block('month_day','month_daily','month_daily');
4164                        $p->set_block('month_day','day_event','day_event');
4165                        $p->set_block('month_day','event','event');
4166
4167                        $p->set_var('extra','');
4168                        $p->set_var('col_width','14');
4169                       
4170                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
4171                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
4172
4173                        foreach($daily as $date => $day_params)
4174                        {
4175                                $year  = (int)substr($date,0,4);
4176                                $month = (int)substr($date,4,2);
4177                                $day   = (int)substr($date,6,2);
4178                                $var   = Array(
4179                                        'column_data' => '',
4180                                        'extra' => ''
4181                                );
4182                                $p->set_var($var);
4183                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
4184                                {
4185                                        $new_event_link = '';
4186                                        $day_num = $day;
4187                                        $dia_semana = $this->month_day_of_week($year,$month,$day_num);
4188                                        $id_aux = mktime(0,0,0,$month,$day,$year);
4189                                        $month_identifier = substr(lang(strftime("%B",$id_aux)),0,3);
4190                                        $day_number = $month_identifier . " - " . $dia_semana . ",  " . $day_num;
4191
4192                                        $var = Array(
4193                                                'extra'         => $day_params['extra'],
4194                                                'new_event_link'=> $new_event_link,
4195                                                'day_number'    => $day_number
4196                                        );
4197
4198                                        $p->set_var($var);
4199
4200                                        if($day_params['appts'])
4201                                        {
4202                                                $var = Array(
4203                                                        'week_day_font_size'    => '2',
4204                                                        'events'                => ''
4205                                                );
4206                                                $p->set_var($var);
4207                                                $events = $this->bo->cached_events[$date];
4208                                                foreach($events as $event)
4209                                                {
4210                                                        if ($this->bo->rejected_no_show($event))
4211                                                        {
4212                                                                continue;       // user does not want to see rejected events
4213                                                        }
4214                                                        $p->set_var('day_events',$this->link_to_month_entry($event,$month,$day,$year));
4215                                                        $p->parse('events','event',True);
4216                                                        $p->set_var('day_events','');
4217                                                }
4218                                        }
4219                                        $p->parse('daily_events','day_event',True);
4220                                        $p->parse('column_data','month_daily',True);
4221                                        $p->set_var('daily_events','');
4222                                        $p->set_var('events','');
4223                                }
4224                                $p->parse('column_header','month_column',True);
4225                                $p->set_var('column_data','');
4226                        }
4227                        $this->bo->owner = $temp_owner;
4228                        return $p->fp('out','monthly_header');
4229
4230                }
4231
4232                function display_month_print($month,$year,$showyear,$owner=0)
4233                {
4234                        if($this->debug)
4235                        {
4236                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
4237                        }
4238
4239/*                      $this->bo->store_to_cache(
4240                                Array(
4241                                        'syear' => $year,
4242                                        'smonth'=> $month,
4243                                        'sday'  => 1
4244                                )
4245                        );
4246*/
4247                        $day_ini = $_GET['day_ini'];// dia do inicio da impressao; o padrao e o dia atual;
4248                        $num_dias = $_GET['num_dias'];// quantidade de dias a partir do dia inicial;
4249
4250                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
4251//                      $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4252
4253                        if($num_dias != 0)
4254                        {
4255                                //se a qtde de dias for informada, a data final para impressao considera a soma $day_ini+$num_dias;
4256                                $monthend   = (int)(date('Ymd',mktime(0,0,0,$month,$day_ini+$num_dias,$year)));
4257                        }
4258                        else
4259                        {
4260                                //se a qtde de dias nao for informada, a data final para impressao vai ate o fim do mes corrente;
4261                                $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4262                        }
4263                       
4264                        if($day_ini != 0)
4265                        {
4266                                //o dia de inicio para impressao passa a ser o informado em $day_ini do mes corrente;
4267                                $start = mktime(0,0,0,$month,$day_ini,$year);
4268                        }
4269                        else
4270                        {
4271                                //se nao for informado o dia para inicio da impressao, esta comeca no dia 1 do mes corrente;
4272                                $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
4273                        }
4274                        //$start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 15);
4275                        $start_d = (int)(date('Ymd',$start));//variavel auxiliar que recebe a data inicial de impressao no formato 'Ymd';
4276                        $saux = (int)(substr($start_d,4,2));//variavel auxiliar que recebe o mes do inicio da impressao;
4277                        $eaux = (int)(substr($monthend,4,2)) + 1;//variavel auxiliar que recebe o mes do fim da impressao;
4278                        //A funcao store_to_cache devolve todos os eventos existentes de determinado usuario em um periodo de tempo
4279                        //especifico. Originalmente, na impressao mensal, esse periodo de tempo era o mes corrente exibido na tela.
4280                        //A mudanca consiste no fato de que uma nova variavel ($saux) e enviada com o mes de inicio do periodo
4281                        //atraves do indice 'smonth' e uma segunda variavel ($eaux) envia o mes final do periodo de tempo atraves
4282                        //do indice 'emonth'. Vide mais comentarios sobre esses valores em class.bocalendar.inc.php,
4283                        //function store_to_cache($params);
4284                        $this->bo->store_to_cache(
4285                        Array(
4286                                'syear' => $year,//ano atual
4287                                'smonth'=> $saux,//mes inicial
4288                                'emonth'=> $eaux,//mes final
4289                                'sday'  => 1
4290                        ));
4291
4292                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4293                        $p->set_unknowns('keep');
4294
4295                        $p->set_file(
4296                                Array(
4297                                        'week' => 'month_day_print.tpl'
4298                                )
4299                        );
4300                        $p->set_block('week','m_w_table','m_w_table');
4301                        $p->set_block('week','event','event');
4302
4303                        $var = Array(
4304                                'cols'      => 1,
4305                                'day_events'=> '' //$this->month_week_header($month,$year,False)
4306                        );
4307//                      $this->output_template_array($p,'row','event',$var);
4308
4309                        $cellcolor = $this->theme['row_on'];
4310
4311                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
4312                        {
4313                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
4314                                $var = Array(
4315                                        'day_events' => $this->month_display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
4316                                );
4317                                $this->output_template_array($p,'row','event',$var);
4318                        }
4319                        return $p->fp('out','m_w_table');
4320                }
4321
4322
4323/***************************************************************************************/
4324
4325                function display_month($month,$year,$showyear,$owner=0)
4326                {
4327                        if($this->debug)
4328                        {
4329                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
4330                        }
4331
4332                        $this->bo->store_to_cache(
4333                                Array(
4334                                        'syear' => $year,
4335                                        'smonth'=> $month,
4336                                        'sday'  => 1
4337                                )
4338                        );
4339
4340                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
4341                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
4342
4343                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
4344
4345                        if($this->debug)
4346                        {
4347                                echo '<!-- display_month:monthstart = '.$monthstart.' -->'."\n";
4348                                echo '<!-- display_month:start = '.date('Ymd H:i:s',$start).' -->'."\n";
4349                        }
4350
4351                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4352                        $p->set_unknowns('keep');
4353
4354                        $p->set_file(
4355                                Array(
4356                                        'week' => 'month_day.tpl'
4357                                )
4358                        );
4359                        $p->set_block('week','m_w_table','m_w_table');
4360                        $p->set_block('week','event','event');
4361
4362                        $var = Array(
4363                                'cols'      => 1,
4364                                'day_events'=> $this->week_header($month,$year,False)
4365                        );
4366                        $this->output_template_array($p,'row','event',$var);
4367
4368                        $cellcolor = $this->theme['row_on'];
4369
4370                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
4371                        {
4372                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
4373                                $var = Array(
4374                                        'day_events' => $this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
4375                                );
4376                                $this->output_template_array($p,'row','event',$var);
4377                        }
4378                        return $p->fp('out','m_w_table');
4379                }
4380
4381                function display_weekly($params)
4382                {
4383                        if(!is_array($params))
4384                        {
4385                                $this->index();
4386                        }
4387
4388                        $year = substr($params['date'],0,4);
4389                        $month = substr($params['date'],4,2);
4390                        $day = substr($params['date'],6,2);
4391                        $showyear = $params['showyear'];
4392                        $owners = $params['owners'];
4393
4394                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4395                        $p->set_unknowns('keep');
4396
4397                        $p->set_file(
4398                                Array(
4399                                        'week'  => 'month_day.tpl'
4400                                )
4401                        );
4402                        $p->set_block('week','m_w_table','m_w_table');
4403                        $p->set_block('week','event','event');
4404
4405                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
4406
4407                        $cellcolor = $this->theme['row_off'];
4408
4409                        $true_printer_friendly = $this->bo->printer_friendly;
4410
4411                        if(is_array($owners))
4412                        {
4413                                $display_name = True;
4414                                $counter = count($owners);
4415                                $owners_array = $owners;
4416                                $cols = 8;
4417                        }
4418                        else
4419                        {
4420                                $display_name = False;
4421                                $counter = 1;
4422                                $owners_array[0] = $owners;
4423                                $cols = 7;
4424                        }
4425                        $var = Array(
4426                                'cols'         => $cols,
4427                                'day_events'   => $this->week_header($month,$year,$display_name)
4428                        );
4429                        $this->output_template_array($p,'row','event',$var);
4430
4431                        $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
4432                        $tstop = $tstart + 604800;
4433                        $original_owner = $this->bo->so->owner;
4434                        for($i=0;$i<$counter;$i++)
4435                        {
4436                                $this->bo->so->owner = $owners_array[$i];
4437                                $this->bo->so->open_box($owners_array[$i]);
4438                                $this->bo->store_to_cache(
4439                                        Array(
4440                                                'syear'  => date('Y',$tstart),
4441                                                'smonth' => date('m',$tstart),
4442                                                'sday'   => date('d',$tstart),
4443                                                'eyear'  => date('Y',$tstop),
4444                                                'emonth' => date('m',$tstop),
4445                                                'eday'   => date('d',$tstop)
4446                                        )
4447                                );
4448                                $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$owners_array[$i]));
4449                                $p->parse('row','event',True);
4450                        }
4451                        $this->bo->so->owner = $original_owner;
4452                        $this->bo->printer_friendly = $true_printer_friendly;
4453                        return $p->fp('out','m_w_table');
4454                }
4455
4456                function view_event($event,$alarms=False)
4457                {
4458                        if((!$event['participants'][$this->bo->owner] && !$this->bo->check_perms(PHPGW_ACL_READ,$event)))
4459                        {
4460                                return False;
4461                        }
4462
4463                        $p = &$GLOBALS['phpgw']->template;
4464
4465                        $p->set_file(
4466                                Array(
4467                                        'view'  => 'view.tpl'
4468                                )
4469                        );
4470                        $p->set_block('view','view_event','view_event');
4471                        $p->set_block('view','list','list');
4472                        $p->set_block('view','hr','hr');
4473
4474                        $vars = $this->bo->event2array($event);
4475
4476                        $vars['title']['tr_color'] = $this->theme['th_bg'];
4477
4478                        foreach($vars['participants']['data'] as $user => $str)
4479                        {
4480                        if ($this->bo->check_perms(PHPGW_ACL_EDIT,0,$user) && ereg('^(.*) \((.*)\)$',$str,$parts))
4481                                {
4482                                        $vars['participants']['data'][$user] = $parts[1].' (<a href="'.$this->page('edit_status','&cal_id='.$event['id'].'&owner='.$user).'">'.$parts[2].'</a>)';
4483                                        $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>)';
4484//system('echo "event: '.$event['start'].'" >>/tmp/controle');
4485                                }
4486                        }
4487                        $vars['participants']['data'] = implode("<br>\n",$vars['participants']['data']);
4488                        foreach($vars as $var)
4489                        {
4490                                if (strlen($var['data']))
4491                                {
4492                                        $this->output_template_array($p,'row','list',$var);
4493                                }
4494                        }
4495
4496                        if($alarms && count($event['alarm']))
4497                        {
4498                                $p->set_var('th_bg',$this->theme['th_bg']);
4499                                $p->set_var('hr_text',lang('Alarms'));
4500                                $p->parse('row','hr',True);
4501                                foreach($event['alarm'] as $key => $alarm)
4502                                {
4503                                        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
4504                                        {       
4505                                                $icon = '<img src="'.$GLOBALS['phpgw']->common->image('calendar',($alarm['enabled']?'enabled':'disabled')).'" width="13" height="13">';
4506                                                $var = Array(                                   
4507                                                        'field' => $icon.$GLOBALS['phpgw']->common->show_date($alarm['time']),
4508                                                        'data'  => lang('Email Notification for %1',$GLOBALS['phpgw']->common->grab_owner_name($alarm['owner']))
4509                                                );
4510                                                $this->output_template_array($p,'row','list',$var);
4511                                        }
4512                                }
4513                        }
4514                        return True;
4515                }
4516
4517                function nm_on_off()
4518                {
4519                        if($GLOBALS['phpgw']->nextmatchs->alternate_row_color() == $this->theme['row_on'])
4520                        {
4521                                return '_on';
4522                        }
4523                        return '_off';
4524                }
4525
4526                function slot_num($time,$set_day_start=0,$set_day_end=0)
4527                {
4528                        static $day_start, $day_end, $interval=0;
4529
4530                        if ($set_day_start) $day_start = $set_day_start;
4531                        if ($set_day_end)   $day_end   = $set_day_end;
4532                        if (!$interval)     $interval  = 60*$this->bo->prefs['calendar']['interval'];
4533
4534                        if ($time > $day_end)
4535                        {
4536                                $time = $day_end;
4537                        }
4538                        $slot = (int)(($time - $day_start) / $interval);
4539
4540                        return $slot < 0 ? 0 : 1+$slot;
4541                }
4542
4543                function print_day($params)
4544                {
4545                        if(!is_array($params))
4546                        {
4547                                $this->index();
4548                        }
4549
4550                        print_debug('in print_day()');
4551
4552                        $this->bo->store_to_cache(
4553                                Array(
4554                                        'syear'  => $params['year'],
4555                                        'smonth' => $params['month'],
4556                                        'sday'   => $params['day'],
4557                                        'eyear'  => $params['year'],
4558                                        'emonth' => $params['month'],
4559                                        'eday'   => $params['day']
4560                                )
4561                        );
4562
4563                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
4564                        $p->set_unknowns('keep');
4565
4566                        $tpl = 'day_cal.tpl';
4567                        if((int)($GLOBALS['phpgw_info']['user']['preferences']['calendar']['mainscreen_showevents'])==2 &&
4568                                $GLOBALS['phpgw_info']['flags']['currentapp'] == 'home')
4569                        {
4570                                $tpl = 'day_list.tpl';
4571                        }
4572                        $templates = Array(
4573                                'day_cal'   => $tpl
4574                        );
4575
4576                        $p->set_file($templates);
4577                        $p->set_block('day_cal','day','day');
4578                        $p->set_block('day_cal','day_row','day_row');
4579                        $p->set_block('day_cal','day_event_on','day_event_on');
4580                        $p->set_block('day_cal','day_event_off','day_event_off');
4581                        $p->set_block('day_cal','day_event_holiday','day_event_holiday');
4582                        $p->set_block('day_cal','day_time','day_time');
4583
4584                        $date_to_eval = sprintf("%04d%02d%02d",$params['year'],$params['month'],$params['day']);
4585
4586                        $day_start = mktime((int)($this->bo->prefs['calendar']['workdaystarts']),0,0,$params['month'],$params['day'],$params['year']);
4587                        $day_end = mktime((int)($this->bo->prefs['calendar']['workdayends']),0,1,$params['month'],$params['day'],$params['year']);
4588                        $daily = $this->set_week_array($GLOBALS['phpgw']->datetime->get_weekday_start($params['year'],$params['month'],$params['day']),$this->theme['row_on'],True);
4589                        print_debug('Date to Eval',$date_to_eval);
4590                        $events_to_show = array();
4591                        if($daily[$date_to_eval]['appts'])
4592                        {
4593                                $events = $this->bo->cached_events[$date_to_eval];
4594                                print_debug('Date',$date_to_eval);
4595                                print_debug('Count',count($events));
4596                                foreach($events as $event)
4597                                {
4598                                        if ($this->bo->rejected_no_show($event))
4599                                        {
4600                                                continue;       // user does not want to see rejected events
4601                                        }
4602                                        if ($event['recur_type'])       // calculate start- + end-datetime for recuring events
4603                                        {
4604                                                $this->bo->set_recur_date($event,$date_to_eval);
4605                                        }
4606                                        $events_to_show[] = array(
4607                                                'starttime' => $this->bo->maketime($event['start']),
4608                                                'endtime'   => $this->bo->maketime($event['end']),
4609                                                'content'   => $this->link_to_entry($event,$params['month'],$params['day'],$params['year'])
4610                                        );
4611                                }
4612                        }
4613                        //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4614                        $other = $GLOBALS['phpgw']->hooks->process(array(
4615                                'location'  => 'calendar_include_events',
4616                                'year'      => $params['year'],
4617                                'month'     => $params['month'],
4618                                'day'       => $params['day'],
4619                                'owner'     => $this->bo->owner // num. id of the user, not necessary current user
4620                        ));
4621
4622                        if (is_array($other))
4623                        {
4624                                foreach($other as $evts)
4625                                {
4626                                        if (is_array($evts))
4627                                        {
4628                                                $events_to_show = array_merge($events_to_show,$evts);
4629                                        }
4630                                }
4631                                usort($events_to_show,create_function('$a,$b','return $a[\'starttime\']-$b[\'starttime\'];'));
4632                                //echo "events_to_show=<pre>"; print_r($events_to_show); echo "</pre>\n";
4633                        }
4634
4635                        if (count($events_to_show))
4636                        {
4637                                $last_slot_end = -1;
4638                                foreach($events_to_show as $event)
4639                                {
4640                                        $slot = $this->slot_num($event['starttime'],$day_start,$day_end);
4641                                        $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
4642
4643                                        if ($slot <= $last_slot_end)
4644                                        {
4645                                                $slot = $last_slot;
4646                                                $slot_end = max($last_slot_end,$slot_end);
4647                                        }
4648                                        $rows[$slot] .= $event['content'];
4649
4650                                        print_debug('slot',$slot);
4651                                        print_debug('row',$rows[$slot]);
4652
4653                                        $row_span[$slot] = 1 + $slot_end - $slot;
4654
4655                                        $last_slot = $slot;
4656                                        $last_slot_end = $slot_end;
4657                                        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));
4658                                        print_debug('Slot',$slot);
4659                                }
4660                                //echo "rows=<pre>"; print_r($rows); echo "<br>row_span="; print_r($row_span); echo "</pre>\n";
4661                        }
4662                        $holiday_names = $daily[$date_to_eval]['holidays'];
4663                        if(!$holiday_names)
4664                        {
4665                                $row_to_print = $this->nm_on_off();
4666                        }
4667                        else
4668                        {
4669                                $row_to_print = '_holiday';
4670                                foreach($holiday_names as $name)
4671                                {
4672                                        $rows[0] = '<center>'.$name.'</center>' . $rows[0];
4673                                }
4674                        }
4675                        $last_slot = $this->slot_num($day_end,$day_start,$day_end);
4676                        $rowspan = 0;
4677                        for ($slot = 0; $slot <= $last_slot; ++$slot)
4678                        {
4679                                $p->set_var('extras','');
4680                                if ($rowspan > 1)
4681                                {
4682                                        $p->set_var('event','');
4683                                        $rowspan--;
4684                                }
4685                                elseif (!isset($rows[$slot]))
4686                                {
4687                                        $p->set_var('event','&nbsp;');
4688                                        $row_to_print = $this->nm_on_off();
4689                                        $p->parse('event','day_event'.$row_to_print);
4690                                }
4691                                else
4692                                {
4693                                        $rowspan = (int)$row_span[$slot];
4694                                        if ($rowspan > 1)
4695                                        {
4696                                                $p->set_var('extras',' rowspan="'.$rowspan.'"');
4697                                        }
4698                                        $p->set_var('event',$rows[$slot]);
4699                                        $row_to_print = $this->nm_on_off();
4700                                        $p->parse('event','day_event'.$row_to_print);
4701                                }
4702                                $open_link = $close_link = '';
4703                                $time = '&nbsp;';
4704
4705                                if (0 < $slot && $slot < $last_slot)    // normal time-slot not before or after day_start/end
4706                                {
4707                                        $time = $day_start + ($slot-1) * 60 * $this->bo->prefs['calendar']['interval'];
4708                                        $hour = date('H',$time);
4709                                        $min  = date('i',$time);
4710                                        $time = $GLOBALS['phpgw']->common->formattime($hour,$min);
4711
4712                                        if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
4713                                        {
4714                                                $open_link = ' <a href="'.$this->page('add',"&date=$date_to_eval&hour=$hour&minute=$min").'">';
4715                                                $close_link = '</a> ';
4716                                        }
4717                                }
4718                                $p->set_var(Array(
4719                                        'open_link'  => $open_link,
4720                                        'time'       => $time,
4721                                        'close_link' => $close_link,
4722                                        'tr_color'   => ''      // dummy to stop output_template_array to set it
4723                                ));
4724                                $p->parse('time','day_time');
4725
4726                                $p->parse('row','day_row',True);
4727                        }
4728                        return $p->fp('out','day');
4729                }       // end function
4730
4731                function timematrix($param)
4732                {
4733                        if(!is_array($param))
4734                        {
4735                                $this->index();
4736                        }
4737
4738                        $date = $param['date'];
4739                        $starttime = $param['starttime'];
4740                        $endtime = $param['endtime'];
4741                        $participants = $param['participants'];
4742                        foreach($participants as $part => $nul)
4743                        {
4744                                $participants[$part] = $GLOBALS['phpgw']->common->grab_owner_name($part);
4745                                // Much better for processor  :)
4746                                $participants_id[]  .= $part;
4747                        }
4748                        uasort($participants,'strnatcasecmp');  // sort them after their fullname
4749
4750                        if(!isset($this->bo->prefs['calendar']['interval']))
4751                        {
4752                                $this->bo->prefs['calendar']['interval'] = 15;
4753                                $GLOBALS['phpgw']->preferences->add('calendar','interval',15);
4754                                $GLOBALS['phpgw']->preferences->save_repository();
4755                        }
4756                        $increment = $this->bo->prefs['calendar']['interval'];
4757                        $interval = (int)(60 / $increment);
4758
4759                        $pix = $GLOBALS['phpgw']->common->image('calendar','pix');
4760
4761                        $str = '<center>'.lang($GLOBALS['phpgw']->common->show_date($date['raw'],'l'))
4762                                . ', '.$this->bo->long_date($date).'<br>'
4763                                . '<table width="85%" border="0" cellspacing="0" cellpadding="0" cols="'.((24 * $interval) + 1).'">'
4764                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>'
4765                                . '<tr><td width="15%"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.lang('Participant').'</font></td>';
4766                        for($i=0;$i<24;$i++)
4767                        {
4768                                for($j=0;$j<$interval;$j++)
4769                                {
4770                                        $k = ($j == 0 ? sprintf('%02d',$i).'<br>':'').sprintf('%02d',$j*$increment);
4771
4772                                        $str .= '<td align="left" bgcolor="'.$this->theme['bg_color'].'"><font color="'.$phpgw_info['theme']['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'
4773                                                . '<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;\">"
4774                                                . $k."</a>&nbsp;</font></td>\n";
4775                                }
4776                        }
4777                        $str .= '</tr>'
4778                                . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="black"><img src="'.$pix.'"></td></tr>';
4779                        if(!$endtime)
4780                        {
4781                                $endtime = $starttime;
4782                        }
4783                        $owner = $this->bo->owner;
4784                        foreach($participants as $part => $fullname)
4785                        {
4786                                $str .= '<tr align="center">'
4787                                        . '<td width="15%" align="left"><font color="'.$this->theme['bg_text'].'" face="'.$this->theme['font'].'" size="-2">'.$fullname.'</font></td>';
4788
4789                                $this->bo->cached_events = Array();
4790                                $this->bo->so->owner = $part;
4791                                $this->bo->so->open_box($part);
4792                                $this->bo->store_to_cache(
4793                                        Array(
4794                                                'syear' => $date['year'],
4795                                                'smonth'=> $date['month'],
4796                                                'sday'  => $date['day'],
4797                                                'eyear' => 0,
4798                                                'emonth'=> 0,
4799                                                'eday'  => $date['day'] + 1
4800                                        )
4801                                );
4802
4803                                if(!$this->bo->cached_events[$date['full']])
4804                                {
4805                                        for($j=0;$j<24;$j++)
4806                                        {
4807                                                for($k=0;$k<$interval;$k++)
4808                                                {
4809                                                        $str .= '<td height="1" align="left" bgcolor="'.$this->theme['bg_color'].'" color="#999999">&nbsp;</td>';
4810                                                }
4811                                                $str .= "\n";
4812                                        }
4813                                }
4814                                else
4815                                {
4816                                        $time_slice = $this->bo->prepare_matrix($interval,$increment,$part,$date['full']);
4817                                        for($h=0;$h<24;$h++)
4818                                        {
4819                                                $hour = $h * 10000;
4820                                                for($m=0;$m<$interval;$m++)
4821                                                {
4822                                                        $index = ($hour + (($m * $increment) * 100));
4823                                                        switch($time_slice[$index]['marker'])
4824                                                        {
4825                                                                case '&nbsp':
4826                                                                        $time_slice[$index]['color'] = $this->theme['bg_color'];
4827                                                                        $extra = '';
4828                                                                        break;
4829                                                                case '-':
4830                                                                        $time_slice[$index]['color'] = $this->theme['bg01'];
4831                                                                        $link = $this->page('view','&cal_id='.$time_slice[$index]['id'].'&date='.$date['full']);
4832                                                                        $extra =' title="'.$time_slice[$index]['description'].'" onClick="location.href=\''.$link.'\';" style="cursor:pointer; cursor:hand;"';
4833                                                                        break;
4834                                                        }
4835                                                        $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>';
4836                                                }
4837                                                $str .= "\n";
4838                                        }
4839                                }
4840                                $str .= '</tr>'
4841                                        . '<tr><td height="1" colspan="'.((24 * $interval) + 1).'" bgcolor="#999999"><img src="'.$pix.'"></td></tr>';
4842                        }
4843                        $this->bo->owner = $owner;
4844                        $this->bo->so->owner = $owner;
4845                        $this->bo->so->open_box($owner);
4846                        return $str.'</table></center>'."\n";
4847                }
4848
4849                function get_response($cal_id)
4850                {
4851                        $p = &$GLOBALS['phpgw']->template;
4852                        $p->set_file(
4853                                Array(
4854                                        'form_button'   => 'form_button_script.tpl'
4855                                )
4856                        );
4857
4858                        $ev = $this->bo->get_cached_event();
4859                        $response_choices = Array(
4860                                ACCEPTED        => lang('Accept'),
4861                                REJECTED        => lang('Reject'),
4862                                TENTATIVE       => lang('Tentative')                           
4863                        );
4864                        $str = '';
4865                        while(list($param,$text) = each($response_choices))
4866                        {
4867                                $var = Array(
4868                                        'action_url_button'     => $this->page('set_action','&cal_id='.$cal_id.'&action='.$param.'&user_id='.$this->bo->owner),
4869                                        'action_text_button'    => '  '.$text.'  ',
4870                                        'action_confirm_button' => '',
4871                                        'action_extra_field'    => ''
4872                                );
4873                                $p->set_var($var);
4874                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4875                        }
4876                        if ($this->bo->return_to)
4877                        {
4878                                $var = Array(
4879                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
4880                                        'action_text_button'    => lang('cancel'),
4881                                        'action_confirm_button' => '',
4882                                        'action_extra_field'    => ''
4883                                );
4884                                $p->set_var($var);
4885                                $str .= '<td>'.$p->fp('out','form_button').'</td>'."\n";
4886                        }
4887                        $str = '<td><b>'.$GLOBALS['phpgw']->common->grab_owner_name($this->bo->owner).":</b></td>\n".$str;
4888
4889                        return '<table width="100%"><tr align="center">'."\n".$str.'</tr></table>'."\n";
4890                }
4891
4892                function accounts_popup()
4893                {
4894                        $GLOBALS['phpgw']->accounts->accounts_popup('calendar');
4895                       
4896                }
4897
4898                function edit_form($param)
4899                {
4900                        if(!is_array($param))
4901                        {
4902                                $this->index();
4903                        }
4904                       
4905                        if(isset($param['event']))
4906                        {
4907                                $event = $param['event'];
4908                        }
4909                       
4910                        $hourformat = substr($this->bo->users_timeformat,0,1);
4911                       
4912                        // $sb = CreateObject('phpgwapi.sbox');
4913                        $sb = CreateObject('phpgwapi.sbox2');
4914                        $jscal = CreateObject('phpgwapi.jscalendar');   // before phpgw_header() !!!
4915                       
4916                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
4917                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
4918                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
4919                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
4920                        $GLOBALS['phpgw_info']['flags']['app_header'] = $event['id'] ? lang('Editing event') : lang('Adding event');
4921                        if ($param['plain'] != "True"){
4922                                $GLOBALS['phpgw']->common->phpgw_header();
4923                        }
4924                        else{
4925                                $GLOBALS['phpgw_info']['theme']['row_on'] = "F8F8F8";
4926                                $GLOBALS['phpgw_info']['theme']['row_off'] = "F8F8F8";
4927                        }
4928
4929                        $p = &$GLOBALS['phpgw']->template;
4930                        $p->set_file(
4931                                Array(
4932                                        'edit'          => 'edit.tpl',
4933                                        'form_button'   => 'form_button_script.tpl'
4934                                )
4935                        );
4936                        $p->set_block('edit','edit_entry','edit_entry');
4937                        $p->set_block('edit','list','list');
4938                        $p->set_block('edit','hr','hr');
4939                       
4940                        $vars = Array(
4941                                'font'                  => $this->theme['font'],
4942                                'bg_color'              => $this->theme['bg_text'],
4943                                'action_url'            => $GLOBALS['phpgw']->link('/index.php',Array('menuaction'=>'calendar.bocalendar.update')),
4944                                'accounts_link'         => $GLOBALS['phpgw']->link('/index.php','menuaction=calendar.uicalendar.accounts_popup'),
4945                                'common_hidden' => '<input type="hidden" name="cal[id]" value="'.$event['id'].'">'."\n"
4946                                        . '<input type="hidden" name="cal[owner]" value="'.$event['owner'].'">'."\n"
4947                                        . '<input type="hidden" name="cal[uid]" value="'.$event['uid'].'">'."\n"
4948                                        . ($_GET['cal_id'] && $event['id'] == 0?'<input type="hidden" name="cal[reference]" value="'.$_GET['cal_id'].'">'."\n":
4949                                        (@isset($event['reference'])?'<input type="hidden" name="cal[reference]" value="'.$event['reference'].'">'."\n":''))
4950                                        . (@isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) && $GLOBALS['phpgw_info']['server']['deny_user_grants_access']?
4951                                        '<input type="hidden" name="participants[]" value="'.$this->bo->owner.'">'."\n":''),
4952                                'errormsg'              => ($param['cd']?$GLOBALS['phpgw']->common->check_code($param['cd']):'')
4953                        );
4954                       
4955                        $p->set_var($vars);
4956
4957// Brief Description
4958                        $var['title'] = Array(
4959                                'tr_color' => $this->theme['th_bg'],
4960                                'field' => lang('Title'),
4961                                'data'  => '<input name="cal[title]" size="45" maxlength="80" value="'.$event['title'].'">'
4962                        );
4963
4964// Full Description
4965                        $var['description'] = Array(
4966                                'field' => lang('Full Description'),
4967                                'data'  => '<textarea name="cal[description]" rows="5" cols="40" wrap="virtual" maxlength="2048">'.$event['description'].'</textarea>'
4968                        );
4969
4970// Display Categories
4971                        if(strpos($event['category'],','))
4972                        {
4973                                $temp_cats = explode(',',$event['category']);
4974                                @reset($temp_cats);
4975                                while(list($key,$value) = each($temp_cats))
4976                                {
4977                                        $check_cats[] = (int)$value;
4978                                }
4979                        }
4980                        elseif($event['category'])
4981                        {
4982                                $check_cats[] = (int)$event['category'];
4983                        }
4984                        else
4985                        {
4986                                $check_cats[] = 0;
4987                        }
4988                        $var['category'] = Array(
4989                                'field' => lang('Category'),
4990                                'data'  => '<select name="categories[]" onchange="javascript:updateTitleField(this)" multiple size="5">'.$this->cat->formated_list('select','all',$check_cats,True).'</select>'
4991                        );
4992
4993// Location
4994                        $var['location'] = Array(
4995                                'field' => lang('Location'),
4996                                'data'  => '<input name="cal[location]" size="45" maxlength="255" value="'.$event['location'].'">'
4997                        );
4998
4999// Date
5000
5001                        $start = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
5002                        $var['startdate'] = Array(
5003                                'field' => lang('Start Date'),
5004/*
5005                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
5006                                   $sb->getYears('start[year]',(int)$GLOBALS['phpgw']->common->show_date($start,'Y')),
5007                                   $sb->getMonthText('start[month]',(int)$GLOBALS['phpgw']->common->show_date($start,'n')),
5008                                   $sb->getDays('start[mday]',(int)$GLOBALS['phpgw']->common->show_date($start,'d'))
5009                                )
5010*/
5011                                'data' => $jscal->input('start[str]',$start)
5012                        );
5013
5014// Time
5015                        if ($this->bo->prefs['common']['timeformat'] == '12')
5016                        {
5017                                $str .= '<input type="radio" name="start[ampm]" value="am"'.($event['start']['hour'] >= 12?'':' checked').'>am'."\n"
5018                                        . '<input type="radio" name="start[ampm]" value="pm"'.($event['start']['hour'] >= 12?' checked':'').'>pm'."\n";
5019                        }
5020                        $var['starttime'] = Array(
5021                                'field' => lang('Start Time'),
5022                                '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
5023                        );
5024
5025// End Date
5026                        $end = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
5027                        $var['enddate'] = Array(
5028                                'field' => lang('End Date'),
5029/*
5030                                'data'  => $GLOBALS['phpgw']->common->dateformatorder(
5031                                   $sb->getYears('end[year]',(int)$GLOBALS['phpgw']->common->show_date($end,'Y')),
5032                                   $sb->getMonthText('end[month]',(int)$GLOBALS['phpgw']->common->show_date($end,'n')),
5033                                   $sb->getDays('end[mday]',(int)$GLOBALS['phpgw']->common->show_date($end,'d'))
5034                                )
5035*/
5036                                'data' => $jscal->input('end[str]',$end)
5037                        );
5038
5039// End Time
5040                        if ($this->bo->prefs['common']['timeformat'] == '12')
5041                        {
5042                                $str = '<input type="radio" name="end[ampm]" value="am"'.($event['end']['hour'] >= 12?'':' checked').'>am'."\n"
5043                                        . '<input type="radio" name="end[ampm]" value="pm"'.($event['end']['hour'] >= 12?' checked':'').'>pm'."\n";
5044                        }
5045                        $var['endtime'] = Array(
5046                                'field' => lang('End Time'),
5047                                '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
5048                        );
5049
5050// Priority
5051                        $var['priority'] = Array(
5052                                'field' => lang('Priority'),
5053                                'data'  => $sb->getPriority('cal[priority]',$event['priority'])
5054                        );
5055
5056                        // Access
5057                        $var['access'] = Array(
5058                        'field' => lang('Type'),
5059                        '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>'
5060                        ); //event['public']
5061
5062                        // Participants
5063                        if(!isset($GLOBALS['phpgw_info']['server']['deny_user_grants_access']) || !$GLOBALS['phpgw_info']['server']['deny_user_grants_access'])
5064                        {
5065                                switch($GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection'])
5066                                {
5067                                        case 'popup':
5068                                                while (is_array($event['participants']) && list($id) = each($event['participants']))
5069                                                {
5070                                                        if($id != (int)$event['owner'])
5071                                                        {
5072                                                                $str .= '<option value="' . $id.$event['participants'][$id] . '"'.($event['participants'][$id]?' selected':'').'>('.$GLOBALS['phpgw']->accounts->get_type($id)
5073                                                                                .') ' . $GLOBALS['phpgw']->common->grab_owner_name($id) . '</option>' . "\n";
5074                                                        }
5075                                                }
5076                                                $var['participants'] = array
5077                                                (
5078                                                        'field' => '<input type="button" value="' . lang('Participants') . '" onClick="accounts_popup();">' . "\n"
5079                                                                        . '<input type="hidden" name="accountid" value="' . $accountid . '">',
5080                                                        'data'  => "\n".'   <select name="participants[]" multiple size="7">' . "\n" . $str . '</select>'
5081                                                );
5082                                                break;
5083                                        default:
5084                                                foreach($event['participants'] as $id => $participant)
5085                                                {
5086                                                        if (($id != $event['owner']) && ($id != ""))
5087                                                        {
5088                                                                $GLOBALS['phpgw']->accounts->get_account_name($id, $lid, $fname, $lname);
5089                                                                $cn = $fname.' '.$lname;                                                       
5090                                                                $option = '    <option  value="' . $id.$participant . '">'.$cn.'</option>'."\n";
5091                                                                $str .= $option;
5092                                                        }                                                               
5093                                                }
5094                                                $str = utf8_decode($str);
5095                                                $footer_ext_participantes =     '<br>&nbsp;&nbsp;'.lang("The email addresses must be separated by ','");                                               
5096                                               
5097                                                $var['participants'] = array
5098                                                (
5099                                                        'field' => lang('Participants'),                                                       
5100                                                        'data'  => "
5101                                                                        <table width='100%' border='0'>
5102                                                                                <tr>
5103                                                                                        <td width='30%'>                                                                               
5104                                                                                                <center>Participantes</center>                                                                                         
5105                                                                                        </td>
5106                                                                                        <td width='8%' >&nbsp;</td>
5107                                                                                        <td width='40%'>&nbsp;</td>
5108                                                                                </tr>                                                                                                                                           
5109                                                                                <tr>           
5110                                                                                        <td width='30%'>                                                                                       
5111                                                                                                <center><select id='user_list' name='participants[]' style='width: 220px' multiple size='7'>".$str."</select></center>                                                                         
5112                                                                                        </td>                           
5113                                                                                        <td width='8%'>
5114                                                                                        <center>
5115                                                                                                <table width='100%' border='0'>                                                                 
5116                                                                                                        <tr height='5'><td>&nbsp;</td></tr>                                                                     
5117                                                                                                        <tr><td align='center'>                                                                 
5118                                                                                                                <button type='button' onClick='javascript:openListUsers(340,533, "
5119                                                                                                                .$event['owner'].
5120                                                                                                                ")'><img src='calendar/templates/".$_SESSION['phpgw_info']['calendar']['user']['preferences']['common']['template_set']."/images/add.png' style='vertical-align: middle;' >&nbsp;Adicionar</button>
5121                                                                                                                </td>
5122                                                                                                        </tr>                                                   
5123                                                                                                        <tr height='5'><td>&nbsp;</td></tr>
5124                                                                                                        <tr><td  align='center'>
5125                                                                                                                <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>
5126                                                                                                                </td>
5127                                                                                                        </tr>
5128                                                                                                </table>
5129                                                                                        </center>
5130                                                                                        </td>
5131                                                                                        <td width='40%'>&nbsp;</td>
5132                                                                                </tr>
5133                                                                                </table>
5134                                                                                <script src='calendar/js/edit.js' type='text/javascript'></script>
5135                                                                        "
5136                                                );
5137                                                // if ExpressoMail 1.2 has been installed and enabled, show the plugin using AJAX.
5138                                                if($GLOBALS['phpgw_info']['server']['cal_expressoMail']) {                                                     
5139                                                        $module_name = 'expressoMail'.(str_replace("1.","1_",$GLOBALS['phpgw_info']['server']['cal_expressoMail']));
5140
5141                                                        if($GLOBALS['phpgw_info']['user']['apps'][$module_name]){                                                               
5142                                                                $ldap_manager = CreateObject('contactcenter.bo_ldap_manager');
5143                                                                $_SESSION['phpgw_info']['expressomail']['user'] = $GLOBALS['phpgw_info']['user'];
5144                                                                $_SESSION['phpgw_info']['expressomail']['user']['owner'] = $event['owner'];
5145                                                                $_SESSION['phpgw_info']['expressomail']['server'] = $GLOBALS['phpgw_info']['server'];
5146                                                                $_SESSION['phpgw_info']['expressomail']['ldap_server'] = $ldap_manager ? $ldap_manager->srcs[1] : null;
5147                                                                $context = $GLOBALS['phpgw_info']['server']['ldap_context'];
5148                                                                $user_context = array();
5149                                                                foreach(explode(",",$GLOBALS['phpgw_info']['user']['account_dn']) as $i => $dn_part){
5150                                                                        if($i)
5151                                                                                $user_context[] = $dn_part;
5152                                                                }
5153                                                                // Prepara o contexto do usuario com sua OU raiz, pois ele pode pertencer a uma OU de nivel N.
5154                                                                $user_ou = explode(",",str_replace($context,"",implode(",",$user_context)));                                                           
5155                                                                $user_context = trim(strtolower($user_ou[count($user_ou) - 2].",".$context));
5156                                                                // Fim         
5157                                                                // Verifica o tipo da visualização da árvore LDAP, configurado no admin da Agenda
5158                                                                $recursive = $GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '1' ? true : false;
5159                                                                //$combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
5160                                                                $footer_ext_participantes = lang("Tip: To search in the <b>Global Catalog</b>, type the <b>F9</b> key, like the ExpressoMail.");
5161                                                                //Caso o minimo de caracteres para a busca nao tenha sido preenchido ele sera por padrao = 3
5162                                                                if(!$GLOBALS['phpgw_info']['server']['min_num_characters']){
5163                                                                        $GLOBALS['phpgw_info']['server']['min_num_characters'] = 0;
5164                                                                }
5165
5166                                                                if ($GLOBALS['phpgw_info']['server']['cal_type_tree_participants'] == '3'){
5167                                                                        $combo_org = '<option value='.$context.'>'.strtoupper($context).'</option>';
5168                                                                }else{
5169                                                                        $combo_org = $this->get_organizations(trim(strtolower($context)),$user_context, $recursive);
5170                                                                }
5171
5172                                                                if ($param['plain'] != "True"){
5173
5174                                                                        // Begin load array lang
5175                                                                        ob_start();
5176                                                                        //@include($module_name.'/inc/load_lang.php');
5177                                                                        $load_lang_vars = ob_get_contents();
5178                                                                        ob_end_clean();
5179                                                                        // End load array_lang
5180                                                                }
5181
5182                                                                $var['participants'] = array
5183                                                                (
5184                                                                        'field' => '
5185                                                                        <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\'>
5186        <iframe src=\'#\' id=\'frame_disponibility\' width=\'500\' marginHeight=\'0\' marginWidth=\'0\' height=\'200px\'></iframe>
5187</div>
5188                                                                        '.lang('Participants'),
5189                                                                        'data'  => '
5190                                                                                        <input type="hidden" id="txt_loading" value="'.lang("Loading").'">' .
5191                                                                                        '<input type="hidden" id="txt_searching" value="'.lang("Searching").'">' .
5192                                                                                        '<input type="hidden" id="txt_users" value="'.lang("Users").'">' .                                                     
5193                                                                                        '<input type="hidden" id="txt_groups" value="'.lang("Groups").'">' .
5194                                                                                        '<table width="100%" border="0">'.
5195                                                                                        '<tr>'.
5196                                                                                        '<td width="25%"><br><br>'.
5197                                                                                        '<br><br>&nbsp;&nbsp;<b>'.lang("Event's participants").'</b><br>'.
5198                                                                                        '       <select id="user_list" name="participants[]" style="width: 300px" multiple size="13">'.$str.'</select>'.
5199                                                                                        '</td>'.
5200                                                                                        '<td width="30px" valign="middle" align="center">&nbsp;'.
5201                                                                                        '</td>'.
5202                                                                                        '<td valign="bottom">'.
5203                                                                                        '       '.lang("Organization").': '.
5204                                                                                        '       <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>'.
5205                                                                                        '       <br>'.
5206                                                                                        '       <font color="red"><span id="cal_span_searching">&nbsp;</span></font>'.                                                                 
5207                                                                                        '       <br>'.lang("Search for").':'.
5208                                                                                        '       <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>'.
5209                                                                                        '       <b>'.lang("Available users and groups").'</b><br>'.
5210                                                                                        '       <select id="user_list_in" style="width: 300px" multiple size="13"></select>'.
5211                                                                                        '</td>'.
5212                                                                                        '</tr>'.
5213                                            '<tr>'.
5214                                            '<td width="25%">'.
5215                                            '<button type="button" id="time_map" onClick="javascript:show_disponibility();">'.lang("Disponibility map").'</button>'.
5216                                            '</td>'.
5217                                            '<td width="30px" valign="middle" align="center">&nbsp;'.
5218                                                                                        '</td>'.
5219                                            '<td valign="bottom">'.
5220                                            '<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>'.
5221                                                                                        '&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>'.
5222                                            '</td>'.
5223                                                                                        '</tr>'.
5224                                                                                        '</table>'.
5225                                                                                        '<script type="text/javascript" src="phpgwapi/js/wz_dragdrop/wz_dragdrop.js"></script>'.
5226                                                                                        '<script type="text/javascript" src="phpgwapi/js/dJSWin/dJSWin.js"></script>'.         
5227                                                                                        "<script src='calendar/js/edit_exmail.js' type='text/javascript'></script>" .
5228                                                                                        $load_lang_vars.                                                                                                                                                       
5229                                                                                        "<script src='".$module_name."/js/connector.js' type='text/javascript'></script>".
5230                                                                                        "<script type='text/javascript'>var DEFAULT_URL = '".$module_name."/controller.php?action=';</script> ".                                                                                       
5231                                                                                        "<script type='text/javascript'>" .
5232                                                                                        "var timeout_get_available_users = setTimeout('get_available_users(\"".$module_name."\",\'".$user_context."\',\'".($recursive ? "" : "search")."\',\'".$GLOBALS['phpgw_info']['server']['auto_search']."\')',1000);".
5233                                                                                        "</script> "
5234                                                                );
5235                                                        }                                               
5236                                                }                                               
5237                                               
5238                                                $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" .
5239                                                        " 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" ' .
5240                                                        '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">'.
5241                                                        '<tr>'.
5242                                                        '<td>'.
5243                                                        '&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">' .
5244                                                        '&nbsp;&nbsp;<a title="'.lang("Close").'" name="b_ext_participants" onClick="javascript:hideExParticipants(this,\''.$module_name.'\')" href="#a_ext_participants">['.lang("Close").']</a>&nbsp;'.                                                                                                               
5245                                                        '</td>'.
5246                                                        '</tr>'.
5247                                                        '<tr>'.
5248                                                        '<td>'.
5249                                                        '&nbsp;&nbsp;>> '.lang("It types below the email addresses, if you want to invite other people out of this system").':'.
5250                                                        '&nbsp;&nbsp;<br><textarea name="ex_participants" id="ex_participants" cols="70" rows="2">'.$event['ex_participants'].'</textarea><br>&nbsp;&nbsp;'.
5251                                                        $footer_ext_participantes.
5252                                                        '</tr>'.                                                       
5253                                                        '</table>';
5254                                                break;
5255                                               
5256                                }
5257                                if((($event['id'] > 0) && isset($event['participants'][$event['owner']])) || !$event['id'])
5258                                {
5259                                        $checked = ' checked';
5260                                }
5261                                else
5262                                {
5263                                        $checked = '';
5264                                }
5265                                $var['owner'] = Array(
5266                                        'field' => $GLOBALS['phpgw']->common->grab_owner_name($event['owner']).' '.lang('Participates'),
5267                                        'data'  => '<input type="checkbox" id="usuarioParticipa" name="participants[]" value="'.$event['owner'].$event['participants'][$event['owner']].'"'.$checked.'>'
5268                                );
5269                        }
5270
5271// Reminder
5272                        // The user must use "Alarm Management" to change/modify an alarm
5273                        // so only display the email reminder fields if this is a new event
5274                        // i.e. not editing an existing event
5275
5276                        if ($event['id'] == 0) {
5277                                // get defaults
5278                                $days = $this->bo->prefs['calendar']['default_email_days'];
5279                                $hours = $this->bo->prefs['calendar']['default_email_hours'];
5280                                $min = $this->bo->prefs['calendar']['default_email_min'];
5281                                if (count($event['alarm']) > 1)
5282                                {
5283                                        // this should not happen because when creating a new event
5284                                        // only 1 alarm is displayed on the screen
5285                                        // if the user wants more than 1 alarm they should
5286                                        // use "Alarm Management"
5287                                        echo '<!-- how did this happen, too many alarms -->'."\n";
5288                                }
5289                                // if there was an error pick up what the user entered
5290                                if (@isset($event['alarm']))
5291                                {
5292                                        @reset($event['alarm']);
5293                                        // just get the first one see above!!!
5294                                        list($key,$alarm) = @each($event['alarm']);
5295
5296
5297                                        //if abaixo trata o caso de um evento repetido nao ter uma data final;
5298                                        //se isto acontecer, nao havera alarmes definidos;
5299                                        //$alarm['time'] recebe $start para $days, $hours e $min ficarem iguais a 0
5300                                        if(!$alarm['time']) {
5301                                                $alarm['time'] = $start;
5302                                        }
5303
5304                                        $diff  = $start - $alarm['time'];
5305                                        $days  = (int)($diff / (24*3600));
5306                                        $hours = (int)(($diff - ($days * 24 * 3600))/3600);
5307                                        $min   = (int)(($diff - ($days * 24 * 3600) - ($hours * 3600))/60);
5308
5309                                        if(@isset($_POST['edit_type']) && $_POST['edit_type'] == 'single') {
5310                                                $days = $diff;
5311                                        }
5312                                }
5313
5314                                // days
5315                                $dout = '<select name="cal[alarmdays]">'."\n";
5316                                for($i=0;$i<32;$i++)
5317                                {
5318                                        $dout .= '<option value="'.$i.'"'.($i==$days?' selected':'').'>'.$i.'</option>'."\n";
5319                                }
5320                                $dout .= '</select>'."\n".' '.lang('days').' ';
5321                                // hours
5322                                $hout = '<select name="cal[alarmhours]">'."\n";
5323                                for($i=0;$i<25;$i++)
5324                                {
5325                                        $hout .= '<option value="'.$i.'"'.($i==$hours?' selected':'').'>'.$i.'</option>'."\n";
5326                                }
5327                                $hout .= '</select>'."\n".' '.lang('hours').' ';
5328                                // minutes
5329                                $mout = '<select name="cal[alarmminutes]">'."\n";
5330                                for($i=0;$i<61;$i++)
5331                                {
5332                                        $mout .= '<option value="'.$i.'"'.($i==$min?' selected':'').'>'.$i.'</option>'."\n";
5333                                }
5334                                $mout .= '</select>'."\n".' '.lang('minutes').' ';
5335
5336                                $var['alarm'] = Array(
5337                                        'field' => lang('Alarm'),
5338                                        'data'  => $dout.$hout.$mout.lang('before the event')
5339                                );
5340
5341                        }
5342
5343// Repeat Type
5344                        $str = '';
5345                        foreach($this->bo->rpt_type as $type => $label)
5346                        {
5347                                $str .= '<option value="'.$type.'"'.($event['recur_type']==$type?' selected':'').'>'.lang($label).'</option>';
5348                        }
5349                        $var['recure_type'] = Array(
5350                                'field' => lang('Repeat Type'),
5351                                'data'  => '<select name="cal[recur_type]">'."\n".$str.'</select>'."\n"
5352                        );
5353
5354                        if($event['recur_enddate']['year'] != 0 && $event['recur_enddate']['month'] != 0 && $event['recur_enddate']['mday'] != 0)
5355                        {
5356                                $checked = ' checked';
5357                                $recur_end = $this->bo->maketime($event['recur_enddate']) - $GLOBALS['phpgw']->datetime->tz_offset;
5358                        }
5359                        else
5360                        {
5361                                $checked = '';
5362                                $recur_end = $this->bo->maketime($event['start']) + 86400 - $GLOBALS['phpgw']->datetime->tz_offset;
5363                        }
5364
5365                        $var['recure_enddate'] = Array(
5366                                'field' => lang('Repeat End Date'),
5367                                'data'  => '<input type="checkbox" name="cal[rpt_use_end]" value="y"'.$checked.'>'.lang('Use End Date').'  '.
5368/*
5369                                        $GLOBALS['phpgw']->common->dateformatorder(
5370                                                $sb->getYears('recur_enddate[year]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'Y')),
5371                                                $sb->getMonthText('recur_enddate[month]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'n')),
5372                                                $sb->getDays('recur_enddate[mday]',(int)$GLOBALS['phpgw']->common->show_date($recur_end,'d'))
5373                                        )
5374*/
5375                                        $jscal->input('recur_enddate[str]',$recur_end)
5376                        );
5377
5378                        $i = 0; $boxes = '';
5379                        foreach ($this->bo->rpt_day as $mask => $name)
5380                        {
5381                                $boxes .= '<input type="checkbox" name="cal[rpt_day][]" value="'.$mask.'"'.($event['recur_data'] & $mask ? ' checked' : '').'>&nbsp;'.lang($name)."\n";
5382                                if (++$i == 5) $boxes .= '<br>';
5383                        }
5384                        $var['recure_day'] = Array(
5385                                'field' => lang('Repeat Day').'<br>'.lang('(required for weekly recursivity)'),
5386                                'data'  => $boxes
5387                        );
5388
5389                        $var['recure_interval'] = Array(
5390                                'field' => lang('Interval'),
5391                                'data'  => '<input name="cal[recur_interval]" size="4" maxlength="4" value="'.$event['recur_interval'].'">'
5392                        );
5393//                      $this->output_template_array($p,'row','list',Array('data' => '<script src="simple_show_hide.js" type="text/javascript"></script>'));
5394
5395                        if (!isset($this->fields))
5396                        {
5397                                $this->custom_fields = CreateObject('calendar.bocustom_fields');
5398                                $this->fields = &$this->custom_fields->fields;
5399                                $this->stock_fields = &$this->custom_fields->stock_fields;
5400                        }
5401                        $this->output_template_array($p,'row','list',$var['access']);
5402                        unset($var['access']);
5403
5404                        $preserved = False;
5405                        foreach($this->fields as $field => $data)
5406                        {
5407                                if (!$data['disabled'])
5408                                {
5409                                        if (isset($var[$field]))
5410                                        {
5411                                                switch($field)
5412                                                {
5413                                                        case 'startdate':
5414                                                                $this->output_template_array($p,'row','list',$var['startdate']);
5415                                                                $this->output_template_array($p,'row','list',$var['starttime']);
5416                                                                break;
5417                                                        case 'enddate':
5418                                                                $this->output_template_array($p,'row','list',$var['enddate']);
5419                                                                $this->output_template_array($p,'row','list',$var['endtime']);
5420                                                                break;
5421                                                        case 'recure_type':
5422                                                                $p->set_var('tr_color',$this->theme['th_bg']);
5423                                                                $p->set_var('hr_text','<center id="rpt_label"><b>'.lang('Repeating Event Information').'</b></center>');
5424                                                                $p->parse('row','hr',True);
5425                                                                $this->output_template_array($p,'row','list',$var['recure_type']);
5426                                                                $this->output_template_array($p,'row','list',$var['recure_enddate']);
5427                                                                $this->output_template_array($p,'row','list',$var['recure_day']);
5428                                                                $this->output_template_array($p,'row','list',$var['recure_interval']);
5429                                                                break;
5430                                                        default:
5431                                                                $this->output_template_array($p,'row','list',$var[$field]);
5432                                                }
5433                                        }
5434                                        elseif (!isset($this->stock_fields[$field]))    // Custom field
5435                                        {
5436                                                $lang = lang($name = substr($field,1));
5437                                                $size = 'SIZE='.($data['shown'] ? $data['shown'] : ($data['length'] ? $data['length'] : 30)).
5438                                                        ' MAXLENGTH='.($data['length'] ? $data['length'] : 255);
5439                                                $v = array(
5440                                                        'field' => $lang == $name.'*' ? $name : $lang,
5441                                                        'data'  => '<input name="cal['.htmlspecialchars($field).']" '.$size.' value="'.$event['#'.$name].'">'
5442                                                );
5443                                                if ($data['title'])
5444                                                {
5445                                                        $v['tr_color'] = $this->theme['th_bg'];
5446                                                }
5447                                                if (!$data['length'] && $data['title'])
5448                                                {
5449                                                        $p->set_var('tr_color',$this->theme['th_bg']);
5450                                                        $p->set_var('hr_text','<center><b>'.$v['field'].'</b></center>');
5451                                                        $p->parse('row','hr',True);
5452                                                }
5453                                                else
5454                                                {
5455                                                        $this->output_template_array($p,'row','list',$v);
5456                                                }
5457                                        }
5458                                }
5459                                else    // preserve disabled fields
5460                                {
5461                                        switch ($field)
5462                                        {
5463                                                case 'owner':
5464                                                        $preserved[$field] = $event['id'] ? $event['participants'][$event['owner']] : 'A';
5465                                                        break;
5466                                                case 'recure_type':
5467                                                        foreach(array('recur_type','recur_enddate','recur_data','recur_interval') as $field)
5468                                                        {
5469                                                                $preserved[$field] = $event[$field];
5470                                                        }
5471                                                        break;
5472                                                case 'startdate':
5473                                                case 'enddate':
5474                                                        $field = substr($field,0,-4);
5475                                                default:
5476                                                        $preserved[$field] = $event[$field];
5477                                        }
5478                                }
5479                        }
5480                        unset($var);
5481                        if (is_array($preserved))
5482                        {
5483                                //echo "preserving<pre>"; print_r($preserved); echo "</pre>\n";
5484                                $p->set_var('common_hidden',$p->get_var('common_hidden').'<input type="hidden" name="preserved" value="'.htmlspecialchars(serialize($preserved)).'">'."\n");
5485                        }
5486                        $p->set_var('submit_button',lang('Save'));
5487
5488                        $delete_button = $cancel_button = '';
5489                        if ($event['id'] > 0)
5490                        {
5491                                $var = Array(
5492                                        'action_url_button'     => $this->page('delete','&cal_id='.$event['id']),
5493                                        'action_text_button'    => lang('Delete'),
5494                                        'action_confirm_button' => "onClick=\"return confirm('".lang('Are you sure want to delete this entry?\\nThis will delete this entry for all users.')."')\"",
5495                                        'action_extra_field'    => '',
5496                                        'button_id'     =>      'delete_button'
5497                                );
5498                                $p->set_var($var);
5499                                $delete_button = $p->fp('out','form_button');
5500                        }
5501                        $p->set_var('delete_button',$delete_button);
5502                        $p->set_var('alert_msg',lang('Required field (category) is empty'));
5503
5504                        if ($this->bo->return_to)
5505                        {
5506                                $var = Array(
5507                                        'action_url_button'     => $GLOBALS['phpgw']->link('/index.php','menuaction='.$this->bo->return_to),
5508                                        'action_text_button'    => lang('Cancel'),
5509                                        'action_confirm_button' => '',
5510                                        'action_extra_field'    => '',
5511                                        'button_id'     =>      'cancel_button'
5512                                );
5513                                $p->set_var($var);
5514                                $cancel_button = $p->fp('out','form_button');
5515                        }
5516                        $p->set_var('cancel_button',$cancel_button);
5517                        $p->pparse('out','edit_entry');
5518                }
5519               
5520                // modify list of an event's external participants (i.e. non pgpgw users)
5521                //
5522                function modify_ext_partlist()
5523                {
5524                        $GLOBALS['phpgw_info']['flags']['noheader'] = True;
5525                        $GLOBALS['phpgw_info']['flags']['nonavbar'] = True;
5526                        $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
5527                        $GLOBALS['phpgw_info']['flags']['noappfooter'] = True;
5528
5529                        $total_contacts = 0;
5530                        $participant = array();
5531                        $control_data= array();
5532
5533                        $control_data['action'] = '';
5534                        $control_data['delete'] = array();
5535                        $control_data['part'] = array();
5536
5537                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
5538                        $p->set_file(
5539                                Array(
5540                                        'T_edit_partlist' => 'edit_partlist.tpl',
5541                                        'T_edit_partlist_blocks' => 'edit_partlist_blocks.tpl'
5542                                )
5543                        );
5544
5545                        $p->set_block('T_edit_partlist_blocks','B_alert_msg','V_alert_msg');
5546                        $p->set_block('T_edit_partlist_blocks','B_partlist','V_partlist');
5547                        $p->set_block('T_edit_partlist_blocks','B_participants_none','V_participants_none');
5548                        $p->set_block('T_edit_partlist_blocks','B_delete_btn','V_delete_btn');
5549
5550                        global $query_addr;
5551                        $sb = CreateObject('phpgwapi.sbox2');
5552                        $addy = $sb->getAddress('addr','',$query_addr);
5553
5554                        $add_ext  = $addy['doSearchFkt'];
5555                        $add_ext .= $addy['addr_title']!=lang('Address Book')?$addy['addr_title']:'';
5556                        $add_ext .= "&nbsp;".$addy['addr'].$addy['addr_nojs'];
5557
5558                        $p->set_var('text_add_name',$add_ext);
5559
5560                        if(isset($_GET['part']) && $_GET['part'])
5561                        {
5562                                $control_data['part'] = split(",", $_GET['part']);
5563                        }
5564                        else
5565                        {
5566                                $control_data['part'] = $_POST['participant'];
5567                                $control_data['action'] = $_POST['action'];
5568                                $control_data['delete'] = $_POST['delete'];
5569                        }
5570
5571                        for ($i=0; $i<count($control_data['part']); $i++)
5572                        {
5573                                $id = $control_data['part'][$i];
5574                                list($contact) = $this->read_contact($id);
5575
5576                                $participant[$id] = array();
5577                                $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
5578                        }
5579
5580                        if ($control_data['action'] == lang('Delete selected contacts'))
5581                        {
5582                                for ($i=0; $i<count($control_data['delete']); $i++)
5583                                {
5584                                        $id = $control_data['delete'][$i];
5585                                        unset($participant[$id]);
5586                                }
5587                        }
5588
5589                        if ($control_data['action'] == lang('Add Contact'))
5590                        {
5591                                $id = $_POST['id_addr'];
5592                                if (isset($id) && (int)$id != 0)
5593                                {
5594                                        list($contact) = $this->read_contact($id);
5595                                        $participant[$id] = array();
5596                                        $participant[$id]['name'] = $contact['n_given'].' '.$contact['n_family'];
5597                                }
5598                        }
5599
5600                        // create list of currently selected contacts
5601                        //
5602                        while(list($id,$contact) = each($participant))
5603                        {
5604                                $p->set_var('hidden_delete_name','participant[]');
5605                                $p->set_var('hidden_delete_value',$id);
5606                                $p->set_var('ckbox_delete_name','delete[]');
5607                                $p->set_var('ckbox_delete_value',$id);
5608                                $p->set_var('ckbox_delete_participant',$contact['name']);
5609                                $p->parse('V_partlist','B_partlist',True);
5610                                $total_contacts++;
5611                        }
5612
5613                        if ($total_contacts == 0)
5614                        {
5615                                // no contacts have been selected
5616                                // => clear the delete form, remove delete button and show the none block
5617                                //
5618                                $p->set_var('V_partlist','');
5619                                $p->set_var('V_delete_btn','');
5620                                $p->set_var('text_none',lang('None'));
5621                                $p->parse('V_participants_none','B_participants_none');
5622                        }
5623                        else
5624                        {
5625                                // at least one contact has been selected
5626                                // => clear the none block, fill the delete form and add delete button
5627                                //
5628                                $p->set_var('V_participants_none','');
5629                                $p->set_var('btn_delete_name','action');
5630                                $p->set_var('btn_delete_value',lang('Delete selected contacts'));
5631                                $p->parse('V_delete_btn','B_delete_btn');
5632                        }
5633
5634                        $body_tags  = 'bgcolor="'.$GLOBALS['phpgw_info']['theme']['bg_color']
5635                                                        . '" alink="'.$GLOBALS['phpgw_info']['theme']['alink']
5636                                                        . '" link="'.$GLOBALS['phpgw_info']['theme']['link']
5637                                                        .'" vlink="'.$GLOBALS['phpgw_info']['theme']['vlink'].'"';
5638
5639                        $form_action = $GLOBALS['phpgw']->link('/index.php', array('menuaction' => 'calendar.uicalendar.modify'));
5640
5641                        $charset = lang('charset');
5642                        $p->set_var('charset',$charset);
5643                        $p->set_var('page_title',$GLOBALS['phpgw_flags']['currentapp']
5644                                . ' - ' .lang('External Participants'));
5645                        $p->set_var('font_family',$GLOBALS['phpgw_info']['theme']['font']);
5646                        $p->set_var('body_tags',$body_tags);
5647                        $p->set_var('form_method','POST');
5648                        $p->set_var('form_action',$form_action);
5649                        $p->set_var('text_add_contact',lang('External Participants'));
5650                        $p->set_var('text_contacts_selected',lang('Selected contacts (%1)',$total_contacts));
5651                        $p->set_var('btn_add_name','action');
5652                        $p->set_var('btn_add_value',lang('Add Contact'));
5653                        $p->set_var('btn_done_name','done');
5654                        $p->set_var('btn_done_value',lang('Done'));
5655                        $p->set_var('btn_done_js','copyback()');
5656                        $p->set_var('form1_name','ext_form');
5657
5658                        $p->pfp('out','T_edit_partlist');
5659                }
5660
5661                function read_contact($id)
5662                {
5663                        $query_fields = Array(
5664                                'n_given' => 'n_given',
5665                                'n_family' => 'n_family',
5666                                'email' => 'email',
5667                                'email_home' => 'email_home'
5668                        );
5669
5670                        /*
5671                        if ($this->rights & PHPGW_ACL_READ)
5672                        {
5673                                return $this->contacts->read_single_entry($id,$fields);
5674                        }
5675                        else
5676                        {
5677                                $rtrn = array(0 => array('No access' => 'No access'));
5678                                return $rtrn;
5679                        }
5680                        */
5681
5682                        $contacts = CreateObject('phpgwapi.contacts', False);
5683                        return $contacts->read_single_entry($id,$query_fields);
5684                }
5685
5686                function build_part_list(&$users,$accounts,$owner)
5687                {
5688                        if(!is_array($accounts))
5689                        {
5690                                return;
5691                        }
5692                        foreach($accounts as $id)
5693                        {
5694                                $id = (int)$id;
5695                                if($id == $owner)
5696                                {
5697                                        continue;
5698                                }
5699                                elseif(!isset($users[$id]))
5700                                {
5701                                        if($GLOBALS['phpgw']->accounts->exists($id) == True)
5702                                        {
5703                                                $users[$id] = Array(
5704                                                        'name'  => $GLOBALS['phpgw']->common->grab_owner_name($id),
5705                                                        'type'  => $GLOBALS['phpgw']->accounts->get_type($id)
5706                                                );
5707                                        }
5708                                        if($GLOBALS['phpgw']->accounts->get_type($id) == 'g')
5709                                        {
5710                                                //$this->build_part_list($users,$GLOBALS['phpgw']->acl->get_ids_for_location($id,1,'phpgw_group'),$owner);
5711                                        }
5712                                }
5713                        }
5714                        if (!function_exists('strcmp_name'))
5715                        {
5716                                function strcmp_name($arr1,$arr2)
5717                                {
5718                                        if ($diff = strcmp($arr1['type'],$arr2['type']))
5719                                        {
5720                                                return $diff;   // groups before users
5721                                        }
5722                                        return strnatcasecmp($arr1['name'],$arr2['name']);
5723                                }
5724                        }
5725                        uasort($users,'strcmp_name');
5726                }
5727
5728                function set_week_array($startdate,$cellcolor,$weekly)
5729                {
5730                        $data = date("m");
5731                        for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
5732                        {
5733                                $date = date('Ymd',$datetime + (60 * 60 * 2)); // +2h to be save when switching to and from dst, $datetime is alreay + TZ-Offset
5734                                print_debug('set_week_array : Date ',$date);
5735
5736                                if($events = $this->bo->cached_events[$date])
5737                                {
5738                                        print_debug('Date',$date);
5739                                        print_debug('Appointments Found',count($events));
5740
5741                                        if (!$this->bo->prefs['calendar']['show_rejected'])
5742                                        {
5743                                                $appts = False;
5744                                                foreach($events as $event)      // check for a not-rejected event
5745                                                {
5746                                                        if (!$this->bo->rejected_no_show($event))
5747                                                        {
5748                                                                $appts = True;
5749                                                                break;
5750                                                        }
5751                                                }
5752                                        }
5753                                        else
5754                                        {
5755                                                $appts = True;
5756                                        }
5757                                }
5758                                else
5759                                {
5760                                        $appts = False;
5761                                }
5762
5763                                $holidays = $this->bo->cached_holidays[$date];
5764                                if($weekly)
5765                                {
5766                                        $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
5767                                }
5768
5769                                $day_image = '';
5770                                if($holidays)
5771                                {
5772                                        $extra = ' bgcolor="'.$this->bo->holiday_color.'"';
5773                                        $class = ($appts?'b':'').'minicalhol';
5774                                        if ($date == $this->bo->today)
5775                                        {
5776                                                $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5777                                        }
5778                                }
5779                                elseif ($date != $this->bo->today)
5780                                {
5781                                        $extra = ' bgcolor="'.$cellcolor.'"';
5782                                        $class = ($appts?'b':'').'minicalendar';
5783                                }
5784                                else
5785                                {
5786                                        $extra = ' bgcolor="'.$GLOBALS['phpgw_info']['theme']['cal_today'].'"';
5787                                        $class = ($appts?'b':'').'minicalendar';
5788                                        $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
5789                                }
5790
5791                                if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
5792                                {
5793                                        $extra = '';
5794                                }
5795
5796                                if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
5797                                {
5798                                        $new_event = True;
5799                                }
5800                                else
5801                                {
5802                                        $new_event = False;
5803                                }
5804                                $holiday_name = Array();
5805                                if($holidays)
5806                                {
5807                                        for($k=0;$k<count($holidays);$k++)
5808                                        {
5809                                                $holiday_name[] = $holidays[$k]['name'];
5810                                        }
5811                                }
5812                                $week = '';
5813                                if (!$j || (!$weekly && $j && substr($date,6,2) == '01'))
5814                                {
5815                                        $week = lang('week').' '.(int)((date('z',($startdate+(24*3600*4)))+7)/7);
5816                                }
5817                                $daily[$date] = Array(
5818                                        'extra'         => $extra,
5819                                        'new_event'     => $new_event,
5820                                        'holidays'      => $holiday_name,
5821                                        'appts'         => $appts,
5822                                        'week'          => $week,
5823                                        'day_image'     => $day_image,
5824                                        'class'         => $class
5825                                );
5826                        }
5827
5828                        if($this->debug)
5829                        {
5830                                _debug_array($daily);
5831                        }
5832
5833                        return $daily;
5834                }
5835               
5836                function get_organizations($context, $selected='', $recursive = false)
5837                {
5838                        $s = CreateObject('phpgwapi.sector_search_ldap');
5839                                               
5840                        return ($recursive ?
5841                                $s->get_organizations($context, $selected, false ,false) :
5842                                $s->get_sectors($selected, false, false));
5843                }               
5844        }
5845?>
Note: See TracBrowser for help on using the repository browser.