<?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>'],
			['Course Year <span class="comp">*</span>'],
			['Semester <span class="comp">*</span>'],
			['Subject <span class="comp">*</span>'],
			['Batch name <span class="comp">*</span>'],
			['Month '],
			['Order By ']

		];

		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 month_name = new Array(12);
		month_name[0] = "January"; month_name[1] = "February"; month_name[2] = "March"; month_name[3] = "April";
		month_name[4] = "May"; month_name[5] = "June"; month_name[6] = "July"; month_name[7] = "August";
		month_name[8] = "September"; month_name[9] = "October"; month_name[10] = "November"; month_name[11] = "December";

		var date = new Date();
		var currmonthno = date.getMonth();
		var currmonth = month_name[date.getMonth()];
		var year = date.getFullYear();
		currmonthno = currmonthno + 1;

		var monthstore = new Ext.data.ArrayStore({
			fields: ['valuemonth', 'displaymonth'],
			data: [['1', 'January'], ['2', 'February'], ['3', 'March'], ['4', 'April'], ['5', 'May'], ['6', 'June'],
			['7', 'July'], ['8', 'August'], ['9', 'September'], ['10', 'October'], ['11', 'November'], ['12', 'December']]
		});

		var month = new Ext.form.ComboBox({
			name: 'monthname',
			id: 'monthid',
			hiddenName: 'monthname',
			labelSeparator: '',
			fieldLabel: labelArray[6],
			displayField: 'displaymonth',
			valueField: 'valuemonth',
			editable: true,
			triggerAction: 'all',
			mode: 'local',
			allowBlank: false,
			store: monthstore,
			value: currmonthno
		});



		var orderbystore = new Ext.data.ArrayStore({
			fields: ['order_by2', 'order_by1'],
			data: [['student_gturegno', 'Enrollment No'],
			['student_surname', 'Surname'],
			['student_firstname', 'First Name'],
			['student_gender,student_surname', 'Gender,Surname'],
			['student_gender,student_gturegno', 'Gender,Enrollment No']]
		});


		var blank_sheet = new Ext.form.Radio({
			hideLabel: true,
			name: 'report_type',
			id: 'report_type1',
			inputValue: 'blank_sheet',
			boxLabel: 'Blank Sheet'

		});

		var detail_sheet = new Ext.form.Radio({
			hideLabel: true,
			name: 'report_type',
			id: 'report_type2',
			inputValue: 'detail_sheet',
			checked: true,
			boxLabel: 'Detail Sheet'
		});


		var startdate = new Ext.form.DateField({
			id: 'startdate',
			labelSeparator: '',
			fieldLabel: 'Date <span class="comp">*</span>',
			name: 'startdate',
			allowBlank: false,
			value: '<?php echo date('Y-m-01'); ?>'
		});

		var enddate = new Ext.form.DateField({
			id: 'enddate',
			fieldLabel: '',
			name: 'enddate',
			allowBlank: false,
			value: '<?php echo date('Y-m-t'); ?>'
		});

		var BatchStore = new Ext.data.JsonStore({
			url: 'data/get-batch.php',
			root: 'data',
			remoteSort: true,
			fields: [{
				name: 'batch_id',
				type: 'int'
			}, {
				name: 'batch_name',
				type: 'string'
			}], autoLoad: true,
		});

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

			var AttendenceForm = new Ext.FormPanel({
				labelWidth: 80,
				url: 'report-attendence-sheet-result.php',
				frame: true,
				standardSubmit: true,
				title: '',
				bodyStyle: 'padding:6px 6px 0',
				layout: 'form',
				defaultType: 'textfield',
				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();
							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());	
						}
					}
				}, {
					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: 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('semester_name').reset();
							} 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: 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('branchyear_name').reset();
							} 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',
					tabIndex: 7,
					width: 163,
					allowBlank: true,
					store: subjectstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('subject_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_name').getValue() != "") {

							} else {
								alert('Select Branch First')
								this.reset();
							}
						}
					}
				}, {
					xtype: 'combo',
					name: 'batch_id',
					id: 'batch_id',
					hiddenName: 'batch_idhidden',
					allowBlank: true,
					fieldLabel: labelArray[5],
					forceSelection: true,
					labelSeparator: '',
					displayField: 'batch_name',
					valueField: 'batch_id',
					triggerAction: 'all',
					mode: 'local',
					store: BatchStore,
					listeners: {
						'select': function (cmb, rec, idx) {
						//	Ext.getCmp('batch_disp').setValue(this.getRawValue());
						}
					}
				},
				{
					xtype: 'container',
					autoEl: {},
					border: false,
					layout: 'column',
					anchor: '100%',
					defaultType: 'field',
					items: [{
						xtype: 'container',
						autoEl: {},
						layout: 'form',
						columnWidth: .62,
						items: [startdate]
					}, {
						xtype: 'container',
						autoEl: {},
						layout: 'form',
						columnWidth: .38,
						labelWidth: 1,
						items: [enddate]
					}]
				}, {
					xtype: 'combo',
					name: 'orderby',
					id: 'orderby',
					hiddenName: 'hid_orderby',
					labelSeparator: '',
					fieldLabel: labelArray[7],
					displayField: 'order_by1',
					valueField: 'order_by2',
					editable: true,
					triggerAction: 'all',
					mode: 'local',
					store: orderbystore
				},
				{
					xtype: 'container',
					autoEl: {},
					border: false,
					layout: 'column',
					anchor: '100%',
					defaultType: 'field',
					items: [{
						xtype: 'container',
						autoEl: {},
						layout: 'form',
						columnWidth: .40,
						items: [detail_sheet]
					}, {
						xtype: 'container',
						autoEl: {},
						layout: 'form',
						columnWidth: .40,
						labelWidth: 1,
						items: [blank_sheet,{
					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: 'subject_disp',
                    id: 'subject_disp',
                   hidden:true,
				}]
					}]
				}]
			});

			var AttendenceWindow = new Ext.Window({
				title: 'Student Attendance Sheet Report',
				height: 310,
				width: 340,
				modal: true,
				layout: 'fit',
				border: false,
				closeAction: 'close',
				collapsible: 'true',
				items: AttendenceForm,
				buttonAlign: 'center',
				onEsc: function (k, e) {
					e.stopEvent();

				},
				buttons: [{
					text: 'View Report',
					iconCls: 'new-tab',
					handler: function (b, e) {

						if (Ext.getCmp('report_type1').getValue() == false && Ext.getCmp('subject_name').getValue() == "") {

							Ext.MessageBox.show({
								title: 'Error',
								msg: 'Select Subject name If you want Detail Sheet Report.',
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.ERROR
							});

						}
						else {

							var branch_hidden = AttendenceForm.getForm().findField('branch_hidden').getValue();
							var semester_hidden = AttendenceForm.getForm().findField('semester_hidden').getValue();
							var year_hidden = AttendenceForm.getForm().findField('year_hidden').getValue();
							var branchyear_hidden = AttendenceForm.getForm().findField('branchyear_hidden').getValue();
							var subject_hidden = AttendenceForm.getForm().findField('subject_hidden').getValue();
							var batch_idhidden = AttendenceForm.getForm().findField('batch_idhidden').getValue();
							var startdate = AttendenceForm.getForm().findField('startdate').getValue().format('Y-m-d');
							var enddate = AttendenceForm.getForm().findField('enddate').getValue().format('Y-m-d');
							var hid_orderby = AttendenceForm.getForm().findField('hid_orderby').getValue();
							
							var report_type = AttendenceForm.getForm().findField('report_type').getGroupValue();
							var branch_disp=AttendenceForm.getForm().findField('branch_disp').getValue();
							var year_disp=AttendenceForm.getForm().findField('year_disp').getValue();
							var branchyear_disp=AttendenceForm.getForm().findField('branchyear_disp').getValue();
							var semester_disp=AttendenceForm.getForm().findField('semester_disp').getValue();
							var subject_disp=AttendenceForm.getForm().findField('subject_disp').getValue();


							//	alert(show_mobile_no);

							var redirect = 'report-attendence-sheet-result.php?branch_hidden=' + branch_hidden + '&semester_hidden=' + semester_hidden +
								'&year_hidden=' + year_hidden+ '&branchyear_hidden=' + branchyear_hidden  +'&subject_hidden=' + subject_hidden + '&batch_idhidden=' + batch_idhidden +
								'&startdate=' + startdate + '&enddate=' + enddate + '&hid_orderby=' + hid_orderby +
								 '&report_type=' + report_type+ '&branch_disp='+branch_disp+ '&year_disp='+year_disp+ '&branchyear_disp='+branchyear_disp 
								 + '&semester_disp='+semester_disp+ '&subject_disp='+subject_disp  ;
							window.location = redirect;


						}
					}
				}, {
					text: 'Reset',
					iconCls: 'icon-reset',
					handler: function () {
						AttendenceForm.getForm().reset();
						Ext.getCmp('branch_name').focus(true, 500);
						Ext.getCmp('batch_id').setValue(0);
						Ext.getCmp('batch_id').setRawValue('All');
					}
				}, {
					text: 'Close',
					iconCls: 'icon-close',
					handler: function () {
						AttendenceWindow.close();
					}
				}]
			});

			var varWidth = (screen.width - AttendenceWindow.width) / 2;
			AttendenceWindow.setPosition(varWidth, ((screen.height / 4) - 85));
			AttendenceWindow.show();
			Ext.getCmp('branch_name').focus(true, 1000);
			Ext.getCmp('batch_id').setValue(0);
			Ext.getCmp('batch_id').setRawValue('All');
		});
	</script>
	<div id="abcd"></div>
</div>
<?php require "_footer.php"; ?>