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

Revision 1500, 184.7 KB checked in by eduardoalex, 15 years ago (diff)

Ticket #681 - Criada a função para delegar evento

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