#!/usr/bin/perl

require 'setting.pl';
require 'fsethtm.pl';
require 'parsform.pl';


# Wwod novogo soobshenia   w progy

if (!&parse_form) {
        print "Error_Message\n";
        }
        else {
      #  foreach $form_field (keys %FORM) {
      # print "$form_field was set to $FORM{$form_field}.\n";

        }
$nstr = $FORM{'nstr'};
if ($nstr == 0) {$nstr = 1;}

$mail1 = '<a href="mailto:';
$mail2 = '"><font color="#000000"><b>';
$mail3 = '</b></font></a>';
$otk1 = '<a href="fsoob.pl?nstem=';
$otk3 = '"><i>';
$otk2 = '&nsotv=';
$otk4 = '</i></a>';
$new1 = '<font color="#FF0000">new</font>';
$smail1 = '<img src="/smail/';
$smail2 = '.gif" border="0"> ';
$prob =  '&nbsp;'x 1 ;
$nick1 = '<b>';
$nick2 = '</b>';

#&zap($STROTKL,$nstr);

# peshat @STROTKL

#wiwod sagolovka
print "Content-type: text/html\n\n";
#print 'Hello 1';
open (HTMSAG, "$HTMSAG" ) || die " not found HTMSAG! ";
@HTMSAG= <HTMSAG>;  # fail -> massiv
close (HTMSAG);

foreach $i (@HTMSAG)
        {
     #   print $i ;
        print  "$i \n";
        }

print  '<br>' ;
print  '<font face="Times New Roman, Times, serif" size="3"><p><b>';
print  "\n" ;
print '&nbsp;'x 30 ;
print '<a href="fotv.pl?nstem=0&nsotv=0">Новое сообщение</a></b></p>';
print  "\n" ;
#print  '<br>'x1 ;
#print  "\n" ;



# print  '<br>' x 1 ;

open (STROTKL, "$STROTKL" ) || die " not found STROTKL! ";
@STROTKL = <STROTKL>;  # fail -> massiv
close (STROTKL);

$ttime = time;
$ttime = $ttime - $NEW;
$ktem = 1;
$kstr = 1;
#$ntemabs = 1;
$nstrtek = 1;

@smail = ( "smile", "sad", "agree", "disagree", "feedback",
 "idea", "more", "note", "question","warning");



 #<a href="sert?eret&amp;7878">ssssssssssert</a>

 ($ntem0, $notv, $smail) =
        split ('\^', $STROTKL[0]) ;               # ne polnaja rasschifrovka!!!
#$ntemper = $ntem0 - (($nstr-1) * $KPOK) ;
#$ntempos = $ntemper - $KPOK ;
#print  "$nstr  $KPOK  $ntem0  $ntemper  $ntempos     \n" ;

foreach $i (@STROTKL)
{
                ($ntem, $notv, $smesh, $smail, $nick, $mail, $tema, $data, $comments, $times, $ips) =
                split ('\^', $i) ;

       if ( $ntem0 != $ntem )
       {
        #   $ntemabs++;
            $ktem++;
            $ntem0 = $ntem ;

           if ($ktem > $KPOK)
           {
            $ktem = 1;
            $nstrtek++;
            $kstr++;
            }
       }

           if ($nstr == $nstrtek)
           {
             if ($times > $ttime)
             { $newotk = $new1 ;}
             else
             { $newotk = '   ' ;}
  #   print $i ;

             if ($notv==0)
             {
              print  '<br>' ;
              print "$ntem";
              if ( $mail == 0 )
              {
              print  "  $smail1$smail[$smail]$smail2  $prob $nick1$nick$nick2  $prob  $otk1$ntem$otk2$notv$otk3$tema$otk4 $data $newotk <br> \n";
              }
              else
              {
              print  "  $smail1$smail[$smail]$smail2  $prob $mail1$mail$mail2$nick$mail3  $prob  $otk1$ntem$otk2$notv$otk3$tema$otk4 $data $newotk <br> \n";
              }
             }
             else
                 { $smesh = $smesh  * 7 ;
                   print '&nbsp;'x $smesh ;
                    if ( $mail == 0 )
              {
              print  "  $smail1$smail[$smail]$smail2  $prob $nick1$nick$nick2  $prob  $otk1$ntem$otk2$notv$otk3$tema$otk4 $data $newotk <br> \n";
              }
              else
              {
              print  "  $smail1$smail[$smail]$smail2  $prob $mail1$mail$mail2$nick$mail3  $prob  $otk1$ntem$otk2$notv$otk3$tema$otk4 $data $newotk <br> \n";
              }
                   }
           }
   if ( $ntem != $ntem0 )
   {
     $ntem = $ntem0 ;
     $ktem = $ktem + 1;
     if ($ktem > $KPOK )
        {
         $kstr =$kstr + 1;
         $ktem = 1;
         }
   }
}

print  '<br>' x 1 ;
print '&nbsp;'x 10 ;
for ( $n = 1; $n <= $kstr; $n++)
{
  if ($n == $nstr)
  {
  print "<b>   $n</b>";
  print '&nbsp;' ;
  }
  else
  {
  print '<a href="fmain.pl?nstr=';
  print "$n";
  print '">';
  print "<i>   $n</i>";
  print '</a>';
   print '&nbsp;' ;
  }
}



print  '<br>' x 2 ;
 open (HTMOK, "$HTMOK" ) || die " not found HTMSAG! ";
@HTMOK= <HTMOK>;  # fail -> massiv
close (HTMOK);
foreach $i (@HTMOK)
        {
     #   print $i ;
        print  "$i \n";
        }



# ?????!


