From 4d6fc32df1712c10d4f795144ea1296fee2d4d7e Mon Sep 17 00:00:00 2001 From: mattf Date: Tue, 3 Jun 2008 19:21:29 +0000 Subject: [PATCH] added timeclock_status.php page for user_group status of timeclock and vicidial logins for users git-svn-id: svn://192.168.202.10@887 3d104415-ff17-0410-8863-d5cf3c621b8a --- agc_2-X/trunk/docs/TIMECLOCK_PROCESS.txt | 4 +- .../trunk/extras/MySQL_AST_CREATE_tables.sql | 6 +- agc_2-X/trunk/extras/first_server_install.sql | 1 + agc_2-X/trunk/extras/upgrade_2.0.5.sql | 20 + .../trunk/www/vicidial/timeclock_status.php | 526 ++++++++++++++++++ agc_2-X/trunk/www/vicidial/user_status.php | 270 +++++++-- 6 files changed, 780 insertions(+), 47 deletions(-) create mode 100644 agc_2-X/trunk/www/vicidial/timeclock_status.php diff --git a/agc_2-X/trunk/docs/TIMECLOCK_PROCESS.txt b/agc_2-X/trunk/docs/TIMECLOCK_PROCESS.txt index b8cda65b..8da612a4 100644 --- a/agc_2-X/trunk/docs/TIMECLOCK_PROCESS.txt +++ b/agc_2-X/trunk/docs/TIMECLOCK_PROCESS.txt @@ -155,10 +155,12 @@ 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', +event_type ENUM('ADD','COPY','LOAD','RESET','MODIFY','DELETE','SEARCH','LOGIN','LOGOUT','CLEAR','OTHER') default 'OTHER', record_id VARCHAR(50) NOT NULL, event_code VARCHAR(255) NOT NULL, event_sql TEXT, +event_notes TEXT, index (user), +index (event_section), index (record_id) ); diff --git a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql index 4f5b9bc0..8f4cf0e0 100644 --- a/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql +++ b/agc_2-X/trunk/extras/MySQL_AST_CREATE_tables.sql @@ -1153,11 +1153,13 @@ 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', +event_type ENUM('ADD','COPY','LOAD','RESET','MODIFY','DELETE','SEARCH','LOGIN','LOGOUT','CLEAR','OTHER') default 'OTHER', record_id VARCHAR(50) NOT NULL, event_code VARCHAR(255) NOT NULL, event_sql TEXT, +event_notes TEXT, index (user), +index (event_section), index (record_id) ); @@ -1210,5 +1212,5 @@ INSERT INTO vicidial_state_call_times SET state_call_time_id='utah',state_call_t INSERT INTO vicidial_state_call_times SET state_call_time_id='washington',state_call_time_state='WA',state_call_time_name='Washington 8am',sct_default_start='800',sct_default_stop='2100'; INSERT INTO vicidial_state_call_times SET state_call_time_id='wyoming',state_call_time_state='WY',state_call_time_name='Wyoming 8am-8pm',sct_default_start='800',sct_default_stop='2000'; -UPDATE system_settings SET db_schema_version='1091'; +UPDATE system_settings SET db_schema_version='1093'; diff --git a/agc_2-X/trunk/extras/first_server_install.sql b/agc_2-X/trunk/extras/first_server_install.sql index c15286bd..6ef15abb 100644 --- a/agc_2-X/trunk/extras/first_server_install.sql +++ b/agc_2-X/trunk/extras/first_server_install.sql @@ -231,6 +231,7 @@ INSERT INTO vicidial_statuses values('B','Busy','Y','N','UNDEFINED'); INSERT INTO vicidial_statuses values('DC','Disconnected Number','Y','N','UNDEFINED'); INSERT INTO vicidial_statuses values('DEC','Declined Sale','Y','Y','UNDEFINED'); INSERT INTO vicidial_statuses values('DNC','DO NOT CALL','Y','Y','UNDEFINED'); +INSERT INTO vicidial_statuses values('DNCL','DO NOT CALL Hopper Match','N','N','UNDEFINED'); INSERT INTO vicidial_statuses values('SALE','Sale Made','Y','Y','UNDEFINED'); INSERT INTO vicidial_statuses values('N','No Answer','Y','N','UNDEFINED'); INSERT INTO vicidial_statuses values('NI','Not Interested','Y','Y','UNDEFINED'); diff --git a/agc_2-X/trunk/extras/upgrade_2.0.5.sql b/agc_2-X/trunk/extras/upgrade_2.0.5.sql index d97b1b5a..f9a674c8 100644 --- a/agc_2-X/trunk/extras/upgrade_2.0.5.sql +++ b/agc_2-X/trunk/extras/upgrade_2.0.5.sql @@ -259,3 +259,23 @@ UPDATE system_settings SET db_schema_version='1091'; CREATE INDEX user ON vicidial_agent_log (user); UPDATE system_settings SET db_schema_version='1092'; + +DROP TABLE vicidial_admin_log; + + 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','LOGIN','LOGOUT','CLEAR','OTHER') default 'OTHER', +record_id VARCHAR(50) NOT NULL, +event_code VARCHAR(255) NOT NULL, +event_sql TEXT, +event_notes TEXT, +index (user), +index (event_section), +index (record_id) +); + +UPDATE system_settings SET db_schema_version='1093'; diff --git a/agc_2-X/trunk/www/vicidial/timeclock_status.php b/agc_2-X/trunk/www/vicidial/timeclock_status.php new file mode 100644 index 00000000..c33d5467 --- /dev/null +++ b/agc_2-X/trunk/www/vicidial/timeclock_status.php @@ -0,0 +1,526 @@ + LICENSE: AGPLv2 +# +# CHANGES +# +# 80602-0201 - First Build +# 80603-1500 - formatting changes +# + +header ("Content-type: text/html; charset=utf-8"); + +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["begin_date"])) {$begin_date=$_GET["begin_date"];} + elseif (isset($_POST["begin_date"])) {$begin_date=$_POST["begin_date"];} +if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} + elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} +if (isset($_GET["user"])) {$user=$_GET["user"];} + elseif (isset($_POST["user"])) {$user=$_POST["user"];} +if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} + elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} +if (isset($_GET["submit"])) {$submit=$_GET["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} +if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} + + +############################################# +##### START SYSTEM_SETTINGS LOOKUP ##### +$stmt = "SELECT use_non_latin,webroot_writable,timeclock_end_of_day FROM system_settings;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {echo "$stmt\n";} +$qm_conf_ct = mysql_num_rows($rslt); +$i=0; +while ($i < $qm_conf_ct) + { + $row=mysql_fetch_row($rslt); + $non_latin = $row[0]; + $webroot_writable = $row[1]; + $timeclock_end_of_day = $row[2]; + $i++; + } +##### END SETTINGS LOOKUP ##### +########################################### + +$PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); +$PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); + +$STARTtime = date("U"); +$TODAY = date("Y-m-d"); +$HHMM = date("Hi"); +$HHteod = substr($timeclock_end_of_day,0,2); +$MMteod = substr($timeclock_end_of_day,2,2); + +if ($HHMM < $timeclock_end_of_day) + {$EoD = mktime($HHteod, $MMteod, 0, date("m"), date("d")-1, date("Y"));} +else + {$EoD = mktime($HHteod, $MMteod, 0, date("m"), date("d"), date("Y"));} + +$EoDdate = date("Y-m-d H:i:s", $EoD); + + $stmt="SELECT count(*) from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW' and user_level > 7 and view_reports='1';"; + if ($non_latin > 0) { $rslt=mysql_query("SET NAMES 'UTF8'");} + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $auth=$row[0]; + +$fp = fopen ("./project_auth_entries.txt", "a"); +$date = date("r"); +$ip = getenv("REMOTE_ADDR"); +$browser = getenv("HTTP_USER_AGENT"); + + if( (strlen($PHP_AUTH_USER)<2) or (strlen($PHP_AUTH_PW)<2) or (!$auth)) + { + Header("WWW-Authenticate: Basic realm=\"VICI-PROJECTS\""); + Header("HTTP/1.0 401 Unauthorized"); + echo "Invalid Username/Password: |$PHP_AUTH_USER|$PHP_AUTH_PW|\n"; + exit; + } + else + { + + if($auth>0) + { + $stmt="SELECT full_name from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $LOGfullname=$row[0]; + if ($webroot_writable > 0) + { + fwrite ($fp, "VICIDIAL|GOOD|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|$LOGfullname|\n"); + fclose($fp); + } + } + else + { + if ($webroot_writable > 0) + { + fwrite ($fp, "VICIDIAL|FAIL|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|\n"); + fclose($fp); + } + } + + } + + +$stmt="select user_group from vicidial_user_groups;"; +$rslt=mysql_query($stmt, $link); +if ($DB) {echo "$stmt\n";} +$user_groups_to_print = mysql_num_rows($rslt); + $i=0; + $user_groups_to_print++; +while ($i < $user_groups_to_print) + { + $row=mysql_fetch_row($rslt); + $LISTuser_groups[$i] =$row[0]; + if ($row[0]==$user_group) + {$FORMuser_groups.="";} + else + {$FORMuser_groups.="";} + $i++; + } + +if (strlen($user_group) > 0) + { + $stmt="SELECT group_name from vicidial_user_groups where user_group='$user_group';"; + $rslt=mysql_query($stmt, $link); + $row=mysql_fetch_row($rslt); + $group_name = $row[0]; + } + +?> + + +VICIDIAL ADMIN: Timeclock Status +\n"; +?> + + +
+ + + + + +\n"; +echo "
+VICIDIAL ADMIN | "; +echo "TIMECLOCK REPORT | "; +echo "USER GROUP\n"; +?> +
Timeclock Status for
 
  \n"; + +echo "
\n"; +echo "\n"; +echo ""; +echo "\n"; + +echo "
\n"; +echo "
\n"; + +if (strlen($user_group) < 1) + { + exit; + } + + +##### grab all users in this user_group ##### +$stmt="SELECT user,full_name from vicidial_users where user_group='" . mysql_real_escape_string($user_group) . "' order by full_name;"; +if ($DB>0) {echo "|$stmt|";} +$rslt=mysql_query($stmt, $link); +$users_to_print = mysql_num_rows($rslt); +$o=0; +while ($users_to_print > $o) + { + $row=mysql_fetch_row($rslt); + $users[$o] = $row[0]; + $full_name[$o] = $row[1]; + $Vevent_time[$o] = ''; + $Vevent_epoch[$o] = 0; + $Vcampaign[$o] = ''; + $Tevent_epoch[$o] = ''; + $Tevent_date[$o] = ''; + $Tstatus[$o] = ''; + $Tip_address[$o] = ''; + $Tlogin_time[$o] = ''; + $Tlogin_sec[$o] = 0; + + $o++; + } + +$o=0; +while ($users_to_print > $o) + { + $total_login_time = 0; + ##### grab timeclock status record for this user ##### + $stmt="SELECT event_epoch,event_date,status,ip_address from vicidial_timeclock_status where user='$users[$o]' and event_epoch >= '$EoD';"; + if ($DB>0) {echo "|$stmt|";} + $rslt=mysql_query($stmt, $link); + $stats_to_print = mysql_num_rows($rslt); + if ($stats_to_print > 0) + { + $row=mysql_fetch_row($rslt); + $Tevent_epoch[$o] = $row[0]; + $Tevent_date[$o] = $row[1]; + $Tstatus[$o] = $row[2]; + $Tip_address[$o] = $row[3]; + + if ( ($row[2]=='START') or ($row[2]=='LOGIN') ) + {$bgcolor[$o]='bgcolor="#B9CBFD"';} + else + {$bgcolor[$o]='bgcolor="#9BB9FB"';} + } + + ##### grab timeclock logged-in time for each user ##### + $stmt="SELECT event,event_epoch,login_sec from vicidial_timeclock_log where user='$users[$o]' and event_epoch >= '$EoD';"; + if ($DB>0) {echo "|$stmt|";} + $rslt=mysql_query($stmt, $link); + $logs_to_parse = mysql_num_rows($rslt); + $p=0; + while ($logs_to_parse > $p) + { + $row=mysql_fetch_row($rslt); + if ( (ereg("LOGIN", $row[0])) or (ereg("START", $row[0])) ) + { + $login_sec=''; + $Tevent_time[$o] = date("Y-m-d H:i:s", $row[1]); + } + if (ereg("LOGOUT", $row[0])) + { + $login_sec = $row[2]; + $total_login_time = ($total_login_time + $login_sec); + } + $p++; + } + if ( (strlen($login_sec)<1) and ($logs_to_parse > 0) ) + { + $login_sec = ($STARTtime - $row[1]); + $total_login_time = ($total_login_time + $login_sec); + } + if ($logs_to_parse > 0) + { + $total_login_hours = ($total_login_time / 3600); + $total_login_hours_int = round($total_login_hours, 2); + $total_login_hours_int = intval("$total_login_hours"); + $total_login_minutes = ($total_login_hours - $total_login_hours_int); + $total_login_minutes = ($total_login_minutes * 60); + $total_login_minutes_int = round($total_login_minutes, 0); + if ($total_login_minutes_int < 10) {$total_login_minutes_int = "0$total_login_minutes_int";} + + $Tlogin_time[$o] = "$total_login_hours_int:$total_login_minutes_int"; + $Tlogin_sec[$o] = $total_login_time; + } + else + { + $total_login_time = 0; + $Tlogin_time[$o] = "0:00"; + $Tlogin_sec[$o] = $total_login_time; + } + + if ($DB>0) {echo "|$Tlogin_sec[$o]|$Tlogin_time[$o]|";} + + ##### grab vicidial_agent_log records in this user_group ##### + $stmt="SELECT event_time,UNIX_TIMESTAMP(event_time),campaign_id from vicidial_agent_log where user='$users[$o]' and event_time >= '$EoDdate' order by agent_log_id desc limit 1;"; + if ($DB>0) {echo "|$stmt|";} + $rslt=mysql_query($stmt, $link); + $vals_to_print = mysql_num_rows($rslt); + if ($vals_to_print > 0) + { + $row=mysql_fetch_row($rslt); + $Vevent_time[$o] = $row[0]; + $Vevent_epoch[$o] = $row[1]; + $Vcampaign[$o] = $row[2]; + } + + $o++; + } + + +##### print each user that has any activity for today ##### +echo "
\n"; +echo "
\n"; + +echo "\n"; +echo "\n"; +echo "\n"; # bright green +echo "\n"; # bright yellow +echo "\n"; # bright red +echo "\n"; +echo "\n"; # dull green +echo "\n"; # dull yellow +echo "\n"; +echo "
    TC Logged in and VICI active     TC Logged in only     VICI active only
    TC Logged out and VICI active     TC Logged out only      

\n"; + +echo "USER STATUS FOR USER GROUP: $user_group\n"; +echo "\n"; +echo "\n"; + +$o=0; +$s=0; +while ($users_to_print > $o) + { + if ( ($Tlogin_sec[$o] > 0) or (strlen($Vevent_time[$o]) > 0) ) + { + if ( ($Tstatus[$o]=='START') or ($Tstatus[$o]=='LOGIN') ) + { + if ($Tlogin_sec[$o] > 0) + {$bgcolor[$o]='bgcolor="#FFFF33"';} # yellow + if ( ($Tlogin_sec[$o] > 0) and (strlen($Vevent_time[$o]) > 0) ) + {$bgcolor[$o]='bgcolor="#99FF33"';} # green + } + else + { + if ($Tlogin_sec[$o] > 0) + {$bgcolor[$o]='bgcolor="#CCCC00"';} # yellow + if (strlen($Vevent_time[$o]) > 0) + {$bgcolor[$o]='bgcolor="#FF6666"';} # red + if ( ($Tlogin_sec[$o] > 0) and (strlen($Vevent_time[$o]) > 0) ) + {$bgcolor[$o]='bgcolor="#66CC66"';} # green + } + + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + if (strlen($Tstatus[$o])>0) + {$TOTlogin_sec = ($TOTlogin_sec + $Tlogin_sec[$o]);} + + $s++; + } + $o++; + } + + + +$total_login_hours = ($TOTlogin_sec / 3600); +$total_login_hours_int = round($total_login_hours, 2); +$total_login_hours_int = intval("$total_login_hours"); +$total_login_minutes = ($total_login_hours - $total_login_hours_int); +$total_login_minutes = ($total_login_minutes * 60); +$total_login_minutes_int = round($total_login_minutes, 0); +if ($total_login_minutes_int < 10) {$total_login_minutes_int = "0$total_login_minutes_int";} + +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo "
# USER NAME IP ADDRESS TC TIMETC LOGIN VICI LAST LOG VICI CAMPAIGN
$s$users[$o]$full_name[$o]$Tip_address[$o]$Tlogin_time[$o]$Tevent_time[$o]$Vevent_time[$o]$Vcampaign[$o]
TOTALS$total_login_hours_int:$total_login_minutes_int
"; + + + + +$ENDtime = date("U"); + +$RUNtime = ($ENDtime - $STARTtime); + +echo "\n\n\n


\n\n"; + + +echo "\n\n\n


\nscript runtime: $RUNtime seconds
"; + + +?> + + +
+ + + +
\n"; + +echo "
\n"; + +echo "TIMECLOCK LOGIN/LOGOUT TIME:\n"; +echo "
\n"; +echo "\n"; + + $stmt="SELECT event,event_epoch,user_group,login_sec,ip_address,timeclock_id,manager_user from vicidial_timeclock_log where user='" . mysql_real_escape_string($user) . "' and event_epoch >= '$SQepoch' and event_epoch <= '$EQepoch';"; + if ($DB>0) {echo "|$stmt|";} + $rslt=mysql_query($stmt, $link); + $events_to_print = mysql_num_rows($rslt); + + $total_logs=0; + $o=0; + while ($events_to_print > $o) { + $row=mysql_fetch_row($rslt); + if ( ($row[0]=='START') or ($row[0]=='LOGIN') ) + {$bgcolor='bgcolor="#B9CBFD"';} + else + {$bgcolor='bgcolor="#9BB9FB"';} + + $TC_log_date = date("Y-m-d H:i:s", $row[1]); + + $manager_edit=''; + if (strlen($row[6])>0) {$manager_edit = ' * ';} + + if (ereg("LOGIN", $row[0])) + { + $login_sec=''; + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + if (ereg("LOGOUT", $row[0])) + { + $login_sec = $row[3]; + $total_login_time = ($total_login_time + $login_sec); + $event_hours = ($login_sec / 3600); + $event_hours_int = round($event_hours, 2); + $event_hours_int = intval("$event_hours_int"); + $event_minutes = ($event_hours - $event_hours_int); + $event_minutes = ($event_minutes * 60); + $event_minutes_int = round($event_minutes, 0); + if ($event_minutes_int < 10) {$event_minutes_int = "0$event_minutes_int";} + echo ""; + echo ""; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + } + $o++; + } +if (strlen($login_sec)<1) + { + $login_sec = ($STARTtime - $row[1]); + $total_login_time = ($total_login_time + $login_sec); + } +$total_login_hours = ($total_login_time / 3600); +$total_login_hours_int = round($total_login_hours, 2); +$total_login_hours_int = intval("$total_login_hours"); +$total_login_minutes = ($total_login_hours - $total_login_hours_int); +$total_login_minutes = ($total_login_minutes * 60); +$total_login_minutes_int = round($total_login_minutes, 0); +if ($total_login_minutes_int < 10) {$total_login_minutes_int = "0$total_login_minutes_int";} + +echo ""; +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; +echo "\n"; + +echo "
ID EDIT EVENT DATE IP ADDRESS GROUPHOURS:MINUTES
$row[5]$manager_edit$row[0] $TC_log_date $row[4] $row[2]
$row[5]$manager_edit$row[0] $TC_log_date $row[4] $row[2] $event_hours_int:$event_minutes_int
TOTAL $total_login_hours_int:$total_login_minutes_int
\n"; + + + + + + + +$ENDtime = date("U"); + +$RUNtime = ($ENDtime - $STARTtime); + +echo "\n\n\n


\n\n"; + + +echo "\n\n\n


\nscript runtime: $RUNtime seconds
"; + + +?> + + + + + + + + + + + + diff --git a/agc_2-X/trunk/www/vicidial/user_status.php b/agc_2-X/trunk/www/vicidial/user_status.php index f341c083..fd1a67d4 100644 --- a/agc_2-X/trunk/www/vicidial/user_status.php +++ b/agc_2-X/trunk/www/vicidial/user_status.php @@ -6,6 +6,7 @@ # CHANGES # # 60619-1738 - Added variable filtering to eliminate SQL injection attack threat +# 80603-1452 - Added manager timeclock force login/logout of user # header ("Content-type: text/html; charset=utf-8"); @@ -16,7 +17,7 @@ $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $PHP_SELF=$_SERVER['PHP_SELF']; if (isset($_GET["begin_date"])) {$begin_date=$_GET["begin_date"];} - elseif (isset($_POST["begin_date"])) {$begin_date=$_POST["begin_date"];} + elseif (isset($_POST["begin_date"])) {$begin_date=$_POST["begin_date"];} if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} if (isset($_GET["user"])) {$user=$_GET["user"];} @@ -25,10 +26,12 @@ if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["stage"])) {$stage=$_GET["stage"];} elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} +if (isset($_GET["DB"])) {$DB=$_GET["DB"];} + elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} if (isset($_GET["submit"])) {$submit=$_GET["submit"];} - elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} + elseif (isset($_POST["submit"])) {$submit=$_POST["submit"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} - elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} + elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### @@ -50,8 +53,10 @@ while ($i < $qm_conf_ct) $PHP_AUTH_USER = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_USER); $PHP_AUTH_PW = ereg_replace("[^0-9a-zA-Z]","",$PHP_AUTH_PW); -$STARTtime = date("U"); +$StarTtimE = date("U"); $TODAY = date("Y-m-d"); +$NOW_TIME = date("Y-m-d H:i:s"); +$ip = getenv("REMOTE_ADDR"); if (!isset($begin_date)) {$begin_date = $TODAY;} if (!isset($end_date)) {$end_date = $TODAY;} @@ -79,11 +84,12 @@ $browser = getenv("HTTP_USER_AGENT"); if($auth>0) { - $stmt="SELECT full_name,change_agent_campaign from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; + $stmt="SELECT full_name,change_agent_campaign,modify_timeclock_log from vicidial_users where user='$PHP_AUTH_USER' and pass='$PHP_AUTH_PW'"; $rslt=mysql_query($stmt, $link); $row=mysql_fetch_row($rslt); - $LOGfullname=$row[0]; - $change_agent_campaign=$row[1]; + $LOGfullname = $row[0]; + $change_agent_campaign = $row[1]; + $modify_timeclock_log = $row[2]; if ($webroot_writable > 0) { fwrite ($fp, "VICIDIAL|GOOD|$date|$PHP_AUTH_USER|$PHP_AUTH_PW|$ip|$browser|$LOGfullname|\n"); @@ -171,43 +177,216 @@ echo "\n" echo "
  \n"; +##### EMERGENCY CAMPAIGN CHANGE FOR AN AGENT ##### if ($stage == "live_campaign_change") -{ + { $stmt="UPDATE vicidial_live_agents set campaign_id='" . mysql_real_escape_string($group) . "' where user='" . mysql_real_escape_string($user) . "';"; $rslt=mysql_query($stmt, $link); echo "Agent $user - $full_name changed to $group campaign
\n"; exit; -} + } +##### EMERGENCY LOGOUT OF AN AGENT ##### if ($stage == "log_agent_out") -{ + { $stmt="DELETE from vicidial_live_agents where user='" . mysql_real_escape_string($user) . "';"; $rslt=mysql_query($stmt, $link); echo "Agent $user - $full_name has been emergency logged out, make sure they close their web browser
\n"; exit; -} + } + + + + + +##### 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";} + $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) + { + ### 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'; + } + } + + 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 "\n"; + } + + + ##### 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';"; + if ($DB) {echo "$stmtA\n";} + $rslt=mysql_query($stmtA, $link); + $affected_rows = mysql_affected_rows($link); + $timeclock_id = mysql_insert_id($link); + print "\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 "\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 "\n"; + + ### Add a record to the vicidial_admin_log + $SQL_log = "$stmtA|$stmtB|$stmtC|"; + $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|';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $affected_rows = mysql_affected_rows($link); + print "\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 "\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;"; + if ($DB) {echo "$stmtB\n";} + $rslt=mysql_query($stmtB, $link); + $affected_rows = mysql_affected_rows($link); + print "\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 "\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 "\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 "\n"; + + ### Add a record to the vicidial_admin_log + $SQL_log = "$stmtA|$stmtB|$stmtC|$stmtD|$stmtE|"; + $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|';"; + if ($DB) {echo "$stmt\n";} + $rslt=mysql_query($stmt, $link); + $affected_rows = mysql_affected_rows($link); + print "\n"; + + $LOG_run++; + $VDdisplayMESSAGE = "You have now logged-out the user: $user - $full_name
Amount of time user was logged-in: $totTIME_HMS"; + } + + if ($LOG_run < 1) + {$VDdisplayMESSAGE = "ERROR: timeclock log problem, could not process: $status|$stage";} + + echo "$VDdisplayMESSAGE\n"; + + exit; + } + +##### END TIMECLOCK LOGOUT OF A USER ##### if ($agents_to_print > 0) -{ - echo "
";
-	echo "Agent Logged in at server:  $Aserver_ip\n";
-	echo "               in session:  $Asession_id\n";
-	echo "               from phone:  $Aextension\n";
-	echo "Agent is in campaign:       $Acampaign\n";
-	echo "              status:       $Astatus\n";
-	echo " hungup last call at:       $Alast_call\n";
-	echo "       Closer groups:       $Acl_campaigns\n\n";
+	{
+	echo "
\n"; + echo "$user - $full_name \n"; + echo "       GROUP: $user_group
\n"; - echo "
"; + echo ""; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
Agent Logged in at server:   $Aserver_ip
in session:   $Asession_id
from phone:   $Aextension
Agent is in campaign:   $Acampaign
status:   $Astatus
hungup last call at:   $Alast_call
Closer groups:   $Acl_campaigns
\n
\n"; if ($change_agent_campaign > 0) - { + { echo "\n"; + echo "\n"; echo "\n"; echo "\n"; echo "Current Campaign: \n"; echo "\n"; echo "\n"; echo "
\n"; + } } -} else -{ + { echo "Agent is not logged in to VICIDIAL\n
"; - -} + } echo "\n
"; if ( ($Tstatus == "LOGIN") or ($Tstatus == "START") ) -{ - echo "User $user - is logged in to the timeclock.
Login time: $Tevent_date from $Tip_address
\n"; - - exit; -} + { + echo "User $user($full_name) - is logged in to the timeclock.
Login time: $Tevent_date from $Tip_address
\n"; + $TC_log_change_stage = 'tc_log_user_OUT'; + $TC_log_change_button = 'TIMECLOCK LOG THIS USER OUT'; + } else -{ - echo "User $user - is NOT logged in to the timeclock.
Last logout time: $Tevent_date from $Tip_address
\n"; - - exit; -} + { + echo "User $user($full_name) - is NOT logged in to the timeclock.
Last logout time: $Tevent_date from $Tip_address
\n"; + $TC_log_change_stage = 'tc_log_user_IN'; + $TC_log_change_button = 'TIMECLOCK LOG THIS USER IN'; + } +if ($modify_timeclock_log > 0) + { + echo "

\n"; + echo "
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "

\n"; + } -echo "           $user - $full_name \n"; -echo "       GROUP: $user_group

\n"; - echo "VICIDIAL Time Sheet\n"; echo " - User Stats\n"; echo " - Modify User\n"; @@ -265,7 +451,7 @@ echo "
\n"; $ENDtime = date("U"); -$RUNtime = ($ENDtime - $STARTtime); +$RUNtime = ($ENDtime - $StarTtimE); echo "\n\n\n


\n\n"; @@ -289,7 +475,3 @@ exit; ?> - - - -