deletegroup.php3 2.59 KB
Newer Older
Leigh Stoller's avatar
Leigh Stoller committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
<?php
include("defs.php3");

#
# Standard Testbed Header
#
PAGEHEADER("Delete a Group");

#
# Only known and logged in users.
#
$uid = GETLOGIN();
LOGGEDINORDIE($uid);

#
# First off, sanity check page args.
#
if (!isset($pid) ||
    strcmp($pid, "") == 0) {
    USERERROR("Must provide a Project ID!", 1);
}
if (!isset($gid) ||
    strcmp($gid, "") == 0) {
    USERERROR("Must privide a Group ID!", 1);
}

#
# We do not allow the default group to be deleted. Never ever!
#
if (strcmp($gid, $pid) == 0) {
    USERERROR("You are not allowed to delete a project's default group!", 1);
}

#
# Verify permission.
#
if (! TBProjAccessCheck($uid, $pid, 0, $TB_PROJECT_DELGROUP)) {
    USERERROR("You do not have permission to delete groups in project $pid!",
	      1);
}

#
# Check to see if there are any active experiments. Abort if there are.
#
$query_result =
    DBQueryFatal("SELECT * FROM experiments where pid='$pid' and gid='$gid'");
if (mysql_num_rows($query_result)) {
    USERERROR("Project/Group '$pid/$gid' has active experiments. You must ".
	      "terminate ".
	      "those experiments before you can remove the project!", 1);
}

#
# We run this twice. The first time we are checking for a confirmation
# by putting up a form. The next time through the confirmation will be
# set. Or, the user can hit the cancel button, in which case we should
# probably redirect the browser back up a level.
#
if ($canceled) {
    echo "<center><h2>
          Group removal canceled!
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    echo "<center><h2>
          Are you <b>REALLY</b> sure you want to remove Group $gid
          in Project $pid?
          </h2>\n";
    
    echo "<form action='deletegroup.php3?pid=$pid&gid=$gid' method=post>";
    echo "<b><input type=submit name=confirmed value=Confirm></b>\n";
    echo "<b><input type=submit name=canceled value=Cancel></b>\n";
    echo "</form>\n";
    echo "</center>\n";

    PAGEFOOTER();
    return;
}

#
# Grab the unix group info of the project for running scripts.
#
TBGroupUnixInfo($pid, $pid, $unix_gid, $unix_name);

#
# Run the script. They will remove the group directory and the unix group.
#
SUEXEC($uid, $unix_gid, "webrmgroup $pid $gid", 1);

#
# Now safe to delete all members of the group, then delete the group.
#
DBQueryFatal("delete from group_membership where pid='$pid' and gid='$gid'");
DBQueryFatal("delete from groups where pid='$pid' and gid='$gid'");

#
# Warm fuzzies.
#
echo "<center><h2>
     Group $gid in Project $pid has been removed with prejudice!
     </h2></center>\n";

#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>