summaryrefslogtreecommitdiff
path: root/lib/RHRD/rddb.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/RHRD/rddb.pm')
-rwxr-xr-xlib/RHRD/rddb.pm76
1 files changed, 73 insertions, 3 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index c209f81..5df0b6c 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -167,7 +167,7 @@ sub get_next_free_slot
# print " --> " . $slot_name . ": " . $slot_low_cart . " - " . $slot_high_cart . " (" . $slot_chunksize . ")\n";;
if($slot_chunksize != $group_chunksize) {
$sth->finish();
- return (undef, 'ERROR', "show group " . $slot_name . " has wrong chunksize " . $slot_chunksize . " != " . $group_chunksize);
+ return (undef, 'ERROR', "group " . $slot_name . " has wrong chunksize " . $slot_chunksize . " != " . $group_chunksize);
}
if($high_cart < $slot_low_cart) {
@@ -177,6 +177,10 @@ sub get_next_free_slot
}
$sth->finish();
+ if($high_cart > $group_high_cart) {
+ return (undef, 'ERROR', "there are no more free group cart slots");
+ }
+
return ($low_cart, $high_cart);
}
@@ -1755,6 +1759,23 @@ sub get_musicpools_next_free_slot
return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'});
}
+sub get_musicpool_num_from_cart
+{
+ my ($ctx, $cart) = @_;
+
+ my ($group_low_cart, $group_high_cart, $group_chunksize) = get_musicpools_cart_range($ctx);
+ unless (defined $group_low_cart) {
+ return ($group_low_cart, $group_high_cart, $group_chunksize);
+ }
+
+ if ($cart < $group_low_cart || $cart > $group_high_cart) {
+ return (undef, 'ERROR', "cart '$cart' is outside of musicpool range");
+ }
+
+ my $num = int(($cart - $group_low_cart) / $group_chunksize);
+ return ($num, 'OK', 'success');
+}
+
sub list_musicpools
{
my ($ctx) = @_;
@@ -1798,10 +1819,10 @@ sub get_musicpool_info
my ($group, $title, $low_cart, $high_cart, $params) = $sth->fetchrow_array();
$sth->finish();
- return (undef, 'ERROR', "pool $shortname does not exist") unless (defined $params);
+ return (undef, 'ERROR', "pool '$shortname' does not exist") unless (defined $params);
my @p = split(';', $params);
- return (undef, 'ERROR', "pool $shortname does not exist") unless ('M' eq $p[0]);
+ return (undef, 'ERROR', "pool '$shortname' does not exist") unless ('M' eq $p[0]);
my $entry = {};
$entry->{'SHORTNAME'} = $shortname;
@@ -1813,6 +1834,55 @@ sub get_musicpool_info
return ($entry, 'OK', 'success');
}
+sub create_musicpool_group
+{
+ my ($ctx, $groupname) = @_;
+
+ my ($cnt, $status, $errorstring) = add_group($ctx, $groupname);
+ unless(defined $cnt) {
+ return (undef, $status, $errorstring);
+ }
+
+ (my $low_cart, my $high_cart, $errorstring) = get_musicpools_next_free_slot($ctx);
+ if(!$low_cart) {
+ return (undef, $high_cart, $errorstring);
+ }
+ (my $num, $status, $errorstring) = get_musicpool_num_from_cart($ctx, $low_cart);
+ unless(defined $num) {
+ return (undef, $status, $errorstring);
+ }
+
+ ($cnt, $status, $errorstring) = set_group_cart_range($ctx, $groupname, $low_cart, $high_cart, 1, 'Y');
+ unless(defined $cnt) {
+ return (undef, $status, $errorstring);
+ }
+
+ ($cnt, $status, $errorstring) = RHRD::rddb::set_group_reports($ctx, $groupname, 'Y', 'N', 'Y');
+ unless(defined $cnt) {
+ return (undef, $status, $errorstring);
+ }
+
+ my $sql = qq{insert into AUDIO_PERMS (GROUP_NAME, SERVICE_NAME) values (?, ?);};
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ $sth->execute($groupname, $ctx->{'config'}{'shows'}{'service'})
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ $sth->finish();
+
+ my @users = get_group_members($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'});
+ if(!defined $users[0] && defined $users[1]) {
+ return (undef, $users[1], $users[2]);
+ }
+ for my $user (@users) {
+ ($cnt, $status, $errorstring) = RHRD::rddb::add_group_member($ctx, $groupname, $user);
+ return (undef, $status, $errorstring) unless(defined $cnt);
+ }
+
+ return ($num, 'OK', 'success');
+}
+
+
sub is_musicpools_user
{
my ($ctx, $username) = @_;