<?php
require "_header.php";
require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
?>
<div id="main-content">
	<script type="text/javascript">
		var labelArray;
		labelArray = [
			['Course<span class="comp">*</span> '],
			['Batch Year<span class="comp">*</span> '],
			['Semester<span class="comp">*</span> '],
			['Course Year<span class="comp">*</span> '],
			['Student Name<span class="comp">*</span> '],
			['Date<span class="comp">*</span> '],
		];
		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 studentstore = new Ext.data.JsonStore({
			url: 'data/getstudent-feesrecive.php',
			root: 'data',
			totalProperty: 'total',
			fields: [
				{ name: 'student_id', type: 'int' },
				{ name: 'student_name', type: 'string' }
			]
		});
		Ext.onReady(function () {
			Ext.QuickTips.init();
			var StudentScholarshipForm = new Ext.FormPanel({
				labelWidth: 90,
				url: 'student_scholarship_report.php',
				frame: true,
				autoHeight: true,
				standardSubmit: true,
				title: '',
				bodyStyle: 'padding:6px 6px 0',
				layout: 'form',
				items: [
					{
						xtype: 'combo',
						name: 'branch_name',
						id: 'branch_name',
						hiddenName: 'branch_hidden',
						fieldLabel: labelArray[0],
						displayField: 'branch_name',
						valueField: 'branch_id',
						width: 200,
						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();
								Ext.getCmp('student_id').reset();
								studentstore.removeAll();
								
								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: 200,
						allowBlank: true,
						store: batchyearstore,
						listeners: {
                                'select': function (cmb, rec, idx) {
									Ext.getCmp('year_disp').setValue(this.getRawValue());
                                    if (Ext.getCmp('branch_name').getValue() != "") {
                                       // Ext.getCmp('student_name').reset();
                                        studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_name').getValue(), 'year_id': Ext.getCmp('year_name').getValue() } });
                                    } else {
                                        this.reset();
                                    }
                                }
                            }
					},
					{
						xtype: 'combo',
						name: 'semester_name',
						id: 'semester_name',
						hiddenName: 'semester_hidden',
						fieldLabel: labelArray[2],
						displayField: 'semester_name',
						valueField: 'semester_id',
						lastQuery: '',
						disabled: true,
						triggerAction: 'all',
						mode: 'local',
						width: 200,
						allowBlank: true,
						store: semesterstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								Ext.getCmp('semester_disp').setValue(this.getRawValue());
								if (Ext.getCmp('branch_name').getValue() != "") {
									Ext.getCmp('student_id').reset();
								
								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					},
					{
						xtype: 'combo',
						name: 'branchyear_name',
						id: 'branchyear_name',
						hiddenName: 'branchyear_hidden',
						fieldLabel: labelArray[3],
						displayField: 'branchyear_name',
						valueField: 'branchyear_id',
						lastQuery: '',
						triggerAction: 'all',
						mode: 'local',
						width: 200,
						allowBlank: true,
						store: yearstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								Ext.getCmp('branchyear_disp').setValue(this.getRawValue());
								if (Ext.getCmp('branch_name').getValue() != "") {
									Ext.getCmp('student_id').reset();
								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					},
					{
						xtype: 'combo',
						name: 'student_id',
						id: 'student_id',
						hiddenName: 'student_hidden',
						fieldLabel: labelArray[4],
						displayField: 'student_name',
						valueField: 'student_id',
						width: 200,
						triggerAction: 'all',
						mode: 'local',
						allowBlank: true,
						store: studentstore,
						listeners: {
                                'select': function (cmb, rec, idx) {
									Ext.getCmp('student_disp').setValue(this.getRawValue());
                                    if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('year_name').getValue() != "") {
                                    }
                                    else if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('branchyear_name').getValue() != "") {
                                    }
                                    else if (Ext.getCmp('branch_name').getValue() != "" && Ext.getCmp('semester_name').getValue() != "") {
                                    }
                                    else {
                                        this.reset();
                                    }
                                }
                            }
					},{
					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,
				},{
					xtype: 'displayfield',
					name: 'student_disp',
                    id: 'student_disp',
                   hidden:true,
				}
				]
			});
			var StudentScholarshipWindow = new Ext.Window({
				title: 'Student Scholarship Report',
				autoHeight: true,
				width: 350,
				modal: true,
				layout: 'fit',
				border: false,
				closeAction: 'close',
				collapsible: 'true',
				items: StudentScholarshipForm,
				buttonAlign: 'center',
				buttons: [{
					text: 'View Report',
					tabIndex: 2,
					iconCls: 'new-tab',
					handler: function (b, e) {
						var branch_hidden = StudentScholarshipForm.getForm().findField('branch_hidden').getValue();
						var year_hidden = StudentScholarshipForm.getForm().findField('year_hidden').getValue();
						var semester_hidden = StudentScholarshipForm.getForm().findField('semester_hidden').getValue();
						var branchyear_hidden = StudentScholarshipForm.getForm().findField('branchyear_hidden').getValue();
						var student_hidden = StudentScholarshipForm.getForm().findField('student_hidden').getValue();
						var branch_disp=StudentScholarshipForm.getForm().findField('branch_disp').getValue();
						var year_disp=StudentScholarshipForm.getForm().findField('year_disp').getValue();
						var branchyear_disp=StudentScholarshipForm.getForm().findField('branchyear_disp').getValue();
						var semester_disp=StudentScholarshipForm.getForm().findField('semester_disp').getValue();
						var student_disp=StudentScholarshipForm.getForm().findField('student_disp').getValue();
							var redirect = 'student_scholarship_report.php?branch_hidden='+branch_hidden + '&semester_hidden='+semester_hidden + 
							'&year_hidden='+year_hidden   + '&student_hidden='+student_hidden +'&branchyear_hidden='+branchyear_hidden + '&branch_disp='+branch_disp+ '&year_disp='+year_disp+ '&branchyear_disp='+branchyear_disp 
							+ '&semester_disp='+semester_disp + '&student_disp='+student_disp; 
                			window.location = redirect;
						
					}
				}, {
					text: 'Reset',
					tabIndex: 3,
					iconCls: 'icon-reset',
					handler: function () {
						StudentScholarshipForm.getForm().reset();
						Ext.getCmp('student_id').focus(true, 500);
					}
				}, {
					text: 'Close',
					tabIndex: 4,
					iconCls: 'icon-close',
					handler: function () {
						StudentScholarshipWindow.close();
					}
				}]
			});
			var varWidth = (screen.width - StudentScholarshipWindow.width) / 2;
			StudentScholarshipWindow.setPosition(varWidth, ((screen.height / 4) - 85));
			StudentScholarshipWindow.show();
			Ext.getCmp('student_id').focus(true, 1000);
		});
	</script>
</div>
<?php require "_footer.php"; ?>