<?php
class UploadfilesMgmt
{
	public $upload_file_id;
	public $upload_id;
	public $title;
	public $active;
	public $login_id;
	public $createdon;
	public $file_name;
	public $assignment_date;
	public $submission_date;


	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT up.branch_id,up.semester_id,up.subject_id,up.title as upload_title,up.description,cuf.*,cuf.title,
				 branch_name,
				 semester_name,
				 subject_name
				FROM 
					cms_upload up,
					cms_semestermaster sem,
					cms_branchmaster branch,
					cms_subjectmaster sub,
                    cms_upload_files cuf
				WHERE 
				branch.branch_id = up.branch_id
				AND sem.semester_id=up.semester_id 
				AND sub.subject_id=up.subject_id 
                AND up.upload_id = cuf.upload_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";
		}
		//echo $qry;

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

	}


	function add()
	{

		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "upload_file_id   ='" . Escape($this->upload_file_id) . "',";
		$Qry1 .= "upload_id   ='" . Escape($this->upload_id) . "',";
		$Qry1 .= "title   ='" . Escape($this->title) . "',";
		$Qry1 .= "active   ='" . Escape($this->active) . "',";
		$Qry1 .= "assignment_date = STR_TO_DATE('" . Escape($this->assignment_date) . "','$SQLDateFormat'),";
		$Qry1 .= "submission_date = STR_TO_DATE('" . Escape($this->submission_date) . "','$SQLDateFormat'),";
		$Qry1 .= "login_id   ='" . Escape($_SESSION["VedantnrUserId"]) . "',";
		$Qry1 .= "createdon   ='" . Escape(date('Y-m-d h:i:s')) . "',";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "insert into cms_upload_files set " . $Qry1 . " ";
			dbQuery($qry);
			$this->upload_file_id = dbInsertedId();
		}

	}

	function edit()
	{
		global $SQLDateFormat;
		$Qry1 = "";
		$Qry1 .= "upload_file_id   ='" . Escape($this->upload_file_id) . "',";
		$Qry1 .= "upload_id   ='" . Escape($this->upload_id) . "',";
		$Qry1 .= "title   ='" . Escape($this->title) . "',";
		$Qry1 .= "active   ='" . Escape($this->active) . "',";
		$Qry1 .= "assignment_date = STR_TO_DATE('" . Escape($this->assignment_date) . "','$SQLDateFormat'),";
		$Qry1 .= "submission_date = STR_TO_DATE('" . Escape($this->submission_date) . "','$SQLDateFormat'),";
		$Qry1 .= "login_id   ='" . Escape($_SESSION["VedantnrUserId"]) . "',";
		$Qry1 .= "createdon   ='" . Escape(date('Y-m-d h:i:s')) . "',";

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

	}


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


	function updatefile()
	{
		$qry = "update cms_upload_files 
				set file_name = '" . $this->file_name . "'
             	where upload_file_id =   '" . $this->upload_file_id . "' ";

		dbQuery($qry);
	}


}

?>