<?php require "_headerhome_feedback.php";	
require "data/combo_semester.php";
	?>

<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
<script type="text/javascript">


function disableBackButton()
{
window.history.forward();

//alert('<?php //echo $_SESSION['temp'] ?>');

}
setTimeout("disableBackButton()", 0);
</script>

<?php  //$_SESSION['temp']=time(); ?>
<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.Ajax.request({
				loadMask: true,
				sync : true,
				url: 'data/getfacultyname.php',
				params: {subject_id:subject_id},
				success: function(resp){
					var value=Ext.decode(resp.responseText).count;
					console.log(value);
					if(value=='' || value == null){
						Ext.getCmp('faculty_label').setText("Instructor\'s Name : ");
						} else{
						var arr_data = new Array();
						arr_data =  value.split(",");
						employee_name = arr_data[0];
						Ext.getCmp('faculty_label').setText("Instructor\'s Name : "+employee_name);
					}					
				}				
			});	*/	
		Ext.getCmp('employee_name').reset();	
		facultystore.removeAll();
		Questionstore.removeAll();		
		facultystore.load({params:{subject_id:subject_id}});
		resetFormFields();
		
		}							
	}}   
});


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:true,
	store: facultystore,
	listeners:{'select': function(cmb, rec, idx){
			resetFormFields();
		Questionstore.load({params:{subject_id:Ext.getCmp('subject_name').getValue()}});
	}
	}
    
});
var questionfields = [
	{name:'que_id',type: 'int'},
	{name:'chapter_added',type: 'string'},
	{name:'question',type: 'string'},
	{name:'ans_a',type: 'string'},
	{name:'ans_b',type: 'string'},
	{name:'ans_c',type: 'string'},
	{name:'ans_d',type: 'string'},
	{name:'given_answer',type: 'string'}

]

var Questionstore = new Ext.data.JsonStore({
    url: 'data/get-schedule-exam-question.php',
    root: 'data',
    fields: questionfields
});

//Questionstore.load({params:{exam_id :<?php //echo $_REQUEST['exam_id'];?>}});
//Questionstore.load();
	
var questioncolModel = new Ext.grid.ColumnModel([
	new Ext.grid.RowNumberer(),
	{
		header: "Atd",
		dataIndex: 'chapter_added',
		width:30,
		renderer: function(v, params, record){
				return '<img src="'+ v +'" height="15" width="15" />';
		}
  	},
	{	
		header: "Question",
		dataIndex: 'question',
		sortable: true,
		width:310 
  	}]);

	var Questiongrid = new Ext.grid.GridPanel({
		id:'Questiongrid',
		name:'Questiongrid',
   		store: Questionstore,
        cm: questioncolModel,
		columnLines: true,
		loadMask:true,
		stripeRows: true,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
					//questionform.getForm().reset();
					resetFormFields();
					
                	Ext.getCmp("questionform").getForm().loadRecord(rec);
					Ext.getCmp('question').update(rec.data.question);
					
					Ext.getCmp('ans_a').update(rec.data.ans_a);
					Ext.getCmp('ans_b').update(rec.data.ans_b);
					Ext.getCmp('ans_c').update(rec.data.ans_c);
					Ext.getCmp('ans_d').update(rec.data.ans_d);
					
					
					if(rec.data.given_answer=='a')
					Ext.getCmp('radio_a').setValue(true);
					
					if(rec.data.given_answer=='b')
					Ext.getCmp('radio_b').setValue(true);
					
					if(rec.data.given_answer=='c')
					Ext.getCmp('radio_c').setValue(true);
					
					if(rec.data.given_answer=='d')
					Ext.getCmp('radio_d').setValue(true);
					
					
				}
         	}
   		}),
		height: 400,
		border: true
 	});
	
	      Questionstore.on({'load': {fn: function(){
			    if(Questionstore.getCount() <= 0){
					       Ext.MessageBox.show({
							   title: 'Error',
							   msg: 'Sorry! You have already given feedback for this subject, Please select other subject.',
							   buttons: Ext.MessageBox.OK,
							   icon:Ext.MessageBox.ERROR
							   });
					 Ext.getCmp('btnsubmit').disable();
					  } 
			    else{
				
					Questiongrid.getSelectionModel().selectFirstRow();	
					Ext.getCmp('btnsubmit').enable();													
					
				}}
		 }
	});	
	

Ext.override(Ext.form.Radio, {
  onClick : function() {
    if(this.el.dom.checked != this.checked) {
      var els = this.el.up('form').select('input[name='+this.el.dom.name+']');
      els.each(function(el) {
        if(el.dom.id == this.id) {
          this.setValue(true);
        } else {
          Ext.getCmp(el.dom.id).setValue(false);   
        }
      }, this);
    }
  }
});
	
var questionform = new Ext.FormPanel({
		id:'questionform',
		name:'questionform',
		 title: "Feedback Form <span style='color:#900'>All Question Are Compalsory.</span>",
		width:1000,	
		height:450, 
		url: 'save-student-feedback.php',
		layout: 'border',
		renderTo:'main-form',
		frame:true,
        items: [{
            region: 'west',
			collapsible: true,
			frame:true,
			border:true,
			title: 'Question',
			collapseMode: 'mini',
            width:'400',
			items:[Questiongrid]
        },{
            region: 'center',
            collapsible: false,
			style:'padding-left:5px',
            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:'label',
								   id:'faculty_label',
								   name:'faculty_label',
								   html:'Instructor\'s Name : ',
								   cls: 'x-form-item myBold2'}*/
						]
						 }, 
						 {columnWidth: 1,
						  layout: 'column',				         
				          items  : [{
							       columnWidth:0.35,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'branch_label',
										   name:'branch_label',
										   html:'Branch : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  },
								  {
								   		
							       columnWidth:0.35,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'semester_label',
										   name:'semester_label',
										   html:'Semester : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  
								   },
								   {							   		
							       columnWidth:0.3,
								   layout:'form',
								   items:[{
										   xtype:'label',
										   id:'year_label',
										   name:'year_label',
										   html:'Academic Year : ',
										   cls: 'x-form-item myBold2'         
									    }]
								  
								   
									}   
								  
								   ]
						  }
						]				
				},{
				xtype:'fieldset',
				border:true,
				height:100,  
				title:'Question',
				items  : [{xtype:'label',
						   id:'question',
						   name:'question',
						   cls: 'x-form-item myBold'}]
				},
				{xtype       : 'container',
						autoEl      : {},
						border      : false,
						layout      : 'column',
						anchor      : '100%',
						defaultType : 'field',
						items       : [
						{
							xtype:'textfield',
							id:'student_session_id',
							name:'student_session_id',
							hidden:true
							
							
							},
						
						{
										xtype  : 'container',
										autoEl : {},
										layout : 'form',
										columnWidth : .49,
										items  : [{
													xtype:'fieldset',
													border:true,
													height:70,  
													title:'Option A',
													layout:'column',
													items  : [{columnWidth: .1,
															  items  : [{
																xtype:'radio',
																name: 'Radiogroup',
																id: 'radio_a',															
																handler:function(){
																	
																	  if(this.checked) {
																		var index=  Questiongrid.getSelectionModel().getSelectedIndex();
																		var record = Questiongrid.store.getAt(index);					
																		
																			record.set('given_answer','a');  
																			record.set('chapter_added','images/success.png'); 
																			//var time=removeHTMLTags(document.getElementById("cntdwn").innerHTML);
																			//record.set('given_at',time); 
																			Questiongrid.getView().refresh();																		
																	  }													  	
																  }	
																}]},
															  {columnWidth: .9,
															  items  : [{
																 xtype:'label',
																id:'ans_a',
																name:'ans_a',
																cls: 'x-form-item myBold'}]}]
												},{
													xtype:'fieldset',
													border:true,
													height:70,  
													title:'Option C',
													layout:'column',
													items  : [{columnWidth: .1,
															  items  : [{
																xtype:'radio',
																name: 'Radiogroup',
																id: 'radio_c',
																handler:function(){
																	  if(this.checked) {
																		var index=  Questiongrid.getSelectionModel().getSelectedIndex();
																		var record = Questiongrid.store.getAt(index);
																		
																			
																			record.set('given_answer','c'); 
																			record.set('chapter_added','images/success.png'); 
																			//var time=removeHTMLTags(document.getElementById("cntdwn").innerHTML);
																			//record.set('given_at',time); 
																			
																	  }													  	
																  }	
																}]},
															  {columnWidth: .9,
															  items  : [{
																 xtype:'label',
																id:'ans_c',
																name:'ans_c',
																 cls: 'x-form-item myBold'}]}]
												}]
									   },{
										xtype       : 'container',
										autoEl      : {},
										layout      : 'form',
										columnWidth : .02,
										labelWidth  : 60,
										items       : [{height:5}]
									   },{
										xtype       : 'container',
										autoEl      : {},
										layout      : 'form',
										columnWidth : .49,
										labelWidth  : 60,
										items       : [{
															xtype:'fieldset',
															border:true,
															height:70,  
															title:'Option B',
															layout:'column',
															items  : [{columnWidth: .1,
															  items  : [{
																xtype:'radio',
																name: 'Radiogroup',
																id: 'radio_b',
																handler:function(){
																	  if(this.checked) {
																		var index=  Questiongrid.getSelectionModel().getSelectedIndex();
																		var record = Questiongrid.store.getAt(index);
																		
																			record.set('given_answer','b');
																			record.set('chapter_added','images/success.png'); 
																			//var time=removeHTMLTags(document.getElementById("cntdwn").innerHTML);
																			//record.set('given_at',time); 
																			Questiongrid.getView().refresh();  
																		
																		
																	  }													  	
																  }	
																}]},
															  {columnWidth: .9,
															  items  : [{
																 xtype:'label',
																id:'ans_b',
																name:'ans_b',
																cls: 'x-form-item myBold'}]}]
													   },{
															xtype:'fieldset',
															border:true,
															height:70,  
															title:'Option D',
															layout:'column',
															items  : [{columnWidth: .1,
															  items  : [{
																xtype:'radio',
																name: 'Radiogroup',
																id: 'radio_d',
																handler:function(){
																	  if(this.checked) {
																		var index=  Questiongrid.getSelectionModel().getSelectedIndex();
																		var record = Questiongrid.store.getAt(index);
																		
																			record.set('given_answer','d'); 
																			record.set('chapter_added','images/success.png'); 
																			//var time=removeHTMLTags(document.getElementById("cntdwn").innerHTML);
																			//record.set('given_at',time); 
																		
																	  }													  	
																  }	
																}]},
															  {columnWidth: .9,
															  items  : [{
																 xtype:'label',
																id:'ans_d',
																name:'ans_d',
																 cls: 'x-form-item myBold'}]}]
														}]
									   }]
		}]
        }
		],
		buttonAlign: 'center',
	    buttons: [{
				text: '.....Previous', 
				name:'btnprv',
				iconCls:'icon-pre',
				id:'btnprv',
				handler: function(){
				
				var row = Questiongrid.getSelectionModel().getSelectedIndex();
						Questiongrid.getSelectionModel().selectRow(row-1);
   				
								
				}	
			},
			{
				text:'Next......', 
				iconCls:'icon-next',
				iconAlign: 'right',				
				handler: function (){
					var row = Questiongrid.getSelectionModel().getSelectedIndex();
						Questiongrid.getSelectionModel().selectRow(row+1);
				}
			},{
				text: 'Submit',
				tabIndex:37,
				name:'btnsubmit',
				id:'btnsubmit',
				disabled:true,
				style:"margin-left:50px",
				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: 'Close',
				tabIndex:37,
				//style:"margin-left:50px",
				iconCls:'icon-close',
				handler: function () {
					 Ext.MessageBox.confirm('Confirmation', 'Do you realy want to cancel feedback and close the window.?',closewindow);
				}
			}
			
		]
    });
	
	


	/*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:1000,	
		height:560,  
		modal:false,		
		shadow:false,
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items:questionform,
		
	});


PatientWindow.show();*/


function submitexam(btn)
{

	if(btn=='yes'){
		
			finalsubmitexam();
			//Ext.getCmp('faculty_label').setText("Instructor\'s Name : ");
			//Ext.getCmp('employee_name').reset();
			  
	}  


}

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 : 2012");


subjectstore.load({params:{
			branch_name:<?php echo $_SESSION['f_cur_branchid'];?>,
			semester_name:<?php echo $_SESSION['f_cur_semesterid'];?>
		}});
function finalsubmitexam()
{
 			   var que_ids = "";
			   var given_answer = "";
			  // var given_at = "";
			   var flagenotgive=0;
			   
				for(var i = 0, len = Ext.getCmp('Questiongrid').store.getCount(); i < len; i++){
				    record = Ext.getCmp('Questiongrid').store.getAt(i);
					if(record.data.given_answer =="")
					{
						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
									});	
						return false;			
					}
						que_ids+=  record.data.que_id + ',';
						given_answer+=record.data.given_answer +',';
						//given_at+=  record.data.given_at +',';
					
				 }
				 
				 que_ids=(que_ids.substring(0,(que_ids.length-1)));
				  given_answer=(given_answer.substring(0,(given_answer.length-1)));
				//  given_at=(given_at.substring(0,(given_at.length-1)));
				
					 Ext.getCmp('questionform').getForm().submit({
							 params  : {
										que_ids:que_ids,
										given_answer:given_answer,										
										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
										   });
										   resetFormFields();
										   Ext.getCmp('subject_name').reset();
										   Ext.getCmp('employee_name').reset();
										   
										   Questionstore.removeAll();
								//window.location='feedback_done.php';
									
								},
								failure: function () {
									Ext.MessageBox.show({
										title: 'Error',
										msg: 'Please fill up complete form.',
										buttons: Ext.MessageBox.OK,
										icon:Ext.MessageBox.ERROR
									});									
								}
							});
				 
}
function resetFormFields(){
	Ext.getCmp('question').update("");
					Ext.getCmp('ans_a').update("");
					Ext.getCmp('ans_b').update("");
					Ext.getCmp('ans_c').update("");
					Ext.getCmp('ans_d').update("");
					Ext.getCmp('radio_a').reset();
					Ext.getCmp('radio_b').reset();
					Ext.getCmp('radio_c').reset();
					Ext.getCmp('radio_d').reset();
}

});



</script>

<div  id="main-content" style="width:1000px;">
   <div id="main-form"  style="text-align:left;">
   </div>
</div>
<?php 
 require "_footer.php"; ?>
