#!/usr/local/bin/perl
#
#illustrator2.cgi
#
#
$datafile="../determinator/dbimage.txt";
if (!$ENV{'QUERY_STRING'}) {$query="tl11.txt"}
else {$query=$ENV{'QUERY_STRING'}}
$auth = substr($query,0,2);
if ($auth eq "pl") {$patafile="../determinator/pereslavl.txt"}
else  {$patafile="../determinator/shust.txt"};


$header1 = (<< "HEADER1") ;
<html>
<head>
<title>Рассказы с иллюстрациями </title>
<link rel="stylesheet" href="../p2002.css">
HEADER1

$header2 = (<< "HEADER2");
<script language="JavaScript">
<!--
var nW=null;
function opfoto(name) {
if (nW==null  || nW.closed) {
nW = open("","myWin","width=300,height=300,scrollbars=yes,resizable=no,menubar=no,location=no,status=no,toolbar=no");
        }
nW.document.close();
nW.document.open();
prezent(name);
nW.document.close();
nW.focus()
}

function closefoto(){
nW.close();
}

function prezent(string){
nW.document.writeln('<html><head><title>Person</title><meta http-equiv="Content-Type" content="text/html"><\/head><body>');
nW.document.writeln(search_in(string,animals));
nW.document.writeln('<\/body><\/html>');
nW.document.close;
}

function search_in(str,list) {
for (var i = 0; i<list.length;i++){
var tmp = list[i].split('|');
var tmp2 = tmp[0].split(' ');
if (str ==tmp2.slice(0,1)) return nice_print(tmp);
}
return str + 'not found';
}


function nice_print(element) {
return '<P STYLE=\"font-size:11pt\"; align:justify><img src=../determinator/images/' + element[1] + '.jpg  border=\"0\"  ><br>' + element[2].fontcolor('blue')  
	}

HEADER2

$header3 = (<< "HEADER3") ;
<\/head><body>
<h2><a href=http://www.uic.nnov.ru/pustyn/><img src=../vp3.gif width=88 height=31></a></h2>
<h1>Библиотека <a href=http://www.uic.nnov.ru/pustyn/>Виртуальной Пустыни</a></h1>
HEADER3


$header4 = (<< "HEADER4") ;
<p class=joli><img src=../determinator/images/shustov.jpg width=100 height=114 align=left Alt=\"Shustov\">Сергей Шустов <a href=mailto:shustov\@dront.ru>shustov\@dront.ru</a>: <br>
<a href=illustrator.pl?tl0.txt>Предисловие</a> -
<a href=illustrator.pl?tl29.txt>Тайны</a> -
<a href=illustrator.pl?tl30.txt>Птицы</a> -
<a href=illustrator.pl?tl31.txt>Студенты</a> -
<a href=illustrator.pl?tl32.txt>Лисички</a> -
<a href=illustrator.pl?tl1.txt>Дачники</a> -
<a href=illustrator.pl?tl35.txt>Праздники</a> -
<a href=illustrator.pl?tl34.txt>Эксперименты</a> -
<a href=illustrator.pl?tl2.txt>Насекомые</a> -
<a href=illustrator.pl?tl33.txt>Пчелы</a> -
<a href=illustrator.pl?tl3.txt>Походы</a> -
<a href=illustrator.pl?tl4.txt>Камни</a> -
<a href=illustrator.pl?tl5.txt>Куколки</a> -
<a href=illustrator.pl?tl6.txt>Ласточки</a> -
<a href=illustrator.pl?tl7.txt>Самолеты</a> -
<a href=illustrator.pl?tl8.txt>Медведки</a> -
<a href=illustrator.pl?tl9.txt>Подарки</a> -
<a href=illustrator.pl?tl10.txt>Телята</a> -
<a href=illustrator.pl?tl11.txt>Дожди</a> -
<a href=illustrator.pl?tl12.txt>Дубы</a> -
<a href=illustrator.pl?tl13.txt>Звезды</a> -
<a href=illustrator.pl?tl14.txt>Звуки</a> -
<a href=illustrator.pl?tl15.txt>Дороги</a> -
<a href=illustrator.pl?tl16.txt>Деревья</a> -
<a href=illustrator.pl?tl17.txt>Радости</a> -
<a href=illustrator.pl?tl18.txt>Листья</a> -
<a href=illustrator.pl?tl19.txt>Ручьи</a> -
<a href=illustrator.pl?tl20.txt>Кошки</a> -
<a href=illustrator.pl?tl21.txt>Заборы</a> -
<a href=illustrator.pl?tl22.txt>Друзья</a> -
<a href=illustrator.pl?tl23.txt>Собаки</a> -
<a href=illustrator.pl?tl24.txt>Американцы</a> -
<a href=illustrator.pl?tl25.txt>Бани</a> -
<a href=illustrator.pl?tl26.txt>Аборигены</a> -
<a href=illustrator.pl?tl27.txt>Туманы</a> -
<a href=illustrator.pl?tl28.txt>Рыбы</a> 
<br clea=all>
</p>
HEADER4



### label
print "Content-Type:text/html \n\n";
print $header1;
open (TEXT,"< ../shust/tales/$query")
or print_err ("Couldn't open for reading ../shust/tales/$query \n") ;
@text = ();
@parag = <TEXT>; 
$h1 = shift @parag;
#print "<h1> $h1 </h1> \n";
foreach (@parag) {
@tmp = split(' ');
$t = shift @tmp;
push (@text,"<p class=little><font color=\"#006600\"><b> $t <\/b><\/font>"," @tmp </p> ");
}
$txt = " @text ";
$txt =~ s/(http\:\/\/\S+)/<a href="$1"> $1 <\/a>/g;
$txt =~ s/(mailto\:\S+)/<a href="$1"> $1 <\/a>/g;
##
#

@list = ();
open(DATA,$datafile);
@anims = (<DATA>);
close DATA;
open (DT,$patafile);
@partners = (<DT>);
push (@anims,@partners);
foreach (@anims) {
chomp;
chomp;
($name,$file,$describ)=split("#");
$name =~ s/\s+$//;
$describ =~ s/"/\\"/g;
chomp($describ);
if ($txt =~ m/\s$name/) {
## est takoj object
# dobavit v massiv znachenie
$anket_str=join('|',($name,$file,$describ));
chomp ($anket_str);
chomp ($anket_str);
$anket_str = "\'" . $anket_str . "\'";
push (@list,$anket_str);
# & zamenit object na ssylka + object
$txt =~ s/\s$name/<a href=\"javascript:void(0)\" onClick=\"opfoto(\'$name\')\"> $name<\/a>/g;
	}
}
close DATA;
chomp(@list);
##
# A teper (if found) vpechataem list s najdennimi zveryami
$l = @list;
if ($l > 0) {
$out_str = commify(@list);
print $header2;
print " var animals \= new Array ( $out_str ) \n" ;
print "\/\/--> \n";
print "<\/script> \n";
	}
print $header3 ;
if ($auth eq "tl") {print " $header4 \n" }
print " $txt  \n\n ";
if ($auth eq "tl") {print " <p class=form>Content - Sergey B. Shustov - <a href=mailto:shustov\@dront.ru>shustov\@dront.ru</a> <br> \n" }
print " CGI-Web-design - Evgeny D. Patarakin - <a href=mailto:pat\@osi.nnov.ru>pat\@osi.nnov.ru</a></</p> \n";
print "<img src\=http\:\/\/www\.counter\.nn\.ru\/cgi-bin\/counter\.cgi\?2009  width\=88 height\=31 border\=0> \n";
print "<\/body><\/html> \n";


sub commify {
(@_ == 0) ? ""		:
(@_ == 1) ? $_[0]		:
(@_ == 2) ? join(",",@_):
		join (",", @_[0 ..($#_ - 1)]," $_[-1]");
}

sub print_err{
 print "Content-Type: text/html\n\n";
 print "<HTML><HEAD><TITLE>Error!!</TITLE></HEAD>";
 print "<BODY><CENTER><H1>@_</H1>";
 print "</BODY></HTML>";
 exit;
 }