Fix Bug #460 - Group Assignment Attachment Issues in Course.php
This commit resolves two critical issues in group assignment attachments: 1. Duplicate Filename Issue: - Implemented $attachments array to track unique files - Added filtering logic using implode() to prevent redundant display 2. Attachment Visibility Issue: - Modified SQL query to retrieve attachments by group ID - All group members can now view all submitted attachments Testing: - Verified duplicate filenames are properly deduplicated - Confirmed all group members can access attachments Affected Components: - course.php - Database queries for group submissions Contributors: - Malango Lusajo Ande (202420781744) - Godswill Bassey Udotung (202420781746)Bug460-Malango
parent
21918cf883
commit
0c81e0c6cb
220
Course.php
220
Course.php
|
@ -152,7 +152,7 @@ include 'Header.php';
|
|||
$att3 = $row['Attachment_link_3'];
|
||||
$att4 = $row['Attachment_link_4'];
|
||||
$labid = $row['Lab_Report_ID'];
|
||||
$days_remaining = "Days remaining: ".date_diff(date_create($deadline), date_create())->format('%a days, %h hours, %i minutes');
|
||||
$days_remaining = date_diff(date_create($deadline), date_create())->format('%a days, %h hours, %i minutes');
|
||||
$full_link = "<a href='~\..\Download.php?file=$att1'>$att1</a>";
|
||||
|
||||
if($att2 != "") {
|
||||
|
@ -165,11 +165,6 @@ include 'Header.php';
|
|||
$full_link = $full_link."| <a href='~\..\Download.php?file=$att4'>$att4</a>";
|
||||
}
|
||||
|
||||
// check if the student has already submitted the assignment
|
||||
$query_result = mysqli_query($con, "SELECT * FROM lab_report_submissions WHERE Student_id=$student_id AND Lab_Report_ID=$labid");
|
||||
if (mysqli_num_rows($query_result) > 0)
|
||||
$days_remaining = 'You have already submitted this assignment.';
|
||||
|
||||
echo "<div class='card mt-md-2' style='word-wrap: break-word;'>
|
||||
<div class='card-body'>
|
||||
<h5 class='card-title'>$title</h5>
|
||||
|
@ -177,7 +172,7 @@ include 'Header.php';
|
|||
<p class='card-text'> $ins </p>
|
||||
<p> <small>Attachments</small>: $full_link </p>
|
||||
<p class='card-text'> <small> Posted: $posted Deadline: $deadline </small> </p>
|
||||
<div class='alert alert-warning'>$days_remaining</div>
|
||||
<div class='alert alert-warning'>Time left: $days_remaining</div>
|
||||
<p><a href='~\..\SubmitLab.php?id=$labid&url=$url' class='btn btn-primary'>Submit</a></p>
|
||||
</div>
|
||||
</div>";
|
||||
|
@ -199,13 +194,34 @@ include 'Header.php';
|
|||
$group_id = -1;
|
||||
}
|
||||
|
||||
$result = mysqli_query($con,"SELECT Lab_Report_ID, Marks, `Course_ID`, `Posted_Date`, `Deadline`, `Instructions`, lab_reports_table.Title, `Attachment_link_1`, `Attachment_link_2`, `Attachment_link_3`, `Attachment_link_4` FROM `lab_reports_table` WHERE Lab_Report_ID not in (select Lab_Report_ID from lab_report_submissions where (Student_id=$student_id or Course_Group_id=$group_id)) and Course_ID=$course_id and Deadline < '$c_date' ORDER by Lab_Report_ID DESC");
|
||||
$submitted_query = "SELECT Lab_Report_ID FROM lab_report_submissions WHERE (Student_id = $student_id OR Course_Group_id = $group_id)";
|
||||
$submitted_result = mysqli_query($con, $submitted_query);
|
||||
|
||||
if(mysqli_num_rows($result) == 0)
|
||||
{
|
||||
echo '<br><div class="alert alert-warning">You missed no lab reports.</div>';
|
||||
if (!$submitted_result) {
|
||||
die('Query failed: ' . mysqli_error($con));
|
||||
}
|
||||
|
||||
} else {
|
||||
// We initialized an empty array to hold the Lab_Report_IDs
|
||||
$submitted_lab_report_ids = [];
|
||||
|
||||
// Then we fetched all Lab_Report_IDs and stored them in the array
|
||||
while ($row = mysqli_fetch_assoc($submitted_result)) {
|
||||
$submitted_lab_report_ids[] = $row['Lab_Report_ID'];
|
||||
}
|
||||
|
||||
// We converted the array to a comma-separated string, for use in the main query
|
||||
$submitted_lab_report_ids_list = implode(',', $submitted_lab_report_ids);
|
||||
|
||||
// Check if the list is empty and handle it
|
||||
if (empty($submitted_lab_report_ids_list)) {
|
||||
$submitted_lab_report_ids_list = 'NULL'; // Handle appropriately
|
||||
}
|
||||
|
||||
// Now, we use the variable in our main query
|
||||
$result = mysqli_query($con, "SELECT Lab_Report_ID, Marks, `Course_ID`, `Posted_Date`, `Deadline`, `Instructions`, lab_reports_table.Title, `Attachment_link_1`, `Attachment_link_2`, `Attachment_link_3`, `Attachment_link_4` FROM `lab_reports_table` WHERE Lab_Report_ID NOT IN ($submitted_lab_report_ids_list) AND Course_ID = $course_id AND Deadline < '$c_date' ORDER BY Lab_Report_ID DESC");
|
||||
if(mysqli_num_rows($result) == 0) {
|
||||
echo '<br><div class="alert alert-warning">You missed no lab reports.</div>';
|
||||
} else {
|
||||
while($row = mysqli_fetch_assoc($result)) {
|
||||
$title = $row['Title'];
|
||||
$marks = $row['Marks'];
|
||||
|
@ -256,108 +272,101 @@ include 'Header.php';
|
|||
|
||||
|
||||
|
||||
<div id="menu3" class="tab-pane <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>">
|
||||
<?php
|
||||
<div id="menu3" class="tab-pane <?php if ($_GET['tab'] == 'Submitted') echo 'active'; ?>">
|
||||
<?php
|
||||
$group_id = $_SESSION['group_id'];
|
||||
if ($group_id == "") {
|
||||
$group_id = -1;
|
||||
} // This fixes "Submitted report not shown" http://118.25.96.118/bugzilla/show_bug.cgi?id=176
|
||||
|
||||
$group_id = $_SESSION['group_id'];
|
||||
if($group_id == "") {
|
||||
$group_id = -1;
|
||||
} // This fixes "Submitted report not shown" http://118.25.96.118/bugzilla/show_bug.cgi?id=176
|
||||
$sql_stmt = "SELECT Lab_Report_ID, Marks, Course_ID, Posted_Date, Deadline, Instructions, lab_reports_table.Title, Attachment_link_1, Attachment_link_2, Attachment_link_3, Attachment_link_4
|
||||
FROM lab_reports_table
|
||||
WHERE Lab_Report_ID IN
|
||||
(
|
||||
SELECT Lab_Report_ID
|
||||
FROM lab_report_submissions
|
||||
WHERE Status='Pending' AND (Student_id=$student_id OR Course_Group_id=$group_id) AND Course_ID=$course_id
|
||||
)
|
||||
ORDER BY Lab_Report_ID DESC";
|
||||
|
||||
$sql_stmt = "SELECT Lab_Report_ID, Marks, Course_ID, Posted_Date, Deadline, Instructions, lab_reports_table.Title, Attachment_link_1, Attachment_link_2, Attachment_link_3, Attachment_link_4
|
||||
FROM lab_reports_table
|
||||
WHERE Lab_Report_ID IN
|
||||
(
|
||||
SELECT Lab_Report_ID
|
||||
FROM lab_report_submissions
|
||||
WHERE Status='Pending' AND (Student_id=$student_id OR Course_Group_id=$group_id) AND Course_ID=$course_id
|
||||
)
|
||||
ORDER BY Lab_Report_ID DESC";
|
||||
$resultx = mysqli_query($con, $sql_stmt);
|
||||
if (mysqli_num_rows($resultx) == 0) {
|
||||
echo '<br><div class="alert alert-warning">You have no unmarked submissions. Check the Marked tab for your marked submissions (if any).</div>';
|
||||
} else {
|
||||
while ($row = mysqli_fetch_assoc($resultx)) {
|
||||
$lab_repo_id = $row['Lab_Report_ID'];
|
||||
$title = $row['Title'];
|
||||
$marks = $row['Marks'];
|
||||
$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'];
|
||||
|
||||
$resultx = mysqli_query($con, $sql_stmt);
|
||||
if(mysqli_num_rows($resultx) == 0) {
|
||||
echo '<br><div class="alert alert-warning">You have no unmarked submissions. Check the Marked tab for your marked submissions (if any).</div>';
|
||||
} else {
|
||||
while($row = mysqli_fetch_assoc($resultx)) {
|
||||
$lab_repo_id = $row['Lab_Report_ID'];
|
||||
$title = $row['Title'];
|
||||
$marks = $row['Marks'];
|
||||
$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'];
|
||||
if ($c_date < $deadline) {
|
||||
$submittedx = "<a href='~\..\SubmitLab.php?id=$id&url=$url' class='btn btn-sm btn-light'>Re-submit</a>";
|
||||
}
|
||||
|
||||
if ($c_date < $deadline) {
|
||||
$submittedx = "<a href='~\..\SubmitLab.php?id=$id&url=$url' class='btn btn-sm btn-light'>Re-submit</a>";
|
||||
}
|
||||
echo "<div class='btn btn-default break-word' style='dislay:block; word-wrap:break-word; border:1px solid #F0F0F0; border-left:1px solid #eee;'>
|
||||
$title ($marks Marks) <i class='fa fa-check-circle'></i>SUBMITTED<br>
|
||||
<span style='font-size:8pt'> $ins </span> <br>
|
||||
<small>Posted: $posted Deadline: $deadline</small> $submittedx <br>
|
||||
<small>Submitted files: ";
|
||||
|
||||
$full_link = "<a href='~\..\Lab_Report_Assignments\\$att1'>$att1</a>";
|
||||
$Sub_result = mysqli_query($con, "
|
||||
SELECT Submission_ID, Submission_Date, lab_report_submissions.Lab_Report_ID,
|
||||
lab_report_submissions.Student_id AS sub_std, lab_report_submissions.Course_Group_id,
|
||||
Attachment1, Notes, Attachment2, Attachment3, Attachment4, Marks,
|
||||
lab_report_submissions.Status, Title, users_table.Full_Name
|
||||
FROM lab_report_submissions
|
||||
LEFT JOIN users_table ON users_table.Student_ID = lab_report_submissions.Student_id
|
||||
WHERE Lab_Report_ID = $lab_repo_id
|
||||
AND (lab_report_submissions.Student_id = '$student_id'OR lab_report_submissions.Course_Group_id = $group_id)");
|
||||
|
||||
if ($att2 != "") {
|
||||
$full_link = $full_link."| <a href='~\..\Lab_Report_Assignments\\$att2'>$att2</a>";
|
||||
}
|
||||
if (mysqli_num_rows($Sub_result) == 0) {
|
||||
echo "No Attachments found.";
|
||||
} else {
|
||||
// An array for tracking displayed attachments
|
||||
$attachments = [];
|
||||
|
||||
if ($att3 != "") {
|
||||
$full_link = $full_link."| <a href='~\..\Lab_Report_Assignments\\$att3'>$att3</a>";
|
||||
}
|
||||
while ($row = mysqli_fetch_assoc($Sub_result)) {
|
||||
$att1 = $row['Attachment1'];
|
||||
$att2 = $row['Attachment2'];
|
||||
$att3 = $row['Attachment3'];
|
||||
$att4 = $row['Attachment4'];
|
||||
|
||||
if ($att4 != "") {
|
||||
$full_link = $full_link."| <a href='~\..\Lab_Report_Assignments\\$att4'>$att4</a>";
|
||||
}
|
||||
// Check and add attachments to the array if not already added
|
||||
if ($att1 != "" && !in_array($att1, $attachments)) {
|
||||
$attachments[] = "<a href='~\..\Download.php?file=$att1&attachment=1'>" . basename($att1) . "</a>";
|
||||
}
|
||||
if ($att2 != "" && !in_array($att2, $attachments)) {
|
||||
$attachments[] = "<a href='~\..\Download.php?file=$att2&attachment=2'>" . basename($att2) . "</a>";
|
||||
}
|
||||
if ($att3 != "" && !in_array($att3, $attachments)) {
|
||||
$attachments[] = "<a href='~\..\Download.php?file=$att3&attachment=3'>" . basename($att3) . "</a>";
|
||||
}
|
||||
if ($att4 != "" && !in_array($att4, $attachments)) {
|
||||
$attachments[] = "<a href='~\..\Download.php?file=$att4&attachment=4'>" . basename($att4) . "</a>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "<div class='btn btn-default break-word' style='dislay:block; word-wrap:break-word; border:1px solid #F0F0F0; border-left:1px solid #eee;'>
|
||||
$title ($marks Marks) <i class='fa fa-check-circle'></i>SUBMITTED<br>
|
||||
<span style='font-size:8pt'> $ins </span> <br>
|
||||
<small>Posted: $posted Deadline: $deadline</small> $submittedx <br>
|
||||
<small>Submitted files: ";
|
||||
// Remove duplicates from attachments array
|
||||
$attachments = array_unique($attachments);
|
||||
|
||||
$Sub_result = mysqli_query($con,"SELECT Submission_ID, Submission_Date, lab_report_submissions.Lab_Report_ID, lab_report_submissions.Student_id sub_std, lab_report_submissions.Course_Group_id, Attachment1, Notes, Attachment2, Attachment3, Attachment4, Marks, lab_report_submissions.Status, Title,users_table.Full_Name, course_group_members_table.Student_ID
|
||||
FROM lab_report_submissions
|
||||
LEFT JOIN users_table ON users_table.Student_ID=lab_report_submissions.Student_id
|
||||
LEFT JOIN course_group_members_table ON course_group_members_table.Course_Group_id=lab_report_submissions.Course_Group_id
|
||||
WHERE Lab_Report_ID=$lab_repo_id AND lab_report_submissions.Student_id='$student_id'");
|
||||
// Create a string from the array for display
|
||||
$full_links = implode(" | ", $attachments);
|
||||
|
||||
if(mysqli_num_rows($Sub_result) == 0) {
|
||||
echo "No Attachments found.";
|
||||
} else {
|
||||
while($row = mysqli_fetch_assoc($Sub_result)) {
|
||||
$att1 = $row['Attachment1'];
|
||||
$att2 = $row['Attachment2'];
|
||||
$att3 = $row['Attachment3'];
|
||||
$att4 = $row['Attachment4'];
|
||||
$base_att1 = basename(rawurldecode($att1));
|
||||
$base_att2 = basename(rawurldecode($att2));
|
||||
$base_att3 = basename(rawurldecode($att3));
|
||||
$base_att4 = basename(rawurldecode($att4));
|
||||
// Display submitted files
|
||||
echo $full_links;
|
||||
}
|
||||
|
||||
$full_link = "<a href='~\..\Download.php?file=$att1&attachment=1'>$base_att1</a>"; // prevent students from directly accessing their classmates' submissions
|
||||
|
||||
if ($att2 != "") {
|
||||
$full_link= $full_link." | <a href='~\..\Download.php?file=$att2&attachment=2'>$base_att2</a>";
|
||||
}
|
||||
|
||||
if ($att3 != "") {
|
||||
$full_link= $full_link." | <a href='~\..\Download.php?file=$att3&attachment=3'>$base_att3</a>";
|
||||
}
|
||||
|
||||
if ($att4 != "") {
|
||||
$full_link= $full_link." | <a href='~\..\Download.php?file=$att4&attachment=4'>$base_att4</a>";
|
||||
}
|
||||
|
||||
echo $full_link;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
echo "</small></div>";
|
||||
}
|
||||
}
|
||||
echo "";
|
||||
?>
|
||||
echo "</small></div>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
|
@ -652,12 +661,11 @@ include 'Header.php';
|
|||
|
||||
|
||||
|
||||
function remarking(url)
|
||||
function remarking(data)
|
||||
{
|
||||
const details = prompt("Please enter your remarking reasons","");
|
||||
if (details != null) {
|
||||
window.location.href = url+"&details="+details;
|
||||
}
|
||||
|
||||
window.location.href = data+"&details="+details;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue