finished timeclock_edit.php script

basic functionality of timeclock features are done

git-svn-id: svn://192.168.202.10@904 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
mattf
2008-07-01 17:28:37 +00:00
parent 716ea4f1df
commit 1b72c55da5
5 changed files with 95 additions and 157 deletions
+1 -1
View File
@@ -108,7 +108,7 @@ NOTE: Upgrading from 1.1.12-3 to 2.0.1 is at the bottom
21. Added collection of hangup reasons for inbound and outbound calls in the
vicidial_log and vicidial_closer_log tables
22. The start of a new timeclock feature (not finished), including the addition
22. Added a new timeclock feature w/ audit and log, including the addition
of shifts to VICIDIAL user groups and the ability to auto-generate
user IDs as you are adding users to the system. timeclock.php user login
page created and linked to from admin/agent/welcome screens
+1 -1
View File
@@ -8,11 +8,11 @@ This will outline the process I have thought through for adding a timeclock comp
- Maintain an audit trail for manager-modified records
- Add a SHIFT section to administration
- Have reports showing all timeclock totals for various parameters(user-group/time-period/user/current-status/etc...)
- ability to allow managers to alter timeclock records with audit trail
Future planned features:
- Allow restrictions of agent-login by shift
- Allow ability to not allow agents to log-in to any VICIDIAL page(admin or agent) without clocking in.
- ability to allow managers to alter timeclock records with audit trail
- reports showing user log activity outside of shift timeframes
+1 -14
View File
@@ -240,20 +240,6 @@ ALTER TABLE vicidial_users ADD add_timeclock_log ENUM('1','0') default '0';
ALTER TABLE vicidial_users ADD modify_timeclock_log ENUM('1','0') default '0';
ALTER TABLE vicidial_users ADD delete_timeclock_log ENUM('1','0') default '0';
CREATE TABLE vicidial_admin_log (
admin_log_id INT(9) UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
event_date DATETIME NOT NULL,
user VARCHAR(20) NOT NULL,
ip_address VARCHAR(15) NOT NULL,
event_section VARCHAR(30) NOT NULL,
event_type ENUM('ADD','COPY','LOAD','RESET','MODIFY','DELETE','SEARCH','LOGOUT','CLEAR','OTHER') default 'OTHER',
record_id VARCHAR(50) NOT NULL,
event_code VARCHAR(255) NOT NULL,
event_sql TEXT,
index (user),
index (record_id)
);
UPDATE system_settings SET db_schema_version='1091';
CREATE INDEX user ON vicidial_agent_log (user);
@@ -294,3 +280,4 @@ UPDATE system_settings SET db_schema_version='1094';
ALTER TABLE vicidial_campaigns MODIFY campaign_cid VARCHAR(20) default '0000000000';
UPDATE system_settings SET db_schema_version='1095';
@@ -215,6 +215,8 @@ space separated phone number||
Agent Screen Header Date Format||
Agent Screen Customer Date Format||
Agent Screen Customer Phone Format||
ERROR- There is a problem with the data that you entered, please go back||
A timeclock session cannot overlap another timeclock session||
############################################################ CLIENT
+90 -141
View File
@@ -6,6 +6,7 @@
# CHANGES
#
# 80624-1342 - First build
# 80701-1323 - functional beta version done
#
header ("Content-type: text/html; charset=utf-8");
@@ -15,6 +16,14 @@ require("dbconnect.php");
$PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER'];
$PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW'];
$PHP_SELF=$_SERVER['PHP_SELF'];
if (isset($_GET["oldLOGINepoch"])) {$oldLOGINepoch=$_GET["oldLOGINepoch"];}
elseif (isset($_POST["oldLOGINepoch"])) {$oldLOGINepoch=$_POST["oldLOGINepoch"];}
if (isset($_GET["oldLOGOUTepoch"])) {$oldLOGOUTepoch=$_GET["oldLOGOUTepoch"];}
elseif (isset($_POST["oldLOGOUTepoch"])) {$oldLOGOUTepoch=$_POST["oldLOGOUTepoch"];}
if (isset($_GET["oldLOGINdate"])) {$oldLOGINdate=$_GET["oldLOGINdate"];}
elseif (isset($_POST["oldLOGINdate"])) {$oldLOGINdate=$_POST["oldLOGINdate"];}
if (isset($_GET["oldLOGOUTdate"])) {$oldLOGOUTdate=$_GET["oldLOGOUTdate"];}
elseif (isset($_POST["oldLOGOUTdate"])) {$oldLOGOUTdate=$_POST["oldLOGOUTdate"];}
if (isset($_GET["LOGINepoch"])) {$LOGINepoch=$_GET["LOGINepoch"];}
elseif (isset($_POST["LOGINepoch"])) {$LOGINepoch=$_POST["LOGINepoch"];}
if (isset($_GET["LOGOUTepoch"])) {$LOGOUTepoch=$_GET["LOGOUTepoch"];}
@@ -194,6 +203,8 @@ $browser = getenv("HTTP_USER_AGENT");
$LOGOUTmanager_ip = $row[10];
$LOGOUTevent_datestamp =$row[11];
}
$user=$LOGINuser;
}
}
@@ -222,6 +233,7 @@ function run_submit()
// Calculate login time
function calculate_hours()
{
var now_epoch = '<? echo $StarTtimE ?>';
var i=0;
var total_percent=0;
var SPANlogin_time = document.getElementById("LOGINlogin_time");
@@ -247,6 +259,8 @@ function calculate_hours()
var LO_hour = ( ( ( (LO_time_array[0] * 1) * 1000) * 3600 ) );
var LO_date_epoch = Date.parse(LO_date_array[0] + '/' + LO_date_array[1] + '/' + LO_date_array[2]);
var LO_epoch = (LO_date_epoch + LO_sec + LO_min + LO_hour);
var temp_LI_epoch = (LI_epoch / 1000 );
var temp_LO_epoch = (LO_epoch / 1000 );
var epoch_diff = ( (LO_epoch - LI_epoch) / 1000 );
var temp_diff = epoch_diff;
@@ -254,7 +268,8 @@ function calculate_hours()
var go_submit = document.getElementById("go_submit");
go_submit.disabled = true;
if ( (epoch_diff < 86401) && (epoch_diff > 0) )
// length is a positive number and no more than 24 hours, datetime is earlier than right now
if ( (epoch_diff < 86401) && (epoch_diff > 0) && (temp_LI_epoch < now_epoch) && (temp_LO_epoch < now_epoch) )
{
go_submit.disabled = false;
@@ -282,198 +297,128 @@ function calculate_hours()
<CENTER>
<TABLE WIDTH=720 BGCOLOR=#D9E6FE cellpadding=2 cellspacing=0><TR BGCOLOR=#015B91><TD ALIGN=LEFT><? echo "<a href=\"./admin.php\">" ?><FONT FACE="ARIAL,HELVETICA" COLOR=WHITE SIZE=2><B> &nbsp; VICIDIAL ADMIN</a>: Timeclock Record Edit for <? echo $user ?></TD><TD ALIGN=RIGHT><FONT FACE="ARIAL,HELVETICA" COLOR=WHITE SIZE=2><B><? echo date("l F j, Y G:i:s A") ?> &nbsp; </TD></TR>
<?
echo "<TR BGCOLOR=\"#F0F5FE\"><TD ALIGN=LEFT COLSPAN=2><FONT FACE=\"ARIAL,HELVETICA\" COLOR=BLACK SIZE=3><B> &nbsp; \n";
##### BEGIN TIMECLOCK RECORD MODIFY #####
if ( ($invalid_record < 1) or (strlen($timeclock_id)<1) )
{
if ($stage == "edit_TC_log")
{
echo "$LOGINepoch<BR>\n";
echo "$LOGOUTepoch<BR>\n";
echo "$notes<BR>\n";
echo "$LOGINevent_id<BR>\n";
echo "$LOGOUTevent_id<BR>\n";
echo "$LOGINuser<BR>\n";
exit;
}
$log_time = ($LOGOUTepoch - $LOGINepoch);
$NEXTevent_epoch = $StarTtimE;
$PREVevent_epoch = 0;
##### BEGIN TIMECLOCK LOGOUT OF A USER #####
if ( ( ($stage == "tc_log_user_OUT") or ($stage == "tc_log_user_IN") ) and ($modify_timeclock_log > 0) )
{
### get vicidial_timeclock_status record count for this user
$stmt="SELECT count(*) from vicidial_timeclock_status where user='$user';";
if ($DB) {echo "|$stmt|\n";}
$stmt="SELECT event_epoch,timeclock_id from vicidial_timeclock_log where timeclock_id > '$LOGOUTevent_id' and user='$user' order by timeclock_id limit 1;";
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$vts_count = $row[0];
$LOG_run=0;
$last_action_sec=99;
if ($vts_count > 0)
if ($DB) {echo "$stmt\n";}
$tc_logs_to_print = mysql_num_rows($rslt);
if ($tc_logs_to_print > 0)
{
### vicidial_timeclock_status record found, grab status and date of last activity
$stmt="SELECT status,event_epoch from vicidial_timeclock_status where user='$user';";
if ($DB) {echo "|$stmt|\n";}
$rslt=mysql_query($stmt, $link);
$row=mysql_fetch_row($rslt);
$status = $row[0];
$event_epoch = $row[1];
$last_action_date = date("Y-m-d H:i:s", $event_epoch);
$last_action_sec = ($StarTtimE - $event_epoch);
if ($last_action_sec > 0)
{
$totTIME_H = ($last_action_sec / 3600);
$totTIME_H_int = round($totTIME_H, 2);
$totTIME_H_int = intval("$totTIME_H");
$totTIME_M = ($totTIME_H - $totTIME_H_int);
$totTIME_M = ($totTIME_M * 60);
$totTIME_M_int = round($totTIME_M, 2);
$totTIME_M_int = intval("$totTIME_M");
$totTIME_S = ($totTIME_M - $totTIME_M_int);
$totTIME_S = ($totTIME_S * 60);
$totTIME_S = round($totTIME_S, 0);
if (strlen($totTIME_H_int) < 1) {$totTIME_H_int = "0";}
if ($totTIME_M_int < 10) {$totTIME_M_int = "0$totTIME_M_int";}
if ($totTIME_S < 10) {$totTIME_S = "0$totTIME_S";}
$totTIME_HMS = "$totTIME_H_int:$totTIME_M_int:$totTIME_S";
}
else
{
$totTIME_HMS='0:00:00';
}
$NEXTevent_epoch = $row[0];
$NEXTevent_id = $row[1];
}
$stmt="SELECT event_epoch,timeclock_id from vicidial_timeclock_log where timeclock_id < '$LOGINevent_id' and user='$user' order by timeclock_id desc limit 1;";
$rslt=mysql_query($stmt, $link);
if ($DB) {echo "$stmt\n";}
$tc_logs_to_print = mysql_num_rows($rslt);
if ($tc_logs_to_print > 0)
{
$row=mysql_fetch_row($rslt);
$PREVevent_epoch = $row[0];
$PREVevent_id = $row[1];
}
if ( ($LOGINepoch <= $PREVevent_epoch) || ($LOGOUTepoch >= $NEXTevent_epoch) )
{
echo "ERROR- There is a problem with the data that you entered, please go back<BR>\n";
echo "A timeclock session cannot overlap another timeclock session<BR>\n";
echo "$LOGINepoch<BR>\n";
echo "$LOGOUTepoch<BR>\n";
echo "$LOGINevent_id<BR>\n";
echo "$LOGOUTevent_id<BR>\n";
echo "$LOGINuser<BR>\n";
echo "$PREVevent_epoch<BR>\n";
echo "$PREVevent_id<BR>\n";
echo "$NEXTevent_epoch<BR>\n";
echo "$NEXTevent_id<BR>\n";
exit;
}
if ( ($LOGINepoch > $StarTtimE) || ($LOGOUTepoch > $StarTtimE) || ($log_time > 86400) || ($log_time < 1) )
{
echo "ERROR- There is a problem with the data that you entered, please go back<BR>\n";
echo "$LOGINepoch<BR>\n";
echo "$LOGOUTepoch<BR>\n";
echo "$notes<BR>\n";
echo "$LOGINevent_id<BR>\n";
echo "$LOGOUTevent_id<BR>\n";
echo "$LOGINuser<BR>\n";
exit;
}
else
{
### No vicidial_timeclock_status record found, insert one
$stmt="INSERT INTO vicidial_timeclock_status set status='START', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_query($stmt, $link);
$status='START';
$totTIME_HMS='0:00:00';
$affected_rows = mysql_affected_rows($link);
print "<!-- NEW vicidial_timeclock_status record inserted for $user: |$affected_rows| -->\n";
}
$LOGINdatetime = date("Y-m-d H:i:s", $LOGINepoch);
$LOGOUTdatetime = date("Y-m-d H:i:s", $LOGOUTepoch);
##### Run timeclock login queries #####
if ( ( ($status=='AUTOLOGOUT') or ($status=='START') or ($status=='LOGOUT') ) and ($stage == "tc_log_user_IN") )
{
### Add a record to the timeclock log
$stmtA="INSERT INTO vicidial_timeclock_log set event='LOGIN', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', event_date='$NOW_TIME', manager_user='$PHP_AUTH_USER', manager_ip='$ip', notes='Manager LOGIN of user from user status page';";
### update LOGIN record in the timeclock log
$stmtA="UPDATE vicidial_timeclock_log set event_epoch='$LOGINepoch', event_date='$LOGINdatetime', manager_user='$PHP_AUTH_USER', manager_ip='$ip', notes='Manager MODIFY', login_sec='$log_time' where timeclock_id='$LOGINevent_id';";
if ($DB) {echo "$stmtA\n";}
$rslt=mysql_query($stmtA, $link);
$affected_rows = mysql_affected_rows($link);
$timeclock_id = mysql_insert_id($link);
print "<!-- NEW vicidial_timeclock_log record inserted for $user: |$affected_rows|$timeclock_id| -->\n";
### Update the user's timeclock status record
$stmtB="UPDATE vicidial_timeclock_status set status='LOGIN', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip' where user='$user';";
if ($DB) {echo "$stmtB\n";}
$rslt=mysql_query($stmtB, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- vicidial_timeclock_status record updated for $user: |$affected_rows| -->\n";
### Add a record to the timeclock audit log
$stmtC="INSERT INTO vicidial_timeclock_audit_log set timeclock_id='$timeclock_id', event='LOGIN', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', event_date='$NOW_TIME';";
if ($DB) {echo "$stmtC\n";}
$rslt=mysql_query($stmtC, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- NEW vicidial_timeclock_audit_log record inserted for $user: |$affected_rows| -->\n";
print "<!-- UPDATE vicidial_timeclock_log record updated for $user: |$affected_rows|$timeclock_id| -->\n";
### Add a record to the vicidial_admin_log
$SQL_log = "$stmtA|$stmtB|$stmtC|";
$SQL_log = "$stmtA|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TIMECLOCK', event_type='LOGIN', record_id='$user', event_code='USER FORCED LOGIN FROM STATUS PAGE', event_sql=\"$SQL_log\", event_notes='Timeclock ID: $timeclock_id|';";
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TIMECLOCK', event_type='MODIFY', record_id='$LOGINevent_id', event_code='MANAGER MODIFY TIMECLOCK LOG', event_sql=\"$SQL_log\", event_notes='user: $user|$oldLOGINepoch|$oldLOGINdate|sec: $log_time|';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_query($stmt, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- NEW vicidial_admin_log record inserted for $PHP_AUTH_USER: |$affected_rows| -->\n";
$LOG_run++;
$VDdisplayMESSAGE = "You have now logged-in the user: $user - $full_name";
}
##### Run timeclock logout queries #####
if ( ( ($status=='LOGIN') or ($status=='START') ) and ($stage == "tc_log_user_OUT") )
{
### Add a record to the timeclock log
$stmtA="INSERT INTO vicidial_timeclock_log set event='LOGOUT', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', login_sec='$last_action_sec', event_date='$NOW_TIME', manager_user='$PHP_AUTH_USER', manager_ip='$ip', notes='Manager LOGOUT of user from user status page';";
if ($DB) {echo "$stmtA\n";}
$rslt=mysql_query($stmtA, $link);
$affected_rows = mysql_affected_rows($link);
$timeclock_id = mysql_insert_id($link);
print "<!-- NEW vicidial_timeclock_log record inserted for $user: |$affected_rows|$timeclock_id| -->\n";
### Update last login record in the timeclock log
$stmtB="UPDATE vicidial_timeclock_log set login_sec='$last_action_sec',tcid_link='$timeclock_id' where event='LOGIN' and user='$user' order by timeclock_id desc limit 1;";
### update LOGOUT record in the timeclock log
$stmtB="UPDATE vicidial_timeclock_log set event_epoch='$LOGOUTepoch', event_date='$LOGOUTdatetime', manager_user='$PHP_AUTH_USER', manager_ip='$ip', notes='Manager MODIFY', login_sec='$log_time' where timeclock_id='$LOGOUTevent_id';";
if ($DB) {echo "$stmtB\n";}
$rslt=mysql_query($stmtB, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- vicidial_timeclock_log record updated for $user: |$affected_rows| -->\n";
### Update the user's timeclock status record
$stmtC="UPDATE vicidial_timeclock_status set status='LOGOUT', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip' where user='$user';";
if ($DB) {echo "$stmtC\n";}
$rslt=mysql_query($stmtC, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- vicidial_timeclock_status record updated for $user: |$affected_rows| -->\n";
### Add a record to the timeclock audit log
$stmtD="INSERT INTO vicidial_timeclock_audit_log set timeclock_id='$timeclock_id', event='LOGOUT', user='$user', user_group='$user_group', event_epoch='$StarTtimE', ip_address='$ip', login_sec='$last_action_sec', event_date='$NOW_TIME';";
if ($DB) {echo "$stmtD\n";}
$rslt=mysql_query($stmtD, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- NEW vicidial_timeclock_audit_log record inserted for $user: |$affected_rows| -->\n";
### Update last login record in the timeclock audit log
$stmtE="UPDATE vicidial_timeclock_audit_log set login_sec='$last_action_sec',tcid_link='$timeclock_id' where event='LOGIN' and user='$user' order by timeclock_id desc limit 1;";
if ($DB) {echo "$stmtE\n";}
$rslt=mysql_query($stmtE, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- vicidial_timeclock_audit_log record updated for $user: |$affected_rows| -->\n";
$timeclock_id = mysql_insert_id($link);
print "<!-- UPDATE vicidial_timeclock_log record updated for $user: |$affected_rows|$timeclock_id| -->\n";
### Add a record to the vicidial_admin_log
$SQL_log = "$stmtA|$stmtB|$stmtC|$stmtD|$stmtE|";
$SQL_log = "$stmtB|";
$SQL_log = ereg_replace(';','',$SQL_log);
$SQL_log = addslashes($SQL_log);
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TIMECLOCK', event_type='LOGOUT', record_id='$user', event_code='USER FORCED LOGOUT FROM STATUS PAGE', event_sql=\"$SQL_log\", event_notes='User login time: $last_action_sec|Timeclock ID: $timeclock_id|';";
$stmt="INSERT INTO vicidial_admin_log set event_date='$NOW_TIME', user='$PHP_AUTH_USER', ip_address='$ip', event_section='TIMECLOCK', event_type='MODIFY', record_id='$LOGOUTevent_id', event_code='MANAGER MODIFY TIMECLOCK LOG', event_sql=\"$SQL_log\", event_notes='user: $user|$oldLOGOUTepoch|$oldLOGOUTdate|sec: $log_time|';";
if ($DB) {echo "$stmt\n";}
$rslt=mysql_query($stmt, $link);
$affected_rows = mysql_affected_rows($link);
print "<!-- NEW vicidial_admin_log record inserted for $PHP_AUTH_USER: |$affected_rows| -->\n";
$LOG_run++;
$VDdisplayMESSAGE = "You have now logged-out the user: $user - $full_name<BR>Amount of time user was logged-in: $totTIME_HMS";
echo "The timeclock session has been updated. <A HREF=\"$PHP_SELF?timeclock_id=$LOGINevent_id\">Click here to view</A>.<BR>\n";
exit;
}
if ($LOG_run < 1)
{$VDdisplayMESSAGE = "ERROR: timeclock log problem, could not process: $status|$stage";}
echo "$VDdisplayMESSAGE\n";
exit;
}
##### END TIMECLOCK RECORD MODIFY #####
##### END TIMECLOCK LOGOUT OF A USER #####
echo "\n<BR>";
if ($modify_timeclock_log > 0)
{
$LOGINevent_id = $timeclock_id;
$LOGOUTevent_id = $tcid_link;
# $LOGINevent_id = $timeclock_id;
# $LOGOUTevent_id = $tcid_link;
$event_hours = ($LOGINlogin_sec / 3600);
$event_hours_int = round($event_hours, 2);
@@ -494,6 +439,10 @@ if ($modify_timeclock_log > 0)
echo "<input type=hidden name=DB value=\"$DB\">\n";
echo "<input type=hidden name=user value=\"$user\">\n";
echo "<input type=hidden name=stage value=edit_TC_log>\n";
echo "<input type=hidden name=oldLOGINepoch id=oldLOGINepoch value=\"$LOGINevent_epoch\">\n";
echo "<input type=hidden name=oldLOGOUTepoch id=oldLOGOUTepoch value=\"$LOGOUTevent_epoch\">\n";
echo "<input type=hidden name=oldLOGINdate id=oldLOGINdate value=\"$LOGINevent_date\">\n";
echo "<input type=hidden name=oldLOGOUTdate id=oldLOGOUTdate value=\"$LOGOUTevent_date\">\n";
echo "<input type=hidden name=LOGINepoch id=LOGINepoch value=\"$LOGINevent_epoch\">\n";
echo "<input type=hidden name=LOGOUTepoch id=LOGOUTepoch value=\"$LOGOUTevent_epoch\">\n";
echo "<input type=hidden name=LOGINevent_id id=LOGINevent_id value=\"$LOGINevent_id\">\n";