From a7558e3ffcb4862f21482af3bfc60c67ab1a435e Mon Sep 17 00:00:00 2001
From: patrick <patrick@algolibre.io>
Date: Tue, 18 Feb 2025 05:31:45 +0000
Subject: [PATCH] Fix Awards System

---
 .devcontainer/science-ation-blank-generic.sql |   9 +-
 admin/award_awards.php                        | 357 +++++++++---------
 admin/awards.php                              |   4 +-
 projects.inc.php                              |  59 +--
 register_participants_main.php                |  30 +-
 register_participants_spawards.php            |  44 ++-
 6 files changed, 263 insertions(+), 240 deletions(-)

diff --git a/.devcontainer/science-ation-blank-generic.sql b/.devcontainer/science-ation-blank-generic.sql
index f76ac430..fbe2d9b9 100644
--- a/.devcontainer/science-ation-blank-generic.sql
+++ b/.devcontainer/science-ation-blank-generic.sql
@@ -1771,9 +1771,10 @@ CREATE TABLE `projectcategories` (
 LOCK TABLES `projectcategories` WRITE;
 /*!40000 ALTER TABLE `projectcategories` DISABLE KEYS */;
 INSERT INTO `projectcategories` VALUES
-(1,'junor','',7,8,2025),
-(2,'senior','',11,12,2025),
-(3,'int','',9,10,2025);
+(1,'Junior','',7,8,2025),
+(2,'Intermediate','',9,10,2025),
+(3,'Senior','',11,12,2025);
+
 /*!40000 ALTER TABLE `projectcategories` ENABLE KEYS */;
 UNLOCK TABLES;
 
@@ -3131,7 +3132,7 @@ CREATE TABLE `schools` (
 LOCK TABLES `schools` WRITE;
 /*!40000 ALTER TABLE `schools` DISABLE KEYS */;
 INSERT INTO `schools` VALUES
-(1,'sd','','','','','','','','','','','','',NULL,NULL,'','','','','',2025,NULL,0,0,0,'',0,'total','no');
+(1,'Sample School','','','','','','','','','','','','',NULL,NULL,'','','','','',2025,NULL,0,0,0,'',0,'total','no');
 /*!40000 ALTER TABLE `schools` ENABLE KEYS */;
 UNLOCK TABLES;
 
diff --git a/admin/award_awards.php b/admin/award_awards.php
index 27d30c81..5af4f4a4 100644
--- a/admin/award_awards.php
+++ b/admin/award_awards.php
@@ -31,16 +31,15 @@ require_once ('awards.inc.php');
 $_GET['action'] = $_GET['action'] ?? '';
 
 switch ($_GET['action']) {
-	case 'awardinfo_load':
-		                    ;
+	case 'awardinfo_load':;
 		$id = intval(get_value_from_array($_GET, 'id'));
-		$q = $pdo->prepare("SELECT * FROM award_awards WHERE id=?");
+		$q = $pdo->prepare('SELECT * FROM award_awards WHERE id=?');
 		$q->execute([$id]);
 		$ret = $q->fetch(PDO::FETCH_ASSOC);
 
 		// json_encode NEEDS UTF8 DATA, but we store it in the database as ISO :(
 		foreach ($ret AS $k => $v) {
-			$ret[$k] = iconv('ISO-8859-1', 'UTF-8', $v);
+			$ret[$k] = iconv('ISO-8859-1', 'UTF-8', get_value_or_default($v, ''));
 		}
 		// echo iconv("ISO-8859-1","UTF-8",json_encode($ret));
 		echo json_encode($ret);
@@ -55,17 +54,17 @@ switch ($_GET['action']) {
 		/* Scrub the data while we save it */
 		$id = intval($_POST['id']);
 
-		if ($id == -1) {
-			$q = $pdo->prepare("INSERT INTO award_awards (year,self_nominate,schedule_judges) 
+		try {
+			if ($id == -1) {
+				$q = $pdo->prepare("INSERT INTO award_awards (year,self_nominate,schedule_judges) 
 					VALUES (?,'yes','yes')");
-			$q->execute([$config['FAIRYEAR']]);
-			$id = $pdo->lastInsertId();
-			happy_('Award Created');
-			/* Set the award_id in the client */
-			echo "<script type=\"text/javascript\">award_id=$id;</script>";
-		}
+				$q->execute([$config['FAIRYEAR']]);
+				$id = $pdo->lastInsertId();
+				/* Set the award_id in the client */
+				echo "<script type=\"text/javascript\">award_id=$id;</script>";
+			}
 
-		$q = "UPDATE award_awards SET 
+			$q = "UPDATE award_awards SET 
 			award_types_id='" . intval($_POST['award_types_id']) . "',
 			presenter='" . iconv('UTF-8', 'ISO-8859-1', stripslashes($_POST['presenter'])) . "', 
 			excludefromac='" . (($_POST['excludefromac'] == 1) ? 1 : 0) . "',
@@ -74,21 +73,32 @@ switch ($_GET['action']) {
 			schedule_judges='" . (($_POST['schedule_judges'] == 'yes') ? 'yes' : 'no') . "', 
 			description='" . iconv('UTF-8', 'ISO-8859-1', stripslashes($_POST['description'])) . "' ";
 
-		if (array_key_exists('name', $_POST)) {
-			/*
-			 * These values may be disabled, if they name key exists, assume
-			 * they aren't disabled and save them too
-			 */
-			$q .= ",name='" . iconv('UTF-8', 'ISO-8859-1', stripslashes($_POST['name'])) . "',
-				criteria='" . iconv('UTF-8', 'ISO-8859-1', stripslashes($_POST['criteria'])) . "', 
-				sponsors_id='" . intval($_POST['sponsors_id']) . "' ";
+			
+			if (array_key_exists('name', $_POST)) {
+				/*
+				 * These values may be disabled, if they name key exists, assume
+				 * they aren't disabled and save them too
+				 */
+				$q .= ",name=" . $pdo->quote($_POST['name']) . ",
+				criteria='" . iconv('UTF-8', 'ISO-8859-1', stripslashes($_POST['criteria'])) . "'";
+				if (intval($_POST['sponsors_id']) != -1) { 
+					$q .= "sponsors_id='" . $sponsors_id . "' ";
+				}
+			}
+
+			$q .= " WHERE id=$id";
+			error_log('query: ' . $q);
+			$q = $pdo->prepare($q);
+			$q->execute();
+
+			happy_('Award Created');
+			happy_('Award information saved');
+		} catch (PDOException $exception) {
+			error_('Award not created');
+			error_('Award information failed to save');
+			error_log("Here");
+			error_log($exception);
 		}
-		$q .= "WHERE id=?";
-		$q = $pdo->prepare($q);
-		$q->execute([$id]);
-	
-		show_pdo_errors_if_any($pdo);
-		happy_('Award information saved');
 		exit;
 
 	case 'eligibility_load':
@@ -96,19 +106,27 @@ switch ($_GET['action']) {
 		// select the current categories that this award is linked to
 		$ret = array('categories' => array(), 'divisions' => array());
 
-		$q = $pdo->prepare("SELECT * FROM award_awards_projectcategories WHERE award_awards_id=?");
-		$q->execute([$id]);
-		while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
-			$ret['categories'][] = $r['projectcategories_id'];
+		try {
+			$q = $pdo->prepare('SELECT * FROM award_awards_projectcategories WHERE award_awards_id=?');
+			$q->execute([$id]);
+
+			while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
+				$ret['categories'][] = $r['projectcategories_id'];
+			}
+
+			// select the current categories that this award is linked to
+			$q = $pdo->prepare('SELECT * FROM award_awards_projectdivisions WHERE award_awards_id=?');
+			$q->execute([$id]);
+
+			while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
+				$ret['divisions'][] = $r['projectdivisions_id'];
+			}
+
+			echo json_encode($ret);
+		} catch (PDOException $exception) {
+			error_log($exception);
 		}
 
-		// select the current categories that this award is linked to
-		$q = $pdo->$prepare("SELECT * FROM award_awards_projectdivisions WHERE award_awards_id=?");
-		$q->execute([$id]);
-		while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
-			$ret['divisions'][] = $r['projectdivisions_id'];
-		}
-		echo json_encode($ret);
 		exit;
 
 	case 'eligibility_save':
@@ -119,78 +137,94 @@ switch ($_GET['action']) {
 			error_('Invalid data');
 			exit;
 		}
-
-		// wipe out any old award-category links
-		$q = $pdo->prepare("DELETE FROM award_awards_projectcategories WHERE award_awards_id=?");
-		$q->execute([$id]);
-		foreach ($_POST['categories'] AS $key => $cat) {
-			$c = intval($cat);
-			$q = $pdo->prepare('INSERT INTO award_awards_projectcategories (award_awards_id, projectcategories_id, year) 
+		try {
+			// wipe out any old award-category links
+			$q = $pdo->prepare('DELETE FROM award_awards_projectcategories WHERE award_awards_id=?');
+			$q->execute([$id]);
+			foreach ($_POST['categories'] AS $key => $cat) {
+				$c = intval($cat);
+				$q = $pdo->prepare('INSERT INTO award_awards_projectcategories (award_awards_id, projectcategories_id, year) 
 						VALUES (:id, :c, :year)');
 
-			$q->bindParam(':id', $id, PDO::PARAM_INT);
-			$q->bindParam(':c', $c, PDO::PARAM_INT);
-			$q->bindParam(':year', $config['FAIRYEAR'], PDO::PARAM_INT);
+				$q->bindParam(':id', $id, PDO::PARAM_INT);
+				$q->bindParam(':c', $c, PDO::PARAM_INT);
+				$q->bindParam(':year', $config['FAIRYEAR'], PDO::PARAM_INT);
 
-			$q->execute();
-		}
+				$q->execute();
+			}
 
-		// wipe out any old award-divisions links
+			// wipe out any old award-divisions links
 
-		$q = $pdo->prepare("DELETE FROM award_awards_projectdivisions WHERE award_awards_id=?");
-		$q->execute([$id]);
+			$q = $pdo->prepare('DELETE FROM award_awards_projectdivisions WHERE award_awards_id=?');
+			$q->execute([$id]);
 
-		// now add the new ones
-		foreach ($_POST['divisions'] AS $key => $div) {
-			$d = intval($div);
+			// now add the new ones
+			foreach ($_POST['divisions'] AS $key => $div) {
+				$d = intval($div);
 
-			$q = $pdo->prepare('INSERT INTO award_awards_projectdivisions (award_awards_id, projectdivisions_id, year) 
+				$q = $pdo->prepare('INSERT INTO award_awards_projectdivisions (award_awards_id, projectdivisions_id, year) 
 						VALUES (:id, :d, :year)');
 
-			$q->bindParam(':id', $id, PDO::PARAM_INT);
-			$q->bindParam(':d', $d, PDO::PARAM_INT);
-			$q->bindParam(':year', $config['FAIRYEAR'], PDO::PARAM_INT);
+				$q->bindParam(':id', $id, PDO::PARAM_INT);
+				$q->bindParam(':d', $d, PDO::PARAM_INT);
+				$q->bindParam(':year', $config['FAIRYEAR'], PDO::PARAM_INT);
 
-			$q->execute();
-			show_pdo_errors_if_any($pdo);
+				$q->execute();
+				show_pdo_errors_if_any($pdo);
+			}
+
+			happy_('Eligibility information saved');
+		} catch (PDOException $exception) {
+			error_('Eligibility information failed to save');
 		}
-		happy_('Eligibility information saved');
 		exit;
 
 	case 'prize_order':
 		$order = 0;
-		foreach ($_GET['prizelist'] as $position => $id) {
-			if ($id == '')
-				continue;
-			$order++;
 
-			$q = $pdo->prepare("UPDATE `award_prizes` SET `order`=? WHERE `id`=?");
-			$q->execute([$order, $id]);
+		try {
+			foreach ($_GET['prizelist'] as $position => $id) {
+				if ($id == '')
+					continue;
+				$order++;
+
+				$q = $pdo->prepare('UPDATE `award_prizes` SET `order`=? WHERE `id`=?');
+				$q->execute([$order, $id]);
+			}
+
+			happy_('Order Updated.');
+		} catch (PDOException $exception) {
+			error_('Order failed to update');
+			error_log($exception);
 		}
-		//	print_r($_GET);
-		happy_('Order Updated.');
 		exit;
 
 	case 'award_order':
 		$order = 0;
-		foreach ($_GET['awardlist'] as $position => $id) {
-			if ($id == '')
-				continue;
-			$order++;
+		try {
+			foreach ($_GET['awardlist'] as $position => $id) {
+				if ($id == '')
+					continue;
+				$order++;
 
-			$q = $pdo->prepare("UPDATE `award_awards` SET `order`=? WHERE `id`=?");
-			$q->execute([$order, $id]);
+				$q = $pdo->prepare('UPDATE `award_awards` SET `order`=? WHERE `id`=?');
+				$q->execute([$order, $id]);
+			}
+
+			happy_('Order updated');
+		} catch (PDOException $exception) {
+			error_('Order failed to update');
+			error_log($exception);
 		}
-		happy_('Order updated');
 		exit;
 
 	case 'prizeinfo_load':
 		$id = intval($_GET['id']);
 		if ($id == -1) {
-						$q = $pdo->prepare("SELECT * FROM award_prizes WHERE year='-1' AND award_awards_id='0' ORDER BY `order`");
+			$q = $pdo->prepare("SELECT * FROM award_prizes WHERE year='-1' AND award_awards_id='0' ORDER BY `order`");
 			$q->execute();
 		} else {
-			$q = $pdo->prepare("SELECT * FROM award_prizes WHERE award_awards_id=? ORDER BY `order`");
+			$q = $pdo->prepare('SELECT * FROM award_prizes WHERE award_awards_id=? ORDER BY `order`');
 			$q->execute([$id]);
 		}
 		while ($r = $q->fetch(PDO::FETCH_ASSOC)) {
@@ -204,7 +238,7 @@ switch ($_GET['action']) {
 	case 'prize_load':
 		$id = intval($_GET['id']);
 
-		$q = $pdo->prepare("SELECT * FROM award_prizes WHERE id=?");
+		$q = $pdo->prepare('SELECT * FROM award_prizes WHERE id=?');
 		$q->execute([$id]);
 		$ret = $q->fetch(PDO::FETCH_ASSOC);
 		foreach ($ret AS $k => $v) {
@@ -221,21 +255,26 @@ switch ($_GET['action']) {
 			$year = -1;
 		}
 
-		$q = $pdo->prepare('INSERT INTO award_prizes (award_awards_id, year) VALUES (:aaid, :year)');
+		try {
+			$q = $pdo->prepare('INSERT INTO award_prizes (award_awards_id, year) VALUES (:aaid, :year)');
 
-		$q->bindParam(':aaid', $aaid, PDO::PARAM_INT);
-		$q->bindParam(':year', $year, PDO::PARAM_INT);
+			$q->bindParam(':aaid', $aaid, PDO::PARAM_INT);
+			$q->bindParam(':year', $year, PDO::PARAM_INT);
 
-		$q->execute();
+			$q->execute();
 
-		$ret = array('id' => $pdo->lastInsertId());
-		echo json_encode($ret);
+			$ret = array('id' => $pdo->lastInsertId());
+			echo json_encode($ret);
+		} catch (PDOException $exception) {
+			error_log($exception);
+		}
 		exit;
 
 	case 'prize_save':
 		$id = intval($_POST['id']);
 
-		$q = $pdo->prepare('UPDATE award_prizes SET 
+		try {
+			$q = $pdo->prepare('UPDATE award_prizes SET 
 					prize = :prize, 
 					cash = :cash,
 					scholarship = :scholarship,
@@ -248,21 +287,25 @@ switch ($_GET['action']) {
 					trophyschoolreturn = :trophyschoolreturn
 					WHERE id = :id');
 
-		$q->bindParam(':prize', stripslashes(iconv('UTF-8', 'ISO-8859-1', $_POST['prize'])), PDO::PARAM_STR);
-		$q->bindValue(':cash', intval($_POST['cash']), PDO::PARAM_INT);
-		$q->bindValue(':scholarship', intval($_POST['scholarship']), PDO::PARAM_INT);
-		$q->bindValue(':value', intval($_POST['value']), PDO::PARAM_INT);
-		$q->bindValue(':number', intval($_POST['number']), PDO::PARAM_INT);
-		$q->bindValue(':excludefromac', ($_POST['excludefromac'] == 1) ? 1 : 0, PDO::PARAM_INT);
-		$q->bindValue(':trophystudentkeeper', ($_POST['trophystudentkeeper'] == 1) ? 1 : 0, PDO::PARAM_INT);
-		$q->bindValue(':trophystudentreturn', ($_POST['trophystudentreturn'] == 1) ? 1 : 0, PDO::PARAM_INT);
-		$q->bindValue(':trophyschoolkeeper', ($_POST['trophyschoolkeeper'] == 1) ? 1 : 0, PDO::PARAM_INT);
-		$q->bindValue(':trophyschoolreturn', ($_POST['trophyschoolreturn'] == 1) ? 1 : 0, PDO::PARAM_INT);
-		$q->bindValue(':id', $id, PDO::PARAM_INT);
+			$q->bindParam(':prize', stripslashes(iconv('UTF-8', 'ISO-8859-1', $_POST['prize'])), PDO::PARAM_STR);
+			$q->bindValue(':cash', intval($_POST['cash']), PDO::PARAM_INT);
+			$q->bindValue(':scholarship', intval($_POST['scholarship']), PDO::PARAM_INT);
+			$q->bindValue(':value', intval($_POST['value']), PDO::PARAM_INT);
+			$q->bindValue(':number', intval($_POST['number']), PDO::PARAM_INT);
+			$q->bindValue(':excludefromac', ($_POST['excludefromac'] == 1) ? 1 : 0, PDO::PARAM_INT);
+			$q->bindValue(':trophystudentkeeper', ($_POST['trophystudentkeeper'] == 1) ? 1 : 0, PDO::PARAM_INT);
+			$q->bindValue(':trophystudentreturn', ($_POST['trophystudentreturn'] == 1) ? 1 : 0, PDO::PARAM_INT);
+			$q->bindValue(':trophyschoolkeeper', ($_POST['trophyschoolkeeper'] == 1) ? 1 : 0, PDO::PARAM_INT);
+			$q->bindValue(':trophyschoolreturn', ($_POST['trophyschoolreturn'] == 1) ? 1 : 0, PDO::PARAM_INT);
+			$q->bindValue(':id', $id, PDO::PARAM_INT);
 
-		$q->execute();
+			$q->execute();
 
-		happy_('Prize saved');
+			happy_('Prize saved');
+		} catch (PDOException $exception) {
+			error_('Prize failed to save');
+			error_log($exception);
+		}
 		exit;
 
 	case 'prize_delete':
@@ -275,7 +318,7 @@ switch ($_GET['action']) {
 		$id = intval($_GET['id']);
 		/* Prepare two lists of fair IDs, for which fairs can upload and download this award */
 
-		$q = $pdo->prepare("SELECT * FROM fairs_awards_link WHERE award_awards_id=?");
+		$q = $pdo->prepare('SELECT * FROM fairs_awards_link WHERE award_awards_id=?');
 		$q->execute([$id]);
 		$ul = array();
 		$dl = array();
@@ -286,7 +329,7 @@ switch ($_GET['action']) {
 				$dl[$r['fairs_id']] = true;
 		}
 
-		$q = $pdo->prepare("SELECT * FROM award_awards WHERE id=?");
+		$q = $pdo->prepare('SELECT * FROM award_awards WHERE id=?');
 		$q->execute([$id]);
 		$a = $q->fetch(PDO::FETCH_ASSOC);
 		?>
@@ -346,38 +389,46 @@ switch ($_GET['action']) {
 
 		/* Prepare a fair-wise list */
 		$data = array();
-		foreach ($dl AS $fairs_id)
+		foreach ($dl AS $fairs_id) {
 			$data[$fairs_id]['dl'] = true;
-		foreach ($ul AS $fairs_id)
+		}
+
+		foreach ($ul AS $fairs_id) {
 			$data[$fairs_id]['ul'] = true;
+		}
 
 		/* Now save each one */
 
-		$q = $pdo->prepare("DELETE FROM fairs_awards_link WHERE award_awards_id=?");
-		$q->execute([$id]);
-		show_pdo_errors_if_any($pdo);
-		foreach ($data as $fairs_id => $f) {
-			$dl = ($f['dl'] == true) ? 'yes' : 'no';
-			$ul = ($f['ul'] == true) ? 'yes' : 'no';
-
-			$q = $pdo->prepare("INSERT INTO fairs_awards_link (award_awards_id,fairs_id,download_award,upload_winners)
-					VALUES (?,?,?,?)");
-			$q->execute([$id,$fairs_id,$dl,$ul]);
+		try {
+			$q = $pdo->prepare('DELETE FROM fairs_awards_link WHERE award_awards_id=?');
+			$q->execute([$id]);
 			show_pdo_errors_if_any($pdo);
-		}
-		$ident = stripslashes($_POST['identifier']);
-		$per_fair = $_POST['per_fair'] == 'yes' ? 'yes' : 'no';
-		$mat = intval($_POST['additional_materials']);
-		$w = intval($_POST['register_winners']);
+			foreach ($data as $fairs_id => $f) {
+				$dl = ($f['dl'] == true) ? 'yes' : 'no';
+				$ul = ($f['ul'] == true) ? 'yes' : 'no';
 
-		$q = $pdo->prepare("UPDATE award_awards SET external_identifier=?,
+				$q = $pdo->prepare('INSERT INTO fairs_awards_link (award_awards_id,fairs_id,download_award,upload_winners)
+					VALUES (?,?,?,?)');
+				$q->execute([$id, $fairs_id, $dl, $ul]);
+				show_pdo_errors_if_any($pdo);
+			}
+			$ident = stripslashes($_POST['identifier']);
+			$per_fair = $_POST['per_fair'] == 'yes' ? 'yes' : 'no';
+			$mat = intval($_POST['additional_materials']);
+			$w = intval($_POST['register_winners']);
+
+			$q = $pdo->prepare('UPDATE award_awards SET external_identifier=?,
 							external_additional_materials=?,
 							external_register_winners=?,
 							per_fair=?
-						WHERE id=?");
-		$q->execute([[$ident, $mat,$w],$per_fair,$id]);
+						WHERE id=?');
+			$q->execute([$ident, $mat, $w, $per_fair, $id]);
 
-		happy_('Feeder Fair information saved');
+			happy_('Feeder Fair information saved');
+		} catch (PDOException $exception) {
+			error_('Feeder Fair information failed to save');
+			error_log($exception);
+		}
 		exit;
 }
 
@@ -387,7 +438,6 @@ send_header('Awards Management',
 		'Awards Main' => 'admin/awards.php'));
 
 ?>
-<!--<script type="text/javascript" src="../js/jquery.tablednd_0_5.js"></script>-->
 <script type="text/javascript">
 
 var award_id = 0;
@@ -396,16 +446,17 @@ var award_tab_update = new Array();
 
 function update_awardinfo()
 {	
-
 	if(award_tab_update['awardinfo'] == award_id) return;
+
 	award_tab_update['awardinfo'] = award_id;
+
 //	alert(award_id);
 	if(award_id == -1) {
 //		$("#awardinfo input:text").val('');
 		/* New award, set defaults and clear everythign else */
 		$("#awardinfo_id").val(-1);
 		$("#awardinfo_name").val("");
-		$("#awardinfo_sponsors_id").val(0);
+		$("#awardinfo_sponsors_id").val(-1);
 		$("#awardinfo_presenter").val("");
 		$("#awardinfo_description").val("");
 		$("#awardinfo_criteria").val("");
@@ -419,9 +470,9 @@ function update_awardinfo()
 	}
 
 	/* Enable all fields */
-	$("#awardinfo *").removeAttr('disabled');
+	$("#awardinfo *").prop('disabled',false);
 
-	$.getJSON("<?= $_SERVER['PHP_SELF'] ?>?action=awardinfo_load&id="+award_id,
+	$.getJSON(`<?= $_SERVER['PHP_SELF'] ?>?action=awardinfo_load&id=${award_id}`,
 		function(json){
 			$("#awardinfo_id").val(json.id);
 			$("#awardinfo_name").val(json.name);
@@ -610,10 +661,10 @@ function update_feeder()
 	$("#editor_tab_feeder").load("<?= $_SERVER['PHP_SELF'] ?>?action=feeder_load&id="+award_id, '',
 		function(responseText, textStatus, XMLHttpRequest) {
 			/* Register buttons and handlers */
-			$("#feeder_enable").change(function() {
+			$("#feeder_enable").on("change", function() {
 					update_feeder_enable();
 				});
-			$("#feeder_save").click(function() {
+			$("#feeder_save").on("click", function() {
 				$("#debug").load("<? $_SERVER['PHP_SELF'] ?>?action=feeder_save", $("#feeder_form").serializeArray());
 				return false;
 			});
@@ -664,28 +715,6 @@ $(document).ready(function() {
 		},
 		active: -1
 	});
-
-	// $("#editor_tabs").tabs({
-	// 		show: function(event, ui) { 
-	// 			switch(ui.panel.id) {
-	// 			case 'editor_tab_awardinfo':
-	// 				update_awardinfo();
-	// 				break;			
-	// 			case 'editor_tab_eligibility':
-	// 				update_eligibility();
-	// 				break;			
-	// 			case 'editor_tab_prizes':
-	// 				update_prizeinfo();
-	// 				break;
-	// 			case 'editor_tab_feeder':
-	// 				update_feeder();
-	// 				break;
-	// 			}
-	// 			return true;
-	// 		},
-	// 		collapsible: true,
-	// 		selected: -1 /* None selected */
-	// 	});
 })
 
  </script>
@@ -725,7 +754,7 @@ $(document).ready(function() {
 $sq = $pdo->prepare('SELECT id,organization FROM sponsors ORDER BY organization');
 $sq->execute();
 echo '<select id="awardinfo_sponsors_id" name="sponsors_id">';
-echo '<option value="">' . i18n('Choose a sponsor') . "</option>\n";
+echo '<option hidden value="-1">' . i18n('Choose a sponsor') . "</option>\n";
 while ($sr = $sq->fetch(PDO::FETCH_OBJ)) {
 	echo "<option value=\"$sr->id\">" . i18n($sr->organization) . '</option>';
 }
@@ -736,7 +765,7 @@ while ($sr = $sq->fetch(PDO::FETCH_OBJ)) {
 			</td></tr>
 		<tr><td><?= i18n('Type') ?>:</td><td>
 <?
-$tq = $pdo->prepare("SELECT id,type FROM award_types WHERE year=? ORDER BY type");
+$tq = $pdo->prepare('SELECT id,type FROM award_types WHERE year=? ORDER BY type');
 $tq->execute([$config['FAIRYEAR']]);
 echo '<select id="awardinfo_award_types_id" name="award_types_id">';
 // only show the "choose a type" option if we are adding,if we are editing, then they must have already chosen one.
@@ -833,7 +862,6 @@ while ($dr = $dq->fetch(PDO::FETCH_OBJ)) {
 		<th><?= i18n('Actions') ?></th>
 	</tr></table>
 	<br >
-	* <?= i18n('Click on the Script Order and drag to re-order the prizes') ?>
 	<br >
 	<hr>
 
@@ -880,7 +908,7 @@ while ($dr = $dq->fetch(PDO::FETCH_OBJ)) {
 	<br />
 	<form>
 	<input type="submit" onClick="prize_create();return false;" value="<?= i18n('Create New Prize') ?>" />
-	<input type="submit" id="prizeinfo_save" onClick="prize_save();return false;" value="<?= i18n('Save Prize') ?>" disabled="disabled" />
+	<input type="submit" id="prizeinfo_save" onClick="prize_save();" value="<?= i18n('Save Prize') ?>" disabled="disabled" />
 	</form>
 </div>
 
@@ -1084,13 +1112,6 @@ echo '</table>';
 <br /><br />
 
 <?
-
-/*
- * For some reason, this submit button opens the dialog then it closes right away, but it doesn't
- * if the entry is done through the a href
- */
-// <input type="submit" onClick="award_create();" value="<?=i18n("Create New Award")>" />
-
 $where_asi = $where_asi ?? '';
 $where_ati = $where_ati ?? '';
 
@@ -1120,16 +1141,16 @@ WHERE
 				award_awards.year=?
 				$where_asi
 				$where_ati
-			AND \taward_types.year=?
+			AND award_types.year=?
 		$orderby
 ");
 
-$q->execute([$config['FAIRYEAR'],$config['FAIRYEAR']]);
+$q->execute([$config['FAIRYEAR'], $config['FAIRYEAR']]);
 
 show_pdo_errors_if_any($pdo);
 
 if ($q->rowCount()) {
-	echo '* ' . i18n('Click on the Script Order and drag to re-order the awards');
+	//echo '* ' . i18n('Click on the Script Order and drag to re-order the awards');
 	echo '<table id="awardlist" class="tableview" >';
 	echo '<tr class="nodrop nodrag">';
 	echo ' <th>' . i18n('Order') . '</th>';
@@ -1154,7 +1175,7 @@ if ($q->rowCount()) {
 		echo " <td $eh>{$r->type}</td>\n";
 		echo " <td $eh>{$r->name}</td>\n";
 
-		$numq = $pdo->prepare("SELECT SUM(number) AS num FROM award_prizes WHERE award_awards_id=?");
+		$numq = $pdo->prepare('SELECT SUM(number) AS num FROM award_prizes WHERE award_awards_id=?');
 		$numq->execute([$r->id]);
 		$numr = $numq->fetch(PDO::FETCH_ASSOC);
 		if (!$numr['num'])
diff --git a/admin/awards.php b/admin/awards.php
index 30eec426..b556b6b7 100644
--- a/admin/awards.php
+++ b/admin/awards.php
@@ -42,8 +42,8 @@ echo '<a href="award_awards.php?action=edit_prize_template">' . i18n('Edit prize
 echo '<br />';
 echo '<a href="award_awardcreatedivisional.php">' . i18n('Create divisional awards for all divisions & categories') . '</a><br />';
 echo '<br />';
-echo '<a href="award_download.php">' . i18n('Download awards from external sources') . '</a><br />';
-echo '<a href="award_upload.php">' . i18n('Upload award winners to external sources') . '</a><br />';
+//echo '<a href="award_download.php">' . i18n('Download awards from external sources') . '</a><br />';
+//echo '<a href="award_upload.php">' . i18n('Upload award winners to external sources') . '</a><br />';
 
 send_footer();
 
diff --git a/projects.inc.php b/projects.inc.php
index ddbf876d..51b93cc2 100644
--- a/projects.inc.php
+++ b/projects.inc.php
@@ -69,7 +69,7 @@ function getLanguagesOfProjectsEligibleForAward($award_id)
 {
 	global $config, $pdo;
 
-	$prjq = $pdo->prepare("SELECT DISTINCT(projects.language) AS language
+	$prjq = $pdo->prepare('SELECT DISTINCT(projects.language) AS language
 			FROM
 				award_awards,
 				award_awards_projectcategories,
@@ -85,7 +85,7 @@ function getLanguagesOfProjectsEligibleForAward($award_id)
 				AND projects.year=?
 			ORDER BY
 				language
-				");
+				');
 	$prjq->execute([$award_id, $config['FAIRYEAR']]);
 	$languages = array();
 	while ($r = $prjq->fetch(PDO::FETCH_OBJ)) {
@@ -100,7 +100,7 @@ function getProjectsEligibleOrNominatedForAwards($awards_ids_array)
 	global $pdo;
 	$projects = array();
 	foreach ($awards_ids_array AS $award_id) {
-		$q = $pdo->prepare("SELECT award_types.type FROM award_awards, award_types WHERE award_awards.id=? AND award_awards.award_types_id=award_types.id");
+		$q = $pdo->prepare('SELECT award_types.type FROM award_awards, award_types WHERE award_awards.id=? AND award_awards.award_types_id=award_types.id');
 		$q->execute([$award_id]);
 		$r = $q->fetch(PDO::FETCH_OBJ);
 
@@ -174,7 +174,8 @@ function getSpecialAwardsNominatedForProject($projectid)
 {
 	global $config, $pdo;
 
-	$awardsq = $pdo->prepare("SELECT
+	try {
+		$awardsq = $pdo->prepare('SELECT
 				award_awards.id,
 				award_awards.name,
 				award_awards.criteria,
@@ -191,25 +192,29 @@ function getSpecialAwardsNominatedForProject($projectid)
 				AND projects.id=?
 			ORDER BY
 				award_awards.name
-				");
-	$awardsq->execute([$projectid, $config['FAIRYEAR'], $projectid]);
-	$awards = array();
-	show_pdo_errors_if_any($pdo);
-	while ($r = $awardsq->fetch(PDO::FETCH_OBJ)) {
-		$awards[$r->id] = array(
-			'id' => $r->id,
-			'criteria' => $r->criteria,
-			'name' => $r->name,
-			'fairs_id' => $r->fairs_id
-		);
+				');
+		$awardsq->execute([$projectid, $config['FAIRYEAR'], $projectid]);
+		$awards = array();
+
+		while ($r = $awardsq->fetch(PDO::FETCH_OBJ)) {
+			$awards[$r->id] = array(
+				'id' => $r->id,
+				'criteria' => $r->criteria,
+				'name' => $r->name,
+				'fairs_id' => $r->fairs_id
+			);
+		}
+		return $awards;
+	} catch (PDOException $exception) {
+		error_log($exception);
+		return false;
 	}
-	return $awards;
 }
 
 function getNominatedForNoSpecialAwardsForProject($projectid)
 {
 	global $config, $pdo;
-	$awardsq = $pdo->prepare("SELECT
+	$awardsq = $pdo->prepare('SELECT
 				projects.id AS projects_id
 			FROM
 				project_specialawards_link,
@@ -219,7 +224,7 @@ function getNominatedForNoSpecialAwardsForProject($projectid)
 				AND projects.year=?
 				AND projects.id=?
 				AND project_specialawards_link.award_awards_id IS NULL
-				");
+				');
 	$awardsq->execute([$projectid, $config['FAIRYEAR'], $projectid]);
 	if ($awardsq->rowCount() == 1)
 		return true;
@@ -233,7 +238,7 @@ function getProjectsNominatedForSpecialAward($award_id)
 	// if they dont use special award nominations, then we will instead get all of the projects that
 	// are eligible for the award, instead of nominated for it.
 	if ($config['specialawardnomination'] != 'none') {
-		$prjq = $pdo->prepare("SELECT
+		$prjq = $pdo->prepare('SELECT
 					projects.projectnumber,
 					projects.title,
 					projects.language,
@@ -248,7 +253,7 @@ function getProjectsNominatedForSpecialAward($award_id)
 					AND projects.year=?
 				ORDER BY
 					projectsort
-					");
+					');
 		$prjq->execute([$award_id, $config['FAIRYEAR']]);
 		$projects = array();
 		while ($prjr = $prjq->fetch(PDO::FETCH_OBJ)) {
@@ -274,7 +279,7 @@ function getLanguagesOfProjectsNominatedForSpecialAward($award_id)
 	// if they dont use special award nominations, then we will instead get all of the projects that
 	// are eligible for the award, instead of nominated for it.
 	if ($config['specialawardnomination'] != 'none') {
-		$prjq = $pdo->prepare("SELECT  DISTINCT(projects.language) AS language
+		$prjq = $pdo->prepare('SELECT  DISTINCT(projects.language) AS language
 				FROM
 					project_specialawards_link,
 					projects
@@ -284,7 +289,7 @@ function getLanguagesOfProjectsNominatedForSpecialAward($award_id)
 					AND projects.projectnumber is not null
 					AND projects.year=?
 					ORDER BY language
-					");
+					');
 		$prjq->execute([$award_id, $config['FAIRYEAR']]);
 		$languages = array();
 		while ($r = $prjq->fetch(PDO::FETCH_OBJ)) {
@@ -304,7 +309,7 @@ function getSpecialAwardsNominatedByRegistrationID($id)
 {
 	global $config, $pdo;
 
-	$awardq = $pdo->prepare("SELECT
+	$awardq = $pdo->prepare('SELECT
 				award_awards.id,
 				award_awards.name,
 				award_awards_projectcategories.projectcategories_id, 
@@ -325,7 +330,7 @@ function getSpecialAwardsNominatedByRegistrationID($id)
 				AND projects.year=?
 			ORDER BY
 				projectsort
-				");
+				');
 	$awardq->execute([$award_id, $config['FAIRYEAR']]);
 	$projects = array();
 	while ($prjr = $awardq->fetch(PDO::FETCH_OBJ)) {
@@ -342,14 +347,14 @@ function project_load($pid)
 {
 	global $pdo;
 	/* Load this project */
-	$q = $pdo->prepare("SELECT * FROM projects WHERE id=?");
+	$q = $pdo->prepare('SELECT * FROM projects WHERE id=?');
 	$q->execute([$pid]);
 	$proj = $q->fetch();
 
 	/* Load the students */
-	$q = $pdo->prepare("SELECT students.*,schools.school FROM students 
+	$q = $pdo->prepare('SELECT students.*,schools.school FROM students 
 		LEFT JOIN schools ON schools.id=students.schools_id
-		WHERE registrations_id=? AND students.year=? ORDER BY students.id");
+		WHERE registrations_id=? AND students.year=? ORDER BY students.id');
 	$q->execute([$proj['registrations_id'], $proj['year']]);
 	$proj['num_students'] = 0;
 	while ($s = $q->fetch(PDO::FETCH_OBJ)) {
diff --git a/register_participants_main.php b/register_participants_main.php
index 13c8cdac..f0887c92 100644
--- a/register_participants_main.php
+++ b/register_participants_main.php
@@ -29,7 +29,7 @@ include 'register_participants.inc.php';
 include 'projects.inc.php';
 
 // authenticate based on email address and registration number from the SESSION
-if (!$_SESSION['email']) {
+if (!get_value_from_array($_SESSION, 'email')) {
 	header('Location: register_participants.php');
 	exit;
 }
@@ -207,25 +207,17 @@ else{
 
 
 // echo i18n("$participationform");
-// if ($all_complete == true)
-// 	echo '</a>';
-// else
-// 	echo '<br /><font color="red">(' . i18n('Available when ALL above sections are "Complete"') . ')</font>';
+if ($all_complete == true)
+	echo '</a>';
+else
+	echo '<br /><font color="red">(' . i18n('Available when ALL above sections are "Complete"') . ')</font>';
 
-echo '</td><td>';
-echo i18n('Sign');
-// check to see if its complete
-echo '</td></tr>';
-
-// received information
-// echo '<tr><td>' . i18n("$participationform Received") . '</td><td>';
-// if (registrationFormsReceived())
-// 	echo outputStatus('complete');
-// else
-// 	echo outputStatus('incomplete');
-
-// // check to see if its complete
-// echo '</td></tr>';
+echo "<td>";
+if (registrationFormsReceived())
+	echo outputStatus('complete');
+else
+	echo outputStatus('incomplete');
+echo "</td>";
 
 echo '</table>';
 
diff --git a/register_participants_spawards.php b/register_participants_spawards.php
index 88f9a754..98a63456 100644
--- a/register_participants_spawards.php
+++ b/register_participants_spawards.php
@@ -40,13 +40,13 @@ if (!$_SESSION['registration_number']) {
 }
 
 $q = $pdo->prepare('SELECT registrations.id AS regid, students.id AS studentid, students.firstname FROM registrations,students '
-	. "WHERE students.email=?"
-	. "AND registrations.num=?"
-	. "AND registrations.id=?"
+	. 'WHERE students.email=?'
+	. 'AND registrations.num=?'
+	. 'AND registrations.id=?'
 	. 'AND students.registrations_id=registrations.id '
 	. 'AND registrations.year=?'
 	. 'AND students.year=?');
-$q->execute([$_SESSION['email'],$_SESSION['registration_number'],$_SESSION['registration_id'],$config['FAIRYEAR'],$config['FAIRYEAR']]);
+$q->execute([$_SESSION['email'], $_SESSION['registration_number'], $_SESSION['registration_id'], $config['FAIRYEAR'], $config['FAIRYEAR']]);
 show_pdo_errors_if_any($pdo);
 
 if ($q->rowCount() == 0) {
@@ -55,7 +55,7 @@ if ($q->rowCount() == 0) {
 }
 $authinfo = $q->fetch(PDO::FETCH_OBJ);
 
-$q = $pdo->prepare("SELECT * FROM projects WHERE registrations_id=?");
+$q = $pdo->prepare('SELECT * FROM projects WHERE registrations_id=?');
 $q->execute([$_SESSION['registration_id']]);
 $project = $q->fetch(PDO::FETCH_OBJ);
 
@@ -91,8 +91,8 @@ echo '<br />';
 
 if ($config['specialawardnomination'] == 'date') {
 	echo notice(i18n('Special award self-nomination is only available from %1 to %2.  Please make sure you complete your nominations between these dates.', array($config['dates']['specawardregopen'], $config['dates']['specawardregclose'])));
-	$q = $pdo->prepare("SELECT (NOW()>? AND NOW()<?) AS datecheck");
-	$q->execute([$config['dates']['specawardregopen'],$config['dates']['specawardregclose']]);
+	$q = $pdo->prepare('SELECT (NOW()>? AND NOW()<?) AS datecheck');
+	$q->execute([$config['dates']['specawardregopen'], $config['dates']['specawardregclose']]);
 	$r = $q->fetch(PDO::FETCH_OBJ);
 	// this will return 1 if its between the dates, 0 otherwise.
 	if ($r->datecheck == 1)
@@ -123,22 +123,26 @@ if ($_POST['action'] == 'save') {
 		if ($num > $config['maxspecialawardsperproject']) {
 			echo error(i18n('You can only apply to %1 special awards.  You have selected %2', array($config['maxspecialawardsperproject'], $num)));
 		} else {
-			$stmt = $pdo->prepare("DELETE FROM project_specialawards_link WHERE projects_id=? AND year=?");
-			$stmt->execute([$project->id,  $config['FAIRYEAR']]);
-			foreach ($splist AS $spaward) {
-				$s = ($spaward == -1) ? 'NULL' : "'$spaward'";
-				$stmt = $pdo->prepare('INSERT INTO project_specialawards_link (award_awards_id,projects_id,year) VALUES (
+			try {
+				$stmt = $pdo->prepare('DELETE FROM project_specialawards_link WHERE projects_id=? AND year=?');
+				$stmt->execute([$project->id, $config['FAIRYEAR']]);
+				foreach ($splist AS $spaward) {
+					$stmt = $pdo->prepare('INSERT INTO project_specialawards_link (award_awards_id,projects_id,year) VALUES (
 					?, 
 					?,
 					?)');
-				$stmt->execute([$s,$project->id,$config['FAIRYEAR']]);
-				show_pdo_errors_if_any($pdo);
-			}
-			if ($num) {
-				if ($noawards == true)
-					echo happy(i18n('Successfully registered for no special awards'));
-				else
-					echo happy(i18n('Successfully registered for %1 special awards', array($num)));
+					$stmt->execute([$s, $project->id, $config['FAIRYEAR']]);
+					show_pdo_errors_if_any($pdo);
+				}
+				if ($num) {
+					if ($noawards == true)
+						echo happy(i18n('Successfully registered for no special awards'));
+					else
+						echo happy(i18n('Successfully registered for %1 special awards', array($num)));
+				}
+			} catch (PDOException $exception) {
+				error(happy(i18n('Failed to register your settings for special awards')));
+				error_log($exception);
 			}
 		}
 	} else {