From 30d01eeb748cf39c35b905935a773ba2e46f82c7 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 12 Jul 2010 23:11:07 +0000 Subject: [PATCH] eligibility editor now checks that no two divisional awards have overlapping eligibility criteria (issue 249) --- admin/award_awards.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/admin/award_awards.php b/admin/award_awards.php index 3a766826..a12c2c0e 100644 --- a/admin/award_awards.php +++ b/admin/award_awards.php @@ -105,6 +105,35 @@ error_("Invalid data"); exit; } + foreach($_POST['categories'] AS $key=>$cat) { + if(!is_numeric($cat)) { + error_("Invalid data"); + exit; + } + } + foreach($_POST['divisions'] AS $key=>$div) { + if(!is_numeric($div)) { + error_("Invalid data"); + exit; + } + } + + $q=mysql_query("SELECT (CASE WHEN ((SELECT a.award_types_id FROM award_awards AS a WHERE id=$id) = 1) THEN ( + SELECT COUNT(*) AS c FROM award_awards AS aa + LEFT JOIN award_awards_projectcategories AS aapc ON (aa.id = aapc.award_awards_id) + LEFT JOIN award_awards_projectdivisions AS aapd ON (aa.id = aapd.award_awards_id) + WHERE aa.year = {$config['FAIRYEAR']} AND + aa.award_types_id=1 AND + aa.id != $id AND + projectcategories_id IN (". implode(",", $_POST['categories']) .") AND + projectdivisions_id IN (". implode(",", $_POST['divisions']) .") + ) ELSE 0 END) as c"); + + $r = mysql_fetch_object($q); + if($r->c != 0) { + error_("Cannot save. There is already a divisional award with the same eligibility criteria."); + exit; + } //wipe out any old award-category links mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'");