diff options
Diffstat (limited to 'lib')
-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) { |