From 39cc06930138b54d30e6c87255f21e4dc908bc30 Mon Sep 17 00:00:00 2001 From: Lan Hui Date: Tue, 5 Sep 2023 20:51:19 +0800 Subject: [PATCH] Courses.php: format code --- Courses.php | 292 ++++++++++++++++++++++++---------------------------- 1 file changed, 136 insertions(+), 156 deletions(-) diff --git a/Courses.php b/Courses.php index 9d98f1c..7331789 100644 --- a/Courses.php +++ b/Courses.php @@ -73,92 +73,86 @@ include 'Header.php'; ON users_table.User_ID=courses_table.Lecturer_User_ID WHERE URL='$course_url' "); - if(mysqli_num_rows($result)==0) - {} else { while($row = mysqli_fetch_assoc($result)) { - $name=$row['Course_Name']; - $code=$row['Course_Code']; - $faculty=$row['Faculty']; - $lecturer=$row['Full_Name']; - $academic=$row['Academic_Year']; - $url=$row['URL']; - $id=$row['Course_ID']; - $course_id=$row['Course_ID']; - echo "

($code) - $name

-
- Faculty: $faculty    Year: $academic    Lecturer: $lecturer -
-
"; - + if(mysqli_num_rows($result) > 0) { + while ($row = mysqli_fetch_assoc($result)) { + $name = $row['Course_Name']; + $code = $row['Course_Code']; + $faculty = $row['Faculty']; + $lecturer = $row['Full_Name']; + $academic = $row['Academic_Year']; + $url = $row['URL']; + $id = $row['Course_ID']; + $course_id = $row['Course_ID']; + echo "

($code) - $name

+
+ Faculty: $faculty    Year: $academic    Lecturer: $lecturer +
+
"; echo "
"; - } + } // ------------------------------Editing Lab Assignment by Lecturer ------------------------------------ - if($_GET['act']=="edit"){ - $getid = mysqli_real_escape_string($con, $_GET["cid"]); - $result1 = mysqli_query($con, "SELECT * from lab_reports_table WHERE Lab_Report_ID = '$getid'"); + if ($_GET['act'] == "edit") { + $getid = mysqli_real_escape_string($con, $_GET["cid"]); + $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)) { - $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']; - } + if (isset($_POST['form_uploadlab'])) { + $deadlinedate = trim(mysqli_real_escape_string($con, $_POST["deadlinedate"])); // remove spaces + $deadlinetime = trim(mysqli_real_escape_string($con, $_POST["deadlinetime"])); // remove spaces + $instructions = mysqli_real_escape_string($con, $_POST["instructions"]); + $title = mysqli_real_escape_string($con, $_POST["title"]); + $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"); - if(isset($_POST['form_uploadlab'])){ - $deadlinedate = trim(mysqli_real_escape_string($con, $_POST["deadlinedate"])); // remove spaces - $deadlinetime = trim(mysqli_real_escape_string($con, $_POST["deadlinetime"])); // remove spaces - $instructions = mysqli_real_escape_string($con, $_POST["instructions"]); - $title = mysqli_real_escape_string($con, $_POST["title"]); - $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 ($con->query($sql) === TRUE) { + $_SESSION["info_Updated"]="Assignment information updated successfully."; + } else { + echo "Serious error happened while updating assignment information."; + } + } - $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 ($con->query($sql) === TRUE) { - $_SESSION["info_Updated"]="Assignment information updated successfully."; - - } else { - // echo "Error: " . $sql . "
" . $con->error; - 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 . "
" . $con->error; - echo "Serious error happened while deleting the assignment."; - } - } + 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 "Serious error happened while deleting the assignment."; + } + } - if( $_SESSION['user_type']=="Lecturer"){ - $Date = $_SESSION['Date']; - $Time = $_SESSION['Time']; - $Instructions = $_SESSION['Instructions']; - $Title = $_SESSION['Title']; - $Marks = $_SESSION['Marks']; - $Type = $_SESSION['Type']; - - echo "

Editing assignment information

"; + if ($_SESSION['user_type'] == "Lecturer") { + $Date = $_SESSION['Date']; + $Time = $_SESSION['Time']; + $Instructions = $_SESSION['Instructions']; + $Title = $_SESSION['Title']; + $Marks = $_SESSION['Marks']; + $Type = $_SESSION['Type']; + echo "

Edit assignment information

"; ?> -
+ Deadline Date/Time
-
">
-
">
+
">
+
">
Title @@ -169,61 +163,54 @@ include 'Header.php'; "> Attachment 1 - Attachment 2 - Attachment 3 - - Attachment 4
- Individual Group"; + echo "Submission Type Individual Group"; } else { - echo "Submission Type Individual Group"; + echo "Submission Type Individual Group"; } ?> -

-




+



-
+
-
- +

New assignment

-
- + + Deadline (date and time)
-
-
+
+
Title @@ -234,14 +221,10 @@ include 'Header.php'; Attachment 1 - Attachment 2 - Attachment 3 - - Attachment 4
@@ -250,86 +233,82 @@ include 'Header.php'; Group

-




- +



"; - echo "

Assignment list

"; - error_reporting(0); - if(isset($_SESSION["info_Updated"])){ - echo '
'; - $_SESSION['info_Updated'] = null; + if (isset($_SESSION["info_Updated"])) { + echo '
'; + $_SESSION['info_Updated'] = null; } if (isset($_SESSION['info_courses'])) { - echo '
'; - $_SESSION['info_courses'] = null; + echo '
'; + $_SESSION['info_courses'] = null; } if (isset($_SESSION['info_courses'])) { - echo '
'; - $_SESSION['info_courses']=null; + echo '
'; + $_SESSION['info_courses']=null; } - - - - $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 "Only Lecturer can post assignments.
"; + if( $_SESSION['user_type'] == "TA") { + echo "Only Lecturer can post assignments.
"; } - if(mysqli_num_rows($result)==0) - { - echo "No assignments posted so far."; - } else { while($row = mysqli_fetch_assoc($result)) { - $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="$att1"; + $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($att2!=""){ - $full_link= $full_link."  |  $att2"; - } - if($att3!=""){ - $full_link= $full_link."  |  $att3"; - } + if(mysqli_num_rows($result)==0) { + echo "No assignments posted so far."; + } else { + while ($row = mysqli_fetch_assoc($result)) { + $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 = "$att1"; - if($att4!=""){ - $full_link= $full_link."   |   $att4"; - } + if ($att2 != "") { + $full_link = $full_link."  |  $att2"; + } + if ($att3 != "") { + $full_link = $full_link."  |  $att3"; + } + if ($att4 != "") { + $full_link = $full_link."   |   $att4"; + } + $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"); - 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; - - echo "
-
+ echo "
+
$title ($marks Marks, $as_type)
$ins

Posted: $posted    Deadline: $deadline

@@ -339,9 +318,10 @@ include 'Header.php'; Extend Deadline

Attachments: $full_link

-
"; +
"; - }} + } + } echo "
"; $resultx1 = mysqli_query($con,"SELECT course_students_table.Student_ID,users_table.Full_Name FROM