<?php
class SemesterMgmt
{
	public $semester_id;
	public $branch_id;
	public $college_id;
	public $semester_name;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT * FROM cms_semestermaster,cms_branchmaster  WHERE 
			cms_semestermaster.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 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "semester_name='" . Escape($this->semester_name) . "',";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "rollno_print='" . Escape($this->rollno_print) . "',";
		$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_semestermaster set " . $Qry1 . " ";
			dbQuery($qry);
			$this->branch_id = dbInsertedId();
		}
	}

	function edit()
	{
		$Qry1 = "";
		$Qry1 .= "semester_name='" . Escape($this->semester_name) . "',";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "rollno_print='" . Escape($this->rollno_print) . "',";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$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_semestermaster set " . $Qry1 . " where semester_id=" . $this->semester_id;
			dbQuery($qry);
		}
	}

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


	function getStudentSemester($semester_id)
	{

		$qry = "SELECT cur_semesterid FROM cms_studentdetail WHERE cur_semesterid= $semester_id ";

		//echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}


	function getsemester($semester_name,$semester_id,$branch_id)
	{

		$qry = "SELECT * FROM cms_semestermaster WHERE semester_name = '$semester_name' AND semester_id != $semester_id AND branch_id = '$branch_id'";
	
		//echo $qry;
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
}
?>