Check that there are steps for the selected song/playmode/difficulty combination...
authorSteinar H. Gunderson <sesse@samfundet.no>
Wed, 16 Feb 2005 18:55:02 +0000 (18:55 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Wed, 16 Feb 2005 18:55:02 +0000 (18:55 +0000)
html/do-edit-scores.pl
html/templates/show-tournament.tmpl

index be93df0..945e25c 100755 (executable)
@@ -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()) {
@@ -23,6 +25,30 @@ for my $p ($cgi->param()) {
        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).");
index d66aa20..e9d56e3 100644 (file)
        </select>
       </td>
       <td class="difficulty">
+[% IF !s.chosen %]
+        <input type="hidden" name="song[% pl.player %]-[% s.songnumber %]" value="[% s.song %]" />
+[% END %]      
         <input type="hidden" name="old-difficulty[% pl.player %]-[% s.songnumber %]" value="[% s.difficulty %]" />
        <select name="difficulty[% pl.player %]-[% s.songnumber %]">
          <option value=""> </option>