diff options
-rw-r--r-- | README | 4 | ||||
-rwxr-xr-x | lib/RHRD/rddb.pm | 86 | ||||
-rwxr-xr-x | utils/rhrd-show | 65 |
3 files changed, 152 insertions, 3 deletions
@@ -13,8 +13,10 @@ CART RANGES: | 1000 | Jingles (2 Carts each) 3000 --+----------+ | | - | 7000 | <unused> + | 5000 | <unused> | | + 8000 --+----------+ + | 2000 | Multi-Show 10000 --+----------+ | | | 10000 | Show Macros diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 7c5bae3..62f43bd 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -54,6 +54,7 @@ sub init or return (undef , 'ERROR', "RHRD Config File Error: " . join("\n", @Config::IniFiles::errors)); $ctx{'config'}{'specialgroups'}{'system'} = $cfg->val('specialgroups', 'system', 'SYSTEM'); + $ctx{'config'}{'specialgroups'}{'multishows'} = $cfg->val('specialgroups', 'multishows', 'MULTISHOWS'); $ctx{'config'}{'specialgroups'}{'shows'} = $cfg->val('specialgroups', 'shows', 'SHOWS'); $ctx{'config'}{'specialgroups'}{'allshows'} = $cfg->val('specialgroups', 'allshows', 'ALL_SHOWS'); $ctx{'config'}{'specialgroups'}{'allpools'} = $cfg->val('specialgroups', 'allpools', 'ALL_POOLS'); @@ -1839,6 +1840,9 @@ sub create_show_macro_cart my $macro = 'LL 1 ' . $logname . ' 0!'; my ($number, $status, $errorstring) = get_next_free_showid($ctx); + unless (defined $number) { + return (undef, $status, $errorstring); + } my $sql = qq{insert into CART (NUMBER, TYPE, GROUP_NAME, TITLE, MACROS, VALIDITY, METADATA_DATETIME) values (?, 2, ?, ?, ?, 3, NOW())}; @@ -1961,6 +1965,86 @@ sub remove_show return @actions; } +sub list_multi_shows +{ + my ($ctx) = @_; + + my $sql = qq{select NUMBER,TITLE,USER_DEFINED from CART where GROUP_NAME = ? order by NUMBER}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($ctx->{'config'}{'specialgroups'}{'multishows'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @mshows; + while(my ($id, $title, $shows) = $sth->fetchrow_array()) { + my @showlist = split(';', $shows); # TODO split this further... + + my $entry = {}; + $entry->{'ID'} = $id; + $entry->{'TITLE'} = $title; + $entry->{'SHOWS'} = @showlist; + + push @mshows, $entry; + } + $sth->finish(); + + return @mshows; +} + +sub get_next_free_multi_showid +{ + my ($ctx) = @_; + + my ($low, $high, $type, undef) = RHRD::rddb::get_group_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'multishows'}); + unless(defined $low) { + return (undef, $high, $type); + } + + my $sql = qq{select NUMBER from CART where GROUP_NAME = ? order by NUMBER}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($ctx->{'config'}{'specialgroups'}{'multishows'}) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my $showid = $low; + while(my ($cart) = $sth->fetchrow_array()) { + last if($showid < $cart); + $showid += 1; + } + $sth->finish(); + + return ($showid, 'OK', 'success'); +} + +sub create_multi_show +{ + my $ctx = shift; + my $title = shift; + my $shows = join(@_, ";"); + + my ($number, $status, $errorstring) = get_next_free_multi_showid($ctx); + unless (defined $number) { + return (undef, $status, $errorstring); + } + + my $sql = qq{insert into CART (NUMBER, TYPE, GROUP_NAME, TITLE, USER_DEFINED, VALIDITY, METADATA_DATETIME) values (?, 2, ?, ?, ?, 3, NOW())}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($number, $ctx->{'config'}{'specialgroups'}{'multishows'}, $title, $shows) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + $sth->finish(); + + return ($number, 'OK', 'success'); +} + + ########################### MUSICPOOL handling ########################### sub get_musicpools_cart_range @@ -2209,8 +2293,8 @@ sub create_musicpool_clock push @events, { NAME => $shortname, START_TIME => $t, LENGTH => 142500 }; $t += 142500; if($i > 0 && ($i % 8) == 0) { - $t += 60000; # TODO: push jingle event + $t += 60000; } } diff --git a/utils/rhrd-show b/utils/rhrd-show index c52d63d..0c87c1e 100755 --- a/utils/rhrd-show +++ b/utils/rhrd-show @@ -21,17 +21,25 @@ # use strict; +use lib "../lib/"; use RHRD::rddb; use RHRD::utils; use Date::Calc; +use Data::Dumper::Simple; + sub print_usage { print STDERR "Usage: rhrd-show list [ <group> ]\n" . " rhrd-show search <expression>\n" . " rhrd-show (show|remove) <show-id>\n" . " rhrd-show add <groupname> <name> <title> <num-carts> <rhythm> <dow> <starttime> <len>\n" . - " rhrd-show edit <show-id> <title> <rhythm> <dow> <starttime> <len>\n"; + " rhrd-show edit <show-id> <title> <rhythm> <dow> <starttime> <len>\n" . + " multi show handling:\n" . + " rhrd-show multi-list\n" . + " rhrd-show (multi-show|multi-remove) <multi-show-id>\n" . + " rhrd-show (multi-add) <title> <show-id> [ <show-id> [ .. ] ]\n" . + " rhrd-show (multi-add-id|multi-remove-id) <multi-show-id> <show-id> [ <show-id> [ .. ] ]\n"; } sub list @@ -306,6 +314,43 @@ sub remove return 0; } +sub multi_list +{ + my ($ctx) = @_; + + my @mshows = RHRD::rddb::list_multi_shows($ctx); + if(!defined $mshows[0] && defined $mshows[1]) { + print STDERR "$mshows[1]: $mshows[2]"; + return 1; + } + my @sorted = sort { lc($a->{'TITLE'}) cmp lc($b->{'TITLE'}) } @mshows; + for my $href (@sorted) { + print $href->{'ID'} . ": " . Dumper($href) . "\n"; +# print $href->{'ID'} . ": " . $href->{'TITLE'} . ": (" . join(@$href->{'SHOWS'}, ", ") . ")\n"; + } + return 0; +} + + +sub multi_add +{ + my $ctx = shift; + my $title = shift; + my @shows = @_; + + ## TODO check shows: needs to have format <week>:<showid> + + my ($result, $status, $errorstring) = RHRD::rddb::create_multi_show($ctx, $title, @shows); + unless(defined $result) { + print STDERR $status . ": " . $errorstring . "\n"; + return 1; + } + + return 0; +} + + + my $num_args = $#ARGV + 1; if($num_args < 1) { print_usage(); @@ -364,6 +409,24 @@ if(defined $ctx) { $ret = edit($ctx, $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6]); } } + elsif($cmd eq "multi-list") { + if($num_args != 1) { + print_usage(); + $ret = 1; + } else { + $ret = multi_list($ctx) + } + } + elsif($cmd eq "multi-add") { + if($num_args < 3) { + print_usage(); + $ret = 1; + } else { + shift @ARGV; + my $title = shift @ARGV; + $ret = multi_add($ctx, $title, @ARGV) + } + } else { print_usage(); $ret = 1; |