science-ation/register_participants_students.php

232 lines
8.4 KiB
PHP
Raw Normal View History

<?
require("common.inc.php");
//authenticate based on email address and registration number from the SESSION
if(!$_SESSION['email'])
{
header("Location: register_participants.php");
exit;
}
if(! ($_SESSION['registration_number'] && $_SESSION['registration_id']))
{
header("Location: register_participants.php");
exit;
}
$q=mysql_query("SELECT registrations.id AS regid, students.id AS studentid, students.firstname FROM registrations,students ".
"WHERE students.email='".$_SESSION['email']."' ".
"AND registrations.num='".$_SESSION['registration_number']."' ".
"AND registrations.id='".$_SESSION['registration_id']."' ".
"AND students.registrations_id=registrations.id ".
"AND registrations.year=".$config['FAIRYEAR']." ".
"AND students.year=".$config['FAIRYEAR']);
echo mysql_error();
if(mysql_num_rows($q)==0)
{
header("Location: register_participants.php");
exit;
}
$r=mysql_fetch_object($q);
send_header("Participant Registration - Student Information");
echo "<a href=\"register_participants_main.php\">&lt;&lt; ".i18n("Back to Participant Registration Summary")."</a><br />";
echo "<br />";
//now do any data saves
if($_POST['action']=="save")
{
$x=1;
while($_POST["num"][$x])
{
//FIXME: move required field checking up here
if($_POST['id'][$x]==0)
{
//INSERT new record
//FIXME: check for required fields before allowing INSERT
$dob=$_POST['year'][$x]."-".$_POST['month'][$x]."-".$_POST['day'][$x];
mysql_query("INSERT INTO students (registrations_id,firstname,lastname,email,address,city,province,postalcode,phone,dateofbirth,grade,year) VALUES (".
"'".$_SESSION['registration_id']."', ".
"'".mysql_escape_string(stripslashes($_POST['firstname'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['lastname'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['email'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['address'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['city'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['province'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['postalcode'][$x]))."', ".
"'".mysql_escape_string(stripslashes($_POST['phone'][$x]))."', ".
"'$dob', ".
"'".mysql_escape_string(stripslashes($_POST['grade'][$x]))."', ".
"'".$config['FAIRYEAR']."')");
echo mysql_error();
echo notice(i18n("%1 %2 successfully added",array($_POST['firstname'][$x],$_POST['lastname'][$x])));
}
else
{
//UPDATE existing record
//FIXME: check for required fields before allowing UPDATE
$dob=$_POST['year'][$x]."-".$_POST['month'][$x]."-".$_POST['day'][$x];
mysql_query("UPDATE students SET ".
"firstname='".mysql_escape_string(stripslashes($_POST['firstname'][$x]))."', ".
"lastname='".mysql_escape_string(stripslashes($_POST['lastname'][$x]))."', ".
"email='".mysql_escape_string(stripslashes($_POST['email'][$x]))."', ".
"address='".mysql_escape_string(stripslashes($_POST['address'][$x]))."', ".
"city='".mysql_escape_string(stripslashes($_POST['city'][$x]))."', ".
"province='".mysql_escape_string(stripslashes($_POST['province'][$x]))."', ".
"postalcode='".mysql_escape_string(stripslashes($_POST['postalcode'][$x]))."', ".
"phone='".mysql_escape_string(stripslashes($_POST['phone'][$x]))."', ".
"dateofbirth='$dob', ".
"grade='".mysql_escape_string(stripslashes($_POST['grade'][$x]))."' ".
"WHERE id='".$_POST['id'][$x]."'");
echo notice(i18n("%1 %2 successfully updated",array($_POST['firstname'][$x],$_POST['lastname'][$x])));
}
$x++;
}
}
//now query and display
$q=mysql_query("SELECT * FROM students WHERE registrations_id='".$_SESSION['registration_id']."' AND year='".$config['FAIRYEAR']."'");
if(mysql_num_rows($q)==0)
{
//uhh oh, we didnt find any, this isnt possible! lets insert one using the logged in persons email address
//although... this can never really happen, since the above queries only allow the page to view if the student
//is found in the students table... soo... well, lets leave it here as a fallback anyways, just incase
mysql_query("INSERT INTO students (registrations_id,email,year) VALUES ('".$_SESSION['registration_id']."','".mysql_escape_string($_SESSION['email'])."','".$config['FAIRYEAR']."')");
//if we just inserted it, then we will obviously find 1
$numfound=1;
}
else
{
$numfound=mysql_num_rows($q);
}
if($_GET['numstudents'])
$numtoshow=$_GET['numstudents'];
else
$numtoshow=$numfound;
echo "<form name=\"numstudentsform\" method=\"get\" action=\"register_participants_students.php\">";
echo i18n("Number of students that worked on the project: ");
echo "<select name=\"numstudents\" onchange=\"document.forms.numstudentsform.submit()\">\n";
for($x=$config['minstudentsperproject'];$x<=$config['maxstudentsperproject'];$x++)
{
if($numtoshow==$x) $selected="selected=\"selected\""; else $selected="";
echo "<option $selected value=\"$x\">$x</option>\n";
}
echo "</select>";
echo "</form>";
echo "<form name=\"studentdata\" method=\"post\" action=\"register_participants_students.php\">";
echo "<input type=\"hidden\" name=\"action\" value=\"save\">";
for($x=1;$x<=$numtoshow;$x++)
{
$studentinfo=mysql_fetch_object($q);
echo "<h3>".i18n("Student %1 Details",array($x))."</h3>";
//if we have a valid student, set their ID, so we can UPDATE when we submit
//if there is no record for this student, then set the ID to 0, so we will INSERT when we submit
if($studentinfo->id) $id=$studentinfo->id; else $id=0;
//true should work here, it just has to be set to _something_ for it to work.
echo "<input type=\"hidden\" name=\"num[$x]\" value=\"true\">";
//save the ID, or 0 if it doesnt exist
echo "<input type=\"hidden\" name=\"id[$x]\" value=\"$id\">";
echo "<table>";
echo "<tr>\n";
echo " <td>".i18n("First Name")."</td><td><input type=\"text\" name=\"firstname[$x]\" value=\"$studentinfo->firstname\"></td>\n";
echo " <td>".i18n("Last Name")."</td><td><input type=\"text\" name=\"lastname[$x]\" value=\"$studentinfo->lastname\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td>".i18n("Email Address")."</td><td><input type=\"text\" name=\"email[$x]\" value=\"$studentinfo->email\"></td>\n";
echo " <td>".i18n("Province")."</td><td><input type=\"text\" name=\"province[$x]\" value=\"$studentinfo->province\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td>".i18n("Address")."</td><td><input type=\"text\" name=\"address[$x]\" value=\"$studentinfo->address\"></td>\n";
echo " <td>".i18n("City")."</td><td><input type=\"text\" name=\"city[$x]\" value=\"$studentinfo->city\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td>".i18n("Postal Code")."</td><td><input type=\"text\" name=\"postalcode[$x]\" value=\"$studentinfo->postalcode\"></td>\n";
echo " <td>".i18n("Phone")."</td><td><input type=\"text\" name=\"phone[$x]\" value=\"$studentinfo->phone\"></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo " <td>".i18n("Date of Birth")."</td><td>\n";
list($year,$month,$day)=split("-",$studentinfo->dateofbirth);
echo "<table><tr><td>";
emit_day_selector("day[$x]",$day);
echo "</td><td>\n";
emit_month_selector("month[$x]",$month);
echo "</td><td>\n";
emit_year_selector("year[$x]",$year,date("Y")-19,date("Y")-10);
echo "</td></tr></table>\n";
echo " </td>\n";
echo " <td>".i18n("Grade")."</td><td>\n";
echo "<select name=\"grade[$x]\">\n";
echo "<option value=\"\">".i18n("Choose Grade")."</option>\n";
for($gr=$config['mingrade'];$gr<=$config['maxgrade'];$gr++)
{
if($studentinfo->grade==$gr) $sel="selected=\"selected\""; else $sel="";
echo "<option $sel value=\"$gr\">$gr</option>\n";
}
echo "</select>\n";
echo " </td>";
echo "</tr>";
/*
</td>
</tr>
<tr>
<td align=right><? echo i18n("tshirtsize"); ?></td>
<td><select name=tshirt1>
<option value="small"><? echo i18n("small"); ?></option>
<option value="medium"><? echo i18n("medium"); ?></option>
<option value="large"><? echo i18n("large"); ?></option>
<option value="xlarge"><? echo i18n("xlarge"); ?></option>
</select>
</td>
<td align=right><? echo i18n("emailaddress"); ?></td>
<td><input type=text name=emailaddress1></td>
</tr>
</table>
echo "<tr><td>".i18n("Name").": </td><td><input type=\"text\" name=\"name$x\" value=\"$studentinfo->name\"></td></tr>";
*/
echo "</table>";
echo "<br />";
echo "<br />";
}
echo "<input type=submit value=\"".i18n("Save Student Information")."\">\n";
echo "</form>";
send_footer();
?>