On second thought, move the award delete and award prize delete into a

separate file, since they're used in two places (by the downloader and
by the editor).   Update the award and prize delete routine to also
delete the winner linkage.
This commit is contained in:
dave 2010-04-22 05:09:50 +00:00
parent a809f80087
commit 2a93723a45
3 changed files with 55 additions and 13 deletions

View File

@ -25,6 +25,7 @@
require_once('../common.inc.php');
require_once('../user.inc.php');
user_auth_required('committee', 'admin');
require_once('awards.inc.php');
switch($_GET['action']) {
case 'awardinfo_load':
@ -41,10 +42,7 @@
case 'award_delete':
$id=intval($_GET['id']);
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$id'");
mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$id'");
mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$id'");
mysql_query("DELETE FROM award_awards WHERE id='$id'");
award_delete($id);
exit;
case 'awardinfo_save':
@ -213,8 +211,7 @@
case 'prize_delete':
$id = intval($_GET['id']);
mysql_query("DELETE FROM award_prizes WHERE id='$id'");
// echo "DELETE FROM award_prizes WHERE id='$id'";
award_prize_delete($id);
happy_("Prize deleted");
exit;

View File

@ -25,6 +25,7 @@
require_once('../user.inc.php');
user_auth_required('committee', 'admin');
require_once('curl.inc.php');
require_once('awards.inc.php');
@ -221,8 +222,7 @@ case 'check':
/* Delete local entries that weren't downloaded */
foreach($existingprizes AS $ep) {
echo "&nbsp;".i18n("Removing prize %1",array($ep['prize']))."<br />";
mysql_query("DELETE FROM award_prizes WHERE id='{$ep['id']}'");
echo mysql_error();
award_prize_delete($ep['id']);
}
}
echo "<br />";
@ -231,11 +231,7 @@ case 'check':
//remove any awards that are left in the $existingawards array, they must have been removed from the source
foreach($existingawards AS $aid=>$val) {
echo i18n("Removing award id %1 that was removed from external source",array($aid))."<br />";
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$aid'");
mysql_query("DELETE FROM award_awards WHERE id='$aid'");
mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$aid'");
mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$aid'");
award_delete($aid);
}
echo "</i>";

49
admin/awards.inc.php Normal file
View File

@ -0,0 +1,49 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2010 David Grant <dave@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
function award_delete($award_awards_id)
{
/* Delete all winners attached to this award */
$q = mysql_query("SELECT id FROM award_prizes WHERE award_awards_id='$award_awards_id'");
while(($p = mysql_fetch_assoc($q))) {
mysql_query("DELETE FROM winners WHERE award_prizes_id='{$p['id']}'");
}
/* FIXME: maybe delte judging teams and judge
* assignments and timeslots?
/* Delete the award */
mysql_query("DELETE FROM award_prizes WHERE award_awards_id='$award_awards_id'");
mysql_query("DELETE FROM award_awards_projectcategories WHERE award_awards_id='$award_awards_id'");
mysql_query("DELETE FROM award_awards_projectdivisions WHERE award_awards_id='$award_awards_id'");
mysql_query("DELETE FROM award_awards WHERE id='$award_awards_id'");
}
function award_prize_delete($award_prizes_id)
{
mysql_query("DELETE FROM winners WHERE award_prizes_id='$award_prizes_id'");
mysql_query("DELETE FROM award_prizes WHERE id='$award_prizes_id'");
}
?>