From a28ab561ebbe1ced739d7909d71568b6e118ef6c Mon Sep 17 00:00:00 2001 From: james Date: Fri, 4 Mar 2011 16:15:10 +0000 Subject: [PATCH] Properly handle award id = -1 for "i dont want special awards" --- register_participants.inc.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/register_participants.inc.php b/register_participants.inc.php index 20df832..74303be 100644 --- a/register_participants.inc.php +++ b/register_participants.inc.php @@ -352,16 +352,32 @@ function saveProjectData($data,$registrations_id=null){ } mysql_query("DELETE FROM project_specialawards_link WHERE projects_id='{$data['project_id']}' AND conferences_id='{$conference['id']}'"); - $idx=0; + //now filter the list we've been given, to make sure everything's hunky dory + $awards=array(); foreach($data['specialawards'] AS $sa) { - if($sa['selected'] && in_array($sa['id'],$eligibleAwardsList)) { - $qstr="INSERT INTO project_specialawards_link (award_awards_id,projects_id,conferences_id) VALUES ('".intval($sa['id'])."','".intval($data['project_id'])."','{$conference['id']}')"; - mysql_query($qstr); - $idx++; - //dont let them sign up for more than they are allowed to - if($idx>=$config['maxspecialawardsperproject']) - break; + //If all they've selected is they don't want to self nominate, then erase all other selections + if($sa['id']==-1) { + //reset the array + unset($awards); + $awards=array(); + $awards[]=$sa; + break; } + else { + if($sa['selected'] && in_array($sa['id'],$eligibleAwardsList)) { + $awards[]=$sa; + } + } + } + + $idx=0; + foreach($awards AS $sa) { + $qstr="INSERT INTO project_specialawards_link (award_awards_id,projects_id,conferences_id) VALUES ('".intval($sa['id'])."','".intval($data['project_id'])."','{$conference['id']}')"; + mysql_query($qstr); + $idx++; + //dont let them sign up for more than they are allowed to + if($idx>=$config['maxspecialawardsperproject']) + break; } }