From 340a45127b817dc40cfead8aec826c99a1f2ec0d Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 18 Feb 2011 16:46:44 +0000 Subject: [PATCH] Added code preventing users from creating more than one registration/project --- api.php | 1 + register_participants.inc.php | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api.php b/api.php index b5c3b8b..8016f65 100644 --- a/api.php +++ b/api.php @@ -875,6 +875,7 @@ switch($request[0]) { case 'add': // be logged in as a student in order to create a project $user = user_load($_SESSION['users_id']); + $ret['userdat'] = $user; if(!$user || !in_array('participant', $_SESSION['roles'])){ $ret['status'] = 'error'; $ret['error'] = "You must be logged in as a participant to create a project"; diff --git a/register_participants.inc.php b/register_participants.inc.php index f5d3585..22a28f9 100644 --- a/register_participants.inc.php +++ b/register_participants.inc.php @@ -605,13 +605,26 @@ function getNewRegNum(){ } // add a registration record and return it's unique "num" id -//FIXME - this should probably do a check to see if the user -// was connected to another project already, and either: -// a) check to see if anyone else is connected to it, and delete it if not -// b) don't let them create a new one without explicitly disassociating with the other +// returns an error message if the user is alredy registered function addRegistration($userId){ global $conference; + // first we make sure that they don't already have a project on the go + $query = mysql_query("SELECT * FROM users WHERE id = $userId"); + $err = mysql_error(); + if($err){ + return "register_participants.inc.php::addRegistration -> " . $err; + } + + $row = mysql_fetch_assoc($query); + if(!$row){ + return "register_participants.inc.php::addRegistration -> user not found"; + } + + if($row['registrations_id'] != null){ + return "register_participants.inc.php::addRegistration -> user already has a project registered"; + } + // create the new registration record, and assign a random/unique registration number. $regnum = getNewRegNum();