<?php
class LecMgmt
{
	public $lec_id;
	public $lec_name;

	public $time_id;
	public $start_time_name;
	public $end_time_name;

	public $room_id;
	public $room_name;
	public $marks_date;


	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT * FROM cms_lecmaster";

		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 getAllRecordssmesterallocate($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT sat.*,lc.*,
		(SELECT branch_name 
				FROM cms_branchmaster sec 
				WHERE sec.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id=sat.branch_id) AS branch_name,
	  		  	(SELECT year_name 
				FROM cms_yearmaster ym 
				WHERE ym.year_id=sat.year_id) AS year_name,
	  		  	(SELECT branchyear_name 
				FROM cms_branchyear bry 
				WHERE bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and bry.branchyear_id=sat.branchyear_id) AS branchyear_name,
	  		  	(SELECT semester_name
			   	 FROM cms_semestermaster sem 
			     WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sat.semester_id) AS semester_name 
			FROM cms_semester_allocate_time  sat,
			cms_lecmaster lc
			where lc.lec_id = sat.lec_id ";

		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 getAllRecordstime($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT tm.*,lm.* FROM cms_timemaster tm,cms_lecmaster lm where tm.lec_id=lm.lec_id";
		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 getAllRecordsroom($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT * FROM cms_roommaster";

		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";
		}

		//	echo $qry; exit;
		$out = dbQuery($qry);

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

	function add()
	{
		$Qry1 = "";
		$Qry1 .= "lec_name='" . Escape($this->lec_name) . "',";

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

	function edit()
	{
		$Qry1 = "";
		$Qry1 .= "lec_name='" . Escape($this->lec_name) . "',";

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

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


	function addtime()
	{
		$Qry1 = "";
		$Qry1 .= "time_start_name='" . Escape($this->time_start_name) . "',";
		$Qry1 .= "time_end_name='" . Escape($this->time_end_name) . "',";
		$Qry1 .= "lec_id='" . Escape($this->lec_id) . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_timemaster set " . $Qry1 . " ";
			dbQuery($qry);
			$this->time_id = dbInsertedId();
		}
	}
	function edittime()
	{
		$Qry1 = "";
		$Qry1 .= "time_start_name='" . Escape($this->time_start_name) . "',";
		$Qry1 .= "time_end_name='" . Escape($this->time_end_name) . "',";
		$Qry1 .= "lec_id='" . Escape($this->lec_id) . "',";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update cms_timemaster set " . $Qry1 . " where time_id=" . $this->time_id;
			dbQuery($qry);
		}
	}

	function deletetime()
	{
		$qry = "delete from cms_timemaster where time_id in (" . $this->time_id . ") ";
		dbQuery($qry);
	}
	function addroom()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "room_name='" . Escape($this->room_name) . "',";
		$Qry1 .= "room_no='" . Escape($this->room_no) . "',";


		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_roommaster set " . $Qry1 . " ";
			dbQuery($qry);
			$this->room_id = dbInsertedId();
		}
	}
	function editroom()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "room_name='" . Escape($this->room_name) . "',";
		$Qry1 .= "room_no='" . Escape($this->room_no) . "',";


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

	function deleteroom()
	{
		$qry = "delete from cms_roommaster where room_id in (" . $this->room_id . ") ";
		dbQuery($qry);
	}

	function adddate()
	{
		global $SQLDateFormat;
		$Qry1 = "";

		$Qry1 .= "date_name=STR_TO_DATE('" . Escape($this->date_name) . "','$SQLDateFormat'),";


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

	function editdate()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "date_name=STR_TO_DATE('" . Escape($this->date_name) . "','$SQLDateFormat'),";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update cms_marksdate set " . $Qry1 . " where date_id=" . $this->date_id;
			dbQuery($qry);
		}
	}


	function deletedate()
	{
		$qry = "delete from cms_marksdate where date_id in (" . $this->date_id . ") ";
		dbQuery($qry);
	}

	function getAllRecordsdate($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT * FROM cms_marksdate ";

		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 addsmesterallocate()
	{
		$Qry1 = "";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "lec_id='" . Escape($this->lec_id) . "',";
		$Qry1 .= "time_start_name='" . Escape($this->time_start_name) . "',";
		$Qry1 .= "time_end_name='" . Escape($this->time_end_name) . "',";

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

	}
	function editsmesterallocate()
	{
		$Qry1 = "";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id='" . Escape($this->branchyear_id) . "',";
		$Qry1 .= "semester_id='" . Escape($this->semester_id) . "',";
		$Qry1 .= "lec_id='" . Escape($this->lec_id) . "',";
		$Qry1 .= "time_start_name='" . Escape($this->time_start_name) . "',";
		$Qry1 .= "time_end_name='" . Escape($this->time_end_name) . "',";


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

	function deletesmesterallocate()
	{
		$qry = "delete from cms_semester_allocate_time where semester_allocate_time_id in (" . $this->semester_allocate_time_id . ") ";
		dbQuery($qry);
	}


	//report-syllabus-covered-result.php
	function getsyllabuscovered($condition)
	{
		$qry = "SELECT cp.*,
					(Select branch_name from cms_branchmaster where cms_branchmaster.branch_id = cp.branch_id)as branch_name,
					(Select lec_name from cms_lecmaster where cms_lecmaster.lec_id = cp.lec_id)as lec_name,
					(Select semester_name from cms_semestermaster where cms_semestermaster.semester_id = cp.semester_id)as semester_name,
					(Select year_name from cms_yearmaster where cms_yearmaster.year_id = cp.year_id)as year_name,
					(Select branchyear_name from cms_branchyear where cms_branchyear.branchyear_id = cp.branchyear_id)as branchyear_name,
					(Select batch_name from cms_batchmaster cb where cp.batch_id = cb.batch_id )as batch_name,
					(Select user_name from cms_usermaster cu where  cp.login_id = cu.user_id  )as user_name 
					FROM 
					cms_presentmaster cp 
					WHERE cp.college_id = " . $_SESSION["VedantnrCollegeId"];
		if ($condition != "") {
			$qry .= $condition;
		}

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

}
?>