#!/usr/bin/perl
#
# BNCweb: A user-friendly interface to the British National Corpus - Version 4.3
# Copyright (C) 2005-10 Hoffmann/Evert/Lehmann
#
# Updates and information available at http://www.bncweb.info
#
# This file is part of BNCweb.
# 
# BNCweb 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 3 of the License, or
# (at your option) any later version.
# 
# BNCweb 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, see <http://www.gnu.org/licenses/>.

#
# based on BNCweb Version 2.0:
# © 1996/2004 Lehmann/Hoffmann/Schneider
#

use lib "../lib_files";
use bncLibCQPXML;


# connect to mysql
$bncHandle = DBI->connect("DBI:mysql:$bwMYSQLtable:$bwMYSQLhost:$bwMysqlPort", "$bwMysqlUser", "$bwMysqlPwd") or bark("Can't connect to mysql on $bwMYSQLhost at port: $bwMysqlPort <BR>$userHandle::errstr\n");


### no longer supported -- check if some regexps need //m modifier
# $*=1; 
	
unless (getParams($ENV{'QUERY_STRING'})) {
	barkFull("incomplete transmition of URL<BR>This problem is likely to occur in combination with proxy servers<BR>turn off your web-proxy and try again");
}


# print header and title (to save space...)
print "Content-type: text/html\n\n";
print <<END;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> 
<HTML>
<HEAD>

<TITLE>BNC Speaker Information</TITLE>

<META NAME="generator" CONTENT="BBEdit 4.5">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<TABLE BORDER="0" CELLPADDING="4" CELLSPACING="2" WIDTH="100%">
	<TR WIDTH="100%">
		<TD HEIGHT="26" COLSPAN="2" BGCOLOR="#CCCCFF">
			<B>Speaker information for $params{spid} (of file $params{text})</B>
		</TD>
	</TR>
END


$sqlQuery = "SELECT filename, spid, age, dialect, education, firstLanguage, sex, class, ageFull, 
		nameFull, occupation, role, num_orthogr_words, numtokens, speakerWords, speakerPuns, speakerTurns, speakerSunits  
		FROM speakers WHERE spid = '$params{spid}'";
$sth = $bncHandle->prepare($sqlQuery) or bark("Can't prepare $sqlQuery: " . $bncHandle::errstr);
$sth->execute or bark("Can't execute $sqlQuery: " . $sth::errstr);

($filename, $spid, $age, $dialect, $education, $firstLanguage, $sex, $class, $ageFull, 
$nameFull, $occupation, $role, $num_orthogr_words, $numtokens, $speakerWords, $speakerPuns, $speakerTurns, $speakerSunits ) = $sth->fetchrow_array;

print "<TR BGCOLOR=\"#DDDDDD\"><TD WIDTH=\"30%\">Name:</TD><TD>$nameFull<\/TD><\/TR>\n";
$speakerWordsDecimal = makeDecimals($speakerWords);
print "<TR BGCOLOR=\"#DDDDDD\"><TD>Number of words:</TD><TD>$speakerWordsDecimal</TD></TR>\n";
$speakerTurnsDecimal = makeDecimals($speakerTurns);
print "<TR BGCOLOR=\"#DDDDDD\"><TD>Number of turns:</TD><TD>$speakerTurnsDecimal</TD></TR>\n";

$averageTurnLength = int((($speakerWords / $speakerTurns) * 10000) + 0.5)/ 10000;

print "<TR BGCOLOR=\"#DDDDDD\"><TD>Average length of turns (&lt;w&gt;-tags per &lt;u&gt;-unit):</TD><TD>$averageTurnLength</TD></TR>\n";

print <<END;
	<TR WIDTH="100%">
		<TD COLSPAN="3" BGCOLOR="#FFCC99">
			<P ALIGN="LEFT"><B>Standard header information:</B>
		</TD>
	</TR>
END
$value = "sex=$sex";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{sex}:</TD><TD>$catValues{$value}</TD></TR>\n";
$value = "age=$age";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{age}:</TD><TD>$catValues{$value}</TD></TR>\n";
$value = "class=$class";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{class}:</TD><TD>$catValues{$value}</TD></TR>\n";
$value = "education=$education";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{education}:</TD><TD>$catValues{$value}</TD></TR>\n";
$value = "firstLanguage=$firstLanguage";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{firstLanguage}:</TD><TD>$catValues{$value}</TD></TR>\n";
$value = "dialect=$dialect";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>$typeValues{dialect}:</TD><TD>$catValues{$value}</TD></TR>\n";
print <<END;
	<TR WIDTH="100%">
		<TD COLSPAN="3" BGCOLOR="#FFCC99">
			<P ALIGN="LEFT"><B>Additional information:</B>
		</TD>
	</TR>
END
print "<TR BGCOLOR=\"#DDDDDD\"><TD>Age:</TD><TD>$ageFull</TD></TR>\n";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>Occupation:</TD><TD>$occupation</TD></TR>\n";
print "<TR BGCOLOR=\"#DDDDDD\"><TD>Role:</TD><TD>$role</TD></TR>\n";

print "</TABLE>\n";


# print the end of html
&printFooter();

#say goodbye
exit (0);


