<?php
class cms_circularmasterMgmt
{
	public $circular_id;
	public $branch_id;
	public $year_id;
	public $branchyear_id;
	public $semester_id;
	public $student_id;
	public $employee_id;
	public $all_student_id;
	public $all_employee_id;
	public $circular_type;
	public $circular_title;
	public $circular_subject;
	public $circular_file;
	public $circular_start_date;
	public $circular_end_date;



	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT cm.*,
		(SELECT branch_name 
				FROM cms_branchmaster sec 
				WHERE sec.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and sec.branch_id=cm.branch_id) AS branch_name,
	  		  	(SELECT year_name 
				FROM cms_yearmaster ym 
				WHERE ym.year_id=cm.year_id) AS year_name,
	  		  	(SELECT branchyear_name 
				FROM cms_branchyear bry 
				WHERE bry.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and bry.branchyear_id=cm.branchyear_id) AS branchyear_name,
	  		  	(SELECT semester_name
			   	FROM cms_semestermaster sem 
				WHERE  sem.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' AND sem.semester_id = cm.semester_id) AS semester_name	  		 	
					 FROM cms_circularmaster cm";

		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 .= "circular_id   ='" . Escape($this->circular_id) . "',";
		$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 .= "student_id   ='" . Escape($this->student_id) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$Qry1 .= "all_student_id   ='" . Escape($this->all_student_id) . "',";
		$Qry1 .= "all_employee_id   ='" . Escape($this->all_employee_id) . "',";
		$Qry1 .= "circular_active   ='" . Escape($this->circular_active) . "',";
		$Qry1 .= "circular_type   ='" . Escape($this->circular_type) . "',";
		$Qry1 .= "circular_title   ='" . Escape($this->circular_title) . "',";
		$Qry1 .= "circular_subject   ='" . Escape($this->circular_subject) . "',";
		$Qry1 .= "circular_start_date = STR_TO_DATE('" . Escape($this->circular_start_date) . "','$SQLDateFormat'),";
		$Qry1 .= "circular_end_date = STR_TO_DATE('" . Escape($this->circular_end_date) . "','$SQLDateFormat'),";
		$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_circularmaster set " . $Qry1 . " ";
			dbQuery($qry);
			$this->circular_id = dbInsertedId();
		}

	}

	function edit()
	{
		global $SQLDateFormat;

		$Qry1 = "";
		$Qry1 .= "circular_id   ='" . Escape($this->circular_id) . "',";
		$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 .= "student_id   ='" . Escape($this->student_id) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$Qry1 .= "all_student_id   ='" . Escape($this->all_student_id) . "',";
		$Qry1 .= "all_employee_id   ='" . Escape($this->all_employee_id) . "',";
		$Qry1 .= "circular_active   ='" . Escape($this->circular_active) . "',";
		$Qry1 .= "circular_type   ='" . Escape($this->circular_type) . "',";
		$Qry1 .= "circular_title   ='" . Escape($this->circular_title) . "',";
		$Qry1 .= "circular_subject   ='" . Escape($this->circular_subject) . "',";
		$Qry1 .= "circular_start_date = STR_TO_DATE('" . Escape($this->circular_start_date) . "','$SQLDateFormat'),";
		$Qry1 .= "circular_end_date = STR_TO_DATE('" . Escape($this->circular_end_date) . "','$SQLDateFormat'),";
		$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_circularmaster set " . $Qry1 . " where  circular_id=" . $this->circular_id;
			dbQuery($qry);
		}

	}


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


	function updatePhoto()
	{
		$qry = "update cms_circularmaster 
				set circular_file = '" . $this->circular_file . "'
             	where circular_id =   " . $this->circular_id . "";
		dbQuery($qry);
	}


}
?>