<?php
class DocumentMgmt
{
	public $document_id;
	public $document_name;
	public $branch_id;
	public $createdon;
	public $lodin_id;

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT dm.*, 
                   (SELECT sec.branch_name 
                             FROM cms_branchmaster sec 
                             WHERE sec.college_id = '" . $_SESSION["VedantnrCollegeId"] . "' 
                               AND sec.branch_id = dm.branch_id)
                  AS branch_name
            FROM cms_documentmaster dm";

		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 getdocumenttypeRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "";
		$qry = "SELECT branch_id FROM cms_documentmaster";


		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 adddocument()
	{
		$Qry1 = "";
		$Qry1 .= "document_name='" . Escape($this->document_name) . "',";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";

		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_documentmaster set " . $Qry1 . " ";

			dbQuery($qry);
			$this->document_id = dbInsertedId();
		}
	}

	function editdocument()
	{
		$Qry1 = "";
		$Qry1 .= "document_name='" . Escape($this->document_name) . "',";
		$Qry1 .= "branch_id='" . Escape($this->branch_id) . "',";

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

	function deletedocument()
	{
		$qry = "delete from cms_documentmaster where document_id in (" . $this->document_id . ") ";
		dbQuery($qry);
	}

}
?>