#!/usr/bin/perl -w
use CGI qw/:standard/;
use strict;
require "common.sub";
#use CGI::Carp qw(fatalsToBrowser);
#warn "this is a complaint";
#die "But this is serious";
print header;
####### SQL CONNECT
&common::sql::Create_DB_Connection;
################## BEGIN DETERMINE ADMIN OR NORMAL USER
my ($username, $syear, $smonth, $sday, $eyear, $emonth, $eday, $start_date, $end_date);
if ($common::auth::user eq "$common::auth::admin"){
$username = &common::sql::filter(param("username"));
$syear = &common::sql::filter(param("syear"));
$smonth = &common::sql::filter(param("smonth"));
$sday = &common::sql::filter(param("sday"));
$eyear = &common::sql::filter(param("eyear"));
$emonth = &common::sql::filter(param("emonth"));
$eday = &common::sql::filter(param("eday"));
$start_date = "$syear-$smonth-$sday";
$end_date = "$eyear-$emonth-$eday";
##### SUB CALLS - This allows you to list all users #####
if ($username eq ""){
&get_all_users;
&admin_results;
}else{
&get_info;
&admin_results;
}
}elsif ($common::auth::user eq ""){
&common::auth::print_error;
}else{
$username = $common::auth::user ;
$syear = &common::sql::filter(param("syear"));
$smonth = &common::sql::filter(param("smonth"));
$sday = &common::sql::filter(param("sday"));
$eyear = &common::sql::filter(param("eyear"));
$emonth = &common::sql::filter(param("emonth"));
$eday = &common::sql::filter(param("eday"));
$start_date = "$syear-$smonth-$sday";
$end_date = "$eyear-$emonth-$eday";
#### SUB CALLS
&get_info;
&normal_results;
}
################## END DETERMINE ADMIN OR NORMAL USER
# Disconnect from the database
$common::sql::sth->finish;
$common::sql::dbh->disconnect;
################ BEGIN GET INFO SUBROUTINE
sub get_all_users{
$main::SQL="SELECT oid,* FROM timeclock WHERE start_stamp >= '$start_date' AND end_stamp <= '$end_date' ORDER BY username";
&common::sql::Do_SQL;
}
################ END GET INFO SUBROUTINE
################ BEGIN GET INFO SUBROUTINE
sub get_info{
$main::SQL="SELECT oid,* FROM timeclock WHERE username = '$username' AND start_stamp >= '$start_date' AND end_stamp <= '$end_date' ORDER BY start_stamp";
&common::sql::Do_SQL;
}
################ END GET INFO SUBROUTINE
################ BEGIN ADMIN RESULTS SUBROUTINE
sub admin_results{
my ($all_time, $search_name);
print <
secret.tld - Timeclock Search
Home |
Timeclock Administration
Search Results for $username, $start_date Through $end_date.
|
secret.tld - Employee Timeclock Database
|
|
Date |
Username |
Clocked In |
Clocked Out |
Daily Total |
Notes |
HTML
while (my @row = $common::sql::sth->fetchrow()){
my $daily_time = sprintf("%d:%02d",$row[4],$row[5]);
my ($total_minutes, $total_hours, $all_minutes, $total_time, $total_time_hours, $total_time_minutes);
$total_minutes = $row[5];
$total_hours = $row[4] * 60;
$all_minutes = $total_hours + $total_minutes;
$total_time = $total_time + $all_minutes;
$total_time_hours = int($total_time / 60);
$total_time_minutes = $total_time % 60;
$all_time = sprintf("%d:%02d",$total_time_hours,$total_time_minutes);
## Make our HTML look better if no data.
$row[0] = " " if($row[0] eq "");
$row[1] = " " if($row[1] eq "");
$search_name = $row[1];
$row[2] = " " if($row[2] eq "");
$row[3] = " " if($row[3] eq "");
$row[4] = " " if($row[4] eq "");
$row[5] = " " if($row[5] eq "");
$row[6] = " " if($row[6] eq "");
my (@date_array01, $print_date, $in_time_sec, @in_time_array, $in_time);
@date_array01 = split(/ /,$row[2]);
$print_date = $date_array01[0];
$in_time_sec = $date_array01[1];
@in_time_array = split(/:/,$in_time_sec);
$in_time = join(":",$in_time_array[0],$in_time_array[1]);
my (@date_array02, $out_time_sec, @out_time_array, $out_time);
@date_array02 = split(/ /,$row[3]);
$out_time_sec = $date_array02[1];
@out_time_array = split(/:/,$out_time_sec);
$out_time = join(":",$out_time_array[0],$out_time_array[1]);
print <
$print_date |
$row[1] |
$in_time |
$out_time |
$daily_time |
$row[6] |
HTML
} # End of while.
if($search_name eq ""){
print<The username $username was not found |
HTML
}
print<
|
Total Time: | $all_time | |
HTML
} # End of normal_results subroutine
################ END ADMIN RESULTS SUBROUTINE
################ BEGIN NORMAL RESULTS SUBROUTINE
sub normal_results{
my $all_time;
print <secret.tld - Timeclock Search
Home |
Timeclock |
Search
Search Results for $username, $start_date Through $end_date.
|
secret.tld - Employee Timeclock Database
|
|
Date |
Clocked In |
Clocked Out |
Daily Total |
Notes |
HTML
while (my @row = $common::sql::sth->fetchrow()){
my $daily_time = sprintf("%d:%02d",$row[4],$row[5]);
my ($total_minutes, $total_hours, $all_minutes, $total_time, $total_time_hours, $total_time_minutes);
$total_minutes = $row[5];
$total_hours = $row[4] * 60;
$all_minutes = $total_hours + $total_minutes;
$total_time = $total_time + $all_minutes;
$total_time_hours = int($total_time / 60);
$total_time_minutes = $total_time % 60;
$all_time = sprintf("%d:%02d",$total_time_hours,$total_time_minutes);
## Make our HTML look better if no data.
$row[0] = " " if($row[0] eq "");
$row[1] = " " if($row[1] eq "");
$row[2] = " " if($row[2] eq "");
$row[3] = " " if($row[3] eq "");
$row[4] = " " if($row[4] eq "");
$row[5] = " " if($row[5] eq "");
$row[6] = " " if($row[6] eq "");
my (@date_array01, $print_date, $in_time_sec, @in_time_array, $in_time);
@date_array01 = split(/ /,$row[2]);
$print_date = $date_array01[0];
$in_time_sec = $date_array01[1];
@in_time_array = split(/:/,$in_time_sec);
$in_time = join(":",$in_time_array[0],$in_time_array[1]);
my (@date_array02, $out_time_sec, @out_time_array, $out_time);
@date_array02 = split(/ /,$row[3]);
$out_time_sec = $date_array02[1];
@out_time_array = split(/:/,$out_time_sec);
$out_time = join(":",$out_time_array[0],$out_time_array[1]);
print <
$print_date |
$in_time |
$out_time |
$daily_time |
$row[6] |
HTML
} # End of while.
print<
|
Total Time: | $all_time | |
HTML
} # End of normal_results subroutine
################ END NORMAL RESULTS SUBROUTINE