]> git.sesse.net Git - ccbs/blob - html/do-edit-scores.pl
Make it possible to enter NULL values by leaving fields blank.
[ccbs] / html / do-edit-scores.pl
1 #! /usr/bin/perl
2
3 use ccbs;
4 use strict;
5 use warnings;
6
7 my $dbh = ccbs::db_connect();
8 my $cgi = new CGI;
9
10 my $tournament = $cgi->param('tournament');
11 my $round = $cgi->param('round');
12 my $group = $cgi->param('group');
13
14 $dbh->{AutoCommit} = 0;
15
16 # Loop through all parameters and see what parameters differ between old- and current
17 # versions
18 for my $p ($cgi->param()) {
19         next if ($p =~ /^old-(.*?)$/);
20         next unless (defined($cgi->param('old-' . $p)));
21         next if ($cgi->param($p) eq $cgi->param('old-' . $p));
22
23         my $val = $cgi->param($p);
24         undef $val if ($val =~ /^\s*$/);
25
26         if ($p =~ /^score(\d+)-(\d+)/) {
27                 $dbh->do('UPDATE scores SET score=? WHERE tournament=? AND round=? AND parallel=? AND player=? AND songnumber=?', undef,
28                         $val, $tournament, $round, $group, $1, $2);
29         }
30 }
31
32 $dbh->commit;
33 $dbh->disconnect;
34
35 ccbs::print_see_other('show-tournament.pl?id=' . $tournament);
36