<?php

$thetopic = "";
$bodyi = "";

function via($infind) {
  global $thetopic;
  $huh = file_get_contents("http://www.rjmprogramming.com.au");
  $sels = explode("<select ", $huh);
  if (sizeof($sels) >= 3) {
    if ($infind == "") {
      $selin = explode("</select>", $sels[2]);
      $xsel = explode(">", $selin[0]);
      $ih = str_replace(($xsel[0] . ">"), "", $selin[0]);
      return "<select " . $xsel[0] . ">" . str_replace("show blog, toggle sort order", "will use as basis for your Course Name", $ih) . "</select>";
    } else {
      $selin = explode("</select>", $sels[2]);
      $xsel = explode(">", $selin[0]);
      $ih = str_replace(($xsel[0] . ">"), "", $selin[0]);
      $newih = "<option value=''>Please select tutorials, in order, that belong to your " . $thetopic . " Course Design ...</OPTION>";
      $lotsnewih = explode("</option>", $ih);
      for ($i=0; $i<sizeof($lotsnewih); $i++) {
        if (strpos($lotsnewih[$i], ">" . $infind . " ") !== false) $newih = str_replace("</OPTION>", "</OPTION>" . str_replace("MyNew-", $infind . "MyNew-", $lotsnewih[$i]) . "</option>", $newih);
      }
      return "<select " . str_replace("tuts'", $infind . "tuts'", $xsel[0]) . ">" . str_replace("</OPTION>", "</option>", $newih) . "</select>";
    }
  }
  return "";
}

if (isset($_GET['show'])) {
   if (file_exists("../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html")) {
     $bodyi = "<iframe id='bodyi' src='../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html' width='100%' height='200'></iframe>";
   } 
}


if (isset($_POST['coursename'])) {
  $tuts = explode(",", $_POST['coursesq']);
  $ltuts = explode(",", $_POST['courselsq']);
  $prev = "";
  $next = "";
  $first = "http://www.rjmprogramming.com.au/wordpress/?p=" . $tuts[0];
  for ($i=0; $i<sizeof($tuts); $i++) {
     if (($i + 1) < sizeof($tuts)) $next = $tuts[$i + 1];
     if ($prev == "" && $next == "") {
       file_put_contents("../PHP/" . $tuts[$i] . "_" . $_SERVER['REMOTE_ADDR'] . ".npg", "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i]);
       $first .= "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i];
     } else if ($prev == "") {
       file_put_contents("../PHP/" . $tuts[$i] . "_" . $_SERVER['REMOTE_ADDR'] . ".npg", "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i]);
       $first .= "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i];
     } else if ($next == "") {
       file_put_contents("../PHP/" . $tuts[$i] . "_" . $_SERVER['REMOTE_ADDR'] . ".npg", "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i]);
     } else {
       file_put_contents("../PHP/" . $tuts[$i] . "_" . $_SERVER['REMOTE_ADDR'] . ".npg", "&pp=" . $prev . "&pn=" . $next . "&title=" . str_replace(" ", "~", $_POST['coursename']) . " " . $ltuts[$i]);
     }
     $prev = $tuts[$i];
     $next = "";
  }
  if (file_exists("../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html")) {
    file_put_contents("../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html", str_replace("</tbody>", "<tr><td><a target=_blank title='" . $_POST['coursename'] .  "' href='" . $first . "'>" . $_POST['coursename'] . "</a></td></tr></tbody>", file_get_contents("../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html")));
  } else {
    file_put_contents("../PHP/" . $_SERVER['REMOTE_ADDR'] . "_courses.html", "<html><head><script type='text/javascript'> var comma=''; </script><title>Ask About Course</title></head><body><table><tbody><tr><td><a target=_blank title='" . $_POST['coursename'] .  "' href='" . $first . "'>" . $_POST['coursename'] . "</a></td></tr></tbody></table></body></html>");
  }
  echo "<html><head><script type='text/javascript'> var comma=''; </script><title>Ask About Course</title></head><body style='background-color:yellow;'>" . $bodyi . "<h1 align='center'>Course Designer</h1><h2>Thanks for your <a target=_blank title='" . $_POST['coursename'] .  "' href='" . $first . "'>" . $_POST['coursename'] . "</a> Course Design</h2><form align='center' action='./design_a_course.php' method='POST'><input type='hidden' name='coursesq' id='coursesq' value=''></input><input type='text' style='display:none;' name='coursename' id='coursename' value=''></input><div id='list' style='display:block;'>" . str_replace("ChangeTutNow(this);", " var ahuh=this.value.split(\"=\"); location.href = \"./design_a_course.php?topic=\" + ahuh[ahuh.length - 1]; ", via("")) . "</div><div id='topic' style='display:none;'>" . via("C++") . "</div><br><br><input style='display:none;' align='center' type='submit' name='submit' id='submit' value='Submit'></input></form>" . "</body></html>";
} else if (isset($_GET['topic'])) {
  $pretopics = explode("title=", $_GET['topic']);
  $topics = explode(" ", str_replace("_", " ", $pretopics[sizeof($pretopics) - 1]));
  $thetopic = $topics[0];
  echo "<html><head><script type='text/javascript'> var comma=''; </script><title>Ask About Course</title></head><body style='background-color:lightgray;'>" . $bodyi . "<h1 align='center'>" . $thetopic . " Course Designer</h1><h3 id='sofar'></h3><br><form align='center' action='./design_a_course.php' method='POST'><input type='hidden' name='courselsq' id='courselsq' value=''></input><input type='hidden' name='coursesq' id='coursesq' value=''></input>Course Name: <input type='text' style='display:block;' name='coursename' id='coursename' value='" . $topics[0] . "'></input><br><div id='list' style='display:none;'>" . via("") . "</div><div id='topic' style='display:block;'>" . str_replace("ChangeTutNow(this);", " var ahuh=this.value.split(\"=\"); if (ahuh[ahuh.length - 1] != \"\") {  var bhuh=ahuh[1].split(\"&\");  document.getElementById(\"coursesq\").value = document.getElementById(\"coursesq\").value + comma + bhuh[0];   document.getElementById(\"courselsq\").value = document.getElementById(\"courselsq\").value + comma + ahuh[ahuh.length - 1].replace(/_/g, \" \");  document.getElementById(\"sofar\").innerHTML = document.getElementById(\"sofar\").innerHTML + \"<\" + \"br\" + \">\" + ahuh[ahuh.length - 1].replace(/_/g, \" \");    document.getElementById(\"topic\").innerHTML = document.getElementById(\"topic\").innerHTML.replace(ahuh[ahuh.length - 1],\"\").replace(ahuh[ahuh.length - 1],\"\"); comma=\",\"; } ", via($topics[0])) . "</div><br><br><input align='center' type='submit' name='submit' id='submit' value='Create Your " . $thetopic . " Course Design'></input></form>" . "</body></html>";
} else {
  echo "<html><head><script type='text/javascript'> var comma=''; </script><title>Ask About Course</title></head><body style='background-color:yellow;'>" . $bodyi . "<h1 align='center'>Course Designer</h1><form align='center' action='./design_a_course.php' method='POST'><input type='hidden' name='coursesq' id='coursesq' value=''></input><input type='text' style='display:none;' name='coursename' id='coursename' value=''></input><div id='list' style='display:block;'>" . str_replace("ChangeTutNow(this);", " var ahuh=this.value.split(\"=\"); location.href = \"./design_a_course.php?topic=\" + ahuh[ahuh.length - 1]; ", via("")) . "</div><div id='topic' style='display:none;'>" . via("C++") . "</div><br><br><input style='display:none;' align='center' type='submit' name='submit' id='submit' value='Submit'></input></form>" . "</body></html>";
}
?>


