<?php
class feedback_que_masterMgmt
{
	public $que_id;

	public $college_id;
	public $year_id;
	public $question;
	public $ans_a;
	public $ans_b;
	public $ans_c;
	public $ans_d;
	public $login_id;
	public $createdon;


	function getAllRecords($limit = 0, $start = 0, $condition = "", $order_field = "", $order_type = "")
	{
		$qry = "SELECT * FROM feedback_que_master 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";
		}

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


	function add()
	{
		$Qry1 = "";
		$Qry1 .= "que_id   ='" . Escape($this->que_id) . "',";
		//$Qry1 .= "branch_id   ='"  .Escape($this->branch_id)."',";
//$Qry1 .= "semester_id   ='"  .Escape($this->semester_id)."',";
//$Qry1 .= "subject_id   ='"  .Escape($this->subject_id)."',";
		$Qry1 .= "college_id   ='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id   ='" . Escape($this->year_id) . "',";
		$Qry1 .= "question   ='" . Escape($this->question) . "',";
		$Qry1 .= "ans_a   ='" . Escape($this->ans_a) . "',";
		$Qry1 .= "ans_b   ='" . Escape($this->ans_b) . "',";
		$Qry1 .= "ans_c   ='" . Escape($this->ans_c) . "',";
		$Qry1 .= "ans_d   ='" . Escape($this->ans_d) . "',";
		$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 feedback_que_master set " . $Qry1 . " ";
			dbQuery($qry);
			$this->que_id = dbInsertedId();
		}

	}

	function edit()
	{
		$Qry1 = "";
		$Qry1 .= "que_id   ='" . Escape($this->que_id) . "',";
		//$Qry1 .= "branch_id   ='"  .Escape($this->branch_id)."',";
//$Qry1 .= "semester_id   ='"  .Escape($this->semester_id)."',";
//$Qry1 .= "subject_id   ='"  .Escape($this->subject_id)."',";
		$Qry1 .= "college_id    ='" . Escape($_SESSION['VedantnrCollegeId']) . "',";
		$Qry1 .= "year_id   ='" . Escape($this->year_id) . "',";
		$Qry1 .= "question   ='" . Escape($this->question) . "',";
		$Qry1 .= "ans_a   ='" . Escape($this->ans_a) . "',";
		$Qry1 .= "ans_b   ='" . Escape($this->ans_b) . "',";
		$Qry1 .= "ans_c   ='" . Escape($this->ans_c) . "',";
		$Qry1 .= "ans_d   ='" . Escape($this->ans_d) . "',";
		$Qry1 .= "login_id  ='" . Escape($_SESSION['aUserId']) . "',";
		//$Qry1 .= "createdon   ='"  .Escape($this->createdon)."',";
		if ($Qry1 != "") {
			$Qry1 = substr($Qry1, 0, strlen($Qry1) - 1);
			$qry = "update feedback_que_master set " . $Qry1 . " where  que_id=" . $this->que_id;
			dbQuery($qry);
		}

	}


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


	function getemployeefeedback($condition)
	{
		$qry = "SELECT 
				que_ids,
				group_concat(answer_arr SEPARATOR '|||') as all_answer,
				sub.subject_name,
				emp.employee_name,
				count(*)as total_row,
				(Select branch_name from cms_branchmaster where cms_branchmaster.branch_id = sub.branch_id)as branch_name,
(Select year_name from cms_yearmaster where cms_yearmaster.year_id = sub.year_id)as year_name,
(Select branchyear_name from cms_branchyear where cms_branchyear.branchyear_id = sub.branchyear_id)as branchyear_name,
(Select semester_name from cms_semestermaster where cms_semestermaster.semester_id = sub.semester_id)as semester_name
				
			FROM 
				 feedback_que_result fb,
				 cms_subjectmaster sub,
				 cms_employeemaster emp
			WHERE 
				fb.employee_id = emp.employee_id AND
				fb.subject_id = sub.subject_id AND
				fb.student_id !=0 AND
				fb.employee_id !=0 AND
				emp.employee_active = 'YES' ";

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

		$out = dbQuery($qry);
		if (dbRows($out) > 0) {
			return $out;
		}
		return $out;
	}
//pendding feedback .php
function getemployeependdingfeedback($condition)
	{
		$qry = " select 
				sm.student_id,
				
				sm.student_gturegno,
				CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS studentname,
				group_concat(CONCAT(fqr.subject_id,'-',fqr.employee_id) ORDER BY fqr.subject_id ASC,fqr.employee_id) as subject_id
				from 
					cms_studentmaster sm,
					cms_studentdetail sd
					left join feedback_que_result fqr on fqr.student_id = sd.student_id
				where
				sm.college_id = '".$_SESSION["VedantnrCollegeId"]."' 
				
				AND sm.student_id = sd.student_id
				AND sm.student_active = 1
				  ";

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

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

}/* Code For EXTJS START \n{
xtype: 'textfield',
name: 'que_id',
id:'que_id',
allowBlank:false,
tabIndex:1,
labelSeparator:'',
fieldLabel :'que_id:',
width:100
},
{
xtype: 'textfield',
name: 'branch_id',
id:'branch_id',
allowBlank:false,
tabIndex:2,
labelSeparator:'',
fieldLabel :'branch_id:',
width:100
},
{
xtype: 'textfield',
name: 'semester_id',
id:'semester_id',
allowBlank:false,
tabIndex:3,
labelSeparator:'',
fieldLabel :'semester_id:',
width:100
},
{
xtype: 'textfield',
name: 'subject_id',
id:'subject_id',
allowBlank:false,
tabIndex:4,
labelSeparator:'',
fieldLabel :'subject_id:',
width:100
},
{
xtype: 'textfield',
name: 'college_id',
id:'college_id',
allowBlank:false,
tabIndex:5,
labelSeparator:'',
fieldLabel :'college_id:',
width:100
},
{
xtype: 'textfield',
name: 'year_id',
id:'year_id',
allowBlank:false,
tabIndex:6,
labelSeparator:'',
fieldLabel :'year_id:',
width:100
},
{
xtype: 'textfield',
name: 'question',
id:'question',
allowBlank:false,
tabIndex:7,
labelSeparator:'',
fieldLabel :'question:',
width:100
},
{
xtype: 'textfield',
name: 'ans_a',
id:'ans_a',
allowBlank:false,
tabIndex:8,
labelSeparator:'',
fieldLabel :'ans_a:',
width:100
},
{
xtype: 'textfield',
name: 'ans_b',
id:'ans_b',
allowBlank:false,
tabIndex:9,
labelSeparator:'',
fieldLabel :'ans_b:',
width:100
},
{
xtype: 'textfield',
name: 'ans_c',
id:'ans_c',
allowBlank:false,
tabIndex:10,
labelSeparator:'',
fieldLabel :'ans_c:',
width:100
},
{
xtype: 'textfield',
name: 'ans_d',
id:'ans_d',
allowBlank:false,
tabIndex:11,
labelSeparator:'',
fieldLabel :'ans_d:',
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 


$objfeedback_que_masterMgmt= new feedback_que_masterMgmt();
$objfeedback_que_masterMgmt->que_id=$_POST['que_id'];
$objfeedback_que_masterMgmt->branch_id=$_POST['branch_id'];
$objfeedback_que_masterMgmt->semester_id=$_POST['semester_id'];
$objfeedback_que_masterMgmt->subject_id=$_POST['subject_id'];
$objfeedback_que_masterMgmt->college_id=$_POST['college_id'];
$objfeedback_que_masterMgmt->year_id=$_POST['year_id'];
$objfeedback_que_masterMgmt->question=$_POST['question'];
$objfeedback_que_masterMgmt->ans_a=$_POST['ans_a'];
$objfeedback_que_masterMgmt->ans_b=$_POST['ans_b'];
$objfeedback_que_masterMgmt->ans_c=$_POST['ans_c'];
$objfeedback_que_masterMgmt->ans_d=$_POST['ans_d'];
$objfeedback_que_masterMgmt->login_id=$_POST['login_id'];
$objfeedback_que_masterMgmt->createdon=$_POST['createdon'];
if($objfeedback_que_masterMgmt->que_id == "0" ||  $objfeedback_que_masterMgmt->que_id== ""){ 
$objfeedback_que_masterMgmt->add(); 
} 
else{
if($_REQUEST[act] == "del")
 {$objfeedback_que_masterMgmt->delete();
 }else
 {$objfeedback_que_masterMgmt->edit();
}
echo'{"success":"true"}'; 
 }

Code For Save File END */

?>