<?php require "_header.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">
var temp=0;
var reader = new Ext.data.JsonReader({
		root: 'data',
		idProperty: 'day_id',
		fields: [{name:'day_id'}, 
				 {name:'branch_name'},
				 {name:'year_name'},
				 {name:'branchyear_name'},
				 {name:'subject_name'},
				 {name:'batch_name'},
				 {name:'day_present'},
				 {name:'day_absent'},
				 {name:'lec_name'},
				// {name:'lectype'},
				 {name:'day_date'},
				 {name:'day_working'},
				 {name:'branch_id'},
				 {name:'year_id'},
				 {name:'branchyear_id'},
				 {name:'subject_id'},
				 {name:'semester_id'},
				 {name:'semester_name'},
				 {name:'batch_id'},
				 {name:'day_comment'},
				 {name:'present_by'},				 
				 ]

    });
	

var store =new Ext.data.GroupingStore({
    url: 'data/get-presentdetails.php',
   	reader: reader,
	successProperty: 'success',
	sortInfo: { field: 'branch_name', direction: 'ASC' },
	groupField: 'branch_name'
});

			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
			});


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

	var branch = new Ext.form.ComboBox({
		name: 'branch_name',
		id:'branch_name',
		hiddenName:'branch_hidden',
		fieldLabel :'Branch <span class="comp"></span>' ,
		displayField:'branch_name',
		valueField: 'branch_id',
		editable:true,
		triggerAction:'all',
		tabIndex:1,
		width:163,
		mode:'local',
		allowBlank:true,
		store: branchstore,
		listeners: {
		'select': function (cmb, rec, idx) {
								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();
								}
							}		
		}
	});

	var year = new Ext.form.ComboBox({
		name: 'year_name',
		id:'year_name',
		hiddenName:'year_hidden',
		fieldLabel :'Batch Year <span class="comp"></span>' ,
		displayField:'year_name',
		valueField: 'year_id',
		editable:true,
		triggerAction:'all',
		tabIndex:2,
		width:163,
		mode:'local',
		allowBlank:true,
		store: batchyearstore,
		listeners: {'select': function(cmb, rec, idx){
			
		}}
	});


	var branchyear = new Ext.form.ComboBox({
		name: 'branchyear_name',
		id:'branchyear_name',
		hiddenName:'branchyear_hidden',
		fieldLabel :'Course Year <span class="comp"></span>' ,
		displayField:'branchyear_name',
		valueField: 'branchyear_id',
		editable:true,
		triggerAction:'all',
		tabIndex:3,
		width:163,
		mode:'local',
		allowBlank:true,
		store: yearstore,
		listeners: {'select': function(cmb, rec, idx){
			var branch=Ext.getCmp('branch_name').getValue();
		}}
	});

	var semester = new Ext.form.ComboBox({
		name: 'semester_name',
		id:'semester_name',
		hiddenName:'semester_hidden',
		labelSeparator:'',	
		fieldLabel :'Semester <span class="comp"></span>' ,
		displayField:'semester_name',
		valueField: 'semester_id',
		editable:true,
		tabIndex:4,
		width:100,
		lastQuery:'',
		triggerAction:'all',
		mode:'local',
		allowBlank:true,
		store: semesterstore,
		listeners: {'select': function(cmb, rec, idx){
			var branch=Ext.getCmp('branch_name').getValue();
		}}
	});
	

	var PresentModel = new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
				{
					id:'branch_name',
					dataIndex: 'branch_name',
					hidden:true,
					width:80
				},{
					id:'year_name',
					dataIndex: 'year_name',
					header: 'Batch Year',
					sortable:true,
					width:45,	
				},{
					id:'branchyear_name',
					dataIndex: 'branchyear_name',
					header: 'Course Year',
					sortable:true,
					width:45
				},
				{
					id:'semester_name',
					dataIndex: 'semester_name',
					header: 'Semester',
					sortable:true,
					width:45
				},{
					id:'subject_name',
					dataIndex: 'subject_name',
					header: 'Subject',
					sortable:true,
					width:100
				},{
					id:'batch_name',
					dataIndex: 'batch_name',
					header: 'Batch',
					sortable:true,
					width:40
				},{
					id:'lec_name',
					dataIndex: 'lec_name',
					header: 'Lecture',
					sortable:true,
					width:40
					
				}, {
					id:'day_present',
					dataIndex: 'day_present',
					header: 'Present',
					sortable:true,
					width:40
					
				}, {
					id:'day_absent',
					dataIndex: 'day_absent',
					header: 'Absent',
					sortable:true,
					width:40
				},{ 
						header: "Day Comment",
						sortable: true,
						id:'day_comment',
						dataIndex: 'day_comment',
						width:125
				},{ 
						header: "Present By",
						sortable: true,
						id:'present_by',
						dataIndex: 'present_by',
						width:60	
				},{ 
					header: "Delete",
					sortable: true,
					id:'Delete',
					width:30,
					renderer:deleteIconRenderer
				}
				]);
	function deleteIconRenderer(value){
	return '<a style="cursor:pointer;margin-left:10px" ><img src="images/delete.png" width=16 height=16></a>';
	}
	var grid = new Ext.grid.GridPanel({
		id:'grid',
		name:'grid',
		frame:true,
		ds: store,
        cm: PresentModel,
		stripeRows:true,
		columnLines:true,
		height: 475,
		loadMask: true, 
		style:'margin-top:5px',
		view: new Ext.grid.GroupingView({
					forceFit: true,
					showGroupName: false,
					enableNoGroups: false,
					enableGroupingMenu: false,
					//hideGroupedColumn: true
				}),
		sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
          listeners: {
			  
            	rowselect: function(sm, row, rec) {
					temp=rec.get('day_id');
					
				}
         	}
   		}),
    });
	

var Presentform = new Ext.FormPanel({
		id:'Presentform',
		name:'Presentform',
		url:'view-present-result.php',
		frame:true,
		standardSubmit:true,
		layout:'column',
        items: [{
				columnWidth:0.25,
				layout:'form',
				labelWidth:50,
				items:[branch]},
				{
				columnWidth:0.25,
				layout:'form',
				labelWidth:50,
				items:[year]},
				{
				columnWidth:0.25,
				layout:'form',
				labelWidth:50,
				items:[branchyear]},
				{
				columnWidth:0.20,
				layout:'form',
				labelWidth:65,
				items:[semester]},
				
				{
				columnWidth:0.17,
				layout:'form',labelWidth:45,
				items:[{
						xtype: 'datefield',
						width:100,
						id: 'day_date',
						name: 'day_date',
						fieldLabel: 'Date <span class="comp">*</span>',
						tabIndex:1,
						format:JSDateFormat,
						maxValue:new Date(),
						value:new Date(),
						vtype: 'daterange',
						allowBlank:false,
						listeners: {
						select: function() {
							grid.getStore().removeAll();
		
						}}
					}]},
				{ 
				columnWidth:0.09,
				items:[{ 
						xtype:'button',
						text: 'View',	
						iconCls:'icon-view',
						width:70,
						tabIndex:4,
						style:'margin-left:5px',
						handler: function(){	 
							var day_date=Ext.getCmp('day_date').getValue();
							var semester_name=Ext.getCmp('semester_name').getValue();
							var year_name=Ext.getCmp('year_name').getValue();
							var branchyear_name=Ext.getCmp('branchyear_name').getValue();
							var branch_name=Ext.getCmp('branch_name').getValue();
							
							store.load({params: {'day_date':day_date,'semester_name':semester_name,'year_name':year_name,'branchyear_name':branchyear_name,'branch_name':branch_name}});
								
						}}]
				},{ 
				columnWidth:0.11,
				items:[{ 
						xtype:'button',
						text: 'View Report',	
						iconCls:'new-tab',
						width:70,
						tabIndex:4,
						style:'margin-left:5px',
						handler: function(){	 
							if(grid.store.getCount()>=1){
								
								
			var branch_hidden=Presentform.getForm().findField('branch_hidden').getValue();
			var semester_hidden=Presentform.getForm().findField('semester_hidden').getValue();

			var year_hidden=Presentform.getForm().findField('year_hidden').getValue();
			var branchyear_hidden=Presentform.getForm().findField('branchyear_hidden').getValue();

			var day_date=Presentform.getForm().findField('day_date').getValue().format('Y-m-d');
			
		//	alert(show_mobile_no);
			
var redirect = 'view-present-result.php?branch_hidden='+branch_hidden + '&year_hidden='+year_hidden + '&branchyear_hidden='+branchyear_hidden + '&semester_hidden='+semester_hidden + '&day_date='+day_date; 
                window.location = redirect;
								
							}
							else{
								Ext.MessageBox.show({
									title: 'Error',
									msg: 'Please click on view to see report',
									buttons: Ext.MessageBox.OK,
									icon:Ext.MessageBox.ERROR
								});
							}
						}}]
				},{ 
				columnWidth:1,
				items:[grid]
				}]
    });
	

var PresentWindow = new Ext.Window({
        title: 'Student Present Info',
		width:920,		
		height:550,
		modal:true,
		border: false,
		layout: 'fit',
		closeAction:'hide',
		items:Presentform,
		maximizable:true,
		collapsible:true	
		
		
	});
   	var varWidth =  (screen.width - PresentWindow.width)/2;
    PresentWindow.setPosition(varWidth,((screen.height/4)-180));
	PresentWindow.show();
	var day_date=Ext.getCmp('day_date').getValue();
store.load({params: {'day_date':day_date}});
	
grid.on('cellclick', function(grid, rowIndex, columnIndex, e){
			if(columnIndex==grid.getColumnModel().getIndexById('Delete')) {
				Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This File.?', deleteRecord);
			}
		
			});

function deleteRecord(btn){
if(btn=='yes'){
					Ext.Ajax.request({
					url:'save-daily-present.php',
					method:'POST',
					params: {day_id:temp,
							act:'Del'},
					waitMsg:'Loading',
					success: function(resp) {
						store.reload();
					}				
				});
}}
 
	
});	


</script>

</div>
<?php require "_footer.php"; ?>


                
    
