#!/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 CGI;
use NEWASSET;
use DBI;



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

CGI::ReadParse();

$in{'dep'} =~ s/\ /%20/g;

#local $Hquery;
#$Hquery = new CGI();
#print $Hquery->header('text/html');


if($in{pass} eq "-1") {
	print "$NEWASSET::NEWASSET_BODY";
}

$in{'skrit'} =~ s/\ /%20/g;
if(!$in{'pass2'}) {

	local $id;
	$id = "&id=$in{'id'}" if($in{'id'});

	print "
	<title>Welcome to the NEWASSET GROUP</title>
	<frameset rows=90,* border=0 bordercolor=#000000>
	<!frame name=hidden src=$NEWASSET::CGI_BINS/newasset-prep?pass=-1 scrolling=no>
	<frame name=head src=http://$NEWASSET::HOST/NEWASSET/newasset-head.html scrolling=no frameborder=0>
	<frame src=$NEWASSET::CGI_BINS/newasset-prep?skrit=$in{'skrit'}&dep=$in{'dep'}&access=$in{'access'}&pass2=1$id>
	</frameset>
	";
}
else {
	if($in{'pass'} eq "-1") {
		exit;
	}
	print "\n";
	print "<frameset rows=40%,* border=10 bordercolor=#ccffff>";

	if($in{'access'} eq "query") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-query?skrit=$in{'skrit'}&dep=$in{'dep'}>
		";
	}

	if($in{'access'} eq "latest") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-latest?skrit=$in{'skrit'}>
		";
	}

	if($in{'access'} eq "sched") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-live>
		";
	}
	
	if($in{'access'} eq "clist") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-clist>
		";
	}

	if($in{'access'} eq "llist") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-llist>
		";
	}

	if($in{'access'} eq "playlists") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-play>
		";
	}
	
	if($in{'access'} eq "randio") {
		local $st, $i, @row, @ids, @locations, $idstring;
		undef(@row);
		undef(@ids);
		undef(@locations);
		$idstring="";

		$db = NEWASSET::opendb();
		$st = $db->prepare("
			SELECT  newasset_page.id, newasset_page.identifier, newasset_page.location
			FROM    newasset_page
		");
		$st->execute();
		$i=0;
		while(@row=$st->fetchrow()) {
			if(-f "$NEWASSET::NEWASSET_PATH/$row[0]/$row[1]") {
				$locations[$i] = $row[2];
				$ids[$i++] = $row[0];
			}
		}
		$st->execute();

		for($i=0;$i<=39;$i++) {
			$x = rand()*$#ids;
			$idstring .= "$ids[$x]\@$locations[$x]:";
		}
		print "
			<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-randio?op=display&ids=$idstring>
			<frameset cols=200,* border=0>
            <frame name=newassetcook src=$NEWASSET::CGI_BINS/newasset-cook?op=look>
			<frame name=f2 src=$NEWASSET::CGI_BINS/newasset-randio?ids=$idstring>
			</frameset>
			</frameset>
		";
		exit;
	}

	if($in{'access'} eq "search") {
		print "
		<frame name=f1 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-search?querystring=$in{'skrit'}&find_what=$in{'dep'}>
		";
	}

	if($in{'access'} eq "id") {
		print "<frame name=f1 src=/NEWASSET/newasset-footer.html>";
		print "
			<frameset cols=200,* border=0>
            <frame name=newassetcook src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-cook?op=look>
            <frame name=f2 src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-display?id=$in{'id'} frameborder=no>
            </frameset>

		";
	}
	else {
    print "<frameset cols=200,* border=0>
            <frame name=newassetcook src=http://$NEWASSET::HOST$NEWASSET::CGI_BINS/newasset-cook?op=look>
            <frame name=f2 src=/NEWASSET/newasset-footer.html frameborder=no>
            </frameset>";

	}
	print "</frameset>";
}

