Diff for /chik/chik.cgi between versions 1.1 and 1.2

version 1.1, 2000/10/31 21:30:30 version 1.2, 2000/11/01 04:06:49
Line 15  to the secretary "Team NN started at I<D Line 15  to the secretary "Team NN started at I<D
 =head1 USES  =head1 USES
   
 MySQL table Chik with the fields:  MySQL table Chik with the fields:
   RegNum Int UNIQUE,     CREATE TABLE Chik (RegNum Int NOT NULL, 
   Name TINYTEXT,                        Name TINYTEXT, 
   Password TINYTEXT,                        Password TINYTEXT,
   Email TINYTEXT,                        Email TINYTEXT, 
   Started ENUM(Y,N),                        Started ENUM('Y','N') DEFAULT 'N', 
   StartTime TIMESTAMP(14),                        StartDate TIMESTAMP(14), Unique(RegNum));
   
   It expects to find the file F<../../cfg/chik/questions.cfg>, with 
   the questions, <F<../../cfg/chik/h.cfg> with the headers and
   F<../../cfg/chik/f.cfg> with the footers.
   
 It expects to find the file F<../mail/chik/robot.cfg>, which is a piece of  
 Perl code, defining the following variables:  
   
 =over 4  
   
 =item C<$secretary>  
   
 Email of the secretary  
   
 =item C<$questions>  
   
 Location of the file with the questions  
   
 =back  
   
 =head1 AUTHOR  =head1 AUTHOR
   
Line 52  $Revision$ Line 42  $Revision$
 =cut  =cut
   
 use strict;  use strict;
 use CGI;  use CGI qw/:standard/;
   use DBI;
   
   my $secretary="elir\@immisrael.com";
   my $SENDMAIL = "/usr/sbin/sendmail";
   my $questions = "../../cfg/chik/q.txt";
   my $header = "../../cfg/chik/h.html";
   my $footer = "../../cfg/f.html";
   
 my $query=new CGI;  my $query=new CGI;
   
 print $query->header;  print $query->header;
 print $query->start_html(-title=>'Вопросы ЧИК',-bgcolor=>'#fff0e0');  print $query->start_html(-title=>'Robot turnira CHIK',-bgcolor=>'#fff0e0');
 print Include_virtual("../dimrub/db/reklama.html");  print Include_virtual("../dimrub/db/reklama.html");
 print $query->h1({'-align'=>'center'},'Вопросы ЧИК');  print $query->h1({'-align'=>'center'},'Робот турнира ЧИК');
   
   open(HEADER,$header);
   print <HEADER>;
   close HEADER;
   
   print "<p> Сейчас на куличках ", `date`," </p>\n";
   
   if ($query->param('Look')) {
       print_list($query);
       $query->delete('Look');
   } elsif ($query->param('Start')) {
       $query->delete('Start');
       print_questions($query);
   }
   
 print_query($query);  print_query($query);
   
   open(FOOTER,$footer);
   print <FOOTER>;
   close FOOTER;
   
   
 print $query->end_html;  print $query->end_html;
   
   
 exit 0;  exit 0;
   
   
Line 91  sub Include_virtual { Line 108  sub Include_virtual {
 sub print_query {  sub print_query {
     my  $query = shift;      my  $query = shift;
     print $query->start_form;      print $query->start_form;
       print $query->h2("Начать игру");
       print "<p>\n";
       print "Рег. номер: ", 
       $query->textfield('regnum'), " ",
       "Пароль: ",$query->password_field('password'), "</p>";
       print "<p>", $query->submit("Start","Start"), " ";
       print $query->defaults('Reset'),"</p>\n";
       print $query->h2("Посмотреть, кто играет");
       print "<p>", $query->submit("Look","Look"), "</p>";
     print $query->end_form;      print $query->end_form;
 }  }
   
   
   
   sub print_list {
       my $query = shift;
   
       my $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "")
           or do {
               print h1("Временные проблемы") . "Робот временно не
                           работает. Заходите попозже.";
               return 0;
           };
       my $sth=$dbh->prepare("SELECT RegNum, Name, StartDate FROM
                              Chik WHERE Started='Y' Order by StartDate");
       $sth->execute;
       print h3("Начали игру:");
       print "<table>\n";
       print "<tr><th>Номер</th><th>Команда</th><th>Начало игры</th></tr>\n";
       while (my @line=$sth->fetchrow) {
           my $date=pop @line;
           $date=convert_date($date);
           push @line,$date;
           print_line(@line);
       }
       print "</table>\n";
       $sth=$dbh->prepare("SELECT RegNum, Name FROM
                                 Chik WHERE Started='N' Order by RegNum");
       $sth->execute;
       print h3("Не начали игру:");
       print "<table>\n";
       print "<tr><th>Номер</th><th>Команда</th></tr>\n";
       while (my @line=$sth->fetchrow) {
           print_line(@line);
       }
       print "</table>\n";
       
       $dbh->disconnect;
       return 0;
       
   }
   
   
   sub print_line {
       print "<tr><td>",join("</td><td>",@_),"</td></tr>\n";
   }
       
        
   sub print_questions {
       my $query = shift;
       my $regnum=$query->param('regnum');
       my $password=$query->param('password');
       my $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "")
           or do {
               print h1("Временные проблемы") . "Робот временно не
                           работает. Заходите попозже.";
               return 1;
           };
       $regnum=$dbh->quote($regnum);
       $password=$dbh->quote($password);
       my $sth=$dbh->prepare("SELECT Name, Email, Started, StartDate FROM
                              Chik WHERE RegNum=$regnum 
                              AND Password=$password");
       $sth->execute;
   
       my @result=$sth->fetchrow;
       if (!scalar @result) {
           print "<p><strong>Пароль неверен. Попробуйте еще раз.</p>\n";
           return 1;
       }
       my ($name,$email,$started,$startdate)=@result;
       $startdate=convert_date($startdate);
       if ($started eq 'Y') {
           print "<p>Ваша команда уже начала играть в $startdate</p>\n";
       } else {
           $sth=$dbh->prepare("UPDATE  Chik SET Started='Y'
                          WHERE RegNum=$regnum");
           $sth->execute;
           open(F, "| $SENDMAIL -t -n" );
           print F <<"EOT";
   To: $secretary
   From: boris\@plmsc.psu.edu
   Subject: Chik: komanda nachala igrat
   MIME-Version: 1.0
   Content-type: text/plain; charset="koi8-r"
   
   EOT
           print F "Команда $name, регистрационный номер $regnum ",
       "начала играть в $startdate\n";
           print F "\n\n--\nРобот\n";
           close F;
           open(F, "| $SENDMAIL -t -n" );
           print F <<"EOT";
   To: $email
   From: boris\@plmsc.psu.edu
   Subject: Voprosy CHIK
   MIME-Version: 1.0
   Content-type: text/plain; charset="koi8-r"
   
   -------------------------------------------------------------
   EOT
   
           open(QUEST,$questions);
           
           print F <QUEST>;
           print F <<"EOT";
   
   -------------------------------------------------------------
   EOT
           print F "\n\n--\nРобот\n";
           close F;
           close (QUEST);
       }
       open(QUEST,$questions);
       print "<hr>\n<pre>\n";
       print <QUEST>;
       print "</pre>\n<hr>\n";
       return 0;
   }
   
   sub convert_date {
       my $date=shift;
       my $year=substr($date,0,4);
       my $month=substr($date,4,2);
       my $day=substr($date,6,2);
       my $hour=substr($date,8,2);
       my $min=substr($date,10,2);
       my $sec=substr($date,12,2);
       return "$year-$month-$day $hour:$min:$sec";
   }

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>