<?php 
	require "_header.php";
	require "includeGridFilters.php";
	require "data/combo_student.php";
	$username = $_SESSION["VedantnrUserName"];
?><div id="main-content">
<!-- start custom CSS/JS -->

<script type="text/javascript">
	var username = '<?php echo $username; ?>';
</script>
<script src="js/login-confirm.js" type="text/javascript"></script>
<script type="text/javascript">
var loadingMask = new Ext.LoadMask(Ext.getBody(), {msg:"Loading data, please wait...",id:"loadingMask"});


Ext.onReady(function(){
	 loadingMask.show();
	 Ext.QuickTips.init();
 	 var xg = Ext.grid;
	 var sm2 = new xg.CheckboxSelectionModel({
        listeners: {
            selectionchange: function(sm) {
                if (sm.getCount() ) {
					 if(flgDelete == "true"){
						grid.removeButton.enable();
					 }
			   } else {
                    grid.removeButton.disable();
				}
            }
        }
    });  	
					 
	var url = {
        local:  'grid-filter.json', 
        remote: 'data/student-grid-filter.php'
       }; 
	var encode = false;
	var local = false;
 
 var backclgform = new Ext.FormPanel({	
		id: 'backclgform',
		frame: true,
		//url:'detain-student-list.php',
		standardSubmit:true,
    	labelAlign: 'left',
    	layout:'column',        
		items :[{
			columnWidth: 1,
			layout: 'form',
			labelWidth:120,
			items:[{
				xtype: 'datefield',
						name: 'backdate',
						id:'backdate',
						labelSeparator:'',	
						fieldLabel :'Back to College date',
						format:'Y/m/d',
						value:new Date(),
						//maxValue:new Date('<?php //echo date("d M Y H:i:s")?>'),
						allowBlank:true,
			}]}
		   
			]
    });
   
   var SemesterWindow = new Ext.Window({
		title: 'Back To College Date',
		width:300,		
		height:130,	
		frame: true,
		border: false,
		modal:true,
		layout: 'fit',
		closeAction:'hide',
		collapsible:true,
		items: backclgform,
		buttons:[
			{
				text: 'OK', 
				name:'btnSave',
				tabIndex:4,
				iconCls:'icon-save',
				id:'btnSave',
				handler:confirmDeleteStudents,
				//SemesterWindow.hide();
				//backclgform.getForm().submit();
				
					
			},
			
			{
				text: 'Reset', 
				name:'btnreset',
				tabIndex:6,
				iconCls:'icon-reset',
				id:'btnreset',
				handler: function (){
					backclgform.getForm().reset();
					
					//Ext.getCmp('backdate').focus(true,500);
					
				}
			},
			{
				text:'Close', 
				name:'btnclose',
				tabIndex:7,
				iconCls:'icon-close',
				id:'btnclose',
				handler: function (){
					SemesterWindow.hide();
				}
			}
		]
	});
	
	function confirmDeleteStudents(){
		SemesterWindow.hide();
		//alert(Ext.getCmp('backdate').getValue());
			Ext.MessageBox.confirm('Confirmation', ' Are you sure Do you want to Add This Student To College.?', function(btn){
				if(btn == 'yes'){
					
					var selections = grid.selModel.getSelections();
					var prez = [];
					var prez1 = [];
					for(i = 0; i< grid.selModel.getCount(); i++){
					prez.push(selections[i].json.student_id);
					}
					for(i = 0; i< grid.selModel.getCount(); i++){
					prez1.push(selections[i].json.year_id);
					}
					var encoded_array = Ext.encode(prez);
					var encoded_array1 = Ext.encode(prez1);
					
					var backdate = Ext.getCmp('backdate').getValue();
					
					
					
					Ext.Ajax.request({
						loadMask: true,
						sync : true,
						url: 'detainedbacktocollege.php',
						params: {action:'student',student_id: encoded_array,year_id:encoded_array1,backdate:backdate},
						success: function(resp){
							var str = "";
							resbool=resp.responseText;
							if(resbool != ""){
								
								Ext.MessageBox.show({
											title: 'info',
											msg: 'Student Transfer to College Successfully',
											buttons: Ext.MessageBox.OK,
											icon:Ext.MessageBox.info
										});	
										store.reload({
							params: {
								'branch_id': Ext.getCmp('branch_id').getValue(),
								start: 0,
								limit: 10   
							}
						});
							}
							else{
								
							}
						}			
					});
				
      			} 
				
			});
			
	} 
	
	function deleteStudents(btn){
		if(btn == 'yes'){
			loginWindow.show();
      	}  
  	}
	
function formatDate(value){
	if(value!="" && value!=null){
		var temp = value.dateFormat('d/m/Y');
			if(temp=="28/02/1900")
			{
				return '';
			}
			else
			{
				return temp;
			}
		}else{
			return temp;
		}
	
	}
	
	
  
  
var sec;
store = new Ext.data.JsonStore({
    	autoDestroy: true,
		url:'data/detained-student-grid-filter.php',
        remoteSort: true,
        storeId: 'myStore',
        idProperty: 'student_id',
        root: 'data',
        totalProperty: 'total',
        fields: [{
            name: 'student_id',
			type:'int'
        }, {
            name: 'student_gturegno'
        }, {
            name: 'semester_name'
        }, {
            name: 'cur_divison'
        }, {
            name: 'studentname'
        },{
            name: 'student_gender'
        },{
            name: 'student_admdate',
			type: 'date',
            dateFormat: 'Y-m-d'
        }, {
            name: 'student_birthdate',
			type: 'date',
            dateFormat: 'Y-m-d'
        }, {
            name: 'student_category'
        },
		{
            name:'student_admby'
        },
		{
			name:'leave_type'
		},
		{
			name:'leave_reason'
		},
		{
			name:'leave_date',
			type: 'date',
            dateFormat: 'Y-m-d'
		},
		{
			name: 'student_mobilestudents'	
		},
		{
			name: 'student_mobileparents'	
		},
		{
			name: 'year_id'	
		},
		{
			name: 'year_name'	
		}
		] 
    });

	
	
 var branchstore = new Ext.data.ArrayStore({
		fields: ['branch_id', 'branch_name'],
		data: Ext.student.branch1
  	}); 
	
 
	
var BranchCombo = {
    xtype: 'combo',
    store: branchstore,
	id:'branch_id',
    displayField: 'branch_name',
    valueField: 'branch_id',
    editable: false,
    mode: 'local',
    forceSelection: true,
    triggerAction: 'all',
    //emptyText: 'Select a Branch...',
    selectOnFocus: true,
	width:100,
    listeners: {
        'select': function(cmb, rec, idx) {
				 sec = this.getValue(),
                 store.load({params: { 'branch_id': this.getValue(),start:0,limit:10}
			});
        }
    }}
	

    var filters = new Ext.ux.grid.GridFilters({
        encode: encode,
        local: false,                                      
		filters: [{
            type: 'numeric',
            dataIndex: 'student_id'
        },  {
            type: 'string',
            dataIndex: 'student_gturegno'
        },  {
            type: 'string',
            dataIndex: 'year_name',
			labelField:'year_name'
        },
		{
            type: 'string',
            dataIndex: 'branchyear_name',
			labelField:'branchyear_name'
        },  {
            type: 'string',
            dataIndex: 'semester_name',
			labelField:'semester_name'
        },{
            type:'string',
            dataIndex: 'studentname',
             phpMode: true
        }, {
            type: 'list',
            dataIndex: 'student_active',
			options : ['Yes','No'],
			 phpMode: true
        }, {
            type: 'list',
            dataIndex: 'student_gender',
			options : ['Male','Female'],
			 phpMode: true
        }, {
			type:'list',
            dataIndex: 'student_category',
			options: [{id:'GENERAL',text:'GENERAL'},
					   {id:'OBC',text:'OBC'},
					   {id:'SC',text:'SC'},
					   {id:'ST',text:'ST'},
					   {id:'MINORITY',text:'MINORITY'} ],
            phpMode: true
        },{
            type: 'date',
            dataIndex: 'student_admdate'
        },<?php if($_SESSION["VedantnrUserRole"]!='Faculty' && $_SESSION["VedantnrUserRole"]!='Hod') { ?>{
            type: 'date',
            dataIndex: 'student_birthdate'
        },<?php } ?>{
            type: 'list',
            dataIndex: 'student_admby',
			options : ['ACPDC','M.Q','V.Q'],
			 phpMode: true
        },{
			type:'list',
            dataIndex: 'leave_type',
			options: [{id:'d',text:'Detained'}],
            phpMode: true
        },{
            type: 'date',
            dataIndex: 'leave_date'
        }]
    });  
	
var createColModel = function (finish, start) {
        var columns = [
		sm2,{
			header: "View Fees",	
			width:70,
		    renderer: function(value, metaData, record, rowIndex, colIndex, store) {
    	   		return '<a href="view-student-fees.php?ID='+ record.get('student_id') +'">View Fees</a>';
			}
		},
		{
            dataIndex: 'student_id',
            header: 'Student ID', 
			width:80,
			hidden:true,
	        filterable: true
        }, {
            dataIndex: 'student_gturegno',
            header: 'Enrollment No',
			width:90,
            filterable: true
        }, {
            dataIndex: 'year_name',
            header: 'Batch Year',
			width:60
        }, {
            dataIndex: 'branchyear_name',
            header: 'Course Name',
			width:60
        },
		{
            dataIndex: 'semester_name',
            header: 'Semester Name',
			width:60
        },{
            dataIndex: 'studentname',
            header: 'Student Name',
            id: 'SurName', 
            filter: {type: 'string'},
			width:190
        }, {
            dataIndex: 'student_admdate',
            header: 'Admis. Date',
			width:70,
			renderer:formatDate,
            filter: {
            }
        }, {
            dataIndex: 'student_birthdate',
            header: 'Birth Date',
			width:70,
			renderer:formatDate,
            filter: {
            }
        }, {
            dataIndex: 'student_gender',
            header: 'Gen',
            id: 'Gender',
			width:40
        }, {
            dataIndex: 'student_category',
            header: 'Category',
			width:65,
            filter: {
            }            
        },{
            dataIndex: 'student_admby',
            header: 'Adm By',
			width:50,
            filter: {
            }            
        },{
            dataIndex: 'student_mobilestudents',
            header: 'Mob.Student',
			width:80,
			hidden:true,
            filter: {
            }            
        },{
            dataIndex: 'student_mobileparents',
            header: 'Mob.Parents',
			width:80,
			hidden:true,
            filter: {
            }            
        },{
            dataIndex: 'leave_type',
            header: 'Leave Type',
			width:80,
			renderer: function(v, params, record){
				if(v=='d')
				{
					return 'Detained';
				}
				else
				{
					return '';
				
				}
			}         
        },{
            dataIndex: 'leave_date',
           	header: 'Leave Date',
			width:71,
			renderer:formatDate,
            filter: {
            }
        }, {
            dataIndex: 'leave_reason',
            header: 'Reason',
            id: 'leave_reason',
			width:120
        },
		{
            dataIndex: 'year_name',
            header: 'Year',
			width:75        
       	    },
			{
            dataIndex: 'year_id',
            header: 'YearId',
			hidden:true 
        	} 
		];
		
		
		return new Ext.grid.ColumnModel({
            columns: columns.slice(start || 0, finish),
            defaults: {
                sortable: true
            }
        });
    };
	
	
	
var grid = new Ext.grid.GridPanel({
		id:'grid',
		name:'grid',
        store: store,
        colModel: createColModel(40), 
        loadMask: true,
		frame: true,
		enableColLock:false,
		columnLines:true,
	    height: 460,    
        width: 900,
        layout: 'fit',
    	selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		listeners: {
            render: {
                fn: function(){
					if(Ext.getCmp('branch_id').getValue()!="")
					{
                    	store.reload({
							params: {
								'branch_id': Ext.getCmp('branch_id').getValue(),
								start: 0,
								limit: 30   
							}
						});
					}
                }
            }
        },
        plugins: [filters],
		sm: sm2,
       	tbar: [{xtype: 'tbtext',text: 'Course:'},' ',
				BranchCombo,{width:3},
				{ 
					text: 'Back To College',
					id:'btnDelete',
					iconCls: 'icon-save',
					handler: function(){SemesterWindow.show();}, 
					ref: '../removeButton',
					disabled: true
      		}
	  ], 
        bbar: new Ext.PagingToolbar({
            store: store,
            pageSize: 30,
			displayInfo: true,
            plugins: [filters]
        })
    });
    grid.getBottomToolbar().add([
        '->',{
            text: 'Clear Filter Data',
            handler: function () {
                grid.filters.clearFilters();
            } 
        }    
    ]);
	
 
 store.on({
	'beforeload': {
    	fn: function(store, options){
            options.params || (options.params = {}); 
            Ext.apply(options.params, {
            	pageNo: this.pageNumber,
				branch_id: Ext.getCmp('branch_id').getValue()
            });
        },
        scope: this
    }
});


 	var StudentWindow = new Ext.Window({
        title: 'Detained Student List',
        height: 415,
        width: 900,
        layout: 'fit',
		modal:true,
		border: false,
		closeAction:'close',
		collapsible:'true',				
		items: grid
    })
	 
	var varWidth =  (screen.width - StudentWindow.width)/2;
	StudentWindow.setPosition(varWidth,((screen.height/4)-85));	 
	StudentWindow.show();
	loadingMask.hide();

	
	if(flgEdit == "false"){
		grid.getColumnModel().setHidden(1, true);
	}
	Ext.getCmp('branch_id').focus(true,1000);
});
</script>
<!-- end custom CSS/JS -->
<div id="abcd" align="center"></div>
</div>
<?php require "_footer.php";?>
