deleteosid.php3 3.04 KB
Newer Older
1 2 3 4 5 6
<?php
include("defs.php3");

#
# Standard Testbed Header
#
7
PAGEHEADER("Delete an OS Descriptor");
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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

#
# Must provide the OSID!
# 
if (!isset($osid) ||
    strcmp($osid, "") == 0) {
  USERERROR("The OSID was not provided!", 1);
}

Leigh B. Stoller's avatar
Leigh B. Stoller committed
23
if (! TBValidOSID($osid)) {
24
    USERERROR("The OSID '$osid' is not valid!", 1);
25 26 27
}

#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
28
# Verify permission.
29
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
30
if (!TBOSIDAccessCheck($uid, $osid, $TB_OSID_DESTROY)) {
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
    USERERROR("You do not have permission to delete OS Descriptor $osid!", 1);
}

#
# Get user level info.
#
if (!TBOSInfo($osid, $osname, $pid)) {
    USERERROR("OS Descriptor '$osid' is no longer valid!", 1);
}

#
# Check to see if the OSID is being used. Force whatever images are using
# it to be deleted or changed. This subsumes EZ created images/osids.
#
$query_result =
    DBQueryFatal("select * from images ".
		 "where part1_osid='$osid' or part2_osid='$osid' or ".
		 "      part3_osid='$osid' or part4_osid='$osid' or ".
		 "      default_osid='$osid'");

if (mysql_num_rows($query_result)) {
    echo "<center>The following images are using this OS Descriptor.<br>
          They must be deleted first!</center><br>\n";
          
    echo "<table border=1 cellpadding=2 cellspacing=2 align='center'>\n";

    echo "<tr>
              <td align=center>Image</td>
              <td align=center>PID</td>
          </tr>\n";

    while ($row = mysql_fetch_array($query_result)) {
	$imageid   = $row['imageid'];
	$url       = rawurlencode($imageid);
	$imagename = $row['imagename'];
	$pid       = $row[pid];

	echo "<tr>
                <td><A href='showimageid.php3?imageid=$url'>$imagename</A>
                    </td>
	        <td>$pid</td>
              </tr>\n";
    }
    echo "</table>\n";
    
    PAGEFOOTER();
    return;
78 79 80 81 82 83 84 85 86 87
}

#
# 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><br>
88
          OS Descriptor removal canceled!
89 90 91 92 93 94 95 96 97
          </h2></center>\n";
    
    PAGEFOOTER();
    return;
}

if (!$confirmed) {
    echo "<center><h2><br>
          Are you <b>REALLY</b>
98
          sure you want to delete OS Descriptor '$osname' in Project $pid?
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
          </h2>\n";
    
    echo "<form action=\"deleteosid.php3\" method=\"post\">";
    echo "<input type=hidden name=osid value=\"$osid\">\n";
    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;
}

#
# Delete the record,
#
Leigh B. Stoller's avatar
Leigh B. Stoller committed
115
DBQueryFatal("DELETE FROM os_info WHERE osid='$osid'");
116 117 118

echo "<p>
      <center><h2>
119
      OS Descriptor '$osname' in Project $pid has been deleted!
120 121
      </h2></center>\n";

122 123 124
echo "<br>
      <a href='showosid_list.php3'>Back to OS Descriptor list</a>\n";

125 126 127 128 129
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>