		<?php
		/**
		*@author  Xu Ding
		*@email   thedilab@gmail.com
		*@website http://www.StarTutorial.com
		**/
		class Calendar {  

		/**
		* Constructor
		*/
		public function __construct(){     
		$this->naviHref = htmlentities($_SERVER['PHP_SELF']);
		}

		/********************* PROPERTY ********************/  
		private $dayLabels = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");

		private $currentYear=0;

		private $currentMonth=0;

		private $previousmnth=0;

		private $currentDate=null;

		private $daysInMonth=0;


		private $previousyear=0;

		private $nxt_year = null;

		private $nxtmnth = 0;

		Private $userID ;

		Private $image = null ; 

		/********************* PUBLIC **********************/  

		/**
		* print out the calendar
		*/
		/********************* Setter Function **********************/  
		function setcrntyear($year)
		{
		if($year!='')
		{
		$this->currentYear = $year;
		}
		}

		function setcrntmnth($mnth)
		{
		if($mnth!='')
		{
		$this->currentMonth = $mnth;
		}
		}

		function setnxtyear($nextyear)
		{
		if($nextyear!='')
		{
		$this->nxt_year = $nextyear;
		}
		}

		function setprevyear($prevyear)
		{
		if($prevyear!='')
		{
		$this->previousyear = $prevyear;
		}
		}

		function setnxtmnth($nextmnth)
		{
		if($nextmnth!='')
		{
		$this->nxtmnth = $nextmnth;
		}
		}

		function setprevmnth($prevmnth)
		{
		if($prevmnth!='')
		{
		$this->previousmnth = $prevmnth;
		}
		}

		function setimage($imageid)
		{
		if($imageid!='')
		{
		$this->image =$imageid;
		}
		}


		/********************* Getter Function **********************/ 

		function getcrntyear()
		{
		if($this->currentYear!='')
		{
		return $this->currentYear ;
		}

		}

		function getcrntmnth()
		{
		if($this->currentMonth!='')
		{
		return $this->currentMonth ;
		}

		} 
		function getnxtyear()
		{
		if($this->nxt_year!='')
		{
		return $this->nxt_year ;
		}

		}

		function getprevyear()
		{
		if($this->previousyear!='')
		{
		return $this->previousyear ;
		}

		}

		function getnxtmnths()
		{
		if($this->nxtmnth!='')
		{
		return $this->nxtmnth ;
		}

		}

		function getpreviousmnth()
		{
		if($this->previousmnth!='')
		{
		return $this->previousmnth ;
		}

		}
		function getimage()
		{
		if($this->image!='')
		{
		return $this->image ;
		}

		}





		/**
		* create the li element for ul
		*/
		public function _showDay()
		{

		if($this->currentDay==0){

		$firstDayOfTheWeek = date('N',strtotime($this->currentYear.'-'.$this->currentMonth.'-01'));

		if(intval($cellNumber) == intval($firstDayOfTheWeek)){

		$this->currentDay=1;

		}
		}

		if( ($this->currentDay!=0)&&($this->currentDay<=$this->daysInMonth) ){

		$this->currentDate = date('Y-m-d',strtotime($this->currentYear.'-'.$this->currentMonth.'-'.($this->currentDay)));

		$cellContent = $this->currentDay;

		$this->currentDay++;   

		}else{

		$this->currentDate =null;

		$cellContent=null;
		}
		return '<li id="li-'.$this->currentDate.'" class="'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
		($cellContent==null?'mask':'').'">'.$cellContent.'</li>';
		}

		/**
		* create navigation
		*/


		/**
		* create calendar week labels
		*/
		public function mnth_trsform($mnt)
		{
		$month_eng = null;
		$month = $mnt;
		if($month == "1")
		{
		$month_eng = "January";
		}
		else
		if($month == "2")
		{
		$month_eng = "February";
		}
		else
		if($month == "3")
		{
		$month_eng = "March";
		}
		else
		if($month == "4")
		{
		$month_eng = "April";
		}
		else
		if($month == "5")
		{
		$month_eng = "May";
		}
		else
		if($month == "6")
		{
		$month_eng = "June";
		}
		else
		if($month == "7")
		{
		$month_eng = "	July";
		}
		else
		if($month == "8")
		{
		$month_eng = "August";
		}
		else
		if($month == "9")
		{
		$month_eng = "September";
		}
		else
		if($month == "10")
		{
		$month_eng = "October";
		}
		else
		if($month == "11")
		{
		$month_eng = "November";
		}
		else
		if($month == "12")
		{
		$month_eng = "December";
		}	

		return 	$month_eng ;

		}


		public function current_Date($mnth,$year)
		{

		$hotelObClnder = new Calendar;


		$hotelObClnder->setcrntyear($year ) ;
		$hotelObClnder->setcrntmnth($mnth) ; // $currentMonth = $mnth;
		$hotelObClnder->setprevyear($year);
		$hotelObClnder->setprevmnth($mnth-1);
		$hotelObClnder->setnxtmnth($mnth+1);
		$hotelObClnder->setnxtyear($year);
		$previousmnth = $hotelObClnder->getpreviousmnth()  ; 
		//echo "Previous Month".$previousmnth;
		$nextmnth = $hotelObClnder->getnxtmnths()   ;
		//echo "NxtMonth".$nextmnth;
		$nxt_year = $hotelObClnder->getnxtyear()    ;
		$prev_year = $hotelObClnder->getprevyear();
		//echo "PYear".$prev_year;
		$crntyear = $hotelObClnder->getcrntyear();
		$crntmnth = $hotelObClnder->getcrntmnth();
		//echo "cyear".$crntyear;



		if($previousmnth == 0) 
		{
		$hotelObClnder->setprevmnth("12"); 	//$previousmnth = 12 ;
		$hotelObClnder->setprevyear($crntyear-1 ); //$prev_year = $year-1;

		}
		if($nextmnth == 13 )
		{
		$hotelObClnder->setnxtmnth(1); //$nxtmnth = 1 ;
		$hotelObClnder->setnxtyear($crntyear+1); //$nxt_year = $year+1;
		}
		}

		/**
		* calculate number of weeks in a particular month
		*/
		public function _weeksInMonth($month=null,$year=null)
		{

		if( null==($year) ) {
		$year =  date("Y",time()); 
		}

		if(null==($month)) {
		$month = date("m",time());
		}

		// find number of days in this month
		$daysInMonths = $this->_daysInMonth($month,$year);

		$numOfweeks = ($daysInMonths%7==0?0:1) + intval($daysInMonths/7);

		$monthEndingDay= date('N',strtotime($year.'-'.$month.'-'.$daysInMonths));

		$monthStartDay = date('N',strtotime($year.'-'.$month.'-01'));

		if($monthEndingDay<$monthStartDay){

		$numOfweeks++;

		}

		return $numOfweeks;
		}

		public function checkStatusRoomType($date,$type,$hotel_id)
		{

		$query = "SELECT hotel_Id,Date_Check,Room_Type FROM  hotel_type_status_check WHERE hotel_id = '$hotel_id' AND Date_Check='$date' AND Room_Type='$type'";
		$queryOb = new classQueryGlobal;
		$array['checkVerificationCode'] =  $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");	
		if(count($array['checkVerificationCode']) == 0)
		{
		$this->InsertStatusRoomType($date,$type,$hotel_id);
		}
		else
		{
		}
		}

		public function InsertStatusRoomType($date,$type,$hotel_id)
		{
		//  echo "at insert";

		echo $date;
		// echo $type;
		// echo $hotel_id;
		$status = "not_available";


		$query = "SELECT * FROM  hotel_type_status_check WHERE hotel_id = '$hotel_id' AND Date_Check='$date' AND Room_Type='$type'";
		$queryOb = new classQueryGlobal;
		$array['checkStatus'] =  $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(count($array['checkStatus']) != 0 )
		{
		echo "Record Already Exist in database . </BR> Now Room Type Available .";
		$query3 = "DELETE FROM hotel_type_status_check WHERE hotel_id = '$hotel_id' AND Date_Check='$date' AND Room_Type='$type'";
		$queryOb = new classQueryGlobal;
		$queryOb->check_fetch_query($query3,'delete',$server="",$debug_mode="off");
		$path = $this->getStatus($date,$type,$hotel_id);
		// echo  "here Path".$path;
		$this->setimage($path);
		}
		else
		{
		$query="INSERT INTO hotel_type_status_check 
		(
		hotel_Id,
		Date_Check,
		Room_Type,
		Status
		) 
		VALUES 
		(
		'$hotel_id',
		'$date',
		'$type',
		'$status'

		)";

		$queryOb = new classQueryGlobal;
		$this->userID= $queryOb->check_fetch_query($query,'insert',$server="",$debug_mode="off");
		$path = $this->getStatus(strtotime($date),$type,$hotel_id);
		//echo  "here Path".$path;
		//$this->setimage($path);

		echo "Record Inserted into database . </BR> Status updated : Non-Available ";
		}
		}

		public function getStatus($date,$type,$hotel_id)
		{

		//echo $date;
		$query = "SELECT Status FROM  hotel_type_status_check WHERE hotel_id = '$hotel_id' AND Date_Check= '$date' AND Room_Type='$type'";
		$queryOb = new classQueryGlobal;
		$room_status = $queryOb->check_fetch_query($query,'select',$server="",$debug_mode="off");
		if(count($room_status) == 0)
		{
		return $img_src = "../images/empty.jpg";
		}
		else
		{
		if(isset($room_status[0]['Status']))
		{
		$status = $room_status[0]['Status'];

		if($status == "not_available")
		{
		return $img_src = "../images/cross.jpg";	
		}
		}
		}

		}

		/**
		* calculate number of days in a particular month
		*/
		public function daysInMonth($month=NULL,$year=NULL)
		{

		if(null==($year))
		$year =  date("Y",time()); 

		if(null==($month))
		$month = date("m",time());

		return date('t',strtotime($year.'-'.$month.'-01'));
		}

		}