Hi all,
I have a flat file database, I have one field is startdate, if startdate is greater than 90 days it will be black, between 60 and 90 is red, between 30 and 60 days is yellow and less than 30 days is green.
Here is my code
<code>
#!/opt/WWW/tools/perl5/perl
$updatetime=`cat lastupdate`;
use Time::Local;
$today = timelocal(localtime);
$Total=`cat pa.TXT | wc -l`;
sub date_to_unix {
my $date = @_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
$time = timelocal($hour, $min, $sec, $day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
my $count = 0;
my $countgt30 = 0;
my $countlt60 = 0;
my $countgt90 = 0;
open (DATA,"pa.TXT") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;
&header_response;
$x=0;
foreach $line (@data) {
$x++;
($Router, $LogOp, $SFC , $Priority, $site, $itemgroup, $itemid, $nc, $shoporder, $status, $starttime)=split(/\|/,$line);
my $epdate = &date_to_unix($starttime);
if ($epdate >= ($today - 2592000)) { # within than 30 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>Less 30 days</TD><TD>$epdate</TD><TD bgcolor=00ff00>$starttime </TD></TR> \n";
$count++;
}
elsif (($epdate >= ($today - 5184000)) && ($epdate < ($today - 2592000))) { # more than 30 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>30 and 60</TD><TD>$epdate </TD><TD bgcolor=yellow>$starttime </TD></TR> \n";
$countgt30++;
}
elsif (($epdate >= ($today - 7776000)) && ($epdate < ($today - 5184000))) { # less than 60 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>60 and 90</TD><TD>$epdate</TD><TD bgcolor=red><font color=white>$starttime </font></TD></TR> \n";
$countlt60++;
}
elsif ($epdate < ($today - 7776000)) { # more than 90 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>more than 90</TD><TD>$epdate</TD><TD bgcolor=black><font color=yellow>$starttime </font></TD></TR> \n";
$countgt90++;
}
}
&footer_response;
####################################################################################################
sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
sub header_response
{
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>test </TITLE>\n";
print "</HEAD>\n";
print qq^<BODY BGCOLOR="#ffffff" TEXT="blue" LINK="#FF6633" VLINK="#FF9933" ALINK="#336699">\n^;
print "$updatetime \n";
print "<BR>\n";
print "<CENTER><a href=#colorcode><IMG SRC='../images/color.gif' border=0></a></CENTER>\n";
print "<BR>\n";
print "<BR><center><FONT size=+1><TABLE BORDER=1><TR bgcolor=#666699><TD><P align=right><font color=white>Qty</P></TD><TD><center><font color=white>Router</center></TD><TD><font color=white><center>LogOp</center></TD><TD><font color=white><center>SFC #</center></TD><TD><font color=white><center>Item <BR>Group</center></TD><TD><font color=white><center>Item ID</center></TD><TD><font color=white><center>No <BR>Of<BR>NCs </center></TD><TD><font color=white><center>Check Date</center></TD><TD><font color=white><center>Epochstartdate</center></TD><TD><font color=white><center>Start Time</center></TD></TR>\n";
return;
}
sub footer_response
{
print "</TABLE></font></CENTER>\n";
print "<BR><BR>\n";
print "<center><a name=colorcode><TABLE WIDTH=600 BORDER=0 CELLPADDING=4 CELLSPACING=3 ><TR VALIGN=center><font color=black size=+1><B> Total $Total PAs opened in SFE</font></TR><TBODY><TR VALIGN=BOTTOM><TD WIDTH=290 bgcolor=00ff00><P ALIGN=LEFT><font color=blue> $count PAs are opened within 30 days </B></font></P></TD><TD WIDTH=290 bgcolor=yellow><P ALIGN=LEFT><font color=blue>$countgt30 PAs are opened > 30 and < 60 days </font></P></TD></TR><TR><TD WIDTH=290 VALIGN=BOTTOM bgcolor=red><P ALIGN=LEFT><font color=white>$countlt60 PAs are opened > 60 and < 90 days </font></P></TD><TD WIDTH=290 VALIGN=TOP bgcolor=000000><P ALIGN=LEFT> <font color=yellow> $countgt90 PAs are opened > 90 days</font></P></TD></TR></TBODY></TABLE></center>\n\n";
print "<BR><BR>\n";
print " </BODY></HTML>\n";
return;
}
</code>
and here is my flat file:
<code>
Para17537 |WYU |226H28EF | 999|BGH |AVALANCHE |595-6510-01 | 0|PA17537A4 |In |07/09/2002 03:10:14
Para17537 |WYU |226H28EC | 999|BGH |AVALANCHE |595-6507-01 | 0|PA17537A1 |In |07/09/2002 03:10:13
Para17537 |WYU |226H28EE | 999|BGH |AVALANCHE |595-6509-01 | 0|PA17537A3 |In |07/09/2002 03:10:14
Para17537 |WYU |226H28ED | 999|BGH |AVALANCHE |595-6508-01 | 0|PA17537A2 |In |07/09/2002 03:10:14
Sacra16044 |BFA |5015777012150 | 5|BGH |HFGD |501-5777-15_PA16044 | 0|52401-001 |In |05/30/2002 23:22:49
Sacra16044 |HJO |5015777012083 | 5|BGH |HFGD |501-5777-15_PA16044 | 2|52401-001 |In |05/30/2002 23:22:19
Sacra16179 |HJO |5015777008990 | 5|BGH |HFGD |501-5777-16_PA16179 | 2|61601-001 |In |09/30/2000 22:31:50
Sacra16179 |HJO |5015777008974 | 5|BGH |HFGD |501-5777-16_PA16179 | 2|61601-001 |In |06/22/2001 15:35:15
</code>
How can the color is black when it have blank $epdate and why it is blank?
Thanks for your help.
I have a flat file database, I have one field is startdate, if startdate is greater than 90 days it will be black, between 60 and 90 is red, between 30 and 60 days is yellow and less than 30 days is green.
Here is my code
<code>
#!/opt/WWW/tools/perl5/perl
$updatetime=`cat lastupdate`;
use Time::Local;
$today = timelocal(localtime);
$Total=`cat pa.TXT | wc -l`;
sub date_to_unix {
my $date = @_[0];
my ($time);
my ($mon, $day, $year) = split(/\//, $_[0]);
my ($hour, $min, $sec) = split(/:/, $_[0]);
unless ($day and $mon and $year) { return undef; }
use Time::Local;
eval {
$mon = int($mon) - 1; $day = int($day); $year = int($year) - 1900;
$time = timelocal($hour, $min, $sec, $day, $mon, $year);
};
if ($@) { return undef; } # Could return 0 if you want.
return ($time);
}
my $count = 0;
my $countgt30 = 0;
my $countlt60 = 0;
my $countgt90 = 0;
open (DATA,"pa.TXT") || die ("Can't Open data File \n");
@data=<DATA>;
close DATA;
&header_response;
$x=0;
foreach $line (@data) {
$x++;
($Router, $LogOp, $SFC , $Priority, $site, $itemgroup, $itemid, $nc, $shoporder, $status, $starttime)=split(/\|/,$line);
my $epdate = &date_to_unix($starttime);
if ($epdate >= ($today - 2592000)) { # within than 30 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>Less 30 days</TD><TD>$epdate</TD><TD bgcolor=00ff00>$starttime </TD></TR> \n";
$count++;
}
elsif (($epdate >= ($today - 5184000)) && ($epdate < ($today - 2592000))) { # more than 30 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>30 and 60</TD><TD>$epdate </TD><TD bgcolor=yellow>$starttime </TD></TR> \n";
$countgt30++;
}
elsif (($epdate >= ($today - 7776000)) && ($epdate < ($today - 5184000))) { # less than 60 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>60 and 90</TD><TD>$epdate</TD><TD bgcolor=red><font color=white>$starttime </font></TD></TR> \n";
$countlt60++;
}
elsif ($epdate < ($today - 7776000)) { # more than 90 days
print "<TR><TD>$x</TD><TD>$Router</TD><TD>$LogOp</TD><TD>$SFC</TD><TD>$itemgroup </TD><TD>$itemid </TD><TD>$nc </TD><TD>more than 90</TD><TD>$epdate</TD><TD bgcolor=black><font color=yellow>$starttime </font></TD></TR> \n";
$countgt90++;
}
}
&footer_response;
####################################################################################################
sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimiter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back to newlines..
}
return @array;
}
sub header_response
{
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>test </TITLE>\n";
print "</HEAD>\n";
print qq^<BODY BGCOLOR="#ffffff" TEXT="blue" LINK="#FF6633" VLINK="#FF9933" ALINK="#336699">\n^;
print "$updatetime \n";
print "<BR>\n";
print "<CENTER><a href=#colorcode><IMG SRC='../images/color.gif' border=0></a></CENTER>\n";
print "<BR>\n";
print "<BR><center><FONT size=+1><TABLE BORDER=1><TR bgcolor=#666699><TD><P align=right><font color=white>Qty</P></TD><TD><center><font color=white>Router</center></TD><TD><font color=white><center>LogOp</center></TD><TD><font color=white><center>SFC #</center></TD><TD><font color=white><center>Item <BR>Group</center></TD><TD><font color=white><center>Item ID</center></TD><TD><font color=white><center>No <BR>Of<BR>NCs </center></TD><TD><font color=white><center>Check Date</center></TD><TD><font color=white><center>Epochstartdate</center></TD><TD><font color=white><center>Start Time</center></TD></TR>\n";
return;
}
sub footer_response
{
print "</TABLE></font></CENTER>\n";
print "<BR><BR>\n";
print "<center><a name=colorcode><TABLE WIDTH=600 BORDER=0 CELLPADDING=4 CELLSPACING=3 ><TR VALIGN=center><font color=black size=+1><B> Total $Total PAs opened in SFE</font></TR><TBODY><TR VALIGN=BOTTOM><TD WIDTH=290 bgcolor=00ff00><P ALIGN=LEFT><font color=blue> $count PAs are opened within 30 days </B></font></P></TD><TD WIDTH=290 bgcolor=yellow><P ALIGN=LEFT><font color=blue>$countgt30 PAs are opened > 30 and < 60 days </font></P></TD></TR><TR><TD WIDTH=290 VALIGN=BOTTOM bgcolor=red><P ALIGN=LEFT><font color=white>$countlt60 PAs are opened > 60 and < 90 days </font></P></TD><TD WIDTH=290 VALIGN=TOP bgcolor=000000><P ALIGN=LEFT> <font color=yellow> $countgt90 PAs are opened > 90 days</font></P></TD></TR></TBODY></TABLE></center>\n\n";
print "<BR><BR>\n";
print " </BODY></HTML>\n";
return;
}
</code>
and here is my flat file:
<code>
Para17537 |WYU |226H28EF | 999|BGH |AVALANCHE |595-6510-01 | 0|PA17537A4 |In |07/09/2002 03:10:14
Para17537 |WYU |226H28EC | 999|BGH |AVALANCHE |595-6507-01 | 0|PA17537A1 |In |07/09/2002 03:10:13
Para17537 |WYU |226H28EE | 999|BGH |AVALANCHE |595-6509-01 | 0|PA17537A3 |In |07/09/2002 03:10:14
Para17537 |WYU |226H28ED | 999|BGH |AVALANCHE |595-6508-01 | 0|PA17537A2 |In |07/09/2002 03:10:14
Sacra16044 |BFA |5015777012150 | 5|BGH |HFGD |501-5777-15_PA16044 | 0|52401-001 |In |05/30/2002 23:22:49
Sacra16044 |HJO |5015777012083 | 5|BGH |HFGD |501-5777-15_PA16044 | 2|52401-001 |In |05/30/2002 23:22:19
Sacra16179 |HJO |5015777008990 | 5|BGH |HFGD |501-5777-16_PA16179 | 2|61601-001 |In |09/30/2000 22:31:50
Sacra16179 |HJO |5015777008974 | 5|BGH |HFGD |501-5777-16_PA16179 | 2|61601-001 |In |06/22/2001 15:35:15
</code>
How can the color is black when it have blank $epdate and why it is blank?
Thanks for your help.