<?php
class SubjectMgmt
{
	public $subject_id;
	public $branch_id;
	public $semester_id;
	public $college_id;
	public $subject_name;
	public $subject_code;
	public $short_name;
	public $subject_practical;
	public $theory_hrs;
	public $tutorial_hrs;
	public $practical_hrs;
	public $subject_active;
	public $branchyear_id;
	public $year_id;


	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT * FROM cms_subjectmaster WHERE 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 getAllRecord($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT sm.*,
		(SELECT branch_name 
				FROM cms_branchmaster sec 
				WHERE sec.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id=sm.branch_id) AS branch_name,
	  		  	(SELECT year_name 
				FROM cms_yearmaster ym 
				WHERE ym.year_id=sm.year_id) AS year_name,
	  		  	(SELECT branchyear_name 
				FROM cms_branchyear bry 
				WHERE bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and bry.branchyear_id=sm.branchyear_id) AS branchyear_name,
	  		  	(SELECT semester_name
			   	 FROM cms_semestermaster sem 
			     WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = sm.semester_id) AS semester_name
			  	 FROM cms_subjectmaster sm WHERE 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 .= "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 .= "subject_name='" . Escape($this->subject_name) . "',";
		$Qry1 .= "subject_code='" . Escape($this->subject_code) . "',";
		$Qry1 .= "short_name='" . Escape($this->short_name) . "',";
		$Qry1 .= "subject_practical='" . Escape($this->subject_practical) . "',";

		$Qry1 .= "theory_hrs='" . Escape($this->theory_hrs) . "',";
		$Qry1 .= "tutorial_hrs='" . Escape($this->tutorial_hrs) . "',";
		$Qry1 .= "practical_hrs='" . Escape($this->practical_hrs) . "',";
		$Qry1 .= "subject_active='" . Escape($this->subject_active) . "',";

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

	function edit()
	{
		$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 .= "subject_name='" . Escape($this->subject_name) . "',";
		$Qry1 .= "subject_code='" . Escape($this->subject_code) . "',";
		$Qry1 .= "short_name='" . Escape($this->short_name) . "',";
		$Qry1 .= "subject_practical='" . Escape($this->subject_practical) . "',";
		$Qry1 .= "theory_hrs='" . Escape($this->theory_hrs) . "',";
		$Qry1 .= "tutorial_hrs='" . Escape($this->tutorial_hrs) . "',";
		$Qry1 .= "practical_hrs='" . Escape($this->practical_hrs) . "',";
		$Qry1 .= "subject_active='" . Escape($this->subject_active) . "',";
		$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_subjectmaster set " . $Qry1 . " where subject_id=" . $this->subject_id;
			dbQuery($qry);
		}
	}

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


	function getsubject($condition)
    {

        $qry =  "SELECT * FROM cms_subjectmaster where 1=1 ";
        if ($condition != "") {
            $qry .= $condition;
        }
//echo $qry;
        $out = dbQuery($qry);

       
        return $out;
    }

	function getworksubject($condition)
    {

        $qry =  "SELECT * FROM work_allotment_subject  ";
        if ($condition != "") {
            $qry .= $condition;
        }

        $out = dbQuery($qry);

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