#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
# 
# This program 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 General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

use DBI;
use CGI;
use NEWASSET;

#local $Hquery;
#$Hquery = new CGI();
#print $Hquery->header('text/html');
local %in, @row, $db, $table, @line, $x, $key, $order;
local $pages, $npage, $apage, $i;
local %hashref;
undef(%in);
undef(%hashref);
undef(@row);
undef(@line);
$order = "";
$x=0;



##   ##            ##            ######         ##   ##
### ###           ####             ##           ###  ##
#######          ##  ##            ##           #### ##
#######          ##  ##            ##           ## ####
## # ##          ######            ##           ##  ###
##   ##          ##  ##            ##           ##   ##
##   ##          ##  ##          ######         ##   ##

CGI::ReadParse();


$db = NEWASSET::opendb();

if($in{'s'} eq "n") {
	
} else {
	if($in{'skrit'} =~ /username/) {
	$order = "$in{'field'}, " if($in{'field'});
	$order = "node.node, " if($in{'field'} =~ /department/);
	$table = $db->prepare("
		SELECT  newasset_page.*,node.node
		FROM    newasset_page, node, item, newasset_conn
		WHERE   newasset_page.username = '$in{'dep'}'
		AND     newasset_page.id = newasset_conn.newasset_page
		AND     newasset_conn.item_sid = item.sid
		AND     item.node_sid = node.sid

		ORDER BY  $order title
	");
  }
	else {
		$order = $in{'field'};
		$in{'skrit'} = "node.node" if($in{'skrit'} eq "department");
		$order = $in{'skrit'} = "node.node" if($in{'field'} eq "department");
		$order .= ", " if($in{'field'});
		$table = $db->prepare("
			SELECT    newasset_page.*, node.node
			FROM    newasset_page, node, item, newasset_conn
			WHERE   node.sid = $in{'dep'}
			AND     newasset_page.id = newasset_conn.newasset_page
			AND     newasset_conn.item_sid = item.sid
			AND     item.node_sid = node.sid
			ORDER BY  $order newasset_page.title
		");

	}
}

$table->execute();
$table->bind_columns(\(@hashrow{@{$table->{NAME_lc}}}));

print "
<HTML>
<HEAD>
<TITLE>Radio Internationale Stadt - Music</TITLE>
</HEAD>
$NEWASSET::NEWASSET_BODY
";


$x = ($in{'n'}+60<$DBI::rows)?$in{'n'}+60:$DBI::rows;
$npage = int($in{'n'}/60);
$pages = int($DBI::rows/60);

$key = $in{'dep'};
$key =~ s/\ /%20/g;
$apage="";
for($i=0;$i<=$pages;$i++) {
	$apage .= " | <a href=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$key&field=$in{'field'}&n=".($i*60).">$i</a>";
}


$page = "
	<table width=100%><tr><td align=left>
	<td><pre>query: $in{'skrit'}, keyword: $in{'dep'}</td>
	<td>$apage p$npage of $pages</td>
	<td>
	<a href=javascript:self.back()><font size=+0>&lt;back</font></a>
	</td>
";

$page .= "<td align=right><a href=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$key&n=$x&field=$in{'field'}><font size=+0>next&gt;</font></a></td>" if($x<$DBI::rows);
$page .= "</tr></table>";


print $page;

print "<pre><img src=/NEWASSET/blindblock.gif>";
print "<pre>   ";
print "title                               <font color=#ffffff>| <A HREF=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$in{'dep'}&field=author>author</A>               | <A HREF=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$in{'dep'}&field=interpret>artist</A>               | <A HREF=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$in{'dep'}&field=label>label</A>           | <A HREF=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&field=department&dep=$key>area</A>       | <A HREF=$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&field=copyright&dep=$in{'dep'}>copyright</A></font>
";

$i=0;
while(@row=$table->fetchrow()) {
	if($i >= $in{'n'} && $i < $x) {
		NEWASSET::display_line(*row,*hashrow);
	}
	$i++
}
$table->finish();


print "</pre>";

print $page;

print "</pre>";
NEWASSET::copyright();

