source: branches/2.2.0.1/calendar/inc/class.uicalendar.inc.php @ 4183

Revision 4183, 221.8 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1812 - Incluir 3 mini-calendários na visão diaria

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