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

<!-- MODULE COORDINATES -->

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

$modulecode= basename(getcwd());?>



<?php
$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;
}
?>







<h1>Change module information for <?php echo $name; ?></h1>
 Enter text (and HTML characters if needed) into each text field and then press submit to upload all text fields at once. An example of a partially completed form is available <a href="../ChangeModule.php.html">here</a>. 
<BR><BR>

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

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

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

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

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

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

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

$myfile = fopen("SupplementaryMaterial.ssi", "r") or die("Unable to open file!");
$supplementary=fread($myfile,filesize("SupplementaryMaterial.ssi"));
fclose($myfile);
?>

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

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

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

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

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

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

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

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

?>

<?php
$tfile = $_FILES["file"];

if (empty($tfile)){}
else { if  ($validUser){
$Lp="uploads/problems.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="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> --> 


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

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

<font size="4"><B> Lecture times &amp; venues:&nbsp;</B></font>
<textarea name="lectures" rows="1" cols="120">
<?php echo $lectures ?>
</textarea>
<br><br>

<font size="4"><B> Tutorial times &amp; venues:&nbsp;</B></font>
<textarea name="tutorials" rows="1" cols="120">
<?php echo $tutorials ?>
</textarea>
<br><br>

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

<font size="4"><B> Module content:&nbsp;</B></font>
<textarea name="content" rows="10" cols="120">
<?php echo $content ?>
</textarea>
<br><br>

<font size="4"><B> Module assessment:&nbsp;</B></font>
<textarea name="assessment" rows="11" cols="120">
<?php echo $assessment ?>
</textarea>
<br><br>

<font size="4"><B> Supplementary material:&nbsp;</B></font>
<textarea name="supplementary" rows="10" cols="120">
<?php echo $supplementary ?>
</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 all of the above text:&nbsp;</B></font>
<input type="submit" name="submit" value="Submit">
<br><br>
<?php if (!empty($_POST))   echo "<META HTTP-EQUIV ='Refresh' Content ='0; URL =ChangeModule.php'>"; ?>
</form>


















</body>
</html>


