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

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

Ticket #717 - Correcao da alteracao feita na revisao 1593

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