#! /usr/bin/perl

use ccbs;
use strict;
use warnings;

ccbs::admin_only();

my $dbh = ccbs::db_connect();
my $cgi = new CGI;

# This is ugly, but we don't need more than one people updating this at a
# time anyhow (we hope).
$dbh->{AutoCommit} = 0;
$dbh->{RaiseError} = 1;
$dbh->do('DELETE FROM songshorttitles');

for my $p ($cgi->param()) {
	$p =~ /^st(\d+)$/ or next;
	my $num = $1;
	my $st = $cgi->param($p);

	my $q = $dbh->prepare('INSERT INTO songshorttitles (song, shorttitle) VALUES (?, ?)');
	if ($st !~ /^\s*$/) {
		$q->execute($num, $st);
	}
}

# This will make the big screen use the new short titles, if it needs them
$dbh->do('NOTIFY scores');

$dbh->commit;

$dbh->disconnect;

ccbs::print_see_other('shorttitles.pl');

