<?php
require "_header.php";
require "includeMultiSelect.php";
require "data/combo_semester.php";
require "data/combo_login.php";
require "data/combo_branchyear.php";
?>
<div id="main-content">
	<style>
		label.myBold {
			font-weight: bold;
			color: #006;
			font-size: 14px;
		}
	</style>

	<div id="abcd">

		<script language="javascript" type="text/javascript">
			Ext.onReady(function () {
				Ext.QuickTips.init();

				var labelArray;
				labelArray = [
					['Course:<span class="comp">*</span>'],
					['Course Year:<span class="comp">*</span>'],
					['Semester:<span class="comp">*</span>'],
					['Enrollment No :<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_left = new Ext.data.JsonStore({
					url: 'data/getstudentdataforIcard.php',
					root: 'data',
					totalProperty: 'total',
					fields: [{ name: 'value', mapping: 'student_id' }, { name: 'text', mapping: 'student_name' }]
				});

				studentstore_right = new Ext.data.JsonStore({
					url: 'data/getstudentdataforIcard.php',
					root: 'data',
					totalProperty: 'total',
					fields: [{ name: 'value', mapping: 'student_id' }, { name: 'text', mapping: 'student_name' }]
				});



				var studentform = new Ext.FormPanel({
        id: 'studentform',
        frame: true,
        labelAlign: 'left',
        bodyStyle: 'padding:5px',
        url: 'report-form-student-identity-result.php',
        standardSubmit: true,
        layout: 'column',
        items: [{
            columnWidth: .50,
            labelWidth: 112,
            layout: 'form',
            items: [{
                xtype: 'combo',
                labelSeparator: '',
                fieldLabel: 'Course :<span class="comp">*</span>',
                name: 'branch_id',
                id: 'branch_id',
                hiddenName: 'branch_id',
                store: branchstore,
                displayField: 'branch_name',
                valueField: 'branch_id',
                width: 200,
                typeAhead: true,
                selectOnFocus: true,
                forceSelection: true,
                mode: 'local',
                triggerAction: 'all',
                emptyText: 'Select Branch...',
                editable: false,
                allowBlank: false,
                listeners: {
                    select: {
                        fn: function (cmb, rec, idx) {
                            // Filter yearstore based on selected branch
                            var branchId = cmb.getValue();
                            var filteredBranchYearData = Ext.year.year.filter(function (year) {
                                return year[0] === branchId; // Filter by branch ID
                            });
                            var filteredSemesterData = Ext.semester.semester.filter(function (semester) {
                                return semester[0] === branchId; // Filter by branch ID
                            });

                            // Update yearstore and semesterstore with the filtered data
                            yearstore.loadData(filteredBranchYearData);
                            semesterstore.loadData(filteredSemesterData);

                            Ext.getCmp('branchyear_id').reset();
                            Ext.getCmp('semester_id').reset();
                            Ext.getCmp('year_id').reset();
							Ext.getCmp('student_gturegno').reset();

                            studentform.getForm().findField('branch_name').setValue(cmb.getRawValue());
                            studentform.getForm().findField('branchyear_id').disable();
                            studentform.getForm().findField('semester_id').disable();
							studentform.getForm().findField('student_gturegno').disable();
                        }
                    }
                }
            }]
        }, {
            columnWidth: .50,
            labelWidth: 112,
            layout: 'form',
            items: [{
                xtype: 'combo',
                name: 'year_id',
                hiddenName: 'year_hidden',
                id: 'year_id',
                tabIndex: 2,
                fieldLabel: 'Batch Year',
                forceSelection: false,
                displayField: 'year_name',
                valueField: 'year_id',
                allowBlank: true,
                triggerAction: 'all',
                mode: 'local',
                store: batchyearstore,
                width: 200,
                selectOnFocus: true,
                listeners: {
                    select: function (cmb, rec, idx) {
                        Ext.getCmp('semester_id').reset();
                        Ext.getCmp('branchyear_id').enable();

                        studentform.getForm().findField('addressradiotypeid3').enable();
                        studentform.getForm().findField('addressradiotypeid2').enable();
                        studentform.getForm().findField('addressradiotypeid1').enable();
                    }
                }
            }]
        }, {
            columnWidth: .15,
            labelWidth: 100,
            layout: 'form',
            items: [{
                xtype: 'radio',
                hideLabel: true,
                name: 'addressradiotype',
                id: 'addressradiotypeid3',
                Value: '2',
                checked: true,
                disabled: true,
                boxLabel: labelArray[1],
                handler: function () {
                    if (this.checked) {
                        studentform.getForm().findField('student_gturegno').setValue('');
                        studentform.getForm().findField('student_gturegno').disable();
						studentform.getForm().findField('semester_id').reset();
                        studentform.getForm().findField('semester_id').disable();
                        studentform.getForm().findField('branchyear_id').enable();
                        studentform.getForm().findField('branchyear_id').reset();
                    }
                }
            }]
        }, {
            columnWidth: .35,
            labelWidth: 100,
            layout: 'form',
            items: [{
                xtype: 'combo',
                hideLabel: true,
                disabled: true,
                name: 'branchyear_id',
                hiddenName: 'branchyear_id',
                id: 'branchyear_id',
                forceSelection: true,
                store: yearstore,
                displayField: 'branchyear_name',
                valueField: 'branchyear_id',
                triggerAction: 'all',
                mode: 'local',
                width: 200,
                emptyText: 'Select Branch year...',
                allowBlank: false,
                editable: false,
                listeners: {
                    select: {
                        fn: function (cmb, rec, idx) {
                            if (Ext.getCmp('branch_id').getValue() != "") {
                                Ext.getCmp('semester_id').reset();
                                Ext.getCmp('student_gturegno').reset();
                            } else {
                                alert('Select Branch First')
                                this.reset();
                            }
                            studentform.getForm().findField('branchyear_name').setValue(cmb.getRawValue());
                        }
                    }
                }
            }]
        }, {
            columnWidth: .15,
            labelWidth: 120,
            layout: 'form',
            items: [{
                xtype: 'radio',
                hideLabel: true,
                name: 'addressradiotype',
                id: 'addressradiotypeid1',
                Value: '1',
                disabled: true,
                boxLabel: labelArray[3],
                handler: function () {
                    if (this.checked) {
                        studentform.getForm().findField('student_gturegno').setValue('');
                        studentform.getForm().findField('student_gturegno').enable();

                        studentform.getForm().findField('semester_id').reset();
                        studentform.getForm().findField('semester_id').disable();

                        studentform.getForm().findField('branchyear_id').reset();
                        studentform.getForm().findField('branchyear_id').disable();
                    }
                }
            }]
        }, {
            columnWidth: .35,
            labelWidth: 100,
            layout: 'form',
            items: [{
                xtype: 'textfield',
                name: 'student_gturegno',
                hideLabel: true,
                id: 'student_gturegno',
                width: 200,
                allowBlank: false,
                disabled: true,
                allowNegative: false,
                allowDecimals: false
            }]
        }, {
            columnWidth: .15,
            labelWidth: 100,
            layout: 'form',
            items: [{
                xtype: 'radio',
                hideLabel: true,
                name: 'addressradiotype',
                id: 'addressradiotypeid2',
                Value: '2',
                disabled: true,
                boxLabel: labelArray[2],
                handler: function () {
                    if (this.checked) {
                        studentform.getForm().findField('student_gturegno').setValue('');
                        studentform.getForm().findField('student_gturegno').disable();
                        studentform.getForm().findField('semester_id').enable();
                        studentform.getForm().findField('semester_id').reset();
						studentform.getForm().findField('branchyear_id').enable();
                        studentform.getForm().findField('branchyear_id').reset();
                    }
                }
            }]
        }, {
            columnWidth: .35,
            labelWidth: 100,
            layout: 'form',
            items: [{
                xtype: 'combo',
                hideLabel: true,
                disabled: true,
                name: 'semester_id',
                hiddenName: 'semester_id',
                id: 'semester_id',
                store: semesterstore,
                displayField: 'semester_name',
                valueField: 'semester_id',
                triggerAction: 'all',
                mode: 'local',
                tabindex: 4,
                width: 200,
                emptyText: 'Select Semester...',
                allowBlank: false,
                editable: false,
                listeners: {
                    select: {
                        fn: function (cmb, rec, idx) {
                            if (Ext.getCmp('branch_id').getValue() != "") {
                                Ext.getCmp('branchyear_id').reset();
                                Ext.getCmp('student_gturegno').reset();
                            } else {
                                alert('Select Branch First')
                                this.reset();
                            }
                            studentform.getForm().findField('semester_name').setValue(cmb.getRawValue());
                        }
                    }
                }
						}]
					}, {
						columnWidth: .35,
						labelWidth: 100,
						layout: 'form',
						items: [{
							xtype: 'button',
							id: 'btnGenerate',
							iconCls: 'icon-view',
							text: 'Show Student',
							tabIndex: 6,
							handler: function () {

								studentstore_left.load({
									params: {
										Year: Ext.getCmp('year_id').getValue(),
										branch: Ext.getCmp('branch_id').getValue(),
										BranchyearId: Ext.getCmp('branchyear_id').getValue(),
										SemesterId: Ext.getCmp('semester_id').getValue(),
										student_gturegno: Ext.getCmp('student_gturegno').getValue()
									}
								});
							}

						}, {
							xtype: 'textfield',
							name: 'semester_name',
							id: 'semester_name',
							hidden: true,
							width: 1
						},
						{
							xtype: 'textfield',
							name: 'branchyear_name',
							id: 'branchyear_name',
							hidden: true,
							width: 1
						}, {
							xtype: 'textfield',
							name: 'branch_name',
							id: 'branch_name',
							hidden: true,
							width: 1
						}]
					},
					{
						columnWidth: 1,
						layout: 'form',
						labelWidth: 10,
						bodyStyle: Ext.isIE ? 'padding:10px 0 0 0;' : 'padding-top:10px;',
						items: [{
							xtype: 'itemselector',
							name: 'studentlist_left',
							id: 'studentlist_left',
							fieldLabel: '',
							multiselects: [{
								name: 'first',
								id: 'first',
								width: 370,
								height: 200,
								store: studentstore_left,
								displayField: 'text',
								valueField: 'value',
								legend: ''
							}, {
								width: 370,
								height: 200,
								store: studentstore_right,
								displayField: 'text',
								valueField: 'value',
								legend: ''
							}]
						}]
					}, {
						columnWidth: 1,
						layout: 'form',
						labelWidth: 10,
						items: [{
							xtype: 'itemselector',
							name: 'studentlist_right',
							id: 'studentlist_right',
							fieldLabel: '',
							hidden: true,
							multiselects: [{
								width: 225,
								height: 200,
								store: studentstore_right,
								displayField: 'text',
								valueField: 'value',
								legend: ''
							}, {
								width: 225,
								height: 200,
								store: studentstore_left,
								displayField: 'text',
								valueField: 'value',
								legend: ''
							}]
						}]
					}]
				});

				studentstore_right.on({
					'afterload': {
						fn: function (store, options) {
							if (studentstore_right.getCount() <= 0 && studentstore_left.getCount() <= 0) {
								Ext.MessageBox.show({
									title: 'Error',
									msg: 'There is no Student Found in this Selection',
									buttons: Ext.MessageBox.OK,
									icon: Ext.MessageBox.ERROR
								});
							}
						}
					}
				});

				var StudentLCWindow = new Ext.Window({
					title: "I-card Generation",
					width: 820,
					height: 400,
					border: false,
					modal: true,
					layout: 'fit',
					closeAction: 'close',
					collapsible: true,
					items: studentform,
					buttonAlign: 'center',
					buttons: [{
						text: 'View Report',
						tabIndex: 7,
						handler: function (b, e) {
                            Ext.getCmp('branchyear_id').setValue(Ext.getCmp('branchyear_id').getRawValue());
						Ext.getCmp('year_id').setValue(Ext.getCmp('year_id').getRawValue());
						Ext.getCmp('semester_id').setValue(Ext.getCmp('semester_id').getRawValue());
						Ext.getCmp('branch_id').setValue(Ext.getCmp('branch_id').getRawValue());
						if (studentform.getForm().isValid()) {
							if (studentstore_right.getCount() <= 0) {
								Ext.Msg.alert('Message', 'Select at least one student');
							}
							
                            else {
							var studentlist_left = studentform.getForm().findField('studentlist_left').getValue();
							var branch_id = studentform.getForm().findField('branch_id').getValue();
							var student_gturegno = studentform.getForm().findField('student_gturegno').getValue();

							var semester_id = studentform.getForm().findField('semester_id').getValue();
							var semester_name = studentform.getForm().findField('semester_name').getValue();

							var branchyear_id = studentform.getForm().findField('branchyear_id').getValue();
							var branchyear_name = studentform.getForm().findField('branchyear_name').getValue();

							var redirect = 'report-form-student-identity-result.php?studentlist_left=' + studentlist_left + '&branch_id=' + branch_id + '&student_gturegno=' + student_gturegno + '&branchyear_id=' + branchyear_id + '&branchyear_name=' + branchyear_name + '&semester_id=' + semester_id + '&semester_name=' + semester_name;
							window.location = redirect;
                            }}
						}
					}, {
						text: 'Reset',
						tabIndex: 8,
						handler: function (b, e) {
							studentform.getForm().reset();
							studentform.getForm().findField('branch_id').focus(true, 500);
						}
					}, {
						text: 'Close',
						tabIndex: 9,
						handler: function () {
							StudentLCWindow.close();
						}
					}]
				});
				var varWidth = (screen.width - StudentLCWindow.width) / 2;
				StudentLCWindow.setPosition(varWidth, ((screen.height / 4) - 110));
				StudentLCWindow.show();
				studentform.getForm().findField('branch_id').focus(true, 500);
				Ext.getCmp('branch_id').focus(true, 1000);
			});
		</script>
	</div>
</div>
<?php require "_footer.php"; ?>