#!/usr/bin/perl
use strict;
use CGI;
use File::Basename;
use lib dirname( __FILE__ ) . '/lib';
use rddb;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
my $status = 'ERROR';
my $errorstring = 'unknown';
my $responsecode = 500;
my @dropboxes = ();
my $q = CGI->new;
my $username = $q->param('LOGIN_NAME');
my $token = $q->param('PASSWORD');
my $dbh;
($dbh, $status, $errorstring) = rddb::opendb();
if(defined $dbh) {
my $result;
($result, $status, $errorstring) = rddb::check_token($dbh, $username, $token);
if($result == 1) {
$responsecode = 200;
@dropboxes = rddb::get_dropboxes($dbh, $username);
} elsif($result == 0) {
$responsecode = 403;
} else {
$responsecode = 500;
}
rddb::closedb($dbh);
}
print "Content-type: application/xml; charset=UTF-8\n\n";
if($responsecode != 200) {
print "\n";
print " " . $responsecode . "\n";
print " " . $errorstring . "\n";
print "\n";
} else {
print "\n";
for my $href (@dropboxes) {
print " \n";
print " " . $href->{'GROUP'} . "\n";
print " " . $href->{'GROUPDESC'} . "\n";
print " " . $href->{'TYPE'} . "\n";
print " " . $href->{'SHOWID'} . "\n";
print " " . $href->{'NORMLEVEL'} . "\n";
print " " . $href->{'TRIMLEVEL'} . "\n";
print " " . $href->{'PARAM'} . "\n";
if($href->{'TYPE'} eq "show") {
print " " . $href->{'SHOWTITLE'} . "\n";
print " " . $href->{'RHYTHM'} . "\n";
print " " . $href->{'DOW'} . "\n";
print " " . $href->{'STARTTIME'} . "\n";
print " " . $href->{'LENGTH'} . "\n";
}
print " \n";
}
print "\n";
}