Skip to content

Commit

Permalink
added remove person functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shewu committed May 15, 2012
1 parent eb5e259 commit b3535a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
31 changes: 28 additions & 3 deletions spacehold/fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ function getPeopleAndSpaces() {
}

while ($row = mysql_fetch_assoc($result)) {
foreach ($row as $val) {
echo $row['handle'] . "; " . $row['space'] . "\n";
}
echo $row['handle'] . "; " . $row['space'] . "\n";
}

mysql_free_result($result);
Expand Down Expand Up @@ -191,5 +189,32 @@ function getPeopleAtSpace($space) {
mysql_free_result($result);
mysql_close($con);
}

function removePersonFromSpace($person, $space) {
global $DB_NAME, $DB_SERVER, $DB_LOGIN;
global $SPACES_TBL, $PEOPLE_TBL;

$con = mysql_connect($DB_SERVER, $DB_LOGIN, getPassword());
if (!$con) {
echo "Failed to connect to database.";
die();
}
if (!mysql_select_db($DB_NAME)) {
echo "Database " . $DB_NAME . " not found!";
die();
}

$cmd = sprintf("DELETE FROM %s WHERE `space` = %s AND `handle` = %s", $PEOPLE_TBL, $space, $person);
$result = mysql_query($cmd);
if (!$result) {
echo "ERROR: command " . $cmd . " failed!";
die();
} else {
echo "0";
}

mysql_free_result($result);
mysql_close($con);
}
?>

4 changes: 4 additions & 0 deletions spacehold/r.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
$space = $_GET["space"];
$person = $_GET["person"];
addPersonToSpace($person, $space);
} else if (strcmp($cmd, "removeperson") == 0) {
$space = $_GET["space"];
$person = $_GET["person"];
removePersonFromSpace($person, $space);
} else {
echo "-1\n";
}
Expand Down

0 comments on commit b3535a9

Please sign in to comment.