<?php
require '../2_Projects/FileOperations.php';
$con = mysql_connect($website,$userid,$pw);
if (!$con) {
	die('Could not connect: ' . mysql_error());
}

$curDB = "../CurrentlyOpenedDBName.tmp";
if(file_exists ($curDB)){
	$f = fopen($curDB, "r");
	$dbase   = trim(fgets($f)); // linked database name
	fclose($f);
	mysql_select_db($dbase, $con);
}else{
	return;
}
mysql_query("SET foreign_key_checks = 0",$con);
$output_id = $_GET[output_id];
echo ("<head><link rel='stylesheet' type='text/css' href='../CSS/Font.css'></head>");
if($debug)echo ("<script>  document.write(document.URL); </script>");

if($_GET[act] == "yes"){
	if(isset($_POST[NotUpdateTable])){
	}elseif(isset($_POST[UpdateTable])){
		if($output_id == "add"){
			mysql_query("INSERT INTO Output(name) VALUES('{$_POST[nameField]}')",$con);
		}else{
			mysql_query("UPDATE Output SET name = '{$_POST[nameField]}' WHERE output_id = {$output_id}",$con);
		}
	}
	echo ("<script>	window.opener.document.location.href ='Output.php?output_id={$output_id}';</script>");
	echo("<script> window.close() </script>");
}

if($output_id != "add"){ // User selected to edit
	$res = mysql_query("SELECT name FROM Output WHERE output_id={$output_id}",$con);
	while($row = mysql_fetch_array($res))$name = $row[0];
} 

echo ("<form action='AddEditOutput.php?act=yes&output_id={$output_id}' method='post'<br/>");
echo ("<table><br/>");

// Name field
echo ("<tr>");
echo ("<td> Name </td>");
echo 	("<td><input 	type='text'  autocomplete='off'
						name='nameField' 
						value='{$name}' 
						maxlength = '{$smaStr}'
						size = '60' 
		</td>");
echo ("</tr>");

echo ("</table><br/>");
echo ("<button type='submit' name='UpdateTable' value='OK' >OK</button>&nbsp");
echo ("<button type='submit' name='NotUpdateTable' value='Cancel' >Cancel</button>");
echo ("<form><br/>");

?>














