From 222541ee6348f21a0b8107bebb3701422614ba88 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 27 Sep 2015 05:16:04 +0200 Subject: get_dropboxes can now look optionally look for a specific group diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm index a052080..a337557 100755 --- a/lib/RHRD/rddb.pm +++ b/lib/RHRD/rddb.pm @@ -567,15 +567,23 @@ sub get_showtitle_and_log sub get_dropboxes { - my ($dbh, $username) = @_; + my ($dbh, $username, $groupname) = @_; my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=?;}; + if(defined $groupname) { + $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.TO_CART,DROPBOXES.NORMALIZATION_LEVEL,DROPBOXES.AUTOTRIM_LEVEL,DROPBOXES.SET_USER_DEFINED,GROUPS.DEFAULT_LOW_CART,GROUPS.DEFAULT_HIGH_CART,GROUPS.DESCRIPTION from USER_PERMS, DROPBOXES, GROUPS where USER_PERMS.USER_NAME=? and DROPBOXES.GROUP_NAME=USER_PERMS.GROUP_NAME and DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME=? and GROUPS.NAME=?;}; + } my $sth = $dbh->prepare($sql) or return (undef, 'ERROR', "Database Error: " . $dbh->errstr); - $sth->execute($username, DROPBOX_PSEUDO_STATION_NAME) - or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + if(defined $groupname) { + $sth->execute($username, DROPBOX_PSEUDO_STATION_NAME, $groupname) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + } else { + $sth->execute($username, DROPBOX_PSEUDO_STATION_NAME) + or return (undef, 'ERROR', "Database Error: " . $sth->errstr); + } my @allowed_dbs; while(my ($group, $to_cart, $normlevel, $trimlevel, $params, $lowcart, $highcart, $groupdesc) = $sth->fetchrow_array()) { diff --git a/test/get-dropboxes b/test/get-dropboxes new file mode 100755 index 0000000..6282a92 --- /dev/null +++ b/test/get-dropboxes @@ -0,0 +1,73 @@ +#!/usr/bin/perl -w +# +# rhrdlibs +# +# Copyright (C) 2015 Christian Pointner +# +# This file is part of rhrdlibs. +# +# rhrdlibs is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# rhrdlibs is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with rhrdlibs. If not, see . +# + +use strict; +use lib "../lib/"; + +use POSIX; +use RHRD::rddb; + + +my $username = $ARGV[0]; +my $groupname = $ARGV[1]; + +my @dropboxes = (); +my ($dbh, $status, $errorstring) = RHRD::rddb::opendb(); +if(defined $dbh) { + @dropboxes = RHRD::rddb::get_dropboxes($dbh, $username, $groupname); + if(!defined $dropboxes[0] && defined $dropboxes[1]) { + print STDERR "$dropboxes[1]: $dropboxes[2]"; + RHRD::rddb::closedb($dbh); + exit 1; + } + RHRD::rddb::closedb($dbh); +} else { + print STDERR "$errorstring\n"; + exit 1; +} + + +print "Dropboxes:\n"; +for my $href (@dropboxes) { + print " * group:" . $href->{'GROUP'} . "\n"; + print " group-description:" . $href->{'GROUPDESC'} . "\n"; + print " group-low-cart:" . $href->{'GROUPLOWCART'} . "\n"; + print " group-high-cart:" . $href->{'GROUPHIGHCART'} . "\n"; + print " normalization-level:" . floor($href->{'NORMLEVEL'}/100) . "\n"; + print " autotrim-level:" . floor($href->{'TRIMLEVEL'}/100) . "\n"; + print " parameters:" . $href->{'PARAM'} . "\n"; + print " type:" . $href->{'TYPE'} . "\n"; + if($href->{'TYPE'} eq "show") { + print " show-id:" . $href->{'SHOWID'} . "\n"; + print " show-title:" . $href->{'SHOWTITLE'} . "\n"; + print " show-log:" . $href->{'SHOWLOG'} . "\n"; + print " show-rhythm:" . $href->{'SHOWRHYTHM'} . "\n"; + print " show-dayofweek:" . $href->{'SHOWDOW'} . "\n"; + print " show-starttime:" . $href->{'SHOWSTARTTIME'} . "\n"; + print " show-length:" . $href->{'SHOWLEN'} . "\n"; + } elsif($href->{'TYPE'} eq "jingle") { + print " jingle-title:" . $href->{'JINGLETITLE'} . "\n"; + } elsif($href->{'TYPE'} eq "musicpool") { + print " musicpool-title:" . $href->{'MUSICPOOLTITLE'} . "\n"; + } + print "\n"; +} -- cgit v0.10.2