<?php 
	require "_header.php"; 
	require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
	require "includeGridFilters.php";
	
	
?>
<div id="main-content" >
<style type="text/css">
	label.myBold
	{
	   font-weight: bold;
	   color:#15428B;
	   font-size: 10px;
	}
</style>
<script type="text/javascript" src="jquery/ux/CheckColumn.js"></script>
<link rel="stylesheet" type="text/css" href="css/Ext.css">
<script type="text/javascript" src="js/Ext.js"></script>
<script type="text/javascript" src="js/Ext_002.js"></script>	
<script language="javascript" type="text/javascript">
Ext.override(Ext.ux.form.LovCombo, {
	beforeBlur: Ext.emptyFn
});
Ext.onReady(function(){
	Ext.QuickTips.init();
    var abstudentSmsId ="";



	var labelArray;
        labelArray = [
            ['Course '],
            ['Batch Year '],
            ['Course Year '],
            ['Semester '],
            ['Batch Name '],
            ['subject '],
            ['Lec Type '],
            ['Employee ']
        ]; 
	var dt = new Date();
	var xg = Ext.grid;
	var checkColumn = new Ext.grid.CheckColumn({
       	header: 'Present',
	   	id: 'day_present',
	   	dataIndex: 'day_present',
	    width: 55,
		editor:{xtype: 'checkbox',allowBlank: false}
	});	

	
	
	//employee store
	var employeestore = new Ext.data.ArrayStore({		
		fields: ['employee_id','employee_name','branch_name'],
		data:Ext.semester.employee
	});
	
	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.student.semester
        });

        var yearstore = new Ext.data.ArrayStore({
            fields: ['branch_id', 'branchyear_id', 'branchyear_name'],
            data: Ext.year.year
        });

	
	var lectypestore = new Ext.data.ArrayStore({		
		fields: ['lectype_id','lectype_name'],
		data:Ext.semester.lectype
	});


	var subjectstore = new Ext.data.JsonStore({
	url:'data/get-subject.php',
    root: 'data',
	totalProperty: 'total',
	fields: ['subject_id','subject_name'] 
});

	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,
});
	store = new Ext.data.JsonStore({
		url:'data/grid_subject_allocation.php',
		root: 'data',
		storeId: 'student_id',
		totalProperty: 'total',
		fields: [{name: 'subject_allocation_id'},{name: 'college_id'},{name: 'branch_id'},
		{name: 'semester_id'},{name: 'div_id'},{name: 'batch_id'},
		{name: 'subject_id'},{name: 'year_id'},{name: 'lectype'},{name: 'lectype_name'},
	
		{name: 'semester_name'},{name: 'batch_name'},{name: 'subject_name'},{name: 'employee_name'}
		] 
	});
	
	var colModel = new Ext.grid.ColumnModel([
	new Ext.grid.RowNumberer(),
	{
		dataIndex: 'subject_allocation_id',
		header: 'Subject Allocation ID', 
		id: 'subject_allocation_id',
		hidden: true
	},{
		dataIndex: 'branch_name',
		header: 'Branch',
		sortable:true,
		width:80
	},{
		dataIndex: 'semester_name',
		header: 'Semester',
		sortable:true,
		width:70,  
	},{
		dataIndex: 'div_id',
		header: 'Div',
		sortable:true,
		width:30,  
	},{
		dataIndex: 'batch_name',
		header: 'Batch',
		sortable:true,
		width:70
	},{
		dataIndex: 'subject_name',
		header: 'Subject',
		sortable:true,
		width:200
	},{
		dataIndex: 'lectype_name',
		header: 'Lec Type',
		sortable:true,
		width:70
	},{
		dataIndex: 'employee_name',
		header: 'Faculty Name',
		sortable:true,
		width:160
	}]);

store.load();

var grid = new Ext.grid.GridPanel({
		xtype: 'grid',
		ds: store,
		cm: colModel,
		sm: new Ext.grid.RowSelectionModel({
			singleSelect: true,
			listeners: {
				rowselect: function(sm, row, rec) {
					Ext.getCmp('btnDelete').enable();
					Ext.getCmp("PresentForm").getForm().loadRecord(rec);
					
			
					Ext.getCmp('branch_name').setRawValue(rec.data.branch_name);
					Ext.getCmp('branch_name').setValue(rec.data.branch_id);
					Ext.getCmp('semester_name').setRawValue(rec.data.semester_name);
					Ext.getCmp('semester_name').setValue(rec.data.semester_id);
				
					Ext.getCmp('subject_name').setRawValue(rec.data.subject_name);
					Ext.getCmp('subject_name').setValue(rec.data.subject_id);
					
					
						
				}
			}
		}),
		height: 370,    
        width: 790,
		border: true,
		loadMask: true
	});
	
	grid.on('render', function() {
		grid.tip = new Ext.ToolTip({
			view: grid.getView(),
			target: grid.getView().mainBody,
			delegate: '.x-grid3-row',
			trackMouse: true,
			loadMask: true, 
			renderTo: document.body,
			listeners: {
				beforeshow: function updateTipBody(tip) {
					tip.body.dom.innerHTML = "Please Click Here To Edit Records.";
				}
			}
		});
  	});
	
	
	Ext.override(Ext.Editor, {
		onBlur: function() {
			if (this.allowBlur === true && this.editing) {
				this.completeEdit();
			}
		}
	});
	
	var PresentForm = new Ext.FormPanel({
		method:'post',
        frame:true,
		id:'PresentForm',
		name:'PresentForm',
		url:'save-subject-allocation.php',
		standardSubmit:false,       
        layout:'column',        
		items :[{
			columnWidth: 0.33,
			layout: 'form',
			labelWidth:75,
			items:[ {
                            xtype: 'combo',
                            name: 'branch_name',
                            id: 'branch_name',
                            hiddenName: 'branch_hidden',
                            fieldLabel: labelArray[0],
                            displayField: 'branch_name',
                            valueField: 'branch_id',
                            width: 163,
                            tabIndex: 1,
                            triggerAction: 'all',
                            mode: 'local',
                            allowBlank: true,
                            store: branchstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    Ext.getCmp('year_name').reset();
                                    Ext.getCmp('semester_name').reset();
                                    Ext.getCmp('branchyear_name').reset();
                                    Ext.getCmp('subject_name').reset();
                                  //  employeestore.removeAll();
									employeestore.filter('branch_id', cmb.getValue(), false, true, true);    
                                    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_name',
                            id: 'branchyear_name',
                            hiddenName: 'branchyear_hidden',
                            fieldLabel: labelArray[2],
                            displayField: 'branchyear_name',
                            valueField: 'branchyear_id',
                            lastQuery: '',
                            triggerAction: 'all',
                            mode: 'local',
                            width: 163,
                            tabIndex: 3,
                            allowBlank: true,
                            store: yearstore,
                            listeners: {
                                'select': function (cmb, rec, idx) {
                                    if (Ext.getCmp('branch_name').getValue() != "") {
                                        Ext.getCmp('subject_name').reset();
                                    } else {
                                        this.reset();
                                    }
                                }
                            }
                        },{		
					xtype: 'combo',
					name: 'employee_id',
					id:'employee_id',
					labelSeparator:'',	
					fieldLabel: labelArray[7],
					forceSelection:true,				
					displayField:'employee_name',
					valueField: 'employee_id',
					hiddenName:'employee_id_hid'
					,lastQuery:''
					,allowBlank:false
					,triggerAction:'all'
					,mode:'local'
					,store:employeestore
					,width:163
					,selectOnFocus: true,
					tabIndex:8,
					listeners: {'select': function(cmb, rec, idx){
					LoadData();
					}}
				}]
		},{
			columnWidth: 0.34,
			layout: 'form',
			labelWidth:85,
			items:[{
                        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:163,
                        tabIndex: 2,
                        allowBlank: true,
                        store: batchyearstore,
                        listeners: {
                            'select': function (cmb, rec, idx) {
                                if (Ext.getCmp('branch_name').getValue() != "") {
                                    Ext.getCmp('student_name').reset();
                                    studentstore.load({ params: { 'branch_id': Ext.getCmp('branch_name').getValue(), 'year_id': Ext.getCmp('year_name').getValue() } });
                                } else {
                                    this.reset();
                                }
                            }
                        }
                    }, {
                        xtype: 'combo',
                        name: 'semester_name',
                        id: 'semester_name',
                        hiddenName: 'semester_hidden',
                        fieldLabel: labelArray[3],
                        displayField: 'semester_name',
                        valueField: 'semester_id',
                        disabled: true,
                        lastQuery: '',
                        triggerAction: 'all',
                        mode: 'local',
                        width: 163,
                        tabIndex: 4,
                        allowBlank: true,
                        store: semesterstore,
                        listeners: {
                            'select': function (cmb, rec, idx) {
                                if (Ext.getCmp('branch_name').getValue() != "") {
                                    Ext.getCmp('student_name').reset();
                                } else {
                                    this.reset();
                                }
                            }
                        }
                    },{
				xtype: 'combo',
				name: 'lectype',
				id:'lectype',
				hiddenName:'lectype_hid',
				labelSeparator:'',	
				fieldLabel: labelArray[6],
				displayField:'lectype_name',
				valueField: 'lectype_id',
				editable:true,
				triggerAction:'all',
				mode:'local',
				tabIndex:7,
				width:163,
				allowBlank:false,
				store: lectypestore

				
			}
			]},
			{
			columnWidth: 0.33,
			layout: 'form',
			labelWidth:75,
			items:[{
				xtype: 'combo',
				name: 'batch_id',
				id:'batch_id',
				hiddenName: 'batch_idhidden',
				allowBlank:true,
				fieldLabel: labelArray[4],
				forceSelection:true,
				tabIndex:4,
				labelSeparator:'',	
				displayField:'batch_name',
				valueField: 'batch_id',
				width:163,
				triggerAction:'all',
				mode:'local',
				store: BatchStore 
				},
				{
				xtype:'hidden',
				id:'subject_allocation_id',
				name:'subject_allocation_id'
				
				
			},{
					xtype: 'combo',
					name: 'subject_name',
					id: 'subject_name',
					hiddenName: 'subject_hidden',
					fieldLabel: labelArray[5],
					displayField: 'subject_name',
					valueField: 'subject_id',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: true,
					store: subjectstore
					
				}]
		
		},
		
		{
			columnWidth: 1,
			layout: 'form',
			items:[{height:5},grid]}
      	]		   
  	});
	
	
  function deleterecord(btn){
    	if(btn=='yes'){
			PresentForm.getForm().submit({
						waitMsg: 'Deleting...',
						params:{act:'del'},
						success: function () {	
							Ext.getCmp('btnDelete').disable();
							store.load();
							PresentForm.getForm().reset();	
							Ext.getCmp('btnSave').enable();	
							Ext.getCmp('branch_name').focus(true,1000);			
						}
					});
					}} 	
	
		
	var PresentWindow = new Ext.Window({
        title: 'Employee Subject Allocation',
		width:820,		
		height:530,	
		modal:true,	
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: PresentForm,
		buttonAlign: 'center',
	    buttons:[{xtype:'button',
						iconCls:'icon-save',
						text: 'Save', 
						width:70,
						tabIndex:9,
						name:'btnSave',
						id:'btnSave',
						handler: function(){
											
						PresentForm.getForm().submit({					
							waitMsg: 'Saving...',
							success: function () {
								Ext.MessageBox.show({
									title: 'Message',
									msg: 'Data has been saved',
									buttons: Ext.MessageBox.OK,
									icon:Ext.MessageBox.INFO
								});	
								
								Ext.getCmp('btnDelete').disable();
								PresentForm.getForm().reset();
								Ext.getCmp('btnSave').enable();
								grid.getSelectionModel().clearSelections();
								Ext.getCmp('branch_name').focus(true,1000);
								store.load();
							}
						})

			}
			} <?php  if($_SESSION["VedantnrUserRole"] == "PowerUser"){ ?>
							,{xtype:'button',
							id:'btnDelete',
							name:'btnDelete',
							text:'Delete',
							iconCls:'remove',
							width:70,
							tabIndex:10,
							handler: function(){ 
							Ext.MessageBox.confirm('Confirmation', ' Are you sure want to delete This Record.?', deleterecord);
							}
						}<?php } ?>,{
						xtype:'button',
						iconCls:'icon-reset',
						text: 'Reset', 
						width:70,
						tabIndex:11,
						name:'btnReset',
						id:'btnReset',
						handler: function (){
							PresentForm.getForm().reset();
							Ext.getCmp('btnSave').enable();
							grid.getSelectionModel().clearSelections();
							Ext.getCmp('branch_name').focus(true,500);
							store.load();
						}
					},{
						xtype:'button',
							id:'btnClose',
							text:'Close',
							name:'btnClose',
							iconCls:'icon-close',
							width:70,
							tabIndex:11,
							handler: function () {
							PresentWindow.close();	
							}
						}]
	});
	
	var varWidth =  (screen.width - PresentWindow.width)/2;
	PresentWindow.setPosition(varWidth,((screen.height/4)-170));	 
	PresentWindow.show();
	Ext.getCmp('branch_name').focus(true,1000);

});
</script>
</div>
<?php require "_footer.php";?>
