source: branches/2.2/mobile/inc/class.ui_mobilecalendar.inc.php @ 3641

Revision 3641, 13.3 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1475 - Barra em arquivo de template único

Line 
1<?php
2    class ui_mobilecalendar {
3               
4                var $bocalendar;
5                var $cat;
6                var $link_tpl;         
7                var $common;
8                var $template;         
9                var $daysOfWeek;
10                var $shortDaysOfWeek;
11               
12                var $public_functions = array(
13                        'index' => true
14                );
15               
16                function ui_mobilecalendar() {
17                        $this->template = CreateObject('phpgwapi.Template', PHPGW_SERVER_ROOT . '/mobile/templates/'.$GLOBALS['phpgw_info']['server']['template_set']);
18                        $this->common   = CreateObject('mobile.common_functions');
19                        $this->bocalendar = CreateObject('calendar.bocalendar',1);                     
20                        $this->cat = &$this->bo->cat;
21                        $this->daysOfWeek = array(lang('Sunday'), lang('Monday'),lang('Tuesday'),lang('Wednesday'),lang('Thursday'),lang('Friday'),lang('Saturday'));
22                        $this->shortDaysOfWeek = array(lang('short Sunday'), lang('short Monday'),lang('short Tuesday'),lang('short Wednesday'),lang('short Thursday'),lang('short Friday'),lang('short Saturday'));
23                       
24                        $GLOBALS['phpgw']->nextmatchs = CreateObject('phpgwapi.nextmatchs');
25                }
26               
27                function index($params) {
28                        $this->template->set_file(
29                                                                        array(
30                                                                                'calendar' => 'calendar.tpl',
31                                                                                'home_search_bar' => 'search_bar.tpl'
32                                                                        )
33                                                                );
34                        $this->template->set_block("calendar","page");
35                        $this->template->set_block('calendar','event_block');
36                        $this->template->set_block('calendar','day_event_block');
37                        $this->template->set_block('calendar','no_event_block');
38                        $this->template->set_block('calendar','type_option_block');
39                        $this->template->set_block('calendar','bar_block');
40                        $this->template->set_block('home_search_bar','search_bar');
41                        $this->template->set_var('lang_back',lang("back"));
42                        $this->template->set_var('lang_calendar',lang("Calendar"));
43                        $this->template->set_var('lang_search',lang("search"));
44                       
45                        $this->template->set_var('search',$this->template->fp('out','search_bar'));
46                       
47                        if(!function_exists("get_events")){
48                                function get_events($self, $accountId, $begin, $end) {
49                                        $self->bocalendar->so->owner = $accountId;
50                                        $self->bocalendar->so->open_box($accountId);
51                                        $self->bocalendar->store_to_cache(
52                                                array(
53                                                        'owner' => $accountId,
54                                                        'syear'  => date('Y',$begin),
55                                                        'smonth' => date('m',$begin),
56                                                        'sday'   => date('d',$begin),
57                                                        'eyear'  => date('Y',$end),
58                                                        'emonth' => date('m',$end),
59                                                        'eday'   => date('d',$end)
60                                                )
61                                        );
62                                       
63                                        $events = $self->bocalendar->cached_events;
64                                        ksort($events);
65                               
66                                        return $events;
67                                }
68                        }
69                       
70                        if(!function_exists("print_events")){   
71                                function print_events($self, $events) {
72                                        foreach($events as $index=>$event)
73                                        {
74                                                $self->template->set_var('dd_class', (($index%2==0) ? "par" : "reset-dt") );   
75                                                $vars = $self->bocalendar->event2array($event);
76                                                $data = array (
77                                                        "title_field"           => $vars['title']['field'],
78                                                        "title_data"            => $vars['title']['data'],
79                                                        "startdate_data"        => substr($vars['startdate']['data'],13, 17),
80                                                        "enddate_data"          => substr($vars['enddate']['data'],13, 17),
81                                                        "location_field"                => $vars['location']['field'],
82                                                        "location_data" => $vars['location']['data'] ? $vars['location']['data'] : "-",
83                                                        "description_field"             => $vars['description']['field'],
84                                                        "description_data"      => $vars['description']['data'] ? $vars['description']['data'] : "-"
85                                                );
86                       
87                                $self->template->set_var($data);
88                                                $self->template->parse('events_box','event_block',true);
89                                        }                               
90                                }
91                        }       
92                       
93                        if(!function_exists("print_events_header")){   
94                                function print_events_header($self, $day, $month, $year) {
95                                        $day_of_week = $self->daysOfWeek[$GLOBALS['phpgw']->datetime->day_of_week($year,$month,$day)];
96                                        $self->template->set_var("day",$day_of_week." - ".$day."/".$month."/".$year);
97                                        $self->template->parse('events_box','day_event_block',true);
98                                }
99                        }
100                               
101                        $type = $_GET["type"];
102                        if(!$type) $type = "dia";
103                        $types = array("dia" => lang("view day"),"semana" => lang("view week"),"calendario" => lang("view calendar"));
104                       
105                        foreach($types as $value=>$label)       {
106                                $this->template->set_var("value",$value);
107                                $this->template->set_var("label",$label);
108                               
109                                if($type == $value)
110                                        $this->template->set_var("selected", "selected");
111                                else
112                                        $this->template->set_var("selected", null);
113                                       
114                                $this->template->parse('type_option_box','type_option_block',true);
115                        }
116                       
117                        $accountId = $GLOBALS['phpgw_info']['user']['account_id'];
118
119                        $day = $_GET["dia"];
120                        if(!$day) $day = $this->bocalendar->day;
121
122                        $month = $_GET["mes"];
123                        if(!$month) $month = $this->bocalendar->month;
124                       
125                        $year = $_GET["ano"];
126                        if(!$year) $year = $this->bocalendar->year;
127                       
128                        $this->template->set_var("lang_today", lang("today"));
129                        $this->template->set_var("today_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=dia&dia");
130                       
131                        if($type==="semana") {
132                                $tstart = $GLOBALS['phpgw']->datetime->get_weekday_start($year, $month, $day) + $GLOBALS['phpgw']->datetime->tz_offset;
133                                $tstart -= $GLOBALS['phpgw']->datetime->tz_offset;
134                                $tstop = $tstart + 604800;
135                                $events = get_events($this, $accountId, $tstart, $tstop);
136                                $current_day_of_week = $GLOBALS['phpgw']->datetime->day_of_week($year, $month, $day);
137                               
138                                //descobrindo a semana anterior e a pŽroxima
139                                $last_week = date("d-m-Y", strtotime("-7 day", mktime(0,0,0,$month,$day,$year) ) );
140                                $last_week = split("-",$last_week);
141                                $next_week = date("d-m-Y", strtotime("+7 day", mktime(0,0,0,$month,$day,$year) ) );
142                                $next_week = split("-",$next_week);
143                               
144                                //descobrind o primeiro dia da semana e o último
145                                $first_week_day = date("d-m-Y", strtotime("-".$current_day_of_week." day", mktime(0,0,0,$month,$day,$year) ) );
146                                $first_week_day = split("-",$first_week_day);
147                                $last_week_day = date("d-m-Y", strtotime("+".(6-$current_day_of_week)." day", mktime(0,0,0,$month,$day,$year) ) );
148                                $last_week_day = split("-",$last_week_day);
149                               
150                                //definindo a barra de navegação do calandário
151                                $this->template->set_var("before_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=semana&dia=".$last_week[0]."&mes=".$last_week[1]."&ano=".$last_week[2]);
152                                $this->template->set_var("current_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=semana&dia=".$day."&mes=".$month."&ano=".$year);
153                                $this->template->set_var("next_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=semana&dia=".$next_week[0]."&mes=".$next_week[1]."&ano=".$next_week[2]);
154                                $this->template->set_var("current_label", $first_week_day[0]."/".$first_week_day[1]."/".$first_week_day[2]." à ".$last_week_day[0]."/".$last_week_day[1]."/".$last_week_day[2]);
155                                $this->template->parse('events_box','bar_block',true);
156                               
157                                if(!empty($events)) {
158                                        foreach($events as $index=>$event)      {
159                                                $event_year  = (int) substr($index,0,4);
160                                                $event_month = (int) substr($index,4,2);
161                                                $event_day   = (int) substr($index,6,2);
162                                                print_events_header($this, $event_day, $event_month, $event_year);
163                                                print_events($this, $events[$event_year.$this->common->complete_string($event_month,2,"R","0").$this->common->complete_string($event_day,2,"R","0")]); 
164                                        }               
165                                } else {
166                                        $this->template->set_var("msg_no_event", lang("Dont have event that week"));
167                                        $this->template->parse('events_box','no_event_block',true);
168                                }                               
169                                               
170                        } elseif($type==="calendario") {
171                                $day_of_week_first_day = $GLOBALS['phpgw']->datetime->day_of_week($year, $month, "01");
172                                $last_day_of_month = date('t', mktime(0,0,0,$month,"01",$year));
173                                $last_day_of_before_month = date('t', mktime(0,0,0,$month-1,"01",$year));
174                                $last_month_year = date("m-Y", strtotime("-1 month", mktime(0,0,0,$month,"01",$year) ) );
175                                $last_month_year = split("-",$last_month_year);
176                                $next_month_year = date("m-Y", strtotime("+1 month", mktime(0,0,0,$month,"01",$year) ) );
177                                $next_month_year = split("-",$next_month_year);
178                                $today = date("d-m-Y");
179                               
180                                $days_of_calendar = array();
181                               
182                                //identificando os dias do mês anterior
183                                for($i = 0; $i < $day_of_week_first_day; $i++) {
184                                        $days_of_calendar[$i] = array("day" => ($last_day_of_before_month-$day_of_week_first_day+$i+1), "month" => $last_month_year[0], "year" => $last_month_year[1], "other_month" => true);                                 
185                                }
186                               
187                                //adicionando os dias do mês especificado
188                                for($i = 0; $i < ($last_day_of_month ); $i++) {
189                                        $days_of_calendar[$i+$day_of_week_first_day] = array("day" => $i+1, "month" => $month, "year" => $year, "other_month" => false);
190                                }
191                               
192                                //pegando todos os eventos a partir o menor dia visível do mês anterior
193                                $tstart = mktime(0,0,0,$last_month_year[0],($last_day_of_before_month-$day_of_week_first_day),$last_month_year[1]);
194                                $tstart -= $GLOBALS['phpgw']->datetime->tz_offset;
195                                $tstop = $tstart + (86400*sizeof($days_of_calendar)); //(24horas*60min*60seg*total de dias exibidos)
196                                $events = get_events($this, $accountId, $tstart, $tstop);
197                               
198                                //definindo os blocos a serem utilizados
199                                $this->template->set_block('calendar','calendar_header_begin_block');
200                                $this->template->set_block('calendar','calendar_header_end_block');
201                                $this->template->set_block('calendar','calendar_header_block');
202                                $this->template->set_block('calendar','calendar_day_block');
203                                $this->template->set_block('calendar','calendar_day_begin_block');
204                                $this->template->set_block('calendar','calendar_day_end_block');
205                               
206                                //definindo a barra de navegação do calandário
207                                $this->template->set_var("before_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=calendario&mes=".$last_month_year[0]."&ano=".$last_month_year[1]);
208                                $this->template->set_var("current_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=calendario&mes=".$month."&ano=".$year);
209                                $this->template->set_var("next_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=calendario&mes=".$next_month_year[0]."&ano=".$next_month_year[1]);
210                                $this->template->set_var("current_label", $month." / ".$year);
211                                $this->template->parse('events_box','bar_block',true);
212                               
213                                for($i = 0; $i < 7; $i++) {
214                                        $this->template->set_var("week_day", $this->shortDaysOfWeek[$i]);
215                                        $this->template->parse('week_day_box','calendar_header_block',true);
216                                }
217                                                               
218                                $this->template->parse('calendar_box','calendar_header_begin_block',true);
219                                $this->template->parse('calendar_box','calendar_day_begin_block',true);
220                               
221                                foreach($days_of_calendar as $index=>$value) {
222                                        $extra_class = "";
223                                        $calendar_day = $value["day"];
224
225                                        if($today === $value["day"]."-".$value["month"]."-".$value["year"])
226                                                $extra_class .= " hoje";
227
228                                        if($value["other_month"])
229                                                $extra_class .= " outro_mes";
230                                       
231                                        $key = $value["year"].$this->common->complete_string($value["month"],2,"R","0").$this->common->complete_string($value["day"],2,"R","0");
232                                       
233                                        if( array_key_exists($key, $events ) ) {
234                                                $this->template->set_var("qtd_commitment", sizeof($events[$key]));
235                                        } else {
236                                                $this->template->set_var("qtd_commitment", null);
237                                        }
238
239                                        $this->template->set_var("calendar_day", $calendar_day);
240                                       
241                                        $this->template->set_var("calendar_day_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=dia&dia=".$value["day"]."&mes=".$value["month"]."&ano=".$value["year"]);
242                                        $this->template->set_var("extra_class", $extra_class);                                 
243                                        $this->template->parse('calendar_box','calendar_day_block',true);
244                                       
245                                        if(($index+1)%7==0) {
246                                                $this->template->parse('calendar_box','calendar_day_end_block',true);
247                                                $this->template->parse('calendar_box','calendar_day_begin_block',true);
248                                        }
249                                }
250                                $this->template->parse('calendar_box','calendar_day_end_block',true);
251                                $this->template->parse('calendar_box','calendar_header_end_block',true);
252                       
253                        } else  {
254                                $tstart = mktime(0,0,0,$month,$day,$year);
255                                $tstart -= $GLOBALS['phpgw']->datetime->tz_offset;
256                                $tstop = $tstart + 86400; //(24horas*60min*60seg*1dia)
257                                $events = get_events($this, $accountId, $tstart, $tstop);
258                               
259                                $day = $this->common->complete_string($day,2,"R","0");
260                                $month = $this->common->complete_string($month,2,"R","0");
261                               
262                                //descobrind o primeiro dia da semana e o último
263                                $before_day = date("d-m-Y", strtotime("-1 day", mktime(0,0,0,$month,$day,$year) ) );
264                                $before_day = split("-",$before_day);
265                                $next_day = date("d-m-Y", strtotime("+1 day", mktime(0,0,0,$month,$day,$year) ) );
266                                $next_day = split("-",$next_day);                               
267                               
268                                //definindo a barra de navegação do calandário
269                                $this->template->set_var("before_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=dia&dia=".$before_day[0]."&mes=".$before_day[1]."&ano=".$before_day[2]);
270                                $this->template->set_var("current_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=dia&dia=".$day."&mes=".$month."&ano=".$year);
271                                $this->template->set_var("next_link", "index.php?menuaction=mobile.ui_mobilecalendar.index&type=dia&dia=".$next_day[0]."&mes=".$next_day[1]."&ano=".$next_day[2]);
272                                $this->template->set_var("current_label", $this->daysOfWeek[$GLOBALS['phpgw']->datetime->day_of_week($year,$month,$day)]." - ".$day."/".$month."/".$year);
273                                $this->template->parse('events_box','bar_block',true);                         
274                               
275                                if(!empty($events[$year.$month.$day]))
276                                        print_events($this, $events[$year.$month.$day]);
277                                else {
278                                        $this->template->set_var("msg_no_event", lang("Dont have event that day"));
279                                        $this->template->parse('events_box','no_event_block',true);
280                                }
281                        }
282                       
283                        $GLOBALS['phpgw_info']['mobiletemplate']->set_content($this->template->fp('out','page'));
284                }
285        }
286       
287?>
Note: See TracBrowser for help on using the repository browser.