<?php
require "_header.php";
require "data/combo_student.php";
require "data/combo_semester.php";
require "data/combo_branchyear.php";
require "data/allocated_sbuject.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">

		var curTime = "";
		var d = new Date(); // for now
		curTime = d.getHours(); // => 9
		//d.getMinutes(); // =>  30
		//d.getSeconds(); // => 51      

		Ext.override(Ext.ux.form.LovCombo, {
			beforeBlur: Ext.emptyFn
		});
		Ext.override(Ext.form.Field, {
			setFieldLabel: function (text) {
				if (this.rendered) {
					this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text);
				}
				this.fieldLabel = text;
			}
		});

		Ext.onReady(function () {
			Ext.QuickTips.init();
			var labelArray;
			labelArray = [
				['Course <span class="comp">*</span>'],
				['Batch Year <span class="comp">*</span>'],
				['Course Year <span class="comp">*</span>'],
				['Semester <span class="comp">*</span>'],
				['Batch Name:<span class="comp">*</span>'],
				['Subject <span class="comp">*</span>'],
				['W-H day <span class="comp">*</span>'],
				['Date <span class="comp">*</span>'],
				['Note <span class="comp">*</span>'],
				['Lecture <span class="comp">*</span>']

			];


			var abstudentSmsId = "";
			var presentDate;
			presentDate = "";
			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 }
			});



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

			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 subjectstore = new Ext.data.JsonStore({
				url:'data/get-subject.php',
   			 	root: 'data',
				totalProperty: 'total',
				fields: ['subject_id','subject_name'] 
				});
				subjectstore.load({params:{task:'getall'}});


			/*var lectype = new Ext.form.ComboBox({
				name: 'lectype',
				id:'lectype',
				hiddenName:'lectype_hid',
				labelSeparator:'',	
				fieldLabel :'Type: <span class="comp">*</span>' ,
				displayField:'lectype_name',
				valueField: 'lectype_id',
				editable:true,
				triggerAction:'all',
				mode:'local',
				tabIndex:7,
				width:163,
				allowBlank:false,
				store: lectypestore,
				listeners: {'select': function(cmb, rec, idx){
					var val=cmb.getValue();
					if(val==1){
						Ext.getCmp('day_comment').setFieldLabel('Topic Covered:<span class="comp">*</span>');  
					}
					else if(val==2){
						Ext.getCmp('day_comment').setFieldLabel('Experiment Name:<span class="comp">*</span>');  
					}else{
						Ext.getCmp('day_comment').setFieldLabel('Note:<span class="comp">*</span>');  
					}
				}}
			});*/



			var workingstore = new Ext.data.ArrayStore({
				fields: ['working_id', 'working_value'],
				data: [['1', 'Working Day'], ['0', 'Holiday']]
			});

			var lecstore = new Ext.data.ArrayStore({
				fields: ['lec_id', 'lec_name'],
				data: Ext.semester.lec
			});

			/*var notestore = new Ext.data.JsonStore({
				url: 'data/note-combo.php',
				root: 'data',
				  fields: ['day_comment']
			});	
			*/
			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/getstudent-present.php',
				root: 'data',
				storeId: 'student_id',
				totalProperty: 'total',
				fields: [{
					name: 'student_id',
					type: 'int'
				}, {
					name: 'student_name',
					type: 'string'
				}, {
					name: 'student_gturegno',
					type: 'string'
				}, {
					name: 'day_present'
				}, {
					name: 'student_mobilestudents'
				}, {
					name: 'student_mobileparents'
				}]
			});

			var colModel = new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
				{
					dataIndex: 'student_id',
					header: 'Student ID',
					id: 'student_id',
					hidden: true
				}, {
					dataIndex: 'student_gturegno',
					header: 'Enrollment No',
					sortable: true,
					width: 120
				}, {
					dataIndex: 'student_name',
					header: 'Student Name',
					sortable: true,
					width: 550,
					id: 'SurName'
				}, {
					dataIndex: 'student_mobilestudents',
					header: 'Mobile Student',
					sortable: true,
					hidden: true,
					width: 90
				}, {
					dataIndex: 'student_mobileparents',
					header: 'Mobile Parents',
					sortable: true,
					width: 100,
					hidden: true,
					id: 'student_mobileparents'
				}, checkColumn]);


			var grid = new Ext.grid.GridPanel({
				store: store,
				cm: colModel,
				loadMask: true,
				enableColLock: false,
				height: 355,
				width: 790,
				plugins: checkColumn,
				clicksToEdit: 1,
				layout: 'fit',
				columnLines: true
			});

			Ext.override(Ext.Editor, {
				onBlur: function () {
					if (this.allowBlur === true && this.editing) {
						this.completeEdit();
					}
				}
			});

			allocation_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: 'batch_id' },
				{ name: 'subject_id' }, 
				{ name: 'year_id' },
				{ name: 'branchyear_id' },
				//	{name: 'lectype'},
				// {name: 'lectype_name'},
				{ name: 'employee_id' },
				 { name: 'branch_name' },
				{ name: 'semester_name' },
				{ name: 'year_name' },
				{ name: 'branchyear_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: 'Course',
					sortable: true,
					width: 80
				},
				{
					dataIndex: 'year_name',
					header: 'Batch Year',
					sortable: true,
					width: 80
				},
				{
					dataIndex: 'branchyear_name',
					header: 'Course Year',
					sortable: true,
					width: 80
				}, {
					dataIndex: 'semester_name',
					header: 'Semester',
					sortable: true,
					width: 70,
				},  {
					dataIndex: 'batch_name',
					header: 'Batch',
					sortable: true,
					width: 70
				}, {
					dataIndex: 'subject_name',
					header: 'Subject',
					sortable: true,
					width: 250
				},
				/*{
					dataIndex: 'lectype_name',
					header: 'Lec Type',
					sortable:true,
					width:70
				}*/
			]);


			var allocation_grid = new Ext.grid.GridPanel({
				store: allocation_store,
				cm: colModel,
				loadMask: true,
				sm: new Ext.grid.RowSelectionModel({
					singleSelect: true,
					listeners: {
						rowselect: function (sm, row, rec) {
							store.removeAll();
							var branch_name = rec.data.branch_id;
							var semester_name = rec.data.semester_id;
							if (branch_name != '' && semester_name != '') {
								subjectstore.load(
									{
										params: { branch_name: branch_name, semester_name: semester_name },
										scope: this,
										callback: function (records, operation, success) {
											if (success) {
												Ext.getCmp('subject_name').setRawValue(rec.data.subject_name);
												Ext.getCmp('subject_name').setValue(rec.data.subject_id);
											}
										}

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


							/*var val=rec.data.lectype;
							if(val==1){
								Ext.getCmp('day_comment').setFieldLabel('Topic Covered:<span class="comp">*</span>');  
							}
							else if(val==2){
								Ext.getCmp('day_comment').setFieldLabel('Experiment Name:<span class="comp">*</span>');  
							}else{
								Ext.getCmp('day_comment').setFieldLabel('Note:<span class="comp">*</span>');  
							}*/

						}
					}
				}),
				enableColLock: false,
				height: 200,
				width: 790,
				plugins: checkColumn,
				clicksToEdit: 1,
				lauout: 'form',
				columnLines: true
			});
			<?php if ($faculty_id) { ?>
				allocation_store.load({ params: { 'employee_id': <?php echo $faculty_id; ?> } });
			<?php } ?>


			
			var PresentForm = new Ext.FormPanel({
				method: 'post',
				id: 'PresentForm',
				name: 'PresentForm',
				frame: true,
				url: 'save-daily-present.php',
				standardSubmit: false,
				layout: 'column',
				items: [{
					columnWidth: 1,
					xtype: 'fieldset',
					collapsible: true,
					border: true,
					height: 200,
					collapsed: true,
					title: '<?php echo $table_string; ?> [Click To View Alloted Subject Detail ]',
					layout: 'fit', items: [<?php if ($faculty_id != "") { ?>allocation_grid <?php } ?>]
				}, {
					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,
						triggerAction: 'all',
						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();
								}
							}
						}
					}, {
						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,
						allowBlank: true,
						store: yearstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								//Ext.getCmp('branchyear_disp').setValue(this.getRawValue());
								if (Ext.getCmp('branch_name').getValue() != "") {

								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					}, {
						xtype: 'combo',
						name: 'workingday',
						hiddenName: 'working_id',
						allowBlank: false,
						id: 'workingday',
						emptyText: 'Please select day...',
						fieldLabel: labelArray[6],
						forceSelection: true,
						tabIndex: 8,
						displayField: 'working_value',
						valueField: 'working_id',
						width: 163,
						triggerAction: 'all',
						mode: 'local',
						store: workingstore
					},
					{
						xtype: 'textfield',
						name: 'day_comment',
						hiddenName: 'day_comment',
						id: 'day_comment',
						fieldLabel: labelArray[8],
						allowBlank: false,
						width: 163,
						tabIndex: 10,
						
					},
					{
						xtype: 'textfield',
						id: 'day_id',
						name: 'day_id',
						hidden: true
					}]
				}, {
					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,
						allowBlank: true,
						store: batchyearstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								//Ext.getCmp('year_disp').setValue(this.getRawValue());
							}
						}
					}, {
						xtype: 'combo',
						name: 'semester_name',
						id: 'semester_name',
						hiddenName: 'semester_hidden',
						fieldLabel: labelArray[3],
						displayField: 'semester_name',
						valueField: 'semester_id',
						lastQuery: '',
						disabled: true,
						triggerAction: 'all',
						mode: 'local',
						width: 163,
						allowBlank: true,
						store: semesterstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								//	Ext.getCmp('semester_disp').setValue(this.getRawValue());
								if (Ext.getCmp('branch_name').getValue() != "") {

								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					}, {
						xtype: 'datefield',
						fieldLabel: labelArray[7],
						width: 163,
						
						id: 'day_date',
						name: 'day_date',
						tabIndex: 9,
						format: JSDateFormat,
						minValue: new Date(),
						maxValue: new Date(),
						value: new Date(),
						vtype: 'daterange',
						allowBlank: false,
						listeners: {
							beforerender: function (c) {
								<?php if ($_SESSION["VedantnrUserRole"] == "PowerUser") { ?>
									c.setMinValue("");
								<?php } ?>
								if (Number(curTime) >= 19) {
									c.disable();
								} else {
									c.enable();
								}
							}
						}
					}]
				},
				{
					columnWidth: 0.33,
					layout: 'form',
					labelWidth: 85,
					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: 'combo',
						name: 'subject_name',
						id: 'subject_name',
						hiddenName: 'subject_hidden',
						fieldLabel: labelArray[5],
						displayField: 'subject_name',
						valueField: 'subject_id',
						triggerAction: 'all',
						mode: 'local',
						tabIndex: 7,
						width: 163,
						allowBlank: true,
						store: subjectstore,
						listeners: {
							'select': function (cmb, rec, idx) {
								if (Ext.getCmp('branch_name').getValue() != "") {

								} else {
									alert('Select Branch First')
									this.reset();
								}
							}
						}
					}, {
						xtype: 'lovcombo',
						allowBlank: false,
						id: 'lecid',
						name: 'lecid',
						hiddenName: 'lec_id',
						fieldLabel: labelArray[9],
						width: 163,
						resizable: false,
						autoScroll: false,
						store: lecstore,
						mode: 'local',
						lastQuery: '',
						tabIndex: 11,
						editable: false,
						displayField: 'lec_name',
						displayFieldTpl: '{student_curdiv}',
						valueField: 'lec_id',
						forceSelection: true,
						navigateItemsWithTab: false,
						listeners: {
							'select': function (cmb, rec, idx) {
								//	var day_comment_val=Ext.getCmp('lectype').getValue();


							}
						}
					}, {
						columnWidth: 0.5,
						layout: 'column',
						labelWidth: 85,
						items: [{
							columnWidth: 0.69,
							layout: 'form',
							style: 'padding:0px 0px 0px 90px',
							labelWidth: 85,
							items: [{}]
						}, {
							columnWidth: 0.69,
							layout: 'form',
							style: 'padding:0px 0px 0px 90px',
							labelWidth: 85,
							items: [{
								xtype: 'button',
								text: 'View',
								iconCls: 'icon-view',
								width: 70,
								tabIndex: 12,
								handler: function () {

									var varentrydate = Ext.getCmp('day_date').getValue();
									var varbranch = Ext.getCmp('branch_name').getValue();
									var varyear = Ext.getCmp('year_name').getValue();
									var varbranchyear = Ext.getCmp('branchyear_name').getValue();
									var varsemester = Ext.getCmp('semester_name').getValue();
									var varsubject = Ext.getCmp('subject_name').getValue();
									var varbatch = Ext.getCmp('batch_id').getValue();
									var varlec = Ext.getCmp('lecid').getValue();
									//	var varlectype=Ext.getCmp('lectype').getValue();


									var resbool = "";
									if (varentrydate != "" && varbranch != ""  && varsubject != "" && varlec != "") {

										Ext.Ajax.request({
											loadMask: true,
											sync: true,
											url: 'check-subject-allocation.php',
											params: {
												action: 'Check', 
												branch_name: varbranch,
												year_name: varyear,
												beanchyear_name: varbranchyear,
												semester_name: varsemester,
												subject_name: varsubject,
												batch_id: varbatch,
												//lectype:varlectype,

											},
											success: function (resp) {
												resbool = Ext.decode(resp.responseText).success;
												if (resbool == 'true') {

													Ext.Ajax.request({
														loadMask: true,
														sync: true,
														url: 'data/presententryrepeat.php',
														params: {
															branch: varbranch,
															year: varyear,
															branchyear: varbranchyear,
															semester: varsemester,
															subject: varsubject,
															day_date: varentrydate,
															batch_id: varbatch,
															lec_id: varlec,
															//lectype:varlectype,
															//div_id: vardiv
														},
														success: function (resp) {
															resbool = Ext.decode(resp.responseText).success;
															var day_id = Ext.decode(resp.responseText).day_id;
															Ext.getCmp('day_id').setValue(day_id);
															if (day_id == -1) {
																Ext.MessageBox.show({
																	title: 'Error',
																	msg: 'Mismatch Sequence of Lec!',
																	buttons: Ext.MessageBox.OK,
																	icon: Ext.MessageBox.ERROR
																});
															}
															else if (day_id == -2) {
																Ext.MessageBox.show({
																	title: 'Error',
																	msg: Ext.getCmp('lecid').getRawValue() + '`s Attendance is already taken!',
																	buttons: Ext.MessageBox.OK,
																	icon: Ext.MessageBox.ERROR
																});
															}
															else if (day_id == -3) {
																Ext.MessageBox.show({
																	title: 'Error',
																	msg: 'Inform to PowerUser for Edit it!',
																	buttons: Ext.MessageBox.OK,
																	icon: Ext.MessageBox.ERROR
																});
															}
															else if (day_id != 0) {
																Ext.MessageBox.confirm('Confirmation', 'Present Entry is already existed for this course,Batch year, Course YearSemester and date.Do u want to modify this record?', editstudent);
															} else {
																grid.stopEditing();
																store.load({ params: { 'branch_id': Ext.getCmp('branch_name').getValue(), 'semester_id': Ext.getCmp('semester_name').getValue(), 'subject_id': Ext.getCmp('subject_name').getValue(), 'batch_id': Ext.getCmp('batch_id').getValue() } });
															}
														}
													});


												} else {
													Ext.MessageBox.show({
														title: 'Error',
														msg: 'You are not been allocated for this selection Please see subject allocation for more detail.',
														buttons: Ext.MessageBox.OK,
														icon: Ext.MessageBox.ERROR
													});
												}
											}
										});

									} else {
										Ext.MessageBox.show({
											title: 'Error',
											msg: 'Please select Course, Semester, Batch year, Course Year, Subject, Lecture and Date',
											buttons: Ext.MessageBox.OK,
											icon: Ext.MessageBox.ERROR
										});
									}

								}
							}

							]
						},
						{
							xtype: 'checkbox',
							name: 'chk',
							id: 'chk',
							checked: false,
							labelSeparator: '',
							fieldLabel: 'Cancel',
							allowBlank: true,
							handler: function () {
								var check = Ext.getCmp('chk').getValue(checked = true)
								{
									grid.stopEditing();
									store.load({ params: { 'chk': Ext.getCmp('chk').getValue(), 'branch_id': Ext.getCmp('branch_name').getValue(), 'semester_id': Ext.getCmp('semester_name').getValue(), 'subject_id': Ext.getCmp('subject_name').getValue(), 'batch_id': Ext.getCmp('batch_id').getValue() } });
								}
							}
						},
						{
							columnWidth: 0.29,
							layout: 'form',
							style: 'padding:0px 0px 0px 0px',
							labelWidth: 70,
							items: [{
								xtype: 'button',
								iconCls: 'icon-reset',
								text: 'Reset',
								width: 70,
								tabIndex: 13,
								name: 'btnReset',
								id: 'btnReset',
								handler: function () {
									store.removeAll();
									PresentForm.getForm().reset();
									Ext.getCmp('branch_name').enable();
									Ext.getCmp('semester_name').enable();
									Ext.getCmp('branchyear_name').enable();
									Ext.getCmp('year_name').enable();

									Ext.getCmp('batch_id').enable();
									Ext.getCmp('lecid').enable();
									Ext.getCmp('subject_name').enable();
									//Ext.getCmp('lectype').enable();
									Ext.getCmp('workingday').enable();
									Ext.getCmp('day_date').enable();

									Ext.getCmp('day_comment').enable();
									Ext.getCmp('batch_id').enable();
									Ext.getCmp('batch_id').setValue('0');
									Ext.getCmp('lecid').setValue('1');
									//Ext.getCmp('branch_name').focus(true, 500);
								}
							}]
						}]
					}]

				}, {
					columnWidth: 1,
					layout: 'form',
					items: [{ height: 5 }, grid]
				}
				]
			});

			Ext.getCmp('workingday').setValue(1);

			function editstudent(btn) {
				if (btn == 'yes') {
					var day_id = Ext.getCmp('day_id').getValue();
					store.load({
						params: {
							day_id: day_id,
							'branch_id': Ext.getCmp('branch_name').getValue(),
							'semester_id': Ext.getCmp('semester_name').getValue(),
							'year_id': Ext.getCmp('year_name').getValue(),
							'branchyear_id': Ext.getCmp('branchyear_name').getValue(),
							'subject_id': Ext.getCmp('subject_name').getValue(),
							'batch_id': Ext.getCmp('batch_id').getValue(),
							'lec_id': Ext.getCmp('lecid').getValue()


						}
					});
					Ext.getCmp('branch_name').disable();
					Ext.getCmp('semester_name').disable();
					Ext.getCmp('year_name').disable();
					Ext.getCmp('branchyear_name').disable();
					Ext.getCmp('subject_name').disable();

					//Ext.getCmp('batch_id').disable();
					//Ext.getCmp('day_date').disable();	
					//Ext.getCmp('workingday').disable();	
					//Ext.getCmp('day_comment').disable();	

					//Ext.getCmp('lecid').disable();	
					//Ext.getCmp('lectype').disable();	
				} else {
					Ext.getCmp('branch_name').reset();
					Ext.getCmp('semester_name').reset();
					Ext.getCmp('subject_name').reset();
					Ext.getCmp('year_name').reset();
					Ext.getCmp('branchyear_name').reset();
					Ext.getCmp('batch_id').reset();
					Ext.getCmp('day_date').reset();
					Ext.getCmp('workingday').reset();
					Ext.getCmp('day_comment').reset();
					//Ext.getCmp('lec_id').reset();

					//Ext.getCmp('lectype').reset();
					store.removeAll();
				}
			}

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


			PresentForm.getForm().on({
				actioncomplete: function (form, action) {
					if (action.type == 'submit') {
						if (action.result.success == "true") {
							Ext.MessageBox.show({
								title: 'Message',
								msg: action.result.msg,
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.INFO
							});
							store.removeAll();
							PresentForm.getForm().reset();
							Ext.getCmp('lecid').setValue('1');
							Ext.getCmp('batch_id').setValue(0);
							Ext.getCmp('batch_id').setRawValue('All');
						//	Ext.getCmp('branch_name').focus(true, 1000);
						} 
					}else 
							Ext.MessageBox.show({
								title: 'Error',
								msg: action.result.msg,
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.ERROR
							});
							//store.removeAll();		 
							//PresentForm.getForm().reset();
							//Ext.getCmp('branch_name').focus(true,1000);		
						
				}
			});


			var PresentWindow = new Ext.Window({
				title: 'Daily Present Entry',
				width: 830,
				height: 570,
				modal: true,
				border: false,
				layout: 'fit',
				closeAction: 'close',
				collapsible: true,
				items: [PresentForm],
				buttonAlign: 'center',
				buttons: [{
					text: 'Save',
					tabIndex: 14,
					iconCls: 'icon-save',
					name: 'btnSave',
					id: 'btnSave',
					handler: function () {
						Ext.getCmp('btnSave').disable();
						var branch_name = Ext.getCmp('branch_name').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 subject_name = Ext.getCmp('subject_name').getValue();

						var batch_id = Ext.getCmp('batch_id').getValue();
						//var lectype = Ext.getCmp('lectype').getValue();

						if (branch_name != "" && subject_name != "") {
							var stcount = grid.store.getCount();
							if (stcount >= 1) {
								Ext.getCmp('branch_name').enable();
								Ext.getCmp('year_name').enable();
								Ext.getCmp('branchyear_name').enable();
								Ext.getCmp('semester_name').enable();
								Ext.getCmp('subject_name').enable();
								Ext.getCmp('day_date').enable();
								Ext.getCmp('workingday').enable();
								Ext.getCmp('day_comment').enable();


								Ext.getCmp('batch_id').enable();
								var absantStudentids = "";
								var presentStudentid = "";
								var j = 0;
								var k = 0;
								for (var i = 0, len = grid.store.getCount(); i < len; i++) {
									record = grid.store.getAt(i);
									if (record.data.day_present == false) {
										absantStudentids += record.data.student_id + ",";
									} else {
										presentStudentid += record.data.student_id + ",";
									}
								}

								if (Ext.getCmp('day_id').getValue() > 0) {
									PresentForm.getForm().submit({
										params: { absstudentids: absantStudentids, prestudentids: presentStudentid },
										waitMsg: 'Saving...',
										success: function () {

										},
										failure: function () {
											Ext.getCmp('btnSave').enable();
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill complete form',
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.ERROR
											});
										}
									});
								}
								else {
									PresentForm.getForm().submit({
										params: { absstudentids: absantStudentids, prestudentids: presentStudentid },
										waitMsg: 'Saving...',
										success: function () {
											store.removeAll();
											Ext.getCmp('btnSave').enable();
											PresentForm.getForm().reset();
											//Ext.getCmp('branch_name').focus(true, 1000);
										},
										failure: function () {
											Ext.getCmp('btnSave').enable();
											Ext.MessageBox.show({
												title: 'Error',
												msg: 'Please fill complete form',
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.ERROR
											});
										}
									});
								}
							}
							else {
								Ext.MessageBox.show({
									title: 'Error',
									msg: 'Please click on view button to see the students record.',
									buttons: Ext.MessageBox.OK,
									icon: Ext.MessageBox.ERROR
								});
							}
						} else {
							Ext.MessageBox.show({
								title: 'Error',
								msg: 'Please select all criteria and than view button.',
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.ERROR
							});
						}
						Ext.getCmp('btnSave').enable();
					}
				}, {
					text: 'Close',
					iconCls: 'icon-close',
					name: 'btncancle',
					tabIndex: 15,
					id: 'btncancle',
					handler: function () {
						PresentWindow.close();
					}
				}]
			});
			Ext.getCmp('lecid').on('expand', function () {
				Ext.getCmp('lecid').setValue('0');
			});
			var varWidth = (screen.width - PresentWindow.width) / 2;
			PresentWindow.setPosition(varWidth, ((screen.height / 4) - 170));
			PresentWindow.show();
			Ext.getCmp('branch_name').focus(true, 1000);
			Ext.getCmp('lecid').setValue('1');
			Ext.getCmp('batch_id').setValue(0);
			Ext.getCmp('batch_id').setRawValue('All');
			//Ext.getCmp('batch_id').getStore().getAt('2');
		});
	</script>
	<div align="center"></div>
</div>
<?php require "_footer.php"; ?>