#!/usr/bin/perl -Tw
#
# db consult
#
# Here you can add "use strict" and make the environment safer. Check the 
# guestbook.cgi script in LinuxFocus article 203 from November 2001 issue.
# This is especially true if you allow the user to write into the database table.
use DBI;
use CGI qw(param());

print <<END_of_start;
Content-type: text/html

<html>
<title>LFAuthors main db</title>
<br>
<center><TABLE>
 <TR VALIGN=TOP>
  <TD><form action="/cgi-bin/lf.cgi" method="get">
      <input type="submit" value="        LFAuth       ">
      </form>
  </TD>
 </TR>
</TABLE>

<br>
<br>

<center><H2>Search by author</H2></center>
<br>
<form action=\"/cgi-bin/lf.cgi\" method=\"get\">Author name : <input
type=\"text\" size=\"30\" name=\"author\"><input type=\"submit\" value=\"Search...\"></form>
</center>


END_of_start


if (param("author") ne '') {
	$author = param("author");
	
	$autsrch.='"';
	$autsrch.=$author;
	$autsrch.='"';

# username has to be replaced with an user name who has read permissions 
# to the database table. Careful here, since this script doesn't ask for any 
# authentication. If you want the user to write into the table, you MUST ask for
# login and password.
	
	$dbh = DBI->connect("DBI:mysql:lf","username",'');

	$sth = $dbh->prepare("
		select *
		from trissue
		where
		author = $autsrch
		");
		
	$sth->execute;

# Display result

print <<END_suite;
	<br>
	<center>
	<TABLE BORDER=1>
		<tr bgcolor=#A1C4EE>
   			<th width=60 align=CENTER><font color=#000000> Num </font></th>
  			<th width=110 align=CENTER><font color=#000000> Category </font></th>
  			<th width=110 align=CENTER><font color=#000000> Title </font></th>
			<th width=110 align=CENTER><font color=#000000> Author </font></th>
			<th width=110 align=CENTER><font color=#000000> En </font></th>
			<th width=110 align=CENTER><font color=#000000> Es </font></th>
			<th width=110 align=CENTER><font color=#000000> Fr </font></th>
			<th width=110 align=CENTER><font color=#000000> De </font></th>
			<th width=110 align=CENTER><font color=#000000> Nl </font></th>
			<th width=110 align=CENTER><font color=#000000> Ru </font></th>
			<th width=110 align=CENTER><font color=#000000> Tk </font></th>
			<th width=110 align=CENTER><font color=#000000> Issue </font></th>
  		</tr>

END_suite
	
	while( ($num,$category,$title,$author,$en,$es,$fr,$de,$nl,$ru,$tk,$issue)=$sth->fetchrow() ) {
	print "<tr>";
	print "<td width=60 bgcolor=#FFFFE8 align=center> $num</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $category</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $title</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $author</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $en</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $es</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $fr</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $de</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $nl</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $ru</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $tk</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $issue</td>";
	print "</tr>";
	
	}
	print "</TABLE>";
	print "<BR>";
	print "<BR>";
	print "<br>";
	
	
} else {

# DB Connect

	$dbh = DBI->connect("DBI:mysql:lf","username",'');


# Search

	$sth = $dbh->prepare("
		select *
		from trissue
		");
		
	$sth->execute;


# Display result


print <<SUITE;
	<br>
	<center>
	<TABLE BORDER=1>
		<tr bgcolor=#A1C4EE>
			<th width=60 align=CENTER><font color=#000000> Num </font></th>
  			<th width=110 align=CENTER><font color=#000000> Category </font></th>
  			<th width=110 align=CENTER><font color=#000000> Title </font></th>
			<th width=110 align=CENTER><font color=#000000> Author </font></th>
			<th width=110 align=CENTER><font color=#000000> En </font></th>
			<th width=110 align=CENTER><font color=#000000> Es </font></th>
			<th width=110 align=CENTER><font color=#000000> Fr </font></th>
			<th width=110 align=CENTER><font color=#000000> De </font></th>
			<th width=110 align=CENTER><font color=#000000> Nl </font></th>
			<th width=110 align=CENTER><font color=#000000> Ru </font></th>
			<th width=110 align=CENTER><font color=#000000> Tk </font></th>
			<th width=110 align=CENTER><font color=#000000> Issue </font></th>
  		</tr>
SUITE
	while( ($num,$category,$title,$author,$en,$es,$fr,$de,$nl,$ru,$tk,$issue)=$sth->fetchrow() ) {
	print "<tr>";
	print "<td width=60 bgcolor=#FFFFE8 align=center> $num</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $category</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $title</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $author</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $en</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $es</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $fr</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $de</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $nl</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $ru</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $tk</td>";
	print "<td width=110 bgcolor=#FFFFE8 align=left> $issue</td>";
	print "</tr>";
	
	}
	print "</TABLE>";
	print "<BR>";
	
}
print end_html;
$sth->finish;


# Disconnect

$dbh->disconnect;

exit;