<?php 
	require "_header.php"; 
	require "data/combo_student.php";
	require "data/combo_semester.php";
	require "data/combo_branchyear.php";
?>

<script type="text/javascript">
var Upload_Fields = [
	{name:'upload_id',type: 'int'},
	{name:'branch_id',type: 'int'},
	{name:'branch_name',type: 'string'},
	{name:'year_id',type: 'int'},
	{name:'year_name',type: 'string'},
	{name:'branchyear_id',type: 'int'},
	{name:'branchyear_name',type: 'string'},
	{name:'semester_id',type: 'int'},
	{name:'semester_name',type: 'string'},
	{name:'subject_id',type: 'int'},
	{name:'subject_name',type: 'string'},
	{name:'title'},
	{name:'description'},
	{name:'active'}
]
var labelArray;
		labelArray = [
			['Course <span class="comp">*</span>'],
			['Batch Year <span class="comp">*</span>'],
			['Course Year <span class="comp">*</span>'],
			['Semester <span class="comp">*</span>'],
			['Subject ']
		];

var UploadStore = new Ext.data.JsonStore({
    url: 'data/upload-grid-data.php',
    root: 'data',
    fields: Upload_Fields,
    autoLoad: true
});

Ext.onReady(function(){
	Ext.QuickTips.init();


	var branchstore = new Ext.data.ArrayStore({
			fields: ['branch_id', 'branch_name'],
			data: Ext.semester.branch
		});

		var batchyearstore = new Ext.data.ArrayStore({
			fields: ['year_id', 'year_name'],
			data: Ext.semester.yearname
		});

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

		var yearstore = new Ext.data.ArrayStore({
			fields: ['branch_id', 'branchyear_id', 'branchyear_name'],
			data: Ext.year.year
		});

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

	var semesterform = new Ext.FormPanel({	
		id: 'semesterform',
		frame: true,
		standardSubmit:true,
		url: 'material_report_result.php',
    	labelAlign: 'left',
    	layout:'column',        
		items :[{
			columnWidth: 1,
			layout: 'form',
			labelWidth:85,
			items:[{
					xtype: 'combo',
					name: 'branch_name',
					id: 'branch_name',
					hiddenName: 'branch_hidden',
					fieldLabel: labelArray[0],
					displayField: 'branch_name',
					valueField: 'branch_id',
					width: 180,
					triggerAction: 'all',
					mode: 'local',
					allowBlank: true,
					store: branchstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('branch_disp').setValue(this.getRawValue());
							Ext.getCmp('semester_name').reset();
							Ext.getCmp('year_name').reset();
							Ext.getCmp('branchyear_name').reset();
							
							semesterstore.filter('branch_id', cmb.getValue(), false, true, true);
							yearstore.filter('branch_id', cmb.getValue(), false, true, true);
							var semesterCombo = Ext.getCmp('semester_name');
							if (cmb.getValue() == 3 || cmb.getValue() == 5) {
								semesterCombo.enable();
							} else {
								semesterCombo.disable();
								semesterCombo.reset();
							}
						}
					}
				}, {
					xtype: 'combo',
					name: 'year_name',
					id: 'year_name',
					hiddenName: 'year_hidden',
					fieldLabel: labelArray[1],
					displayField: 'year_name',
					valueField: 'year_id',
					lastQuery: '',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: true,
					store: batchyearstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('year_disp').setValue(this.getRawValue());	
						}
					}
					
				}, {
					xtype: 'combo',
					name: 'branchyear_name',
					id: 'branchyear_name',
					hiddenName: 'branchyear_hidden',
					fieldLabel: labelArray[2],
					displayField: 'branchyear_name',
					valueField: 'branchyear_id',
					lastQuery: '',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: true,
					store: yearstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('branchyear_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_name').getValue() != "") {
								
							} else {
								alert('Select Branch First')
								this.reset();
							}
						}
					}
				}, {
					xtype: 'combo',
					name: 'semester_name',
					id: 'semester_name',
					hiddenName: 'semester_hidden',
					fieldLabel: labelArray[3],
					displayField: 'semester_name',
					valueField: 'semester_id',
					lastQuery: '',
					disabled: true,
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: true,
					store: semesterstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('semester_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_name').getValue() != "") {
								
							} else {
								alert('Select Branch First')
								this.reset();
							}
						}
					}
				},{
					xtype: 'combo',
					name: 'subject_name',
					id: 'subject_name',
					hiddenName: 'subject_hidden',
					fieldLabel: labelArray[4],
					displayField: 'subject_name',
					valueField: 'subject_id',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: true,
					store: subjectstore	
				},{
					xtype: 'displayfield',
					name: 'branch_disp',
                    id: 'branch_disp',
                   hidden:true,
				},
				{
					xtype: 'displayfield',
					name: 'year_disp',
                    id: 'year_disp',
                   hidden:true,
				},
				{
					xtype: 'displayfield',
					name: 'branchyear_disp',
                    id: 'branchyear_disp',
                   hidden:true,
				},
				{
					xtype: 'displayfield',
					name: 'semester_disp',
                    id: 'semester_disp',
                   hidden:true,
				}
		   
			]}]
    });

	var SemesterWindow = new Ext.Window({
		title: 'Uploaded Material Report',
		width:330,		
		height:210,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: semesterform,
		buttons:[
			{
				text: 'View Report', 
				name:'btnSave',
				tabIndex:4,
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
				
					var branch_hidden = semesterform.getForm().findField('branch_hidden').getValue();
					var year_hidden = semesterform.getForm().findField('year_hidden').getValue();
					var branchyear_hidden = semesterform.getForm().findField('branchyear_hidden').getValue();
					var semester_hidden = semesterform.getForm().findField('semester_hidden').getValue();
					var subject_hidden=semesterform.getForm().findField('subject_hidden').getValue();
					var branch_disp=semesterform.getForm().findField('branch_disp').getValue();
					var year_disp=semesterform.getForm().findField('year_disp').getValue();
					var branchyear_disp=semesterform.getForm().findField('branchyear_disp').getValue();
					var semester_disp=semesterform.getForm().findField('semester_disp').getValue();
		//	alert(show_mobile_no);
			
		var redirect = 'material_report_result.php?branch_hidden='+branch_hidden +
 						'&year_hidden='+year_hidden+'&branchyear_hidden='+branchyear_hidden+ 
 						'&semester_hidden='+semester_hidden + '&subject_hidden='+subject_hidden 
						+ '&branch_disp='+branch_disp+ '&year_disp='+year_disp+ '&branchyear_disp='+branchyear_disp 
						+ '&semester_disp='+semester_disp  ; 
                window.location = redirect;
				
				}	
			},
			
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:6,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					semesterform.getForm().reset();
					
					
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:7,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					SemesterWindow.close();
				}
			}
		]
	});
	var varWidth =  (screen.width - SemesterWindow.width)/2;
	SemesterWindow.setPosition(varWidth,((screen.height/4)-85));
	SemesterWindow.show();
//	Ext.getCmp('subject_id').focus(true,1000);

});
</script>

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