<?php
class cms_subject_allocationMgmt
{
	public $subject_allocation_id;
	public $college_id;
	public $branch_id;
	public $semester_id;
	public $div_id;
	public $batch_id;
	public $subject_id;
	public $year_id;
	public $lectype;
	public $shift;
	public $employee_id;
	public $login_id;
	public $createdon;


	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT sa.*,
(Select branch_name from cms_branchmaster where cms_branchmaster.branch_id = sa.branch_id)as branch_name,
(Select year_name from cms_yearmaster where cms_yearmaster.year_id = sa.year_id)as year_name,
(Select branchyear_name from cms_branchyear where cms_branchyear.branchyear_id = sa.branchyear_id)as branchyear_name,
(Select lectype_name from cms_lectype where cms_lectype.lectype_id = sa.lectype)as lectype_name,
(Select semester_name from cms_semestermaster where cms_semestermaster.semester_id = sa.semester_id)as semester_name,
(Select batch_name from cms_batchmaster where cms_batchmaster.batch_id = sa.batch_id)as batch_name,
(Select subject_name from cms_subjectmaster where cms_subjectmaster.subject_id = sa.subject_id)as subject_name,
(Select employee_name from cms_employeemaster where cms_employeemaster.employee_id = sa.employee_id)as employee_name
 FROM cms_subject_allocation as sa where 1=1 ";

		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; exit; 
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
	function getAllRecords1($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT sa.*,
(Select branch_name from cms_branchmaster where cms_branchmaster.branch_id = sa.branch_id)as branch_name,
(Select year_name from cms_yearmaster where cms_yearmaster.year_id = sa.year_id)as year_name,
(Select branchyear_name from cms_branchyear where cms_branchyear.branchyear_id = sa.branchyear_id)as branchyear_name,
(Select lectype_name from cms_lectype where cms_lectype.lectype_id = sa.lectype)as lectype_name,
(Select semester_name from cms_semestermaster where cms_semestermaster.semester_id = sa.semester_id)as semester_name,
(Select time_start_name from cms_timemaster where cms_timemaster.time_id = sa.time_id)as time_name,
(Select time_end_name from cms_timemaster where cms_timemaster.time_id = sa.time_id)as time_name1,
(Select subject_name from cms_subjectmaster where cms_subjectmaster.subject_id = sa.subject_id)as subject_name,
(Select employee_name from cms_employeemaster where cms_employeemaster.employee_id = sa.employee_id)as employee_name,
(Select room_name from cms_roommaster where cms_roommaster.room_id = sa.room_id)as room_name,
(Select room_no from cms_roommaster where cms_roommaster.room_id = sa.room_id)as room_name1,
(Select subject_code from cms_subjectmaster where cms_subjectmaster.subject_id = sa.subject_id)as subject_name1,
(Select lec_name from cms_lecmaster where cms_lecmaster.lec_id = sa.lec_id)as lec_name
 FROM work_allotment_subject as sa where 1=1 ";

		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()
	{
		$Qry1 = "";
		$Qry1 .= "subject_allocation_id   ='" . Escape($this->subject_allocation_id) . "',";
		$Qry1 .= "college_id   ='" . Escape($this->college_id) . "',";
		$Qry1 .= "branch_id   ='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id   ='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id   ='" . Escape($this->branchyear_id) . "',";
		//$Qry1 .= "room_id   ='"  .Escape($this->room_id)."',";
		$Qry1 .= "semester_id   ='" . Escape($this->semester_id) . "',";
		$Qry1 .= "div_id   ='" . Escape($this->div_id) . "',";
		$Qry1 .= "batch_id   ='" . Escape($this->batch_id) . "',";
		$Qry1 .= "subject_id   ='" . Escape($this->subject_id) . "',";
	
		$Qry1 .= "lectype   ='" . Escape($this->lectype) . "',";
		$Qry1 .= "shift   ='" . Escape($this->shift) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$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_subject_allocation set " . $Qry1 . " ";
			dbQuery($qry);
			$this->subject_allocation_id = dbInsertedId();
		}

	}

	function edit()
	{
		$Qry1 = "";
		$Qry1 .= "subject_allocation_id   ='" . Escape($this->subject_allocation_id) . "',";
		$Qry1 .= "college_id   ='" . Escape($this->college_id) . "',";
		$Qry1 .= "branch_id   ='" . Escape($this->branch_id) . "',";
		$Qry1 .= "year_id   ='" . Escape($this->year_id) . "',";
		$Qry1 .= "branchyear_id   ='" . Escape($this->branchyear_id) . "',";
		//$Qry1 .= "room_id   ='"  .Escape($this->room_id)."',";
		$Qry1 .= "semester_id   ='" . Escape($this->semester_id) . "',";
		$Qry1 .= "div_id   ='" . Escape($this->div_id) . "',";
		$Qry1 .= "batch_id   ='" . Escape($this->batch_id) . "',";
		$Qry1 .= "subject_id   ='" . Escape($this->subject_id) . "',";
		$Qry1 .= "lectype   ='" . Escape($this->lectype) . "',";
		$Qry1 .= "shift   ='" . Escape($this->shift) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$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_subject_allocation set " . $Qry1 . " where  subject_allocation_id=" . $this->subject_allocation_id;
			dbQuery($qry);
		}

	}


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

	function add_work()
	{
		$Qry1 = "";
		$Qry1 .= "work_allotment_subject_id   ='" . Escape($this->work_allotment_subject_id) . "',";
		//$Qry1 .= "college_id   ='"  .Escape($this->college_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 .= "room_id   ='" . Escape($this->room_id) . "',";
		$Qry1 .= "div_id   ='" . Escape($this->div_id) . "',";
		$Qry1 .= "time_id   ='" . Escape($this->time_id) . "',";
		$Qry1 .= "subject_id   ='" . Escape($this->subject_id) . "',";
	
		$Qry1 .= "lectype   ='" . Escape($this->lectype) . "',";
		$Qry1 .= "day_name   ='" . Escape($this->day_name) . "',";
		$Qry1 .= "lec_id   ='" . Escape($this->lec_id) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$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 work_allotment_subject set " . $Qry1 . " ";

			//echo $qry; exit; 
			dbQuery($qry);
			$this->work_allotment_subject_id = dbInsertedId();
		}

	}
	function edit_work()
	{
		$Qry1 = "";
		$Qry1 .= "work_allotment_subject_id   ='" . Escape($this->work_allotment_subject_id) . "',";
		//$Qry1 .= "college_id   ='"  .Escape($this->college_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 .= "div_id   ='" . Escape($this->div_id) . "',";
		$Qry1 .= "room_id   ='" . Escape($this->room_id) . "',";
		$Qry1 .= "time_id   ='" . Escape($this->time_id) . "',";
		$Qry1 .= "subject_id   ='" . Escape($this->subject_id) . "',";
		$Qry1 .= "lec_id   ='" . Escape($this->lec_id) . "',";
		$Qry1 .= "lectype   ='" . Escape($this->lectype) . "',";
		$Qry1 .= "day_name   ='" . Escape($this->day_name) . "',";
		$Qry1 .= "employee_id   ='" . Escape($this->employee_id) . "',";
		$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 work_allotment_subject set " . $Qry1 . " where  work_allotment_subject_id=" . $this->work_allotment_subject_id;

			//echo $Qry1; exit;
			dbQuery($qry);
		}

	}

	function delete_work()
	{
		$qry = "delete from work_allotment_subject where work_allotment_subject_id in (" . $this->work_allotment_subject_id . ") ";
		dbQuery($qry);
	}


	//get-subject.php
	function getsubjectallocation($condition)
	{
		$qry ="select GROUP_CONCAT(subject_id) as subject_id 
		from cms_subject_allocation where 1=1";

		if ($condition != "") {
			$qry .= $condition;
		}
		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}


	//pendding feedback.php
	
function getemployeesub($condition)
{
	$qry = "SELECT 
						alo.subject_id,
						alo.employee_id,
						sub.short_name,
						sub.subject_code,
						emp.employee_name
					FROM 
						 `cms_subjectmaster` sub,
						 `cms_employeemaster` emp,
						 `cms_subject_allocation` alo
					WHERE 
					alo.employee_id = emp.employee_id 
					AND alo.lectype=1
					AND alo.subject_id = sub.subject_id 
					AND emp.employee_active = 'YES' ";
	if ($condition != "") {
		$qry .= $condition;
	}


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




}
/* Code For EXTJS START \n{
xtype: 'textfield',
name: 'subject_allocation_id',
id:'subject_allocation_id',
allowBlank:false,
tabIndex:1,
labelSeparator:'',
fieldLabel :'subject_allocation_id:',
width:100
},
{
xtype: 'textfield',
name: 'college_id',
id:'college_id',
allowBlank:false,
tabIndex:2,
labelSeparator:'',
fieldLabel :'college_id:',
width:100
},
{
xtype: 'textfield',
name: 'branch_id',
id:'branch_id',
allowBlank:false,
tabIndex:3,
labelSeparator:'',
fieldLabel :'branch_id:',
width:100
},
{
xtype: 'textfield',
name: 'semester_id',
id:'semester_id',
allowBlank:false,
tabIndex:4,
labelSeparator:'',
fieldLabel :'semester_id:',
width:100
},
{
xtype: 'textfield',
name: 'div_id',
id:'div_id',
allowBlank:false,
tabIndex:5,
labelSeparator:'',
fieldLabel :'div_id:',
width:100
},
{
xtype: 'textfield',
name: 'batch_id',
id:'batch_id',
allowBlank:false,
tabIndex:6,
labelSeparator:'',
fieldLabel :'batch_id:',
width:100
},
{
xtype: 'textfield',
name: 'subject_id',
id:'subject_id',
allowBlank:false,
tabIndex:7,
labelSeparator:'',
fieldLabel :'subject_id:',
width:100
},
{
xtype: 'textfield',
name: 'year_id',
id:'year_id',
allowBlank:false,
tabIndex:8,
labelSeparator:'',
fieldLabel :'year_id:',
width:100
},
{
xtype: 'textfield',
name: 'lectype',
id:'lectype',
allowBlank:false,
tabIndex:9,
labelSeparator:'',
fieldLabel :'lectype:',
width:100
},
{
xtype: 'textfield',
name: 'shift',
id:'shift',
allowBlank:false,
tabIndex:10,
labelSeparator:'',
fieldLabel :'shift:',
width:100
},
{
xtype: 'textfield',
name: 'employee_id',
id:'employee_id',
allowBlank:false,
tabIndex:11,
labelSeparator:'',
fieldLabel :'employee_id:',
width:100
},
{
xtype: 'textfield',
name: 'login_id',
id:'login_id',
allowBlank:false,
tabIndex:12,
labelSeparator:'',
fieldLabel :'login_id:',
width:100
},
{
xtype: 'textfield',
name: 'createdon',
id:'createdon',
allowBlank:false,
tabIndex:13,
labelSeparator:'',
fieldLabel :'createdon:',
width:100
},
Code For EXTJS END */




/* Code For Save File START 


$objcms_subject_allocationMgmt= new cms_subject_allocationMgmt();
$objcms_subject_allocationMgmt->subject_allocation_id=$_POST['subject_allocation_id'];
$objcms_subject_allocationMgmt->college_id=$_POST['college_id'];
$objcms_subject_allocationMgmt->branch_id=$_POST['branch_id'];
$objcms_subject_allocationMgmt->semester_id=$_POST['semester_id'];
$objcms_subject_allocationMgmt->div_id=$_POST['div_id'];
$objcms_subject_allocationMgmt->batch_id=$_POST['batch_id'];
$objcms_subject_allocationMgmt->subject_id=$_POST['subject_id'];
$objcms_subject_allocationMgmt->year_id=$_POST['year_id'];
$objcms_subject_allocationMgmt->lectype=$_POST['lectype'];
$objcms_subject_allocationMgmt->shift=$_POST['shift'];
$objcms_subject_allocationMgmt->employee_id=$_POST['employee_id'];
$objcms_subject_allocationMgmt->login_id=$_POST['login_id'];
$objcms_subject_allocationMgmt->createdon=$_POST['createdon'];
if($objcms_subject_allocationMgmt->subject_allocation_id == "0" ||  $objcms_subject_allocationMgmt->subject_allocation_id== ""){ 
$objcms_subject_allocationMgmt->add(); 
} 
else{
if($_REQUEST[act] == "del")
 {$objcms_subject_allocationMgmt->delete();
 }else
 {$objcms_subject_allocationMgmt->edit();
}
echo'{"success":"true"}'; 
 }

Code For Save File END */

?>