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

Revision 4030, 215.5 KB checked in by rafaelraymundo, 13 years ago (diff)

Ticket #1742 - Imprimir Horários Livres na Impressão Diária

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