<?php 	require "_header.php"; 
require "data/combo_semester.php";
 ?>
<script type="text/javascript" src="fckeditor/fckeditor.js"></script>
<script type="text/javascript">
var sFCKeditorToolbar = 'Basic';
var sFCKeditorBasePath = 'fckeditor/';
var sFCKeditorBaseHref = '<?php echo $SiteBaseUrl; ?>/fckeditor/';
var sFCKeditorSkinPath = '<?php echo $SiteBaseUrl; ?>/fckeditor/editor/skins/office2003/';
</script>
<script type="text/javascript" src="js/extfckediter.js"></script>
<div  id="main-content">
<script type="text/javascript" language="javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
/*
var labelArray;
labelArray = [  
	['Branch:<span class="comp">*</span>'],
	['Semester:<span class="comp">*</span>'],
	['Subject:<span class="comp">*</span>']
	
];
var branchstore = new Ext.data.ArrayStore({		
	fields: ['branch_id','branch_name'],
	data:Ext.semester.branch
});

var semesterstore = new Ext.data.ArrayStore({		
	fields: ['semester_id','semester_name'],
	data:Ext.semester.semester
});

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


var branch = new Ext.form.ComboBox({
	name:'branch_name',
	id:'branch_name',
	hiddenName:'branch_hidden',
	labelSeparator:'',	
	fieldLabel :labelArray[0] ,
	displayField:'branch_name',
	valueField: 'branch_id',
	editable:true,
	width:150,
	forceSelection:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	store:branchstore,
    listeners:{'select': function(cmb, rec, idx){
		//Ext.getCmp('branch_disp').setValue(this.getRawValue());
		//Ext.getCmp('division_id').reset();
		LoadData();
		QueReset();
	}}
});

var semester = new Ext.form.ComboBox({
	name:'semester_name',
	id:'semester_name',
	hiddenName:'semester_hidden',
	labelSeparator:'',	
	fieldLabel:labelArray[1] ,
	displayField:'semester_name',
	valueField:'semester_id',
	editable:true,
	forceSelection:true,
	triggerAction:'all',
	mode:'local',
	allowBlank:false,
	width:150,
	store:semesterstore,
    listeners:{'select': function(cmb, rec, idx){
		//Ext.getCmp('semester_disp').setValue(this.getRawValue());
		LoadData();
		QueReset();
	
	}}
});

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:300,
	allowBlank:true,
	store: subjectstore,
    listeners:{'select': function(cmb, rec, idx){
		//Ext.getCmp('subject_disp').setValue(this.getRawValue());
		QueReset();
		Questionstore.load({params:{
								branch_id:Ext.getCmp('branch_name').getValue(),
								semester_id:Ext.getCmp('semester_name').getValue(),
								subject_id:this.getValue()
							}});
	}}
});

function LoadData(){
	var branch_name = Ext.getCmp('branch_name').getValue();
	var semester_name = Ext.getCmp('semester_name').getValue();
	
	if(branch_name != '' && semester_name != ''){	
		Ext.getCmp('subject_name').reset();
		subjectstore.load({params:{
			branch_name:branch_name,
			semester_name:semester_name
		}});
	}}*/
//=========

var Questionfields = [
	{name:'que_id',type: 'int'},
	/*{name:'branch_id',type: 'int'},
	{name:'semester_id',type: 'int'},
	{name:'subject_id',type: 'int'},*/
	{name:'question',type: 'string'},	
	{name:'ans_a',type: 'string'},
	{name:'ans_b',type: 'string'},
	{name:'ans_c',type: 'string'},
	{name:'ans_d',type: 'string'}
]

var Questionstore = new Ext.data.JsonStore({
    url: 'data/Feedbackgrid-data.php',
    root: 'data',
	autoLoad:true,
    fields: Questionfields
});

	
	var QueModel = new Ext.grid.ColumnModel([
	new Ext.grid.RowNumberer(),
	{ 
		header: "Question",
		dataIndex: 'question',
		sortable: true,
		width:880,
  	}]);

	var Questiongrid = new Ext.grid.GridPanel({
   		store: Questionstore,
        cm: QueModel,
		columnLines: true,
		loadMask:true,
		stripeRows: true,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
					Ext.getCmp("Feedbackform").getForm().loadRecord(rec);
					//Ext.getCmp("boardque_id").setRawValue(removeHTMLTags(Ext.getCmp("boardque_id").getRawValue()));
					Ext.getCmp('btngujcetdelete').enable();
					//Ext.getCmp('final_question_id').setValue(rec.data.boardque_id);
				}
         	}
   		}),
		height: 250,
		border: true
 	});
	
var Feedbackform = new Ext.FormPanel({	
		id: 'Feedbackform',
		frame: true,
		url: 'save-feedbackque.php',
		autoHeight:true,    
		labelWidth:75,
		items: [/*{xtype       : 'container',
						autoEl      : {},
						border      : false,
						layout      : 'column',
						anchor      : '100%',
						defaultType : 'field',
						items       : [{
										xtype  : 'container',
										autoEl : {},
										layout : 'form',
										columnWidth : .25,
										labelWidth  : 75,
										items  : [branch]
									   },
									   {
										xtype       : 'container',
										autoEl      : {},
										layout      : 'form',
										columnWidth : .25,
										labelWidth  : 60,
										items       : [semester]
									   },
									   {
										xtype       : 'container',
										autoEl      : {},
										layout      : 'form',
										columnWidth : .50,
										labelWidth  : 60,
										items       : [subject]
									   }]
		},*/	
	 
				{
				    columnWidth: 1,
					xtype: 'fieldset',
					title:'Feedback Question and Options',
					collapsible: true,
					labelWidth: 60,
					forceLayout:true, 
			   		autoHeight : true,
					layout: 'form',
					border: true,
					items:[{
							 xtype:'hidden',
							 id:'que_id',
							 name:'que_id',
							 value:0
							 },{
								xtype:'fckeditor',
								name:'question',
								id:'question',
								tabIndex:5,
								fieldLabel:'Question',
								height:200,
								width:850
							 },
						   {
						xtype       : 'container',
						autoEl      : {},
						border      : false,
						layout      : 'column',
						anchor      : '100%',
						defaultType : 'field',
						items       : [{
										xtype  : 'container',
										autoEl : {},
										layout : 'form',
										columnWidth : .5,
										labelWidth  : 60,
										items  : [{xtype:'fckeditor',
													name:'ans_a',
													id:'ans_a',
													fieldLabel:'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A',
													tabIndex:6,
													height:150,
													width:400
												 },{
													 xtype:'fckeditor',
													 id:'ans_c',
													 tabIndex:8,
													 name:'ans_c',
													 fieldLabel:'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C',
													 height:150,
													 width:400
													 }]
									   },
									   {
										xtype       : 'container',
										autoEl      : {},
										layout      : 'form',
										columnWidth : .5,
										labelWidth  : 27,
										items       : [{
														 xtype:'fckeditor',
														 id:'ans_b',
														 name:'ans_b',
														 tabIndex:7,
														 fieldLabel:'&nbsp;&nbsp;B',
														 height:150,
														 width:415
													 },{
														 xtype:'fckeditor',
														 id:'ans_d',
														 name:'ans_d',
														 tabIndex:9,
														 fieldLabel:'&nbsp;&nbsp;D',
														 height:150,
														 width:415
													 }]
									   }]
					    }
					       ]
					},
				{
				    columnWidth: 1,
					xtype: 'fieldset',
					title:'Feedback Questions Grid',
					collapsible: true,
    		   		collapsed  : true,
			   		forceLayout:true, 
			   		autoHeight : true,
					layout: 'form',
					border: true,
					items:[Questiongrid]},
			
				]
			
    });
	
function deleteFeedQue(btn){
    	if(btn=='yes'){
			Feedbackform.getForm().submit({
										waitMsg: 'Saving...',
										params: {act:'del'},
										success: function () {	
											/*Questionstore.load({params:{
																branch_id:Ext.getCmp('branch_name').getValue(),
																semester_id:Ext.getCmp('semester_name').getValue(),
																subject_id:Ext.getCmp('subject_name').getValue()
																}});*/
											Questionstore.load();					
											QueReset();								
										},
										failure: function () {
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill up complete form.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										}
									});	
	 	}  
  	}
	
	
function  QueReset()
{
	Ext.getCmp('que_id').reset();
	Ext.getCmp('question').reset();
	Ext.getCmp('ans_a').reset();
	Ext.getCmp('ans_b').reset();
	Ext.getCmp('ans_c').reset();
	Ext.getCmp('ans_d').reset();	
}

var FeedbackWindow = new Ext.Window({
		title: 'Add Feedback Question',
		width:980,		
		autoHeight:true,
		frame: true,
		border: false,
		modal:false,
		layout: 'fit',
		closeAction:'hide',
		maximizable: true,
		collapsible:true,
		items: Feedbackform,
		buttonAlign:'center',
		buttons:[{
				text: 'Save', 
				name:'btngujcetSave',
				tabIndex:12,
				iconCls:'icon-save',
				id:'btngujcetSave',
				handler: function(){
				//var gujcet_ask_Year  = Ext.getCmp('gujcet_ask_Year').getValue();
				Feedbackform.getForm().submit({
										waitMsg: 'Saving...',										
										success: function () {	
											/*Questionstore.load({params:{
																						branch_id:Ext.getCmp('branch_name').getValue(),
																						semester_id:Ext.getCmp('semester_name').getValue(),
																						subject_id:Ext.getCmp('subject_name').getValue()
																						}});*/
											Questionstore.load();											
											QueReset();	
							
										},
										failure: function () {
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill up complete form.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										}
									});		
				}	
			},
			{
				text: 'Delete', 
				name:'btngujcetdelete',
				tabIndex:13,
				disabled:true,
				iconCls:'remove',
				id:'btngujcetdelete',
				handler: function (){
					
					/*var semester_id=Ext.getCmp('semester_id').getValue();
					Ext.Ajax.request({
						loadMask: true,
						sync : true,
						url: 'data/getRelatedRecord.php',
						params: {action:'semester',semester_id:semester_id},
						success: function(resp){
							var str = "";
							resbool=resp.responseText;
							if(resbool != 0){
								str = "It has related record in " + resbool +"Please Delete This Record First";
								Ext.MessageBox.show({
									title: 'Error',
									msg: str,
									buttons: Ext.MessageBox.OK,
									icon:Ext.MessageBox.ERROR
								});			
							}
							else{*/
								Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleteFeedQue);
							/*}
						}				
					});*/
				
					
				}
			},
			{
				text: 'Reset', 
				name:'btngujcetreset',
				tabIndex:14,
				iconCls:'icon-reset',
				id:'btngujcetreset',
				handler: function (){
					
					Questionstore.removeAll();
					Questionstore.load();
					Feedbackform.getForm().reset();
					Ext.getCmp('btngujcetdelete').disable();					

				}
			},
			{
				text:'Close', 
				name:'btngujcetclose',
				tabIndex:15,
				iconCls:'icon-close',
				id:'btngujcetclose',
				handler: function (){
					FeedbackWindow.hide();
				}
			}
		]
});
	
	var varWidth =  (screen.width - FeedbackWindow.width)/2;
	FeedbackWindow.setPosition(varWidth,((screen.height/4)-180));
	FeedbackWindow.show();
	//SetSectionValue("add",sectionstore,'section_id','section_id');
	//Ext.getCmp('standard_id').focus(true,500);	
});
</script>
</div>
<?php require "_footer.php";?>