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