forked from science-ation/science-ation
Added api functionality for disconnecting a user from a registration : api/project/remove
This commit is contained in:
parent
f785a71be2
commit
64ef61d88f
12
api.php
12
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':
|
||||
|
@ -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';
|
||||
}
|
||||
*/
|
||||
|
||||
?>
|
||||
|
22
testapi.php
22
testapi.php
@ -63,6 +63,7 @@ include "common.inc.php";
|
||||
<a href="apidoc.php">API Documentation</a><br />
|
||||
<a href="doc/dictionary.php">Registration Group/Fields Dictionary Documentation</a><br/>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>General Commands</h2>
|
||||
|
||||
Login
|
||||
@ -90,6 +91,7 @@ Date List
|
||||
<input type="submit" value="Conference Date List">
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Account Settings</h2>
|
||||
<strong>Edit account information</strong><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>
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Project related commands</h2>
|
||||
|
||||
<h3>Start a new project</h3>
|
||||
<a href="api/project/add">start a new project</a><br/>
|
||||
|
||||
<h3>Join a project</h3>
|
||||
<form method = "post" action = "api/project/join">
|
||||
<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>
|
||||
</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>
|
||||
<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">
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>User Stuff</h2>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Event Schedule</h2>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Roles</h2>
|
||||
<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>
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Registration Fields</h2>
|
||||
<a href="api/registration/dictionary">View the dictionary of registration fields</a>
|
||||
<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">
|
||||
</form>
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Schools</h2>
|
||||
<a href="api/school/list">School Listing</a><br/>
|
||||
|
||||
@ -222,6 +237,7 @@ foreach($roles AS $role=>$r) {
|
||||
</form>
|
||||
|
||||
|
||||
<!-- ******************************************** -->
|
||||
<h2>Session Variables</h2>
|
||||
<?
|
||||
echo json_encode($_SESSION);
|
||||
|
Loading…
Reference in New Issue
Block a user