forked from science-ation/science-ation
c995e226c7
Update registration_statistics Update registration_receivedforms Update student_editor
396 lines
12 KiB
PHP
396 lines
12 KiB
PHP
<?
|
|
/*
|
|
This file is part of the 'Science Fair In A Box' project
|
|
SFIAB Website: http://www.sfiab.ca
|
|
|
|
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
|
|
Copyright (C) 2005 James Grant <james@lightbox.org>
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public
|
|
License as published by the Free Software Foundation, version 2.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; see the file COPYING. If not, write to
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA.
|
|
*/
|
|
?>
|
|
<?
|
|
require_once('register_participants.inc.php');
|
|
require_once('user.inc.php');
|
|
function registrationFormsReceived($reg_id="")
|
|
{
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
$q=mysql_query("SELECT status FROM registrations WHERE id='$rid'");
|
|
$r=mysql_fetch_object($q);
|
|
if($r->status=="complete" || $r->status=="paymentpending")
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
function registrationDeadlinePassed()
|
|
{
|
|
global $config;
|
|
$q=mysql_query("SELECT (NOW()<'".$config['dates']['regclose']."') AS datecheck");
|
|
$datecheck=mysql_fetch_object($q);
|
|
if($datecheck->datecheck==1)
|
|
return false;
|
|
else
|
|
return true;
|
|
|
|
}
|
|
|
|
function studentIndividualStatus($userid) {
|
|
global $config, $conference;
|
|
global $prependdir;
|
|
$required_fields=user_fields_required('participant');
|
|
$required_fields[]="grade";
|
|
|
|
if($config['participant_student_tshirt']=="yes")
|
|
$required_fields[]="tshirt";
|
|
|
|
$q=mysql_query("SELECT * FROM users WHERE id='{$userid}' AND conferences_id='{$conference['id']}'");
|
|
$r=mysql_fetch_object($q);
|
|
|
|
foreach ($required_fields AS $req) {
|
|
if($req=="birthdate") {
|
|
if($r->$req=="0000-00-00" || !$r->$req)
|
|
return "incomplete";
|
|
}
|
|
else {
|
|
if(!$r->$req) {
|
|
$fp=fopen($prependdir."data/logs/incomplete.log","a+");
|
|
$str="user id $userid ($r->firstname $r->lastname) incomplete on required field: $req, user[$req]='{$r->$req}'\n";
|
|
// echo $str;
|
|
fputs($fp,$str);
|
|
fclose($fp);
|
|
return "incomplete";
|
|
}
|
|
}
|
|
}
|
|
return 'complete';
|
|
}
|
|
|
|
function studentsStatus($reg_id="") {
|
|
global $config, $conference;
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
//get the num students from the registrations table
|
|
$q=mysql_query("SELECT numstudents FROM registrations WHERE id='$rid'");
|
|
$r=mysql_fetch_object($q);
|
|
$numstudents=$r->numstudents;
|
|
|
|
//select all the users currently with this registration id
|
|
$q=mysql_query("SELECT id FROM users WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
|
|
|
|
//if we don't have what we said we were gonna have, return incomplete
|
|
if($numstudents!=mysql_num_rows($q))
|
|
return "incomplete";
|
|
|
|
//if we dont have the minimum, return incomplete
|
|
if(mysql_num_rows($q)<$config['minstudentsperproject'])
|
|
return "incomplete";
|
|
|
|
while($r=mysql_fetch_object($q)) {
|
|
//if any one of them is incomplete, then the overall status is incomplete
|
|
if(studentIndividualStatus($r->id)=='incomplete')
|
|
return 'incomplete';
|
|
}
|
|
//if it made it through without returning incomplete, then we must be complete
|
|
return "complete";
|
|
}
|
|
|
|
function emergencycontactStatus($reg_id="")
|
|
{
|
|
global $conference;
|
|
$required_fields=array("firstname","lastname","relation","phone1");
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
$sq=mysql_query("SELECT id FROM users WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
|
|
$returnval = 'complete';
|
|
$fields = array('firstname', 'lastname', 'relation', 'phone1', 'phone2', 'phone3', 'phone4', 'email');
|
|
while($sr=mysql_fetch_object($sq)) {
|
|
$q = mysql_query("SELECT " . implode(',', $fields) . " FROM emergencycontact WHERE users_id = $sr->id ORDER BY id");
|
|
if(!mysql_num_rows($q)) {
|
|
$returnval = 'incomplete';
|
|
break;
|
|
}
|
|
$oneValid = false;
|
|
while($contact=mysql_fetch_assoc($q)) {
|
|
$valid = true;
|
|
foreach($required_fields AS $req){
|
|
if(!$contact[$req]) $valid = false;
|
|
break;
|
|
}
|
|
$oneValid |= $valid;
|
|
}
|
|
if(!$oneValid){
|
|
$returval = 'incomplete';
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $returnval;
|
|
}
|
|
|
|
function projectStatus($reg_id="")
|
|
{
|
|
global $config, $conference;
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
$required_fields=array("title","projectcategories_id","projectdivisions_id","language","summarycountok");
|
|
|
|
if($config['participant_short_title_enable'] == 'yes')
|
|
$required_fields[] = 'shorttitle';
|
|
if($config['participant_project_summary_wordmin'] > 0)
|
|
$required_fields[] = 'summary';
|
|
if($config['participant_project_table'] == 'yes')
|
|
$requiredFields[] = 'req_table';
|
|
if($config['participant_project_electricity'] == 'yes')
|
|
$requiredFields[] = 'req_electricity';
|
|
|
|
|
|
$q=mysql_query("SELECT * FROM projects WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
|
|
|
|
//if we dont have a project entry yet, return empty
|
|
if(!mysql_num_rows($q))
|
|
return "empty";
|
|
|
|
while($r=mysql_fetch_object($q)) {
|
|
foreach ($required_fields AS $req) {
|
|
if(!$r->$req) {
|
|
return "incomplete";
|
|
}
|
|
}
|
|
}
|
|
|
|
//if it made it through without returning incomplete, then we must be complete
|
|
return "complete";
|
|
}
|
|
|
|
|
|
function mentorStatus($reg_id="")
|
|
{
|
|
global $config, $conference;
|
|
|
|
if($config['participant_mentor']=="no")
|
|
return "notapplicable";
|
|
|
|
$required_fields=array("firstname","lastname","phone","email","organization","description");
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
//first check the registrations table to see if 'nummentors' is set, or if its null
|
|
$q=mysql_query("SELECT nummentors FROM registrations WHERE id='$rid' AND conferences_id='".$conference['id']."'");
|
|
$r=mysql_fetch_object($q);
|
|
if($r->nummentors==null)
|
|
return "incomplete";
|
|
|
|
//grab all the mentors for this registration
|
|
$q=mysql_query("SELECT * FROM mentors WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
|
|
|
|
//if we dont have the minimum, return incomplete
|
|
if(mysql_num_rows($q)<$config['minmentorserproject'])
|
|
return "incomplete";
|
|
|
|
//and if we have less than they say we're gonna have, we're also incomplete
|
|
if(mysql_num_rows($q)<$r->nummentors)
|
|
return "incomplete";
|
|
|
|
while($r=mysql_fetch_object($q)) {
|
|
foreach ($required_fields AS $req) {
|
|
if(!$r->$req) {
|
|
return "incomplete";
|
|
}
|
|
}
|
|
}
|
|
//if it made it through without returning incomplete, then we must be complete
|
|
return "complete";
|
|
}
|
|
|
|
function safetyStatus($reg_id="")
|
|
{
|
|
global $conference;
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
//grab all of their answers
|
|
$q=mysql_query("SELECT * FROM safety WHERE registrations_id='$rid'");
|
|
$safetyanswers=array();
|
|
while($r=mysql_fetch_object($q)) {
|
|
$safetyanswers[$r->safetyquestions_id]=$r->answer;
|
|
}
|
|
|
|
//now grab all the questions
|
|
$q=mysql_query("SELECT * FROM safetyquestions WHERE conferences_id='".$conference['id']."' ORDER BY ord");
|
|
while($r=mysql_fetch_object($q)) {
|
|
if($r->required=="yes" && !$safetyanswers[$r->id]) {
|
|
return "incomplete";
|
|
}
|
|
}
|
|
return "complete";
|
|
}
|
|
|
|
function spawardStatus($reg_id="")
|
|
{
|
|
global $conference;
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
$q=mysql_query("SELECT * FROM projects WHERE registrations_id='$rid'");
|
|
$project=mysql_fetch_object($q);
|
|
|
|
/* We want this query to get any awards with a NULL award_awards_id */
|
|
$awardsq=mysql_query("SELECT
|
|
projects.id AS projects_id
|
|
FROM
|
|
project_specialawards_link,
|
|
projects
|
|
WHERE
|
|
project_specialawards_link.projects_id='".$project->id."'
|
|
AND projects.conferences_id='".$conference['id']."'
|
|
");
|
|
|
|
//this also catches the -1 award for "i dont want special awards"
|
|
//if there's no rows it means they havent signed up
|
|
//if there's at least one row, they signed up for at leaset one award, OR they choose ' id ont want specail awards'
|
|
if(mysql_num_rows($awardsq))
|
|
return "complete";
|
|
else
|
|
return "incomplete";
|
|
}
|
|
|
|
function tourStatus($reg_id="")
|
|
{
|
|
/************************************************************************
|
|
FIXME
|
|
This function depends on the tours_choice table, which currently links to the students table.
|
|
tours_choice needs to be updated to link to users.id instead (and the conferences_id column
|
|
can be dropped after all).
|
|
It's not getting used this year anyway, so meh.
|
|
The next line here should then be removed, and the code modified accordingly.
|
|
************************************************************************/
|
|
return 'notapplicable'; // delete me
|
|
|
|
|
|
global $config, $conference;
|
|
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
|
|
/* Get the students for this project */
|
|
$q=mysql_query("SELECT * FROM students WHERE registrations_id='$rid' AND conferences_id='".$conference['id']."'");
|
|
$num_found = mysql_num_rows($q);
|
|
|
|
$ret = "complete";
|
|
while($s=mysql_fetch_object($q)) {
|
|
//grab all of their tour prefs
|
|
$sid = $s->id;
|
|
$qq=mysql_query("SELECT * FROM tours_choice WHERE students_id='$sid' and conferences_id='{$conference['id']}' ORDER BY rank");
|
|
|
|
$n_tours = mysql_num_rows($qq);
|
|
if($n_tours > 0) {
|
|
/* See if there's a rank 0 tour (rank 0 == their tour assignment) */
|
|
$i = mysql_fetch_object($qq);
|
|
if($i->rank == 0) {
|
|
/* Yes, there is, no matter what, this student's tour
|
|
* selection is complete. */
|
|
continue;
|
|
}
|
|
}
|
|
|
|
/* Else, they haven't been assigned a tour, see if they've made
|
|
* the appropraite selection(s) */
|
|
if( ($n_tours >= $config['tours_choices_min']) && ($n_tours <= $config['tours_choices_max']) ){
|
|
continue;
|
|
}
|
|
$ret = "incomplete";
|
|
break;
|
|
}
|
|
return $ret;
|
|
}
|
|
|
|
function namecheckStatus($reg_id="")
|
|
{
|
|
global $conference;
|
|
if($reg_id) $rid=$reg_id;
|
|
else $rid=$_SESSION['registration_id'];
|
|
$q = mysql_query("SELECT namecheck_complete FROM users WHERE registrations_id = $rid AND conferences_id = '{$conference['id']}'");
|
|
|
|
while($s=mysql_fetch_object($q)) {
|
|
if($s->namecheck_complete == 'no') {
|
|
return 'incomplete';
|
|
}
|
|
}
|
|
return 'complete';
|
|
}
|
|
|
|
function participant_status_completion_details($u,$regId=null){
|
|
if($regId) {
|
|
//just use it
|
|
}else {
|
|
//we onlty have the user object, so get the regId from that
|
|
$p = getProject($u['id']);
|
|
$regId = $p['registrations_id'];
|
|
}
|
|
if(!$regId){
|
|
return array(
|
|
'namecheck' => 'incomplete',
|
|
'students' => 'incomplete',
|
|
'tour' => 'incomplete',
|
|
'spaward' => 'incomplete',
|
|
'safety' => 'incomplete',
|
|
'mentor' => 'incomplete',
|
|
'project' => 'incomplete',
|
|
'emergencycontact' => 'incomplete',
|
|
);
|
|
}
|
|
return array(
|
|
'namecheck' => namecheckStatus($regId),
|
|
'students' => studentsStatus($regId),
|
|
'tour' => tourStatus($regId),
|
|
'spaward' => spawardStatus($regId),
|
|
'safety' => safetyStatus($regId),
|
|
'mentor' => mentorStatus($regId),
|
|
'project' => projectStatus($regId),
|
|
'emergencycontact' => emergencycontactStatus($regId),
|
|
);
|
|
}
|
|
|
|
function participant_status_update(&$u){
|
|
//for the 'role' participant to be complete, all we need is that ONE CURRENT students personal details to be complete
|
|
//this doesnt mean that their registration is complete though.
|
|
$complete=studentIndividualStatus($u['id']);
|
|
$u['roles']['participant']['complete'] = $complete;
|
|
return $complete;
|
|
}
|
|
|
|
/*
|
|
function participantregistration_status_update(&$u) {
|
|
$status = participant_status_completion_details($u);
|
|
$overall = 'complete';
|
|
foreach($status as $key => $val){
|
|
if($val != 'complete'){
|
|
$overall = 'incomplete';
|
|
}
|
|
}
|
|
return $overall;
|
|
}
|
|
*/
|