<?php 
	require "_header.php";
	require "includeMultiSelect.php";
	require "data/combo_semester.php";
?>
<div id="main-content">
<style>
	label.myBold{font-weight: bold;color:#006;font-size: 14px;}
</style>

<div id="abcd">

<script language="javascript" type="text/javascript">
Ext.onReady(function() {
	Ext.QuickTips.init();
	
	var labelArray;
	labelArray = [  
		['Branch:<span class="comp">*</span>'],
		['Semester:<span class="comp">*</span>']
	];
	
	/*var yearstore = new Ext.data.ArrayStore({		
		fields: ['year_id','year_name'],
		data:Ext.semester.yearname
	});*/
	
	var branchstore = new Ext.data.ArrayStore({		
		fields: ['branch_id','branch_name'],
		data:Ext.semester.branch
	});
	
	
	var semesterstoreleft = new Ext.data.ArrayStore({		
		fields: ['semester_id','semester_name'],
		data:Ext.semester.semester
	});
	
	var shiftstore = new Ext.data.ArrayStore({
           fields: ['shift'],
	       data: [['Shift-1'],['Shift-2']]
        });
		
	var semesterstoreright = new Ext.data.ArrayStore({		
		fields: ['semester_id','semester_name'],
		data:Ext.semester.semesterright
	});
	
	var divisionstore_right = new Ext.data.ArrayStore({
			fields:['division_id','division_name'],
			data: Ext.semester.division
		});	
		
	var divisionstore_left = new Ext.data.ArrayStore({
			fields:['division_id','division_name'],
			data: Ext.semester.division
		});	
	
	/*var year_left = new Ext.form.ComboBox({
		name: 'year_left',
		id:'year_left',
		hiddenName:'year_hidden_left',
		labelSeparator:'',	
		fieldLabel :'Year:<span class="comp">*</span>' ,
		displayField:'year_name',
		valueField: 'year_id',
		editable:true,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: yearstore,
		listeners: {'select': function(cmb, rec, idx){
			Ext.getCmp('branch_left').reset();
			Ext.getCmp('branch_right').reset();
			studentstore_left.removeAll();
			studentstore_right.removeAll();
		}}
	});
	
	var year_right = new Ext.form.ComboBox({
		name: 'year_right',
		id:'year_right',
		hiddenName:'year_hidden_right',
		labelSeparator:'',	
		fieldLabel :'Year:<span class="comp">*</span>',
		displayField:'year_name',
		valueField: 'year_id',
		editable:true,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: yearstore,
		listeners: {'select': function(cmb, rec, idx){
			Ext.getCmp('branch_left').reset();
			Ext.getCmp('branch_right').reset();
			studentstore_left.removeAll();
			studentstore_right.removeAll();
		}}
	});*/
	
	
	var branch_left = new Ext.form.ComboBox({
		name: 'branch_left',
		id:'branch_left',
		hiddenName:'branch_hidden_left',
		labelSeparator:'',	
		fieldLabel :labelArray[0] ,
		displayField:'branch_name',
		valueField: 'branch_id',
		editable:true,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: branchstore,
		listeners: {'select': function(cmb, rec, idx){
			Ext.getCmp('semester_left').reset();
			Ext.getCmp('semester_right').reset();
			studentstore_left.removeAll();
			studentstore_right.removeAll();
		}}
	});
	
	var branch_right = new Ext.form.ComboBox({
		name: 'branch_right',
		id:'branch_right',
		hiddenName:'branch_hidden_right',
		labelSeparator:'',	
		fieldLabel :labelArray[0] ,
		displayField:'branch_name',
		valueField: 'branch_id',
		editable:true,
		triggerAction:'all',
		mode:'local',
		readOnly:true,
		allowBlank:false,
		store: branchstore,
		listeners: {'select': function(cmb, rec, idx){
			Ext.getCmp('semester_left').reset();
			Ext.getCmp('semester_right').reset();
			studentstore_left.removeAll();
			studentstore_right.removeAll();
		}}
	});
	
	var semester_left = new Ext.form.ComboBox({
		name: 'semester_left',
		id:'semester_left',
		hiddenName:'semester_hidden_left',
		labelSeparator:'',	
		fieldLabel :labelArray[1] ,
		displayField:'semester_name',
		valueField: 'semester_id',
		editable:true,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: semesterstoreleft,
		listeners: {'select': function(cmb, rec, idx) {
		Ext.getCmp('division_left').reset();
		var branch=Ext.getCmp('branch_left').getValue();
		divisionstore_left.filter('division_id',branch+cmb.getValue(),false,true,true);
		var cnt=divisionstore_left.getCount();
		if(cnt==1)
		{
			Ext.getCmp('division_left').setValue(divisionstore_left.getAt(0).data.division_name);
		}
				
        }
		}
	});

	var semester_right = new Ext.form.ComboBox({
		name: 'semester_right',
		id:'semester_right',
		hiddenName:'semester_hidden_right',
		labelSeparator:'',	
		fieldLabel :labelArray[1] ,
		displayField:'semester_name',
		valueField: 'semester_id',
		editable:true,
		readOnly:true,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: semesterstoreright,
		listeners: {'select': function(cmb, rec, idx) {
		Ext.getCmp('division_right').reset();
		var branch=Ext.getCmp('branch_right').getValue();
		divisionstore_right.filter('division_id',branch+cmb.getValue(),false,true,true);
		var cnt=divisionstore_right.getCount();
		if(cnt==1)
		{
			Ext.getCmp('division_right').setValue(divisionstore_right.getAt(0).data.division_name);
		}
				
        }
		}
	});
	
	
	var division_left = {		
						xtype: 'combo',
						name: 'division_left',
						id:'division_left',
						labelSeparator:'',	
						fieldLabel :'Division :<span class="comp">*</span>' ,
						forceSelection:true,				
						displayField:'division_name',
						valueField: 'division_name'
						,lastQuery:''
						,allowBlank:false
						,triggerAction:'all'
						,mode:'local'
						,store:divisionstore_left
						,selectOnFocus: true,
						listeners: {'select': function(cmb, rec, idx) {}
					    }
				  }
	
	var division_right = {		
						xtype: 'combo',
						name: 'division_right',
						id:'division_right',
						labelSeparator:'',	
						readOnly:true,
						fieldLabel :'Division :<span class="comp">*</span>' ,
						forceSelection:true,				
						displayField:'division_name',
						valueField: 'division_name'
						,lastQuery:''
						,allowBlank:false
						,triggerAction:'all'
						,mode:'local'
						,store:divisionstore_right
						,selectOnFocus: true,
						listeners: {'select': function(cmb, rec, idx) {}
     }}



var shift_left = {		
						xtype: 'combo',
						name: 'shift_left',
						id:'shift_left',
						labelSeparator:'',	
						fieldLabel :'Shift :<span class="comp">*</span>' ,
						forceSelection:true,				
						displayField:'shift',
						valueField: 'shift'
						,lastQuery:''
						,allowBlank:false
						,triggerAction:'all'
						,mode:'local'
						,store:shiftstore
						,selectOnFocus: true,
						listeners: {'select': function(cmb, rec, idx) {}
					    }
				  }
	
	var shift_right = {		
						xtype: 'combo',
						name: 'shift_right',
						id:'shift_right',
						labelSeparator:'',	
						fieldLabel :'Shift :<span class="comp">*</span>' ,
						forceSelection:true,				
						displayField:'shift',
						valueField: 'shift'
						,lastQuery:''
						,allowBlank:false
						,triggerAction:'all'
						,mode:'local'
						,store:shiftstore
						,selectOnFocus: true,
						listeners: {'select': function(cmb, rec, idx) {}
     }}



var studentstore_left = new Ext.data.Store({
	proxy: new Ext.data.HttpProxy({url: 'data/getstudentdata2.php'}),
	reader: new Ext.data.JsonReader({id: 'student_id',root: 'data'},
	[{name:'value',mapping:'student_id'},{name:'text',mapping: 'student_name'}])
});	

	
	studentstore_right = new Ext.data.JsonStore({
		url:'data/getstudentdata1.php',
		root: 'data',
		totalProperty: 'total',
		fields: [{name: 'value', mapping:'student_id'}, {name: 'text', mapping: 'student_name'}] 
	});

    var SemTransferForm = new Ext.FormPanel({
        id:'SemTransferForm',
        frame: true,
        labelAlign: 'left',
		bodyStyle: 'padding:5px',
        url:'save-semtransfer.php',
		layout:'column',
		items:[{ 
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[{
				xtype: 'label',
				text: 'From Semester',
				style: 'padding:0px 0px',
				cls: 'x-form-item myBold'	
			}]
		},{ 
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[{
				xtype: 'label',
				text: 'To Semester',
				style: 'padding:0px 0px',
				cls: 'x-form-item myBold'	
			}]
		}/*,{  
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[year_left]
		},{  
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[year_right]
		}*/,{  
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[branch_left]
		},{ 
			columnWidth:.5,
		    labelWidth:75,  
			layout:'form',
			items:[branch_right]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',
			items:[semester_left]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',				  
			items:[semester_right]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',
			items:[division_left]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',				  
			items:[division_right]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',
			items:[shift_left]
		},{ 
			columnWidth:.5,
			labelWidth:75,  
			layout:'form',				  
			items:[shift_right]
		},{ 
			columnWidth:.5,
			layout:'form',
			items:[{   
				xtype:'button',
				text: 'Show',
				style: 'padding:0px 0px 10px 235px',	
				handler:function(){	 
					var branch_left	  = Ext.getCmp('branch_left').getValue();
					var branch_right  = Ext.getCmp('branch_right').getValue();
					
					
					var sem_left  = Ext.getCmp('semester_left').getValue();
					var sem_right = Ext.getCmp('semester_right').getValue();
					
					if(branch_left!="" &&  sem_left!="" ){   
						     
						
							Ext.getCmp('branch_left').disable();
							Ext.getCmp('branch_right').disable();
							Ext.getCmp('semester_left').disable();
							Ext.getCmp('semester_right').disable();
							Ext.getCmp('division_left').disable();
							Ext.getCmp('division_right').disable();
							Ext.getCmp('shift_left').disable();
							Ext.getCmp('shift_right').disable();
																				 
							studentstore_left.load({
								params:{
								branch_id:Ext.getCmp('branch_left').getValue(),
								semester_id:Ext.getCmp('semester_left').getValue(),
								division_id:Ext.getCmp('division_left').getValue(),
								shift1:Ext.getCmp('shift_left').getValue()
								
								}});
							studentstore_right.load({
								params:{branch_id:Ext.getCmp('branch_right').getValue(),
								semester_id:Ext.getCmp('semester_right').getValue(),
								division_id:Ext.getCmp('division_left').getValue(),
								shift1:Ext.getCmp('shift_left').getValue()
								}});
						
					} 
	               	else{
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'Fill up all of the above Fields',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.ERROR
						});
					} 
				}
			}]
		},{ 
			columnWidth:.5,
			layout:'form',
			items:[{  
				xtype:'button',
				text: 'Reset',
				style: 'padding:0px 0px 10px 0px',	
				handler: function () {	 
					Ext.getCmp('branch_left').reset();
					Ext.getCmp('branch_right').reset();
					Ext.getCmp('semester_left').reset();
					Ext.getCmp('semester_right').reset();
					Ext.getCmp('division_left').reset();
					Ext.getCmp('division_right').reset();
					Ext.getCmp('shift_left').reset();
					Ext.getCmp('shift_right').reset();
							
					studentstore_left.removeAll();	
					studentstore_right.removeAll();	
					Ext.getCmp('branch_left').enable();
					Ext.getCmp('branch_right').enable();
					Ext.getCmp('semester_left').enable();
					Ext.getCmp('semester_right').enable();
					Ext.getCmp('division_left').enable();
					Ext.getCmp('division_right').enable();
					Ext.getCmp('shift_left').enable();
					Ext.getCmp('shift_right').enable();
					Ext.getCmp('branch_left').focus(true,500);
				}
			}]
		},{ 
			columnWidth: 1,
			layout: 'form',
			labelWidth:10,
			items:[{
				xtype: 'itemselector', 
				name: 'studentlist_left', 
				id:'studentlist_left', 
				fieldLabel: '', 
				multiselects:[{    
					name:'first', 
					id:'first', 
					width: 370, 
					height: 200, 
					store: studentstore_left, 
					displayField: 'text', 
					valueField: 'value',
					legend:''
                },{   
					width: 370, 
					height: 200, 
					store: studentstore_right, 
					displayField: 'text', 
					valueField: 'value', 
					legend:''
				}]
         	}]
		},{  
			columnWidth: 1,
			layout: 'form',
			labelWidth:10,
			items:[{
				xtype: 'itemselector', 
				name: 'studentlist_right', 
				id:'studentlist_right', 
				fieldLabel: '',
				hidden:true, 
				multiselects:[{  
					width: 225, 
					height: 200, 
					store: studentstore_right, 
					displayField: 'text', 
					valueField: 'value', 
					legend:''
				},{   
					width: 225, 
					height: 200, 
					store: studentstore_left, 
					displayField: 'text', 
					valueField: 'value', 
					legend:''
				}]
         	}]
		}]
    });

	studentstore_right.on({'afterload': {
		fn: function(store, options){ 
			if(studentstore_right.getCount() <= 0 && studentstore_left.getCount() <= 0){
				Ext.MessageBox.show({
					title: 'Error',
					msg: 'There is no Student Found in this Selection',
					buttons: Ext.MessageBox.OK,
					icon:Ext.MessageBox.ERROR
				});
			} 
		}
	}});

	var SemTransferWindow = new Ext.Window({
    	title:'Semester Transfer',
		width:820,		
		height:460,	
		modal:true,	
		border: false,
		layout: 'fit',
		closeAction:'close',
		collapsible:true,
		items: SemTransferForm,
		buttonAlign: 'center',
	    buttons:[{
			text: 'Save',
			handler:function(){  	
				Ext.getCmp('branch_left').enable();
				Ext.getCmp('branch_right').enable();
				Ext.getCmp('semester_left').enable();
				Ext.getCmp('semester_right').enable();
				Ext.getCmp('division_left').enable();
				Ext.getCmp('division_right').enable();
				Ext.getCmp('shift_left').enable();
				Ext.getCmp('shift_right').enable();
				
				SemTransferForm.getForm().submit({
					waitMsg: 'Saving...',
					success: function(resp)
					{
						if(resp.responseText == 'true')
						{
							Ext.MessageBox.show({
							title: 'Message',
							msg: 'Successfully saved',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.INFO
							});
					   		 SemTransferForm.getForm().reset();
							studentstore_left.removeAll();	
							studentstore_right.removeAll();
						}
						else
						{
							Ext.MessageBox.show({
							title: 'Message',
							msg: 'Please Collect Fees First',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.INFO
						});
					    SemTransferForm.getForm().reset();
						studentstore_left.removeAll();	
						studentstore_right.removeAll();
						}
					},
					failure: function () 
					{
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'Saving data failed!',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.ERROR
						});
						Ext.getCmp('branch_left').disable();
						Ext.getCmp('branch_right').disable();
						Ext.getCmp('semester_left').disable();
						Ext.getCmp('semester_right').disable();						
					}
				});
			}
        },{
			text: 'Close',
			handler: function () {  
				SemTransferWindow.close();
			}
      	}]

	});
		SemTransferForm.getForm().findField('branch_left').on('blur',function (){
	
		var branch_left =SemTransferForm.getForm().findField('branch_left').getValue();
		
	
	Ext.getCmp('branch_right').setValue(branch_left);	
	
	});
	
		SemTransferForm.getForm().findField('division_left').on('blur',function (){
	
		var division_left =SemTransferForm.getForm().findField('division_left').getValue();
		
	
	Ext.getCmp('division_right').setValue(division_left);	
	
	});



	SemTransferForm.getForm().findField('semester_left').on('blur',function (){
	
		
		
		var semester_left =SemTransferForm.getForm().findField('semester_left').getValue();
		
			
		
		
		if(semester_left == 1)
		{
		Ext.getCmp('semester_right').setValue('2nd sem');	
		}
		else if(semester_left == 2)
		{
			Ext.getCmp('semester_right').setValue('3rd sem');	
		}
		else if(semester_left == 3)
		{
			Ext.getCmp('semester_right').setValue('4th sem');	
		}
		else if(semester_left == 4)
		{
			Ext.getCmp('semester_right').setValue('5th sem');	
		}
		else
			{
				Ext.getCmp('semester_right').setValue('6th sem');	
			}
	});
	
	var varWidth =  (screen.width - SemTransferWindow.width)/2;
	SemTransferWindow.setPosition(varWidth,((screen.height/4)-85));
	SemTransferWindow.show();
	Ext.getCmp('branch_left').focus(true,1000);
});
</script>
</div>
</div>
<?php require "_footer.php";?>