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

Revision 1720, 185.9 KB checked in by eduardoalex, 14 years ago (diff)

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