Location: PHPKode > projects > Basic Announce > Basic Announce Version 4.0/modules/calendar/calendar.class.php
<?php
################################################################################
##              -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =-                 #
## --------------------------------------------------------------------------- #
##  ApPHP Calendar version 2.0.1 (Modified for ApPHP AdminPanel)     		   #
##  Developed by:  ApPhp <hide@address.com>                                      #
##  License:       GNU LGPL v.3                                                #
##  Site:          http://www.apphp.com/php-calendar/                          #
##  Copyright:     ApPHP Calendar (c) 2009. All rights reserved.               #
##                                                                             #
################################################################################
## Last changes:
## --------------------------------------------------------------------------- #
## 31.07.2011 - added SetOperations()
##

class Calendar{	
	
	// PUBLIC
	// --------
	// __construct()
	// __destruct()
	// Show()
	// SetCalendarDimensions
	// SetCaption
	// SetWeekStartedDay
	// SetWeekDayNameLength
	// ShowWeekNumberOfYear
	// SetTimeZone
	// GetCurrentTimeZone
	// SetDefaultView
	// SetSubmissionType
	// Debug
	//
	// STATIC
	// ----------
	// Version
	// GetDefaultTimeZone
	// 
	// PRIVATE
	// --------
	// SetDefaultParameters
	// GetCurrentParameters
	// DrawCssStyle
	// DrawJsFunctions
	// DrawMessages
	// DrawYear
	// DrawMonth	
	// DrawMonthSmall
	// DrawWeek
	// DrawDay
	// DrawTypesChanger
	// DrawDateJumper
	// DrawTodayJumper
	// --------
	// GetEventsList
	// isYear
	// isMonth
	// isDay
	// ConvertToDecimal
	// GetFormattedMicrotime
	

	//--- PUBLIC DATA MEMBERS --------------------------------------------------
	public $error;
	
	//--- PROTECTED DATA MEMBERS -----------------------------------------------
	protected $weekDayNameLength;
	
	//--- PRIVATE DATA MEMBERS -------------------------------------------------
	private  $arrWeekDays;
	private  $arrMonths;
	private  $arrViewTypes;
	private  $defaultView;
	private  $defaultAction;
	
	private  $arrParameters;
	private  $arrToday;
	private  $prevYear;
	private  $nextYear;
	private  $prevMonth;
	private  $nextMonth;
	private  $prevWeek;
	private  $nextWeek;
	private  $prevDay;
	private  $nextDay;
	
	private  $isDrawNavigation;
	private  $isWeekNumberOfYear;
	
	private  $crLt;	
	private  $caption;		
	private  $calWidth;		
	private  $calHeight;
	private  $cellHeight;
	
	private  $timezone;
	
	private  $submissionType;

	private  $isDemo;	
	private  $isDebug;
	private  $arrMessages;
	private  $arrErrors;
    private  $startTime;
	private  $endTime;

	static private $version = "2.0.2";
	
		
	//--------------------------------------------------------------------------
    // CLASS CONSTRUCTOR
	//--------------------------------------------------------------------------
	function __construct()
	{
		$this->defaultView   = "monthly";
		$this->defaultAction = "view";
		
		// possible values 1,2,....7
		$this->weekStartedDay = 1;
		
		$this->weekDayNameLength = "short"; // short|long
		
		$this->arrWeekDays = array();
		$this->arrWeekDays[0] = array("short"=>"Sun", "long"=>"Sunday");
		$this->arrWeekDays[1] = array("short"=>"Mon", "long"=>"Monday");
		$this->arrWeekDays[2] = array("short"=>"Tue", "long"=>"Tuesday");
		$this->arrWeekDays[3] = array("short"=>"Wed", "long"=>"Wednesday");
		$this->arrWeekDays[4] = array("short"=>"Thu", "long"=>"Thursday");
		$this->arrWeekDays[5] = array("short"=>"Fri", "long"=>"Friday");
		$this->arrWeekDays[6] = array("short"=>"Sat", "long"=>"Satarday");
		
		$this->arrMonths = array();
		$this->arrMonths["1"] = "January";
		$this->arrMonths["2"] = "February";
		$this->arrMonths["3"] = "March";
		$this->arrMonths["4"] = "April";
		$this->arrMonths["5"] = "May";
		$this->arrMonths["6"] = "June";
		$this->arrMonths["7"] = "July";
		$this->arrMonths["8"] = "August";
		$this->arrMonths["9"] = "September";
		$this->arrMonths["10"] = "October";
		$this->arrMonths["11"] = "November";
		$this->arrMonths["12"] = "December";
		
		$this->arrViewTypes = array();
		$this->arrViewTypes["daily"]   = "daily";
		$this->arrViewTypes["weekly"]  = "weekly";
		$this->arrViewTypes["monthly"] = "monthly";
		$this->arrViewTypes["yearly"]  = "yearly";
		
		$this->arrParameters = array();
		$this->SetDefaultParameters();

		$this->arrToday  = array();
		$this->prevYear  = array();
		$this->nextYear  = array();
		$this->prevMonth = array();
		$this->nextMonth = array();
		$this->prevWeek  = array();
		$this->nextWeek  = array();
		$this->prevDay   = array();
		$this->nextDay   = array();
		
		$this->isDrawNavigation = true;
		$this->isWeekNumberOfYear = true;
		
		$this->crLt = "\n";
		$this->caption = "";
		$this->calWidth = "800px";
		$this->calHeight = "470px";
		$this->celHeight = number_format(((int)$this->calHeight)/6, "0")."px";
		
		$this->timezone = self::GetDefaultTimeZone();
		
		$this->submissionType = "post";
		
		$this->cssStyle = "blue";

		$this->isDemo = false;	
		$this->isDebug = false;
		$this->arrMessages = array();
		$this->arrErrors = array();

		$this->arrOpearations = array();
		$this->arrOpearations['add']     = true;
		$this->arrOpearations['delete']  = true;
	}
	
	//--------------------------------------------------------------------------
    // CLASS DESTRUCTOR
	//--------------------------------------------------------------------------
    function __destruct()
	{
		// echo 'this object has been destroyed';
    }

	
	//==========================================================================
    // PUBLIC DATA FUNCTIONS
	//==========================================================================			
	/**
	 *	Show Calendar 
	 *
	*/	
	function Show()
	{
		//ob_start();
		
        // start calculating running time of a script
        $this->startTime = 0;
        $this->endTime = 0;
        if($this->isDebug){
            $this->startTime = $this->GetFormattedMicrotime();
        }        

		$this->HandleEvents();
		$this->GetCurrentParameters();
		$this->DrawCssStyle();
		$this->DrawJsFunctions();

		echo "<form name='frmCalendar' id='frmCalendar' action='".$this->arrParameters["current_file"]."' method='".$this->submissionType."'>".$this->crLt;
		echo "<input type='hidden' id='hid_event_action' name='hid_event_action' value='' />".$this->crLt;
		echo "<input type='hidden' id='hid_event_id' name='hid_event_id' value='' />".$this->crLt;
	    echo "<input type='hidden' id='hid_action' name='hid_action' value='' />".$this->crLt;
		echo "<input type='hidden' id='hid_view_type' name='hid_view_type' value='' />".$this->crLt;
		echo "<input type='hidden' id='hid_year' name='hid_year' value='' />".$this->crLt;
		echo "<input type='hidden' id='hid_month' name='hid_month' value='' />".$this->crLt;
		echo "<input type='hidden' id='hid_day' name='hid_day' value='' />".$this->crLt;
		
		echo "<div id='calendar' style='width:".$this->calWidth.";'>".$this->crLt;		
		
		// draw calendar header
		echo "<table id='calendar_header'>".$this->crLt;
		echo $this->DrawMessages(false);		
		echo "<tr>";
		echo "<th class='caption_left'>".$this->DrawTodayJumper(false)."</th>";
		echo "<th class='caption' nowrap>".$this->caption."</th>";
		echo "<th class='types_changer'>".$this->DrawTypesChanger(false)."</th>";
		echo "</tr>".$this->crLt;
		echo "</table>";
		
		switch($this->arrParameters["view_type"])
		{			
			case "daily":
				$this->DrawDay();
				break;
			case "weekly":
				$this->DrawWeek();
				break;
			case "yearly":
				$this->DrawYear();
				break;			
			default:
			case "monthly":				
				$this->DrawMonth();
				break;
		}
		
		echo "</div>".$this->crLt;
		echo "</form>".$this->crLt;
		
		if($this->isDebug){
			$this->endTime = $this->GetFormattedMicrotime();

			echo "<div style='width:".$this->calWidth."; margin: 10px auto; text-align:left; color:#000096;'>";
			echo "Debug Info: (Total running time: ".round((float)$this->endTime - (float)$this->startTime, 6)." sec.) <br />========<br />";
			echo "GET: <br />--------<br />";
			echo "<pre>";
			print_r($_GET);
			echo "</pre><br />";
			echo "POST: <br />--------<br />";
			echo "<pre>";
			print_r($_POST);
			echo "</pre><br />";
			echo "SQL: <br />--------<br />";
			$this->DrawErrors();
			echo "</div>";
		}		
		
        echo $this->crLt."<!-- This script was generated by ApPHP Calendar v.".self::$version." (http://www.apphp.com) -->".$this->crLt;
		
		//ob_end_flush();		
	}	
	
	/**
	 *	Set calendar dimensions
	 *  	@param $width
	 *  	@param $height
	*/	
	function SetCalendarDimensions($width = "", $height = "")
	{
		$this->calWidth = ($width != "") ? $width : "800px";
		$this->calHeight = ($height != "") ? $height : "470px";
		$this->celHeight = number_format(((int)$this->calHeight)/6, "0")."px";
	}

	/**
	 *	Check if parameters is 4-digit year
	 *  	@param $year - string to be checked if it's 4-digit year
	*/	
	function SetCaption($caption_text = "")
	{
		$this->caption = $caption_text;	
	}
	
	/**
	 *	Set week started day
	 *  	@param $started_day - started day of week 1...7
	*/	
	function SetWeekStartedDay($started_day = "1")
	{
		if(is_numeric($started_day) && (int)$started_day >= 1 && (int)$started_day <= 7){
			$this->weekStartedDay = (int)$started_day;				
		}
	}

	/**
	 *	Set week day name length 
	 *  	@param $length_name - "short"|"long"
	*/	
	function SetWeekDayNameLength($length_name = "short")
	{
		if(strtolower($length_name) == "long"){
			$this->weekDayNameLength = "long";
		}
	}
	
	/**
	 *	Set week day name length 
	 *  	@param $length_name - "short"|"long"
	*/	
	function ShowWeekNumberOfYear($show = true)
	{
		if($show === true || strtolower($show) == "true"){
			$this->isWeekNumberOfYear = true;
		}else{
			$this->isWeekNumberOfYear = false;
		}
	}
	
	/**
	 *	Set timezone
	 *		@param $timezone
	*/	
	function SetTimeZone($timezone = "")
	{
		if($timezone != ""){
			$this->timezone = $timezone;
			date_default_timezone_set($this->timezone); 
		}
	}

	/**
	 *	Get current timezone 
	*/	
	function GetCurrentTimeZone()
	{
		return $this->timezone;
	}
	
	/**
	 *	Set default calendar view
	 *		@param $default_view
	*/	
	function SetDefaultView($default_view = "monthly")
	{
		if(array_key_exists($default_view, $this->arrViewTypes)){
			$this->defaultView = $default_view;
		}
	}
	
	/**
	 *	Set form submission type
	 *		@param $submission_type
	*/	
	function SetSubmissionType($submission_type = "post")
	{
		if(strtolower($submission_type) == "get") $this->submissionType = "get";
		else $this->submissionType = "post";
	}

	/**
	 *	Set CSS style
	 *		@param $style
	*/	
	function SetCssStyle($style = "blue")
	{		
		if(strtolower($style) == "green") $this->cssStyle = "green";
		else $this->cssStyle = "blue";
	}
	
	/**
	 *	Set debug mode
	 *		@param $mode
	*/	
	function Debug($mode = false)
	{
		if($mode === true || strtolower($mode) == "true") $this->isDebug = true;
	}
	
	//==========================================================================
    // STATIC
	//==========================================================================		
	/**
	 *	Return current version
	*/	
	static function Version()
	{
		return self::$version;
	}
	
	/**
	 *	Return default time zone
	*/	
	static function GetDefaultTimeZone()
	{
		return date_default_timezone_get();  
	}

	
	//==========================================================================
    // PRIVATE DATA FUNCTIONS
	//==========================================================================		
	/**
	 *	Set default parameters
	 *
	*/	
	function SetDefaultParameters()
	{
		$this->arrParameters["year"]  = date("Y");
		$this->arrParameters["month"] = date("m");
		$this->arrParameters["month_full_name"] = date("F");
		$this->arrParameters["day"]   = date("d");
		$this->arrParameters["view_type"] = $this->defaultView;
		$this->arrParameters["action"] = "display";
		$this->arrToday = getdate();

		// get current file
		$this->arrParameters["current_file"] = $_SERVER["SCRIPT_NAME"];
		$parts = explode('/', $this->arrParameters["current_file"]);
		$this->arrParameters["current_file"] = $parts[count($parts) - 1];		
	}

	/**
	 *	Get current parameters - read them from URL
	 *
	*/	
	function GetCurrentParameters()
	{		
		$year 		= (isset($_REQUEST['hid_year']) && $this->isYear($_REQUEST['hid_year'])) ? $_REQUEST['hid_year'] : date("Y");
		$month 		= (isset($_REQUEST['hid_month']) && $this->isMonth($_REQUEST['hid_month'])) ? $_REQUEST['hid_month'] : date("m");
		$day 		= (isset($_REQUEST['hid_day']) && $this->isDay($_REQUEST['hid_day'])) ? $_REQUEST['hid_day'] : date("d");
		$view_type 	= (isset($_REQUEST['hid_view_type']) && array_key_exists($_REQUEST['hid_view_type'], $this->arrViewTypes)) ? $_REQUEST['hid_view_type'] : $this->defaultView;
	
		$cur_date = getdate(mktime(0,0,0,$month,$day,$year));
		
		$this->arrParameters["year"]  = $cur_date['year'];
		$this->arrParameters["month"] = $this->ConvertToDecimal($cur_date['mon']);
		$this->arrParameters["month_full_name"] = $cur_date['month'];
		$this->arrParameters["day"]   = $day;
		$this->arrParameters["view_type"] = $view_type;
		$this->arrParameters["action"] = "view";
		$this->arrToday = getdate();
		
		///print_r($this->arrParameters);

		$this->prevYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']-1));
		$this->nextYear = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"],$this->arrParameters['year']+1));

		$this->prevMonth = getdate(mktime(0,0,0,$this->arrParameters['month']-1,$this->arrParameters["day"],$this->arrParameters['year']));
		$this->nextMonth = getdate(mktime(0,0,0,$this->arrParameters['month']+1,$this->arrParameters["day"],$this->arrParameters['year']));
         
		$this->prevWeek = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"]-7,$this->arrParameters['year']));
		$this->nextWeek = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"]+7,$this->arrParameters['year']));
		
		$this->prevDay = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"]-1,$this->arrParameters['year']));
		$this->nextDay = getdate(mktime(0,0,0,$this->arrParameters['month'],$this->arrParameters["day"]+1,$this->arrParameters['year']));
	}

	/**
	 *	Handle events - proccess events: insert, edit or delete
	 *
	*/	
	function HandleEvents()
	{
		$event_action 		= isset($_REQUEST['hid_event_action']) ? $_REQUEST['hid_event_action'] : "";
		$event_id 		    = isset($_REQUEST['hid_event_id']) ? $_REQUEST['hid_event_id'] : "";

		$event_name 		= isset($_REQUEST['event_name']) ? $_REQUEST['event_name'] : "";
		$event_description 	= isset($_REQUEST['event_description']) ? $_REQUEST['event_description'] : "";

		$event_from_hour 	= isset($_REQUEST['event_from_hour']) ? $_REQUEST['event_from_hour'] : "";
		$event_from_day 	= isset($_REQUEST['event_from_day']) ? $_REQUEST['event_from_day'] : "";
		$event_from_month 	= isset($_REQUEST['event_from_month']) ? $_REQUEST['event_from_month'] : "";
		$event_from_year 	= isset($_REQUEST['event_from_year']) ? $_REQUEST['event_from_year'] : "";
		$start_date         = $event_from_year."-".$event_from_month."-".$event_from_day." ".$event_from_hour;
		
		$event_to_hour 		= isset($_REQUEST['event_to_hour']) ? $_REQUEST['event_to_hour'] : "";
		$event_to_day 		= isset($_REQUEST['event_to_day']) ? $_REQUEST['event_to_day'] : "";
		$event_to_month 	= isset($_REQUEST['event_to_month']) ? $_REQUEST['event_to_month'] : "";
		$event_to_year 		= isset($_REQUEST['event_to_year']) ? $_REQUEST['event_to_year'] : "";
		$finish_date        = $event_to_year."-".$event_to_month."-".$event_to_day." ".$event_to_hour;

		if($this->isDemo && $event_action != ""){ 
			$this->arrMessages[] = "<font color='#a60000'>This operation is blocked in DEMO version.</font>";
			return false;
		}
			
		if($event_action == "add"){
			$sql = "INSERT INTO ".TABLE_EVENTS." (id, name, description) VALUES (NULL, '".$event_name."', '".$event_description."') ";
			$insert_id = database_void_query($sql);	
			if($insert_id != false){
				$sql = "INSERT INTO ".TABLE_CALENDAR." (id, event_id, event_date, event_time) VALUES ";
				$current_date = $start_date;
				$offset = 0;
				while($current_date < $finish_date){
					$current = getdate(mktime($this->ParseHour($event_from_hour)+$offset,0,0,$event_from_month,$event_from_day,$event_from_year));
					$curr_date = $current['year']."-".$this->ConvertToDecimal($current['mon'])."-".$this->ConvertToDecimal($current['mday']);
					$curr_time = $this->ConvertToHour($current['hours']);
					$current_date = $curr_date." ".$curr_time;
					
					if($current_date < $finish_date){
						if($offset > 0) $sql .= ", ";
						$sql .= "(NULL, ".(int)$insert_id.", '".$curr_date."', '".$curr_time."')";
					}
					$offset++;
				}
				if(!database_void_query($sql)){
					$this->arrErrors[] = $sql."<br />".mysql_error();					
					$this->arrMessages[] = "<font color='#a60000'>An error occured while inserting new events! Please try again later.</font>";
				}else{
					$this->arrMessages[] = "<font color='#00a600'>New event was successfully added!</font>";					
				}
			}else{
				$this->arrErrors[] = $sql."<br />".mysql_error();					
				$this->arrMessages[] = "<font color='#a60000'>An error occured while inserting new event! Please try again later.</font>";
			}
		}else if($event_action == "delete"){
			$sql = "DELETE FROM ".TABLE_CALENDAR." WHERE id = ".(int)$event_id;			
			if(!database_void_query($sql)){
				$this->arrErrors[] = $sql."<br />".mysql_error();					
				$this->arrMessages[] = "<font color='#a60000'>An error occured while deleting event! Please try again later.</font>";
			}else{
				$this->arrMessages[] = "<font color='#00a600'>Event was successfully deleted!</font>";					
			}
		}
	}
	

	/**
	 *	Draw CSS style
	 *
	*/	
	private function DrawCssStyle()
	{
		echo "<link href='../modules/calendar/style/".$this->cssStyle."/style.css' rel='stylesheet' type='text/css' />".$this->crLt;		
	}

	/**
	 *	Draw javascript functions
	 *
	*/	
	private function DrawJsFunctions()
	{
		echo "<script type='text/javascript'>\n";
		echo "<!--\n
			GL_jump_day   = '".$this->arrToday["mday"]."';
			GL_jump_month = '".$this->ConvertToDecimal($this->arrToday["mon"])."';
			GL_jump_year  = '".$this->arrToday["year"]."';
			GL_view_type  = '".$this->defaultView."';

			GL_today_year = '".$this->arrToday["year"]."';
			GL_today_mon  = '".$this->ConvertToDecimal($this->arrToday["mon"])."';
			GL_today_mday = '".$this->arrToday["mday"]."';

		\n//-->\n";
		echo "</script>";
		echo "<script type='text/javascript' src='../modules/calendar/js/calendar.js'></script>".$this->crLt;
		
	}
	
	/**
	 *	Draw system messages
	 *
	*/	
	private function DrawMessages()
	{		
		if(count($this->arrMessages) > 0){
			echo "<tr>";
			foreach($this->arrMessages as $key){
				echo "<th class='caption_center' colspan='3'>".$key."</th>".$this->crLt;
			}
			echo "</tr>";
		}
	}
	
	/**
	 *	Draw system errors
	 *
	*/	
	private function DrawErrors()
	{		
		if(count($this->arrErrors) > 0){
			foreach($this->arrErrors as $key){
				echo "<span>".$key."</span><br />".$this->crLt;
			}
		}
	}

	/**
	 *	Draw yearly calendar
	 *
	*/	
	private function DrawYear()
	{
		$this->celHeight = "20px";
		echo "<table class='year_container'>".$this->crLt;
		echo "<tr>".$this->crLt;
			echo "<th colspan='3'>";
				echo "<table class='table_navbar'>".$this->crLt;
				echo "<tr>";
				echo "<th class='tr_navbar_left' valign='middle'>
					  ".$this->DrawDateJumper(false, false, false)."
					  </th>".$this->crLt;
				echo "<th class='tr_navbar'></th>".$this->crLt;
				echo "<th class='tr_navbar_right'>				
					  <a href=\"javascript:__doPostBack('view', 'yearly', '".$this->prevYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->prevYear['year']."</a> |
					  <a href=\"javascript:__doPostBack('view', 'yearly', '".$this->nextYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->nextYear['year']."</a>
					  </th>".$this->crLt;
				echo "</tr>".$this->crLt;
				echo "</table>".$this->crLt;
			echo "</td>".$this->crLt;
		echo "</tr>".$this->crLt;

		echo "<tr>";
		for($i = 1; $i <= 12; $i++){
			echo "<td align='center' valign='top'>";
			echo "<a href=\"javascript:__doPostBack('view', 'monthly', '".$this->arrParameters['year']."', '".$this->ConvertToDecimal($i)."', '".$this->arrParameters['day']."')\"><b>".$this->arrMonths["$i"]."</b></a>";
			$this->DrawMonthSmall($this->arrParameters['year'], $this->ConvertToDecimal($i));
			echo "</td>";
			if(($i != 1) && ($i % 3 == 0)) echo "</tr><tr>";
		}
		echo "</tr>";
		echo "<tr><td nowrap height='5px'></td></tr>";
		echo "</table>";
	}

	/**
	 *	Draw monthly calendar
	 *
	*/	
	private function DrawMonth()
	{
	
		// today, first day and last day in month
		$firstDay = getdate(mktime(0,0,0,$this->arrParameters['month'],1,$this->arrParameters['year']));
		$lastDay  = getdate(mktime(0,0,0,$this->arrParameters['month']+1,0,$this->arrParameters['year']));

		$arrEventsCount = $this->GetEventCountForMonth($this->arrParameters['year'], $this->arrParameters['month']);
		$actday = 0;
		
		///echo "<pre>";
		///print_r($arrEventsCount);
		///echo "</pre>";

		
		// Create a table with the necessary header informations
		echo "<table class='month'>".$this->crLt;
		echo "<tr>";
			if($this->isWeekNumberOfYear) echo "<th colspan='8'>";
			else echo "<th colspan='7'>";
				echo "<table class='table_navbar'>".$this->crLt;
				echo "<tr>";
				echo "<th class='tr_navbar_left'>
					  ".$this->DrawDateJumper(false)."	
					  </th>".$this->crLt;
				echo "<th class='tr_navbar'>";
				echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevMonth['year']."', '".$this->ConvertToDecimal($this->prevMonth['mon'])."', '".$this->arrParameters['day']."')\">&laquo;&laquo;</a> ";
				echo $this->arrParameters['month_full_name']." - ".$this->arrParameters['year'];
				echo " <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextMonth['year']."', '".$this->ConvertToDecimal($this->nextMonth['mon'])."', '".$this->arrParameters['day']."')\">&raquo;&raquo;</a> ";
				echo "</th>".$this->crLt;
				echo "<th class='tr_navbar_right'>				
					  <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->prevYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->prevYear['year']."</a> |
					  <a href=\"javascript:__doPostBack('view', 'monthly', '".$this->nextYear['year']."', '".$this->arrParameters['month']."', '".$this->arrParameters['day']."')\">".$this->nextYear['year']."</a>
					  </th>".$this->crLt;
				echo "</tr>".$this->crLt;
				echo "</table>".$this->crLt;
			echo "</td>".$this->crLt;
		echo "</tr>".$this->crLt;
		echo "<tr class='tr_days'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='th_wn'></td>".$this->crLt;
			for($i = $this->weekStartedDay-1; $i < $this->weekStartedDay+6; $i++){
				echo "<td class='th'>".$this->arrWeekDays[($i % 7)][$this->weekDayNameLength]."</td>".$this->crLt;
			}
		echo "</tr>".$this->crLt;		
		
		// Display the first calendar row with correct positioning
		if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
		$max_empty_days = $firstDay['wday']-($this->weekStartedDay-1);		
		if($max_empty_days < 7){
			echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear){
				echo "<td class='td_wn'>";
				echo "<a href=\"javascript:__doPostBack('view', 'weekly', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".(1-$max_empty_days)."')\">";
				echo date("W", mktime(0,0,0,$this->arrParameters["month"],1-$max_empty_days,$this->arrParameters["year"]));
				echo "</a>";
				echo "</td>".$this->crLt;
			}
			for($i = 1; $i <= $max_empty_days; $i++){
				echo "<td class='td_empty'>&nbsp;</td>".$this->crLt;
			}			
			for($i = $max_empty_days+1; $i <= 7; $i++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
					$class = " class='td_actday'";			
				} else if ($actday == $this->arrParameters['day']){				
					$class = " class='td_selday'";				
				} else {
					$class = " class='td'";
				} 
				echo "<td$class>";
				echo "<a href=\"javascript:__doPostBack('view', 'daily', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$this->ConvertToDecimal($actday)."')\">".$actday."</a>";
				echo "<br />";
				$events_count = $arrEventsCount[$this->ConvertToDecimal($actday)];
				echo ($events_count > 0) ? (($events_count > 1) ? $events_count." events" : $events_count." event") : "";
				echo "</td>".$this->crLt;
			}
			echo "</tr>".$this->crLt;
		}
		
		//Get how many complete weeks are in the actual month
		$fullWeeks = floor(($lastDay['mday']-$actday)/7);
		
		for ($i=0;$i<$fullWeeks;$i++){
			echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear){
				echo "<td class='td_wn'>";
				echo "<a href=\"javascript:__doPostBack('view', 'weekly', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".($actday+1)."')\">";
				echo date("W", mktime(0,0,0,$this->arrParameters["month"],$actday+1,$this->arrParameters["year"]));
				echo "</a>";
				echo "</td>".$this->crLt;
			}
			for ($j=0;$j<7;$j++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
					$class = " class='td_actday'";
				} else if ($actday == $this->arrParameters['day']){				
					$class = " class='td_selday'";				
				} else {
					$class = " class='td'";
				}
				echo "<td$class>";
				echo "<a href=\"javascript:__doPostBack('view', 'daily', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$this->ConvertToDecimal($actday)."')\">".$actday."</a>";
				echo "<br />";
			    $events_count = $arrEventsCount[$this->ConvertToDecimal($actday)];
				echo ($events_count > 0) ? (($events_count > 1) ? $events_count." events" : $events_count." event") : "";
				echo "</td>".$this->crLt;
				echo "</td>".$this->crLt;
			}
			echo "</tr>".$this->crLt;
		}
		
		//Now display the rest of the month
		if ($actday < $lastDay['mday']){
			echo "<tr class='tr' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear){
				echo "<td class='td_wn'>";
				echo "<a href=\"javascript:__doPostBack('view', 'weekly', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$this->ConvertToDecimal($actday+1)."')\">";
				echo date("W", mktime(0,0,0,$this->arrParameters["month"],$actday+1,$this->arrParameters["year"]));
				echo "</a>";
				echo "</td>".$this->crLt;
			}

			for ($i=0; $i<7;$i++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
					$class = " class='td_actday'";
				} else {
					$class = " class='td'";
				}				
				if ($actday <= $lastDay['mday']){
					echo "<td$class>";
					echo "<a href=\"javascript:__doPostBack('view', 'daily', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$this->ConvertToDecimal($actday)."')\">".$actday."</a>";
					echo "<br />";
					$events_count = $arrEventsCount[$this->ConvertToDecimal($actday)];
					echo ($events_count > 0) ? (($events_count > 1) ? $events_count." events" : $events_count." event") : "";
					echo "</td>".$this->crLt;
				} else {
					echo "<td class='td_empty'>&nbsp;</td>".$this->crLt;
				}
			}					
			echo "</tr>".$this->crLt;
		}		
		echo "</table>".$this->crLt;
		
	}

	/**
	 *	Draw small monthly calendar
	 *
	*/	
	private function DrawMonthSmall($year = "", $month = "")
	{
		if($month == "") $month = $this->arrParameters['month'];
		if($year == "") $year = $this->arrParameters['year'];
		$week_rows = 0;
		$actday = 0;
		
		// today, first day and last day in month
		$firstDay = getdate(mktime(0,0,0,$month,1,$year));
		$lastDay  = getdate(mktime(0,0,0,$month+1,0,$year));
		
		// create a table with the necessary header informations
		echo "<table class='month_small'>".$this->crLt;
		echo "<tr class='tr_small_days'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='th_small_wn'></td>".$this->crLt;
			for($i = $this->weekStartedDay-1; $i < $this->weekStartedDay+6; $i++){
				echo "<td class='th_small'>".$this->arrWeekDays[($i % 7)]["short"]."</td>".$this->crLt;		
			}
		echo "</tr>".$this->crLt;
		
		// display the first calendar row with correct positioning
		if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
		$max_empty_days = $firstDay['wday']-($this->weekStartedDay-1);		
		if($max_empty_days < 7){
			echo "<tr class='tr_small' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='td_small_wn'>".date("W", mktime(0,0,0,$month,1-$max_empty_days,$year))."</td>".$this->crLt;			
			for($i = 1; $i <= $max_empty_days; $i++){
				echo "<td class='td_small_empty'>&nbsp;</td>".$this->crLt;
			}			
			for($i = $max_empty_days+1; $i <= 7; $i++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $month) && ($this->arrToday['year'] == $year)) {
					$class = " class='td_small_actday'";			
				} else {
					$class = " class='td_small'";
				} 
				echo "<td$class>$actday</td>".$this->crLt;
			}
			echo "</tr>".$this->crLt;
			$week_rows++;
		}
		
		// get how many complete weeks are in the actual month
		$fullWeeks = floor(($lastDay['mday']-$actday)/7);
		
		for ($i=0;$i<$fullWeeks;$i++){
			echo "<tr class='tr_small' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='td_small_wn'>".date("W", mktime(0,0,0,$month,$actday,$year))."</td>".$this->crLt;			
			for ($j=0;$j<7;$j++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $month) && ($this->arrToday['year'] == $year)) {
					$class = " class='td_small_actday'";
				} else {
					$class = " class='td_small'";
				}
				echo "<td$class>$actday</td>".$this->crLt;
			}
			echo "</tr>".$this->crLt;
			$week_rows++;			
		}
		
		// now display the rest of the month
		if ($actday < $lastDay['mday']){
			echo "<tr class='tr_small' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='td_small_wn'>".date("W", mktime(0,0,0,$month,$actday,$year))."</td>".$this->crLt;			
			for ($i=0; $i<7;$i++){
				$actday++;
				if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $month) && ($this->arrToday['year'] == $year)) {
					$class = " class='td_small_actday'";
				} else {
					$class = " class='td_small'";
				}				
				if ($actday <= $lastDay['mday']){
					echo "<td$class>$actday</td>".$this->crLt;
				} else {
					echo "<td class='td_small_empty'>&nbsp;</td>".$this->crLt;
				}
			}					
			echo "</tr>".$this->crLt;
			$week_rows++;
		}
		
		// complete last line
		if($week_rows < 5){
			echo "<tr class='tr_small' style='height:".$this->celHeight.";'>".$this->crLt;
			if($this->isWeekNumberOfYear) echo "<td class='td_small_wn'></td>".$this->crLt;
			for ($i=0; $i<7;$i++){
				echo "<td class='td_small_empty'>&nbsp;</td>".$this->crLt;
			}					
			echo "</tr>".$this->crLt;
			$week_rows++;			
		}
		
		echo "</table>".$this->crLt;
		
	}	

	/**
	 *	Draw weekly calendar
	 *
	*/	
	private function DrawWeek()
	{
		// today, first day and last day in month
		$firstDay = getdate(mktime(0,0,0,$this->arrParameters['month'],1,$this->arrParameters['year']));
		$lastDay  = getdate(mktime(0,0,0,$this->arrParameters['month']+1,0,$this->arrParameters['year']));
		
		// Create a table with the necessary header informations
		echo "<table class='month' border=0>".$this->crLt;
		echo "<tr>".$this->crLt;
		echo "<th colspan='7'>".$this->crLt;
			echo "<table border=0 width='100%'>".$this->crLt;
			echo "<tr>";
			echo "<th class='tr_navbar_left'>".$this->DrawDateJumper(false)."</th>";				  
			echo "<th class='tr_navbar'>".(($this->prevWeek['month'] != $this->nextWeek['month']) ? $this->prevWeek['month']."-".$this->nextWeek['month']." " : $this->prevWeek['month']." - ").$this->arrParameters['year']."</th>".$this->crLt;
			echo "<th class='tr_navbar_right'>				
				  <a href=\"javascript:__doPostBack('view', 'weekly', '".$this->prevWeek['year']."', '".$this->prevWeek['mon']."', '".$this->ConvertToDecimal($this->prevWeek['mday'])."')\">".$this->ConvertToDecimal($this->prevWeek['mday'])."th ".$this->prevWeek['month']."</a> |
				  <a href=\"javascript:__doPostBack('view', 'weekly', '".$this->nextWeek['year']."', '".$this->nextWeek['mon']."', '".$this->ConvertToDecimal($this->nextWeek['mday'])."')\">".$this->ConvertToDecimal($this->nextWeek['mday'])."th ".$this->nextWeek['month']."</a>
				  </th>".$this->crLt;
			echo "</tr>".$this->crLt;
			echo "</table>".$this->crLt;			  
		echo "</th>".$this->crLt;
		echo "</tr>".$this->crLt;
		echo "<tr class='tr_days'>".$this->crLt;
			for($i = $this->weekStartedDay-1; $i < $this->weekStartedDay+6; $i++){
				echo "<td class='th'>".$this->arrWeekDays[($i % 7)][$this->weekDayNameLength]."</td>";		
			}
		echo "</tr>".$this->crLt;
		
		// Display the first calendar row with correct positioning
		echo "<tr>".$this->crLt;
		if ($firstDay['wday'] == 0) $firstDay['wday'] = 7;
		$actday = 0;
		for($i = 0; $i <= 6; $i++){
			$actday = date("d", mktime(0,0,0,$this->arrParameters["month"],$this->arrParameters["day"]+$i,$this->arrParameters["year"]));
			$actmon = date("M", mktime(0,0,0,$this->arrParameters["month"],$this->arrParameters["day"]+$i,$this->arrParameters["year"]));
			if (($actday == $this->arrToday['mday']) && ($this->arrToday['mon'] == $this->arrParameters["month"])) {
				$class = " class='td_actday_w'";
			} else {
				$class = " class='td'";
			}
			echo "<td$class>".$this->crLt;
				
				// prepare events for this day of week
				$sql = "SELECT
							".TABLE_CALENDAR.".id,
							".TABLE_CALENDAR.".event_date,
							".TABLE_CALENDAR.".event_time,
							DATE_FORMAT(".TABLE_CALENDAR.".event_time, '%H') as event_time_formatted,
							".TABLE_EVENTS.".name,
							".TABLE_EVENTS.".description
						FROM ".TABLE_CALENDAR."
							INNER JOIN ".TABLE_EVENTS." ON ".TABLE_CALENDAR.".event_id = ".TABLE_EVENTS.".id
						WHERE
							".TABLE_CALENDAR.".event_date = '".$this->arrParameters['year']."-".$this->arrParameters['month']."-".$actday."' 
						ORDER BY ".TABLE_CALENDAR.".id ASC";
						
				$result = database_query($sql, _DATA_AND_ROWS, _ALL_ROWS, _FETCH_ASSOC);
				
				$arrEvents = array(
					"00"=>array(), "01"=>array(), "02"=>array(), "03"=>array(), "04"=>array(), "05"=>array(), "06"=>array(), "07"=>array(), "08"=>array(), "09"=>array(), "10"=>array(), "11"=>array(),
					"12"=>array(), "13"=>array(), "14"=>array(), "15"=>array(), "16"=>array(), "17"=>array(), "18"=>array(), "19"=>array(), "20"=>array(), "21"=>array(), "22"=>array(), "23"=>array());
					 
				foreach($result[0] as $key => $val){
					$arrEvents[$val['event_time_formatted']][] = array("id"=>$val['id'], "name"=>$val['name']);
				}
			
				echo "<table width='100%' border='0' cellpadding='0' celspacing='0'>".$this->crLt;
				echo "<tr class='td_header'><td align='left' colspan='2'><b><a href=\"javascript:__doPostBack('view', 'daily', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$actday."')\">$actmon $actday</a></b></td></tr>".$this->crLt;
				for($i_hour=0; $i_hour<24; $i_hour++){
					echo "<tr>";
					echo "<td align='left' width='35px'>".$this->ConvertToHour($i_hour)."</td>";
					echo "<td align='left' style='font-weight:normal;'>";
					echo $this->GetEventsList($arrEvents[$this->ConvertToDecimal($i_hour)], 8);
					echo "</td>";
					echo "</tr>".$this->crLt;
				}
				echo "</table>".$this->crLt;
			echo "</td>".$this->crLt;
		}
		echo "</tr>".$this->crLt;
		echo "</table>".$this->crLt;		
	}

	/**
	 *	Draw daily calendar
	 *
	*/	
	private function DrawDay()
	{
		$sql = "SELECT
					".TABLE_CALENDAR.".id,
					".TABLE_CALENDAR.".event_date,
					".TABLE_CALENDAR.".event_time,
					DATE_FORMAT(".TABLE_CALENDAR.".event_time, '%H') as event_time_formatted,					
					".TABLE_EVENTS.".name,
					".TABLE_EVENTS.".description
				FROM ".TABLE_CALENDAR."
					INNER JOIN ".TABLE_EVENTS." ON ".TABLE_CALENDAR.".event_id = ".TABLE_EVENTS.".id
				WHERE
					".TABLE_CALENDAR.".event_date = '".$this->arrParameters['year']."-".$this->arrParameters['month']."-".$this->arrParameters['day']."' 
				ORDER BY ".TABLE_CALENDAR.".id ASC";
				
		$result = database_query($sql, _DATA_AND_ROWS, _ALL_ROWS, _FETCH_ASSOC);
		
		$arrEvents = array(
		    "00"=>array(), "01"=>array(), "02"=>array(), "03"=>array(), "04"=>array(), "05"=>array(), "06"=>array(), "07"=>array(), "08"=>array(), "09"=>array(), "10"=>array(), "11"=>array(),
			"12"=>array(), "13"=>array(), "14"=>array(), "15"=>array(), "16"=>array(), "17"=>array(), "18"=>array(), "19"=>array(), "20"=>array(), "21"=>array(), "22"=>array(), "23"=>array());
             
		foreach($result[0] as $key => $val){
			$arrEvents[$val['event_time_formatted']][] = array("id"=>$val['id'], "name"=>$val['name']);
		}
		
		// Create a table with the necessary header informations
		echo "<table class='day_navigation' width='100%' border='0' cellpadding='0' celspacing='0'>".$this->crLt;
		echo "<tr>";
		echo "<th class='tr_navbar_left'>
			  ".$this->DrawDateJumper(false)."	
			  </th>".$this->crLt;
		echo "<th class='tr_navbar'>";
		echo " <a href=\"javascript:__doPostBack('view', 'daily', '".$this->prevDay['year']."', '".$this->ConvertToDecimal($this->prevDay['mon'])."', '".$this->ConvertToDecimal($this->prevDay['mday'])."')\">&laquo;&laquo;</a> ";
		echo $this->arrParameters['month_full_name']." ".$this->arrParameters['day'].", ".$this->arrParameters['year'];
		echo " <a href=\"javascript:__doPostBack('view', 'daily', '".$this->nextDay['year']."', '".$this->ConvertToDecimal($this->nextDay['mon'])."', '".$this->ConvertToDecimal($this->nextDay['mday'])."')\">&raquo;&raquo;</a> ";
		echo "</th>".$this->crLt;
		echo "<th class='tr_navbar_right' colspan='2'>				
			  <a href=\"javascript:__doPostBack('view', 'daily', '".$this->prevWeek['year']."', '".$this->prevWeek['mon']."', '".$this->ConvertToDecimal($this->prevWeek['mday'])."')\">".$this->ConvertToDecimal($this->prevWeek['mday'])."th ".$this->prevWeek['month']."</a> |
			  <a href=\"javascript:__doPostBack('view', 'daily', '".$this->nextWeek['year']."', '".$this->nextWeek['mon']."', '".$this->ConvertToDecimal($this->nextWeek['mday'])."')\">".$this->ConvertToDecimal($this->nextWeek['mday'])."th ".$this->nextWeek['month']."</a>
			  </th>".$this->crLt;
		echo "</tr>".$this->crLt;
		echo "</table>".$this->crLt;

		echo "<table class='day' width='100%' border='0' cellpadding='0' celspacing='0'>".$this->crLt;
		for($i_hour=0; $i_hour<24; $i_hour++){
			if($this->ConvertToDecimal($i_hour) == $this->arrToday['hours']) {
				$td_acthour_d = " class='td_acthour_d_h'";
				$td_d = " class='td_acthour_d'";
			} else {
				$td_acthour_d = " class='td_d_h'";
				$td_d = " class='td_d'";
			}
			echo "<tr>".$this->crLt;
			echo "<td".$td_acthour_d." width='50px'><b>".$this->ConvertToHour($i_hour)."</b></td>".$this->crLt;
			echo "<td".$td_d.">";
			if($this->arrOpearations['add']){
				echo "<a href=\"javascript:__CallAddEventForm('divAddEvent', '".$this->arrParameters["year"]."', '".$this->arrParameters["month"]."', '".$this->arrParameters["day"]."', '".$this->ConvertToHour($i_hour)."');\" title='Add New Event'>+</a> ";
			}
            echo $this->GetEventsList($arrEvents[$this->ConvertToDecimal($i_hour)]);
			echo "</td>".$this->crLt;
			echo "</tr>".$this->crLt;
		}
		echo "</table>".$this->crLt;
		
		echo "<div id='divAddEvent'>			
				<table>				
				<tr>
					<td colspan='2'>
						<table class='header'>
						<tr>
							<td align='left'><b>Add Event</b></td>
							<td align='right'><a href=\"javascript:__HideEventForm('divAddEvent');\">[Close]</a></td>						
						</tr>
						</table>					
					</td>					
				</tr>
				<tr>
					<td>Event Name:</td>
					<td><input type='text' style='width:240px' id='event_name' name='event_name' /></td>
				</tr>
				<tr>
					<td>Event Decription:</td>
					<td><textarea style='width:240px; height:50px;' id='event_description' name='event_description'></textarea></td>
				</tr>
				<tr>
					<td>From:</td>
					<td>".$this->DrawDateTime("from", $this->arrParameters["year"], $this->arrParameters["month"], $this->arrParameters["day"], $this->arrToday['hours'], false)."</td>
				</tr>
				<tr>
					<td>To:</td>
					<td>".$this->DrawDateTime("to", $this->arrParameters["year"], $this->arrParameters["month"], $this->arrParameters["day"], $this->arrToday['hours'], false)."</td>
				</tr>
				<tr><td colspan='2' align='center' style='height:25px;padding:0px;'><div id='divAddEvent_msg'></div</td></tr>
				<tr><td colspan='2' align='right' style='padding-right:5px;'><input type='button' name='btnSubmit' value='Add' onclick='javascript:__AddEvent();'/></td></tr>
				</table>				
			</div>";
	}

	/**
	 *	Draw calendar types changer
	 *  	@param $draw - draw or return
	*/	
	private function DrawTypesChanger($draw = true)
	{
		$result = "<select class='form_select' name='view_type' id='view_type' onchange=\"javascript:__doPostBack('view', this.value)\">";
		foreach($this->arrViewTypes as $key => $val){
			$result .= "<option value='".$key."'".(($this->arrParameters['view_type'] == $key) ? " selected='selected'" : "").">".$val."</option>";
		}
		$result .= "</select>";
		
		if($draw){
			echo $result;
		}else{
			return $result;
		}
	}

	/**
	 *	Draw today jumper
	 *  	@param $draw - draw or return
	*/	
	private function DrawTodayJumper($draw = true)
	{
		$result = "<input class='form_button' type='button' value='Today' onclick=\"javascript:__JumpTodayDate()\" />";
		if($draw){
			echo $result;
		}else{
			return $result;
		}
	}
	
	/**
	 *	Draw date jumper
	 *  	@param $draw - draw or return
	*/	
	private function DrawDateJumper($draw = true, $draw_day = true, $draw_month = true, $draw_year = true)
	{
		$result = "";
		
		// draw days ddl
		if($draw_day){
			$result = "<select class='form_select' name='jump_day' id='jump_day'>";
			for($i=1; $i <= 31; $i++){
				$i_converted = $this->ConvertToDecimal($i);
				$result .= "<option value='".$i_converted."'".(($this->arrParameters["day"] == $i_converted) ? " selected='selected'" : "").">".$i_converted."</option>";
			}
			$result .= "</select> ";			
		}else{
			$result .= "<input type='hidden' name='jump_day' id='jump_day' value='".$this->arrToday["mday"]."' />";			
		}

		// draw months ddl
		if($draw_month){			
			$result .= "<select class='form_select' name='jump_month' id='jump_month'>";
			for($i=1; $i <= 12; $i++){
				$i_converted = $this->ConvertToDecimal($i);
				$result .= "<option value='".$i_converted."'".(($this->arrParameters["month"] == $i_converted) ? " selected='selected'" : "").">".$this->arrMonths[$i]."</option>";
			}
			$result .= "</select> ";			
		}else{
			$result .= "<input type='hidden' name='jump_month' id='jump_month' value='".$this->ConvertToDecimal($this->arrToday["mon"])."' />";			
		}

		// draw years ddl
		if($draw_year){			
			$result .= "<select class='form_select' name='jump_year' id='jump_year'>";
			for($i=$this->arrParameters["year"]-10; $i <= $this->arrParameters["year"]+10; $i++){
				$result .= "<option value='".$i."'".(($this->arrParameters["year"] == $i) ? " selected='selected'" : "").">".$i."</option>";
			}
			$result .= "</select> ";
		}else{
			$result .= "<input type='hidden' name='jump_year' id='jump_year' value='".$this->arrToday["year"]."' />";			
		}
		
		$result .= "<input class='form_button' type='button' value='Go' onclick='__JumpToDate()' />";
		
		if($draw){
			echo $result;
		}else{
			return $result;
		}
	}

	/**
	 *	Draw datetime calendar
	 *  	@param $draw - draw or return
	 *  	@param $type - from|to
	*/	
	private function DrawDateTime($type = "from", $year = "", $month = "", $day = "", $hour = "", $draw = true)
	{
		$result = ""; 
		
		// draw days ddl
		$result = "<select class='form_select' name='event_".$type."_day' id='event_".$type."_day'>";
		for($i=1; $i <= 31; $i++){
			$i_converted = $this->ConvertToDecimal($i);
			$result .= "<option value='".$i_converted."'".(($day == $i_converted) ? " selected='selected'" : "").">".$i_converted."</option>";
		}
		$result .= "</select> ";			

		// draw months ddl
		$result .= "<select class='form_select' name='event_".$type."_month' id='event_".$type."_month'>";
		for($i=1; $i <= 12; $i++){
			$i_converted = $this->ConvertToDecimal($i);
			$result .= "<option value='".$i_converted."'".(($month == $i_converted) ? " selected='selected'" : "").">".$this->arrMonths[$i]."</option>";
		}
		$result .= "</select> ";			

		// draw years ddl
		$result .= "<select class='form_select' name='event_".$type."_year' id='event_".$type."_year'>";
		for($i=$year-10; $i <= $year+10; $i++){
			$result .= "<option value='".$i."'".(($year == $i) ? " selected='selected'" : "").">".$i."</option>";
		}
		$result .= "</select> ";		
		
		// draw hours ddl
		$result .= "<select class='form_select' name='event_".$type."_hour' id='event_".$type."_hour'>";
		for($i=0; $i < 24; $i++){
			$i_converted = $this->ConvertToDecimal($i);
			$i_converted_hour = $this->ConvertToHour($i);
			$result .= "<option value='".$i_converted_hour."'".(($hour == $i_converted) ? " selected='selected'" : "").">".$i_converted_hour."</option>";
		}
		$result .= "</select> ";			

		if($draw){
			echo $result;
		}else{
			return $result;
		}
	}

	////////////////////////////////////////////////////////////////////////////
	// Auxilary
	////////////////////////////////////////////////////////////////////////////
	/**
	 *	Returns list of events for certain hour
	 *  	@param $events - array of events
	*/	
	private function GetEventsList($events = array(), $max_length = "")
	{
		$output = "";
		foreach($events as $key => $cal){
			if($output != "") $output .= ", ";
			$output .= $cal['name'];
			if($this->arrOpearations['delete']){
				if($max_length == "") $output .= " <a href='javascript:void(0);' onclick=\"__DeleteEvent('".$cal['id']."');\" title='Click to delete'><img src='../modules/calendar/style/".$this->cssStyle."/images/delete.gif' title='Click to delete' style='border:0px;vertical-align:middle;' alt='' /></a>";
			}
		}
		if($max_length != "" && strlen($output) > $max_length){
			$output = "<label title='".$output."' style='cursor:help;'>".substr($output, 0, $max_length)."...</label>";
		}
		return $output;
	}	
				
	/**
	 *	Returns count of events for the certain day
	 *  	@param $event_date - day of events
	*/	
	private function GetEventCountForDay($event_date = "")
	{
		// prepare events for this day of week
		$sql = "SELECT
					".TABLE_CALENDAR.".event_date,
					".TABLE_CALENDAR.".event_time,
					DATE_FORMAT(".TABLE_CALENDAR.".event_time, '%H') as event_time_formatted,
					".TABLE_EVENTS.".name,
					".TABLE_EVENTS.".description
				FROM ".TABLE_CALENDAR."
					INNER JOIN ".TABLE_EVENTS." ON ".TABLE_CALENDAR.".event_id = ".TABLE_EVENTS.".id
				WHERE
					".TABLE_CALENDAR.".event_date = ".$event_date." 
				GROUP BY ".TABLE_EVENTS.".id";
		return database_query($sql, _ROWS_ONLY);
	}

	/**
	 *	Returns count of events for the certain month
	 *  	@param $event_year - $year of events
	 *  	@param $event_month - $month of events
	*/	
	private function GetEventCountForMonth($event_year = "", $event_month = "")
	{
		// prepare events for this day of week
		$sql = "SELECT
					GROUP_CONCAT(DISTINCT ".TABLE_EVENTS.".id ORDER BY ".TABLE_EVENTS.".id ASC SEPARATOR '-') as cnt,
					".TABLE_CALENDAR.".event_date,
					SUBSTRING(".TABLE_CALENDAR.".event_date, 9, 2) as day
				FROM ".TABLE_CALENDAR."
					INNER JOIN ".TABLE_EVENTS." ON ".TABLE_CALENDAR.".event_id = ".TABLE_EVENTS.".id
				WHERE
					SUBSTRING(".TABLE_CALENDAR.".event_date, 1, 4) =  '".$event_year."' AND 
					SUBSTRING(".TABLE_CALENDAR.".event_date, 6, 2) =  '".$event_month."' 
				GROUP BY
					SUBSTRING(".TABLE_CALENDAR.".event_date, 9, 2)";
		$result = database_query($sql, _DATA_AND_ROWS, _ALL_ROWS, _FETCH_ASSOC);
		$arrEventsCount = array(
			"01"=>0, "02"=>0, "03"=>0, "04"=>0, "05"=>0, "06"=>0, "07"=>0, "08"=>0, "09"=>0, "10"=>0, "11"=>0, "12"=>0, "13"=>0, "14"=>0, "15"=>0,
			"16"=>0, "17"=>0, "18"=>0, "19"=>0, "20"=>0, "21"=>0, "22"=>0, "23"=>0, "24"=>0, "25"=>0, "26"=>0, "27"=>0, "28"=>0, "29"=>0, "30"=>0, "31"=>0);
			 
		foreach($result[0] as $key => $val){
			$cnt_array = explode("-", $val['cnt']);
			$arrEventsCount[$val['day']] = count($cnt_array);
		}		
		return $arrEventsCount;
	}

	/**
	 *	Check if parameters is 4-digit year
	 *  	@param $year - string to be checked if it's 4-digit year
	*/	
	private function isYear($year = "")
	{
		if(!strlen($year) == 4 || !is_numeric($year)) return false;
		for($i = 0; $i < 4; $i++){
			if(!(isset($year[$i]) && $year[$i] >= 0 && $year[$i] <= 9)){
				return false;	
			}
		}
		return true;
	}

	/**
	 *	Check if parameters is month
	 *  	@param $month - string to be checked if it's 2-digit month
	*/	
	private function isMonth($month = "")
	{
		if(!strlen($month) == 2 || !is_numeric($month)) return false;
		for($i = 0; $i < 2; $i++){
			if(!(isset($month[$i]) && $month[$i] >= 0 && $month[$i] <= 9)){
				return false;	
			}
		}
		return true;
	}

	/**
	 *	Check if parameters is day
	 *  	@param $day - string to be checked if it's 2-digit day
	*/	
	private function isDay($day = "")
	{
		if(!strlen($day) == 2 || !is_numeric($day)) return false;
		for($i = 0; $i < 2; $i++){
			if(!(isset($day[$i]) && $day[$i] >= 0 && $day[$i] <= 9)){
				return false;	
			}
		}
		return true;
	}

	/**
	 *	Convert to decimal number with leading zero
	 *  	@param $number
	*/	
	private function ConvertToDecimal($number)
	{
		return (($number < 10) ? "0" : "").$number;
	}

	/**
	 *	Convert to hour formar with leading zero
	 *  	@param $number
	*/	
	private function ConvertToHour($number)
	{
		return (($number < 10) ? "0" : "").$number.":00";
	}
	
	/**
	 *	Parse hour from hour format string
	 *  	@param $hour
	*/	
	private function ParseHour($hour)
	{
		$hour_array = explode(":", $hour);
		return (isset($hour_array[0]) ? $hour_array[0] : "0");
	}	

	/**
	 *	Get formatted microtime
	*/	
    private function GetFormattedMicrotime(){
        list($usec, $sec) = explode(' ', microtime());
        return ((float)$usec + (float)$sec);
    }

	/**
	 *	Set (allow) calendar operations
	 *		@param $operations
	*/	
	function SetOperations($operations = array())
	{
		$this->arrOpearations['add']     = isset($operations['add']) ? (bool)$operations['add'] : false;
		$this->arrOpearations['delete']  = isset($operations['delete']) ? (bool)$operations['delete'] : false;
	}

}
?>
Return current item: Basic Announce