diff --git a/api.php b/api.php
index bfc9523..9ed2709 100644
--- a/api.php
+++ b/api.php
@@ -966,20 +966,17 @@ switch($request[0]) {
break;
/* APIDOC: project/remove
- post(registration_number integer)
+ post(registrations_id integer)
description(remove the current user from an existing project. If no other users are in the project, then it is deleted.)
*/
case 'remove':
- $ret['status'] = "error";
- $ret['error'] = $_GET['request'] . " functionality not yet implemented";
- /*
- if(!array_key_exists('registration_number', $_POST)){
+ if(!array_key_exists('registrations_id', $_POST)){
$ret['status'] = 'error';
- $ret['error'] = 'registration_number (integer) is required';
+ $ret['error'] = 'registrations_id (integer) is required';
break;
}
- $result = removeProject($_POST['registration_number']);
+ $result = removeProject($_POST['registrations_id']);
if($result != 'ok'){
$ret['status'] = "error";
$ret['error'] = $result;
@@ -987,7 +984,6 @@ switch($request[0]) {
}
$ret['status'] = 'ok';
- */
break;
case 'mentor':
diff --git a/register_participants.inc.php b/register_participants.inc.php
index d88e111..0ff7469 100644
--- a/register_participants.inc.php
+++ b/register_participants.inc.php
@@ -764,31 +764,52 @@ function joinProject($registration_number, $email){
// disassociate the active user from the specified project registration. If the registration no longer
// has any users connected to it, delete it, and any projects tied to it
-/*
-function removeProject($registration_id){
+function removeProject($registrations_id){
// make sure this user is indeed connected to the specified project
$uid = $_SESSION['users_id'];
$regId = getRegistrationsId($uid);
- $registration_number = intval($registration_number);
- if($regId != $registration_number){
+ $registrations_id = intval($registrations_id);
+ if($regId != $registrations_id){
return 'register_participants.inc.php::removeProject -> you are not connected to that project';
}
- mysql_query("UPDATE users SET registrations_id = null WHERE ud = $uid");
+ mysql_query("UPDATE users SET registrations_id = null WHERE id = $uid");
if(mysql_error()){
return "register_participants.inc.php::removeProject -> " . mysql_error();
}
// now let's see if anyone else is connected to that registration
- $q = mysql_query("SELECT COUNT(*) AS tally FROM users WHERE registrations_id = $registration_number");
+ $q = mysql_query("SELECT COUNT(*) AS tally FROM users WHERE registrations_id = $registrations_id");
$result = mysql_fetch_assoc($q);
if($result['tally'] == 0){
//nobody wants the poor lonely registration. Let's put it out of it's misery
- mysql_query("DELETE FROM registrations WHERE num = $registration_number");
- mysql_query("DELETE FROM projects WHERE registrations_id
+
+ mysql_query("DELETE FROM registrations WHERE id = $registrations_id");
+ if(mysql_error()){
+ return "register_participants.inc.php::removeProject -> " . mysql_error();
+ }
+
+ $projIds = array();
+ $q = mysql_query("SELECT id FROM projects WHERE registrations_id = $registrations_id");
+ while($row = mysql_fetch_assoc($q)){
+ $projIds[] = $row['id'];
+ }
+ if(count($projIds) > 0){
+ mysql_query("DELETE FROM project_specialawards_link
+ WHERE projects_id IN(" . implode('.', $projIds) . ")");
+ if(mysql_error()){
+ return "register_participants.inc.php::removeProject -> " . mysql_error();
+ }
+ }
+
+ mysql_query("DELETE FROM projects WHERE registrations_id = $registrations_id");
+ if(mysql_error()){
+ return "register_participants.inc.php::removeProject -> " . mysql_error();
+ }
+
}
return 'ok';
}
-*/
+
?>
diff --git a/testapi.php b/testapi.php
index 4fd13a3..c4ffe31 100644
--- a/testapi.php
+++ b/testapi.php
@@ -63,6 +63,7 @@ include "common.inc.php";
API Documentation
Registration Group/Fields Dictionary Documentation
+