<?php
class ExamscheduleMgmt
{
	public $schedule_id;
	public $branch_id;
	public $semester_id;
	public $exam_id;
	public $subject_id;
	public $college_id;
	public $year_id;
	public $daydate;
	public $daytime;
	public $test_type;
	public $login_id;
	public $createdon;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT 
						es.*,
						bm.branch_name,
						sm.semester_name,
						em.exam_name,
						sub.subject_name 
					FROM 
						cms_examschedule es,
						cms_branchmaster bm,
						cms_semestermaster sm,
						cms_exammaster em,
						cms_subjectmaster sub 
					WHERE 
						es.branch_id = bm.branch_id AND
						es.semester_id = sm.semester_id AND
						es.exam_id = em.exam_id AND
						es.subject_id = sub.subject_id  AND 
						es.college_id = " . $_SESSION['VedantnrCollegeId'];

		if ($condition != "") {
			$qry .= $condition;
		}

		if ($order_field != "" && $order_type != "") {
			$qry .= " order by $order_field $order_type";
		}

		if (intval($limit) > 0 && intval($start) >= 0) {
			$qry .= " Limit $start , $limit";
		}

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}

	function add()
	{
		global $SQLDateFormat;

		$Qry1 = "";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "exam_id='" . Escape($this->exam_id) . "',";
		$Qry1 .= "subject_id='" . Escape($this->subject_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "daydate=STR_TO_DATE('" . Escape($this->daydate) . "','$SQLDateFormat'),";
		$Qry1 .= "daytime='" . Escape($this->daytime) . "',";
		$Qry1 .= "test_type='" . Escape($this->test_type) . "',";
		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_examschedule set " . $Qry1 . " ";
			dbQuery($qry);
			$this->schedule_id = dbInsertedId();
		}
	}

	function edit()
	{
		global $SQLDateFormat;

		$Qry1 = "";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "exam_id='" . Escape($this->exam_id) . "',";
		$Qry1 .= "subject_id='" . Escape($this->subject_id) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "daydate=STR_TO_DATE('" . Escape($this->daydate) . "','$SQLDateFormat'),";
		$Qry1 .= "daytime='" . Escape($this->daytime) . "',";
		$Qry1 .= "test_type='" . Escape($this->test_type) . "',";
		$Qry1 .= "login_id='" . Escape($_SESSION['aUserId']) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update cms_examschedule set " . $Qry1 . " where schedule_id=" . $this->schedule_id;
			dbQuery($qry);
		}
	}

	function delete()
	{
		$qry = "delete from cms_examschedule where schedule_id in (" . $this->schedule_id . ") ";
		dbQuery($qry);
	}
}
?>