Subversion Repositories ORC

Rev

Rev 8 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }

use cPanelUserConfig;
use CGI qw/:standard/;
use RollerCon;
use Spreadsheet::WriteExcel;
use DateTime;
use DateTime::Duration;

my $cookie_string = authenticate(2) || die;
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $user = getUser($EML);
my $username = $user->{derby_name};
my $RCid = $user->{RCid};
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");

my $GID = param('GID');
my $T1  = param('T1');
my $T2  = param('T2');
my $action = param('action');

die unless $GID;

my $dbh = getRCDBH;
my $gethan = $dbh->prepare("select * from v_scores where id = ?");
my $puthan = $dbh->prepare("replace into score (gid, team1_score, team2_score) values (?, ?, ?)");

my $savestatus = "";
my $reload = "";
if ($action eq "Save") {
        if ($T1 eq '' or $T2 eq '') {
                $savestatus = "<font color=red><b>ERROR:</b> Missing Score!</font>";
        } else {
                $savestatus = "Saved!";
                $reload = 'onload="reloadParent()"';
                $puthan->execute($GID, $T1, $T2) or $savestatus="<font color=red><b>ERROR:</b> Error Saving!</font>";
        }
}

$gethan->execute($GID);
my ($game) = $gethan->fetchrow_hashref();

print CGI::header(-cookie=>$RCAUTH_cookie);

print<<page1;
<HTML><HEAD>
        <TITLE>RC17 Game Score Recorder</TITLE>
        <link rel="stylesheet" type="text/css" href="/rollercon.css">
</HEAD>
<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#FF0000" $reload>

        <form action="update_score.pl" method=GET name=ScoreUpdate>
        $savestatus
        <table>
        <tr>
                <td colspan=2>Game: $game->{id}<input type=hidden name=GID value=$game->{id}> - $game->{dayofweek} - $game->{track} - $game->{time}</TD>
        </tr><tr>
                <td>$game->{team1}</td><td><input type=text name=T1 size=4 value=$game->{team1_score}></td>
        </tr><tr>
                <td>$game->{team2}</td><td><input type=text name=T2 size=4 value=$game->{team2_score}></td>
        </tr><tr>
                <td colspan=2><input type=Submit name=action value=Reset> <input type=Submit name=action value=Save> <input type=Reset value=Cancel onClick=window.close();></td>
        </tr>
        </table>
        </form>

page1

if ($savestatus ne '') {
        print<<refresh;
        <SCRIPT language="JavaScript">
        <!-- 
                        function sleep(milliseconds) {
                          var start = new Date().getTime();
                          for (var i = 0; i < 1e7; i++) {
                            if ((new Date().getTime() - start) > milliseconds){
                              break;
                            }
                          }
                        }
         
                        function reloadParent() {
              window.opener.location.reload();
              setTimeout(() => { window.close(); }, 3000);
                        }

        //-->
        </SCRIPT>

refresh
}

print "</BODY></HTML>\n";