X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=html%2Fdo-edit-scores.pl;h=be93df0536c9ef0871822406f37b1dd92bb1195a;hp=4b5d4828034597a8f2fe487ec1beb755a928d2ce;hb=a5bef5a751fddcaa09f7d4281e2452ea778436ca;hpb=50e6991fc69f8bace6489c40dbbe6b5ba9df8572 diff --git a/html/do-edit-scores.pl b/html/do-edit-scores.pl index 4b5d482..be93df0 100755 --- a/html/do-edit-scores.pl +++ b/html/do-edit-scores.pl @@ -8,18 +8,41 @@ my $dbh = ccbs::db_connect(); my $cgi = new CGI; my $tournament = $cgi->param('tournament'); - -# Loop through all parameters until we find the update button -my $player; -for my $param ($cgi->param()) { - if ($param =~ /^update(\d+)$/) { - $player = $1; - last; +my $round = $cgi->param('round'); +my $group = $cgi->param('group'); + +$dbh->{AutoCommit} = 0; + +# Loop through all parameters and see what parameters differ between old- and current +# versions +for my $p ($cgi->param()) { + next if ($p =~ /^old-(.*?)$/); + next unless (defined($cgi->param('old-' . $p))); + next if ($cgi->param($p) eq $cgi->param('old-' . $p)); + + my $val = $cgi->param($p); + undef $val if ($val =~ /^\s*$/); + + if ($p =~ /^score(\d+)-(\d+)/) { + if (defined($val) && ($val < 0 || $val > 10000)) { + ccbs::user_error("Alle poengsummer må være mellom 0 og 10000 (inklusive)."); + } + + $dbh->do('UPDATE scores SET score=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef, + $val, $tournament, $round, $group, $1, $2); + } elsif ($p =~ /^playmode(\d+)-(\d+)/) { + $dbh->do('UPDATE scores SET playmode=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef, + $val, $tournament, $round, $group, $1, $2); + } elsif ($p =~ /^difficulty(\d+)-(\d+)/) { + $dbh->do('UPDATE scores SET difficulty=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef, + $val, $tournament, $round, $group, $1, $2); + } elsif ($p =~ /^song(\d+)-(\d+)/) { + $dbh->do('UPDATE scores SET song=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=? AND chosen=\'t\'', undef, + $val, $tournament, $round, $group, $1, $2); } } -die "Form-submit uten å trykke på noen update-knapp?" unless (defined($player)); - +$dbh->commit; $dbh->disconnect; ccbs::print_see_other('show-tournament.pl?id=' . $tournament);