#!/usr/bin/perl -W
use strict;
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
my $q = new CGI;
# Check user is logged in and get user name and shift
if(defined $q->cookie('TASKLIST_LOGIN')) {
my $cookie = $q->cookie('TASKLIST_LOGIN');
(my $username, my $SHIFT) = split(/:/, $cookie);
# Set up date and time functionality
my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ) ;
(my $sec, my $min, my $hour, my $day, my $month, my $year) = localtime(time);
$year += 1900;
if ($day < 10) { $day = "0$day"; }
if ($month < 10) { $month = "0$month"; }
my $MONTH = $months[$month];
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }
# initialize variables & Assign Values
my $date = ("$year$MONTH$day");
my $time = ("$hour:$min");
my $tasktime = param ('tasktime');
my $task = param ('task');
my $platform = param ('platform');
my $action = param ('action');
my $username2 = param ('name');
my $count = param ('count');
my $fcheck = param ('fcheck');
my $server_IP = "$ENV{'SERVER_ADDR'}";
my $base = "/var/[URL unfurl="true"]www/htdocs/midr/tasklist";[/URL]
my $logdir = "/var/[URL unfurl="true"]www/htdocs/midr/tasklist/tmplogs";[/URL]
my $dayt = ("$months[$month] $day, $year");
my $SHIFT2 = "$SHIFT";
$SHIFT2 =~ tr/n|d/N|D/;
## Main program begins ##
sub format {
# Begin Format function
$tasktime = shift; $task = shift; $platform = shift; $action = shift; $username = shift; my $count = shift;
if (-e "$logdir/$count$SHIFT") { exit; }
print ("<tr>\n");
print (' <form method="post" id="tasks" name="tasks" action="' . "[URL unfurl="true"]http://$server_IP/cgi-bin/tasklist/$SHIFT"[/URL] . 's.cgi#x">' . "\n");
print <<FOO;
<td>$tasktime</td>
<td>$task</td><a name=x></a>
<td>$platform</td>
<td>$action</td>
<td><input type="text" name="name" size="10" value=$username></td>
<td><input type="submit" value="submit"></td>
<input type="hidden" name="count" value="$count">
<input type="hidden" name="tasktime" value="$tasktime">
<input type="hidden" name="action" value="$action">
<input type="hidden" name="platform" value="$platform">
<input type="hidden" name="task" value="$task">
<input type="hidden" name="fcheck" id="fcheck" value="nogo">
</form>
</tr>
FOO
} # End of format function
if ($count >= "0001")
# these three sections creates the shift log file (nightlog.html for the night shifts)
# and the individual log files for each task as it is completed.
{
if ($SHIFT eq 'night') {
if (! -e "$base/nightlog.html") {
open(OUT, ">$base/nightlog.html");
printf OUT "<html>\n<head><title>$SHIFT2 Tasklist</title>\n";
printf OUT "\n</head><body bgcolor=#9099b6><center>\n";
printf OUT "<h2>Midrange Daily Tasklist<br />$dayt - $SHIFT2 Shift</h2>\n";
printf OUT '<table width="95%" border=2 valign=center halign=center bgcolor=white>';
printf OUT "\n<tr>\n";
printf OUT " <td><b>Time-Date</b></td>\n";
printf OUT " <td><b>Task</b></td>\n";
printf OUT " <td><b>Platform</b></td>\n";
printf OUT " <td><b>Action</b></td>\n";
printf OUT " <td><b>Name</b></td>\n";
printf OUT " <td><b>Time</b></td>\n";
printf OUT "</tr>\n";
close(OUT);
} }
my $tempfile= "$logdir/$count" . "$SHIFT";
open(OUT, ">$tempfile");
printf OUT "<tr>\n";
printf OUT " <td>$tasktime</td>\n";
printf OUT " <td>$task</td>\n";
printf OUT " <td>$platform</td>\n";
printf OUT " <td>$action</td>\n";
printf OUT " <td>$username2</td>\n";
printf OUT " <td>$time</td>\n";
printf OUT "</tr>\n";
close(OUT);
# this part appends the task info to the shift log .html file
if ($SHIFT eq 'day') { open(FILE, ">>$base/$date-am.html"); }
if ($SHIFT eq 'night') { open(FILE, ">>$base/nightlog.html"); }
printf FILE "<tr>\n";
printf FILE " <td>$tasktime</td>\n";
printf FILE " <td>$task</td>\n";
printf FILE " <td>$platform</td>\n";
printf FILE " <td>$action</td>\n";
printf FILE " <td>$username2</td>\n";
printf FILE " <td>$time</td>\n";
printf FILE "</tr>\n";
close(FILE);
}
if ($count == "190001")
# Creates date variable to use in renaming the log file
# to the correct date at the end of the night shift.
{
my $tempfile="$base/backday-temp";
open(TMP, ">$tempfile");
printf TMP $date;
close(TMP);
}
if ($fcheck eq 'done') {
my $tempfile="$base/TEST-FILE";
open(TMP, ">$tempfile");
printf TMP "Line of text for testing. check = $fcheck";
close(TMP);
}
# Main HTML code for this page
print ("Content-type: text/html\n\n<html>\n<head>");
print("\n<title>$SHIFT2 Tasklist</title>\n\n");
print ("\n\n" . '<meta http-equiv="refresh" content="35; url=' . $SHIFT . 's.cgi#x">' . "\n\n");
print <<FOO;
[COLOR=red]
<script language="JavaScript" type="text/javascript">
function isform() {
var shift = "$SHIFT";
var count = document.forms.length;
alert("Count is at "+count);
if ((count == 0) && (shift == "night")) {
alert("PERL worked.");
document.getElementById("fcheck").value="done";
alert("Javascript worked too");
}
}
</script>
[/color]
FOO
print ("\n</head>\n" . '<body bgcolor="#9099b6" onload="return(isform());">' . "\n");
print ("<center>\n");
print ("<h2>Midrange Daily Tasklist - $SHIFT2 Shift</h2>\n");
print ("<table width=95% border=2 valign=center halign=center bgcolor=white>\n");
print ("<tr>\n<td width=5%><b>Time/Date</b></td>\n");
print (" <td width=5%><b>Task</b></td>\n");
print (" <td width=5%><b>Platform</b></td>\n");
print (" <td width=60%><b>Action</b></td>\n");
print (" <td width=5%><b>Name</b></td>\n");
print (" <td width=5%><b>Time</b></td>\n</tr>\n");
#### Tasks Begin Here ####
##########################
if (-e "$logdir/190001night")
{ open(TMP, "$logdir/190001night"); while(<TMP>) {print $_; } close(TMP); }
elsif (! -e "$logdir/190001night")
{ &format("19:00- Daily","Monitoring","AS/400",'<ul><li>Task number 1</li></ul>',$username,'190001'); }
if (-e "$logdir/190002night")
{ open(TMP, "$logdir/190002night"); while(<TMP>) {print $_; } close(TMP); }
elsif ((! -e "$logdir/190002night") and (! -e "$logdir/190001night"))
{ &format("19:00- Daily","Monitoring","NT",'<ul><li>Task number 2</li></ul>'," ","190002"); }
elsif ((! -e "$logdir/190002night") and (-e "$logdir/190001night"))
{ &format("19:00- Daily","Monitoring","NT",'<ul><li>Task number 2</li></ul>',$username,"190002"); }
if (-e "$logdir/190003night")
{ open(TMP, "$logdir/190003night"); while(<TMP>) {print $_; } close(TMP); }
elsif ((! -e "$logdir/190003night") and (! -e "$logdir/190002night"))
{ &format("19:00- Daily","Tape Return Process","AS/400",'<ul><li>Task number 3</li></ul>'," ","190003"); }
elsif ((! -e "$logdir/190003night") and (-e "$logdir/190002night"))
{ &format("19:00- Daily","Tape Return Process","AS/400",'<ul><li>Task number 3</li></ul>',$username,"190003"); }
if (-e "$logdir/190004night")
{ open(TMP, "$logdir/190004night"); while(<TMP>) {print $_; } close(TMP); }
elsif ((! -e "$logdir/190004night") and (! -e "$logdir/190003night"))
{ &format("19:00- Daily","Tape Management","AS/400",'<ul><li>Task number 4</li></ul>'," ","190004"); }
elsif ((! -e "$logdir/190004night") and (-e "$logdir/190003night"))
{ &format("19:00- Daily","Tape Management","AS/400",'<ul><li>Task number 4</li></ul>',$username,"190004"); }
if (-e "$logdir/190005night")
{ open(TMP, "$logdir/190005night"); while(<TMP>) {print $_; } close(TMP); }
elsif ((! -e "$logdir/190005night") and (! -e "$logdir/190004night"))
{ &format("19:00- Daily","Backup","Unix",'<ul><li>Task number 5</li></ul>'," ","190005"); }
elsif ((! -e "$logdir/190005night") and (-e "$logdir/190004night"))
{ &format("19:00- Daily","Backup","Unix",'<ul><li>Task number 5</li></ul>',$username,"190005"); }
if (-e "$logdir/190006night")
{ open(TMP, "$logdir/190006night"); while(<TMP>) {print $_; } close(TMP); }
elsif ((! -e "$logdir/190006night") and (! -e "$logdir/190005night"))
{ &format("19:00- Tuesday","Backup","FDMS RSC6000",'<ul><li>Task number 6</li></ul>'," ","190006"); }
elsif ((! -e "$logdir/190006night") and (-e "$logdir/190005night"))
{ &format("19:00- Tuesday","Backup","FDMS RSC6000",'<ul><li>Task number 6</li></ul>',$username,"190006"); }
##### End of Tasks #####
# If user is not logged in then return them to the login page
} else {
print $q->redirect(-location=>'../../midr/tasklist/login.html');
}