diff options
author | Christian Pointner <equinox@spreadspace.org> | 2015-12-17 16:26:17 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2015-12-17 16:26:17 (GMT) |
commit | 62488862215502f7e96fa7e40ab7ac66d0766a13 (patch) | |
tree | 6184fe7af38764c0e8ee406f69f83bda270de85e /lib/RHRD | |
parent | 9f5c6162a22670ffd23b71ff28b4600a249d317b (diff) |
setting music pool clock works now and get returns title as well
Diffstat (limited to 'lib/RHRD')
-rwxr-xr-x | lib/RHRD/rddb.pm | 33 |
1 files changed, 23 insertions, 10 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index f70a87a..cd0374a 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -1454,7 +1454,7 @@ sub is_musicpools_user { my ($ctx, $username) = @_; - return 0 if $username = ''; + return 0 if $username eq ''; for my $groupuser (@{$ctx->{'config'}{'specialusers'}{'allpools'}}) { if ($username eq $groupuser) { @@ -1478,8 +1478,7 @@ sub get_musicpools_clocks } } - 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 $sql = 'select GRID.DOW,GRID.HOUR,CLOCKS.SHORT_NAME,CLOCKS.COLOR,GROUPS.DESCRIPTION from DROPBOXES,GROUPS,CLOCKS,(' . join(' UNION ' , @reqs) . ") as GRID where GRID.CLOCK = CLOCKS.NAME and CLOCKS.SHORT_NAME = DROPBOXES.PATH and DROPBOXES.GROUP_NAME = GROUPS.NAME;"; my $sth = $ctx->{'dbh'}->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); @@ -1488,13 +1487,13 @@ sub get_musicpools_clocks or return (undef, 'ERROR', "Database Error: " . $sth->errstr); my @clocks; - while(my ($dow, $hour, $name, $color) = $sth->fetchrow_array()) { + while(my ($dow, $hour, $shortname, $color, $title) = $sth->fetchrow_array()) { my $clock = {}; $clock->{'DOW'} = $dow; $clock->{'HOUR'} = $hour; - $clock->{'NAME'} = $name; + $clock->{'SHORTNAME'} = $shortname; $clock->{'COLOR'} = $color; - $clock->{'TITLE'} = "unknown title"; # TODO: fetch title from Group Description + $clock->{'TITLE'} = $title; push @clocks, $clock; } @@ -1505,15 +1504,29 @@ sub get_musicpools_clocks sub set_musicpools_clock { - my ($ctx, $dow, $hour, $name) = @_; + my ($ctx, $dow, $hour, $shortname) = @_; + + my $sql = qq{select NAME from CLOCKS where SHORT_NAME = ?;}; + + my $sth = $ctx->{'dbh'}->prepare($sql) + or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); + + $sth->execute($shortname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + + my ($name) = $sth->fetchrow_array; + $sth->finish(); + + if(!defined $name) { + return (undef, 'ERROR', "clock '" . $shortname . "' does not exist"); + } my $day = $dow - 1; $day = 6 if $dow == 0; my $idx = (($day*24) + $hour); + $sql = 'update SERVICES set CLOCK' . $idx . ' = ? where NAME = ?'; - 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'}) + my $rows = $ctx->{'dbh'}->do($sql, undef, $name, $ctx->{'config'}{'shows'}{'service'}) or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr); unless($rows == 1) { |