Add some check before solving exercice

This commit is contained in:
nemunaire 2013-12-13 20:11:26 +01:00
parent 6cabc4003f
commit 10eb72688f

View File

@ -65,7 +65,7 @@ for my $f (readdir $dh)
{'RaiseError' => 1, 'PrintError' => 1}) {'RaiseError' => 1, 'PrintError' => 1})
or die $DBI::errstr if !$dbh; 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 # Check solutions
while (my $row = get_row($sth)) while (my $row = get_row($sth))
@ -88,16 +88,40 @@ for my $f (readdir $dh)
# Register solve # Register solve
if ($good == -1) { 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) elsif ($good == 1)
{ {
say "Team $team solve exercice $exercice in $theme at ".localtime(); # Check if the exercice exists
query($dbh, "INSERT INTO solved (id_team, id_exercice, time) VALUES ($team, '$exercice', CURRENT_TIMESTAMP);"); $sth = query($dbh, "SELECT `require` FROM exercices E WHERE E.id_theme = $theme AND E.id = ".$dbh->quote($exercice));
$exit++; 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 { 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 # Remove the file