#!/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 DBI;
use NEWASSET;
use HTTP::Date;


local (@row, $st, %dep, $dep2, $contribs, %hashrow);


$contribs=0;
undef(%in);
undef(%dep);
undef(%dep2);
undef(%hashrow);
undef(@row);



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

$db = NEWASSET::opendb();

CGI::ReadParse();
print "
<HTML>
<HEAD>

<TITLE>Radio Internationale Stadt - Music</TITLE>


</HEAD>
$NEWASSET::NEWASSET_BODY
<b>User overview</b>
";

$st = $db->prepare("
					SELECT		*
					FROM		users
					WHERE		username='$in{'username'}'
");
$st->execute();
$st->bind_columns(\(@hashrow{@{$st->{NAME_lc}}}));
while(@row=$st->fetchrow()) {
	$output = "
	<table>
		<tr><td align=right>username:</td><td>$hashrow{username}</td></tr>
		<tr><td align=right>name:</td><td>$hashrow{name}</td></tr>
		<tr><td align=right>e-mail:</td><td><a href=mailto:$hashrow{email}>$hashrow{email}</a></td></tr>
		<tr><td align=right>street:</td><td>$hashrow{street}</td></tr>
		<tr><td align=right>postal:</td><td>$hashrow{postal}</td></tr>
		<tr><td align=right>city:</td><td>$hashrow{city}</td></tr>
		<tr><td align=right>state:</td><td>$hashrow{state}</td></tr>
	</table>
	";
}

$st = $db->prepare("SELECT		*
					FROM		newasset_page
					WHERE		username='$in{'username'}'
");
$st->execute();
while(@row=$st->fetchrow()) {
	$contribs++;
	$dep{$row[0]} = 1;
}
$st->finish();
	
print "<table width=90%><tr><td valign=top>$output</td>";

foreach $k (keys %dep)
{
  $st = $db->prepare("
          SELECT    node.node
          FROM    node, item, newasset_conn
          WHERE   $k = newasset_conn.newasset_page
          AND newasset_conn.item_sid = item.sid
          AND item.node_sid = node.sid
  ");
  $st->execute();
  while(@row=$st->fetchrow()) {
    $dep2{$row[0]}++;
  }
  $st->finish();
}

$output = "<table>
	<tr><td align=right>total:</td><td><a href=$NEWASSET::CGI_BINS/newasset-query?skrit=username&dep=$in{'username'}>$contribs</a></td></tr>\n";

foreach $k (sort(keys %dep2))
{
	$output .= "<tr><td align=right>$k:</td><td>$dep2{$k}</td></tr>\n";
}
$output .= "</table>";
print "<td valign=top>$output</tr></table>";


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