#!/usr/bin/perl -w use CGI qw/:standard/; require "common.sub"; use strict; #use CGI::Carp qw(fatalsToBrowser); #warn "this is a complaint"; #die "But this is serious"; my $username = "$common::auth::user"; my ($time, $date); # Declare current_time_date() args #my ($in_time, $print_date, $hidden_oid, @out_oid); # Declare check_for_in() args print header; if ($username eq ""){ &common::auth::print_error; }elsif($username eq "$common::auth::admin"){ &common::sql::Create_DB_Connection; admin_get_users_in(); current_time_date(); print_admin_data(); }else{ &common::sql::Create_DB_Connection; current_time_date(); check_for_in ($username); } $common::sql::dbh->disconnect; ####################### GET TIME AND DATE FOR IN FORM sub current_time_date { my ($min, $hour, $day, $month, $year, $calc_year, $calc_month); ($date, $time) = @_; ($min, $hour, $day, $month, $year) = (localtime)[1,2,3,4,5]; #($calc_year, $calc_month); $calc_year = $year+1900; $calc_month = $month+1; $date = "$calc_year-$calc_month-$day"; $time = sprintf("%d:%02d", $hour,$min); } ####################### END GET TIME AND DATE FOR IN FORM ################ BEGIN GET USERS CLOCKED IN SUBROUTINE - ADMIN sub admin_get_users_in { $main::SQL="SELECT oid,username,start_stamp FROM timeclock WHERE total_hours = NULL AND total_minutes = NULL AND end_stamp = NULL ORDER BY username"; common::sql::Do_SQL(); } ################ END GET USERS CLOCKED IN SUBROUTINE ################ CHECK IF CLOCKED IN SUBROUTINE - NORMAL sub check_for_in ($) { my ($username) = @_; my (@clocked_in, @date_array01, $in_time_sec, @in_time_array, $print_date, $in_time, $hidden_oid); # $main::SQL="SELECT oid,* FROM timeclock WHERE end_stamp = NULL AND total_hours = NULL AND total_minutes = NULL AND username = #'$username'"; $main::SQL="SELECT oid,* FROM timeclock WHERE end_stamp = NULL AND username = '$username'"; common::sql::Do_SQL(); @clocked_in = $common::sql::sth->fetchrow(); unless ($clocked_in[1] eq "$username"){ clock_in_form($username, $date, $time); }else{ $main::SQL="SELECT oid,* FROM timeclock WHERE username = '$username' AND oid = $clocked_in[0]"; common::sql::Do_SQL(); while(my @out_oid = $common::sql::sth->fetchrow()){ @date_array01 = split(/ /,$out_oid[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]); $hidden_oid = $out_oid[0]; clock_out_form($hidden_oid, $username, $time, $print_date, $in_time, @out_oid); } } } ################ END CHECK FOR IN SUBROUTINE