From 1283d78ec24c3b4e084409610e4711015044ce58 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 31 Jul 2016 14:12:14 +0200 Subject: print used carts for musicpools diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index b576ad4..de34bbd 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -2284,6 +2284,32 @@ sub remove_musicpool return @actions; } +sub get_musicpool_carts_used +{ + my ($ctx, $shortname) = @_; + + my ($groupname, $status, $errorstring) = get_musicpool_group($ctx, $shortname); + unless (defined $groupname) { + return (undef, $status, $errorstring); + } + + 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($groupname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my @carts; + while(my ($cart) = $sth->fetchrow_array()) { + push @carts, $cart; + } + $sth->finish(); + + return @carts; +} + sub is_musicgrid_user { my ($ctx, $username) = @_; diff --git a/utils/rhrd-pool b/utils/rhrd-pool index 1534af6..dc85f94 100755 --- a/utils/rhrd-pool +++ b/utils/rhrd-pool @@ -58,8 +58,14 @@ sub show print STDERR "$errorstring\n"; return 1; } + my @carts = RHRD::rddb::get_musicpool_carts_used($ctx, $shortname); + if(!defined $carts[0] && defined $carts[1]) { + print STDERR "$carts[1]: $carts[2]"; + return 1; + } + print $pool->{'TITLE'} . " (" . $pool->{'SHORTNAME'} . "):\n"; - print " group: " . $pool->{'GROUP'} . ", carts: " . $pool->{'LOW_CART'} . "-" . $pool->{'HIGH_CART'} . "\n"; # TODO print info about cart usage + print " group: " . $pool->{'GROUP'} . ", carts: " . $pool->{'LOW_CART'} . "-" . $pool->{'HIGH_CART'} . " (" . scalar(@carts) . " used)\n"; return 0; } -- cgit v0.10.2