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

<div id="main-content">
	<script language="javascript" type="text/javascript">

		Ext.onReady(function () {
			Ext.QuickTips.init();
			var dt = new Date();

			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 firststore = new Ext.data.Store({
				proxy: new Ext.data.HttpProxy({ url: 'data/getstudentdata.php' }),
				reader: new Ext.data.JsonReader({ id: 'id', root: 'data' },
					[{ name: 'value', mapping: 'student_id' },
					{ name: 'text', mapping: 'student_name' }]),
				sortInfo: { field: 'value', direction: 'ASC' }
			});

			var secondstore = new Ext.data.Store({});

			var columnfirststore = new Ext.data.ArrayStore({
				fields: ['value', 'text'],
				data: Ext.student.column
			});

			var columnsecondstore = new Ext.data.Store({});

			var studentselection = new Ext.FormPanel({
				method: 'post',
				frame: true,
				standardSubmit: true,
				url: 'report-student-selection.php',
				bodyStyle: 'padding:5px',
				items: [{
					layout: 'column',
					items: [{
						columnWidth: .50, layout: 'form', labelWidth: 56,
						items: [{
							xtype: 'combo',
							name: 'branch_id',
							hiddenName: 'branch_hidden',
							id: 'branch_id',
							fieldLabel: 'Course ',
							forceSelection: true,
							displayField: 'branch_name',
							valueField: 'branch_id'
							, allowBlank: false
							, triggerAction: 'all'
							, mode: 'local'
							, store: branchstore
							, width: 170
							, selectOnFocus: true
							, tabIndex: 1
							, listeners: {
								'select': function (cmb, rec, idx) {
									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: 'branchyear_id',
							hiddenName: 'branchyear_hidden',
							id: 'branchyear_id',
							fieldLabel: 'Course Year ',
							forceSelection: true,
							lastQuery: '',
							displayField: 'branchyear_name',
							valueField: 'branchyear_id'
							, allowBlank: false
							, triggerAction: 'all'
							, mode: 'local'
							, store: yearstore
							, width: 170
							, selectOnFocus: true,
							tabIndex: 2,
							listeners: {
								select: {
									fn: function (combo, value) {
										
										firststore.load({
											params: {
												branch_id: Ext.getCmp('branch_id').getValue(),
												branchyear_id: combo.getValue()
											}
										});
										var branch = Ext.getCmp('branch_id').getValue();
									}
								}
							}
						}]
					},
					{
						columnWidth: .50, layout: 'form', labelWidth: 70,
						items: [{
							xtype: 'combo',
							name: 'year_id',
							hiddenName: 'year_hidden',
							id: 'year_id',
							fieldLabel: 'Batch Year ',
							forceSelection: true,
							lastQuery: '',
							displayField: 'year_name',
							valueField: 'year_id'
							, allowBlank: false
							, triggerAction: 'all'
							, mode: 'local'
							, store: batchyearstore
							, width: 170
							, selectOnFocus: true,
							tabIndex: 2,
							listeners: {
								select: {
									fn: function (combo, value) {
										firststore.load({
											params: {
												branch_id: Ext.getCmp('branch_id').getValue(),
												year_id: combo.getValue()
											}
										});
										var branch = Ext.getCmp('branch_id').getValue();
									}
								}
							}
						}, {
							xtype: 'combo',
							name: 'semester_id',
							hiddenName: 'semester_hidden',
							id: 'semester_id',
							fieldLabel: 'Semester ',
							forceSelection: false,
							lastQuery: '',
							disabled: true,
							displayField: 'semester_name',
							valueField: 'semester_id'
							, allowBlank: false
							, triggerAction: 'all'
							, mode: 'local'
							, store: semesterstore
							, width: 170
							, selectOnFocus: false,
							tabIndex: 2,
							listeners: {
								select: {
									fn: function (combo, value) {
										firststore.load({
											params: {
												branch_id: Ext.getCmp('branch_id').getValue(),
												semester_id: combo.getValue()
											}
										});
										var branch = Ext.getCmp('branch_id').getValue();
									}
								}
							}
						}]
					},
					{
						columnWidth: 1,
						layout: 'form',
						style: { margin: '0px 0px 0px 0px', padding: '0px 0px 0px 390px' },
						items: [{
							buttons: [{
								text: 'Reset',
								style: 'padding:0px 0px 0px 0px',
								handler: function () {
									studentselection.getForm().reset();
									firststore.removeAll();
									studentselection.getForm().findField('branch_id').focus(true, 500);
								}
							}]
						}]
					},
					{
						columnWidth: .15,
						layout: 'form',
						items: [{
							xtype: 'textfield',
							name: 'selstid',
							id: 'selstid',
							hiddenname: 'selstid',
							hidden: true
						}]
					},
					{
						columnWidth: .5,
						layout: 'form',
						items: [{
							xtype: 'textfield',
							name: 'blanklabel',
							id: 'blanklabel',
							hiddenname: 'blanklabel',
							hidden: true
						}]
					},
					{
						columnWidth: 1,
						layout: 'form',
						labelWidth: 15,
						items: [{
							xtype: 'itemselector'
							, name: 'itemselector'
							, fieldLabel: ''
							, multiselects:
								[{
									width: 250
									, height: 200
									, store: firststore
									, displayField: 'text'
									, valueField: 'value'
									, legend: 'Available Students '
								}, {
									width: 250
									, height: 200
									, store: secondstore, displayField: 'text'
									, valueField: 'value'
									, legend: 'Selected Students '
								}]
						}]
					},
					{
						columnWidth: 1,
						layout: 'form',
						labelWidth: 15,
						items: [{
							xtype: 'itemselector'
							, name: 'columnselector'
							, fieldLabel: ''
							, multiselects:
								[{
									width: 250
									, height: 200
									, store: columnfirststore
									, displayField: 'text'
									, valueField: 'value'
									, legend: 'Available Fields '
								}, {
									width: 250
									, height: 200
									, store: columnsecondstore
									, displayField: 'text'
									, valueField: 'value'
									, legend: 'Selected Fields '
								}
								]
						}]
					}]
				}]
			});
			var StudentSelectionWindow = new Ext.Window({
				title: 'Student Selection ',
				width: 580,
				height: 575,
				modal: true,
				border: false,
				layout: 'fit',
				closeAction: 'close',
				collapsible: true,
				items: studentselection,
				buttonAlign: 'center',
				buttons: [{
					text: 'Save',
					handler: function () {
						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 (studentselection.getForm().isValid()) {
							if (secondstore.getCount() <= 0) {
								Ext.Msg.alert('Message', 'Select at least one student');
							}
							else if (columnsecondstore.getCount() <= 0) {
								Ext.Msg.alert('Message', 'Select at least one Field');
							}
							else {
								var branch_hidden = studentselection.getForm().findField('branch_hidden').getValue();
								var year_hidden = studentselection.getForm().findField('year_hidden').getValue();
								var branchyear_hidden = studentselection.getForm().findField('branchyear_hidden').getValue();
								var semester_hidden = studentselection.getForm().findField('semester_hidden').getValue();
								var itemselector = studentselection.getForm().findField('itemselector').getValue();
								var columnselector = studentselection.getForm().findField('columnselector').getValue();

								var redirect = 'report-student-selection.php?branch_hidden=' + branch_hidden  + '&year_hidden=' +
								 year_hidden +'&branchyear_hidden=' + branchyear_hidden+ '&semester_hidden=' + semester_hidden +
								'&itemselector=' + itemselector + '&columnselector=' + columnselector;
								window.location = redirect;
							}
						}
					}
				}, {
					text: 'Close',
					handler: function () {
						StudentSelectionWindow.close();
					}
				}]
			});
			var varWidth = (screen.width - StudentSelectionWindow.width) / 2;
			StudentSelectionWindow.setPosition(varWidth, ((screen.height / 4) - 180));
			StudentSelectionWindow.show();
		});
	</script>
	<div align="center"></div>
</div>
<!-- end custom CSS/JS -->
<?php require "_footer.php"; ?>