<?php
// member.php
// RJM Programming
// May, 2015
// Thanks to PHP and MySql Web Development by Luke Welling, Laura Thomson
// Thanks to Professional PHP Programming by Jesus Castagnetto, Haeish Rawat, Sascha Schumann, Chris Scollo, Deepak Veliath ... chapter 20

for ($j=0; $j<200; $j++) {
  if (isset($_POST['b' . $j])) {
    $fx=urlencode(str_replace("Agree to Moderation of ","",urldecode($_POST['b' . $j]))) . ".aml";
    if (file_exists($fx)) {
      unlink($fx);
      $qw=@file_get_contents("what_we_have_in_common.html");
      file_put_contents("what_we_have_in_common.html", str_replace("Agree to Moderation of ","",urldecode($_POST['b' . $j])) . "\n" . $qw);
    } else if (str_replace(".aml", "", $fx) != "") {
      $qw=@file_get_contents("what_we_have_in_common.html");
      file_put_contents("what_we_have_in_common.html", urldecode($_POST['b' . $j]) . "\n" . $qw);
    }
  }
}

$nextpage="next.php";
$nextval="Next Page";

$logpage="login.php";
if (!file_exists("loginpage.name")) {
   $loginpage=@file_get_contents("loginpage.name");
   if (strpos($loginpage, ".php") !== false) $logpage=$loginpage;
}
if (!isset($_SESSION['login']) && !isset($_POST['login'])) {
   header("Location: " . $logpage . str_replace("?&", "?", ("?" . str_replace("backto=", "lastone=", $_SERVER['QUERY_STRING']) . "&backto=" . $_SERVER['PHP_SELF'])));
   exit;
}
$_SESSION['login']=true;
$backbuttonhtml="";
$i=0;
foreach (glob("*.aml") as $filename) {
     if (substr($filename, 1, 1) == ":") { // Windows
      $parts=explode("\\", $filename);
     } else {
      $parts=explode("/", $filename);
     }
     $thisfile=urldecode(str_replace(".aml", "", $parts[-1 + sizeof($parts)]));
     if ($backbuttonhtml == "") {
      $backbuttonhtml='<form id="f' . $i . '" action="./member.php" method="POST"><input type="submit" name="b' . $i . '" id="b' . $i . '" value="Agree to Moderation of ' . $thisfile . '"></input></form>'; 
     } else {
      $backbuttonhtml.='</td></tr><tr><td><form id="f' . $i . '" action="./member.php" method="POST"><input type="submit" name="b' . $i . '" id="b' . $i . '" value="Agree to Moderation of ' . $thisfile . '"></input></form>'; 
     }
     $i++;
}
if ($backbuttonhtml == "") {
      $backbuttonhtml='<form id="f' . $i . '" action="./member.php" method="POST"><input type="text" name="b' . $i . '" id="b' . $i . '" value=""></input><input type="submit" value="Okay This Email Suggestion"></input></form>'; 
} else {
      $backbuttonhtml.='</td></tr><tr><td><form id="f' . $i . '" action="./member.php" method="POST"><input type="text" name="b' . $i . '" id="b' . $i . '" value=""></input><input type="submit" value="Okay This Email Suggestion"></input></form>'; 
}
if (strpos($_SERVER['HTTP_REFERER'], $logpage) === false && strpos($_SERVER['HTTP_REFERER'], $nextpage) === false && strlen($_SERVER['HTTP_REFERER']) > 0) {
   $backpage=$_SERVER['HTTP_REFERER'];
   $backvals=explode("/", $backpage);
   $backval= strtoupper(substr($backvals[sizeof($backvals) - 1],0,1)) . str_replace(".php", " Page", substr($backvals[sizeof($backvals) - 1],1));
}
?>
<!doctype html>
<html>
<body>
<div align="center">
<table align="center"><tr><td><?php echo $backbuttonhtml; ?><form style='display:none;' action='<?php echo $nextpage; ?>' method='post'><input type='hidden' name='login' value='true'></input><input type='submit' id='subm' name='subm' value='<?php echo $nextval; ?>'></input></form></td></tr></table>
<br>
<br>
<a href="<?php echo $logpage; ?>?logout=<?php echo urlencode(str_replace('=form','=y', $_SERVER['QUERY_STRING'])); ?>" title="Logout">Logout</a>
</div>
</body>
</html>
