<?php
class ExamsetupMgmt
{
	public $setup_id;
	public $branch_id;
	public $semester_id;
	public $exam_id;
	public $subject_id;
	public $college_id;
	public $year_id;
	public $total_marks;
	public $passing_mark;
	public $total_marks_pr;
	public $passing_mark_pr;

	public $total_marks_pr_ese;
	public $passing_mark_pr_ese;
	public $total_marks_pr_pa;
	public $passing_mark_pr_pa;

	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_examsetup 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()
	{
		$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 .= "total_marks='" . Escape($this->total_marks) . "',";
		$Qry1 .= "passing_marks='" . Escape($this->passing_marks) . "',";

		$Qry1 .= "total_marks_pr='" . Escape($this->total_marks_pr) . "',";
		$Qry1 .= "passing_marks_pr='" . Escape($this->passing_marks_pr) . "',";

		$Qry1 .= "total_marks_pr_ese='" . Escape($this->total_marks_pr_ese) . "',";
		$Qry1 .= "passing_marks_pr_ese='" . Escape($this->passing_marks_pr_ese) . "',";
		$Qry1 .= "total_marks_pr_pa='" . Escape($this->total_marks_pr_pa) . "',";
		$Qry1 .= "passing_marks_pr_pa='" . Escape($this->passing_marks_pr_pa) . "',";

		$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_examsetup set " . $Qry1 . " ";
			dbQuery($qry);
			$this->setup_id = dbInsertedId();
		}
	}

	function edit()
	{
		$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 .= "total_marks='" . Escape($this->total_marks) . "',";
		$Qry1 .= "passing_marks='" . Escape($this->passing_marks) . "',";

		$Qry1 .= "total_marks_pr='" . Escape($this->total_marks_pr) . "',";
		$Qry1 .= "passing_marks_pr='" . Escape($this->passing_marks_pr) . "',";

		$Qry1 .= "total_marks_pr_ese='" . Escape($this->total_marks_pr_ese) . "',";
		$Qry1 .= "passing_marks_pr_ese='" . Escape($this->passing_marks_pr_ese) . "',";
		$Qry1 .= "total_marks_pr_pa='" . Escape($this->total_marks_pr_pa) . "',";
		$Qry1 .= "passing_marks_pr_pa='" . Escape($this->passing_marks_pr_pa) . "',";

		$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_examsetup set " . $Qry1 . " where setup_id=" . $this->setup_id;
			dbQuery($qry);
		}
	}

	function delete()
	{
		$qry = "delete from cms_examsetup where setup_id in (" . $this->setup_id . ") ";
		dbQuery($qry);
	}

	function getexamsetup($condition)
	{

		$qry ="SELECT * FROM cms_examsetup WHERE 1=1";
		
		if ($condition != "") {
			$qry .= $condition;
		}
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
}
?>