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


<!-- LECTURE CONTENT -->


<?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("LectureNumber.txt", "r") or die("Unable to open file!");
$number=fread($myfile,filesize("LectureNumber.txt"));
fclose($myfile);
$L="uploads/L". $number . ".ssi";

$myfile = fopen($L, "r") or die("Unable to open file!");
$summary=fread($myfile,filesize($L));
fclose($myfile);
 ?>

<h1>Update lecture information for <?php echo $name; ?></h1>



<?php
$tsummary = $_POST["summary"];

if (empty($tsummary)){}
else {
$L="uploads/L". $number . ".ssi";
$myfile = fopen($L, "w") or die("Unable to open file!");
if  ($validUser)   {fwrite($myfile,$tsummary);}
else { header("Location: error.html");} 
fclose($myfile);}

$tfile = $_FILES["file"];

if (empty($tfile)){}
else { if  ($validUser){
$myfile = fopen("LectureNumber.txt", "r") or die("Unable to open file!");
$number=fread($myfile,filesize("LectureNumber.txt"));
fclose($myfile);
$Lp="uploads/L". $number . ".pdf";
 $targetfolder = $Lp;
 $ok=1;
$file_type=$_FILES['file']['type'];
if ($file_type=="application/pdf") {
 if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))
 {
 echo "The file ". basename( $_FILES['file']['name']). " is uploaded";
 }
 else {
 echo "Problem uploading file";
 }
}
else {
 echo "You may only upload PDF files and you need a valid username and password.<br>";
}}
else { header("Location: error.html");}
}

?>



<form method="post" action=" "> 

<font size="4"><B> Summary of Lecture <?php echo $number ?>:&nbsp;</B></font>
<textarea name="summary" rows="10" cols="120">
<?php echo $summary?>
</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 click here to save the summary:&nbsp;</B></font>  
<input type="submit" name="submit" value="Submit"> 
<br><br>


<?php 
if (!empty($_POST))
  { echo "<META HTTP-EQUIV ='Refresh' Content ='0; URL =ChangeLecture.php'>";};
 ?>
</form>


<BR><BR>
<form action="" method="post" enctype="multipart/form-data">

<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 upload slides for Lecture <?php echo $number ?> as a single pdf file:&nbsp;</B></font>
<input type="file" name="file" size="10" />
<input type="submit" name="submit" value="Upload" />
</form>


</body>
</html>











