X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=html%2Fdo-edit-scores.pl;h=945e25cdc298ef2c1615cf57450ba0015b4f4e03;hp=fe29c168abe76ddc895101fa02f0e67aaec502bc;hb=a6500d8a7d1a7fc0bd172373f1a670b8ee7ce92e;hpb=9e9977d8d73f4f28e6f8f3d6d1a007a859bc3955 diff --git a/html/do-edit-scores.pl b/html/do-edit-scores.pl index fe29c16..945e25c 100755 --- a/html/do-edit-scores.pl +++ b/html/do-edit-scores.pl @@ -13,6 +13,8 @@ my $group = $cgi->param('group'); $dbh->{AutoCommit} = 0; +my %checked_songs = (); + # Loop through all parameters and see what parameters differ between old- and current # versions for my $p ($cgi->param()) { @@ -20,9 +22,49 @@ for my $p ($cgi->param()) { 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*$/); + + # _Before_ we do changes to the database, check if this is possibly something + # that will trigger a foreign key error. There will be an error if the tuple + # (song,playmode,difficulty) is set (ie. all members are set) and the combination + # doesn't exist in songratings, so check that. However, only check once per + # song (or else we'll be doing lots of unneeded database calls). + if ($p =~ /^(?:playmode|difficulty|song)(\d+)-(\d+)$/ && !defined($checked_songs{"$1-$2"})) { + # check that the entire triple is set + if (defined($cgi->param("playmode$1-$2")) && $cgi->param("playmode$1-$2") !~ /^\s*$/ && + defined($cgi->param("difficulty$1-$2")) && $cgi->param("difficulty$1-$2") !~ /^\s*$/ && + defined($cgi->param("song$1-$2")) && $cgi->param("song$1-$2") !~ /^\s*$/) { + my $ref = $dbh->selectrow_hashref('SELECT COUNT(*) AS num_songs FROM songratings WHERE song=? AND playmode=? AND difficulty=?', + undef, $cgi->param("song$1-$2"), $cgi->param("playmode$1-$2"), + $cgi->param("difficulty$1-$2")); + if ($ref->{'num_songs'} != 1) { + # Fetch the name of the song if we can + $ref = $dbh->selectrow_hashref('SELECT title FROM songs WHERE song=?', + undef, $cgi->param("song$1-$2")); + ccbs::user_error("Sangen $ref->{'title'} har ikke steps for " . + $cgi->param("playmode$1-$2") . " " . $cgi->param("difficulty$1-$2") . "."); + } + $checked_songs{"$1-$2"} = 1; + } + } + 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, - $cgi->param($p), $tournament, $round, $group, $1, $2); + $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); } }