forked from science-ation/science-ation
Added the necessary code for updating the grade category that a project belongs in whenever it or it's participants are modified.
This commit is contained in:
parent
1749d8c67b
commit
0c6f1c3b70
5
api.php
5
api.php
@ -1051,13 +1051,14 @@ switch($request[0]) {
|
|||||||
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':
|
||||||
if(!array_key_exists('registration_id', $_SESSION)){
|
$regId = getRegistrationsId($_SESSION['users_id']);
|
||||||
|
if(!$regId){
|
||||||
$ret['status'] = 'error';
|
$ret['status'] = 'error';
|
||||||
$ret['error'] = 'current user not associated with a project';
|
$ret['error'] = 'current user not associated with a project';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = removeProject($_SESSION['registration_id']);
|
$result = removeProject($regId);
|
||||||
if($result != 'ok'){
|
if($result != 'ok'){
|
||||||
$ret['status'] = "error";
|
$ret['status'] = "error";
|
||||||
$ret['error'] = $result;
|
$ret['error'] = $result;
|
||||||
|
@ -290,6 +290,21 @@ function project_load($pid)
|
|||||||
return $proj;
|
return $proj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getProjectCategory($registrations_id){
|
||||||
|
global $conference;
|
||||||
|
$q=mysql_query("SELECT MAX(grade) AS maxgrade FROM users WHERE registrations_id='$registrations_id'");
|
||||||
|
$gradeinfo=mysql_fetch_object($q);
|
||||||
|
$projectcategories_id = null;
|
||||||
|
//now lets grab all the age categories, so we can choose one based on the max grade
|
||||||
|
$q=mysql_query("SELECT * FROM projectcategories WHERE conferences_id='".$conference['id']."' ORDER BY id");
|
||||||
|
while(($r=mysql_fetch_object($q)) && $projectcategories_id === null)
|
||||||
|
{
|
||||||
|
if($gradeinfo->maxgrade >= $r->mingrade && $gradeinfo->maxgrade <= $r->maxgrade)
|
||||||
|
{
|
||||||
|
$projectcategories_id = $r->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $projectcategories_id;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
// legacy - functions previously included here have been split off into participants.inc.php,
|
// legacy - functions previously included here have been split off into participants.inc.php,
|
||||||
// but expected in this file by other code
|
// but expected in this file by other code
|
||||||
require_once("participant.inc.php");
|
require_once("participant.inc.php");
|
||||||
|
require_once("projects.inc.php");
|
||||||
|
|
||||||
function generateProjectNumber($registration_id)
|
function generateProjectNumber($registration_id)
|
||||||
{
|
{
|
||||||
@ -452,9 +453,11 @@ function getProject($userId){
|
|||||||
// add a project
|
// add a project
|
||||||
function addProject($registrations_id){
|
function addProject($registrations_id){
|
||||||
global $conference;
|
global $conference;
|
||||||
|
// get the appropriate category for this project
|
||||||
|
$projCategory = getProjectCategory($registrations_id);
|
||||||
mysql_query("
|
mysql_query("
|
||||||
INSERT INTO projects(registrations_id, conferences_id)
|
INSERT INTO projects(registrations_id, conferences_id, projectcategories_id)
|
||||||
VALUES ('" . $registrations_id . "','" . $conference['id']."')
|
VALUES ('" . $registrations_id . "','" . $conference['id']."', '$projCategory')
|
||||||
");
|
");
|
||||||
//now query the one we just inserted
|
//now query the one we just inserted
|
||||||
$q = mysql_query("SELECT * FROM projects WHERE registrations_id='$registrations_id' AND conferences_id='{$conference['id']}'");
|
$q = mysql_query("SELECT * FROM projects WHERE registrations_id='$registrations_id' AND conferences_id='{$conference['id']}'");
|
||||||
@ -476,7 +479,7 @@ function joinProject($registration_number, $email){
|
|||||||
return 'register_participants.inc.php::joinProject -> you are already registered for a project';
|
return 'register_participants.inc.php::joinProject -> you are already registered for a project';
|
||||||
}
|
}
|
||||||
|
|
||||||
// let's avoid an SQL naughtiness
|
// let's avoid any SQL naughtiness
|
||||||
$email = mysql_real_escape_string($email);
|
$email = mysql_real_escape_string($email);
|
||||||
$registration_number = intval($registration_number);
|
$registration_number = intval($registration_number);
|
||||||
|
|
||||||
@ -504,6 +507,16 @@ function joinProject($registration_number, $email){
|
|||||||
return "register_participants.inc.php::joinProject -> " . mysql_error();
|
return "register_participants.inc.php::joinProject -> " . mysql_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// finally, we can update the project's age category if necessary
|
||||||
|
$category = getProjectCategory($registration_id);
|
||||||
|
if($category !== null){
|
||||||
|
mysql_query("UPDATE projects SET projectcategories_id = $category WHERE registrations_id = $registration_id");
|
||||||
|
if(mysql_error()){
|
||||||
|
return "register_participants.inc.php::joinProject -> " . mysql_error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return 'ok';
|
return 'ok';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -869,7 +869,16 @@ function user_save(&$u)
|
|||||||
if(mysql_error() != '') return "SQLERR7: " . mysql_error();
|
if(mysql_error() != '') return "SQLERR7: " . mysql_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($u['orig']['grade'] != $u['grade'] && $u['registrations_id']){
|
||||||
|
// their grade has changed and they're connected to a registration. Let's update
|
||||||
|
// the registration's grade level to match if necessary
|
||||||
|
$category = getProjectCategory($u['registrations_id']);
|
||||||
|
if($category !== null){
|
||||||
|
mysql_query("UPDATE projects SET projectcategories_id = $category WHERE registrations_id = $registration_id");
|
||||||
|
if(mysql_error() != '') return "SQLERR8: " . mysql_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
/* Record all the data in orig that we saved so subsequent
|
/* Record all the data in orig that we saved so subsequent
|
||||||
* calls to user_save don't try to overwrite data already
|
* calls to user_save don't try to overwrite data already
|
||||||
* saved to the database */
|
* saved to the database */
|
||||||
|
Loading…
Reference in New Issue
Block a user