<?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 '],
			['Batch Year '],
			['Course Year '],
			['Semester '],
			['Student Name '],
			['Enrollment Reg No '],
		];
		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 branch_disp = new Ext.form.TextField({
			name: 'branch_disp',
			id: 'branch_disp',
			hidden: true
		});


		var year_disp = new Ext.form.TextField({
			name: 'year_disp',
			id: 'year_disp',
			hidden: true
		});


		var branchyear_disp = new Ext.form.TextField({
			name: 'branchyear_disp',
			id: 'branchyear_disp',
			hidden: true
		});

		var semester_disp = new Ext.form.TextField({
			name: 'semester_disp',
			id: 'semester_disp',
			hidden: true
		});

		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'
			}, {
				name: 'student_gturegno',
				type: 'string'
			}]
		});

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






			var StudentPerfomanceForm = new Ext.FormPanel({
				labelWidth: 90,
				//	url: 'save-birth-certificate.php',
				url: 'report-student-bonafied-records-result.php',
				frame: true,
				autoHeight: true,
				standardSubmit: true,
				title: '',
				bodyStyle: 'padding:6px 6px 0',
				layout: 'form',
				items: [
					{
						xtype: 'combo',
						name: 'branch_id',
						id: 'branch_id',
						hiddenName: 'branch_hidden',
						fieldLabel: labelArray[0],
						displayField: 'branch_name',
						valueField: 'branch_id',
						width: 150,
						triggerAction: 'all',
						mode: 'local',
						allowBlank: true,
						store: branchstore,
						listeners: {
							'select': function (cmb, rec, idx) {

								Ext.getCmp('semester_id').reset();
								Ext.getCmp('year_id').reset();
								Ext.getCmp('branchyear_id').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_id');
								if (cmb.getValue() == 3 || cmb.getValue() == 5) {
									semesterCombo.enable();
								} else {
									semesterCombo.disable();
									semesterCombo.reset();
								}
								
							}
						}
						}, 
					
				
					
						{
						xtype: 'combo',
						name: 'year_id',
						id: 'year_id',
						hiddenName: 'year_hidden',
						fieldLabel: labelArray[1],
						displayField: 'year_name',
						valueField: 'year_id',
						lastQuery: '',
						triggerAction: 'all',
						mode: 'local',
						width: 150,
						allowBlank: true,
						store: batchyearstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								if (Ext.getCmp('branch_id').getValue() != "") {
									// Ext.getCmp('student_name').reset();
									studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_id').getValue(), 'year_id': Ext.getCmp('year_id').getValue() } });
								} else {
									this.reset();
								}
							}
						}
					}, {
						xtype: 'combo',
						name: 'branchyear_id',
						id: 'branchyear_id',
						hiddenName: 'branchyear_hidden',
						fieldLabel: labelArray[2],
						displayField: 'branchyear_name',
						valueField: 'branchyear_id',
						lastQuery: '',
						triggerAction: 'all',
						mode: 'local',
						width: 150,
						allowBlank: true,
						store: yearstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								if (Ext.getCmp('branch_id').getValue() != "") {
									studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_id').getValue(), 'year_id': Ext.getCmp('year_id').getValue(), 'branchyear_id': Ext.getCmp('branchyear_id').getValue() } });

								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					}, {
						xtype: 'combo',
						name: 'semester_id',
						id: 'semester_id',
						hiddenName: 'semester_hidden',
						fieldLabel: labelArray[3],
						displayField: 'semester_name',
						valueField: 'semester_id',
						lastQuery: '',
						disabled: true,
						triggerAction: 'all',
						mode: 'local',
						width: 150,
						allowBlank: true,
						store: semesterstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								if (Ext.getCmp('branch_id').getValue() != "") {
									studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_id').getValue(), 'year_id': Ext.getCmp('year_id').getValue(), 'semester_id': Ext.getCmp('semester_id').getValue() } });

								} 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: 150,
						triggerAction: 'all',
						mode: 'local',
						allowBlank: true,
						store: studentstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								if (Ext.getCmp('branch_id').getValue() != "" && Ext.getCmp('year_id').getValue() != "") {
									Ext.getCmp('student_gturegno').setValue(studentstore.getAt(idx).data.student_gturegno);
								}
								else if (Ext.getCmp('branch_id').getValue() != "" && Ext.getCmp('branchyear_id').getValue() != "") {
									Ext.getCmp('student_gturegno').setValue(studentstore.getAt(idx).data.student_gturegno);
								}
								else if (Ext.getCmp('branch_id').getValue() != "" && Ext.getCmp('semester_id').getValue() != "") {
									Ext.getCmp('student_gturegno').setValue(studentstore.getAt(idx).data.student_gturegno);
								}
								else {
									this.reset();
								}
							}
						}
					},
					{
                        xtype: 'textfield',
                        name: 'student_gturegno',
                        id: 'student_gturegno',
                        fieldLabel: labelArray[5],
                        allowBlank: true,
                        width: 150
                    },
					
				]
			});
			StudentPerfomanceForm.getForm().findField('student_gturegno').on('blur', function () {
            var varstudent_gturegno = StudentPerfomanceForm.getForm().findField('student_gturegno').getValue();
            if (varstudent_gturegno != "") {
                StudentPerfomanceForm.getForm().load({
                    params: {
                        grno: varstudent_gturegno,
                        branch_id: StudentPerfomanceForm.getForm().findField('branch_id').getValue()
                    },
                    url: 'data/get-enrollmentno.php',
                    waitMsg: 'Loading',
                    failure: function () {
                        Ext.MessageBox.show({
                            title: 'Error',
                            msg: 'Invalid GR No.',
                            buttons: Ext.MessageBox.OK,
                            icon: Ext.MessageBox.ERROR
                        });
                        StudentPerfomanceForm.getForm().findField('student_gturegno').reset();
                        StudentPerfomanceForm.getForm().findField('student_id').reset();
                        StudentPerfomanceForm.getForm().findField('student_gturegno').focus(true, 4000)
                    }
                });
            }
        });
		
			var StudentPerfomanceWindow = new Ext.Window({
				title: 'Student Bonafied Records',
				autoHeight: true,
				width: 310,
				modal: true,
				layout: 'fit',
				border: false,
				closeAction: 'close',
				collapsible: 'true',
				items: StudentPerfomanceForm,
				buttonAlign: 'center',
				buttons: [{
					text: 'View Report',
					tabIndex: 2,
					iconCls: 'new-tab',
					handler: function (b, e) {
						var branch_hidden = StudentPerfomanceForm.getForm().findField('branch_hidden').getValue();
						var year_hidden = StudentPerfomanceForm.getForm().findField('year_hidden').getValue();
						var branchyear_hidden = StudentPerfomanceForm.getForm().findField('branchyear_hidden').getValue();
						var semester_hidden = StudentPerfomanceForm.getForm().findField('semester_hidden').getValue();
						var student_hidden = StudentPerfomanceForm.getForm().findField('student_hidden').getValue();
						var student_gturegno = StudentPerfomanceForm.getForm().findField('student_gturegno').getValue();

						if (branch_hidden != "" && year_hidden != "" && branchyear_hidden != "") {
							var redirect = 'report-student-bonafied-records-result.php?branch_hidden=' + branch_hidden + '&branchyear_hidden=' + branchyear_hidden + '&student_hidden=' + student_hidden + '&student_gturegno=' + student_gturegno  ;

						}
						if (branch_hidden != "" && year_hidden != "" && branchyear_hidden != "" && semester_hidden != "") {
							var redirect = 'report-student-bonafied-records-result.php?branch_hidden=' + branch_hidden + '&branchyear_hidden=' + branchyear_hidden + '&semester_hidden=' + semester_hidden + '&student_hidden=' + student_hidden + '&student_gturegno=' + student_gturegno  ;

						}
						window.location = redirect;
					}
				}, {
					text: 'Reset',
					tabIndex: 3,
					iconCls: 'icon-reset',
					handler: function () {
						StudentPerfomanceForm.getForm().reset();
						Ext.getCmp('student_gturegno').focus(true, 500);
					}
				}, {
					text: 'Close',
					tabIndex: 4,
					iconCls: 'icon-close',
					handler: function () {
						StudentPerfomanceWindow.close();
					}
				}]
			});


			var varWidth = (screen.width - StudentPerfomanceWindow.width) / 2;
			StudentPerfomanceWindow.setPosition(varWidth, ((screen.height / 4) - 85));
			StudentPerfomanceWindow.show();
			Ext.getCmp('student_gturegno').focus(true, 1000);
		});
	</script>
</div>
<?php require "_footer.php"; ?>