Added api functionality for disconnecting a user from a registration : api/project/remove

This commit is contained in:
jacob 2011-02-18 21:53:07 +00:00
parent f785a71be2
commit 64ef61d88f
3 changed files with 53 additions and 20 deletions

12
api.php
View File

@ -966,20 +966,17 @@ switch($request[0]) {
break; break;
/* APIDOC: project/remove /* 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.) description(remove the current user from an existing project. If no other users are in the project, then it is deleted.)
*/ */
case 'remove': case 'remove':
$ret['status'] = "error"; if(!array_key_exists('registrations_id', $_POST)){
$ret['error'] = $_GET['request'] . " functionality not yet implemented";
/*
if(!array_key_exists('registration_number', $_POST)){
$ret['status'] = 'error'; $ret['status'] = 'error';
$ret['error'] = 'registration_number (integer) is required'; $ret['error'] = 'registrations_id (integer) is required';
break; break;
} }
$result = removeProject($_POST['registration_number']); $result = removeProject($_POST['registrations_id']);
if($result != 'ok'){ if($result != 'ok'){
$ret['status'] = "error"; $ret['status'] = "error";
$ret['error'] = $result; $ret['error'] = $result;
@ -987,7 +984,6 @@ switch($request[0]) {
} }
$ret['status'] = 'ok'; $ret['status'] = 'ok';
*/
break; break;
case 'mentor': case 'mentor':

View File

@ -764,31 +764,52 @@ function joinProject($registration_number, $email){
// disassociate the active user from the specified project registration. If the registration no longer // 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 // has any users connected to it, delete it, and any projects tied to it
/* function removeProject($registrations_id){
function removeProject($registration_id){
// make sure this user is indeed connected to the specified project // make sure this user is indeed connected to the specified project
$uid = $_SESSION['users_id']; $uid = $_SESSION['users_id'];
$regId = getRegistrationsId($uid); $regId = getRegistrationsId($uid);
$registration_number = intval($registration_number); $registrations_id = intval($registrations_id);
if($regId != $registration_number){ if($regId != $registrations_id){
return 'register_participants.inc.php::removeProject -> you are not connected to that project'; 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()){ if(mysql_error()){
return "register_participants.inc.php::removeProject -> " . mysql_error(); return "register_participants.inc.php::removeProject -> " . mysql_error();
} }
// now let's see if anyone else is connected to that registration // 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); $result = mysql_fetch_assoc($q);
if($result['tally'] == 0){ if($result['tally'] == 0){
//nobody wants the poor lonely registration. Let's put it out of it's misery //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'; return 'ok';
} }
*/
?> ?>

View File

@ -63,6 +63,7 @@ include "common.inc.php";
<a href="apidoc.php">API Documentation</a><br /> <a href="apidoc.php">API Documentation</a><br />
<a href="doc/dictionary.php">Registration Group/Fields Dictionary Documentation</a><br/> <a href="doc/dictionary.php">Registration Group/Fields Dictionary Documentation</a><br/>
<!-- ******************************************** -->
<h2>General Commands</h2> <h2>General Commands</h2>
Login Login
@ -90,6 +91,7 @@ Date List
<input type="submit" value="Conference Date List"> <input type="submit" value="Conference Date List">
</form> </form>
<!-- ******************************************** -->
<h2>Account Settings</h2> <h2>Account Settings</h2>
<strong>Edit account information</strong><br/> <strong>Edit account information</strong><br/>
Username: <input type="text" id="username"></input><br/> Username: <input type="text" id="username"></input><br/>
@ -106,16 +108,26 @@ email address: <input type="text" name="email"></input><br/>
<input type="submit" value="Create Account"></input> <input type="submit" value="Create Account"></input>
</form> </form>
<!-- ******************************************** -->
<h2>Project related commands</h2> <h2>Project related commands</h2>
<h3>Start a new project</h3> <h3>Start a new project</h3>
<a href="api/project/add">start a new project</a><br/> <a href="api/project/add">start a new project</a><br/>
<h3>Join a project</h3> <h3>Join a project</h3>
<form method = "post" action = "api/project/join"> <form method = "post" action = "api/project/join">
<label>project e-mail address:<input type="text" name="email"></input></label><br/> <label>project e-mail address:<input type="text" name="email"></input></label><br/>
<label>registration id:<input type="text" name="registrations_id"></input></label><br/> <label>registration number:<input type="text" name="registration_number"></input></label><br/>
<input type="submit" value="Join"></input> <input type="submit" value="Join"></input>
</form> </form>
<h3>Leave a project</h3>
<form method ="post" action = "api/project/remove">
<label>registration id:<input type="text" name="registrations_id"></input></label><br/>
<input type="submit" value="Leave"></input>
</form>
<!-- ******************************************** -->
<h2>Teacher Specific Commands</h2> <h2>Teacher Specific Commands</h2>
<a href="api/scienceolympics/teams/list">Science Olympic Teams List</a><br /> <a href="api/scienceolympics/teams/list">Science Olympic Teams List</a><br />
@ -135,6 +147,7 @@ email address: <input type="text" name="email"></input><br/>
<input type="submit" value="Edit Team"> <input type="submit" value="Edit Team">
</form> </form>
<!-- ******************************************** -->
<h2>User Stuff</h2> <h2>User Stuff</h2>
<a href="api/user/view/">View the user</a><br/> <a href="api/user/view/">View the user</a><br/>
@ -160,8 +173,7 @@ role id: <input type="text" name="roles_id"></input><br/>
<input type="submit" value="Uninvite User"></input> <input type="submit" value="Uninvite User"></input>
</form> </form>
<!-- ******************************************** -->
<h2>Event Schedule</h2> <h2>Event Schedule</h2>
<a href="api/schedule/list">Schedule Listing</a><br/> <a href="api/schedule/list">Schedule Listing</a><br/>
@ -181,6 +193,7 @@ Schedule ID: <input type="text" name="schedule_id"></input>
<input type="submit" value="Unregister"></input> <input type="submit" value="Unregister"></input>
</form> </form>
<!-- ******************************************** -->
<h2>Roles</h2> <h2>Roles</h2>
<a href="api/role/list">Get a list of roles for this conference</a><br/> <a href="api/role/list">Get a list of roles for this conference</a><br/>
@ -199,6 +212,7 @@ Remove a role from this account
</div> </div>
</form> </form>
<!-- ******************************************** -->
<h2>Registration Fields</h2> <h2>Registration Fields</h2>
<a href="api/registration/dictionary">View the dictionary of registration fields</a> &nbsp; <a href="api/registration/dictionary">View the dictionary of registration fields</a> &nbsp;
<a href="doc/dictionary.php">View Documentation Generated by this API call</a><br/> <a href="doc/dictionary.php">View Documentation Generated by this API call</a><br/>
@ -212,6 +226,7 @@ foreach($roles AS $role=>$r) {
<input type="submit" value="List Registration Fields for Selected Roles"> <input type="submit" value="List Registration Fields for Selected Roles">
</form> </form>
<!-- ******************************************** -->
<h2>Schools</h2> <h2>Schools</h2>
<a href="api/school/list">School Listing</a><br/> <a href="api/school/list">School Listing</a><br/>
@ -222,6 +237,7 @@ foreach($roles AS $role=>$r) {
</form> </form>
<!-- ******************************************** -->
<h2>Session Variables</h2> <h2>Session Variables</h2>
<? <?
echo json_encode($_SESSION); echo json_encode($_SESSION);