From ea9b9429b23b4789b9c9c0c05bd43274c54cfd7c Mon Sep 17 00:00:00 2001 From: Hui Lan Date: Tue, 13 Dec 2022 10:49:22 +0800 Subject: [PATCH] YAAQB: this commit fixes Bug 457 - Can't remove a group or group member in LRR --- Course.php | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++--- Script.php | 36 ++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/Course.php b/Course.php index 8c43f55..34561e3 100644 --- a/Course.php +++ b/Course.php @@ -529,21 +529,37 @@ course_groups_table.Course_Group_id=course_group_members_table.Course_Group_id W $extra3=" Decline"; } - echo "
$name ($status) $extra $extra2 $extra3
"; + + # Add "delete group" button and allow only group creator to delete it + $extra4 = ""; + + echo "
$name ($status) $extra $extra2 $extra3" . + (($status == "Created")? "$extra4": "") + ."
"; $rs2=mysqli_query($con,"SELECT `ID`, `Course_Group_id`, course_group_members_table.Student_ID, course_group_members_table.`Status`,users_table.Full_Name FROM `course_group_members_table` INNER JOIN users_table on users_table.Student_ID=course_group_members_table.Student_ID where course_group_members_table.Course_Group_id=$id"); - + + #Check whether the current user in session is the creator of the group + $rs3 = mysqli_query($con, "SELECT `Status` from course_group_members_table where Student_ID = $student_id"); + $flag = mysqli_fetch_assoc($rs3)['Status'] == "Created"; + while($row = mysqli_fetch_assoc($rs2)) { $name=$row['Full_Name']; $id=$row['Course_Group_id']; $status=$row['Status']; $Student_ID=$row['Student_ID']; - - echo "
  • $name-$Student_ID ($status)
  • "; + #Show group members + remove button next to each member except the creator of the group + if($flag){ + echo "
  • $name-$Student_ID ($status)".(($status != "Created")?"":"")."
  • "; + }else{ + echo "
  • $name-$Student_ID ($status)"; + } } @@ -688,5 +704,62 @@ function remarking(data) window.location.href = data+"&details="+details; } +function remove_member(student_id, group_id) { + + try + { + + + $('
    \n\ + \n\ + \n\ +
    ').dialog({ + modal: true, + title:'Remove '+student_id+'?', + buttons: { + 'Confirm': function () { + $('#frm').submit(); + + $(this).dialog('close'); + }, + 'X': function () { + + $(this).dialog('close'); + } + + } +}); + + } catch(e){ alert(e); } +} + +function delete_group(id) { + + try + { + + + $('
    \n\ + \n\ +
    ').dialog({ + modal: true, + title:'Delete this group?', + buttons: { + 'Confirm': function () { + $('#frm').submit(); + + $(this).dialog('close'); + }, + 'X': function () { + + $(this).dialog('close'); + } + + } +}); + + } catch(e){ alert(e); } +} + diff --git a/Script.php b/Script.php index 224c84f..14d0ada 100644 --- a/Script.php +++ b/Script.php @@ -815,6 +815,42 @@ if (!empty($_GET["acceptinvite"])) { } } +#Remove a member from group + +if (!empty($_GET["removemember"])) { + + $student_id = mysqli_real_escape_string($con, $_GET["student_id"]); + $group_id = mysqli_real_escape_string($con, $_GET["group_id"]); + $url = mysqli_real_escape_string($con, $_GET["url"]); + + $sql = "Delete from `course_group_members_table` where student_id=$student_id and Course_Group_id=$group_id"; + + if ($con->query($sql) === TRUE) { + $_SESSION["info_ReMarking"] = " Member " . $student_id . " removed from the group"; + header("Location: Course.php?url=" . $url); + } else { + echo "Error: " . $sql . "
    " . $con->error; + } +} + +#Delete a whole group + +if (!empty($_GET["deletegroup"])) { + + $group_id = mysqli_real_escape_string($con, $_GET["group_id"]); + $url = mysqli_real_escape_string($con, $_GET["url"]); + + $sql1 = "Delete from `course_group_members_table` where Course_Group_id=$group_id"; + $sql2 = "Delete from `course_groups_table` where Course_Group_id=$group_id"; + + if ($con->query($sql1) === TRUE && $con->query($sql2) === TRUE) { + $_SESSION["info_ReMarking"] = " Group has been deleted successfully. "; + header("Location: Course.php?url=" . $url); + } else { + echo "Error: " . $sql . "
    " . $con->error; + } +} + #Extend Deadline if (!empty($_GET["extenddeadline"])) { -- 2.17.1