<?php ?><?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "index.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?><?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$maxRows_InitialInfo = 1;
$pageNum_InitialInfo = 0;
if (isset($_GET['pageNum_InitialInfo'])) {
  $pageNum_InitialInfo = $_GET['pageNum_InitialInfo'];
}
$startRow_InitialInfo = $pageNum_InitialInfo * $maxRows_InitialInfo;

$colname_InitialInfo = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_InitialInfo = $_SESSION['MM_Username'];
}
mysql_select_db("TOM", mysql_pconnect("tom.theporch.com","root","dart9640t"));
$query_InitialInfo = sprintf("SELECT modulus, e FROM users WHERE username = %s", GetSQLValueString($colname_InitialInfo, "text"));
$query_limit_InitialInfo = sprintf("%s LIMIT %d, %d", $query_InitialInfo, $startRow_InitialInfo, $maxRows_InitialInfo);
$InitialInfo = mysql_query($query_limit_InitialInfo, mysql_pconnect("tom.theporch.com","root","dart9640t")) or die(mysql_error());
$row_InitialInfo = mysql_fetch_assoc($InitialInfo);

if (isset($_GET['totalRows_InitialInfo'])) {
  $totalRows_InitialInfo = $_GET['totalRows_InitialInfo'];
} else {
  $all_InitialInfo = mysql_query($query_InitialInfo);
  $totalRows_InitialInfo = mysql_num_rows($all_InitialInfo);
}
$totalPages_InitialInfo = ceil($totalRows_InitialInfo/$maxRows_InitialInfo)-1;

$colname_PrivateKey = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_PrivateKey = $_SESSION['MM_Username'];
}
mysql_select_db("TOM", mysql_pconnect("tom.theporch.com","root","dart9640t"));
$query_PrivateKey = sprintf("SELECT d FROM users WHERE username = %s", GetSQLValueString($colname_PrivateKey, "text"));
$PrivateKey = mysql_query($query_PrivateKey, mysql_pconnect("tom.theporch.com","root","dart9640t")) or die(mysql_error());
$row_PrivateKey = mysql_fetch_assoc($PrivateKey);
$totalRows_PrivateKey = mysql_num_rows($PrivateKey);

$maxRows_userinfo = 1;
$pageNum_userinfo = 0;
if (isset($_GET['pageNum_userinfo'])) {
  $pageNum_userinfo = $_GET['pageNum_userinfo'];
}
$startRow_userinfo = $pageNum_userinfo * $maxRows_userinfo;

$colname_userinfo = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_userinfo = $_SESSION['MM_Username'];
}
mysql_select_db("TOM", mysql_pconnect("tom.theporch.com","root","dart9640t"));
$query_userinfo = sprintf("SELECT modulus, e, d, solved FROM users WHERE username = %s", GetSQLValueString($colname_userinfo, "text"));
$query_limit_userinfo = sprintf("%s LIMIT %d, %d", $query_userinfo, $startRow_userinfo, $maxRows_userinfo);
$userinfo = mysql_query($query_limit_userinfo, mysql_pconnect("tom.theporch.com","root","dart9640t")) or die(mysql_error());
$row_userinfo = mysql_fetch_assoc($userinfo);
$Privatekey = $row_userinfo['d'];

if (isset($_GET['totalRows_userinfo'])) {
  $totalRows_userinfo = $_GET['totalRows_userinfo'];
} else {
  $all_userinfo = mysql_query($query_userinfo);
  $totalRows_userinfo = mysql_num_rows($all_userinfo);
}
$totalPages_userinfo = ceil($totalRows_userinfo/$maxRows_userinfo)-1;
?><!--MMDW 5 --><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html mmdw="0"  xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta mmdw="1"  http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The Problem</title>
<link mmdw="2"  href="admin.css" rel="stylesheet" type="text/css" />
</head>

<body>
<h1>Here is your starting information:</h1>
<h2>Modulus: <!--MMDW 6 --><?php echo $row_InitialInfo['modulus']; ?><!--MMDW 7 --></h2>
<h2>Public Key: <!--MMDW 8 --><?php echo $row_InitialInfo['e']; ?><!--MMDW 9 --> </h2>
<p>&nbsp;</p>
<h5>Please enter your calculated private key:</h5>
<form mmdw="3"  id="private" name="private" method="post" action="">
  <p>
    <label mmdw="4"  for="private">Calculated Private Key:</label>
    <br />
    <input mmdw="5"  type="text" name="private" id="private" />
  </p>
  <p>
    <input mmdw="6"  name="doKeycheck" type="submit" id="doKeycheck" value="Submit" />
  </p>
</form>	  
<!--MMDW 10 --><?php {
if $row_PrivateKey['d'] == $private {
	echo "<h1>Success!!!</h1>"; }
	else {
	echo "<h1>That is not correct.</h1>";
	}
?><!--MMDW 11 -->
<p>&nbsp; </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;<a mmdw="7"  href="<?php echo $logoutAction ?>">Log out</a></p>
<p>&nbsp; </p>
</body>
</html>
<!--MMDW 12 --><?php
mysql_free_result($InitialInfo);

mysql_free_result($PrivateKey);

mysql_free_result($userinfo);
?><!--MMDW 13 -->
<!-- MMDW:success -->