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

include_once("class.database.php");

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

class subjects
{ // class : begin


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

var $id;   // KEY ATTR. WITH AUTOINCREMENT

var $course_id;   // (normal Attribute)
var $batch_id;   // (normal Attribute)
var $subject;   // (normal Attribute)
var $staff;   // (normal Attribute)
var $org_id;   // (normal Attribute)

var $database; // Instance of class database


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

function subjects()
{

$this->database = new Database();

}


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


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

function getcourse_id()
{
return $this->course_id;
}

function getbatch_id()
{
return $this->batch_id;
}

function getsubject()
{
return $this->subject;
}

function getstaff()
{
return $this->staff;
}

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

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


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

function setcourse_id($val)
{
$this->course_id =  $val;
}

function setbatch_id($val)
{
$this->batch_id =  $val;
}

function setsubject($val)
{
$this->subject =  $val;
}

function setstaff($val)
{
$this->staff =  $val;
}

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

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

function select($id)
{
$org_id=$_SESSION['org_id'];
$sql =  "SELECT * FROM subjects WHERE id = $id AND  org_id = $org_id";
$result =  $this->database->query($sql);
$result = $this->database->result;
$row = mysql_fetch_object($result);


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

$this->course_id = $row->course_id;

$this->batch_id = $row->batch_id;

$this->subject = $row->subject;

$this->staff = $row->staff;

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

}





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

function delete($id)
{
	$org_id=$_SESSION['org_id'];
$sql = "DELETE FROM subjects WHERE id = $id AND org_id = $org_id;";
$result = $this->database->query($sql);

}

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

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

$sql = "INSERT INTO subjects ( course_id,batch_id,subject,staff,org_id ) VALUES ( '$this->course_id','$this->batch_id','$this->subject','$this->staff','$this->org_id' )";
$result = $this->database->query($sql);
$this->id = mysql_insert_id($this->database->link);

}

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

function update($id)
{


$org_id=$_SESSION['org_id'];
$sql = " UPDATE subjects SET  course_id = '$this->course_id',batch_id = '$this->batch_id',subject = '$this->subject',staff = '$this->staff',org_id = '$this->org_id' WHERE id = $id  AND  org_id = $org_id";

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



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

/*Org Select all*/
function selectorgall()
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM subjects 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*/
/*Org Select subjects*/
function selectsubject($batch)
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM subjects WHERE batch_id='$batch' AND org_id='$org_id' ";
	//die($sql);
	
	$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 subjects*/
/*  Check subject */
 function check_subject($id)
	{
		$org_id=$_SESSION['org_id'];
		$sql =  "SELECT * FROM subjects WHERE id = '$id' AND org_id='$org_id';";
		//die($sql);
		$result =  $this->database->query($sql);
		$result = $this->database->result;
		if($row=mysql_fetch_object($result))
		{
			return $row->id;
		}
		else 
		{
			return -1;
		}
	}
	/*  Check subject */
	
	
	
	/*  Check subject name */
 function checksubjectname($course,$batch,$subjectname)
	{
		$org_id=$_SESSION['org_id'];
		$sql =  "SELECT * FROM subjects WHERE course_id = '$course' AND batch_id = '$batch' AND subject = '$subjectname' AND org_id='$org_id';";
		//die($sql);
		$result =  $this->database->query($sql);
		$result = $this->database->result;
		if($row=mysql_fetch_object($result))
		{
			return $row->id;
		}
		else 
		{
			return -1;
		}
	}
	/*  Check subject name*/
	/*Delete Batch*/
function deletebatch($bid)
{
$org_id=$_SESSION['org_id'];
$sql = "DELETE FROM subjects WHERE org_id='$org_id' AND batch_id='$bid'";
$result = $this->database->query($sql);
}
	/*Delete Batch*/
} // class : end

?>