<!DOCTYPE html>
<html>
<body bgcolor="#E6E6FA">


<?php
$modulecode= basename(getcwd());
$errorMsg = "";
$validUser = $_SESSION["login"] === true;
if(isset($_POST["submit"])) {
  $validUser = $_POST["username"] == $modulecode && $_POST["password"] == strrev($modulecode);
  if(!$validUser) {$errorMsg = "Invalid username or password.";
  header("Location: error.html");}
  else $_SESSION["login"] = true;
}
?>

<?php
$myfile = fopen("ModuleName.ssi", "r") or die("Unable to open file!");
$name=fread($myfile,filesize("ModuleName.ssi"));
fclose($myfile); 

$myfile = fopen("poll_question.ssi", "r") or die("Unable to open file!");
$question=fread($myfile,filesize("poll_question.ssi"));
fclose($myfile); 

$myfile = fopen("poll_mcoption0.ssi", "r") or die("Unable to open file!");
$option0=fread($myfile,filesize("poll_mcoption0.ssi"));
fclose($myfile); 

$myfile = fopen("poll_mcoption1.ssi", "r") or die("Unable to open file!");
$option1=fread($myfile,filesize("poll_mcoption1.ssi"));
fclose($myfile); 

$myfile = fopen("poll_mcoption2.ssi", "r") or die("Unable to open file!");
$option2=fread($myfile,filesize("poll_mcoption2.ssi"));
fclose($myfile); 

$myfile = fopen("poll_mcoption3.ssi", "r") or die("Unable to open file!");
$option3=fread($myfile,filesize("poll_mcoption3.ssi"));
fclose($myfile);


?>





<h1>Create poll for <?php echo $name; ?></h1>
  


<?php
$myfile = fopen("ModuleName.ssi", "r") or die("Unable to open file!");
$name=fread($myfile,filesize("ModuleName.ssi"));
fclose($myfile);

?>

<?php
$tquestion = $_POST["question"];
if ((empty($tquestion)) or (!$validUser)){}
else {
$myfile = fopen("poll_question.ssi", "w") or die("Unable to open file!");
fwrite($myfile,$tquestion);
fclose($myfile);}

$toption0 = $_POST["option0"];
if ((empty($toption0)) or (!$validUser)){}
else {
$myfile = fopen("poll_mcoption0.ssi", "w") or die("Unable to open file!");
fwrite($myfile,$toption0);
fclose($myfile);}

$toption1 = $_POST["option1"];
if ((empty($toption1)) or (!$validUser)){}
else {
$myfile = fopen("poll_mcoption1.ssi", "w") or die("Unable to open file!");
fwrite($myfile,$toption1);
fclose($myfile);}

$toption2 = $_POST["option2"];
if ((empty($toption2)) or (!$validUser)){}
else {
$myfile = fopen("poll_mcoption2.ssi", "w") or die("Unable to open file!");
fwrite($myfile,$toption2);
fclose($myfile);}


$toption3 = $_POST["option3"];
if ((empty($toption3)) or (!$validUser)){}
else {
$myfile = fopen("poll_mcoption3.ssi", "w") or die("Unable to open file!");
fwrite($myfile,$toption3);
fclose($myfile);}

if (!$validUser){}
else {
$insertvote = "0"."||"."0"."||"."0"."||"."0";
$fp = fopen("poll_result.txt","w");
fputs($fp,$insertvote);
fclose($fp);}




?>



<!-- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> --> 


<form method="post" action=" "> 
<font size="4"><B> Question:&nbsp;</B></font> 
<textarea name="question" rows="1" cols="120" id="update">
<?php echo $question ?>
</textarea>
<br><br>

<font size="4"><B> Option 1:&nbsp;</B></font>
<textarea name="option0" rows="1" cols="120">
<?php echo $option0 ?>
</textarea>
<br><br>

<font size="4"><B> Option 2:&nbsp;</B></font>
<textarea name="option1" rows="1" cols="120">
<?php echo $option1 ?>
</textarea>
<br><br>

<font size="4"><B> Option 3:&nbsp;</B></font>
<textarea name="option2" rows="1" cols="120">
<?php echo $option2 ?>
</textarea>
<br><br>

<font size="4"><B> Option 4:&nbsp;</B></font>
<textarea name="option3" rows="1" cols="120">
<?php echo $option3 ?>
</textarea>
<br><br>




<font size="4"><B>Enter your
<label for="username">Username:</label><input type="text" value="<?= $_POST["username"] ?>" id="username" name="username" />
 and 
<label for="password">Password:</label><input type="password" value="" id="password" name="password" /> and then &nbsp;</B></font>
<input type="submit" name="submit" value="Submit">
<br><br>
<?php if (!empty($_POST))   echo "<META HTTP-EQUIV ='Refresh' Content ='0; URL =change_poll.php'>"; ?>
</form>


















</body>
</html>


