7 my $dbh = ccbs::db_connect();
10 my $tournament = $cgi->param('tournament');
11 my $round = $cgi->param('round');
12 my $group = $cgi->param('group');
14 $dbh->{AutoCommit} = 0;
16 my $tournamentdata = $dbh->selectrow_hashref('SELECT * FROM tournaments NATURAL JOIN machines WHERE tournament=?',
19 my %checked_songs = ();
21 # Loop through all parameters and see what parameters differ between old- and current
23 for my $p ($cgi->param()) {
24 next if ($p =~ /^old-(.*?)$/);
25 next unless (defined($cgi->param('old-' . $p)));
26 next if ($cgi->param($p) eq $cgi->param('old-' . $p));
28 my $val = $cgi->param($p);
29 undef $val if ($val =~ /^\s*$/);
31 # _Before_ we do changes to the database, check if this is possibly something
32 # that will trigger a foreign key error. There will be an error if the tuple
33 # (song,playmode,difficulty) is set (ie. all members are set) and the combination
34 # doesn't exist in songratings, so check that. However, only check once per
35 # song (or else we'll be doing lots of unneeded database calls).
36 if ($p =~ /^(?:playmode|difficulty|song)(\d+)-(\d+)$/ && !defined($checked_songs{"$1-$2"})) {
37 # check that the entire triple is set
38 if (defined($cgi->param("playmode$1-$2")) && $cgi->param("playmode$1-$2") !~ /^\s*$/ &&
39 defined($cgi->param("difficulty$1-$2")) && $cgi->param("difficulty$1-$2") !~ /^\s*$/ &&
40 defined($cgi->param("song$1-$2")) && $cgi->param("song$1-$2") !~ /^\s*$/) {
41 my $ref = $dbh->selectrow_hashref('SELECT COUNT(*) AS num_songs FROM songratings WHERE song=? AND playmode=? AND difficulty=? AND machine=?',
42 undef, $cgi->param("song$1-$2"), $cgi->param("playmode$1-$2"),
43 $cgi->param("difficulty$1-$2"), $tournamentdata->{'machine'});
44 if ($ref->{'num_songs'} != 1) {
45 # Fetch the name of the song if we can
46 $ref = $dbh->selectrow_hashref('SELECT title FROM songs WHERE song=?',
47 undef, $cgi->param("song$1-$2"));
48 ccbs::user_error("Sangen $ref->{'title'} har ikke steps for " .
49 $cgi->param("playmode$1-$2") . " " . $cgi->param("difficulty$1-$2") . " på ".
50 $tournamentdata->{'machinename'} . ".");
52 $checked_songs{"$1-$2"} = 1;
56 if ($p =~ /^score(\d+)-(\d+)/) {
57 if (defined($val) && ($val < 0 || $val > 10000)) {
58 ccbs::user_error("Alle poengsummer må være mellom 0 og 10000 (inklusive).");
61 $dbh->do('UPDATE scores SET score=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef,
62 $val, $tournament, $round, $group, $1, $2);
63 } elsif ($p =~ /^playmode(\d+)-(\d+)/) {
64 $dbh->do('UPDATE scores SET playmode=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef,
65 $val, $tournament, $round, $group, $1, $2);
66 } elsif ($p =~ /^difficulty(\d+)-(\d+)/) {
67 $dbh->do('UPDATE scores SET difficulty=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef,
68 $val, $tournament, $round, $group, $1, $2);
69 } elsif ($p =~ /^song(\d+)-(\d+)/) {
70 $dbh->do('UPDATE scores SET song=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=? AND chosen=\'t\'', undef,
71 $val, $tournament, $round, $group, $1, $2);
75 $dbh->do('UPDATE bigscreen.active_groups SET last_updated=now() WHERE tournament=? AND round=? AND parallel=?',
76 undef, $tournament, $round, $group);
77 $dbh->do('NOTIFY scores');
82 ccbs::print_see_other('show-tournament.pl?id=' . $tournament . '#round' . $round);