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;
|
||||
}
|
||||
|
||||
function award_upload_school(&$student, &$school, $year)
|
||||
function award_upload_school(&$student, &$school, $year, &$response)
|
||||
{
|
||||
|
||||
$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'");
|
||||
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 */
|
||||
mysql_query("INSERT INTO schools(`school`,`year`) VALUES ('".mysql_real_escape_string($school['schoolname'])."','$year')");
|
||||
$school_id = mysql_insert_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
|
||||
* transport name => sql name mapping */
|
||||
@ -208,10 +209,11 @@ function award_upload_assign(&$fair, &$prize, &$project, $year)
|
||||
echo mysql_error();
|
||||
if(mysql_num_rows($q) == 1) {
|
||||
$our_project = mysql_fetch_assoc($q);
|
||||
echo "Found existing project";
|
||||
$registrations_id = $our_project['registrations_id'];
|
||||
$pid = $our_project['id'];
|
||||
$response['notice'][] = " - Found existing project: {$project['title']}";
|
||||
} else {
|
||||
$response['notice'][] = " - Creating new project: {$project['title']}";
|
||||
/* Create a registration */
|
||||
$regnum=0;
|
||||
//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 */
|
||||
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))."`";
|
||||
$values = "";
|
||||
@ -279,11 +283,14 @@ function handle_award_upload(&$u, &$fair, &$data, &$response)
|
||||
$award = mysql_fetch_assoc($q);
|
||||
$aaid = $award['id'];
|
||||
|
||||
$response['notice'][] = "Found award: {$award['name']}";
|
||||
|
||||
/* 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 */
|
||||
$prizes = array();
|
||||
$q = mysql_query("SELECT * FROM award_prizes WHERE award_awards_id='$aaid'");
|
||||
while($prize = mysql_fetch_assoc($q)) {
|
||||
$response['notice'][] = " - Prize: {$prize['prize']}";
|
||||
/* Clean out existing winners for this prize */
|
||||
mysql_query("DELETE FROM winners WHERE
|
||||
award_prize_id='{$prize['id']}'
|
||||
@ -294,11 +301,10 @@ function handle_award_upload(&$u, &$fair, &$data, &$response)
|
||||
if(!is_array($ul_p['projects'])) continue;
|
||||
|
||||
foreach($ul_p['projects'] as &$project) {
|
||||
award_upload_assign($fair, $prize, $project, $year);
|
||||
award_upload_assign($fair, $prize, $project, $year, $response);
|
||||
}
|
||||
}
|
||||
|
||||
$response['message'] = 'Award winners saved';
|
||||
$response['notice'][] = 'Award winners saved';
|
||||
$response['error'] = 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user