include "common.inc.php";
if($_SESSION['schoolid'] && $_SESSION['schoolaccesscode'])
{
send_header(i18n("School Participant Invitations"));
echo "<< ".i18n("Return to school access main page")."
";
echo "
";
$q=mysql_query("SELECT * FROM schools WHERE id='".$_SESSION['schoolid']."' AND accesscode='".$_SESSION['schoolaccesscode']."' AND year='".$config['FAIRYEAR']."'");
echo mysql_error();
$school=mysql_fetch_object($q);
if($school)
{
if($config['participant_registration_type']=="invite")
{
if($_POST['action']=="invite")
{
if($_POST['firstname'] && $_POST['lastname'] && $_POST['email'] && $_POST['grade'])
{
//make sure they arent already invited!
$q=mysql_query("SELECT firstname, lastname FROM students WHERE year='".$config['FAIRYEAR']."' AND email='".$_POST['email']."'");
if(mysql_num_rows($q))
{
echo error(i18n("That students email address has already been invited"));
}
else
{
$regnum=0;
//now create the new registration record, and assign a random/unique registration number to then.
do
{
//random number between
//100000 and 999999 (six digit integer)
$regnum=rand(100000,999999);
$q=mysql_query("SELECT * FROM registrations WHERE num='$regnum' AND year=".$config['FAIRYEAR']);
}while(mysql_num_rows($q)>0);
//actually insert it
mysql_query("INSERT INTO registrations (num,email,start,status,year) VALUES (".
"'$regnum',".
"'".$_POST['email']."',".
"NOW(),".
"'open',".
$config['FAIRYEAR'].
")");
$regid=mysql_insert_id();
mysql_query("INSERT INTO students (registrations_id,email,firstname,lastname,schools_id,grade,year) VALUES (
'$regid',
'".mysql_escape_string($_POST['email'])."',
'".mysql_escape_string($_POST['firstname'])."',
'".mysql_escape_string($_POST['lastname'])."',
'".mysql_escape_string($_SESSION['schoolid'])."',
'".mysql_escape_string($_POST['grade'])."',
'".$config['FAIRYEAR']."')");
email_send("new_participant",$_POST['email'],array("FAIRNAME"=>i18n($config['fairname'])),array("REGNUM"=>"$regnum"));
echo happy(i18n("The participant has been successfully invited"));
}
}
else
echo error(i18n("All fields are required for invitations"));
}
if($_GET['action']=="uninvite")
{
//first, make sure that this is really their student, and it sfor this year.
$q=mysql_query("SELECT * FROM students WHERE id='".$_GET['uninvite']."' AND year='".$config['FAIRYEAR']."' AND schools_id='".$_SESSION['schoolid']."'");
if(mysql_num_rows($q))
{
$r=mysql_fetch_object($q);
$registrations_id=$r->registrations_id;
if($registrations_id) //just to be safe!
{
mysql_query("DELETE FROM students WHERE registrations_id='$registrations_id'");
mysql_query("DELETE FROM projects WHERE registrations_id='$registrations_id'");
mysql_query("DELETE FROM mentors WHERE registrations_id='$registrations_id'");
mysql_query("DELETE FROM safety WHERE registrations_id='$registrations_id'");
mysql_query("DELETE FROM emergencycontact WHERE registrations_id='$registrations_id'");
mysql_query("DELETE FROM registrations WHERE id='$registrations_id'");
echo happy(i18n("Student successfully uninvited"));
}
}
else
echo error(i18n("Invalid student to uninvite"));
}
$q=mysql_query("SELECT (NOW()>'".$config['dates']['regopen']."' AND NOW()<'".$config['dates']['regclose']."') AS datecheck");
$datecheck=mysql_fetch_object($q);
$q=mysql_query("SELECT students.*,
registrations.num
FROM
students,
registrations
WHERE
students.schools_id='".$school->id."'
AND students.year='".$config['FAIRYEAR']."'
AND students.registrations_id=registrations.id
ORDER BY
lastname,
firstname");
if($datecheck!=0)
$currentinvited=mysql_num_rows($q);
{
echo i18n("In order for your school's students to register for the fair, you will need to invite them to register. Simply enter their email address below to invite them to register. Important: for group projects, only add one of the participants, that participant will then add the other group member(s) to the project");
echo "
";
echo "
";
$okaygrades=array();
if($school->projectlimitper=="total")
{
if($school->projectlimit)
{
echo i18n("You have invited %1 of %2 total projects for your school",array($currentinvited,$school->projectlimit));
if($currenteinvited<$school->projectlimit)
{
for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
$okaygrades[]=$a;
}
}
else
{
echo i18n("You have invited %1 project(s) for your school",array($currentinvited,$school->projectlimit));
for($a=$config['mingrade'];$a<=$config['maxgrade'];$a++)
$okaygrades[]=$a;
}
}
else if($school->projectlimitper=="agecategory")
{
echo "
";
$catq=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($catr=mysql_fetch_object($catq))
{
$q2=mysql_query("SELECT COUNT(students.id) AS num
FROM
students,
registrations
WHERE
students.schools_id='".$school->id."'
AND students.grade>='$catr->mingrade'
AND students.grade<='$catr->maxgrade'
AND students.year='".$config['FAIRYEAR']."'
AND students.registrations_id=registrations.id
");
echo mysql_error();
$r2=mysql_fetch_object($q2);
$currentinvited=$r2->num;
if($currentinvited<$school->projectlimit)
{
for($a=$catr->mingrade;$a<=$catr->maxgrade;$a++)
$okaygrades[]=$a;
}
echo i18n("You have invited %1 of %2 total projects for for the %3 age category",array($currentinvited,$school->projectlimit,i18n($catr->category)));
echo "
";
}
}
echo "
";
if(count($okaygrades))
{
echo "
".i18n("Last Name")." | ".i18n("First Name")." | "; echo "".i18n("Email Address")." | "; echo "".i18n("Grade")." | "; echo "".i18n("Registration Number")." | "; echo "".i18n("Actions")." |
---|---|---|---|---|---|
$r->lastname | $r->firstname | "; echo "$r->email | "; echo "$r->grade | "; echo "$r->num | "; echo ""; echo "id\">"; echo " | "; echo "