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

Revision 3731, 13.4 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1523 - Criado o layout do Expresso Mini para navegadores desktop

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