<?php
class ContactMgmt
{
	public $contact_id;
	public $college_id;
	public $group_name;
	public $designation;
	public $name;
	public $address;
	public $landline_no;
	public $mobile_no1;
	public $mobile_no2;
	public $email;
	public $birth_date;
	public $joining_date;
	public $bankacno;
	public $pancardno;
	public $biometriccode;
	public $busfacility;
	public $login_id;
	public $createdon;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT * FROM cms_contact sm WHERE sm.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()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "group_name='" . Escape($this->group_name) . "',";
		$Qry1 .= "designation='" . Escape($this->designation) . "',";
		$Qry1 .= "name='" . Escape($this->name) . "',";
		$Qry1 .= "address='" . Escape($this->address) . "',";
		$Qry1 .= "landline_no='" . Escape($this->landline_no) . "',";
		$Qry1 .= "mobile_no1='" . Escape($this->mobile_no1) . "',";
		$Qry1 .= "mobile_no2='" . Escape($this->mobile_no2) . "',";
		$Qry1 .= "email='" . Escape($this->email) . "',";
		$Qry1 .= "birth_date=STR_TO_DATE('" . Escape($this->birth_date) . "','$SQLDateFormat'),";
		$Qry1 .= "joining_date=STR_TO_DATE('" . Escape($this->joining_date) . "','$SQLDateFormat'),";
		$Qry1 .= "bankacno='" . Escape($this->bankacno) . "',";
		$Qry1 .= "pancardno='" . Escape($this->pancardno) . "',";
		$Qry1 .= "biometriccode='" . Escape($this->biometriccode) . "',";
		$Qry1 .= "busfacility='" . Escape($this->busfacility) . "',";
		$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_contact set " . $Qry1 . " ";
			dbQuery($qry);
			$this->contact_id = dbInsertedId();
		}
	}

	function edit()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "college_id='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "group_name='" . Escape($this->group_name) . "',";
		$Qry1 .= "designation='" . Escape($this->designation) . "',";
		$Qry1 .= "name='" . Escape($this->name) . "',";
		$Qry1 .= "address='" . Escape($this->address) . "',";
		$Qry1 .= "landline_no='" . Escape($this->landline_no) . "',";
		$Qry1 .= "mobile_no1='" . Escape($this->mobile_no1) . "',";
		$Qry1 .= "mobile_no2='" . Escape($this->mobile_no2) . "',";
		$Qry1 .= "email='" . Escape($this->email) . "',";
		$Qry1 .= "birth_date=STR_TO_DATE('" . Escape($this->birth_date) . "','$SQLDateFormat'),";
		$Qry1 .= "joining_date=STR_TO_DATE('" . Escape($this->joining_date) . "','$SQLDateFormat'),";
		$Qry1 .= "bankacno='" . Escape($this->bankacno) . "',";
		$Qry1 .= "pancardno='" . Escape($this->pancardno) . "',";
		$Qry1 .= "biometriccode='" . Escape($this->biometriccode) . "',";
		$Qry1 .= "busfacility='" . Escape($this->busfacility) . "',";
		$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_contact set " . $Qry1 . " where contact_id =" . $this->contact_id;
			dbQuery($qry);
		}
	}

	function delete()
	{
		$qry = "delete from  cms_contact 
					where contact_id in (" . $this->contact_id . ") 
					and college_id='" . $_SESSION["VedantnrCollegeId"] . "'";
		dbQuery($qry);
	}

	function getDistinctGroup()
	{
		$SQL = "SELECT DISTINCT group_name FROM cms_contact WHERE group_name != '' AND college_id= '" . $_SESSION["VedantnrCollegeId"] . "' ";
		$RES = dbQuery($SQL);
		if (dbRows($RES) > 0) {
			return $RES;
		}
		return $RES;
	}

	//report-employee-list.php
	function getemployeelist($condition)
	{
		$qry ="SELECT * FROM cms_contact WHERE college_id = ".$_SESSION["VedantnrCollegeId"];
		if ($condition != "") {
			$qry .= $condition;
		}
		
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
	function getDesignation($condition)
	{
		$qry = "SELECT * FROM cms_designation";
		if ($condition != "") {
			$qry .= $condition;
		}
		$out = dbQuery($qry);
		
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
}
?>