Courses.php: format code

Bug430-Eden2
Lan Hui 2023-09-05 20:51:19 +08:00
parent 09301d84ca
commit 39cc069301
1 changed files with 136 additions and 156 deletions

View File

@ -73,92 +73,86 @@ include 'Header.php';
ON users_table.User_ID=courses_table.Lecturer_User_ID ON users_table.User_ID=courses_table.Lecturer_User_ID
WHERE URL='$course_url' "); WHERE URL='$course_url' ");
if(mysqli_num_rows($result)==0) if(mysqli_num_rows($result) > 0) {
{} else { while($row = mysqli_fetch_assoc($result)) { while ($row = mysqli_fetch_assoc($result)) {
$name=$row['Course_Name']; $name = $row['Course_Name'];
$code=$row['Course_Code']; $code = $row['Course_Code'];
$faculty=$row['Faculty']; $faculty = $row['Faculty'];
$lecturer=$row['Full_Name']; $lecturer = $row['Full_Name'];
$academic=$row['Academic_Year']; $academic = $row['Academic_Year'];
$url=$row['URL']; $url = $row['URL'];
$id=$row['Course_ID']; $id = $row['Course_ID'];
$course_id=$row['Course_ID']; $course_id = $row['Course_ID'];
echo "<p class='mt-md-1 mb-md-1'> <strong>($code) - $name</strong> </p> echo "<p class='mt-md-1 mb-md-1'> <strong>($code) - $name</strong> </p>
<br> <br>
<small> Faculty: $faculty &nbsp;&nbsp; Year: $academic &nbsp;&nbsp; Lecturer: $lecturer </small> <small> Faculty: $faculty &nbsp;&nbsp; Year: $academic &nbsp;&nbsp; Lecturer: $lecturer </small>
<hr> <hr>
<div class='row'>"; <div class='row'>";
echo "<div class='col-md-5'>"; echo "<div class='col-md-5'>";
} }
// ------------------------------Editing Lab Assignment by Lecturer ------------------------------------ // ------------------------------Editing Lab Assignment by Lecturer ------------------------------------
if($_GET['act']=="edit"){ if ($_GET['act'] == "edit") {
$getid = mysqli_real_escape_string($con, $_GET["cid"]); $getid = mysqli_real_escape_string($con, $_GET["cid"]);
$result1 = mysqli_query($con, "SELECT * from lab_reports_table WHERE Lab_Report_ID = '$getid'"); $result1 = mysqli_query($con, "SELECT * from lab_reports_table WHERE Lab_Report_ID = '$getid'");
while($row1 = mysqli_fetch_assoc($result1)) {
$Deadline = $row1['Deadline'];
$_SESSION['Date'] = trim( strstr($Deadline, ' ', true) );
$_SESSION['Time'] = trim( strstr($Deadline, ' ') );
$_SESSION['Instructions'] = $row1['Instructions'];
$_SESSION['Title'] = $row1['Title'];
$_SESSION['Marks'] = $row1['Marks'];
$_SESSION['Type'] = $row1['Type'];
}
while($row1 = mysqli_fetch_assoc($result1)) { if (isset($_POST['form_uploadlab'])) {
$Deadline = $row1['Deadline']; $deadlinedate = trim(mysqli_real_escape_string($con, $_POST["deadlinedate"])); // remove spaces
$_SESSION['Date'] = trim( strstr($Deadline, ' ', true) ); $deadlinetime = trim(mysqli_real_escape_string($con, $_POST["deadlinetime"])); // remove spaces
$_SESSION['Time'] = trim( strstr($Deadline, ' ') ); $instructions = mysqli_real_escape_string($con, $_POST["instructions"]);
$_SESSION['Instructions'] = $row1['Instructions']; $title = mysqli_real_escape_string($con, $_POST["title"]);
$_SESSION['Title'] = $row1['Title']; $marks = mysqli_real_escape_string($con, $_POST["marks"]);
$_SESSION['Marks'] = $row1['Marks']; $type = mysqli_real_escape_string($con, $_POST["type"]);
$_SESSION['Type'] = $row1['Type']; $Deadline = $deadlinedate." ".$deadlinetime;
} $date = date("Y-m-d H:i");
if(isset($_POST['form_uploadlab'])){ $sql = "UPDATE `lab_reports_table` SET `Deadline` = ('" . $Deadline . "'), `Instructions` = ('" . $instructions . "'), `Title` = ('" . $title . "'), `Marks` = ('" . $marks . "'), `Type` = ('" . $type . "') WHERE `lab_reports_table`.`Lab_Report_ID` = '$getid'";
$deadlinedate = trim(mysqli_real_escape_string($con, $_POST["deadlinedate"])); // remove spaces if ($con->query($sql) === TRUE) {
$deadlinetime = trim(mysqli_real_escape_string($con, $_POST["deadlinetime"])); // remove spaces $_SESSION["info_Updated"]="Assignment information updated successfully.";
$instructions = mysqli_real_escape_string($con, $_POST["instructions"]); } else {
$title = mysqli_real_escape_string($con, $_POST["title"]); echo "Serious error happened while updating assignment information.";
$marks = mysqli_real_escape_string($con, $_POST["marks"]); }
$type = mysqli_real_escape_string($con, $_POST["type"]); }
$Deadline = $deadlinedate." ".$deadlinetime;
$date = date("Y-m-d H:i");
$sql = "UPDATE `lab_reports_table` SET `Deadline` = ('" . $Deadline . "'), `Instructions` = ('" . $instructions . "'), `Title` = ('" . $title . "'), `Marks` = ('" . $marks . "'), `Type` = ('" . $type . "') WHERE `lab_reports_table`.`Lab_Report_ID` = '$getid'"; if (isset($_POST['form_deletelab'])) {
if ($con->query($sql) === TRUE) { $sql = "DELETE FROM lab_reports_table WHERE Lab_Report_ID='$getid'";
$_SESSION["info_Updated"]="Assignment information updated successfully."; if ($con->query($sql) === TRUE) {
$_SESSION["info_Updated"]="Assignment deleted successfully.";
} else { } else {
// echo "Error: " . $sql . "<br>" . $con->error; echo "Serious error happened while deleting the assignment.";
echo "Serious error happened while updating assignment information."; }
} }
}
if(isset($_POST['form_deletelab'])) {
$sql = "DELETE FROM lab_reports_table WHERE Lab_Report_ID='$getid'";
if ($con->query($sql) === TRUE) {
$_SESSION["info_Updated"]="Assignment deleted successfully.";
} else {
// echo "Error: " . $sql . "<br>" . $con->error;
echo "Serious error happened while deleting the assignment.";
}
}
if( $_SESSION['user_type']=="Lecturer"){ if ($_SESSION['user_type'] == "Lecturer") {
$Date = $_SESSION['Date']; $Date = $_SESSION['Date'];
$Time = $_SESSION['Time']; $Time = $_SESSION['Time'];
$Instructions = $_SESSION['Instructions']; $Instructions = $_SESSION['Instructions'];
$Title = $_SESSION['Title']; $Title = $_SESSION['Title'];
$Marks = $_SESSION['Marks']; $Marks = $_SESSION['Marks'];
$Type = $_SESSION['Type']; $Type = $_SESSION['Type'];
echo "<h3><a href='Courses.php?course=".$url."'>Edit assignment information</a></h3>";
echo " <h3><a href='Courses.php?course=".$url."'>Editing assignment information</a></h3>";
?> ?>
<form method='post' enctype='multipart/form-data' action=''> <form method='post' enctype='multipart/form-data' action=''>
<input type='hidden' name='form_uploadlab' value='true' required=''/> <input type='hidden' name='form_uploadlab' value='true' required=''/>
<input type='hidden' name='course_id' value='<?php echo "$id" ?>' required=''/> <input type='hidden' name='course_id' value='<?php echo "$id" ?>' required=''/>
<input type='hidden' name='url' value='<?php echo ".$course_url." ?>' required=''/> <input type='hidden' name='url' value='<?php echo ".$course_url." ?>' required=''/>
Deadline Date/Time Deadline Date/Time
<div class='row'> <div class='row'>
<div class='col-md-7'><input type='date' id='date' name='deadlinedate' placeholder='' class='form-control' required='' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Date : ""; ?>"> </div> <div class='col-md-7'><input type='date' id='date' name='deadlinedate' placeholder='' class='form-control' required='' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Date : ""; ?>"> </div>
<div class='col-md-5'> <input type='text' id='time' class='form-control' name='deadlinetime' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Time : ""; ?>"> </div> <div class='col-md-5'> <input type='text' id='time' class='form-control' name='deadlinetime' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Time : ""; ?>"> </div>
</div> </div>
Title Title
@ -169,61 +163,54 @@ include 'Header.php';
<input type='text' name='marks' placeholder='Marks' class='form-control' required='' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Marks : ""; ?>"> <input type='text' name='marks' placeholder='Marks' class='form-control' required='' value="<?php echo isset($_GET['act']) && $_GET['act']=="edit" ? $Marks : ""; ?>">
Attachment 1 Attachment 1
<input type='file' name='attachment1' placeholder='Attachment 1' class='form-control'> <input type='file' name='attachment1' placeholder='Attachment 1' class='form-control'>
Attachment 2 Attachment 2
<input type='file' name='attachment2' placeholder='Attachment 1' class='form-control'> <input type='file' name='attachment2' placeholder='Attachment 1' class='form-control'>
Attachment 3 Attachment 3
<input type='file' name='attachment3' placeholder='Attachment 1' class='form-control' > <input type='file' name='attachment3' placeholder='Attachment 1' class='form-control' >
Attachment 4 Attachment 4
<input type='file' name='attachment4' placeholder='Attachment 4' class='form-control' > <input type='file' name='attachment4' placeholder='Attachment 4' class='form-control' >
<br> <br>
<?php <?php
if ($Type == "Individual") { if ($Type == "Individual") {
echo "Submission Type <input type='radio' name='type' value='Individual' checked /> Individual <input type='radio' name='type' value='Group' /> Group"; echo "Submission Type <input type='radio' name='type' value='Individual' checked /> Individual <input type='radio' name='type' value='Group' /> Group";
} else { } else {
echo "Submission Type <input type='radio' name='type' value='Individual' /> Individual <input type='radio' name='type' value='Group' checked> Group"; echo "Submission Type <input type='radio' name='type' value='Individual' /> Individual <input type='radio' name='type' value='Group' checked> Group";
} }
?> ?>
<br> <br>
<input type='submit' class='btn btn-primary' value='Update assignment'><br> <input type='submit' class='btn btn-primary' value='Update assignment'><br>
</form><br><br><br><br> </form><br><br><br><br>
<form method='post' action=''> <form method='post' action=''>
<input type='hidden' name='form_deletelab' value='true' required=''/> <input type='hidden' name='form_deletelab' value='true' required=''/>
<input type='submit' class='btn btn-danger' value='Delete assignment'><br> <input type='submit' class='btn btn-danger' value='Delete assignment'><br>
</form> </form>
<?php <?php
}}else{ }
} else {
// ------------------------------Posting New Lab Assignment------------------------------------ // ------------------------------Posting New Lab Assignment------------------------------------
// Mysql to split 1 string into 2 similar to the tsrstr in php // Mysql to split 1 string into 2 similar to the tsrstr in php
// SELECT SUBSTRING_INDEX(Deadline, ' ', 1) as Date, SUBSTRING_INDEX(Deadline, ' ', -1) as Time from lab_reports_table // SELECT SUBSTRING_INDEX(Deadline, ' ', 1) as Date, SUBSTRING_INDEX(Deadline, ' ', -1) as Time from lab_reports_table
if( $_SESSION['user_type']=="Lecturer"){ if ($_SESSION['user_type'] == "Lecturer") {
?> ?>
<h3>New assignment</h3> <h3>New assignment</h3>
<form method='post' enctype='multipart/form-data' action='Script.php'> <form method='post' enctype='multipart/form-data' action='Script.php'>
<?php <?php
$_SESSION['url']=$url; $_SESSION['url'] = $url;
?> ?>
<input type='hidden' name='form_uploadlab' value='true' required=''/> <input type='hidden' name='form_uploadlab' value='true' required=''/>
<input type='hidden' name='course_id' value='<?php echo "$id" ?>' required=''/> <input type='hidden' name='course_id' value='<?php echo "$id" ?>' required=''/>
<input type='hidden' name='url' value='<?php echo ".$course_url." ?>' required=''/> <input type='hidden' name='url' value='<?php echo ".$course_url." ?>' required=''/>
Deadline (date and time) Deadline (date and time)
<div class='row'> <div class='row'>
<div class='col-md-7'><input type='date' id='date' name='deadlinedate' placeholder='' class='form-control' required='' value=""> </div> <div class='col-md-7'><input type='date' id='date' name='deadlinedate' placeholder='' class='form-control' required='' value=""> </div>
<div class='col-md-5'> <input type='time' class='form-control' name='deadlinetime' value=""> </div> <div class='col-md-5'> <input type='time' class='form-control' name='deadlinetime' value=""> </div>
</div> </div>
Title Title
@ -234,14 +221,10 @@ include 'Header.php';
<input type='text' name='marks' placeholder='Marks' class='form-control' required='' value=""> <input type='text' name='marks' placeholder='Marks' class='form-control' required='' value="">
Attachment 1 Attachment 1
<input type='file' name='attachment1' placeholder='Attachment 1' class='form-control'> <input type='file' name='attachment1' placeholder='Attachment 1' class='form-control'>
Attachment 2 Attachment 2
<input type='file' name='attachment2' placeholder='Attachment 1' class='form-control'> <input type='file' name='attachment2' placeholder='Attachment 1' class='form-control'>
Attachment 3 Attachment 3
<input type='file' name='attachment3' placeholder='Attachment 1' class='form-control' > <input type='file' name='attachment3' placeholder='Attachment 1' class='form-control' >
Attachment 4 Attachment 4
<input type='file' name='attachment4' placeholder='Attachment 4' class='form-control' > <input type='file' name='attachment4' placeholder='Attachment 4' class='form-control' >
<br> <br>
@ -250,86 +233,82 @@ include 'Header.php';
<input type='radio' name='type' value='Group' required=''> Group <input type='radio' name='type' value='Group' required=''> Group
<hr> <hr>
<input type='submit' class='btn btn-primary' value='Post'><br> <input type='submit' class='btn btn-primary' value='Post'><br>
</form><br><br><br><br> </form><br><br><br><br>
<?php <?php
} }
} }
} }
echo "</div>"; echo "</div>";
echo "<div class='col-md-7'><h3>Assignment list</h3>"; echo "<div class='col-md-7'><h3>Assignment list</h3>";
error_reporting(0); error_reporting(0);
if(isset($_SESSION["info_Updated"])){ if (isset($_SESSION["info_Updated"])) {
echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_Updated'] . '</div>'; echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_Updated'] . '</div>';
$_SESSION['info_Updated'] = null; $_SESSION['info_Updated'] = null;
} }
if (isset($_SESSION['info_courses'])) { if (isset($_SESSION['info_courses'])) {
echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_courses'] . '</div>'; echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_courses'] . '</div>';
$_SESSION['info_courses'] = null; $_SESSION['info_courses'] = null;
} }
if (isset($_SESSION['info_courses'])) { if (isset($_SESSION['info_courses'])) {
echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_courses'] . '</div>'; echo '<hr><div class="alert alert-warning" role="alert">' . $_SESSION['info_courses'] . '</div>';
$_SESSION['info_courses']=null; $_SESSION['info_courses']=null;
} }
if( $_SESSION['user_type'] == "TA") {
echo "<b style='color:gray'>Only Lecturer can post assignments.</b><br>";
$result = mysqli_query($con," SELECT `Lab_Report_ID`,Type,Marks, `Course_ID`, `Posted_Date`, `Deadline`, `Instructions`, `Title`, `Attachment_link_1`, `Attachment_link_2`, `Attachment_link_3`, "
. "`Attachment_link_4` FROM `lab_reports_table` WHERE Course_ID=$id ORDER by Lab_Report_ID DESC");
if( $_SESSION['user_type']=="TA")
{
echo "<b style='color:gray'>Only Lecturer can post assignments.</b><br>";
} }
if(mysqli_num_rows($result)==0)
{
echo "No assignments posted so far.";
} else { while($row = mysqli_fetch_assoc($result)) { $result = mysqli_query($con, "SELECT Lab_Report_ID, Type, Marks, Course_ID, Posted_Date, Deadline, Instructions, Title, Attachment_link_1, Attachment_link_2, Attachment_link_3, Attachment_link_4
$marks=$row['Marks']; FROM lab_reports_table
$title=$row['Title']; WHERE Course_ID=$id ORDER BY Lab_Report_ID DESC");
$ins=$row['Instructions'];
$posted=$row['Posted_Date'];
$deadline=$row['Deadline'];
$att1=$row['Attachment_link_1'];
$att2=$row['Attachment_link_2'];
$att3=$row['Attachment_link_3'];
$att4=$row['Attachment_link_4'];
$id=$row['Lab_Report_ID'];
$cours_id=$row['Course_ID'];
$as_type=$row['Type'];
$full_link="<a href='~\..\Download.php?file=$att1'>$att1</a>";
if($att2!=""){ if(mysqli_num_rows($result)==0) {
$full_link= $full_link." &nbsp|&nbsp <a href='~\..\Download.php?file=$att2'>$att2</a>"; echo "No assignments posted so far.";
} } else {
if($att3!=""){ while ($row = mysqli_fetch_assoc($result)) {
$full_link= $full_link." &nbsp|&nbsp <a href='~\..\Download.php?file=$att3'>$att3</a>"; $marks = $row['Marks'];
} $title = $row['Title'];
$ins = $row['Instructions'];
$posted = $row['Posted_Date'];
$deadline = $row['Deadline'];
$att1 = $row['Attachment_link_1'];
$att2 = $row['Attachment_link_2'];
$att3 = $row['Attachment_link_3'];
$att4 = $row['Attachment_link_4'];
$id = $row['Lab_Report_ID'];
$cours_id = $row['Course_ID'];
$as_type = $row['Type'];
$full_link = "<a href='~\..\Download.php?file=$att1'>$att1</a>";
if($att4!=""){ if ($att2 != "") {
$full_link= $full_link." &nbsp; | &nbsp <a href='~\..\Download.php?file=$att4'>$att4</a>"; $full_link = $full_link." &nbsp|&nbsp <a href='~\..\Download.php?file=$att2'>$att2</a>";
} }
if ($att3 != "") {
$full_link = $full_link." &nbsp|&nbsp <a href='~\..\Download.php?file=$att3'>$att3</a>";
}
if ($att4 != "") {
$full_link = $full_link." &nbsp; | &nbsp <a href='~\..\Download.php?file=$att4'>$att4</a>";
}
$resultx1 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id");
while ($row = mysqli_fetch_assoc($resultx1)) {
$count_subs = $row['cnt'];
}
$resultx2 = mysqli_query($con, "SELECT COUNT(*) AS cnt FROM lab_report_submissions WHERE lab_report_submissions.Lab_Report_ID=$id AND Marks IS NOT null");
if (mysqli_num_rows($resultx2) == 0) {
$count_marked = 0;
} else {
while ($row = mysqli_fetch_assoc($resultx2)) {
$count_marked = $row['cnt'];
}
}
$header="Courses > ".$name."($code) > Assignments > ".$title;
$resultx1 = mysqli_query($con,"Select Count(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id"); echo " <div class='card mt-md-2'>
while($row = mysqli_fetch_assoc($resultx1)) {$count_subs=$row['cnt'];} <div class='card-body'>
$resultx2 = mysqli_query($con,"Select COUNT(*) as cnt from lab_report_submissions where lab_report_submissions.Lab_Report_ID=$id and Marks is not null");
if(mysqli_num_rows($resultx2)==0){$count_marked=0;} else { while($row = mysqli_fetch_assoc($resultx2)) {$count_marked =$row['cnt'];}}
$header="Courses > ".$name."($code) > Assignments > ".$title;
echo " <div class='card mt-md-2'>
<div class='card-body'>
<h5 class='card-title'>$title ($marks Marks, $as_type)</h5> <h5 class='card-title'>$title ($marks Marks, $as_type)</h5>
<h6 class='card-subtitle'>$ins</h6> <h6 class='card-subtitle'>$ins</h6>
<p class='card-text text-muted'><small>Posted: $posted &nbsp;&nbsp; Deadline: $deadline</small></p> <p class='card-text text-muted'><small>Posted: $posted &nbsp;&nbsp; Deadline: $deadline</small></p>
@ -339,9 +318,10 @@ include 'Header.php';
<a class='card-link' href='#' onclick='extendDeadline($id)'> Extend Deadline </a> <a class='card-link' href='#' onclick='extendDeadline($id)'> Extend Deadline </a>
<p class='card-text'> Attachments: $full_link</p> <p class='card-text'> Attachments: $full_link</p>
</div> </div>
</div>"; </div>";
}} }
}
echo "</div>"; echo "</div>";
$resultx1 = mysqli_query($con,"SELECT course_students_table.Student_ID,users_table.Full_Name FROM $resultx1 = mysqli_query($con,"SELECT course_students_table.Student_ID,users_table.Full_Name FROM