<?php
/*
*
* -------------------------------------------------------
* CLASSNAME:        event
* GENERATION DATE:  21.02.2014
* FOR MYSQL TABLE:  event
* FOR MYSQL DB:     web-school
* -------------------------------------------------------
* CODE GENERATED BY:
* PHP-MYSQL-CLASS GENERATOR
* -------------------------------------------------------
*
*/

include_once("class.database.php");

// **********************
// CLASS DECLARATION
// **********************

class event
{ // class : begin


// **********************
// ATTRIBUTE DECLARATION
// **********************

var $id;   // KEY ATTR. WITH AUTOINCREMENT

var $start_date;   // (normal Attribute)
var $end_date;   // (normal Attribute)
var $title;   // (normal Attribute)
var $description;   // (normal Attribute)
var $holiday;   // (normal Attribute)
var $common;   // (normal Attribute)
var $batch;   // (normal Attribute)
var $department;   // (normal Attribute)
var $event_key;   // (normal Attribute)
var $org_id;   // (normal Attribute)

var $database; // Instance of class database


// **********************
// CONSTRUCTOR METHOD
// **********************

function event()
{

$this->database = new Database();

}


// **********************
// GETTER METHODS
// **********************


function getid()
{
return $this->id;
}

function getstart_date()
{
return $this->start_date;
}

function getend_date()
{
return $this->end_date;
}

function gettitle()
{
return $this->title;
}

function getdescription()
{
return $this->description;
}

function getholiday()
{
return $this->holiday;
}

function getcommon()
{
return $this->common;
}

function getbatch()
{
return $this->batch;
}

function getdepartment()
{
return $this->department;
}

function getevent_key()
{
return $this->event_key;
}

function getorg_id()
{
return $this->org_id;
}

// **********************
// SETTER METHODS
// **********************


function setid($val)
{
$this->id =  $val;
}

function setstart_date($val)
{
$this->start_date =  $val;
}

function setend_date($val)
{
$this->end_date =  $val;
}

function settitle($val)
{
$this->title =  $val;
}

function setdescription($val)
{
$this->description =  $val;
}

function setholiday($val)
{
$this->holiday =  $val;
}

function setcommon($val)
{
$this->common =  $val;
}

function setbatch($val)
{
$this->batch =  $val;
}

function setdepartment($val)
{
$this->department =  $val;
}

function setevent_key($val)
{
$this->event_key =  $val;
}

function setorg_id($val)
{
$this->org_id =  $val;
}

// **********************
// SELECT METHOD / LOAD
// **********************

function select($id)
{

$sql =  "SELECT * FROM event WHERE id = $id;";
$result =  $this->database->query($sql);
$result = $this->database->result;
$row = mysql_fetch_object($result);


$this->id = $row->id;

$this->start_date = $row->start_date;

$this->end_date = $row->end_date;

$this->title = $row->title;

$this->description = $row->description;

$this->holiday = $row->holiday;

$this->common = $row->common;

$this->batch = $row->batch;

$this->department = $row->department;

$this->event_key = $row->event_key;

$this->org_id = $row->org_id;

}





// **********************
// DELETE
// **********************

function delete($id)
{
$sql = "DELETE FROM event WHERE id = $id;";
$result = $this->database->query($sql);

}

// **********************
// INSERT
// **********************

function insert()
{
$this->id = ""; // clear key for autoincrement

$sql = "INSERT INTO event ( start_date,end_date,title,description,holiday,common,batch,department,event_key,org_id ) VALUES ( '$this->start_date','$this->end_date','$this->title','$this->description','$this->holiday','$this->common','$this->batch','$this->department','$this->event_key','$this->org_id' )";
$result = $this->database->query($sql);
$this->id = mysql_insert_id($this->database->link);

}

// **********************
// UPDATE
// **********************

function update($id)
{



$sql = " UPDATE event SET  start_date = '$this->start_date',end_date = '$this->end_date',title = '$this->title',description = '$this->description',holiday = '$this->holiday',common = '$this->common',batch = '$this->batch',department = '$this->department',event_key = '$this->event_key',org_id = '$this->org_id' WHERE id = $id ";

$result = $this->database->query($sql);



}

// **********************
// CUSTOM METHOD / LOAD
// **********************

/*Org Select all*/
function selectorgall()
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM event WHERE org_id='$org_id' ";
	$result =  $this->database->query($sql);
	$result = $this->database->result;
	$this->rows=array();
	while($row=mysql_fetch_object($result))
	{
	$this->rows[] = $row;
	}
	return $this->rows;
}
/*Org Select all*/

/*Unique event Select */
function selectorgunique()
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT DISTINCT(event_key),title,start_date,end_date FROM event WHERE org_id='$org_id' ";
	$result =  $this->database->query($sql);
	$result = $this->database->result;
	$this->rows=array();
	while($row=mysql_fetch_object($result))
	{
	$this->rows[] = $row;
	}
	return $this->rows;
}
/*Unique event Select*/

/*Unique event key Select */
function selecteventkey()
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT MAX(id) as id FROM event WHERE org_id='$org_id' ";
	$result =  $this->database->query($sql);
	$result = $this->database->result;
	$row = mysql_fetch_object($result);
	$this->id = $row->id;
		
}
/*Unique event key Select*/
/*Org Select holiday*/
function selectholiday($dept,$leavedate)
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM event WHERE org_id='$org_id' AND (department='-1' OR  department='$dept') AND holiday=1 AND ( '$leavedate'>=start_date AND '$leavedate'<=end_date )";
	//die($sql);
	$result =  $this->database->query($sql);
		$result = $this->database->result;
		if($row=mysql_fetch_object($result))
		{
			return $row->id;
		}
		else 
		{
			return -1;
		}
}
/*Org Select holiday*/

/*Org Select batch holiday*/
function selectstdholiday($batchid,$leavedate)
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM event WHERE org_id='$org_id' AND ( batch='-1' OR  batch='$batchid' ) AND holiday=1 AND ( '$leavedate'>=start_date AND '$leavedate'<=end_date ) ";
	//die($sql);
	   $result =  $this->database->query($sql);
		$result = $this->database->result;
		if($row=mysql_fetch_object($result))
		{
			return $row->id;
		}
		else 
		{
			return -1;
		}
	}
/*Org Select holiday*/

/*Org Select same event entry*/
function selectsameevent($startdate,$enddate,$title)
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM event WHERE org_id='$org_id' AND start_date='$startdate' AND end_date='$enddate' AND title='$title' ";
	//die($sql);
	   $result =  $this->database->query($sql);
		$result = $this->database->result;
		if($row=mysql_fetch_object($result))
		{
			return $row->id;
		}
		else 
		{
			return -1;
		}
	}
/*Org Select same event entry*/


	/*Delete Batch*/
function deletebatch($bid)
{
$org_id=$_SESSION['org_id'];
$sql = "DELETE FROM event WHERE org_id='$org_id' AND batch='$bid'";
$result = $this->database->query($sql);
}
	/*Delete Batch*/
	
	
} // class : end

?>