summaryrefslogtreecommitdiff
path: root/lib/RHRD
diff options
context:
space:
mode:
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-xlib/RHRD/rddb.pm76
-rwxr-xr-xlib/RHRD/utils.pm12
2 files changed, 83 insertions, 5 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) = @_;
diff --git a/lib/RHRD/utils.pm b/lib/RHRD/utils.pm
index d06e1ce..bcdac56 100755
--- a/lib/RHRD/utils.pm
+++ b/lib/RHRD/utils.pm
@@ -72,7 +72,7 @@ use constant {
CMDLINE_DOW_HINT => "must be one of MO, TU, WE, TH, FR, SA, SU",
# this is a subset of the colors from: stackoverflow.com/questions/2328339
- POOL_COLORS => ["FFFF00", "1CE6FF", "FF34FF", "FF4A46", "008941", "006FA6", "A30059",
+ POOL_COLORS => ["FFFFFF", "FFFF00", "1CE6FF", "FF34FF", "FF4A46", "008941", "006FA6",
"FFDBE5", "7A4900", "0000A6", "63FFAC", "B79762", "004D43", "8FB0FF",
"5A0007", "809693", "FEFFE6", "4FC601", "3B5DFF", "4A3B53", "FF2F80",
"61615A", "BA0900", "6B7900", "00C2A0", "FFAA92", "FF90C9", "B903AA",
@@ -81,7 +81,7 @@ use constant {
"00489C", "6F0062", "0CBD66", "EEC3FF", "B77B68", "7A87A1", "788D66",
"885578", "FAD09F", "FF8A9A", "D157A0", "BEC459", "0086ED", "886F4C",
"549E79", "FFF69F", "72418F", "BC23FF", "99ADC0", "3A2465", "922329",
- "5B4534", "FDE8DC", "404E55", "0089A3", "CB7E98", "A4E804", "324E72",
+ "5B4534", "404E55", "0089A3", "CB7E98", "A4E804", "324E72", "A30059",
"B4A8BD", "452C2C", "636375", "A3C8C9", "9B9700", "D0AC94", "FF6832",
"575329", "00FECF", "B05B6F", "8CD0FF", "1E6E00", "66E1D3", "CFCDAC",
"A77500", "6367A9", "A05837", "772600", "D790FF", "5B4E51", "8ADBB4",
@@ -89,6 +89,14 @@ use constant {
"DA007C", "FF1A59"]
};
+sub get_musicpool_color
+{
+ my ($num) = @_;
+
+ $num = 0 if($num < 0 || $num > $#{+POOL_COLORS});
+ return POOL_COLORS->[$num];
+}
+
sub dropbox_param_type_ok
{
my ($type) = @_;