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

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

Ticket #1410 - Corrigido o layout da tela de compromissos do expresso mini

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