Fix a bug in loading users (cant call user_load() within any function that is called within user_load itself, like all the individual page checks -- in this case, emergencycontactStatus()

Add special awards display to project/view
Add special awards saving to project/edit
This commit is contained in:
james 2011-03-03 04:24:21 +00:00
parent b9fbc56372
commit 26e4204015
5 changed files with 50 additions and 18 deletions

View File

@ -1056,8 +1056,9 @@ switch($request[0]) {
/* APIDOC: project/view /* APIDOC: project/view
description(Displays the current project information) description(Displays the current project information)
return(project array) return(project array)
object(project: {project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text,safetyquestions array of question}) object(project: {project_id integer, projectdivisions_id integer, title varchar(255), language char(2), req_electricity enum('no', 'yes'), req_table enum('no', 'yes'), req_special varchar(128), summary text,safetyquestions array of question, specialawards array of specialaward})
object(question: {id,question,type,required,ord,answer}) object(question: {id,question,type,required,ord,answer})
object(specialaward: {id,name,criteria,self_nominate,selected})
*/ */
case 'view': case 'view':
if($u=user_load($_SESSION['users_id'])) { if($u=user_load($_SESSION['users_id'])) {
@ -1081,6 +1082,7 @@ switch($request[0]) {
description(Edit an existing project. "language" notes the language a participant wishes to be judged in. "req_electricity" notes whethor or not the project requires an electrical outlet. "req_table" states whether or not the project needs a table. "req_special" is a field for special requirements.) description(Edit an existing project. "language" notes the language a participant wishes to be judged in. "req_electricity" notes whethor or not the project requires an electrical outlet. "req_table" states whether or not the project needs a table. "req_special" is a field for special requirements.)
object(project: as per project/view) object(project: as per project/view)
object(question: for sake of not re-transmitting all the safetyquestion text, the only fields required to save are {id,answer}) object(question: for sake of not re-transmitting all the safetyquestion text, the only fields required to save are {id,answer})
object(specialaward: for sake of not re-transmitting all the specialaward text, the only fields required to save are {id,selected})
return(project array) return(project array)
*/ */
case 'edit': case 'edit':

View File

@ -104,16 +104,17 @@ function emergencycontactStatus($reg_id="")
$sq=mysql_query("SELECT id FROM users WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'"); $sq=mysql_query("SELECT id FROM users WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
$returnval = 'complete'; $returnval = 'complete';
$fields = array('firstname', 'lastname', 'relation', 'phone1', 'phone2', 'phone3', 'phone4', 'email');
while($sr=mysql_fetch_object($sq)) { while($sr=mysql_fetch_object($sq)) {
$u = user_load($sr->id); $q = mysql_query("SELECT " . implode(',', $fields) . " FROM emergencycontact WHERE users_id = $sr->id ORDER BY id");
if(!array_key_exists('emergencycontacts', $u)){ if(!mysql_num_rows($q)) {
$returnval = 'incomplete'; $returnval = 'incomplete';
break; break;
} }
$oneValid = false; $oneValid = false;
foreach($u['emergencycontacts'] as $contact){ while($contact=mysql_fetch_assoc($q)) {
$valid = true; $valid = true;
foreach($rquired_fields AS $req){ foreach($required_fields AS $req){
if(!$contact[$req]) $valid = false; if(!$contact[$req]) $valid = false;
break; break;
} }
@ -151,10 +152,8 @@ function projectStatus($reg_id="")
if(!mysql_num_rows($q)) if(!mysql_num_rows($q))
return "empty"; return "empty";
while($r=mysql_fetch_object($q)) while($r=mysql_fetch_object($q)) {
{ foreach ($required_fields AS $req) {
foreach ($required_fields AS $req)
{
if(!$r->$req) { if(!$r->$req) {
return "incomplete"; return "incomplete";
} }

View File

@ -319,18 +319,19 @@ function getProjectId($registrations_id){
function getAwardListing($project_id){ function getAwardListing($project_id){
$returnval = array(); $returnval = array();
$eligibleAwards = getSpecialAwardsEligibleForProject($projectId); $eligibleAwards = getSpecialAwardsEligibleForProject($project_id);
$nominatedawards = getSpecialAwardsNominatedForProject($projectId); $nominatedawards = getSpecialAwardsNominatedForProject($project_id);
$nominatedawards_list=array(); $nominatedawards_list=array();
foreach($nominatedawards AS $naward){ foreach($nominatedawards AS $naward){
$nominatedawards_list[] = $naward['id']; $nominatedawards_list[] = $naward['id'];
} }
$idx = 0;
foreach($eligibleAwards AS $eaward){ foreach($eligibleAwards AS $eaward){
$returnval[$idx] = $eaward; if(in_array($eaward['id'],$nominatedawards_list))
if(in_array($eaward['id'],$nominatedawards_list)) $returnval[$idx]['selected'] = true; $eaward['selected']=true;
$idx++; else
$eaward['selected']=false;
$returnval[] = $eaward;
} }
return $returnval; return $returnval;
} }

View File

@ -334,6 +334,23 @@ function saveProjectData($data){
} }
} }
//and update the special award nominations
//but make sure they dont sign up for anything they're not allowed to :p
if(is_array($data['specialawards'])) {
$eligibleAwards = getSpecialAwardsEligibleForProject($data['project_id']);
$eligibleAwardsList=array();
foreach($eligibleAwards AS $ea) {
$eligibleAwardsList[]=$ea['id'];
}
mysql_query("DELETE FROM projects_specialawards_link WHERE projects_id='{$data['projects_id']}' AND conferences_id='{$conference['id']}'");
foreach($data['specialawards'] AS $sa) {
if($sa['selected']==true) {
mysql_query("INSERT INTO projects_specialawards_link (award_awards_id,projects_id,conferences_id) VALUES ('".intval($sa['id'])."','".intval($data['projects_id'])."','{$conference['id']}')");
}
}
}
if($message == ''){ if($message == ''){
$message = 'success'; $message = 'success';
} }
@ -499,6 +516,10 @@ function getProject($userId){
$safetyquestions=getSafetyQuestions($regId); $safetyquestions=getSafetyQuestions($regId);
$returnval['safetyquestions']=$safetyquestions; $returnval['safetyquestions']=$safetyquestions;
$specialawards=getAwardListing($returnval['id']);
$returnval['specialawards']=$specialawards;
return $returnval; return $returnval;
} }

View File

@ -39,11 +39,11 @@ if(array_key_exists('join', $_GET)){
// this is a request to join this conference // this is a request to join this conference
// get the corresponding account id to go with this user id // get the corresponding account id to go with this user id
if($edit_id == null){ if(!$edit_id) {
// this will happen if they have no user record // this will happen if they have no user record
$edit_accounts_id = $_SESSION['accounts_id']; $edit_accounts_id = $_SESSION['accounts_id'];
}else{ }else{
$q = mysql_query("SELECT accounts_id FROM users WHERE id=$edit_id"); $q = mysql_query("SELECT accounts_id FROM users WHERE id='$edit_id'");
if(!$q){ if(!$q){
echo mysql_error(); echo mysql_error();
exit(); exit();
@ -62,6 +62,11 @@ if(array_key_exists('join', $_GET)){
user_save($u); user_save($u);
$edit_id = $u['id']; $edit_id = $u['id'];
} }
else {
$u=user_load_by_accounts_id($edit_accounts_id);
$edit_id=$u['id'];
//echo "we have {$data[0]} users already";
}
}else{ }else{
$joinConference = false; $joinConference = false;
if($edit_id == ''){ if($edit_id == ''){
@ -87,6 +92,10 @@ if(array_key_exists('join', $_GET)){
require_once("user_edit_tabs.inc.php"); require_once("user_edit_tabs.inc.php");
$u = user_load($edit_id); $u = user_load($edit_id);
if(!$u) {
echo "Could not load user id $edit_id";
exit;
}
$types = array_keys($u['roles']); $types = array_keys($u['roles']);
$selected = $_GET['tab']; $selected = $_GET['tab'];
if(!array_key_exists($selected, $tabs)) { if(!array_key_exists($selected, $tabs)) {