source: sandbox/2.3-MailArchiver/calendar/inc/class.uipublicview.inc.php @ 6779

Revision 6779, 30.9 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Calendar                                                    *
4  * http://www.eGroupWare.org                                                *
5  * Maintained and further developed by RalfBecker@outdoor-training.de       *
6  * Based on Webcalendar by Craig Knudsen <cknudsen@radix.net>               *
7  *          http://www.radix.net/~cknudsen                                  *
8  * Originaly modified by Mark Peters <skeeter@phpgroupware.org>             *
9  * --------------------------------------------                             *
10  *  This program is free software; you can redistribute it and/or modify it *
11  *  under the terms of the GNU General Public License as published by the   *
12  *  Free Software Foundation; either version 2 of the License, or (at your  *
13  *  option) any later version.                                              *
14  \**************************************************************************/
15
16
17        class uipublicview
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                // Variable defined to view public calendars;
29                var $publicView = False;
30                var $user = False;
31
32                var $debug = False;
33//              var $debug = True;
34
35                var $cat_id;
36                var $theme;
37                var $link_tpl;
38
39                // planner related variables
40                var $planner_header;
41                var $planner_rows;
42
43                var $planner_group_members;
44
45                var $planner_firstday;
46                var $planner_lastday;
47                var $planner_days;
48
49                var $planner_end_month;
50                var $planner_end_year;
51                var $planner_days_in_end_month;
52
53                var $planner_intervals = array( // conversation hour and interval depending on intervals_per_day
54                                        //                                  1 1 1 1 1 1 1 1 1 1 2 2 2 2
55                                        //              0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3
56                                                '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
57                                                '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
58                                                '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
59                                                '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
60                                        );
61
62                var $public_functions = array(         
63                        'index' => True,
64                        'publicView'  => True,
65                        'get_publicView' => True,
66                        'view' => True,
67                        'header' => True,
68                        'footer' => True,
69                       
70                );
71
72                function uipublicview()
73                {
74                        $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
75                        $GLOBALS['phpgw']->browser    = CreateObject('phpgwapi.browser');
76
77                        $this->theme = $GLOBALS['phpgw_info']['theme'];
78
79                        $this->bo = CreateObject('calendar.bocalendar',1);
80                        $this->cat = &$this->bo->cat;
81                        print_debug('BO Owner',$this->bo->owner);
82
83                        $this->template = $GLOBALS['phpgw']->template;
84                        $this->template_dir = $GLOBALS['phpgw']->common->get_tpl_dir('calendar');
85                        $this->holiday_color = (substr($this->theme['bg06'],0,1)=='#'?'':'#').$this->theme['bg06'];
86
87                        $this->cat_id   = $this->bo->cat_id;
88
89                        $this->link_tpl = CreateObject('phpgwapi.Template',$this->template_dir);
90                        $this->link_tpl->set_unknowns('remove');
91                        $this->link_tpl->set_file(
92                                Array(
93                                        'link_picture'  => 'link_pict.tpl'
94                                )
95                        );
96                       
97                        $this->link_tpl->set_block('link_picture','link_pict','link_pict');
98                        $this->link_tpl->set_block('link_picture','pict','pict');
99                        $this->link_tpl->set_block('link_picture','link_open','link_open');
100                        $this->link_tpl->set_block('link_picture','link_close','link_close');
101                        $this->link_tpl->set_block('link_picture','link_text','link_text');
102
103                        if($this->bo->use_session)
104                        {
105                                // save return-fkt for add, view, ...
106                                list(,,$fkt) = explode('.',$_GET['menuaction']);
107                                if ($fkt == 'day' || $fkt == 'week' || $fkt == 'month' || $fkt == 'year' || $fkt == 'planner')
108                                {
109                                        $this->bo->return_to = $_GET['menuaction'].
110                                                sprintf('&date=%04d%02d%02d',$this->bo->year,$this->bo->month,$this->bo->day);
111                                }
112                                $this->bo->save_sessiondata();
113                        }
114                        $this->always_app_header = True;
115                       
116                       
117                        print_debug('UI',$this->_debug_sqsof());
118
119                        if (!is_object($GLOBALS['phpgw']->html))
120                        {
121                                $GLOBALS['phpgw']->html = CreateObject('phpgwapi.html');
122                        }
123                        $this->html = &$GLOBALS['phpgw']->html;
124                }
125
126                /* Public functions */
127
128                function index($params='')
129                {
130                        if (!$params)
131                        {
132                                foreach(array('date','year','month','day') as $field)
133                                {
134                                        if (isset($_GET[$field]))
135                                        {
136                                                $params[$field] = $_GET[$field];
137                                        }
138                                }
139                        }
140                        $GLOBALS['phpgw']->redirect($this->page('',$params));
141                }
142
143                /* Private functions */
144                function _debug_sqsof()
145                {
146                        $data = array(
147                                'filter'     => $this->bo->filter,
148                                'cat_id'     => $this->bo->cat_id,
149                                'owner'      => $this->bo->owner,
150                                'year'       => $this->bo->year,
151                                'month'      => $this->bo->month,
152                                'day'        => $this->bo->day,
153                                'sortby'     => $this->bo->sortby,
154                                'num_months' => $this->bo->num_months
155                        );
156                        Return _debug_array($data,False);
157                }
158
159                function output_template_array(&$p,$row,$list,$var)
160                {
161                        if (!isset($var['hidden_vars']))
162                        {
163                                $var['hidden_vars'] = '';
164                        }
165                        if (!isset($var['tr_color']))
166                        {
167                                $var['tr_color'] = $GLOBALS['phpgw']->nextmatchs->alternate_row_color();
168                        }
169                        $p->set_var($var);
170                        $p->parse($row,$list,True);
171                }
172
173                function page($_page='',$params='')
174                {
175                        if($_page == '')
176                        {
177                                $page_ = explode('.',$this->bo->prefs['calendar']['defaultcalendar']);
178                                $_page = $page_[0];
179
180                                if ($_page=='planner_cat' || $_page=='planner_user')
181                                {
182                                        $_page = 'planner';
183                                }
184                                elseif ($_page=='index' || ($_page != 'day' && $_page != 'week' && $_page != 'month' && $_page != 'year' && $_page != 'planner'))
185                                {
186                                        $_page = 'month';
187                                        $GLOBALS['phpgw']->preferences->add('calendar','defaultcalendar','month');
188                                        $GLOBALS['phpgw']->preferences->save_repository();
189                                }
190                        }
191                       
192                        if($GLOBALS['phpgw_info']['flags']['currentapp'] == 'home' ||
193                                strstr($GLOBALS['phpgw_info']['flags']['currentapp'],'mail'))   // email, felamimail, ...
194                        {       
195                                $page_app = 'calendar';
196                        }
197                        else
198                        {       
199                                $page_app = $GLOBALS['phpgw_info']['flags']['currentapp'];
200                        }
201                        $page_app = 'calendar.uipublicview.publicView';
202                       
203                        if (is_array($params))
204                        {
205                                $params['menuaction'] = $page_app;
206                        }
207                        else
208                        {
209                                $params = 'menuaction='.$page_app.$params;
210                        }
211                        return $GLOBALS['phpgw']->link('/index.php',$params);
212                }
213
214                function header()
215                {
216                        $cols = 8;
217                        if($this->bo->check_perms(PHPGW_ACL_PRIVATE) == True)
218                        {
219                                $cols++;
220                        }
221
222                        $tpl = $GLOBALS['phpgw']->template;
223                        $tpl->set_unknowns('remove');
224
225                        if (!file_exists($file = $this->template_dir.'/header.inc.php'))
226                        {
227                                $file = PHPGW_SERVER_ROOT . '/calendar/templates/default/header.inc.php';
228                        }
229                        include($file);
230                        $header = $tpl->fp('out','head');
231                        unset($tpl);
232                        echo $header;
233                }
234
235                function footer(){
236               
237                }
238                function selectFilter()
239                {
240                       
241                        $menuaction = $_GET['menuaction'];
242
243                        list(,,$method) = explode('.',$menuaction);
244
245                        if (@$this->bo->printer_friendly)
246                        {
247                                return;
248                        }
249
250                        $p = $GLOBALS['phpgw']->template;
251                       
252                        $p->set_file(
253                                Array(
254                                        'footer'        => 'footer.tpl',
255                                        'form_button'   => 'form_button_script.tpl'
256
257                                )
258                        );
259                        $p->set_block('footer','footer_table','footer_table');
260                        $p->set_block('footer','footer_row','footer_row');
261                        $p->set_block('footer','blank_row','blank_row');
262
263                        $m = $this->bo->month;
264                        $y = $this->bo->year;
265
266                        $thisdate = date('Ymd',mktime(0,0,0,$m,1,$y));
267                        $y--;
268
269                        $str = '';
270                        for ($i = 0; $i < 25; $i++)
271                        {
272                                $m++;
273                                if ($m > 12)
274                                {
275                                        $m = 1;
276                                        $y++;
277                                }
278                                $d = mktime(0,0,0,$m,1,$y);
279                                $d_ymd = date('Ymd',$d);
280                                $str .= '<option value="'.$d_ymd.'"'.($d_ymd == $thisdate?' selected':'').'>'.lang(date('F', $d)).strftime(' %Y', $d).'</option>'."\n";
281                        }
282                       
283                        $var = Array(
284                                'action_url'    => $this->page($method,''),
285                                'form_name'     => 'SelectMonth',
286                                'label'         => lang('Month'),
287                                'user'  => $this->user,
288                                'form_label'    => 'date',
289                                'form_onchange' => 'document.SelectMonth.submit()',
290                                'row'           => $str,
291                                'go'            => lang('Go!')
292                        );
293                       
294                        $this->output_template_array($p,'table_row','footer_row',$var);
295
296                   if($menuaction == 'calendar.uipublicview.week' || $menuaction == 'calendar.uipublicview.publicView')
297                   {
298                                unset($thisdate);
299                                $thisdate = mktime(0,0,0,$this->bo->month,$this->bo->day,$this->bo->year) - $GLOBALS['phpgw']->datetime->tz_offset;
300                                $sun = $GLOBALS['phpgw']->datetime->get_weekday_start($this->bo->year,$this->bo->month,$this->bo->day) - $GLOBALS['phpgw']->datetime->tz_offset;
301
302                                $str = '';
303                                for ($i = -7; $i <= 7; $i++)
304                                {
305                                        $begin = $sun + (7*24*60*60 * $i) + 12*60*60;   // we use midday, that changes in daylight-saveing does not effect us
306                                        $end = $begin + 6*24*60*60;
307                    $str .= '<option value="' . $GLOBALS['phpgw']->common->show_date($begin,'Ymd') . '"'.($begin <= $thisdate+12*60*60 && $end >= $thisdate+12*60*60 ? ' selected':'').'>'                   
308                                                . $GLOBALS['phpgw']->common->show_date($begin,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']) . ' - '
309                        . $GLOBALS['phpgw']->common->show_date($end,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'])
310                        . '</option>' . "\n";                       
311                                }
312
313                                $var = Array(
314                                        'action_url'    => $this->page($method,''),
315                                        'form_name'     => 'SelectWeek',
316                                        'label'         => lang('Week'),
317                                        'form_label'    => 'date',
318                                        'user'  => $this->user,
319                                        'form_onchange' => 'document.SelectWeek.submit()',
320                                        'row'           => $str,
321                                        'go'            => lang('Go!')
322                                );
323
324                                $this->output_template_array($p,'table_row','footer_row',$var);
325                        }
326
327                        $str = '';
328                        for ($i = ($this->bo->year - 3); $i < ($this->bo->year + 3); $i++)
329                        {
330                                $str .= '<option value="'.$i.'"'.($i == $this->bo->year?' selected':'').'>'.$i.'</option>'."\n";
331                        }
332
333                        $var = Array(
334                                'action_url'    => $this->page($method,''),
335                                'form_name'     => 'SelectYear',
336                                'label'         => lang('Year'),
337                                'user'  => $this->user,
338                                'form_label'    => 'year',
339                                'form_onchange' => 'document.SelectYear.submit()',
340                                'row'           => $str,
341                                'go'            => lang('Go!')
342                        );
343                        $this->output_template_array($p,'table_row','footer_row',$var);
344
345                        if($menuaction == 'calendar.uipublicview.planner')
346                        {
347                                $str = '';
348                                $date_str = '';
349
350                                if(isset($_GET['date']) && $_GET['date'])
351                                {
352                                        $date_str .= '    <input type="hidden" name="date" value="'.$_GET['date'].'">'."\n";
353                                }
354                                $date_str .= '    <input type="hidden" name="month" value="'.$this->bo->month.'">'."\n";
355                                $date_str .= '    <input type="hidden" name="day" value="'.$this->bo->day.'">'."\n";
356                                $date_str .= '    <input type="hidden" name="year" value="'.$this->bo->year.'">'."\n";
357
358                                for($i=1; $i<=6; $i++)
359                                {
360                                        $str .= '<option value="'.$i.'"'.($i == $this->bo->num_months?' selected':'').'>'.$i.'</option>'."\n";
361                                }
362                               
363                                $var = Array(
364                                        'action_url'    => $this->page($method,''),
365                                        'form_name'     => 'SelectNumberOfMonths',
366                                        'label'         => lang('Number of Months'),
367                                        'hidden_vars' => $date_str,
368                                        'form_label'    => 'num_months',
369                                        'form_onchange' => 'document.SelectNumberOfMonths.submit()',
370                                        'action_extra_field'    => $date_str,
371                                        'user'  => $this->user,
372                                        'row'           => $str,
373                                        'go'            => lang('Go!')
374                                );
375                               
376
377                                $this->output_template_array($p,'table_row','footer_row',$var);
378                        }
379                               
380                        $p->pparse('out','footer_table');
381                        unset($p);
382                }
383
384
385                function link_to_entry($event,$month,$day,$year)
386                {
387                        $str = '';
388                        $is_private = !$event['public'] && !$this->bo->check_perms(PHPGW_ACL_READ,$event);
389                        $viewable = !$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_READ,$event);
390
391                        $starttime = $this->bo->maketime($event['start']) - $GLOBALS['phpgw']->datetime->tz_offset;
392                        $endtime = $this->bo->maketime($event['end']) - $GLOBALS['phpgw']->datetime->tz_offset;
393                        $rawdate = mktime(0,0,0,$month,$day,$year);
394                        $rawdate_offset = $rawdate - $GLOBALS['phpgw']->datetime->tz_offset;
395                        $nextday = mktime(0,0,0,$month,$day + 1,$year) - $GLOBALS['phpgw']->datetime->tz_offset;
396                        if ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') && $starttime == $endtime)
397                        {
398                                $time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
399                        }
400                        elseif ($starttime <= $rawdate_offset && $endtime >= $nextday - 60)
401                        {
402                                $time = '[ '.lang('All Day').' ]';
403                        }
404                        elseif ((int)$GLOBALS['phpgw']->common->show_date($starttime,'Hi') || $starttime != $endtime)
405                        {
406                                if($starttime < $rawdate_offset && $event['recur_type'] == MCAL_RECUR_NONE)
407                                {
408                                        $start_time = $GLOBALS['phpgw']->common->show_date($rawdate_offset,$this->bo->users_timeformat);
409                                }
410                                else
411                                {
412                                        $start_time = $GLOBALS['phpgw']->common->show_date($starttime,$this->bo->users_timeformat);
413                                }
414
415                                if($endtime >= ($rawdate_offset + 86400))
416                                {
417                                        $end_time = $GLOBALS['phpgw']->common->show_date(mktime(23,59,59,$month,$day,$year) - $GLOBALS['phpgw']->datetime->tz_offset,$this->bo->users_timeformat);
418                                }
419                                else
420                                {
421                                        $end_time = $GLOBALS['phpgw']->common->show_date($endtime,$this->bo->users_timeformat);
422                                }
423                                $time = $start_time.'-'.$end_time;
424                        }
425                        else
426                        {
427                                $time = '';
428                        }
429                       
430                        $texttitle = $texttime = $textdesc = $textlocation = $textstatus = '';
431
432                       
433                       
434                        if(!$is_private)
435                        {
436                                // split text for better display by templates, also see $texttime $texttitle $textdesc $textlocation   
437                                $textstatus=$this->bo->display_status($event['users_status']);
438                               
439                        }
440
441                       
442                        $texttime=$time;
443                        $texttitle=$this->bo->get_short_field($event,$is_private,'title');
444                        $textdesc=(!$is_private && $event['description'] ? $this->bo->get_short_field($event,$is_private,'description'):'');
445                        // added $textlocation but this must be activated in the actual pict_link.tpl file of the used template set
446                        $textlocation=$this->bo->get_short_field($event,$is_private,'location');
447
448                        if (!$is_private)
449                        {
450                                if($event['priority'] == 3)
451                                {
452                                        $picture[] = Array(
453                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','high'),
454                                                'width' => 16,
455                                                'height'=> 16,
456                                                'title' => lang('high priority')
457                                        );
458                                }
459                                if($event['recur_type'] == MCAL_RECUR_NONE)
460                                {
461                                        $picture[] = Array(
462                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
463                                                'width' => 9,
464                                                'height'=> 9,
465                                                'title' => lang('single event')
466                                        );
467                                }
468                                if($event['attachment'] != '')
469                                {
470                                        $picture[] = Array(
471                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','circle'),
472                                                'width' => 9,
473                                                'height'=> 9,
474                                                'title' => lang('Has Attachment')
475                                        );
476                                }
477                                else
478                                {
479                                        $picture[] = Array(
480                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','recur'),
481                                                'width' => 12,
482                                                'height'=> 12,
483                                                'title' => lang('recurring event')
484                                        );
485                                }
486                        }
487                        $participants = $this->planner_participants($event['participants']);
488                        if(count($event['participants']) > 1)
489                        {
490                                $picture[] = Array(
491                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','multi_3'),
492                                        'width' => 14,
493                                        'height'=> 14,
494                                        'title' => $participants
495                                );
496                        }
497                        else
498                        {
499                                $picture[] = Array(
500                                        'pict'  =>  $GLOBALS['phpgw']->common->image('calendar','single'),
501                                        'width' => 14,
502                                        'height'=> 14,
503                                        'title' => $participants
504                                );
505                        }
506                        if($event['public'] == 0)
507                        {
508                                $picture[] = Array(
509                                        'pict'  => $GLOBALS['phpgw']->common->image('calendar','private'),
510                                        'width' => 13,
511                                        'height'=> 13,
512                                        'title' => lang('private')
513                                );
514                        }
515                        if(@isset($event['alarm']) && count($event['alarm']) >= 1 && !$is_private)
516                        {
517                                // if the alarm is to go off the day before the event
518                                // the icon does not show up because of 'alarm_today'
519                                // - TOM
520                                if($this->bo->alarm_today($event,$rawdate_offset,$starttime))
521                                {
522                                        $picture[] = Array(
523                                                'pict'  => $GLOBALS['phpgw']->common->image('calendar','alarm'),
524                                                'width' => 13,
525                                                'height'=> 13,
526                                                'title' => lang('alarm')
527                                        );
528                                }
529                        }
530
531                        if($event['attachment'] != '')
532                        {
533                            $picture[] = Array(
534                                    'pict'      => $GLOBALS['phpgw']->common->image('calendar','circle'),
535                                    'width'     => 9,
536                                    'height'=> 9,
537                                    'title' => lang('Has Attachment')
538                            );
539                        }
540                        $description = $this->bo->get_short_field($event,$is_private,'description');
541                        for($i=0;$i<count($picture);$i++)
542                        {
543                                $var = Array(
544                                        'pic_image' => $picture[$i]['pict'],
545                                        'width'     => $picture[$i]['width'],
546                                        'height'    => $picture[$i]['height'],
547                                        'title'     => $picture[$i]['title']
548                                );
549                                $this->output_template_array($this->link_tpl,'picture','pict',$var);
550                        }
551                        if ($texttitle)
552                        {
553                                $var = Array(
554                        //              'text' => $text,
555                                        'time'=> $texttime,
556                                        'title'=> $texttitle,
557                                        'users_status'=>$textstatus,
558                                        'desc'=> $textdesc,
559                                        'location'=> $textlocation
560                                );
561                                $this->output_template_array($this->link_tpl,'picture','link_text',$var);
562                        }
563
564                        if ($viewable)
565                        {
566                                $this->link_tpl->parse('picture','link_close',True);
567                        }
568                        $str = $this->link_tpl->fp('out','link_pict');
569                        $this->link_tpl->set_var('picture','');
570                        $this->link_tpl->set_var('out','');
571//                      unset($p);
572                        return $str;
573                }
574
575                function planner_participants($parts)
576                {
577                        static $id2lid;
578
579                        $names = '';
580                        while (list($id,$status) = each($parts))
581                        {
582                                $status = substr($this->bo->get_long_status($status),0,1);
583
584                                if (!isset($id2lid[$id]))
585                                {
586                                        $id2lid[$id] = $GLOBALS['phpgw']->common->grab_owner_name($id);
587                                }
588                                if (strlen($names))
589                                {
590                                        $names .= ",\n";
591                                }
592                                $names .= $id2lid[$id]." ($status)";
593                        }
594                        if($this->debug)
595                        {
596                                echo '<!-- Inside participants() : '.$names.' -->'."\n";
597                        }
598                        return $names;
599                }
600
601
602                function week_header($month,$year,$display_name = False)
603                {
604                        $this->weekstarttime = $GLOBALS['phpgw']->datetime->get_weekday_start($year,$month,1);
605
606                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
607                        $p->set_unknowns('remove');
608                        $p->set_file(
609                                Array (
610                                        'month_header' => 'month_header.tpl'
611                                )
612                        );
613                        $p->set_block('month_header','monthly_header','monthly_header');
614                        $p->set_block('month_header','column_title','column_title');
615
616                        $var = Array(
617                                'bgcolor'       => $this->theme['th_bg'],
618                                'font_color'    => $this->theme['th_text']
619                        );
620                        if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
621                        {
622                                $var = Array(
623                                        'bgcolor'       => '',
624                                        'font_color'    => ''
625                                );
626                        }
627                        $p->set_var($var);
628
629                        $p->set_var('col_width','14');
630                        if($display_name == True)
631                        {
632                                $p->set_var('col_title',lang('name'));
633                                $p->parse('column_header','column_title',True);
634                                $p->set_var('col_width','12');
635                        }
636
637                        for($i=0;$i<7;$i++)
638                        {
639                                $p->set_var('col_title',lang($GLOBALS['phpgw']->datetime->days[$i]));
640                                $p->parse('column_header','column_title',True);
641                        }
642                        return $p->fp('out','monthly_header');
643                }
644
645                function display_week($startdate,$weekly,$cellcolor,$display_name = False,$owner=0,$monthstart=0,$monthend=0)
646                {       
647                        if($owner == 0)
648                        {
649                                $owner = $GLOBALS['phpgw_info']['user']['account_id'];
650                        }
651
652                        $temp_owner = $this->bo->owner;
653                        $publicView = $this -> publicView;
654
655                        $str = '';
656                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
657                        $p->set_unknowns('keep');
658
659                        $p->set_file(
660                                Array(
661                                        'month_header'  => 'month_header.tpl',
662                                        'month_day'     => 'month_day.tpl'
663                                )
664                        );
665                        $p->set_block('month_header','monthly_header','monthly_header');
666                        $p->set_block('month_header','month_column','month_column');
667                        $p->set_block('month_day','month_daily','month_daily');
668                        $p->set_block('month_day','day_event','day_event');
669                        $p->set_block('month_day','event','event');
670
671                        $p->set_var('extra','');
672                        $p->set_var('col_width','14');
673                        if($display_name)
674                        {
675                                $p->set_var('column_data',$GLOBALS['phpgw']->common->grab_owner_name($owner));
676                                $p->parse('column_header','month_column',True);
677                                $p->set_var('col_width','12');
678                        }
679                        $today = date('Ymd',$GLOBALS['phpgw']->datetime->users_localtime);
680                        $daily = $this->set_week_array($startdate - $GLOBALS['phpgw']->datetime->tz_offset,$cellcolor,$weekly);
681                        foreach($daily as $date => $day_params)
682                        {
683                                $year  = (int)substr($date,0,4);
684                                $month = (int)substr($date,4,2);
685                                $day   = (int)substr($date,6,2);
686                                $var   = Array(
687                                        'column_data' => '',
688                                        'extra' => ''
689                                );
690                                $p->set_var($var);
691                                if ($weekly || ($date >= $monthstart && $date <= $monthend))
692                                {
693                                        if ($day_params['new_event'] && !$publicView)
694                                        {
695                                                $new_event_link = ' <a href="'.$this->page('add','&date='.$date).'">'
696                                                        . '<img src="'.$GLOBALS['phpgw']->common->image('calendar','new3').'" width="10" height="10" title="'.lang('New Entry').'" border="0" align="center">'
697                                                        . '</a>';
698                                                $day_number = '<a href="'.$this->page('day','&date='.$date).'">'.$day.'</a>';
699                                        }
700                                        else
701                                        {
702                                                $new_event_link = '';
703                                                $day_number = $day;
704                                        }
705
706                                        $var = Array(
707                                                'extra'         => $day_params['extra'],
708                                                'new_event_link'=> $new_event_link,
709                                                'day_number'    => $day_number
710                                        );
711                                                        $p->set_var($var);
712
713                                        if(@$day_params['holidays'])
714                                        {
715                                                foreach($day_params['holidays'] as $key => $value)
716                                                {
717                                                        $var = Array(
718                                                                'day_events' => '<font face="'.$this->theme['font'].'" size="-1">'.$value.'</font>'.$GLOBALS['phpgw']->browser->br
719                                                        );
720                                                        $this->output_template_array($p,'daily_events','event',$var);
721                                                }
722                                        }
723
724                                        if($day_params['appts'])
725                                        {
726                                                $var = Array(
727                                                        'week_day_font_size'    => '2',
728                                                        'events'                => ''
729                                                );
730                                                $p->set_var($var);
731                                                $events = $this->bo->cached_events[$date];
732                                                foreach($events as $event)
733                                                {
734                                                        if ($this->bo->rejected_no_show($event))
735                                                        {
736                                                                continue;       // user does not want to see rejected events
737                                                        }
738                                                        $p->set_var('day_events',$this->link_to_entry($event,$month,$day,$year));
739                                                        $p->parse('events','event',True);
740                                                        $p->set_var('day_events','');
741                                                }
742                                        }
743                                        $p->parse('daily_events','day_event',True);
744                                        $p->parse('column_data','month_daily',True);
745                                        $p->set_var('daily_events','');
746                                        $p->set_var('events','');
747                                }
748                                $p->parse('column_header','month_column',True);
749                                $p->set_var('column_data','');
750                        }
751                        $this->bo->owner = $temp_owner;
752                        return $p->fp('out','monthly_header');
753                }
754
755                function display_month($month,$year,$showyear,$owner=0)
756                {
757                        if($this->debug)
758                        {
759                                echo '<!-- datetime:gmtdate = '.$GLOBALS['phpgw']->datetime->cv_gmtdate.' -->'."\n";
760                        }
761
762                        $this->bo->store_to_cache(
763                                Array(
764                                        'syear' => $year,
765                                        'smonth'=> $month,
766                                        'sday'  => 1
767                                )
768                        );
769
770                        $monthstart = (int)(date('Ymd',mktime(0,0,0,$month    ,1,$year)));
771                        $monthend   = (int)(date('Ymd',mktime(0,0,0,$month + 1,0,$year)));
772
773                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, 1);
774
775                        if($this->debug)
776                        {
777                                echo '<!-- display_month:monthstart = '.$monthstart.' -->'."\n";
778                                echo '<!-- display_month:start = '.date('Ymd H:i:s',$start).' -->'."\n";
779                        }
780
781                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
782                        $p->set_unknowns('keep');
783
784                        $p->set_file(
785                                Array(
786                                        'week' => 'month_day.tpl'
787                                )
788                        );
789                        $p->set_block('week','m_w_table','m_w_table');
790                        $p->set_block('week','event','event');
791
792                        $var = Array(
793                                'cols'      => 7,
794                                'day_events'=> $this->week_header($month,$year,False)
795                        );
796                        $this->output_template_array($p,'row','event',$var);
797
798                        $cellcolor = $this->theme['row_on'];
799
800                        for($i = (int)($start + $GLOBALS['phpgw']->datetime->tz_offset);(int)(date('Ymd',$i)) <= $monthend;$i += 604800)
801                        {
802                                $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
803                                $var = Array(
804                                        'day_events' => $this->display_week($i,False,$cellcolor,False,$owner,$monthstart,$monthend)
805                                );
806                                $this->output_template_array($p,'row','event',$var);
807                        }
808                        return $p->fp('out','m_w_table');
809                }
810
811                function display_weekly($params, $accountId)
812                {
813                        if(!is_array($params))
814                        {
815                                $this->index();
816                        }
817
818                        $year = substr($params['date'],0,4);
819                        $month = substr($params['date'],4,2);
820                        $day = substr($params['date'],6,2);
821                        $showyear = $params['showyear'];
822                        $owners = $params['owners'];
823                       
824                       
825                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
826                        $p->set_unknowns('keep');
827
828                        $p->set_file(
829                                Array(
830                                        'week'  => 'month_day.tpl'
831                                )
832                        );
833                        $p->set_block('week','m_w_table','m_w_table');
834                        $p->set_block('week','event','event');
835
836                        $start = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
837
838                        $cellcolor = $this->theme['row_off'];
839
840                        $true_printer_friendly = $this->bo->printer_friendly;
841
842                        if(is_array($owners))
843                        {
844                                $display_name = True;
845                                $counter = count($owners);
846                                $owners_array = $owners;
847                                $cols = 8;
848                        }
849                        else
850                        {
851                                $display_name = False;
852                                $counter = 1;
853                                $owners_array[0] = $owners;
854                                $cols = 7;
855                        }
856                        $var = Array(
857                                'cols'         => $cols,
858                                'day_events'   => $this->week_header($month,$year,$display_name)
859                        );
860                        $this->output_template_array($p,'row','event',$var);
861
862                        $tstart = $start - $GLOBALS['phpgw']->datetime->tz_offset;
863                        $tstop = $tstart + 604800;
864                        $original_owner = $this->bo->so->owner;
865
866                        $this->bo->so->owner = $accountId;
867                        $this->bo->so->open_box($accountId);
868                        $this->bo->store_to_cache(
869                                        Array(
870                                                'syear'  => date('Y',$tstart),
871                                                'owner' => $original_owner,
872                                                'smonth' => date('m',$tstart),
873                                                'sday'   => date('d',$tstart),
874                                                'eyear'  => date('Y',$tstop),
875                                                'emonth' => date('m',$tstop),
876                                                'eday'   => date('d',$tstop)
877                                        )
878                                );
879                               
880                        $p->set_var('day_events',$this->display_week($start,True,$cellcolor,$display_name,$accountId, True));
881                                $p->parse('row','event',True);
882                       
883                        $this->bo->so->owner = $original_owner;
884                        $this->bo->printer_friendly = $true_printer_friendly;
885                        return $p->fp('out','m_w_table');
886                }
887               
888                function set_week_array($startdate,$cellcolor,$weekly)
889                {
890                        for ($j=0,$datetime=$startdate;$j<7;$j++,$datetime += 86400)
891                        {
892                                $date = date('Ymd',$datetime + (60 * 60 * 2)); // +2h to be save when switching to and from dst, $datetime is alreay + TZ-Offset
893                                print_debug('set_week_array : Date ',$date);
894
895                                if($events = $this->bo->cached_events[$date])
896                                {
897                                        print_debug('Date',$date);
898                                        print_debug('Appointments Found',count($events));
899
900                                        if (!$this->bo->prefs['calendar']['show_rejected'])
901                                        {
902                                                $appts = False;
903                                                foreach($events as $event)      // check for a not-rejected event
904                                                {
905                                                        if (!$this->bo->rejected_no_show($event))
906                                                        {
907                                                                $appts = True;
908                                                                break;
909                                                        }
910                                                }
911                                        }
912                                        else
913                                        {
914                                                $appts = True;
915                                        }
916                                }
917                                else
918                                {
919                                        $appts = False;
920                                }
921
922                                $holidays = $this->bo->cached_holidays[$date];
923                                if($weekly)
924                                {
925                                        $cellcolor = $GLOBALS['phpgw']->nextmatchs->alternate_row_color($cellcolor);
926                                }
927
928                                $day_image = '';
929                                if($holidays)
930                                {
931                                        $extra = ' bgcolor="'.$this->bo->holiday_color.'"';
932                                        $class = ($appts?'b':'').'minicalhol';
933                                        if ($date == $this->bo->today)
934                                        {
935                                                $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
936                                        }
937                                }
938                                elseif ($date != $this->bo->today)
939                                {
940                                        $extra = ' bgcolor="'.$cellcolor.'"';
941                                        $class = ($appts?'b':'').'minicalendar';
942                                }
943                                else
944                                {
945                                        $extra = ' bgcolor="'.$GLOBALS['phpgw_info']['theme']['cal_today'].'"';
946                                        $class = ($appts?'b':'').'minicalendar';
947                                        $day_image = ' background="'.$GLOBALS['phpgw']->common->image('calendar','mini_day_block').'"';
948                                }
949
950                                if($this->bo->printer_friendly && @$this->bo->prefs['calendar']['print_black_white'])
951                                {
952                                        $extra = '';
953                                }
954
955                                if(!$this->bo->printer_friendly && $this->bo->check_perms(PHPGW_ACL_ADD))
956                                {
957                                        $new_event = True;
958                                }
959                                else
960                                {
961                                        $new_event = False;
962                                }
963                                $holiday_name = Array();
964                                if($holidays)
965                                {
966                                        for($k=0;$k<count($holidays);$k++)
967                                        {
968                                                $holiday_name[] = $holidays[$k]['name'];
969                                        }
970                                }
971                                $week = '';
972                                if (!$j || (!$weekly && $j && substr($date,6,2) == '01'))
973                                {
974                                        $week = lang('week').' '.(int)((date('z',($startdate+(24*3600*4)))+7)/7);
975                                }
976                                $daily[$date] = Array(
977                                        'extra'         => $extra,
978                                        'new_event'     => $new_event,
979                                        'holidays'      => $holiday_name,
980                                        'appts'         => $appts,
981                                        'week'          => $week,
982                                        'day_image'     => $day_image,
983                                        'class'         => $class
984                                );
985                        }
986
987                        if($this->debug)
988                        {
989                                _debug_array($daily);
990                        }
991
992                        return $daily;
993                }
994               
995                function publicView()
996                {       
997                                                                       
998                        $account_name = $_POST['user'] ?
999                                                        $_POST['user'] :
1000                                                        ($_GET['account_name'] ?
1001                                                         $_GET['account_name'] : '');
1002
1003                        $theme_css = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/phpgwapi/templates/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'].'/css/'.$GLOBALS['phpgw_info']['user']['preferences']['common']['theme'].'.css';
1004               
1005                        echo '<html>'."\n"
1006                                .'<head>'."\n"
1007                                .'<LINK href="'.$theme_css.'" type=text/css rel=StyleSheet>'."\n"
1008                                .'</head><body>'
1009                                .'<div id="divAppboxHeader">'
1010                                .lang('weekly agenda of events')
1011                                .'</div><div id="divAppbox"  align="center" >';
1012                                                         
1013                        if(!$account_name){                     
1014                                echo '<font color="GREEN" size="+1">'.lang('it types login of the user to have access public agenda').'</font></center></div>';
1015                                return True;
1016                        }
1017                                                         
1018                        $accounts = CreateObject('phpgwapi.accounts');
1019                        $accountId = $accounts->name2id($account_name);
1020
1021                        if(!$accountId){                       
1022                                echo '<font color="RED" size="+1">'.lang('this user does not exist').'</font></center></div>';
1023                                return True;
1024                        }
1025
1026                        $prefs = CreateObject('phpgwapi.preferences', $accountId);
1027                        $account_prefs = $prefs->read();
1028                       
1029                        $publicView = $account_prefs['calendar']['public_view'];
1030                       
1031                        if($publicView){
1032                                $this -> user = $account_name;
1033                                $this-> selectFilter();                         
1034                                echo $this->printer_publicView($this->get_publicView($accountId));
1035                               
1036                        }
1037                        else {
1038                                echo '<font color="RED" size="+1">'.lang('it types login of the user to have access public agenda').'</font></center></div>';
1039                        }
1040
1041                        return True;   
1042                }
1043
1044                function get_publicView($accountId)
1045                {
1046                        // allow users to view public calendars;
1047                        $this -> publicView = True;
1048                        $this->bo->read_holidays();
1049
1050                        $next = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day + 7,$this->bo->year);
1051                        $prev = $GLOBALS['phpgw']->datetime->makegmttime(0,0,0,$this->bo->month,$this->bo->day - 7,$this->bo->year);
1052
1053                        $var = Array(
1054                                'week_display'          =>      $this->display_weekly(
1055                                        Array(
1056                                                'date'          => sprintf("%04d%02d%02d",$this->bo->year,$this->bo->month,$this->bo->day),
1057                                                'showyear'      => true, False
1058                                        ),$accountId
1059                                ),
1060                                'print'                 =>      $print
1061                        );
1062
1063                        $p = CreateObject('phpgwapi.Template',$this->template_dir);
1064                        $p->set_file(
1065                                Array(
1066                                        'week_t' => 'publicView.tpl'
1067                                )
1068                        );
1069                        $p->set_var($var);
1070                        return $p->fp('out','week_t');
1071
1072                }
1073               
1074                function printer_publicView($body)
1075                {                               
1076                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
1077                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
1078                        unset($GLOBALS['phpgw_info']['flags']['noappheader']);
1079                        unset($GLOBALS['phpgw_info']['flags']['noappfooter']);
1080                       
1081                        $new_body .= $this->bo->debug_string.$body;
1082                        return $new_body;
1083                }
1084               
1085               
1086        }
1087?>
Note: See TracBrowser for help on using the repository browser.