From a5246f74e35ba01fce7d22f41ea8c8a61446368e Mon Sep 17 00:00:00 2001 From: dave Date: Mon, 21 Sep 2009 07:49:11 +0000 Subject: [PATCH] - Server-side prettying --- xmltransport.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xmltransport.php b/xmltransport.php index 7f10274..bf27cc9 100644 --- a/xmltransport.php +++ b/xmltransport.php @@ -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; }