<?php require "_header.php";	?>
<?php 
$show_menu=0;
$today_date=strtotime(date('Y-m-d'));
$str_feedback_start_date=strtotime($feedback_start_date);
$str_feedback_end_date=strtotime($feedback_end_date);
$array_feedback_semester=explode(',',$feedback_semester);
$inarray=in_array($_SESSION['cur_semesterid'],$array_feedback_semester);
if($feedback_active==1 && $today_date >= $str_feedback_start_date && $today_date <= $str_feedback_end_date && $inarray){
	$show_menu=1;
	$question_sql=" select * from `feedback_que_master` ";
	$result=dbQuery($question_sql);
	if(dbRows($result) > 0){	
		$create_str="";
		$i=1;
		$question_ids="";
		while($record = dbArray($result)){
			$ans_a=str_ireplace('<p>','',str_ireplace('<p>','',$record['ans_a']));
			$ans_b=str_ireplace('<p>','',str_ireplace('<p>','',$record['ans_b']));
			$ans_c=str_ireplace('<p>','',str_ireplace('<p>','',$record['ans_c']));
			$ans_d=str_ireplace('<p>','',str_ireplace('<p>','',$record['ans_d']));
			$question_ids.=$record['que_id'].',';
			$create_str.="{xtype:'fieldset',border:true,autoHeight:true,title:'Question ".$i."',labelWidth:1,items:[{xtype:'label',cls: 'x-form-item myBold',html:";
			$create_str.="'".$record['question']."'},";
			$create_str.="{xtype: 'radiogroup',columns: 2,allowBlank: false,vertical: true,items:[{boxLabel:'A :- ".$ans_a."', name: 'ans[".$i."]', inputValue:'a'},{boxLabel: 'B :-".$ans_b."', name: 'ans[".$i."]', inputValue:'b'},{boxLabel: 'C :- ".$ans_c." ', name: 'ans[".$i."]', inputValue:'c'},{boxLabel: 'D :- ".$ans_d."', name: 'ans[".$i."]', inputValue:'d'}]}]},";
			$i++;
		}
	}
}
if($show_menu==0){
echo "Currently Feedback is disabled from admin";
exit;
}
?>
<script type="text/javascript" src="../jquery/ux/CheckColumn.js"></script>
<style>
label.myBold
		{
		   font-family:Georgia, "Times New Roman", Times, serif;
		   font-weight:600;
		   color:#930;
		   font-size: 14px;
		}
label.myBold2
		{
		   font-family:Georgia, "Times New Roman", Times, serif;
		   font-weight:600;
		   color:green;
		   font-size: 14px;
		}		
		.my-class .x-form-cb-label {font-weight: bold;}
.icon-next {
background-image: url(../images/button/right.png) !important;
}
.icon-pre {
background-image: url(../images/button/left.png) !important;
}
</style>
<script type="text/javascript">

var labelArray;
labelArray = [  
	['Branch:<span class="comp">*</span>'],
	['Semester:<span class="comp">*</span>'],
	['Select Subject:<span class="comp">*</span>']
	
];
Ext.onReady(function(){
Ext.QuickTips.init();

var subjectstore = new Ext.data.JsonStore({
	url:'../data/get-subject-withcode.php',
    root: 'data',
	totalProperty: 'total',
	autoLoad:false,
	fields: ['subject_id','subject_name'] 
});

var subject = new Ext.form.ComboBox({
	name: 'subject_name',
	id:'subject_name',
	hiddenName:'subject_hidden',
	labelSeparator:'',	
	fieldLabel :labelArray[2] ,
	displayField:'subject_name',
	valueField: 'subject_id',
	editable:true,
	forceSelection:true,	
	triggerAction:'all',
	mode:'local',
	width:400,
	allowBlank:false,
	store: subjectstore,
	listeners:{'select': function(cmb, rec, idx){
		var subject_id = this.getValue();
		if(subject_id != "" ){		
		Ext.getCmp('employee_name').reset();	
		facultystore.removeAll();
		facultystore.load({params:{subject_id:subject_id,branch_id:'<?php echo $_SESSION['cur_branchid']; ?>',semester_id:'<?php echo $_SESSION['cur_semesterid']; ?>',div_id:'<?php echo $_SESSION['cur_divison']; ?>'}});
		}							
	}}   
});


var facultystore = new Ext.data.JsonStore({
	url:'../data/get-subject-faculty.php',
    root: 'data',
	autoLoad:false,
	totalProperty: 'total',
	fields: ['employee_id','employee_name'] 
});
var employee_name = new Ext.form.ComboBox({
	name: 'employee_name',
	id:'employee_name',
	hiddenName:'employee_hidden',
	labelSeparator:'',	
	fieldLabel : 'Select Faculty :<span class="comp">*</span> ',
	displayField:'employee_name',
	valueField: 'employee_id',
	editable:true,
	forceSelection:true,	
	triggerAction:'all',
	mode:'local',
	width:250,
	allowBlank:false,
	store: facultystore,
	listeners:{'select': function(cmb, rec, idx){
				var employee_id=Ext.getCmp('employee_name').getValue();
				var subject_id=Ext.getCmp('subject_name').getValue();
				Ext.Ajax.request({
						waitMsg:'Loading',
						sync : true,
						url: '../data/get-feedback-done.php',
						params: {action:'setup',employee_id:employee_id,subject_id:subject_id},
						success: function(resp){
							var str = "";
							resbool=resp.responseText;
							if(resbool == 0){
								str = "Sorry! You have already given feedback for this subject, Please select other subject.";
									questionform.getForm().reset();
									Ext.getCmp('subject_name').reset();
									Ext.getCmp('employee_name').reset();
									Ext.MessageBox.show({
									title: 'Error',
									msg: str,
									buttons: Ext.MessageBox.OK,
									icon:Ext.MessageBox.ERROR
								});			
							}
							
						}				
					});
			
	}
	}
    
});

var questionform = new Ext.FormPanel({
		id:'questionform',
		name:'questionform',
		width:1000,	
		autoHeight:true, 
		url: '../save-stud-feedback.php',
		frame:true,
        items: [{
				    
				xtype:'fieldset',
				border:true,
				height:110, 				
				layout:'column', 
				title:'Select Subject For giving Feedback',
				items  : [
				         {
						  columnWidth: 1,
						  layout: 'form',	
				          labelWidth  : 100,
						  items:[subject]
						  },
						   {columnWidth:1,
						    layout: 'form',	
						   items  : [employee_name,
						   		{xtype:'hidden',
								id:'question_ids',
								name:'question_ids',
								value:'<?php echo $question_ids?>'}]
						 }, 
						 {
							 columnWidth: 1,
						  layout: 'column',				         
				          items  : [{
							       columnWidth:0.30,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'branch_label',
										   name:'branch_label',
										   html:'Branch : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  },
								  {
								   		
							       columnWidth:0.30,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'semester_label',
										   name:'semester_label',
										   html:'Semester : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  
								   },
								   {							   		
							       columnWidth:0.40,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'year_label',
										   name:'year_label',
										   html:'Academic Year : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  
								   
									}   
								  
								   ]
						  }
						]				
				},<?php echo $create_str; ?>
		]		
    });
	
	


	var PatientWindow = new Ext.Window({
        title: "Feedback Form <span style='color:#900'>All Question Are Compalsory.</span>",
		style:'text-align:left;',
		id:'PatientWindow',
		name:'PatientWindow',
		width:1200,	
		autoHeight:true, 
		modal:false,		
		shadow:false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items:questionform,
		buttonAlign: 'center',
	    buttons: [{
				text: 'Submit',
				tabIndex:37,
				name:'btnsubmit',
				id:'btnsubmit',
				iconCls:'icon-save',
				handler: function () {
					if(Ext.getCmp('subject_name').isValid())
					  {
						 Ext.MessageBox.confirm('Confirmation', 'Do u Realy want to submit your feedback.?', submitexam);
					  }
					else
					 {
						 alert("Please select subject first !");
					 }
				}
			},
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:7,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					questionform.getForm().reset();
					Ext.getCmp('subject_name').reset();
					Ext.getCmp('employee_name').reset();
				}
			},
			{
				text: 'Close',
				tabIndex:37,
				iconCls:'icon-close',
				handler: function () {
					 Ext.MessageBox.confirm('Confirmation', 'Do you realy want to cancel feedback and close the window.?',closewindow);
				}
			}
			
		]
	});

var varWidth =  (screen.width - PatientWindow.width)/2;
	PatientWindow.setPosition(varWidth,((screen.height/4)-85));
	PatientWindow.show();



function submitexam(btn)
{

	if(btn=='yes'){
		
			Ext.getCmp('questionform').getForm().submit({
							 params  : {
										act:'add' },
								waitMsg: 'Saving...',
								success: function () {	
								 Ext.MessageBox.show({
										   title: 'Thank you for your feedback',
										   msg: 'Thank You, Your feedback of this subject is saved successfully,<br> you can also give feedback to other subject of faculty.',
										   buttons: Ext.MessageBox.OK,
										   icon:Ext.MessageBox.INFO
										   });
										   questionform.getForm().reset();
										   Ext.getCmp('subject_name').reset();
										   Ext.getCmp('employee_name').reset();
								
								},
								failure: function () {
									Ext.MessageBox.show({
										title: 'Error',
										msg: 'Sorry! all questions are compalsory, so you have to attempt all questions.',
										buttons: Ext.MessageBox.OK,
										icon:Ext.MessageBox.ERROR
									});									
								}
							});
			  
	}  


}

function closewindow(btn)
{

	if(btn=='yes'){
		
		window.location='feedback_done.php';	
			  
	}  


}

Ext.getCmp('branch_label').setText("Branch : <?php echo $_SESSION['f_branch_name'];?>");
Ext.getCmp('semester_label').setText("Semester : <?php echo $_SESSION['f_semester_name'];?>");
Ext.getCmp('year_label').setText("Academic Year : <?php echo $_SESSION['f_year_name'];?>");
subjectstore.load({params:{
			branch_name:<?php echo $_SESSION['f_cur_branchid'];?>,
			semester_name:<?php echo $_SESSION['f_cur_semesterid'];?>
		}});


});



</script>

<?php 
 require "_footer.php"; ?>
