<?php require "_header.php";
require "includeLanguageBar.php";
require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
?>



<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>	


<!-- s
tart custom CSS/JS -->
<style type="text/css">
	label.myBold
	{
	   font-weight: bold;
	   color:#15428B;
	   font-size: 10px;
	}
</style>

<script type="text/javascript">
Ext.override(Ext.ux.form.LovCombo, {
	beforeBlur: Ext.emptyFn
});

 
 


Ext.onReady(function(){
    Ext.QuickTips.init();
	
	var Circular_typestore = new Ext.data.ArrayStore({
		fields: ['circular_type_id','circular_type'],
		data: [['1','News'],['2','Circular'],['3','Notice']]
	});

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

		var yearstore = new Ext.data.ArrayStore({
			fields: ['branch_id', 'branchyear_id', 'branchyear_name'],
			data: Ext.year.year
		});
	
	var Result_Fields = [
	{name: 'circular_id', 	type: 'int'},
	{name: 'circular_type', 	type: 'int'},
	{name: 'circular_type_name', 	type: 'string'},
	//{name: 'circular_type_id', 	type: 'int'},
	{name: 'circular_subject',	type: 'string'},
	{name: 'circular_file', 	type: 'string'},
	
	{name: 'branch_id', 	type: 'int'},
	{name: 'year_id', 	type: 'int'},
	{name: 'branchyear_id', 	type: 'int'},
	{name: 'semester_id', 	type: 'int'},

	{name: 'branch_name', 	type: 'string'},
	{name: 'year_name', 	type: 'string'},
	{name: 'branchyear_name', 	type: 'string'},
	{name: 'semester_name', 	type: 'string'},
	{name: 'all_student_id'},
	{name: 'all_employee_id'},
	
	{name: 'circular_active'},
	{name: 'circular_active_status', type: 'string'},
	
	{name: 'student_id', 	type: 'string'},
	{name: 'employee_id', 	type: 'string'},
	
	{name: 'circular_start_date' },
	{name: 'circular_end_date' },
	
];

var resultStore = new Ext.data.JsonStore({
   url: 'data/circular-grid-data.php',
    root: 'data',
    fields: Result_Fields,
    autoLoad: true,
	/*remoteGroup:true,
	remoteSort: true,*/
	groupField:'circular_type'
});	

var colModel = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
		{
			header:'Circular Type',
			id: 'circular_type',
			dataIndex:'circular_type',
			//width: 75,
			hidden:true
		},
		{
			header:'Circular Type',
			id: 'circular_type_name',
			dataIndex:'circular_type_name',
			width: 75
		},{ 
			id: 'circular_subject',
			header: "Description",
			width: 410,
			dataIndex: 'circular_subject',
			sortable: true
        },{
			id: 'circular_file',
			header: "File Name",
			width: 90,
			dataIndex: 'circular_file',
			sortable: true
		},{
			id: 'circular_active_status',
			header: "Active",
			width: 60,
			dataIndex: 'circular_active_status',
			sortable: true
		}
    ]);
	
	var grid = new Ext.grid.GridPanel({
   		store: resultStore,
        cm: colModel,
		columnLines: true,
		//features: [groupingFeature],
		//stateful: true,
		loadMask:true,
		stripeRows: true,
		autoScroll:true,
		columnLines: true,
        sm: new Ext.grid.RowSelectionModel({
        	singleSelect: true,
            listeners: {
            	rowselect: function(sm, row, rec) {
                	Ext.getCmp("CircularForm").getForm().loadRecord(rec);
					Ext.getCmp('newPic').setValue(rec.data.circular_file);
					Ext.getCmp('btnSave').enable();
					Ext.getCmp('btnDelete').enable();
					//var gender= rec.data.gender;
					//Ext.getCmp('gender').setValue(gender);
					
				}
         	},
			 renderTo: Ext.getBody()
   		}),
		height: 400,
		border: true
 	});

	grid.on('render', function(){
		grid.tip = new Ext.ToolTip({
    		view: grid.getView(),
    		target: grid.getView().mainBody,
    		delegate: '.x-grid3-row',
    		trackMouse: true,
    		renderTo: document.body,
    		listeners: {
     			beforeshow: function updateTipBody(tip) {
      				tip.body.dom.innerHTML = "Please click here to edit record.";
     			}
    		}
   		});
  	});
	
	var circular_type = new Ext.form.ComboBox({
		name: 'circular_type',
		id:'circular_type',
		hiddenName:'circulartype_hidden',
		labelSeparator:'',	
		fieldLabel :'Circular Type: <span class="comp">*</span>' ,
		displayField:'circular_type',
		valueField: 'circular_type_id',
		editable:true,
		tabIndex:1,
		width:175,
		triggerAction:'all',
		mode:'local',
		allowBlank:false,
		store: Circular_typestore
	});
	

var newPic = new Ext.form.FileUploadField({
	fieldLabel: 'File <span class="comp"></span>',
	name: 'newPic',					
	id:'newPic',
	allowBlank: true,
	tabIndex:4,
	width:175
});

var subject = new Ext.form.TextArea({
	labelSeparator:'',
	fieldLabel: 'Description :<span class="comp">*</span>',
	name: 'circular_subject',					
	id:'circular_subject',
	allowBlank: false,
	tabIndex:3,
	width:175
});

var CircularForm = new Ext.FormPanel({	
		id: 'CircularForm',
		url: 'save-circular.php',
		frame: true,
		autoHeight:true,
		fileUpload: true,
		layout: 'column',
    	items: [
			{
				columnWidth: 0.71,
				layout: 'fit',
				items:[grid]
			},
			{
            	columnWidth: 0.29,
         		items: [{
								columnWidth: 1,
								labelWidth:85,
								style: 'padding:0px 5px',
								layout: 'form',
								items:[
										circular_type,
										subject,
										newPic,
										{
					xtype: 'combo',
					name: 'branch_id',
					id: 'branch_id',
					hiddenName: 'branch_hidden',
					fieldLabel: 'Course ',
					displayField: 'branch_name',
					valueField: 'branch_id',
					width: 180,
					triggerAction: 'all',
					mode: 'local',
					allowBlank: false,
					store: branchstore,
					listeners: {
						'select': function (cmb, rec, idx) {
					//		Ext.getCmp('branch_disp').setValue(this.getRawValue());
							Ext.getCmp('semester_id').reset();
							Ext.getCmp('year_id').reset();
							Ext.getCmp('branchyear_id').reset();
							
							
							semesterstore.filter('branch_id', cmb.getValue(), false, true, true);
							yearstore.filter('branch_id', cmb.getValue(), false, true, true);
							var semesterCombo = Ext.getCmp('semester_id');
							if (cmb.getValue() == 3 || cmb.getValue() == 5) {
								semesterCombo.enable();
							} else {
								semesterCombo.disable();
								semesterCombo.reset();
							}
						}
					}
				}, {
					xtype: 'combo',
					name: 'year_id',
					id: 'year_id',
					hiddenName: 'year_hidden',
					fieldLabel: 'Batch year ',
					displayField: 'year_name',
					valueField: 'year_id',
					lastQuery: '',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: false,
					store: batchyearstore,
					
				}, {
					xtype: 'combo',
					name: 'branchyear_id',
					id: 'branchyear_id',
					hiddenName: 'branchyear_hidden',
					fieldLabel: 'Course Year',
					displayField: 'branchyear_name',
					valueField: 'branchyear_id',
					lastQuery: '',
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: false,
					store: yearstore,
					listeners: {
						'select': function (cmb, rec, idx) {
							//Ext.getCmp('branchyear_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_id').getValue() != "") {
								
							} else {
								alert('Select Branch First')
								this.reset();
							}
						}
					}
				}, {
					xtype: 'combo',
					name: 'semester_id',
					id: 'semester_id',
					hiddenName: 'semester_hidden',
					fieldLabel: 'Semester',
					displayField: 'semester_name',
					valueField: 'semester_id',
					lastQuery: '',
					disabled: true,
					triggerAction: 'all',
					mode: 'local',
					width: 180,
					allowBlank: false,
					store: semesterstore,
					listeners: {
						'select': function (cmb, rec, idx) {
						//	Ext.getCmp('semester_disp').setValue(this.getRawValue());
							if (Ext.getCmp('branch_id').getValue() != "") {
								
							} else {
								alert('Select Branch First')
								this.reset();
							}
						}
					}
				},
									{
										id:'all_student_id',
										name:'all_student_id',
										xtype:'checkbox',
										labelSeparator:'',
										tabIndex:7,
										//store: svsstore,
										fieldLabel:'All Student',
										handler: function(){
										/*if(this.getValue()==true)
											{
												Ext.getCmp('svscombo').disable();	
												Ext.getCmp('school_type').disable();
												Ext.getCmp('grantcombo').disable();	
												
												Ext.getCmp('svscombo').reset();	
												Ext.getCmp('school_type').reset();
												Ext.getCmp('grantcombo').reset();												 
											}
										else
											{
												Ext.getCmp('svscombo').enable();	
												Ext.getCmp('school_type').enable();	
												Ext.getCmp('grantcombo').enable();			
											}*/
									   }
										
									},{
										allowBlank:true,
										msgTarget: 'title',
										id:'all_employee_id',
										name:'all_employee_id',
										xtype:'checkbox',
										labelSeparator:'',
										fieldLabel:'All Employee',
										width:175,
										tabIndex:8,
										resizable: false,
										autoScroll:false,
										//store: employeestore,
										mode: 'local',
										editable:false,
										valueField: 'employee_id',
										
									},{
										allowBlank:true,
										id:'circular_active',
										name:'circular_active',
										xtype:'checkbox',
										labelSeparator:'',
										fieldLabel:'Circular Active',
										width:175,
										tabIndex:8,
										resizable: false,
										autoScroll:false,
										//store: employeestore,
										mode: 'local',
										editable:false,
										valueField: 'circular_active',
										
									},{
										xtype: 'datefield',
										name: 'circular_start_date',
										id:'circular_start_date',
										labelSeparator:'',	
										//format:'d-M-Y',
										//altFormats:'Y-m-d',
										fieldLabel :'Start Date :<span class="comp">*</span>',
										tabIndex:9,
										maxValue:new Date(),
										value:new Date(),
										allowBlank:false,
										width:175
									},{
										xtype: 'datefield',
										name: 'circular_end_date',
										id:'circular_end_date',
										labelSeparator:'',	
										//format:'d-M-Y',
										//altFormats:'Y-m-d',
										fieldLabel :'End Date :<span class="comp">*</span>',
										tabIndex:10,
										//maxValue:new Date(),
										value:new Date(),
										allowBlank:false,
										width:175
									},
									{
										 xtype:'textfield',
										 id:'circular_id',
										 name:'circular_id',
										 hidden:true
									 }]
							
        			}
				]
			}
		]
    });
	
	var CircularWindow = new Ext.Window({
		tbar: languageToolbar,
		title: 'Circular Detail',
		width:1000,
		autoHeight:true,
		//height:500,	
		frame: true,
		autoScroll:true,
   	 	collapsible:'true',
		closeAction:'close',
		items: CircularForm,
		buttons:[{
				text: 'Save', 
				tabIndex:11,
				name:'btnSave',
				iconCls:'icon-save',
				id:'btnSave',
				handler: function(){
					var flage =0;
					if(Ext.getCmp('newPic').getValue() !='')
					{
						var res = validate();
						if(res)
						{
							flage=1;
						}
						else {
							flage=0;
						}
					}else{
						flage= 1;
					}
					if(flage == 1){	
					CircularForm.getForm().submit({
					waitMsg: 'Saving...',
					success: function () {	
							//Ext.MessageBox.confirm('Confirmation',' Do U Want To Send SMS To School Principal Regaring This Circular ?',deleteallowances);
						Ext.MessageBox.show({
							title: 'Message',
							msg: 'Data has been saved',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.INFO
						});	
						CircularForm.getForm().reset();
						Ext.getCmp('btnDelete').disable();
						resultStore.load();
					},
					failure: function () {
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'Please fill up complete form.',
							buttons: Ext.MessageBox.OK,
							icon:Ext.MessageBox.ERROR
						});									
					}
					});							
				}	
				}
			},{
				text: 'Delete',
				iconCls:'remove',
				id:'btnDelete',
				name:'btnDelete',
				tabIndex:12,
				handler: function(){
					CircularForm.getForm().submit({
						waitMsg: 'Deleting...',
						params:{act:'del'},
						success: function () {	
							CircularForm.getForm().reset();	
							Ext.getCmp('circular_id').setValue('0');	
							resultStore.load();									
						}
					});
				}
			},{
				text: 'Reset', 
				tabIndex:13,
				iconCls:'icon-reset',
				name:'btnreset',
				id:'btnreset',
				handler: function (){
					CircularForm.getForm().reset();
					Ext.getCmp('circular_id').setValue('0');
					grid.getSelectionModel().clearSelections();
					Ext.getCmp('btnDelete').disable();
				//	Ext.getCmp('btnSave').disable();
					
				}
			},
			{
				text:'Close', 
				tabIndex:14,
				iconCls:'icon-close',
				name:'btnclose',
				id:'btnclose',
				handler: function (){
					CircularWindow.close();
				}
			}
		]
	});

	var varWidth =  (screen.width - CircularWindow.width)/2;
	CircularWindow.setPosition(varWidth,((screen.height/4)-110));
	CircularWindow.show();
	initIndicIME();
	//Ext.getCmp('all_school').setValue('true');
	//CircularForm.getForm().findField('circular_titel').focus(true,500);
});
function validate()
{
	var fruits = ["txt", "TXT","xls","XLS","pdf","PDF","jpg", "JPG", "gif", "gif","png", "PNG", "jpeg", "JPEG","doc","DOC","docx","DOCX","ppt","pptx","flv"];
	var f_ext = document.getElementById("newPic").value.match(/(.{3}$)/)[1];	
	
	var a = fruits.indexOf(f_ext); 
	if(a == -1)
	{
		alert(" Invalid file format, please try again!");
		document.getElementById("newPic").value='';
		document.getElementById("newPic").focus();
		return false;
	}
	else
	{
		return true;
	}
}
</script>
<!-- end custom CSS/JS -->
<div id="main-content"></div>
<?php require "_footer.php";?>