Scan
|
#!/usr/bin/perl -Tw
#####################################
# Script by Joseph W. Guillaume #
# All Rights Reserved #
# Last updated June 6, 2005 #
#####################################
use strict;
use CGI qw(:standard);
print "Content-Type: text/html\n\n";
print '<body bgcolor="cccccc">';
#####################################
my $employee=param('employee_name');
my $certification=param('certification');
my $month=param('month');
my @month="";
my $day=param('day');
my $year=param('year');
my $mo_yr=param('mo_yr');
my @data=();
my @data_names;
my $data_names;
my $data;
my $lines;
my $lines1;
my $number;
my $file;
my $time;
my $i;
my @mon = qw (January Feburary March April May June July August September October November December);
my $now_month;
my $now_yr;
my $now_year;
my $date;
my $expir_month;
my $expir_year;
#####################################
my $s;
my $m;
my $h;
my $wday;
my $yday;
my $mon;
my $isdst;
my $date_command;
my @Days;
my @days;
my @months;
my @MONTHS;
my @Months;
my $hour;
my $min;
my $sec;
my $mday;
my $yr;
my $Year;
my $date1;
my $date2;
my $date3;
my $local;
#####################################
# Read Names file #
#####################################
open(JOE, "<Files/Names.txt") or die "No can! :$!";
@data_names = <JOE>;
chomp @data_names;
close (JOE);
$lines1 =scalar@data_names;
#$line1 is the number of employees names in the data_names array
#####################################
# Read File #
#####################################
for ($i=0; $i < @data_names; $i++) {
$file = $data_names[$i];
open(JOE, "< Files/$file.txt")or die "No can!";
#print "Opening file named $file.txt<p\/>";
@data = <JOE>;
chomp @data;
close (JOE);
#$lines is the number of lines in the data array
#####################################
# Find Expiration Date #
#####################################
$lines=scalar@data/5;
if ($lines <= 0) {
print "has no records at this time.";
}
while ($lines >=1) {
$certification = shift(@data);
my $number = shift (@data);
$month = $mon [$number-1];
$day = shift (@data);
$year = shift(@data);
$mo_yr = shift(@data);
$lines--;
}
}
##############################################
# $month $year value in to subroutine
&DATESUBROUTINE;
# $now_month $now_yr value from subroutine
##############################################
$mo_yr= '09 2005';
##############################################
# Calculate Todays Date against Expir. Date #
##############################################
$expir_month = substr ($mo_yr, 0, 2);
$expir_year = substr ($mo_yr, 3, 5);
if ($expir_month <= $now_month and $expir_year ==$now_yr) {
print "I will send an e-mail <p\/>";
#######################################################
# This is designed for Net::SMTP module
# from the llama book p.286
#######################################################
# $smtp mail-> ($from);
# $smtp to -> ($to);
# $smtp -> data();
# $smtp mail->datasend ("To: $email_address");
# $smtp mail->datasend ("Subject: Your certification in $certification is");
# $smtp mail->datasend ("about to expire in aprox. three months.");
# $smtp mail->datasend ("Any other messages may be written here.");
# $smtp->dataend();
# $smtp->quit;
}
elsif ($expir_month >= $now_month) {
print "No Certifications within 3 months of expirirng today $date2<p\/>";
}
else { print "Program ERROR!";
}
#######################################################
# Variables for Troubleshooting #
#######################################################
#$now_month
#$now_year
#$expir_month
#$expir_year
#print "Month and Year Variable (mo_yr) $mo_yr<p\/>";
#print "Date Now Variable (date3) $date3<p\/>";
#print "Now month is $now_month <p\/>";
#print "Now year is $now_yr <p\/><HR>";
#print "Expiration month is $expir_month <p\/>";
#print "Expiration year is $expir_year <p\/>";
#####################################
print "<p\/><hr><p\/>";
print '<div align="center"><table width="120" border="1" cellspacing="2" cellpadding="0"><tr><td align="center">To go Back</td></tr><tr><td align="center"><a href="http://127.0.0.1/FFD_folder/index.html">ClickNote: This is the localhost URL Here</a></td></tr></table><p></p></div>';
#print "<p\/><hr><p\/>";
print '</body';
#####################################
exit;
#####################################
# Date Subroutine #
#####################################
sub DATESUBROUTINE {
$date_command = "/bin/date";
@Days = ( 'Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday' );
@days = ( 'Sun','Mon','Tue','Wed','Thu','Fri','Sat' );
@MONTHS = ( 'January','February','March','April',
'May','June','July','August',
'September','October','November','December' );
@Months = ( 'Jan','Feb','Mar','Apr','May','June',
'July','Aug','Sep','Oct','Nov','Dec' );
@months = ( '01','02','03','04','05','06',
'07','08','09','10','11','12' );
( $s,$m,$h,$mday,$mon,$yr,$wday,$yday,$isdst ) = localtime( time );
if( $hour < 10 ) { $hour = "0$hour" }
if( $min < 10 ) { $min = "0$min" }
if( $sec < 10 ) { $sec = "0$sec" }
if( $mday < 10 ) { $mday = "0$mday" }
$yr = substr( $yr,1,2 );
$Year = "20$yr";
$date1 = "$Days[ $wday ], $MONTHS[ $mon ] $mday, $Year";
$date2 = "$Months[ $mon ] $mday, $Year";
$date3 = "$months[ $mon ]/$mday/$yr";
$local = localtime( time );
#####################################
$now_month = $months[ $mon ];
$now_yr = $Year;
}