#!/usr/bin/perl
#<a href=/cgi/nauka?05>
#<a href=/cgi/nauka?05&9710&05710002>

$htdocs="/usr/local/www/vhosts/nauka-i-zizn.ru/htdocs/";
unshift(@INC,"/usr/local/www/vhosts/nauka-i-zizn.ru/support");
require "cgi-lib.pl";
open(WEB,">/usr/local/www.vhosts/nauka-i-zizn.ru/"."0_AL.log");
print WEB "==20.02========\n";
$HEADER="header";
$NARGV = $#ARGV;
# print WEB "$NARGV\n";
$RR=$ARGV[0];
  print WEB "$NARGV $RR $HEADER\n";
   $shtml = "htm"; $list="dir";
 if ( -e "$htdocs/$RR/LIST.shtml") {
   $shtml ="shtml"; $list="LIST";
 };
 if ( ($NARGV == 1) && ($ARGV[1] == 9999) ){
     $NARGV=0;    # $HEADER="_self" ; #$HEADER="_top" ;
     print WEB "$NARGV $RR $ARGV[1] $HEADER\n";
 };
 if($NARGV > 1) {
   $YYNN=$ARGV[1];
   $YYNN =~ /(\d)(\d)(\d\d)/;
      $YY=$1.$2; $Y=$2; $YY00=$YY."00"; $YNN=$2.$3; $NN=$3;
   $RRYNNPPP=$ARGV[2];
   $RRYNNPPP =~ /(\d\d)(\d)(\d\d)/; $rr=$1; $ynn=$2.$3;

   $JG="00";
if ($rr > $JG ) {
  @RN  =("01","16","24","40","50","57");
 print WEB "==20.02======$rr $JG==\n";
 foreach $i (0 ..  ($#RN - 1) ) {
       $JG=$RN[$i];
 print WEB " $i $rr $JG $RN[$i]\n";
   last if( ($rr >= $RN[$i]) && ($rr < $RN[$i+1]) );
 };
 print WEB "==20.02======$rr $JG==\n";
}; #$rr > "00"
   $HTM = ($NARGV == 3)?$ARGV[3]:htm;
$WIDTH=($HTM eq 'htm'|| $HTM eq 'html'|| $HTM eq 'shtml')?'34%,66%':'14%,40%,46%';
   $DIR ="D$RR.$shtml";
   $DIR="D$YYNN.shtml" if($HTM eq 'HTM'|| $HTM eq 'htm');
#19/02   $RETURN="/cgi/nauka.pl?00+$YY00+00$Y"."00000+shtml";
#20/02  $RETURN="/cgi/nauka.pl?00+9999+00$Y"."00000+shtml";
  $RETURN="/cgi/nauka.pl?00+9999+007"."000".$JG."+shtml";
#   $RETURN="/0-DIR/RUBRIKI.HTM";
#   $RETURN="/0-DIR/dir$YYNN.shtml" if($HTM eq 'HTM'|| $HTM eq 'htm');
$RETURN=
"/cgi/nauka.pl?00+$YY00+00$YNN"."000+shtml" if($HTM eq 'HTM'|| $HTM eq 'htm');
$RETURN="/rubriki.htm";
#19/02   $RETURN=
#"/00/$YY00/00$YNN"."000.shtml" if($HTM eq 'HTM'|| $HTM eq 'htm');
   if ($RR eq "00") {  $RETURN="/index.htm";};
 };
print WEB "=== $NARGV $RR $YYNN $RRYNNPPP $DIR $RETURN  ===\n";
#====================
if ($NARGV == 0) {
   $JG="00";
 if ($RR > $JG ) {
  @RN  =("01","16","24","40","50","57");
  print WEB "==20.02======$RR $JG==\n";
  foreach $i (0 ..  ($#RN - 1) ) {
       $JG=$RN[$i];
  print WEB " $i $RR $JG $RN[$i]\n";
   last if( ($RR >= $RN[$i]) && ($RR < $RN[$i+1]) );
 };
 print WEB "==20.02======$RR $JG==\n";
   $RETURN="/cgi/nauka.pl?00+9999+007000".$JG."+shtml";
$RETURN="/rubriki.htm";
 }; #$RR > "00"


#    $RETURN="RUBRIKI.HTM";
   if ($RR eq "00") {  $RETURN="index.htm";};
#   system("cp $htdocs/$RR/dir.$shtml $htdocs/$RR/DIR.shtml");
   $DIR ="D$RR.shtml";
   $YyNn=""; $RRYNNPPP="dir"; $FRAME=$RR."000000";
  print WEB "$list.$shtml\n";
   open(LIST,$htdocs."$RR/$list.$shtml");
$NL=0; $TITLE='';
   while(<LIST>) { chop; ++$NL;
#             <font color="#FF0000">04 - Рассказы о минералах</font>
    if( ($NL==1) && ( $_ =~ /^<font color\".+\">(.+)<\/font>/ ) ) {
     print WEB "$NL $1\n";
        $TITLE=$1;
     };

     if(/^<a href=\"(\d+)\/(\d+)\.(htm|HTM)\"/) {
     $YYNN=$1;  $YyNn=$1."/"; $RRYNNPPP=$2; $FRAM=$2; $HTM=$3;
     $WIDTH=($HTM eq "htm")?'34%,66%':'14%,40%,46%';
       last;
     };
#          $1                            $2/RR  $3/YYMM $4/RRYMMPPP.     $5
if(/^(<A HREF|a href)=\"\/cgi\/nauka\.pl\?(\d\d)\+(\d+)\+([0-9a-z]+)\+(html|HTML|shtml)/ ) {
     $RR=$2; $YYNN=$3;  $YyNn=$3."/"; $RRYNNPPP=$4;
     $HTM = $5; # ($5 eq "+")?'HTML':'htm';
     $WIDTH=($HTM eq "HTML")?'14%,40%,46%':'34%,66%';
       last;
     };
   };
};


#проба возврата
#if ($NARGV == 5) 
#       {
#         $BACK=$ARGV[5];
#         if ($BACK == 'n')
#               {
#                $RETURN="/cgi/nauka.pl?00+"."$YY00"."+0"."$YY$NN"."000+shtml";
#                }
#         }



#if ($TITLE) {
if($HTM ne 'shtml') {
open(DIR,">$htdocs"."$RR/$DIR");
print DIR <<"DIR_HTM";
<html>
<head>
<title>$TITLE</title>
</head>
<body bgcolor="#FFFFFF">
<CENTER><A HREF='$RETURN' TARGET='_top'>
<IMG SRC="../IMAGES/up.jpg" alt="return" BORDER=0 HEIGHT=20 WIDTH=60></A>
</CENTER><br>
<!--#include virtual="LIST.shtml"-->

<!--LiveInternet counter--><script type="text/javascript"><!--
document.write("<a href='http://www.liveinternet.ru/click' "+
"target=_blank><img src='http://counter.yadro.ru/hit?t44.1;r"+
escape(document.referrer)+((typeof(screen)=="undefined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+
";"+Math.random()+
"' alt='' title='LiveInternet' "+
"border=0 width=31 height=31><\/a>")//--></script><!--/LiveInternet-->

<CENTER><A HREF='$RETURN' TARGET='_top'>
<IMG SRC="../IMAGES/up.jpg" alt="return" BORDER=0 HEIGHT=20 WIDTH=60></A>
</CENTER>

</body>
</html>
DIR_HTM
close(DIR);
};# if($HTM ne 'shtml') ||  $if($TITLE) ...
#
close(WEB);
#
 $HEADER = "contents";  #"_parent"; # "_self";    "_top";
  $RR_DIR="/$RR/$DIR";
 if($HTM eq 'shtml') {
  $WIDTH='30%,70%';
  $RR_DIR="/index-$ynn.shtml";
# system("cp $htdocs/index.shtml $htdocs/INDEX.shtml");
 };
  $FR_D="<FRAME SRC=\'$RR_DIR\' name=\'$HEADER\' marginwidth=5>";
  $FR_P='';
 if($HTM eq 'HTML'|| $HTM eq 'HTM') {
  #$FR_P= 
  # "<FRAME SRC=\'/$RR/$YYNN/$RRYNNPPP.html\' name='pictures' marginwidth='5' MARGINHEIGHT='5' SCROLLING='auto'>";
 };
$htm=($HTM eq 'shtml')?'shtml':'htm';
  $FR_C=
   "<FRAME SRC=\'/$RR/$YYNN/$RRYNNPPP.$htm\' name='view' marginwidth='5' MARGINHEIGHT='5' SCROLLING='auto'>";
#
$FRAMES="$RR/$RRYNNPPP.htm";
open(FRAMES,">$htdocs"."$FRAMES");
#Content-type: text/html
#
print FRAMES <<"end_frame";
<HTML>
<HEAD><TITLE>Science and Life</TITLE>
<!--
<script language="Javascript">
var count=1
</script>
//-->
</HEAD>
<!-- FRAMESET ROWS="70,*" border=3>
<FRAME SRC="/cgi/reklama.pl" scrolling=no marginheight=0 marginwidth=0>
-->
<FRAMESET COLS="$WIDTH">
$FR_D
$FR_P

 <FRAMESET ROWS="*">
   $FR_C
 </FRAMESET>
</FRAMESET>
</HTML>
end_frame
close(FRAMES);
print "Location: /$FRAMES\n\n";
#$page_c = "/$RR/$YYNN/$RRYNNPPP.$htm";
#print "Location: $page_c\n\n";
exit;

