#! /usr/bin/perl

use ccbs;
use strict;
use warnings;

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

my $season = $cgi->param('season');
my $name = $cgi->param('name');
my $country = $cgi->param('country');
my $place = $cgi->param('place');
my $date = $cgi->param('date');
my $machine = $cgi->param('machine');
my $scoringsystem = $cgi->param('scoringsystem');

if ($date !~ /^ ( \d{4} - \d\d - \d\d ) $/x) {
	ccbs::user_error("Ugyldig dato (må være på formen YYYY-MM-DD).");
}

$dbh->do('INSERT INTO tournaments (season, tournamentname, country, location, date, machine, scoringsystem) VALUES (?,?,?,?,?,?,?)',
	undef, $season, $name, $country, $place, $date, $machine, $scoringsystem);

ccbs::print_header();
ccbs::process_template('do-add-tournament.tmpl', 'Legg til turnering', {});

$dbh->disconnect;
