summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-09-21 03:08:37 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-09-21 03:08:37 (GMT)
commit68c56aa6633257c9ca9af0cb25df2a9672662b32 (patch)
treea841df32774e4dcffb5bd0a9d0fe3c718cfa683e
parentf4059249c81e3c88b750aad69e834d1ad8e96b41 (diff)
refactored show log specification
-rw-r--r--js/shows.js4
-rwxr-xr-xlib/rddb.pm56
-rwxr-xr-xlistdropboxes.cgi19
3 files changed, 46 insertions, 33 deletions
diff --git a/js/shows.js b/js/shows.js
index 1bf7c3b..03af34f 100644
--- a/js/shows.js
+++ b/js/shows.js
@@ -127,18 +127,18 @@ function shows_updateList(data, status, req) {
type = $(this).find('type').text();
if(type == 'show') {
var show = {
- id: $(this).find('showid').text(),
+ id: $(this).find('show-id').text(),
title: $(this).find('show-title').text(),
dow: $(this).find('show-dayofweek').text(),
rhythm: $(this).find('show-rhythm').text(),
starttime: $(this).find('show-starttime').text(),
length: $(this).find('show-length').text(),
+ log: $(this).find('show-log').text(),
group: {
name: $(this).find('group').text(),
lowcart: $(this).find('group-low-cart').text(),
highcart: $(this).find('group-high-cart').text(),
},
- log: $(this).find('log').text(),
normlevel: $(this).find('normalization-level').text(),
trimlevel: $(this).find('autotrim-level').text(),
}
diff --git a/lib/rddb.pm b/lib/rddb.pm
index 6b7b40f..34321d2 100755
--- a/lib/rddb.pm
+++ b/lib/rddb.pm
@@ -77,31 +77,40 @@ sub check_token
return (0, 'ERROR', "wrong password");
}
-sub get_showtitle
+sub get_showtitle_and_log
{
my ($dbh, $showid) = @_;
- my $sql = qq{select TITLE from CART where NUMBER = ?;};
+ my $sql = qq{select TITLE,MACROS from CART where NUMBER = ?;};
my $sth = $dbh->prepare($sql)
- or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
+ or return (undef, undef, 'ERROR', "Database Error: " . $dbh->errstr);
$sth->execute($showid)
- or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
+ or return (undef, undef, 'ERROR', "Database Error: " . $sth->errstr);
- my ($title) = $sth->fetchrow_array;
+ my ($title, $macros) = $sth->fetchrow_array;
$sth->finish();
unless(defined $title) {
- return (undef, 'ERROR', "Show wid ID=" . $showid . " not found!")
+ return (undef, undef, 'ERROR', "Show with ID=" . $showid . " not found!")
+ }
+ unless(defined $macros) {
+ return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has no macro!");
+ }
+
+ unless($macros =~ /^LL 1 ([^ ]+) 0\!$/) {
+ return (undef, undef, 'ERROR', "Show with ID=" . $showid . " has invalid macro: '" . $macros . "'");
}
- return ($title, 'OK', 'success');
+ my $log = $1;
+
+ return ($title, $log, 'OK', 'success');
}
sub get_dropboxes
{
my ($dbh, $username) = @_;
- my $sql = qq{select USER_PERMS.GROUP_NAME,DROPBOXES.PATH,DROPBOXES.TO_CART,DROPBOXES.LOG_PATH,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=?;};
+ 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=?;};
my $sth = $dbh->prepare($sql)
or return (undef, 'ERROR', "Database Error: " . $dbh->errstr);
@@ -110,35 +119,34 @@ sub get_dropboxes
or return (undef, 'ERROR', "Database Error: " . $sth->errstr);
my @allowed_dbs;
- while(my ($group, $type, $showid, $log, $normlevel, $trimlevel, $params, $lowcart, $highcart, $groupdesc) = $sth->fetchrow_array()) {
+ while(my ($group, $to_cart, $normlevel, $trimlevel, $params, $lowcart, $highcart, $groupdesc) = $sth->fetchrow_array()) {
+ my @p = split(';', $params);
my $entry = {};
$entry->{'GROUP'} = $group;
$entry->{'GROUPDESC'} = $groupdesc;
$entry->{'GROUPLOWCART'} = $lowcart;
$entry->{'GROUPHIGHCART'} = $highcart;
- $entry->{'TYPE'} = $type;
- $entry->{'SHOWID'} = -1;
- $entry->{'LOG'} = $log;
$entry->{'NORMLEVEL'} = $normlevel;
$entry->{'TRIMLEVEL'} = $trimlevel;
$entry->{'PARAM'} = $params;
- if($type eq "show") {
- $entry->{'SHOWID'} = $showid;
+ if($p[0] eq "S") {
+ $entry->{'TYPE'} = 'show';
+ $entry->{'SHOWID'} = $to_cart;
- my ($title, $status, $errorstring) = get_showtitle($dbh, $showid);
- unless (defined $title) {
+ my ($title, $log, $status, $errorstring) = get_showtitle_and_log($dbh, $to_cart);
+ unless (defined $title && defined $log) {
return (undef, $status, $errorstring);
}
$entry->{'SHOWTITLE'} = $title;
-
- if($params =~ /^([01]{4})-([1-7])-([0-9]{2})([0-9]{2})-([0-9]{3})$/) {
- $entry->{'RHYTHM'} = $1;
- $entry->{'DOW'} = int $2;
- $entry->{'DOW'} = 0 unless $entry->{'DOW'} < 7;
- $entry->{'STARTTIME'} = "$3:$4";
- $entry->{'LENGTH'} = int $5;
- }
+ $entry->{'SHOWLOG'} = $log;
+
+ $entry->{'SHOWRHYTHM'} = $p[1];
+ $entry->{'SHOWDOW'} = int $p[2];
+ $entry->{'SHOWDOW'} = 0 unless $entry->{'SHOWDOW'} < 7;
+ substr($p[3], 2, 0) = ':';
+ $entry->{'SHOWSTARTTIME'} = $p[3];
+ $entry->{'SHOWLEN'} = int $p[4];
}
push @allowed_dbs, $entry;
diff --git a/listdropboxes.cgi b/listdropboxes.cgi
index 18c5902..9261e20 100755
--- a/listdropboxes.cgi
+++ b/listdropboxes.cgi
@@ -23,6 +23,11 @@ if(defined $dbh) {
if($result == 1) {
$responsecode = 200;
@dropboxes = rddb::get_dropboxes($dbh, $username);
+ unless (defined $dropboxes[0]) {
+ $responsecode = 500;
+ $status = $dropboxes[1];
+ $errorstring = $dropboxes[2];
+ }
} elsif($result == 0) {
$responsecode = 403;
} else {
@@ -46,18 +51,18 @@ if($responsecode != 200) {
print " <group-description>" . $href->{'GROUPDESC'} . "</group-description>\n";
print " <group-low-cart>" . $href->{'GROUPLOWCART'} . "</group-low-cart>\n";
print " <group-high-cart>" . $href->{'GROUPHIGHCART'} . "</group-high-cart>\n";
- print " <type>" . $href->{'TYPE'} . "</type>\n";
- print " <showid>" . $href->{'SHOWID'} . "</showid>\n";
- print " <log>" . $href->{'LOG'} . "</log>\n";
print " <normalization-level>" . $href->{'NORMLEVEL'} . "</normalization-level>\n";
print " <autotrim-level>" . $href->{'TRIMLEVEL'} . "</autotrim-level>\n";
print " <parameters>" . $href->{'PARAM'} . "</parameters>\n";
+ print " <type>" . $href->{'TYPE'} . "</type>\n";
if($href->{'TYPE'} eq "show") {
+ print " <show-id>" . $href->{'SHOWID'} . "</show-id>\n";
print " <show-title>" . $href->{'SHOWTITLE'} . "</show-title>\n";
- print " <show-rhythm>" . $href->{'RHYTHM'} . "</show-rhythm>\n";
- print " <show-dayofweek>" . $href->{'DOW'} . "</show-dayofweek>\n";
- print " <show-starttime>" . $href->{'STARTTIME'} . "</show-starttime>\n";
- print " <show-length>" . $href->{'LENGTH'} . "</show-length>\n";
+ print " <show-log>" . $href->{'SHOWLOG'} . "</show-log>\n";
+ print " <show-rhythm>" . $href->{'SHOWRHYTHM'} . "</show-rhythm>\n";
+ print " <show-dayofweek>" . $href->{'SHOWDOW'} . "</show-dayofweek>\n";
+ print " <show-starttime>" . $href->{'SHOWSTARTTIME'} . "</show-starttime>\n";
+ print " <show-length>" . $href->{'SHOWLEN'} . "</show-length>\n";
}
print " </dropbox>\n";
}