<?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 = [
	['Branch <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 '],
	['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 lectypestore = new Ext.data.ArrayStore({		
		fields: ['lectype_id','lectype_name'],
		data:Ext.semester.lectype
	});
	*/
	

/*var min_persentage = new Ext.form.TextField({
	name: 'min_persentage',
	id:'min_persentage',
	labelSeparator:'',	
	fieldLabel :'Min[%] <span class="comp">*</span>',
	value:'50'
});*/





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-summary-result.php',
		frame:true,
		standardSubmit:true,
	    autoHeight:true,
        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: 180,
					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: 180,
					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: 180,
					allowBlank: true,
					store: yearstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('branchyear_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_name').getValue() != "") {
								
							} 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: 180,
					allowBlank: true,
					store: semesterstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('semester_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_name').getValue() != "") {
								
							} 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',
					width: 180,
					allowBlank: true,
					store: subjectstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							Ext.getCmp('subject_disp').setValue(this.getRawValue());	
						}
					}	

				},
				/*{
					xtype: 'combo',
					name: 'lectype',
					id:'lectype',
					hiddenName:'lectype_hid',
					labelSeparator:'',	
					fieldLabel :'Lec Type:' ,
					displayField:'lectype_name',
					valueField: 'lectype_id',
					editable:true,
					triggerAction:'all',
					mode:'local',
					allowBlank:true,
					store: lectypestore,
					listeners: {'select': function(cmb, rec, idx){
						Ext.getCmp('lectype_disp').setValue(this.getRawValue());

					}}
				},*/
				{
				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',
				width: 180,
				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:.64,
				items:[{
					xtype:'datefield',
					id: 'startdate',
					labelSeparator:'',	
					fieldLabel :'Date <span class="comp">*</span>',
					name: 'startdate',
					allowBlank:false,
					value:'<?php  echo date('Y-m-01');?>'
				}]
			},{
				xtype:'container',
				autoEl:{},
				layout:'form',
				columnWidth:.36,
				labelWidth:1,
				items:[{
					xtype:'datefield',
   					id: 'enddate',
					fieldLabel: '',
					name: 'enddate',
					allowBlank:false,
					value:'<?php  echo date('Y-m-t');?>'
				}]
			}]
		},{
					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,
				},
				/*{
					xtype: 'displayfield',
					name: 'lectype_disp',
                    id: 'lectype_disp',
                   hidden:true,
				},*/
				{
					xtype: 'displayfield',
					name: 'batch_disp',
                    id: 'batch_disp',
                   hidden:true,
				}]
 	});
	
	var AttendenceWindow = new Ext.Window({
        title: 'Student Attendance Summary Report',
	    autoHeight:true,
        width: 350,
		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('branch_name').getValue()=="" && Ext.getCmp('semester_name').getValue()=="" && Ext.getCmp('division_id').getValue()=="")
				{
					
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Select Branch,Semester And Division First.',
												buttons: Ext.MessageBox.OK,
												icon:Ext.MessageBox.ERROR
											});									
										
				}
				else
				{
					
							
			var branch_hidden=AttendenceForm.getForm().findField('branch_hidden').getValue();
			var year_hidden=AttendenceForm.getForm().findField('year_hidden').getValue();
			var branchyear_hidden=AttendenceForm.getForm().findField('branchyear_hidden').getValue();
			var semester_hidden=AttendenceForm.getForm().findField('semester_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 lectype_hid=AttendenceForm.getForm().findField('lectype_hid').getValue();
			//var min_persentage=AttendenceForm.getForm().findField('min_persentage').getValue();
		

			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();
			var batch_disp=AttendenceForm.getForm().findField('batch_disp').getValue();
			//var lectype_disp=AttendenceForm.getForm().findField('lectype_disp').getValue();
		//	alert(show_mobile_no);
			
var redirect = 'report-attendence-summary-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 +
'&branch_disp='+branch_disp +'&year_disp='+year_disp + '&branchyear_disp='+branchyear_disp +
'&semester_disp='+semester_disp + '&subject_disp='+subject_disp +'&batch_disp='+batch_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";?>
