summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2015-10-07 01:56:44 (GMT)
committerChristian Pointner <equinox@spreadspace.org>2015-10-07 01:56:44 (GMT)
commita67de4921bd05a567e5957729f1e2d06358d1218 (patch)
treef75ae3465dc318059614a75e1b1b95b55247639d /lib
parentfdb8d0f78ad94dbaa352c6bb096cbf63863dfe7d (diff)
moved some parts of add show command to rddb
Diffstat (limited to 'lib')
-rwxr-xr-xlib/RHRD/rddb.pm84
1 files changed, 76 insertions, 8 deletions
diff --git a/lib/RHRD/rddb.pm b/lib/RHRD/rddb.pm
index 1064505..14c21a1 100755
--- a/lib/RHRD/rddb.pm
+++ b/lib/RHRD/rddb.pm
@@ -806,19 +806,37 @@ sub get_dropboxes
{
my ($ctx, $username, $groupname, $type) = @_;
- 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) {
+ my $sql;
+ if(defined $username && !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 = ?;};
+ }
+ elsif(defined $username && 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 = ?;};
}
+ elsif(!defined $username && defined $groupname) {
+ $sql = qq{select GROUPS.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 DROPBOXES, GROUPS where DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ? and GROUPS.NAME = ?;};
+ }
+ else {
+ $sql = qq{select GROUPS.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 DROPBOXES, GROUPS where DROPBOXES.GROUP_NAME=GROUPS.NAME and DROPBOXES.STATION_NAME = ?;};
+ }
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
- if(defined $groupname) {
+ if(defined $username && !defined $groupname) {
+ $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ }
+ elsif(defined $username && defined $groupname) {
$sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname)
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
- } else {
- $sth->execute($username, $ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
+ }
+ elsif(!defined $username && defined $groupname) {
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'}, $groupname)
+ or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ }
+ else {
+ $sth->execute($ctx->{'config'}{'dropboxes'}{'dropbox-pseudo-station'})
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
}
@@ -885,7 +903,7 @@ sub list_shows
{
my ($ctx) = @_;
- my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=?;};
+ my $sql = qq{select TO_CART,SET_USER_DEFINED from DROPBOXES where STATION_NAME=? order by TO_CART;};
my $sth = $ctx->{'dbh'}->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $ctx->{'dbh'}->errstr);
@@ -920,7 +938,7 @@ sub list_shows
return @show_dbs;
}
-sub get_show_group_carts
+sub get_show_group_cart_range
{
my ($ctx, $showid) = @_;
@@ -938,6 +956,56 @@ sub get_show_group_carts
return ($group_low_cart, $group_high_cart, 'OK', 'success');
}
+sub get_show_group_carts_used
+{
+ my ($ctx, $groupname) = @_;
+
+ my @dropboxes = RHRD::rddb::get_dropboxes($ctx, undef, $groupname, 'S');
+ if(!defined $dropboxes[0]) {
+ if(defined $dropboxes[1]) {
+ return (undef, $dropboxes[1], $dropboxes[2]);
+ }
+ return ();
+ }
+
+ my @carts = ();
+ for my $db (@dropboxes) {
+ my @show_carts = RHRD::rddb::get_show_carts($ctx, $db->{'SHOWID'});
+ if(!defined $show_carts[0] && defined $show_carts[1]) {
+ return (undef, $show_carts[1], $show_carts[2]);
+ }
+ @carts = (@carts, @show_carts) if defined($show_carts[0])
+ }
+
+ return sort(@carts);
+}
+
+sub get_next_free_show_group_carts
+{
+ my ($ctx, $groupname, $num_carts) = @_;
+
+ my ($low_cart, $high_cart, $type, undef) = get_group_cart_range($ctx, $groupname);
+ unless(defined $low_cart) {
+ return (undef, $high_cart, $type);
+ }
+
+ my @carts = get_show_group_carts_used($ctx, $groupname);
+ if(!defined $carts[0] && defined $carts[1]) {
+ return (undef, $carts[1], $carts[2]);
+ }
+
+ for my $cart (@carts) {
+ last if(($low_cart + $num_carts - 1) < $cart);
+ $low_cart = $cart + 1;
+ }
+ if(($low_cart + $num_carts -1) > $high_cart) {
+ return (undef, 'ERROR', 'not enough free carts left in group');
+ }
+
+ return ($low_cart, 'OK', 'success');
+}
+
+
sub get_show_title_and_log
{
my ($ctx, $showid) = @_;
@@ -971,7 +1039,7 @@ sub get_show_carts
{
my ($ctx, $showid) = @_;
- my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_carts($ctx, $showid);
+ my ($group_low_cart, $group_high_cart, $status, $errorstring) = get_show_group_cart_range($ctx, $showid);
unless (defined $group_low_cart && defined $group_high_cart) {
return (undef, $status, $errorstring);
}