<?PHP
// Installation script
$phppunch_ROOTPWD = "";
$ppconf = array();

require_once "phppunch_version.inc.php";
require_once("ppio.inc.php");
require_once("ppmysql.inc.php");

header("Content-type: text/html; charset=utf-8");
function wizrcstr($rc) {
	return $rc?"<SPAN style=\"color:#008000;font-weight:bold;\">success.</SPAN>":"<SPAN style=\"color:red;font-weight:bold;\">failed.</SPAN>";
}
$act = "main";
echo "<HTML><HEAD><TITLE>ΠΑΡΟΥΣΙΟΛΟΓΙΟ installer</TITLE>";
echo "<LINK rel=\"stylesheet\" href=\"pmstyle.css\" type=\"text/css\" media=\"screen\" />\n";
echo "</HEAD>\n";
if (isset($_REQUEST["act"])) $act = $_REQUEST["act"];
echo "<BODY><H1>ΠΑΡΟΥΣΙΟΛΟΓΙΟ installer</H1>";
if ($act != "main") echo "<A href=\"install.php?act=main\">[Return to installation overview]</A>";
echo "<HR>\n";

if ($act == "main") {
	?>
	<P>This script will help you setting up ΠΑΡΟΥΣΙΟΛΟΓΙΟ on your server.<BR>
	<B>A new installation is done in 4 steps:</B>
	<UL>
	<LI><A href="install.php?act=edconfig">Setting up the configuration files</A>
	<LI><A href="install.php?act=installdb">Initializing the mysql database</A>
	<LI><A href="install.php?act=installtables">Setting up tables in the database</A>
	<LI><A href="install.php?act=maintplants">Creating a ΠΑΡΟΥΣΙΟΛΟΓΙΟ &quot;plant&quot; (=your organisation/company) in the database.</A>
	</UL>
	</P>
	<P>
	<B>Upgrading an existing installation requires 2 steps:</B>
	<UL>
	<LI><A href="install.php?act=upgrconfig">Upgrading the configuration files</A>
	<LI><A href="install.php?act=installtables">Upgrading the database</A>
	</UL>
	</P>
	<P>
	<B>Other tasks:</B>
	<UL><LI><A href="install.php?act=maintplants">Manage plants</A>
	<LI><A href="admin.php">open plant administration</A>
	</P>
	
	<?PHP 
} elseif ($act == "edconfig") {
	?>
	<H2>Setting up the configuration files</H2>
	<P>Two configuration files are used. The first one is <B>conf/configuration.inc.php</B> which is used
	for all kind of options and also declares the location of the second configuration file
	<B>dbc/phppunch_dbc.inc.php</B> which contains the server name, username and password for the
	mysql database connection. It also contains the phppunch_ROOTPWD password definition. this file should be moved to a save location (See the comments at the beginning of
	the file for more information).
	<?PHP 
} elseif ($act == "upgrconfig") {
	?>
	<H2>Upgrading the configuration files</H2>
	<P>Your config files will be overwritten when you update so you will have to edit them over and over again. Sorry
	for the inconvenience. Maybe we will fix that in a later release.</P>
	<?PHP 
} elseif ($act == "installdb") {
	?>
	<H2>Initializing the mysql database</H2>
	<P>You need the a mysql database to run ΠΑΡΟΥΣΙΟΛΟΓΙΟ. This database must contain a table
	&quot;phppunch_dbversion&quot; which holds a single row that stores the version of the database layout.
	You can either create this table manually or install.php can do it for you. if you want to create it
	manually (e.g. using phpmysqladmin) you have to execute the following sql-commands:</P>
	<PRE>
	CREATE TABLE phppunch_dbversion (
		DBVER_PK VARCHAR( 8 ) NOT NULL ,
		DBVER_Value VARCHAR( 255 ) NOT NULL ,
		PRIMARY KEY ( `DBVER_PK` )
	);
	
	INSERT INTO phppunch_dbversion (DBVER_PK, DBVER_Value) VALUES ('VER', '0');
	</PRE>
	<P>If you want me to do this initialization, you have to <A href="install.php?act=edconfig">edit the configuration file</A> so i know how to connect
	to the database and then click here:</P>
	<FORM method="post" action="install.php">
	<INPUT type="hidden" name="act" value="doinstalldb">
	phppunch_ROOTPWD: <INPUT type="password" name="p" value="">
	<INPUT type="submit" value="Set up the table phppunch_dbversion"><BR>
	<SMALL>(Hint: If a php error is displayed instead of the page, there is probably something wrong with
	conf/configuration.inc.php!)</SMALL>
	</FORM>
	<?PHP 
} elseif ($act == "maintplants") {
	?>
	<H2>Maintenance of punchmachine plants.</H2>
	&quot;plants&quot; are the root containers of any data in the
	ΠΑΡΟΥΣΙΟΛΟΓΙΟ database scheme. So you can handle multiple companies/organizations with a single
	installation. Enter the value of<B>phppunch_ROOTPWD</B> set in your phppunch_dbc.inc.php.<BR><BR>
	<FORM method="post" action="install.php">
	<?PHP echo ppformelemts(); ?>
	<INPUT type="hidden" name="act" value="showplants">
	phppunch_ROOTPWD: <INPUT type="password" name="p" value="">
	<INPUT type="submit" value="Submit"><BR>
	</FORM>
	<?PHP
}
if ($act == "doinstalldb" || $act == "installtables" || $act == "doinstalltables"
	|| $act == "showplants" || $act == "renameplant" || $act == "chpwplant" || $act == "deleteplant") {
	echo "Including conf/configuration.inc.php... ";
	include("conf/configuration.inc.php");
	echo wizrcstr(true)."<BR>\n";
	echo "Including dbc... ";
	include $ppconf["dbcscriptpath"];
	echo wizrcstr(true)."<BR>\n";
	echo "Connecting to the database server... ";
	$ppconf["mysqli_linkid"] = mysqli_connect($ppconf["mysqli_server"], $ppconf["mysqli_username"], $ppconf["mysqli_password"]);
	if (!$ppconf["mysqli_linkid"]) {
		echo wizrcstr(false)."<BR>\n";
		die ("<A href=\"install.php?act=edconfig\">Click here to see how to set up the database connection.</A></BODY></HTML>");
	} else {
		echo wizrcstr(true)."<BR>\n";
	}
	echo "Selecting the database... ";
	if (!@mysqli_select_db($ppconf["mysqli_linkid"], $ppconf["mysqli_dbname"])) {
		echo wizrcstr(false)."<BR>\n";
		die ("<A href=\"install.php?act=edconfig\">Click here to see how to set up the database connection.</A></BODY></HTML>");
	} else {
		echo wizrcstr(true)."<BR>\n";
	}
	$dbname = $ppconf["mysqli_dbname"];
}
if ($act == "doinstalldb" || $act == "doinstalltables"
	|| $act == "showplants" || $act == "renameplant" || $act == "chpwplant" || $act == "deleteplant") {
	if (strlen($phppunch_ROOTPWD) == 0) {
		echo "<P style=\"color:red;\">You did not set a phppunch_ROOTPWD in the phppunch_dbc.inc.php yet! Please set a password and retry.</P>";
		die ("</BODY></HTML>");
	}
	if (("AA".$phppunch_ROOTPWD) != ("AA".pp_postfield("p"))) {
		echo "<P style=\"color:red;\">Wrong phppunch_ROOTPWD password!</P>";
		die ("</BODY></HTML>");
	}
}

if ($act == "doinstalldb") {
	$crtcmd = array();
	$crtcmd[0] = "CREATE TABLE phppunch_dbversion (DBVER_PK VARCHAR( 8 ) NOT NULL , DBVER_Value VARCHAR( 255 ) NOT NULL , PRIMARY KEY ( `DBVER_PK` ))";
	$crtcmd[1] = "INSERT INTO phppunch_dbversion (DBVER_PK, DBVER_Value) VALUES ('VER', '0')";
	for ($i=0; $i<2; $i+=1) {
		echo "executing sql: <I>".htmlspecialchars($crtcmd[$i]).";</I><BR>";
		mysqli_query($ppconf["mysqli_linkid"], $crtcmd[$i]);
		$errno = mysqli_errno($ppconf["mysqli_linkid"]); $error = mysqli_error($ppconf["mysqli_linkid"]);
		if ($errno != 0) {
			echo wizrcstr(false)."<BR>";
			echo "mysql error code: ".htmlspecialchars($errno).", error description: ".htmlspecialchars($error);
		} else {
			echo wizrcstr(true);
		}
		echo "<BR><BR>\n";
	}
}
if ($act == "doinstalldb" || $act == "installtables" || $act == "doinstalltables"
	|| $act == "showplants"  || $act == "renameplant" || $act == "chpwplant" || $act == "deleteplant") {
	$sqlcmd = "SELECT DBVER_Value FROM phppunch_dbversion WHERE DBVER_PK='VER' LIMIT 1";
	echo "Gathering current database layout version <SMALL>(".htmlspecialchars($sqlcmd).")</SMALL>...";
	$result = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
	$errno = mysqli_errno($ppconf["mysqli_linkid"]); $error = mysqli_error($ppconf["mysqli_linkid"]);
	if ($errno != 0) {
		echo wizrcstr(false)."<BR>";
		echo "mysql error code: ".htmlspecialchars($errno).", error description: ".htmlspecialchars($error);
		die ("</BODY></HTML>");
	} else {
		if ($row = mysqli_fetch_assoc($result)) {
			echo wizrcstr(true)."<BR>";
			$phppunch_PHYSDBVER = (int)$row["DBVER_Value"];
			echo "The installed database layout version is: ".htmlspecialchars($phppunch_PHYSDBVER).".<BR>\n";
		} else {
			echo wizrcstr(false)."<BR>";
			echo "<I>".htmlspecialchars($sqlcmd)."</I> did not return any rows :-(";
			die ("</BODY></HTML>");
		}
	}
}
if ($act == "installtables" || $act == "doinstalltables"
	|| $act == "showplants" || $act == "renameplant" || $act == "chpwplant" || $act == "deleteplant") {
	echo "The database layout version required for ΠΑΡΟΥΣΙΟΛΟΓΙΟ v".htmlspecialchars($phppunch_VER)." is: ".htmlspecialchars($phppunch_DBVER).".<BR>\n";
}
if ($act == "installtables" || ($act == "doinstalltables" && $phppunch_DBVER <= $phppunch_PHYSDBVER)) {
	if ($phppunch_DBVER > $phppunch_PHYSDBVER) {
		echo "<BR><BR><B>Your database needs an upgrade to version ".htmlspecialchars($phppunch_DBVER)."</B><BR>\n";
		echo "<FORM method=\"post\" action=\"install.php\">\n";
		echo "<INPUT type=\"hidden\" name=\"act\" value=\"doinstalltables\">\n";
		echo "phppunch_ROOTPWD: <INPUT type=\"password\" name=\"p\" value=\"\">";
		echo "<INPUT type=\"submit\" value=\"Click here to upgrade the database layout.\"><BR>\n";
	} elseif ($phppunch_DBVER < $phppunch_PHYSDBVER) {
		echo "<BR><BR><B>The installed database layout is newer then the one required by the installed program version.</B><BR>\n";
		echo "Update the program if possible!";
	} else {
		echo "<BR><BR><B>The installed database layout is right for this  version of ΠΑΡΟΥΣΙΟΛΟΓΙΟ (".htmlspecialchars($phppunch_VER).").</B><BR>\n";
	}	
} elseif ($act == "doinstalltables") {
	echo "<H2>Upgrading your database! Please do not interrupt!</H2><HR>\n";
	@set_time_limit(5*60);
	echo "Opening file <I>makedb.dat</I>...";
	$fh = fopen("makedb.dat","rb");
	if ($fh) {
		echo wizrcstr(true)."<BR>Reading file contents...";
		$size = filesize("makedb.dat");
		$cmddata = fread($fh, $size);
		if ($size > 0 && strlen($cmddata) > 0) {
			echo wizrcstr(true)."<BR>\n";	
		} else {
			echo wizrcstr(false)."<BR>\n";
			fclose($fh);
			die("</BODY></HTML>");
		}
		fclose ($fh);
	} else {
		echo wizrcstr(false)."<BR>";
		die("</BODY></HTML>");
	}
	$phppunch_PHYSDBVER  = (int)$phppunch_PHYSDBVER;
	$cmdarr = explode("\n",$cmddata);
	for ($i = 0;isset($cmdarr[$i]);$i+=1) {
		$line = trim($cmdarr[$i]);
		if (substr($line,0,1) == ";" || substr($line,0,1) == "#" || strlen($line) == 0) {
			// comment or empty line
			continue;
		}
		$pos = strpos($line,":");
		if ($pos > 0) {
			$ver = (int)trim(substr($line,0,$pos));
			$cmd = trim(substr($line,$pos + 1));
			if ($ver == $phppunch_PHYSDBVER + 1) {
				echo "<B>Upgrading from version ".$phppunch_PHYSDBVER." to version ".$ver.":</B><BR>\n";
				echo "<SMALL>".htmlspecialchars($cmd)."</SMALL><BR>";
				
				// here cmd can be catched for special operations instead of mysqli_query
				
				if (true) {
					mysqli_query($ppconf["mysqli_linkid"], $cmd);
					$errno = mysqli_errno($ppconf["mysqli_linkid"]); $error = mysqli_error($ppconf["mysqli_linkid"]);
				}

				if ($errno != 0) {
					echo wizrcstr(false)."<BR>";
					echo "mysql error code: ".htmlspecialchars($errno).", error description: ".htmlspecialchars($error);
					echo "<BR><BR>Check the layout by hand and then increment the version (the row in the table phppunch_dbversion) to ".$ver." manually.<BR>";
					die ("</BODY></HTML>");
				} else {
					echo wizrcstr(true).", updating version info...";
					$sqlcmd = "UPDATE phppunch_dbversion SET DBVER_Value='".($phppunch_PHYSDBVER + 1)."' WHERE DBVER_Value='".($phppunch_PHYSDBVER + 0)."' AND DBVER_PK='VER' LIMIT 1";
					mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
					$errno = mysqli_errno($ppconf["mysqli_linkid"]); 
					$error = mysqli_error($ppconf["mysqli_linkid"]); 
					$affrows = mysqli_affected_rows($ppconf["mysqli_linkid"]);
					if ($errno == 0) {
						if ($affrows >= 1) {
							echo wizrcstr(true)."<BR><BR>\n";
							$phppunch_PHYSDBVER += 1;
						} else {
							echo wizrcstr(false)."<BR>";
							echo "Version info update failed (mysqli_affected_rows = $affrows).";
							echo "<BR><BR>Check the layout by hand and then increment the version (the row in the table phppunch_dbversion) to ".$ver." manually.<BR>";
							die ("</BODY></HTML>");
						}
					} else {
						echo wizrcstr(false)."<BR>";
						echo "Version info update failed, mysql error code: ".htmlspecialchars($errno).", error description: ".htmlspecialchars($error);
						echo "<BR><BR>Check the layout by hand and then increment the version (the row in the table phppunch_dbversion) to ".$ver." manually.<BR>";
						die ("</BODY></HTML>");						
					}
				}
			} else {
				echo "<SMALL><I>Skipping line ".($i + 1)." (ver $ver)</I></SMALL><BR>\n";
			}
		} else {
			echo "<I>Warning! Could not parse line ".($i + 1)." in makedb.dat.</I><BR>\n";
		}	
	}
}
if ($act == "showplants" || $act == "renameplant" || $act == "chpwplant" || $act == "deleteplant") {
	if ($phppunch_DBVER > $phppunch_PHYSDBVER) {
		echo "You need to <A href=\"install.php?act=installtables\">Upgrade the database layout first!";
		die ("</BODY></HTML>");
	}
}
if ($act == "showplants") {
	echo "<HR>\n";
	if (isset($_REQUEST["act2"]) && $_REQUEST["act2"] == "createplant") {
		$PPLANT_Caption = trim(pp_postfield("PPLANT_Caption"));
		$PPLANT_PWD = trim(pp_postfield("PPLANT_PWD"));
		if (strlen($PPLANT_Caption) < 1 || strlen($PPLANT_PWD) < 1) {
			echo "<P style=\"color:red;\">Please provide both name and admin pwd!</P>\n";
		} else {
			$sqlcmd = "SELECT PPLANT_ID FROM $dbname.pplant WHERE PPLANT_Caption='".ppaddslashes($PPLANT_Caption)."' LIMIT 1";
			$tres = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
			if (mysqli_num_rows($tres) > 0) {
				echo "<P style=\"color:red;\">Please provide a unique name!</P>\n";
			} else {
				$pw2 = md5($ppconf["plantpwd_bloat"].$PPLANT_PWD.$ppconf["plantpwd_bloat"]);
				$sqlcmd = "INSERT INTO $dbname.pplant(PPLANT_Caption, PPLANT_PWD)"
				." VALUES "
				."('".ppaddslashes($PPLANT_Caption)."', '".ppaddslashes($pw2)."')";
				mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
				echo htmlspecialchars(mysqli_error($ppconf["mysqli_linkid"]));
				$greenrow = mysqli_insert_id($ppconf["mysqli_linkid"]);
			}
		}
	} elseif (isset($_REQUEST["act2"]) && $_REQUEST["act2"] == "renameplant") {
		$plid = (int)pp_postfield("plid");
		$PPLANT_Caption = trim(pp_postfield("PPLANT_Caption"));
		if (strlen($PPLANT_Caption) > 0) {
			$sqlcmd = "SELECT PPLANT_ID FROM $dbname.pplant WHERE PPLANT_Caption='".ppaddslashes($PPLANT_Caption)."' AND PPLANT_ID <> '".ppaddslashes($plid)."' LIMIT 1";
			$tres = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
			if (mysqli_num_rows($tres) > 0) {
				echo "<P style=\"color:red;\">Please provide a unique name!</P>\n";
			} else {
				$sqlcmd = "UPDATE $dbname.pplant SET PPLANT_Caption='".ppaddslashes($PPLANT_Caption)."'"
				." WHERE PPLANT_ID='".ppaddslashes($plid)."' LIMIT 1";
				mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
				echo htmlspecialchars(mysqli_error($ppconf["mysqli_linkid"]));
				$greenrow = $plid;
			}
		} else {
			echo "<P style=\"color:red;\">Please provide a name!</P>\n";
		}
	} elseif (isset($_REQUEST["act2"]) && $_REQUEST["act2"] == "chpwplant") {
		$plid = (int)pp_postfield("plid");
		$PPLANT_PWD = trim(pp_postfield("PPLANT_PWD"));
		if (strlen($PPLANT_PWD) > 0) {
			$pw2 = md5($ppconf["plantpwd_bloat"].$PPLANT_PWD.$ppconf["plantpwd_bloat"]);
			$sqlcmd = "UPDATE $dbname.pplant SET PPLANT_PWD='".ppaddslashes($pw2)."' WHERE PPLANT_ID='".ppaddslashes($plid)."' LIMIT 1";
			mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
			echo htmlspecialchars(mysqli_error($ppconf["mysqli_linkid"]));
			$greenrow = $plid;
		} else {
			echo "<P style=\"color:red;\">Please provide a password!</P>\n";
		}
	}
	$sqlcmd = "SELECT * FROM $dbname.pplant ORDER BY PPLANT_ID ASC";
	$pres = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
	echo htmlspecialchars(mysqli_error($ppconf["mysqli_linkid"]));
	echo "<H2>Plants in the database:</H2>\n";
	echo "<TABLE border=\"0\" cellpadding=\"1\" cellspacing=\"1\">";
	echo "<TR><TH>ID</TH><TH>Caption</TH><TH>Current Host</TH><TH>Rename</TH><TH>Change admin password</TH><TH>Delete</TH></TR>\n";
	$rowcolor = 0;
	while ($prow = mysqli_fetch_assoc($pres)) {
		$rowc = $ppconf["html_rowc".$rowcolor]; $rowcolor = 1 - $rowcolor;
		if (isset($greenrow) && $greenrow == $prow["PPLANT_ID"]) $rowc = $ppconf["html_green"];
		echo "<TR>";
		echo "<TD bgcolor=$rowc>".htmlspecialchars($prow["PPLANT_ID"])."</TD>";
		echo "<TD bgcolor=$rowc>".htmlspecialchars($prow["PPLANT_Caption"])."</TD>";
		echo "<TD bgcolor=$rowc>".htmlspecialchars($prow["PPLANT_CurrentHost"])."</TD>";
		echo "<TD bgcolor=$rowc><A href=\"#\" onclick=\"document.getElementById('rename_plid').value=".((int)$prow["PPLANT_ID"])."; document.getElementById('renfrm').submit();\" oncontextmenu=\"return false;\">[Rename]</A></TD>";
		echo "<TD bgcolor=$rowc><A href=\"#\" onclick=\"document.getElementById('chp_plid').value=".((int)$prow["PPLANT_ID"])."; document.getElementById('chpfrm').submit();\" oncontextmenu=\"return false;\">[Change Admin Password]</A></TD>";
		echo "<TD bgcolor=$rowc><A href=\"install.php?act=deleteplant&plid=".rawurlencode($prow["PPLANT_ID"])."\" onclick=\"alert('sorry not implemented!'); return false;\">[Delete]</A></TD>";
		echo "</TR>\n";
	}
	echo "</TABLE>\n";
	echo "<HR>";
	echo "<FORM method=\"post\" action=\"install.php\">";
	echo ppformelemts();
	echo "<H2>Add a new plant to the database:</H2>";
	echo "<TABLE border=\"0\" cellpadding=\"1\" cellspacing=\"1\">\n";
	echo "<TR><TD>Caption:</TD><TD><INPUT type=\"text\" name=\"PPLANT_Caption\" value=\"\"></TD></TR>\n";
	echo "<TR><TD>New Plant Admin Password:</TD><TD><INPUT type=\"password\" name=\"PPLANT_PWD\" value=\"\"></TD></TR>\n";
	echo "<TR><TD></TD><TD>";
	echo "<INPUT type=\"hidden\" name=\"p\" value=\"".htmlspecialchars(pp_postfield("p"))."\">";
	echo "<INPUT type=\"hidden\" name=\"act\" value=\"showplants\">";
	echo "<INPUT type=\"hidden\" name=\"act2\" value=\"createplant\">";
	echo "<INPUT type=\"submit\" value=\"Create plant\">";
	echo "</TD></TR></TABLE>";
	echo "</FORM>";
	echo "<FORM method=\"post\" id=\"renfrm\" action=\"install.php?act=renameplant\">";
	echo "<INPUT type=\"hidden\" name=\"plid\" id=\"rename_plid\" value=\"\">";
	echo "<INPUT type=\"hidden\" name=\"p\" value=\"".htmlspecialchars(pp_postfield("p"))."\">";
	echo "</FORM>";
	echo "<FORM method=\"post\" id=\"chpfrm\" action=\"install.php?act=chpwplant\">";
	echo "<INPUT type=\"hidden\" name=\"plid\" id=\"chp_plid\" value=\"\">";
	echo "<INPUT type=\"hidden\" name=\"p\" value=\"".htmlspecialchars(pp_postfield("p"))."\">";
	echo "</FORM>";
}
if ($act == "renameplant" || $act == "chpwplant") {
	$sqlcmd = "SELECT * FROM $dbname.pplant WHERE PPLANT_ID='".ppaddslashes((int)pp_postfield("plid"))."' LIMIT 1";
	$result = mysqli_query($ppconf["mysqli_linkid"], $sqlcmd);
	if ($prow = mysqli_fetch_assoc($result)) {
	echo "<FORM method=\"post\" action=\"install.php\">";
	echo ppformelemts();
	echo "<INPUT type=\"hidden\" name=\"plid\" value=\"".htmlspecialchars($prow["PPLANT_ID"])."\">";
	echo "<H2>Rename plant:</H2>";
	echo "<TABLE border=\"0\" cellpadding=\"1\" cellspacing=\"1\">\n";
	if ($act == "renameplant") {
		echo "<TR><TD>Caption:</TD><TD>";
		echo "<INPUT type=\"text\" name=\"PPLANT_Caption\" value=\"".htmlspecialchars($prow["PPLANT_Caption"])."\">";
		echo "<INPUT type=\"hidden\" name=\"act2\" value=\"renameplant\">";
		echo "</TD></TR>\n";
	}
	if ($act == "chpwplant") {
		echo "<TR><TD>Caption:</TD><TD>".htmlspecialchars($prow["PPLANT_Caption"])."</TD></TR>\n";
		echo "<TR><TD>New Plant Admin Password:</TD>";
		echo "<TD><INPUT type=\"password\" name=\"PPLANT_PWD\" value=\"\">";
		echo "<INPUT type=\"hidden\" name=\"act2\" value=\"chpwplant\">";
		echo "</TD></TR>\n";
	}
	echo "<TR><TD></TD><TD>";
	echo "<INPUT type=\"hidden\" name=\"p\" value=\"".htmlspecialchars(pp_postfield("p"))."\">";
	echo "<INPUT type=\"hidden\" name=\"act\" value=\"showplants\">";
	echo "";
	echo "<INPUT type=\"submit\" value=\"";
	if ($act == "renameplant") echo "Rename";
	if ($act == "chpwplant") echo "Set Admin Password";
	echo "\">";
	echo "</TD></TR></TABLE>";
	echo "</FORM>";	
		
	}
}
echo "</BODY></HTML>";
?>
