From 10eb72688fce178e42ee60f0c7a75eefdc7a78c7 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 13 Dec 2013 20:11:26 +0100 Subject: [PATCH] Add some check before solving exercice --- check.pl | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/check.pl b/check.pl index 9d88f259..4c87106b 100755 --- a/check.pl +++ b/check.pl @@ -65,7 +65,7 @@ for my $f (readdir $dh) {'RaiseError' => 1, 'PrintError' => 1}) or die $DBI::errstr if !$dbh; - my $sth = query($dbh, "SELECT format, value FROM exercice_keys WHERE id_exercice = '$exercice';"); + my $sth = query($dbh, "SELECT format, value FROM exercice_keys WHERE id_exercice = ".$dbh->quote($exercice)); # Check solutions while (my $row = get_row($sth)) @@ -88,16 +88,40 @@ for my $f (readdir $dh) # Register solve if ($good == -1) { - say "Exercice $exercice doesn't exist ; given by team $team in theme $theme."; + say localtime().": Exercice $exercice doesn't exist ; given by team $team in theme $theme."; } elsif ($good == 1) { - say "Team $team solve exercice $exercice in $theme at ".localtime(); - query($dbh, "INSERT INTO solved (id_team, id_exercice, time) VALUES ($team, '$exercice', CURRENT_TIMESTAMP);"); - $exit++; + # Check if the exercice exists + $sth = query($dbh, "SELECT `require` FROM exercices E WHERE E.id_theme = $theme AND E.id = ".$dbh->quote($exercice)); + if ($sth->rows && (my $row = get_row($sth))) + { + # Check if the team has solved dependancies + $sth = query($dbh, "SELECT COUNT(S.id) FROM solved S WHERE S.id_exercice = ".$dbh->quote(@$row[0])) if @$row[0]; + if (! (@$row[0] && $sth->rows)) + { + # Check if the team has not already solved this exercice + $sth = query($dbh, "SELECT COUNT(S.id) FROM solved S WHERE S.id_exercice = ".$dbh->quote($exercice)); + if (! $sth->rows) + { + say localtime().": Team $team solve exercice $exercice in $theme"; + query($dbh, "INSERT INTO solved (id_team, id_exercice, time) VALUES ($team, ".$dbh->quote($exercice).", CURRENT_TIMESTAMP);"); + $exit++; + } + else { + warn localtime().": Team $team try to solve exercice $exercice in $theme but ALREADY solved it"; + } + } + else { + warn localtime().": Team $team try to solve exercice $exercice in $theme but has NOT SOLVED required exercice ".@$row[0]; + } + } + else { + warn localtime().": Team $team try to solve exercice $exercice in $theme but does not exist"; + } } else { - say "Team $team didn't give the correct answer for exercice $exercice."; + say localtime().": Team $team didn't give the correct answer for exercice $exercice."; } # Remove the file