forked from science-ation/science-ation
- Server-side prettying
This commit is contained in:
parent
b7a30542d9
commit
a5246f74e3
@ -152,7 +152,7 @@ function award_upload_update_school(&$mysql_query, &$school, $school_id = -1)
|
|||||||
return $sid;
|
return $sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
function award_upload_school(&$student, &$school, $year)
|
function award_upload_school(&$student, &$school, $year, &$response)
|
||||||
{
|
{
|
||||||
|
|
||||||
$school_name = mysql_real_escape_string($school['schoolname']);
|
$school_name = mysql_real_escape_string($school['schoolname']);
|
||||||
@ -177,13 +177,14 @@ function award_upload_school(&$student, &$school, $year)
|
|||||||
$q = mysql_query("SELECT * FROM schools WHERE school='$school_name' AND city='$student_city' AND year='$year'");
|
$q = mysql_query("SELECT * FROM schools WHERE school='$school_name' AND city='$student_city' AND year='$year'");
|
||||||
if(mysql_num_rows($q) == 1) return award_upload_update_school($q, $school);
|
if(mysql_num_rows($q) == 1) return award_upload_update_school($q, $school);
|
||||||
|
|
||||||
|
$response['notice'][] = " - Creating new school: $school_name";
|
||||||
/* No? ok, make a new school */
|
/* No? ok, make a new school */
|
||||||
mysql_query("INSERT INTO schools(`school`,`year`) VALUES ('".mysql_real_escape_string($school['schoolname'])."','$year')");
|
mysql_query("INSERT INTO schools(`school`,`year`) VALUES ('".mysql_real_escape_string($school['schoolname'])."','$year')");
|
||||||
$school_id = mysql_insert_id();
|
$school_id = mysql_insert_id();
|
||||||
return award_upload_update_school($q, $school, $school_id);
|
return award_upload_update_school($q, $school, $school_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function award_upload_assign(&$fair, &$prize, &$project, $year)
|
function award_upload_assign(&$fair, &$prize, &$project, $year, &$response)
|
||||||
{
|
{
|
||||||
/* Copied from admin/award_upload.php, this is the
|
/* Copied from admin/award_upload.php, this is the
|
||||||
* transport name => sql name mapping */
|
* transport name => sql name mapping */
|
||||||
@ -208,10 +209,11 @@ function award_upload_assign(&$fair, &$prize, &$project, $year)
|
|||||||
echo mysql_error();
|
echo mysql_error();
|
||||||
if(mysql_num_rows($q) == 1) {
|
if(mysql_num_rows($q) == 1) {
|
||||||
$our_project = mysql_fetch_assoc($q);
|
$our_project = mysql_fetch_assoc($q);
|
||||||
echo "Found existing project";
|
|
||||||
$registrations_id = $our_project['registrations_id'];
|
$registrations_id = $our_project['registrations_id'];
|
||||||
$pid = $our_project['id'];
|
$pid = $our_project['id'];
|
||||||
|
$response['notice'][] = " - Found existing project: {$project['title']}";
|
||||||
} else {
|
} else {
|
||||||
|
$response['notice'][] = " - Creating new project: {$project['title']}";
|
||||||
/* Create a registration */
|
/* Create a registration */
|
||||||
$regnum=0;
|
$regnum=0;
|
||||||
//now create the new registration record, and assign a random/unique registration number to then.
|
//now create the new registration record, and assign a random/unique registration number to then.
|
||||||
@ -247,7 +249,9 @@ function award_upload_assign(&$fair, &$prize, &$project, $year)
|
|||||||
/* Add new */
|
/* Add new */
|
||||||
foreach($project['students'] as &$student) {
|
foreach($project['students'] as &$student) {
|
||||||
|
|
||||||
$schools_id = award_upload_school($student, $student['school'], $year);
|
$response['notice'][] = " - Student {$student['firstname']} {$student['lastname']} saved";
|
||||||
|
|
||||||
|
$schools_id = award_upload_school($student, $student['school'], $year, $response);
|
||||||
|
|
||||||
$keys = ",`".join("`,`", array_values($student_fields))."`";
|
$keys = ",`".join("`,`", array_values($student_fields))."`";
|
||||||
$values = "";
|
$values = "";
|
||||||
@ -279,11 +283,14 @@ function handle_award_upload(&$u, &$fair, &$data, &$response)
|
|||||||
$award = mysql_fetch_assoc($q);
|
$award = mysql_fetch_assoc($q);
|
||||||
$aaid = $award['id'];
|
$aaid = $award['id'];
|
||||||
|
|
||||||
|
$response['notice'][] = "Found award: {$award['name']}";
|
||||||
|
|
||||||
/* Load prizes, we fetched the right award by year, so we don't need to
|
/* Load prizes, we fetched the right award by year, so we don't need to
|
||||||
* check the year as long as we query by aaid */
|
* check the year as long as we query by aaid */
|
||||||
$prizes = array();
|
$prizes = array();
|
||||||
$q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$aaid'");
|
$q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$aaid'");
|
||||||
while($prize = mysql_fetch_assoc($q)) {
|
while($prize = mysql_fetch_assoc($q)) {
|
||||||
|
$response['notice'][] = " - Prize: {$prize['prize']}";
|
||||||
/* Clean out existing winners for this prize */
|
/* Clean out existing winners for this prize */
|
||||||
mysql_query("DELETE FROM winners WHERE
|
mysql_query("DELETE FROM winners WHERE
|
||||||
award_prize_id='{$prize['id']}'
|
award_prize_id='{$prize['id']}'
|
||||||
@ -294,11 +301,10 @@ function handle_award_upload(&$u, &$fair, &$data, &$response)
|
|||||||
if(!is_array($ul_p['projects'])) continue;
|
if(!is_array($ul_p['projects'])) continue;
|
||||||
|
|
||||||
foreach($ul_p['projects'] as &$project) {
|
foreach($ul_p['projects'] as &$project) {
|
||||||
award_upload_assign($fair, $prize, $project, $year);
|
award_upload_assign($fair, $prize, $project, $year, $response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$response['notice'][] = 'Award winners saved';
|
||||||
$response['message'] = 'Award winners saved';
|
|
||||||
$response['error'] = 0;
|
$response['error'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user