📄 calendar_view.class.inc
字号:
<?php/** * @copyright Intermesh 2005 * @author Merijn Schering <mschering@intermesh.nl> * @version $Revision: 1.55 $ $Date: 2006/04/10 13:21:11 $ * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. */require_once($GO_MODULES->modules['calendar']['class_path'].'event.class.inc');class calendar_view extends table{ var $current_day; var $current_month; var $current_year; var $clicked_day; var $clicked_month; var $clicked_year; var $day; var $month; var $year; var $hour; var $min; var $_offset; var $offset; var $start_time; var $end_time; var $calendar_start_time; var $calendar_end_time; var $events; var $all_day_events; var $colspans; var $time_interval; var $return_to; var $id; var $form_name; var $timezone_offset; var $weeks = 1; function calendar_view($id, $day_start_hour, $day_end_hour, $time_interval, $form_name='0') { global $GO_CONFIG, $GO_SECURITY; $this->id = $id; $this->form_name = $form_name; $this->current_day = date('j', get_time()); $this->current_month = date('n', get_time()); $this->current_year = date('Y', get_time()); $this->calendar_start_time = $day_start_hour*3600; $this->calendar_end_time = $day_end_hour*3600+3600; if(isset($_POST[$this->id]['day'])) { if($this->offset != $_POST[$this->id]['offset']) { $GO_CONFIG->save_setting( 'calendar_offset', smart_addslashes($_POST[$this->id]['offset']), $GO_SECURITY->user_id); } $browse_time = mktime( $_POST[$this->id]['hour'], $_POST[$this->id]['min'], 0, $_POST[$this->id]['month'], $_POST[$this->id]['day'], $_POST[$this->id]['year']); $this->offset = $_POST[$this->id]['offset']; $_SESSION[$this->id]['browse_time'] = $browse_time; }else { $this->offset = $GO_CONFIG->get_setting('calendar_offset', $GO_SECURITY->user_id); if(!$this->offset) { $this->offset = 7; } if(!isset($_SESSION[$this->id]['browse_time'])) { $browse_time = get_time(); }else { $browse_time = $_SESSION[$this->id]['browse_time']; } } $this->_offset = $this->offset; //echo date('Ymd G:i', $browse_time); $this->year = $this->clicked_year = date("Y", $browse_time); $this->month = $this->clicked_month = date("n", $browse_time); $this->day = $this->clicked_day = date("j", $browse_time); $this->hour = date("H", $browse_time); $this->min = date("i", $browse_time); if ($this->_offset > 4) { //calculate the first day to display in the week view. $weekday = date("w", $browse_time); $tmpday = $this->day - $weekday + $_SESSION['GO_SESSION']['first_weekday']; if ($tmpday > $this->day) { $tmpday = $tmpday -7; } $new_time = mktime(0,0,0,$this->month, $tmpday, $this->year); $this->day = date("j", $new_time); $this->month = date('n', $new_time); $this->year = date('Y', $new_time); } if($this->_offset > 7) { $this->weeks = ceil($this->_offset/7); $this->_offset = 7; } $this->time_interval = $time_interval; $this->start_time = mktime(0,0,0,$this->month, $this->day, $this->year); $this->end_time = $this->start_time+($this->_offset*$this->weeks*86400); $this->return_to = $_SERVER['HTTP_REFERER']; } function set_return_to($return_to) { $this->return_to = $return_to; } function add_holiday($name, $time) { $this->holidays[$time]=$name; } function get_header() { global $GO_MODULES; return '<script type="text/javascript" src="'.$GO_MODULES->modules['calendar']['url'].'calendar.js"></script>'; } function add_event($event) { $timezone_offset = get_timezone_offset($event['start_time'])*3600; $event['start_time'] += $timezone_offset; $timezone_offset = get_timezone_offset($event['end_time'])*3600; $event['end_time'] += $timezone_offset; $timezone_offset = get_timezone_offset($event['repeat_end_time'])*3600; $event['repeat_end_time'] += $timezone_offset; if($event['start_time'] == $event['end_time']) { $event['end_time'] += 3600; } if($event['start_time'] < $this->end_time && $event['end_time'] > $this->start_time) { $event['display_start_time'] = floor($event['start_time']/$this->time_interval)*$this->time_interval; $event['display_end_time'] = ceil($event['end_time']/$this->time_interval)*$this->time_interval; //echo date('Ymd G:i', $event['display_start_time']); //Maybe event is out of display range if($event['display_start_time'] < $this->calendar_start_time) { $event['display_start_time'] = $this->calendar_start_time; } if($event['display_end_time'] > $this->end_time) { $event['display_end_time'] = $this->end_time; } if($event['all_day_event'] == '1') { for($time=$event['display_start_time'];$time<$event['display_end_time'];$time+=86400) { $this->all_day_events[$time][] = &$event; } }else { for($time=$event['display_start_time'];$time<$event['display_end_time'];$time+=$this->time_interval) { $this->events[$time][] = &$event; } } } } function calculate_colspans() { for($time=$this->calendar_start_time;$time<=$this->calendar_end_time;$time+=$this->time_interval) { for($display_day=0;$display_day<$this->_offset*$this->weeks;$display_day++) { $current_time = mktime(0,0,$time,$this->month, $this->day+$display_day, $this->year); if(!isset($this->colspans[$display_day])) { $this->colspans[$display_day] = 1; } if(isset($this->events[$current_time])) { for($n=0;$n<count($this->events[$current_time]);$n++) { if(!isset($this->events[$current_time][$n]['days'][$display_day]['position'])) { if(isset($this->events[$current_time][$n-1]['days'][$display_day]['position'])) { $this->events[$current_time][$n-1]['days'][$display_day]['neighbour'] = true; $this->events[$current_time][$n]['days'][$display_day]['position'] = $this->events[$current_time][$n-1]['days'][$display_day]['position']+1; }else { $this->events[$current_time][$n]['days'][$display_day]['position'] = 0; } } if($this->events[$current_time][$n]['days'][$display_day]['position'] >= $this->colspans[$display_day]) { $this->colspans[$display_day] = $this->events[$current_time][$n]['days'][$display_day]['position']+1; } } } } } } function get_new_event_handler($day,$month, $year,$hour,$min) { return "new_event($year,$month,$day,$hour,$min)"; } function get_change_view_handler($day, $month, $year, $offset=null) { $_offset = isset($_offset) ? $_offset : $this->_offset; return "change_view('".$this->id."','".$this->form_name."', $offset, $day, $month, $year);"; } function get_date_handler($day, $month, $year) { return "goto_date('".$this->id."','".$this->form_name."', $day, $month, $year);"; } function load_holidays($user_id, $calendar_id) { global $GO_MODULES; require_once($GO_MODULES->modules['calendar']['class_path'].'cal_holidays.class.inc'); $holidays = new holidays(); $end = $this->_offset+($this->weeks*7); for($i=0;$i<$end;$i++) { $current_time = mktime(0,0,0,$this->month, $this->day+$i, $this->year); if($holidays->get_holiday($user_id, $calendar_id, $current_time)) { $this->holidays[$current_time]=$holidays->f('name'); } } } function set_headings($week=0) { $heading_width = ceil(100/$this->_offset).'%'; $row = new table_row(); $th = new table_heading(' '); //$th->set_attribute('style','width:5%'); $row->add_cell($th); $end = $this->_offset+($week*7); for($i=($week*7);$i<$end;$i++) { $current_time = mktime(0,0,0,$this->month, $this->day+$i, $this->year); $weekday = date('w', $current_time); $link = new hyperlink( 'javascript:'.$this->get_change_view_handler($this->day+$i, $this->month, $this->year, 1), $GLOBALS['full_days'][$weekday].'<br />'. date($_SESSION['GO_SESSION']['date_format'], $current_time)); if(isset($this->holidays[$current_time])) { $link->innerHTML .= '<br />'.htmlspecialchars($this->holidays[$current_time]); } $new_time = mktime(0,0,0,$this->month, $this->day+$i, $this->year); $new_day = date('j', $new_time); $new_month = date('n', $new_time); $new_year = date('Y', $new_time); if($new_day==$this->current_day && $new_month==$this->current_month && $new_year==$this->current_year) { $link->set_attribute('class', 'HoverLinkSelected'); }else { $link->set_attribute('class', 'HoverLink'); } $th = new table_heading($link->get_html()); $th->set_attribute('style','width:'.$heading_width);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -