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

include_once("class.database.php");

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

class course
{ // class : begin


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

var $id;   // KEY ATTR. WITH AUTOINCREMENT

var $course_name;   // (normal Attribute)
var $section_name;   // (normal Attribute)
var $code;   // (normal Attribute)
var $org_id;   // (normal Attribute)

var $database; // Instance of class database


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

function course()
{

$this->database = new Database();

}


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


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

function getcourse_name()
{
return $this->course_name;
}

function getsection_name()
{
return $this->section_name;
}

function getcode()
{
return $this->code;
}

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

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


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

function setcourse_name($val)
{
$this->course_name =  $val;
}

function setsection_name($val)
{
$this->section_name =  $val;
}

function setcode($val)
{
$this->code =  $val;
}

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

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

function select($id)
{
$org_id=$_SESSION['org_id'];
$sql =  "SELECT * FROM course 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_name = $row->course_name;

$this->section_name = $row->section_name;

$this->code = $row->code;

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

}





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

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

}

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

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

$sql = "INSERT INTO course ( course_name,section_name,code,org_id ) VALUES ( '$this->course_name','$this->section_name','$this->code','$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 course SET  course_name = '$this->course_name',section_name = '$this->section_name',code = '$this->code',org_id = '$this->org_id' WHERE id = $id AND  org_id = $org_id";

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



}

// **********************
// SELECT ALL
// **********************
function selectall($cond='',$limit='',$order)
{
	$sql =  "SELECT * FROM course ";
	if($cond!='')
		$sql .= " WHERE $cond ";
	
	if($order!='')
		$sql .= " ORDER BY $order ";
		
	if($limit!='')
		$sql .= " LIMIT $limit ";
	
	$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;
}

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

/*Org Select all*/
function selectorgall()
{
	$org_id=$_SESSION['org_id'];
	$sql =  "SELECT * FROM course 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*/

/*  Check course */
 function check_course($id)
	{
		$org_id=$_SESSION['org_id'];
		$sql =  "SELECT * FROM course 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 course */
	
	/*  Check course name*/
 function checkcoursename($coursename)
	{
		$org_id=$_SESSION['org_id'];
		$sql =  "SELECT * FROM course WHERE course_name = '$coursename' 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 course name*/
} // class : end

?>