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