<?php
require "_header.php";
// require "data/combo_timetable.php";

$school_id = Escape($_SESSION['VedantnrCollegeId']);
if ($school_id != "" && isset($school_id)) {
	$mode = "edit";

	$limit = 1;
	$start = 0;
	//	$condition=" and school_id = '$school_id' ";
	$order_field = "";
	$order_type = "";

	$objStandardMgmt = new TTStandardMgmt();

	$out = $objStandardMgmt->getAllRecords($limit, $start, $condition, $order_field, $order_type);
	if (dbRows($out)) {
		$row = dbArray($out);
		extract($row);
		//echo "<pre>";print_r($row);		
	}
} else {
	$school_id = 0;
	$mode = "add";
}
?>
<script type="text/javascript">
	formMode = "<?php echo $mode ?>";
	var tt_working_days = new Ext.form.NumberField({
		id: 'tt_working_days',
		fieldLabel: 'Working Days Per Week',
		name: 'tt_working_days',
		emptyText: '',
		maxValue: 7,
		allowBlank: false,
		allowNegative: false,
		allowDecimals: false,
		width: 25
	});

	var tt_periods_per_day = new Ext.form.NumberField({
		id: 'tt_periods_per_day',
		fieldLabel: 'Periods Per Day',
		name: 'tt_periods_per_day',
		emptyText: '',
		maxValue: 15,
		allowBlank: false,
		allowNegative: false,
		allowDecimals: false,
		width: 25
	});

	var tt_periods_lastday = new Ext.form.NumberField({
		id: 'tt_periods_lastday',
		fieldLabel: 'Periods Last Day Per Week',
		name: 'tt_periods_lastday',
		emptyText: '',
		maxValue: 15,
		allowBlank: false,
		allowNegative: false,
		allowDecimals: false,
		width: 25
	});


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


		var tt_school = new Ext.FormPanel({
			labelWidth: 120, // label settings here cascade unless overridden
			url: 'save-tt-standard.php',
			method: 'post',
			frame: true,
			title: '',
			bodyStyle: 'padding:6px 6px 0',
			// width: 450,
			defaultType: 'textfield',
			items: [
				//tt_working_days,

				{
					xtype: 'container',
					autoEl: {},
					border: false,
					layout: 'column',
					anchor: '100%',
					defaultType: 'field',
					items: [
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: 1,
							labelWidth: 170,
							items: [tt_working_days]
						}]
				},
				{
					xtype: 'container',
					autoEl: {},
					border: false,
					layout: 'column',
					anchor: '100%',
					defaultType: 'field',
					items: [
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: 1,
							labelWidth: 170,
							items: [tt_periods_per_day]
						},
						{
							xtype: 'container',
							autoEl: {},
							layout: 'form',
							columnWidth: 1,
							labelWidth: 170,
							items: [tt_periods_lastday]
						}]
				}
			],
			buttonAlign: 'center',
			buttons: [{
				text: 'Save',
				iconCls: 'icon-save',
				handler: function () {
					tt_school.getForm().findField('tt_working_days').enable();
					tt_school.getForm().findField('tt_periods_per_day').enable();
					tt_school.getForm().findField('tt_periods_lastday').enable();
					tt_school.getForm().submit({
						waitMsg: 'Saving...',
						success: function () {

							Ext.MessageBox.show({
								title: 'Message',
								msg: 'Data has been saved',
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.INFO
							});


							//alert("Data has been saved.");
							//tt_school.getForm().reset();
						},
						failure: function () {

							Ext.MessageBox.show({
								title: 'Error',
								msg: 'Please fill complete form.',
								buttons: Ext.MessageBox.OK,
								icon: Ext.MessageBox.ERROR
							});
							//alert("Please Fill up Complete Form.");
						}
					});
				}
			},
			/*{
				  text: 'Reset',
				  handler: function()
				  {
					  tt_school.getForm().findField('tt_working_days').enable();		
					  tt_school.getForm().findField('tt_periods_per_day').enable();		
				tt_school.getForm().findField('tt_periods_lastday').enable();
			tt_school.getForm().reset();
					Ext.getCmp('tt_working_days').focus(true,500);
		  }
			  }*/
			{
				text: 'Close',
				iconCls: 'icon-close',
				handler: function () {
					window.location = 'loginhome.php';
				}
			}]
		});

		var tt_school_win = new Ext.Window({
			title: 'Time Table : Format Set up',
			height: 160,
			width: 250,
			border: false,
			modal: true,
			layout: 'fit',
			closeAction: 'close',
			collapsible: 'true',
			items: tt_school
		});

		tt_school_win.hide();

		function tt_school_form_show() {
			tt_school_win.show();
			Ext.getCmp('tt_working_days').focus(true, 500);
		}
		var varWidth = (screen.width - tt_school_win.width) / 2;
		tt_school_win.setPosition(varWidth, ((screen.height / 4) - 110));
		tt_school_win.show();
		Ext.getCmp('tt_working_days').focus(true, 500);

		function editstudent(btn) {
			if (btn == 'yes') {
				tt_school.getForm().findField('tt_working_days').setValue(working_days);
				tt_school.getForm().findField('tt_periods_per_day').setValue(periods_per_day);
				tt_school.getForm().findField('tt_periods_lastday').setValue(periods_lastday);
			}
			else {
				tt_school.getForm().findField('tt_working_days').setValue(working_days);
				tt_school.getForm().findField('tt_periods_per_day').setValue(periods_per_day);
				tt_school.getForm().findField('tt_periods_lastday').setValue(periods_lastday);
				tt_school.getForm().findField('tt_working_days').disable();
				tt_school.getForm().findField('tt_periods_per_day').disable();
				tt_school.getForm().findField('tt_periods_lastday').disable();
			}
		}

		if (formMode == 'edit') {
			Ext.getCmp('tt_working_days').setValue("<?php echo $working_days; ?>");
			Ext.getCmp('tt_periods_per_day').setValue("<?php echo $periods_per_day; ?>");
			Ext.getCmp('tt_periods_lastday').setValue("<?php echo $periods_lastday; ?>");
		}
	});
</script>
<?php require "_footer.php"; ?>