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

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

Ticket #1798 - Destacar nos mini-calendários o dia que está em exibição

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