diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-09-29 16:09:47 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-09-29 16:09:47 (GMT) |
commit | efb5d6557591ef21c27aa46aae220d862c36feeb (patch) | |
tree | 2b5e0f17d28a8687b74383e9a24a4f921ed25156 /lib | |
parent | 15db57fb8eb839f48763394f73709a1d5952131b (diff) |
implemented show show and list
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/RHRD/rddb.pm | 173 |
1 files changed, 121 insertions, 52 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index 09b307b..3957459 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -626,44 +626,15 @@ sub list_groups return @groups; } -########################### SHOW handling ########################### - -sub get_showtitle_and_log -{ - my ($dbh, $showid) = @_; - - my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;}; - my $sth = $dbh->prepare($sql) - or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); - - $sth->execute($showid) - or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); - - my ($title, $macros) = $sth->fetchrow_array; - $sth->finish(); - - unless(defined $title) { - return (undef, undef, 'ERROR', "Show with ID=" . $showid . " not found!") - } - unless(defined $macros) { - return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has no macro!"); - } - - unless($macros =~ /^LL 1 ([^ ]+) 0\!$/) { - return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has invalid macro: '" . $macros . "'"); - } - my $log = $1; - - return ($title, $log, 'OK', 'success'); -} +########################### Dropboxes handling ###################### sub get_dropboxes { my ($dbh, $username, $groupname, $type) = @_; - my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=?;}; + my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;}; if(defined $groupname) { - $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=? and GROUPS.NAME=?;}; + $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME = ? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=? and GROUPS.NAME = ?;}; } my $sth = $dbh->prepare($sql) @@ -694,7 +665,7 @@ sub get_dropboxes $entry->{'TYPE'} = 'show'; $entry->{'SHOWID'} = $to_cart; - my ($title, $log, $status, $errorstring) = get_showtitle_and_log($dbh, $to_cart); + my ($title, $log, $status, $errorstring) = get_show_title_and_log($dbh, $to_cart); unless (defined $title && defined $log) { return (undef, $status, $errorstring); } @@ -722,27 +693,137 @@ sub get_dropboxes return @allowed_dbs; } +########################### SHOW handling ########################### + +sub get_shows_cart_range +{ + my ($dbh) = @_; + return get_cart_range($dbh, RHRD_ALLSHOWS_GROUP) +} + +sub get_shows_next_free_slot +{ + my ($dbh) = @_; + return get_next_free_slot($dbh, RHRD_ALLSHOWS_GROUP) +} + +sub list_shows +{ + my ($dbh) = @_; + + my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=?;}; + + my $sth = $dbh->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute(DROPBOX_PSEUDO_STATION_NAME) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @show_dbs; + while(my ($to_cart, $params, $lowcart, $highcart) = $sth->fetchrow_array()) { + my @p = split(';', $params); + next if ('S' ne $p[0]); + + my $entry = {}; + $entry->{'ID'} = $to_cart; + my ($title, $log, $status, $errorstring) = get_show_title_and_log($dbh, $to_cart); + unless (defined $title && defined $log) { + return (undef, $status, $errorstring); + } + $entry->{'TITLE'} = $title; + $entry->{'LOG'} = $log; + $entry->{'RHYTHM'} = $p[1]; + $entry->{'DOW'} = int $p[2]; + $entry->{'DOW'} = 0 unless $entry->{'DOW'} < 7; + substr($p[3], 2, 0) = ':'; + $entry->{'STARTTIME'} = $p[3]; + $entry->{'LEN'} = int $p[4]; + + push @show_dbs, $entry; + } + $sth->finish(); + + return @show_dbs; +} + +sub get_show_group_carts +{ + my ($dbh, $showid) = @_; + + my $sql = qq{select GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART from DROPBOXES, GROUPS where DROPBOXES.TO_CART = ? and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($showid, DROPBOX_PSEUDO_STATION_NAME) + or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($group_low_cart, $group_high_cart) = $sth->fetchrow_array(); + unless(defined($group_low_cart) && defined($group_high_cart)) { + return (undef, undef, 'ERROR', "Show not found"); + } + return ($group_low_cart, $group_high_cart, 'OK', 'success'); +} + +sub get_show_title_and_log +{ + my ($dbh, $showid) = @_; + + my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;}; + my $sth = $dbh->prepare($sql) + or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr); + + $sth->execute($showid) + or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($title, $macros) = $sth->fetchrow_array; + $sth->finish(); + + unless(defined $title) { + return (undef, undef, 'ERROR', "Show with ID=" . $showid . " not found!") + } + unless(defined $macros) { + return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has no macro!"); + } + + unless($macros =~ /^LL 1 ([^ ]+) 0\!$/) { + return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has invalid macro: '" . $macros . "'"); + } + my $log = $1; + + return ($title, $log, 'OK', 'success'); +} + sub get_show_carts { - my ($dbh, $logname, $group_low_cart, $group_high_cart) = @_; + my ($dbh, $showid) = @_; + + my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_carts($dbh, $showid); + unless (defined $group_low_cart && defined $group_high_cart) { + return (undef, $status, $errorstring); + } + + (undef, my $log, $status, $errorstring) = get_show_title_and_log($dbh, $showid); + unless (defined $log) { + return (undef, $status, $errorstring); + } my $sql = qq{select LOG_EXISTS from LOGS where NAME = ?;}; my $sth = $dbh->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); - $sth->execute($logname) + $sth->execute($log) or return (undef, 'ERROR', "Database Error: " . $sth->errstr); - my $log_exists = $sth->fetchrow_array; + my $log_exists = $sth->fetchrow_array(); $sth->finish(); if(!defined $log_exists || $log_exists ne 'Y') { - return (undef, 'ERROR', "Log with name '$logname' does not exist") + return (undef, 'ERROR', "Log with name '$log' does not exist") } - $logname=~s/ /_/g; - $logname = $dbh->quote_identifier($logname . '_LOG'); - $sql = qq{select COUNT,CART_NUMBER from $logname order by COUNT;}; + $log=~s/ /_/g; + $log = $dbh->quote_identifier($log . '_LOG'); + $sql = qq{select COUNT,CART_NUMBER from $log order by COUNT;}; $sth = $dbh->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); @@ -761,18 +842,6 @@ sub get_show_carts return @carts; } -sub get_shows_cart_range -{ - my ($dbh) = @_; - return get_cart_range($dbh, RHRD_ALLSHOWS_GROUP) -} - -sub get_shows_next_free_slot -{ - my ($dbh) = @_; - return get_next_free_slot($dbh, RHRD_ALLSHOWS_GROUP) -} - ########################### MUSICPOOL handling ########################### sub get_musicpools_cart_range |