summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/rddb.pm66
1 files changed, 40 insertions, 26 deletions
diff --git a/lib/rddb.pm b/lib/rddb.pm
index f307d51..226c415 100755
--- a/lib/rddb.pm
+++ b/lib/rddb.pm
@@ -56,16 +56,16 @@ sub check_token
my $sql = qq{select PASSWORD from USERS where LOGIN_NAME = ?;};
my $sth = $dbh->prepare($sql)
- or return (0, 'ERROR', "Database Error: " . $dbh->errstr);
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
$sth->execute($username)
- or return (0, 'ERROR', "Database Error: " . $sth->errstr);
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
my ($token_result) = $sth->fetchrow_array;
$sth->finish();
unless(defined $token_result) {
- return (0, 'ERROR', "user '" . $username . "' not known by rivendell")
+ return (undef, 'ERROR', "user '" . $username . "' not known by rivendell")
}
if($token_result == $token) {
@@ -74,36 +74,50 @@ sub check_token
return (0, 'ERROR', "wrong password");
}
-sub get_cart_range
+sub get_dropboxes
{
- my ($dbh, $group) = @_;
-
- my $sql = qq{select DEFAULT_LOW_CART,DEFAULT_HIGH_CART from GROUPS where NAME = ?;};
- my $sth = $dbh->prepare($sql)
- or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr);
-
- $sth->execute($group)
- or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr);
+ my ($dbh, $username) = @_;
- my ($low_cart, $high_cart) = $sth->fetchrow_array();
- $sth->finish();
+ my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH,DROPBOXES.TO_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;};
- unless(defined $low_cart && defined $high_cart) {
- return (undef, undef, 'ERROR', "group '" . $group . "' not known by rivendell")
- }
- return ($low_cart, $high_cart, 'OK', 'success');
-}
+ my $sth = $dbh->prepare($sql)
+ or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
-sub get_num_carts
-{
- my ($dbh, $group) = @_;
+ $sth->execute($username)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
- my ($low_cart, $high_cart, $status, $errorstring) = get_cart_range($dbh, $group);
- unless(defined $low_cart && defined $high_cart) {
- return (undef, $status, $errorstring);
+ my @allowed_dbs;
+ while(my ($group, $path, $to_cart, $desc) = $sth->fetchrow_array()) {
+ $path =~ s/\/\*$//;
+ my $name = $path;
+ if($name =~ /^([0-9]{2}-[A-Za-z]+)\/([0-9]{2})([0-9]{2})-([01]{4})-([0-9]{3})\/(.*)$/) {
+ $name = "$1 - $2:$3 - $6 ($4, $5)";
+ }
+ elsif($name =~ /^([0-9]{2}-[A-Za-z]+)\/jingle$/ || $name =~ /^jingles\/(.*)$/) {
+ $name = "Jingles - $1";
+ }
+ elsif($name =~ /^pool\/pool(.*)$/) {
+ $name = "Pool $1 - $desc";
+ }
+ elsif($name =~ /^pool\/(.*)$/) {
+ $name = "Pool - $1";
+ }
+ elsif($name =~ /^sondersendungen\/(.*)$/) {
+ $name = "Sondersendungen - $1";
+ }
+ elsif($name =~ /^autoimport\/(.*)$/) {
+ $name = "autoimport - $1";
+ }
+ my $perm = {};
+ $perm->{'GROUP'} = $group;
+ $perm->{'PATH'} = $path;
+ $perm->{'TO_CART'} = $to_cart;
+ $perm->{'NAME'} = $name;
+ push @allowed_dbs, $perm;
}
+ $sth->finish();
- return ($high_cart - $low_cart + 1, 'OK', 'success');
+ return sort { uc($a->{'NAME'}) cmp uc($b->{'NAME'}) } @allowed_dbs;
}