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

?>
<div id="main-content">
	<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>

	<style type="text/css">
		label.myBold {
			font-weight: bold;
			color: #15428B;
			font-size: 11px;
			padding-left: 10px;
		}
	</style>
	<script type="text/javascript">
		function handlekeypress() {
			var msgtext = Ext.getCmp('msgtext').getValue();
			var msgprefix = Ext.getCmp('msgprefix').getValue();
			var msgsuffix = Ext.getCmp('msgsuffix').getValue();
			var total = msgtext.length + msgprefix.length + msgsuffix.length;
			var divid = total / 160;
			var modu = Math.round(divid);
			if (divid > modu) {
				modu = modu + 1;
				Ext.getCmp('charcount').setText(total + ' Char');
				Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
			} else {
				Ext.getCmp('charcount').setText(total + ' Char');
				Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
			}
		}
		function getbalance() {

			return <?php // echo getBalance($SmsUserName,$SmsPassword,$SMSGetbalance); ?>
		}
	</script>

	<script type="text/javascript">


		Ext.override(Ext.ux.form.LovCombo, {
			beforeBlur: Ext.emptyFn
		});

		var student_all = new Ext.form.Radio({
			hideLabel: true,
			name: 'student_selection',
			inputValue: 'all',
			boxLabel: 'All Student',
			handler: function () {
				if (this.checked) {
					Ext.getCmp('branch_name').setValue('');
					Ext.getCmp('year_name').setValue('');
					Ext.getCmp('branchyear_name').setValue('');
					Ext.getCmp('semester_name').setValue('');
					Ext.getCmp('student_gturegno').setValue('');

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

					Ext.getCmp('chkBranch').setValue(0);
					Ext.getCmp('chkYear').setValue(0);
					Ext.getCmp('chkBranchyear').setValue(0);
					Ext.getCmp('chkSemester').setValue(0);
					Ext.getCmp('chkGturegno').setValue(0);

					Ext.getCmp('chkBranch').disable();
					Ext.getCmp('chkYear').disable();
					Ext.getCmp('chkBranchyear').disable();
					Ext.getCmp('chkSemester').disable();
					Ext.getCmp('chkGturegno').disable();
				}
			}
		});

		var student_selected = new Ext.form.Radio({
			hideLabel: true,
			name: 'student_selection',
			inputValue: 'other',
			boxLabel: 'Selected Student',
			handler: function () {
				if (this.checked) {
					Ext.getCmp('chkBranch').enable();
					Ext.getCmp('chkYear').enable();
					Ext.getCmp('chkBranchyear').enable();
					Ext.getCmp('chkSemester').enable();
					Ext.getCmp('chkGturegno').enable();
				}
			}
		});

		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 headstore = new Ext.data.ArrayStore({
			fields: ['head_id', 'head_name'],
			data: Ext.semester.headall
		});

		var head = new Ext.ux.form.LovCombo({
			allowBlank: true,
			msgTarget: 'title',
			id: 'head_id',
			name: 'head_id',
			labelSeparator: '',
			width: 100,
			resizable: false,
			autoScroll: false,
			store: headstore,
			mode: 'local',
			editable: false,
			disabled: true,
			displayField: 'head_name',
			displayFieldTpl: '{head_name}',
			valueField: 'head_id',
			forceSelection: true,
			navigateItemsWithTab: false
		});*/

		var checkbox_branch = new Ext.form.Checkbox({
			hideLabel: true,
			name: 'chkBranch',
			id: 'chkBranch',
			inputValue: 'branch',
			disabled: true,
			handler: function () {
				if (this.checked) {
					Ext.getCmp('branch_name').setValue('');
					Ext.getCmp('branch_name').enable();
				}
				else {
					Ext.getCmp('branch_name').setValue('');
					Ext.getCmp('branch_name').disable();
				}
			}
		});



		var checkbox_year = new Ext.form.Checkbox({
			hideLabel: true,
			name: 'chkYear',
			id: 'chkYear',
			inputValue: 'year',
			disabled: true,
			handler: function () {
				if (this.checked) {
					Ext.getCmp('year_name').setValue('');
					Ext.getCmp('year_name').enable();
				}
				else {
					Ext.getCmp('year_name').setValue('');
					Ext.getCmp('year_name').disable();
				}
			}
		});


		var checkbox_branchyear = new Ext.form.Checkbox({
			hideLabel: true,
			name: 'chkBranchyear',
			id: 'chkBranchyear',
			inputValue: 'branchyear',
			disabled: true,
			handler: function () {
				if (this.checked) {
					Ext.getCmp('branchyear_name').setValue('');
					Ext.getCmp('branchyear_name').enable();
				}
				else {
					Ext.getCmp('branchyear_name').setValue('');
					Ext.getCmp('branchyear_name').disable();
				}
			}
		});

		var checkbox_semester = new Ext.form.Checkbox({
			hideLabel: true,
			name: 'chkSemester',
			id: 'chkSemester',
			inputValue: 'semester',
			disabled: true,
			handler: function () {
				if (this.checked) {
					Ext.getCmp('semester_name').setValue('');
					Ext.getCmp('semester_name').enable();
				}
				else {
					Ext.getCmp('semester_name').setValue('');
					Ext.getCmp('semester_name').disable();
				}
			}
		});


		var checkbox_gturegno = new Ext.form.Checkbox({
			hideLabel: true,
			name: 'chkGturegno',
			id: 'chkGturegno',
			inputValue: 'gturegno',
			disabled: true,
			handler: function () {
				if (this.checked) {
					Ext.getCmp('student_gturegno').setValue('');
					Ext.getCmp('student_gturegno').enable();
				}
				else {
					Ext.getCmp('student_gturegno').setValue('');
					Ext.getCmp('student_gturegno').disable();
				}
			}
		});

		var branch = new Ext.form.ComboBox({
			name: 'branch_name',
			id: 'branch_name',
			hiddenName: 'branch_hidden',
			labelSeparator: '',
			fieldLabel: 'Branch:',
			displayField: 'branch_name',
			valueField: 'branch_id',
			editable: true,
			emptyText: 'Select Branch',
			triggerAction: 'all',
			mode: 'local',
			disabled: true,
			allowBlank: false,
			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();
					}
				}
			}
		});



		var year = new Ext.form.ComboBox({
			name: 'year_name',
			id: 'year_name',
			hiddenName: 'year_hidden',
			labelSeparator: '',
			fieldLabel: 'Batch Year:',
			displayField: 'year_name',
			valueField: 'year_id',
			editable: true,
			triggerAction: 'all',
			mode: 'local',
			disabled: true,
			emptyText: 'Select year',
			allowBlank: false,
			store: batchyearstore,
			listeners: {
				'select': function (cmb, rec, idx) {

					var branch = Ext.getCmp('branch_name').getValue();

				}
			}
		});

		var branchyear = new Ext.form.ComboBox({
			name: 'branchyear_name',
			id: 'branchyear_name',
			hiddenName: 'branchyear_hidden',
			labelSeparator: '',
			fieldLabel: 'Course Year:',
			displayField: 'branchyear_name',
			valueField: 'branchyear_id',
			editable: true,
			triggerAction: 'all',
			mode: 'local',
			disabled: true,
			emptyText: 'Select Course year',
			allowBlank: false,
			store: yearstore,
			listeners: {
				'select': function (cmb, rec, idx) {

					var branch = Ext.getCmp('branch_name').getValue();

				}
			}
		});


		var semester = new Ext.form.ComboBox({
			name: 'semester_name',
			id: 'semester_name',
			hiddenName: 'semester_hidden',
			labelSeparator: '',
			fieldLabel: 'Semester:',
			displayField: 'semester_name',
			valueField: 'semester_id',
			editable: true,
			triggerAction: 'all',
			mode: 'local',
			disabled: true,
			emptyText: 'Select Semester',
			allowBlank: false,
			store: semesterstore,
			listeners: {
				'select': function (cmb, rec, idx) {

					var branch = Ext.getCmp('branch_name').getValue();

				}
			}
		});

		var gturegno = new Ext.form.TextField({
			name: 'student_gturegno',
			id: 'student_gturegno',
			labelSeparator: '',
			fieldLabel: 'GTU No:',
			width: 164,
			emptyText: 'Select GTU No',
			allowBlank: false,
			disabled: true
		});

		var daymonthstore = new Ext.data.ArrayStore({
			fields: ['valueday', 'displayday'],
			data: [['day', 'Current Day'], ['month', 'Select Month']]
		});

		var monthstore = new Ext.data.ArrayStore({
			fields: ['valuemonth', 'displaymonth'],
			data: [['1', 'January'], ['2', 'February'], ['3', 'March'], ['4', 'April'], ['5', 'May'], ['6', 'June'],
			['7', 'July'], ['8', 'August'], ['9', 'September'], ['10', 'October'], ['11', 'November'], ['12', 'December']]
		});

		var month = new Ext.form.ComboBox({
			name: 'month',
			id: 'month',
			labelSeparator: '',
			displayField: 'displaymonth',
			valueField: 'valuemonth',
			editable: true,
			emptyText: 'Select Month',
			triggerAction: 'all',
			mode: 'local',
			width: 100,
			disabled: true,
			allowBlank: false,
			store: monthstore
		});

		var daymonth = new Ext.form.ComboBox({
			name: 'daymonth',
			id: 'daymonth',
			labelSeparator: '',
			displayField: 'displayday',
			valueField: 'valueday',
			editable: true,
			emptyText: 'Day or Month',
			triggerAction: 'all',
			mode: 'local',
			width: 100,
			disabled: true,
			allowBlank: false,
			store: daymonthstore,
			listeners: {
				select: {
					fn: function (combo, value) {
						if (this.getValue() == "month") {
							Ext.getCmp('month').enable();
							Ext.getCmp('month').reset();
						} else {
							Ext.getCmp('month').disable();
							Ext.getCmp('month').reset();
						}
					}
				}
			}
		});

		var charcount = new Ext.form.Label({
			name: 'charcount',
			id: 'charcount',
			cls: 'x-form-item myBold',
			text: "0 Char"
		});

		var smscount = new Ext.form.Label({
			name: 'smscount',
			id: 'smscount',
			cls: 'x-form-item myBold',
			text: "(0 SMS)"
		});

		var balance = new Ext.form.Label({
			name: 'balance',
			id: 'balance',
			cls: 'x-form-item myBold',
			text: "Avilabel  ",
		});

		var msgprefix = new Ext.form.TextField({
			name: 'msgprefix',
			id: 'msgprefix',
			emptyText: 'Message Prefix',
			width: 200,
			value: 'Dear,',
			readOnly: true,
			allowBlank: true,
			enableKeyEvents: true,
			listeners: {
				keyup: handlekeypress
			}
		});

		var msgsuffix = new Ext.form.TextField({
			name: 'msgsuffix',
			id: 'msgsuffix',
			emptyText: 'Message Suffix',
			width: 200,
			readOnly: true,
			allowBlank: true,
			value: ' From Shital Nursing.',
			enableKeyEvents: true,
			listeners: {
				keyup: handlekeypress
			}
		});

		var msgtext = new Ext.form.TextArea({
			name: 'msgtext',
			id: 'msgtext',
			width: 200,
			height: 105,
			labelSeparator: '',
			allowBlank: true,
			emptyText: 'Message Text',
			enableKeyEvents: true,
			listeners: {
				keyup: handlekeypress
			}
		});

		var radPresent = new Ext.form.Radio({
			hideLabel: true,
			name: 'present_fees',
			id: 'present_radio',
			inputValue: 'present',
			boxLabel: 'Present',
			handler: function () {
				if (this.checked) {
					Ext.getCmp('daymonth').enable();
					//Ext.getCmp('greaterfees').disable();
				//	Ext.getCmp('head_id').disable();
					Ext.getCmp('birth_date').disable();
					//Ext.getCmp('exam_name').disable();
					//Ext.getCmp('checkbox_allsub').disable();
					Ext.getCmp('daymonth').reset();
					//Ext.getCmp('greaterfees').reset();
				//	Ext.getCmp('head_id').reset();
					Ext.getCmp('birth_date').reset();
					//Ext.getCmp('exam_name').reset();
				}
			}
		});

		/*var radFees = new Ext.form.Radio({
			hideLabel: true,
			name: 'present_fees',
			id: 'fees_radio',
			inputValue: 'fees',
			boxLabel: 'Fees',
			handler: function () {
				if (this.checked) {
					Ext.getCmp('greaterfees').enable();
					Ext.getCmp('head_id').enable();
					Ext.getCmp('month').disable();
					Ext.getCmp('daymonth').disable();
					Ext.getCmp('exam_name').disable();
					Ext.getCmp('checkbox_allsub').disable();
					Ext.getCmp('month').reset();
					Ext.getCmp('daymonth').reset();
					Ext.getCmp('greaterfees').reset();
					Ext.getCmp('head_id').reset();
					Ext.getCmp('birth_date').disable();
					Ext.getCmp('birth_date').reset();
					Ext.getCmp('exam_name').reset();
				}
			}
		});

		var radExam = new Ext.form.Radio({
			hideLabel: true,
			name: 'present_fees',
			id: 'exam_radio',
			inputValue: 'exam',
			boxLabel: 'Exam',
			handler: function () {
				if (this.checked) {
					Ext.getCmp('greaterfees').disable();
					Ext.getCmp('head_id').disable();
					Ext.getCmp('month').disable();
					Ext.getCmp('daymonth').disable();
					Ext.getCmp('exam_name').enable();
					Ext.getCmp('checkbox_allsub').enable();
					Ext.getCmp('month').reset();
					Ext.getCmp('daymonth').reset();
					Ext.getCmp('greaterfees').reset();
					Ext.getCmp('head_id').reset();
					Ext.getCmp('exam_name').reset();
					Ext.getCmp('birth_date').disable();
					Ext.getCmp('birth_date').reset();
				}
			}
		}); */

		var radAtkt = new Ext.form.Radio({
			hideLabel: true,
			name: 'present_fees',
			id: 'atkt_radio',
			inputValue: 'atkt',
			boxLabel: 'ATKT',
			handler: function () {
				if (this.checked) {
				//	Ext.getCmp('greaterfees').disable();
				//	Ext.getCmp('head_id').disable();
					Ext.getCmp('month').disable();
					Ext.getCmp('daymonth').disable();
				//	Ext.getCmp('exam_name').disable();
				//	Ext.getCmp('checkbox_allsub').disable();
					Ext.getCmp('month').reset();
					Ext.getCmp('daymonth').reset();
					//Ext.getCmp('greaterfees').reset();
					//Ext.getCmp('head_id').reset();
					//Ext.getCmp('exam_name').reset();
					//Ext.getCmp('checkbox_allsub').reset();
					Ext.getCmp('birth_date').disable();
					Ext.getCmp('birth_date').reset();
				}
			}
		});

		var radBday = new Ext.form.Radio({
			hideLabel: true,
			name: 'present_fees',
			id: 'bday_radio',
			inputValue: 'bday',
			boxLabel: 'Birthday',
			handler: function () {
				if (this.checked) {
					//Ext.getCmp('greaterfees').disable();
				//	Ext.getCmp('head_id').disable();
					Ext.getCmp('month').disable();
					Ext.getCmp('daymonth').disable();
				//	Ext.getCmp('exam_name').disable();
					//Ext.getCmp('checkbox_allsub').disable();
					Ext.getCmp('month').reset();
					Ext.getCmp('daymonth').reset();
				//	Ext.getCmp('greaterfees').reset();
				//	Ext.getCmp('head_id').reset();
				//	Ext.getCmp('exam_name').reset();
					//Ext.getCmp('checkbox_allsub').reset();
					Ext.getCmp('birth_date').enable();
					Ext.getCmp('birth_date').reset();
				}
			}
		});

		var birth_date = new Ext.form.DateField({
			id: 'birth_date',
			name: 'birth_date',
			disabled: true,
			vtype: 'daterange',
			allowBlank: false,
			value: new Date()
		});

	/*	var examstore = new Ext.data.ArrayStore({
			fields: ['exam_id', 'exam_name'],
			data: Ext.semester.exam
		});

		var exam = new Ext.form.ComboBox({
			name: 'exam_name',
			id: 'exam_name',
			hiddenName: 'exam_hidden',
			labelSeparator: '',
			displayField: 'exam_name',
			valueField: 'exam_id',
			editable: true,
			width: 100,
			disabled: true,
			allowBlank: false,
			emptyText: 'Select Exam',
			triggerAction: 'all',
			forceSelection: true,
			mode: 'local',
			store: examstore
		});

		var checkbox_allsub = new Ext.form.Checkbox({
			fieldLabel: 'Subwise Marks',
			name: 'checkbox_allsub',
			id: 'checkbox_allsub',
			disabled: true,
			inputValue: 'allsub'
		});

		var greaterfees = new Ext.form.NumberField({
			name: 'greaterfees',
			id: 'greaterfees',
			emptyText: 'greater Amt',
			width: 100,
			disabled: true
		});*/

		var studentstore = new Ext.data.JsonStore({
			url: 'data/getstudent-message.php',
			root: 'data',
			storeId: 'student_id',
			totalProperty: 'count',
			fields: [{
				name: 'student_id',
				type: 'int'
			}, {
				name: 'branch_name',
				type: 'string'
			}, {
				name: 'year_name',
				type: 'string'
			},
			{
				name: 'branchyear_name',
				type: 'string'
			}, {
				name: 'semester_name',
				type: 'string'
			}, {
				name: 'message',
				type: 'string'
			}, {
				name: 'student_name',
				type: 'string'
			}, {
				name: 'student_gturegno',
				type: 'int'
			}, {
				name: 'student_mobilestudents'
			}, {
				name: 'student_mobileparents'
			}]
		});

		studentstore.on({
			'load': {
				fn: function () {
					if (studentstore.getCount() <= 0) {
						Ext.MessageBox.show({
							title: 'Error',
							msg: 'There is no Data found for this Selection.',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.ERROR
						});
					} else {
						record = grid.store.getAt(0).data.message;
						Ext.getCmp('msgtext').setValue(record);
						handlekeypress();
						sm2.selectAll();
					}
				}
			}
		});

		var sm2 = new Ext.grid.CheckboxSelectionModel();

		var colModel = new Ext.grid.ColumnModel([
			new Ext.grid.RowNumberer(),
			{
				dataIndex: 'student_id',
				header: 'Student ID',
				id: 'student_id',
				hidden: true
			}, {
				dataIndex: 'branch_name',
				header: 'Branch',
				sortable: true,
				width: 65
			}, {
				dataIndex: 'student_gturegno',
				header: 'GTU',
				sortable: true,
				width: 50
			}, {
				dataIndex: 'student_name',
				header: 'Student Name',
				sortable: true,
				width: 123,
				id: 'SurName'
			}, {
				dataIndex: 'message',
				header: 'Message',
				sortable: true,
				width: 225,
				id: 'message'
			}, {
				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'
			}, sm2
		]);

		var grid = new Ext.grid.GridPanel({
			store: studentstore,
			cm: colModel,
			loadMask: true,
			enableColLock: false,
			height: 575,
			width: 540,
			sm: sm2,
			clicksToEdit: 1,
			columnLines: true
		});

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

		var sendto = new Ext.form.Label({
			name: 'sendto',
			id: 'sendto',
			text: "Send To:"
		});

		var checkbox_parents = new Ext.form.Checkbox({
			fieldLabel: ' Parent',
			name: 'checkbox_parents',
			id: 'checkbox_parents',
			inputValue: 'parents'
		});

		var checkbox_students = new Ext.form.Checkbox({
			fieldLabel: 'Student',
			name: 'checkbox_students',
			id: 'checkbox_students',
			inputValue: 'students'
		});

		Ext.onReady(function () {
			Ext.QuickTips.init();

			var SMSForm = new Ext.FormPanel({
				labelWidth: 80,
				id: 'SMSForm',
				url: 'sending-message.php',
				frame: true,
				autoHeight: true,
				standardSubmit: false,
				title: '',
				bodyStyle: 'padding:5px',
				layout: 'column',
				items: [{
					columnWidth: 0.37,
					layout: 'form',
					items: [{
						xtype: 'fieldset',
						title: 'Student Information',
						collapsible: false,
						collapsed: false,
						forceLayout: true,
						autoHeight: true,
						labelWidth: 60,
						width: 310,
						layout: 'column',
						items: [{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .45,
							items: [student_all]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .55,
							items: [student_selected]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .1,
							items: [checkbox_branch]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .9,
							items: [branch]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .1,
							items: [checkbox_year]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .9,
							items: [year]
						},
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .1,
							items: [checkbox_branchyear]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .9,
							items: [branchyear]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .1,
							items: [checkbox_semester]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .9,
							items: [semester]
						},
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .1,
							items: [checkbox_gturegno]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .9,
							items: [gturegno]
						}]
					}, {
						xtype: 'fieldset',
						title: 'Message Information',
						collapsible: false,
						collapsed: false,
						forceLayout: true,
						autoHeight: true,
						labelWidth: 1,
						width: 310,
						layout: 'column',
						items: [{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .23,
							items: [radPresent]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .37,
							items: [daymonth]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .40,
							items: [month]
						}, 
						/*{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .23,
							items: [radFees]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .37,
							items: [greaterfees]
						},
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .4,
							items: [head]
						}, 
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .23,
							items: [radExam]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .4,
							items: [exam]
						}, 
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .37,
							labelWidth: 83,
							items: [checkbox_allsub]
						}, */
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .23,
							labelWidth: 83,
							items: [radBday]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .77,
							items: [birth_date]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: 1,
							labelWidth: 83,
							items: [radAtkt]
						}]
					}, {
						xtype: 'fieldset',
						title: 'Message Content',
						collapsible: false,
						collapsed: false,
						forceLayout: true,
						autoHeight: true,
						labelWidth: 1,
						width: 310,
						layout: 'column',
						items: [{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .72,
							items: [msgprefix]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .28,
							items: [charcount]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .72,
							items: [msgsuffix]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .28,
							items: [smscount]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .72,
							items: [msgtext]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .28,
							height: 115,
							items: [balance]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .16,
							labelWidth: 45,
							style: {
								padding: '3px 0px 0px 0px'
							},
							items: [sendto]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .20,
							labelWidth: 35,
							items: [checkbox_parents]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .28,
							labelWidth: 45,
							items: [checkbox_students]
						}, {
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: .36,
							items: [{
								xtype: 'button',
								name: 'search_grno',
								id: 'search_grno',
								text: 'Generate Msg',
								iconCls: 'icon-search',
								tooltip: 'Generate Student List',
								fieldLabel: '',
								disabled: false,
								handler: function () {
									var message_to = "";
									var flag = 1;

									if (Ext.getCmp('present_radio').getValue() == true) {
										message_to = "present_day";
										if (Ext.getCmp('daymonth').getValue() == "month") {
											if (Ext.getCmp('month').getValue() == "") {
												flag = 0;
												Ext.MessageBox.show({
													title: 'Message',
													msg: "select month name.",
													buttons: Ext.MessageBox.OK,
													icon: Ext.MessageBox.INFO
												});
											} else {
												message_to = "present_month";
											}
										} else if (Ext.getCmp('daymonth').getValue() == "") {
											flag = 0;
											Ext.MessageBox.show({
												title: 'Message',
												msg: "select day or month option.",
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.INFO
											});
										}

									} 
									/*else if (Ext.getCmp('fees_radio').getValue() == true) {
										message_to = "fees";

										if (Ext.getCmp('head_id').getValue() == "") {
											flag = 0;
											Ext.MessageBox.show({
												title: 'Message',
												msg: "select fees.",
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.INFO
											});
										}

									} */
								else if (Ext.getCmp('atkt_radio').getValue() == true) {
										message_to = "atkt";
									} else if (Ext.getCmp('bday_radio').getValue() == true) {
										message_to = "BirthDay";
										if (Ext.getCmp('birth_date').getValue() == "") {
											flag = 0;
											Ext.MessageBox.show({
												title: 'Message',
												msg: "select date.",
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.INFO
											});
										}

									} 
									/*else if (Ext.getCmp('exam_radio').getValue() == true) {
										message_to = "exam";
										if (Ext.getCmp('exam_name').getValue() == "") {
											flag = 0;
											Ext.MessageBox.show({
												title: 'Message',
												msg: "select exam.",
												buttons: Ext.MessageBox.OK,
												icon: Ext.MessageBox.INFO
											});
										}
									} */else {
										flag = 0;
										Ext.MessageBox.show({
											title: 'Message',
											msg: "select message information.",
											buttons: Ext.MessageBox.OK,
											icon: Ext.MessageBox.INFO
										});
									}

									if (flag == 1) {

										var branch = Ext.getCmp('branch_name').getValue();
										var year = Ext.getCmp('year_name').getValue();
										var branchyear = Ext.getCmp('branchyear_name').getValue();
										var semester = Ext.getCmp('semester_name').getValue();
										var gtuno = Ext.getCmp('student_gturegno').getValue();
									//	var morefees = Ext.getCmp('greaterfees').getValue();
										//var head_id = Ext.getCmp('head_id').getValue();
										//var exam = Ext.getCmp('exam_name').getValue();
										var bday = Ext.getCmp('birth_date').getValue();
										var msgprefix = Ext.getCmp('msgprefix').getValue();
										var msgsuffix = Ext.getCmp('msgsuffix').getValue();
										//var allsub = Ext.getCmp('checkbox_allsub').getValue();
										//var msgtext=Ext.getCmp('msgtext').getValue();
										var msgtext = '';
										var date = new Date();
										var d = date.getDate();
										var m = date.getMonth() + 1;
										var y = date.getFullYear();
										var present_day = "";
										var present_month = Ext.getCmp('month').getValue();

										if (present_month == "") {
											present_day = y + "-" + m + "-" + d;
										}
										studentstore.removeAll();
										studentstore.load({
											params: {
												'branch_id': branch,
												'year_id': year,
												'branchyear_id': branchyear,
												'semester_id': semester,
												'student_gturegno': gtuno,
												'message_to': message_to,
												//'greaterfees': morefees,
												//'head_id': head_id,
												'present_day': present_day,
												'present_month': present_month,
												'msgprefix': msgprefix,
												'msgsuffix': msgsuffix,
												//'exam': exam,
												'bday': bday,
												//'allsub': allsub,
												'msgtext': msgtext
											}
										});
									} else {
										studentstore.removeAll();
									}
								}
							}]
						}]
					}]
				}, {
					columnWidth: 0.63,
					layout: 'form',
					items: [grid]
				}]
			});

			var SMSWindow = new Ext.Window({
				title: 'Autogenerated Message',
				height: 630,
				width: 900,
				modal: true,
				autoHeight: true,
				layout: 'fit',
				border: false,
				closeAction: 'close',
				collapsible: 'true',
				items: SMSForm,
				buttonAlign: 'center',
				buttons: [{
					text: 'Send SMS',
					handler: function (b, e) {
						if (grid.store.getCount() > 0) {
							var selections = grid.selModel.getSelections();
							var message = [];
							var mobilestudents = [];
							var mobileparents = [];

							for (i = 0; i < grid.selModel.getCount(); i++) {
								if (Ext.getCmp('checkbox_students').checked == true) {
									mobilestudents.push(selections[i].json.student_mobilestudents);
									//message.push(selections[i].json.student_mobilestudents);
								}
								if (Ext.getCmp('checkbox_parents').checked == true) {
									mobileparents.push(selections[i].json.student_mobileparents);
									//message.push(selections[i].json.student_mobileparents);
								}
								message.push(selections[i].json.message);
							}

							var encoded_message = Ext.encode(message);
							var encoded_mobilestudents = Ext.encode(mobilestudents);
							var encoded_mobileparents = Ext.encode(mobileparents);
							SMSForm.getForm().submit({
								params: {
									message: encoded_message,
									mobilestudents: encoded_mobilestudents,
									mobileparents: encoded_mobileparents
								},
								timeout: 3000,
								waitMsg: 'Saving...',
								success: function () {
									studentstore.removeAll();
									SMSForm.getForm().reset();
									var gtotal = Ext.getCmp('msgprefix').getValue().length + Ext.getCmp('msgsuffix').getValue().length;
									var divid = gtotal / 160;
									var modu = Math.round(divid);
									if (divid > modu) {
										modu = modu + 1;
										Ext.getCmp('charcount').setText(gtotal + ' Char');
										Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
									} else {
										Ext.getCmp('charcount').setText(gtotal + ' Char');
										Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
									}
									Ext.MessageBox.show({
										title: 'Message',
										msg: 'Message Send to selected student.',
										buttons: Ext.MessageBox.OK,
										icon: Ext.MessageBox.INFO
									});
								},
								failure: function () {
									Ext.MessageBox.show({
										title: 'Error',
										msg: 'Please fill complete form',
										buttons: Ext.MessageBox.OK,
										icon: Ext.MessageBox.ERROR
									});
								}
							});
						} else {
							Ext.MessageBox.show({
								title: 'Message',
								msg: "Generate student list and select data for Send Message.",
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.INFO
							});
						}
					}
				}, {
					text: 'Reset',
					handler: function () {
						SMSForm.getForm().reset();
						var gtotal = Ext.getCmp('msgprefix').getValue().length + Ext.getCmp('msgsuffix').getValue().length;
						var divid = gtotal / 160;
						var modu = Math.round(divid);
						if (divid > modu) {
							modu = modu + 1;
							Ext.getCmp('charcount').setText(gtotal + ' Char');
							Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
						} else {
							Ext.getCmp('charcount').setText(gtotal + ' Char');
							Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
						}
					}
				}, {
					text: 'Close',
					handler: function () {
						SMSWindow.close();
					}
				}]
			});
			var gtotal = Ext.getCmp('msgprefix').getValue().length + Ext.getCmp('msgsuffix').getValue().length;
			var divid = gtotal / 160;
			var modu = Math.round(divid);
			if (divid > modu) {
				modu = modu + 1;
				Ext.getCmp('charcount').setText(gtotal + ' Char');
				Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
			} else {
				Ext.getCmp('charcount').setText(gtotal + ' Char');
				Ext.getCmp('smscount').setText('(' + modu + ' SMS)');
			}
			var varWidth = (screen.width - SMSWindow.width) / 2;
			SMSWindow.setPosition(varWidth, ((screen.height / 4) - 190));
			SMSWindow.show();
		});
	</script>
	<div id="abcd" align="center"></div>
</div>
<?php require "_footer.php"; ?>