<?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);
	//echo "Connected to " . $dbase . "<br/>";
}else{
	//No database currently open
	return;
}
mysql_query("SET foreign_key_checks = 0",$con);

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"){
	echo ("<a id='#Return' href='../Common/BlankPage.html' target='WorkingFrame'></a> "); 
	echo ("<a id='#Reload1' href='Static.php?source_id={$_GET[FK]}&static_id={$_GET[PK]}' target='StaticFrame'></a> "); 
	echo ("<a id='#Reload2' href='Source.php?source_id={$_GET[FK]}&loadothers=no' target='SourceFrame'></a> "); 
	if(isset($_POST[NotUpdateTable])){
		echo("<script>document.getElementById('#Return').click();</script>");
	}
	if(isset($_POST[UpdateTable])){
		if($_GET[PK] == "add"){
			mysql_query("INSERT INTO Static(source_id,attribute,value) 
						VALUES({$_GET[FK]},'{$_POST[attributeField]}','{$_POST[valueField]}')",$con);
		}else{
			mysql_query("UPDATE Static SET attribute='{$_POST[attributeField]}',value='{$_POST[valueField]}' 
						WHERE static_id={$_GET[PK]}",$con);
		}
		echo("<script>document.getElementById('#Reload2').click();</script>");
		echo("<script>document.getElementById('#Reload1').click();</script>");
		echo("<script>document.getElementById('#Return').click();</script>");
	}
}

$PK = $_GET[PK];
$FK = $_GET[FK];
if($PK == "add"){
	$add = true;
	$edit = false;
}else{
	$add = false;
	$edit = true;
}
if($edit){
	$res = mysql_query("SELECT count(attribute) FROM Static WHERE static_id={$PK}",$con);
	$res = mysql_query("SELECT attribute,value FROM Static WHERE static_id={$PK}",$con);
	while($row = mysql_fetch_array($res)){
		$attribute = $row[0];
		$value = $row[1];
	}
}

echo ("<form action='AddEditStatic.php?act=yes&PK={$PK}&FK={$FK}' method='post'<br/>");
echo ("<table><br/>");
echo ("<tr>");
echo ("<td> Tag </td>");
echo 	("<td><input 	type='text' autocomplete='off'
						name='attributeField' 
						value='{$attribute}' 
						maxlength = '{$smaStr}'
						size = '60' 
						placeholder='Enter attribute name here'>
		</td>");
echo ("</tr>");
echo ("<tr>");
echo ("<td> Value </td>");
echo 	("<td><input 	type='text'  autocomplete='off'
						name='valueField' 
						value='{$value}' 
						maxlength = '{$smaStr}'
						size = '60' 
						placeholder='Enter value here'>
		</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/>");

?>














