calendar.class.inc

来自「国外很不错的一个开源OA系统Group-Office」· INC 代码 · 共 2,387 行 · 第 1/5 页

INC
2,387
字号
<?php/* Copyright Intermesh 2003 Author: Merijn Schering <mschering@intermesh.nl> Version: 1.0 Release date: 08 July 2003 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.*/define('REPEAT_NONE', 0);define('REPEAT_DAILY', 1);define('REPEAT_WEEKLY', 2);define('REPEAT_MONTH_DATE', 3);define('REPEAT_MONTH_DAY', 4);define('REPEAT_YEARLY', 5);define('DB_DATETIME_FORMAT', 'Y-m-d H:i:00');define('DB_DATE_FORMAT', 'Y-m-d');define('DB_TIME_FORMAT', 'H:i:00');define('PARTICIPANTS_WRITE', '0');define('EVERYBODY_READ', '1');define('EVERYBODY_WRITE', '2');define('PRIVATE_EVENT', '3');define('CUSTOM', '4');require_once($GLOBALS['GO_CONFIG']->class_path.'xml/xml.class.inc');class calendar extends db{	var $events = array();	var $events_sort = array(); //used to sort the events at start_time	var $all_day_events = array();	var $backgrounds = array();	function calendar()	{		$this->db();	}	function get_backgrounds()	{		$sql = "SELECT * FROM cal_backgrounds";		$this->query($sql);		return $this->num_rows();	}	function add_background($background)	{		$background['id'] = $this->nextid('cal_backgrounds');		if($this->insert_row('cal_backgrounds', $background))		{			return $background['id'];		}		return false;	}	function update_background($background)	{		return $this->update_row('cal_backgrounds', 'id', $background);	}	function get_background($background_id)	{		$sql = "SELECT * FROM cal_backgrounds WHERE id='$background_id'";		$this->query($sql);		if($this->next_record())		{			return $this->Record;		}		return false;	}	function delete_background($background_id)	{		$sql = "DELETE FROM cal_calendar_backgrounds WHERE background_id='$background_id'";		$this->query($sql);		$sql = "DELETE FROM cal_backgrounds WHERE id='$background_id'";		return $this->query($sql);	}	function get_calendar_backgrounds($calendar_id)	{		$sql = "SELECT cal_calendar_backgrounds.*, cal_backgrounds.color, ".		"cal_backgrounds.name FROM cal_calendar_backgrounds INNER JOIN cal_backgrounds ON ".		"cal_backgrounds.id=cal_calendar_backgrounds.background_id ".		"WHERE cal_calendar_backgrounds.calendar_id=$calendar_id ".		"ORDER BY weekday ASC, start_time ASC";		$this->query($sql);		return $this->num_rows();	}	function add_calendar_background($calendar_background)	{		$calendar_background['id'] = $this->nextid('cal_calendar_backgrounds');		if($this->insert_row('cal_calendar_backgrounds', $calendar_background))		{			return $calendar_background['id'];		}		return false;	}	function update_calendar_background($calendar_background)	{		return $this->update_row('cal_calendar_backgrounds', 'id',$calendar_background);	}	function get_calendar_background($calendar_background_id)	{		$sql = "SELECT * FROM cal_calendar_backgrounds WHERE id='$calendar_background_id'";		$this->query($sql);		if($this->next_record())		{			return $this->Record;		}		return false;	}	function delete_calendar_background($calendar_background_id)	{		$sql = "DELETE FROM cal_calendar_backgrounds WHERE id='$calendar_background_id'";		return $this->query($sql);	}	function event_to_html($event)	{		global $GO_LANGUAGE;		require($GO_LANGUAGE->get_language_file('calendar'));		$table = new table();		$row = new table_row();		$row->add_cell(new table_cell($cal_subject.':'));		$row->add_cell(new table_cell($event['name']));		$table->add_row($row);		$cal = new calendar();		$status=$cal->get_status($event['status_id']);		$row = new table_row();		$row->add_cell(new table_cell($cal_status.':'));		$row->add_cell(new table_cell($cal_statuses[$status['name']]));		$table->add_row($row);		if (!empty($event['location'])) {			$row = new table_row();			$cell = new table_cell($sc_location.':');			$cell->set_attribute('valign','top');			$row->add_cell($cell);			$row->add_cell(new table_cell(text_to_html($event['location'])));			$table->add_row($row);		}		//don't calculate timezone offset for all day events		$timezone_offset_string = get_timezone_offset($event['start_time']);		if ($timezone_offset_string > 0) {			$gmt_string = '(\G\M\T +'.$timezone_offset_string.')';		}		elseif ($timezone_offset_string < 0) {			$gmt_string = '(\G\M\T -'.$timezone_offset_string.')';		} else {			$gmt_string = '(\G\M\T)';		}		if ($event['all_day_event']=='1') {			$event_datetime_format = $_SESSION['GO_SESSION']['date_format'];		} else {			$event_datetime_format = $_SESSION['GO_SESSION']['date_format'].' '.$_SESSION['GO_SESSION']['time_format'].' '.$gmt_string;		}		//$event_time_format = $_SESSION['GO_SESSION']['time_format'].' '.$gmt_string;		$row = new table_row();		$cell = new table_cell('&nbsp;');		$cell->set_attribute('colspan','2');		$row->add_cell($cell);		$table->add_row($row);		$row = new table_row();		$row->add_cell(new table_cell($sc_start_at.':'));		$row->add_cell(new table_cell(date($event_datetime_format, gmt_to_local_time($event['start_time']))));		$table->add_row($row);		$row = new table_row();		$row->add_cell(new table_cell($sc_end_at.':'));		$row->add_cell(new table_cell(date($event_datetime_format, gmt_to_local_time($event['end_time']))));		$table->add_row($row);		if($event['repeat_type']!=REPEAT_NONE)		{			$row = new table_row();			$cell = new table_cell();			$cell->set_attribute('colspan','2');			switch($event['repeat_type'])			{				case REPEAT_WEEKLY:					$event = $this->shift_days_to_local($event);					$days=array();					if($event['sun']=='1')					{						$days[]=$GLOBALS['full_days'][0];					}					if($event['mon']=='1')					{						$days[]=$GLOBALS['full_days'][1];					}					if($event['tue']=='1')					{						$days[]=$GLOBALS['full_days'][2];					}					if($event['wed']=='1')					{						$days[]=$GLOBALS['full_days'][3];					}					if($event['thu']=='1')					{						$days[]=$GLOBALS['full_days'][4];					}					if($event['fri']=='1')					{						$days[]=$GLOBALS['full_days'][5];					}					if($event['sat']=='1')					{						$days[]=$GLOBALS['full_days'][6];					}					if(count($days)==1)					{						$daysStr=$days[0];					}else					{						$daysStr = ' '.$cal_and.' '.array_pop($days);						$daysStr = implode(', ', $days).$daysStr;					}					if($event['repeat_every']>1)					{						$cell->innerHTML .= sprintf($cal_repeats_at_not_every,						$event['repeat_every'], $sc_weeks,						$daysStr);					}else					{						$cell->innerHTML .= sprintf($cal_repeats_at,						$sc_week,						$daysStr);					}					break;				case REPEAT_DAILY:					if($event['repeat_every']>1)					{						$cell->innerHTML .= sprintf($cal_repeats_not_every,						$event['repeat_every'], $sc_days);					}else					{						$cell->innerHTML .= sprintf($cal_repeats,						$sc_day);					}					break;				case REPEAT_MONTH_DATE:					if($event['repeat_every']>1)					{						$cell->innerHTML .= sprintf($cal_repeats_not_every,						$event['repeat_every'], $sc_months);					}else					{						$cell->innerHTML .= sprintf($cal_repeats,						$sc_month);					}					break;				case REPEAT_MONTH_DAY:					$event = $this->shift_days_to_local($event);					$days=array();					if($event['sun']=='1')					{						$days[]=$GLOBALS['full_days'][0];					}					if($event['mon']=='1')					{						$days[]=$GLOBALS['full_days'][1];					}					if($event['tue']=='1')					{						$days[]=$GLOBALS['full_days'][2];					}					if($event['wed']=='1')					{						$days[]=$GLOBALS['full_days'][3];					}					if($event['thu']=='1')					{						$days[]=$GLOBALS['full_days'][4];					}					if($event['fri']=='1')					{						$days[]=$GLOBALS['full_days'][5];					}					if($event['sat']=='1')					{						$days[]=$GLOBALS['full_days'][6];					}					if(count($days)==1)					{						$daysStr=$days[0];					}else					{						$daysStr = ' '.$cal_and.' '.array_pop($days);						$daysStr = implode(', ', $days).$daysStr;					}					if($event['repeat_every']>1)					{						$cell->innerHTML .= sprintf($cal_repeats_at_not_every,						$event['repeat_every'], $sc_months, $daysStr);					}else					{						$cell->innerHTML .= sprintf($cal_repeats_at,						$sc_month, $daysStr);					}					break;				case REPEAT_YEARLY:					if($event['repeat_every']>1)					{						$cell->innerHTML .= sprintf($cal_repeats_not_every,						$event['repeat_every'], $sc_years);					}else					{						$cell->innerHTML .= sprintf($cal_repeats,						$sc_year);					}					break;			}			if ($event['repeat_forever'] != '1') {				$cell->innerHTML .= ' '.$cal_until.' '.date($_SESSION['GO_SESSION']['date_format'], $event['repeat_end_time']);			}			$row->add_cell($cell);			$table->add_row($row);		}		$row = new table_row();		$cell = new table_cell('&nbsp;');		$cell->set_attribute('colspan','2');		$row->add_cell($cell);		$table->add_row($row);		if(!empty($event['custom_fields']))		{			$fieldsNode =text_to_xml($event['custom_fields']);			$fields = $fieldsNode->children();			if(count($fields) > 0 && isset($fields[0]->_name))			{				$row = new table_row();				$cell = new table_cell('&nbsp;');				$cell->set_attribute('colspan','2');				$row->add_cell($cell);				$table->add_row($row);				foreach(	$fields as $inputNode)				{					$row = new table_row();					$type = $inputNode->get_attribute('type') ? $inputNode->get_attribute('type') : 'text';					switch($type)					{						default:							$row->add_cell(new table_cell($inputNode->get_attribute('name').':'));							$row->add_cell(new table_cell($inputNode->get_attribute('value')));							break;						case 'checkbox':							$row->add_cell(new table_cell($inputNode->get_attribute('name').':'));							$value = $inputNode->get_attribute('value')=='1' ? $GLOBALS['cmdYes'] : $GLOBALS['cmdNo'];							$row->add_cell(new table_cell($value));							break;					}					$table->add_row($row);				}				$row = new table_row();				$cell = new table_cell('&nbsp;');				$cell->set_attribute('colspan','2');				$row->add_cell($cell);				$table->add_row($row);			}		}		$calendars=array();		$this->get_calendars_from_event($event['id']);		while($this->next_record())		{			$calendars[]=$this->f('name');		}		$row = new table_row();		$cell = new table_cell($cal_event_calendars.':');		$cell->set_attribute('valign','top');		$row->add_cell($cell);		$row->add_cell(new table_cell(implode(', ', $calendars)));		$table->add_row($row);		if (!empty($event['description'])) {			$row = new table_row();			$cell = new table_cell($GLOBALS['strDescription'].':');			$cell->set_attribute('valign','top');			$row->add_cell($cell);			$row->add_cell(new table_cell(text_to_html($event['description'])));			$table->add_row($row);		}		return $table->get_html();	}	function get_statuses($type='VEVENT')	{		$sql = "SELECT * FROM cal_statuses WHERE type='$type'";		$this->query($sql);		return $this->num_rows();	}	function get_status($status_id)	{		$sql = "SELECT * FROM cal_statuses WHERE id='$status_id'";		$this->query($sql);		if($this->next_record())		{			return $this->Record;		}		return false;	}	function get_status_id($name)	{		$sql = "SELECT * FROM cal_statuses WHERE name='$name'";		$this->query($sql);		if($this->next_record())		{			return $this->f('id');		}		return false;	}	function add_custom_field($group_id, $field)	{		$existing_group = $this->get_group($group_id);		if(trim($existing_group['custom_fields']) == '' || trim($existing_group['custom_fields']) == '<fields></fields>')		{

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?