<?php

/**
 * This is a class file used for Student Cast Certificate.
 *
 * PHP version 5
 *
 * @category Admin_Tool
 * @package  Admin_Tool
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  CVS:1.0.1
 * @link     http://auminfosys.com/
 * @filesource
 */

/**
 * This is a class named CastCetificate.
 *
 * @category School Management System
 * @package  School Management System
 * @author   Aum Infosys <admin@auminfosys.com>
 * @license  Aum Infosys
 * @version  Release: 1.0.1
 * @link     http://auminfosys.com/
 *
 */

class cumrelivingCertificateMgmt
{
	public $cumrelivingcertificate_id;

	public $branch_id;

	public $year_id;
	public $branchyear_id;
	public $semester_id;
	public $certificate_no;
	public $student_id;
	public $student_gturegno;
	public $college_id;
	public $createdon;


	function add()
	{

		global $SQLDateFormat;
		if (duplicateForeign("cms_cumrelivingcertificate", "student_gturegno", "college_id,branch_id,student_gturegno", $this->college_id . "," . $this->branch_id . "," . $this->student_gturegno)) {
			$this->cumrelivingcertificate_id = 0;
		} else {

			$Qry1 = "";

			$Qry1 .= "cumrelivingcertificate_id='" . Escape($this->cumrelivingcertificate_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 .= "certificate_no='" . Escape($this->certificate_no) . "',";
			$Qry1 .= "student_id='" . Escape($this->student_id) . "',";
			$Qry1 .= "student_gturegno='" . Escape($this->student_gturegno) . "',";
			$Qry1 .= "college_id='" . Escape($this->college_id) . "',";
			$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";

			if ($Qry1 != "") {
				$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
				$qry = "insert into cms_cumrelivingcertificate set " . $Qry1 . " ";
				 //echo $qry;
				//	exit();
				dbQuery($qry);
				$this->cumrelivingcertificate_id = dbInsertedId();
			}
		}
	}

	function edit()
	{
		global $SQLDateFormat;
		$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 .= "certificate_no='" . Escape($this->certificate_no) . "',";
		$Qry1 .= "student_id='" . Escape($this->student_id) . "',";
		$Qry1 .= "student_gturegno='" . Escape($this->student_gturegno) . "',";
		$Qry1 .= "createdon='" . Escape(date('Y-m-d h:i:s')) . "',";
		$Qry1 .= "college_id='" . Escape($this->college_id) . "',";

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

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

	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->student_count = 0;
		$qry = "SELECT 
					 cm.*,sd.*,sm.*,
					 Concat(sm.student_surname,' ',sm.student_firstname,' ',sm.student_lastname) AS student_name,
					 (SELECT branch_name 
					 FROM cms_branchmaster cbm
					 WHERE cbm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and  cbm.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 bym
					 WHERE bym.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and  bym.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_cumrelivingcertificate cm,
					 cms_studentmaster sm,
					 cms_studentdetail sd
				 WHERE 									  
					 sm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and 
					 cm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and 
					 sm.student_id  = cm.student_id and 
					 sm.student_id  = sd.student_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) {
			$this->student_count = dbRows($out);
			return $out;
		}
		return $out;
	}

	function getCountRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$this->student_count = 0;

		$qry = "SELECT
	   			Count(*) AS Count
		     FROM 
			 	cms_cumrelivingcertificate cm,
				cms_studentmaster sm,
				cms_studentdetail sd
			 WHERE		 					
				sm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and 
				cm.college_id   = '" . $_SESSION["VedantnrCollegeId"] . "' and
				sm.student_id  = cm.student_id and										
				sm.student_id  = sd.student_id and
				cm.branch_id  = sm.branch_id ";

		if ($condition != "") {
			$qry .= $condition;
		}

		$out = dbQuery($qry);

		if (dbRows($out) > 0) {
			$row = dbArray($out);
			extract($row);
			$this->student_count = $Count;
			dbResult($out);
		}
		return $this->student_count;
	}

	function getMaxRecordNumber($bid)
	{
		$qry = "SELECT MAX(certificate_no) as mxcerti 
		        FROM cms_cumrelivingcertificate 
				where college_id='" . $_SESSION["VedantnrCollegeId"] . "' ";

		$condition = " AND branch_id = '$bid' ";

		if ($condition != "") {
			$qry .= $condition;
		}
		$out = dbQuery($qry);
		$result = dbArray($out);
		$num = $result['mxcerti'];
		$num = $num + 1;
		return $num;
	}

}
?>