summaryrefslogtreecommitdiff
path: root/lib/RHRD
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-12-16 17:12:06 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-12-16 17:12:29 (GMT)
commit9f5c6162a22670ffd23b71ff28b4600a249d317b (patch)
treee793bb60e08d4a98b449ee1d35a1c7b9dd3a2514 /lib/RHRD
parent2481a1ff41a5ee7e33807947813ad4672bdcc851 (diff)
added musicpools grid handling functions (not yet finished)
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-xlib/RHRD/rddb.pm80
1 files changed, 76 insertions, 4 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index c5e0a1a..f70a87a 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -1441,13 +1441,85 @@ sub remove_show
sub get_musicpools_cart_range
{
my ($ctx) = @_;
- return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'})
+ return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'});
}
sub get_musicpools_next_free_slot
{
my ($ctx) = @_;
- return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'})
+ return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'allpools'});
+}
+
+sub is_musicpools_user
+{
+ my ($ctx, $username) = @_;
+
+ return 0 if $username = '';
+
+ for my $groupuser (@{$ctx->{'config'}{'specialusers'}{'allpools'}}) {
+ if ($username eq $groupuser) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+sub get_musicpools_clocks
+{
+ my ($ctx) = @_;
+
+ my @reqs;
+ for my $day (0 .. 6){
+ for my $hour (0 .. 23){
+ my $dow = $day + 1;
+ $dow = 0 if $dow >=7;
+ push @reqs, 'select ' . $dow . ' as DOW ,' . $hour . ' as HOUR,CLOCK' . (($day*24) + $hour) .
+ ' as CLOCK from SERVICES where NAME=' . $ctx->{'dbh'}->quote($ctx->{'config'}{'shows'}{'service'});
+ }
+ }
+
+ my $sql = 'select GRID.DOW,GRID.HOUR,CLOCKS.NAME,CLOCKS.SHORT_NAME,CLOCKS.COLOR from CLOCKS,(' . join(' UNION ' , @reqs) . ") as GRID where GRID.CLOCK = CLOCKS.NAME;";
+ print $sql;
+
+ my $sth = $ctx->{'dbh'}->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ my $cnt = $sth->execute()
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+
+ my @clocks;
+ while(my ($dow, $hour, $name, $color) = $sth->fetchrow_array()) {
+ my $clock = {};
+ $clock->{'DOW'} = $dow;
+ $clock->{'HOUR'} = $hour;
+ $clock->{'NAME'} = $name;
+ $clock->{'COLOR'} = $color;
+ $clock->{'TITLE'} = "unknown title"; # TODO: fetch title from Group Description
+ push @clocks, $clock;
+ }
+
+ $sth->finish();
+
+ return @clocks;
+}
+
+sub set_musicpools_clock
+{
+ my ($ctx, $dow, $hour, $name) = @_;
+
+ my $day = $dow - 1;
+ $day = 6 if $dow == 0;
+ my $idx = (($day*24) + $hour);
+
+ my $sql = 'update SERVICES set CLOCK' . $idx . ' = (select NAME from CLOCKS where SHORT_NAME = ?) where NAME = ?'; # TODO: only set if CLOCKS.NAME is not null
+
+ my $rows = $ctx->{'dbh'}->do($sql, $name, $ctx->{'config'}{'shows'}{'service'})
+ or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
+
+ unless($rows == 1) {
+ return (undef, 'ERROR', "clock does not exist")
+ }
+ return (1, 'OK', 'success');
}
########################### JINGLES handling ###########################
@@ -1455,13 +1527,13 @@ sub get_musicpools_next_free_slot
sub get_jingles_cart_range
{
my ($ctx) = @_;
- return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'})
+ return get_cart_range($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'});
}
sub get_jingles_next_free_slot
{
my ($ctx) = @_;
- return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'})
+ return get_next_free_slot($ctx, $ctx->{'config'}{'specialgroups'}{'alljingles'});
}
################################# END ####################################