, Joe Johnson LICENSE: AGPLv2 # # This is the report page where you can view report information of any of the dialer's chats. The web page will # display the information about the chat, including the start time and participants, and will also provide links # allowing you to download transcripts of any chat you wish, based on your account permissions. # # CHANGES # # 150608-0647 - First build # 160108-2300 - Changed some mysqli_query to mysql_to_mysqli for consistency # 161217-0820 - Added chat-type to allow for multi-user internal chat sessions # 170409-1550 - Added IP List validation code # 191013-0857 - Fixes for PHP7 # 220303-0909 - Added allow_web_debug system setting # 240801-1130 - Code updates for PHP8 compatibility # $startMS = microtime(); require("dbconnect_mysqli.php"); require("functions.php"); $PHP_AUTH_USER=$_SERVER['PHP_AUTH_USER']; $PHP_AUTH_PW=$_SERVER['PHP_AUTH_PW']; $PHP_SELF=$_SERVER['PHP_SELF']; $PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF); if (isset($_GET["query_date"])) {$query_date=$_GET["query_date"];} elseif (isset($_POST["query_date"])) {$query_date=$_POST["query_date"];} if (isset($_GET["end_date"])) {$end_date=$_GET["end_date"];} elseif (isset($_POST["end_date"])) {$end_date=$_POST["end_date"];} if (isset($_GET["group"])) {$group=$_GET["group"];} elseif (isset($_POST["group"])) {$group=$_POST["group"];} if (isset($_GET["user_group"])) {$user_group=$_GET["user_group"];} elseif (isset($_POST["user_group"])) {$user_group=$_POST["user_group"];} if (isset($_GET["inbound_group"])) {$inbound_group=$_GET["inbound_group"];} elseif (isset($_POST["inbound_group"])) {$inbound_group=$_POST["inbound_group"];} if (isset($_GET["users"])) {$users=$_GET["users"];} elseif (isset($_POST["users"])) {$users=$_POST["users"];} if (isset($_GET["shift"])) {$shift=$_GET["shift"];} elseif (isset($_POST["shift"])) {$shift=$_POST["shift"];} 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"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} if (isset($_GET["file_download"])) {$file_download=$_GET["file_download"];} elseif (isset($_POST["file_download"])) {$file_download=$_POST["file_download"];} if (isset($_GET["text_search"])) {$text_search=$_GET["text_search"];} elseif (isset($_POST["text_search"])) {$text_search=$_POST["text_search"];} if (isset($_GET["report_display_type"])) {$report_display_type=$_GET["report_display_type"];} elseif (isset($_POST["report_display_type"])) {$report_display_type=$_POST["report_display_type"];} if (isset($_GET["chat_log_type"])) {$chat_log_type=$_GET["chat_log_type"];} elseif (isset($_POST["chat_log_type"])) {$chat_log_type=$_POST["chat_log_type"];} if (isset($_GET["download_chat_id"])) {$download_chat_id=$_GET["download_chat_id"];} elseif (isset($_POST["download_chat_id"])) {$download_chat_id=$_POST["download_chat_id"];} if (isset($_GET["download_chat_subid"])) {$download_chat_subid=$_GET["download_chat_subid"];} elseif (isset($_POST["download_chat_subid"])) {$download_chat_subid=$_POST["download_chat_subid"];} if (isset($_GET["download_user"])) {$download_user=$_GET["download_user"];} elseif (isset($_POST["download_user"])) {$download_user=$_POST["download_user"];} if (isset($_GET["download_manager"])) {$download_manager=$_GET["download_manager"];} elseif (isset($_POST["download_manager"])) {$download_manager=$_POST["download_manager"];} $DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); $MT[0]=''; $NOW_DATE = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $STARTtime = date("U"); if (!is_array($group)) {$group = array();} if (!is_array($inbound_group)) {$inbound_group = array();} if (!is_array($user_group)) {$user_group = array();} if (!is_array($users)) {$users = array();} if (!isset($query_date)) {$query_date = $NOW_DATE;} if (!isset($end_date)) {$end_date = $NOW_DATE;} if (strlen($shift)<2) {$shift='ALL';} $report_name = 'Agent-Manager Chat Log'; $db_source = 'M'; $JS_text="\n"; $HTML_head.="\n"; $HTML_head.="\n"; $HTML_text.="\n"; $HTML_head.="\n"; $HTML_head.=""._QXZ("$report_name")."\n"; $short_header=1; # require("admin_header.php"); $HTML_text.="
"; $HTML_text.="
\n"; $HTML_text.=""; $HTML_text.=""; $HTML_text.="\n"; $HTML_text.="
"._QXZ("Dates").":
"; $HTML_text.="\n"; $HTML_text.=""; $HTML_text.="\n"; $HTML_text.="
"._QXZ("to")."
"; $HTML_text.="\n"; $HTML_text.="
"._QXZ("Campaigns").":
"; $HTML_text.="\n"; $HTML_text.="
"._QXZ("Inbound Groups").":
"; $HTML_text.="\n"; $HTML_text.="
"._QXZ("User Groups").":
"; $HTML_text.="\n"; $HTML_text.="
"._QXZ("Users").":
"; $HTML_text.="\n"; $HTML_text.="
"; $HTML_text.=_QXZ("Chat type").":
"; $HTML_text.="\n

"; $HTML_text.=_QXZ("Chat text").":
"; $HTML_text.="

"; $HTML_text.=_QXZ("Display as").":
"; $HTML_text.="

\n"; $HTML_text.="$NWB#agent_performance_detail$NWE\n"; $HTML_text.="
        "; $HTML_text.="          \n"; $HTML_text.=" "._QXZ("REPORTS")." \n"; $HTML_text.="\n"; $HTML_text.="
"; $HTML_text.="
\n\n"; $HTML_text.="
\n";

if (!$group)
	{
	$HTML_text.="\n";
	$HTML_text.=_QXZ("PLEASE SELECT A CAMPAIGN AND DATE-TIME ABOVE AND CLICK SUBMIT")."\n";
	$HTML_text.=" "._QXZ("NOTE: stats taken from shift specified")."\n";
	}
else 
	{
	if ($shift == 'AM') {
		$time_BEGIN=$AM_shift_BEGIN;
		$time_END=$AM_shift_END;
		if (strlen($time_BEGIN) < 6) {$time_BEGIN = "03:45:00";}   
		if (strlen($time_END) < 6) {$time_END = "15:14:59";}
	}
	if ($shift == 'PM') {
		$time_BEGIN=$PM_shift_BEGIN;
		$time_END=$PM_shift_END;
		if (strlen($time_BEGIN) < 6) {$time_BEGIN = "15:15:00";}
		if (strlen($time_END) < 6) {$time_END = "23:15:00";}
	}
	if ($shift == 'ALL') {
		if (strlen($time_BEGIN) < 6) {$time_BEGIN = "00:00:00";}
		if (strlen($time_END) < 6) {$time_END = "23:59:59";}
	}
	$query_date_BEGIN = "$query_date $time_BEGIN";   
	$query_date_END = "$end_date $time_END";

	$HTML_text.=_QXZ("Agent/Manager Chat Log Report",47)." $NOW_TIME\n";

	$HTML_text.=_QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\n\n";
	$HTML_text.="---------- "._QXZ("$chat_log_type CHAT LOG Details")." -------------\n\n";


	if ($chat_log_type=="INTERNAL") {
		$stmt="select * from vicidial_manager_chats_archive where chat_start_date>='$query_date 00:00:00' and chat_start_date<='$end_date 23:59:59' $user_SQL$matching_text_SQL order by chat_start_date asc";
		if ($DB) {echo "$stmt
\n";} $rslt=mysql_to_mysqli($stmt, $link); if (mysqli_num_rows($rslt)>0) { $ASCII_text.="$ASCII_rpt_header\n"; if ($DB) {$ASCII_text.=$stmt."\n";} if ($DB) {$GRAPH_text.=$stmt."\n";} $ASCII_border="+---------+---------------------+-----------+------------+---------+$ASCII_border_header\n"; $ASCII_header="| "._QXZ("CHAT ID",7)." | "._QXZ("CHAT START DATE",19)." | "._QXZ("CHAT TYPE",9)." | "._QXZ("STARTED BY",10)." | "._QXZ("REPLIES",7)." |$ASCII_header\n"; $ASCII_text.=$ASCII_border.$ASCII_header.$ASCII_border; $GRAPH_text.="

"; $GRAPH_text.="$GRAPH_header"; while ($row=mysqli_fetch_array($rslt)) { $colspan='6'; $ASCII_text.="| ".sprintf("%7s", $row["manager_chat_id"])." "; $ASCII_text.="| ".$row["chat_start_date"]." "; $ASCII_text.="| ".sprintf("%9s", _QXZ($row["internal_chat_type"], 9))." "; $ASCII_text.="| ".sprintf("%-10s", $row["manager"])." "; $ASCII_text.="| ".$row["allow_replies"]." "; $selected_agents=preg_replace('/^\|$/', "ALL", $row["selected_agents"]); $selected_user_groups=preg_replace('/^\|$/', "ALL", $row["selected_user_groups"]); $selected_campaigns=preg_replace('/^\|$/', "ALL", $row["selected_campaigns"]); $selected_agents=preg_replace('/^\||\|$/', '', $selected_agents); $selected_user_groups=preg_replace('/^\||\|$/', '', $selected_user_groups); $selected_campaigns=preg_replace('/^\||\|$/', '', $selected_campaigns); $selected_agents=preg_replace('/\|/', ', ', $selected_agents); $selected_user_groups=preg_replace('/\|/', ', ', $selected_user_groups); $selected_campaigns=preg_replace('/\|/', ', ', $selected_campaigns); $GRAPH_text.=""; if (!preg_match("/\-\-ALL\-\-/", $user_string)) { $ASCII_text.="| ".sprintf("%-50s", $selected_agents)." "; $GRAPH_text.=""; $colspan++; } if (!preg_match("/\-\-ALL\-\-/", $user_group_string)) { $ASCII_text.="| ".sprintf("%-50s", $selected_user_groups)." "; $GRAPH_text.=""; $colspan++; } if (!preg_match("/\-\-ALL\-\-/", $group_string)) { $ASCII_text.="| ".sprintf("%-50s", $selected_campaigns)." "; $GRAPH_text.=""; $colspan++; } $ASCII_text.="| ["._QXZ("DOWNLOAD FULL LOG")."]["._QXZ("SHOW INDIVIDUAL CHATS")."]\n"; $GRAPH_text.=""; $sub_stmt="select manager_chat_subid, v.user, vu.full_name, count(*) from vicidial_manager_chat_log_archive v, vicidial_users vu where manager_chat_id='".$row["manager_chat_id"]."' and v.user!=v.manager and v.user=vu.user $matching_text_subid_SQL group by manager_chat_subid, user, full_name order by manager_chat_subid asc"; if ($DB) {echo "$sub_stmt
\n";} $sub_rslt=mysql_to_mysqli($sub_stmt, $link); $ASCII_text.=""; } $ASCII_text.=$ASCII_border; $GRAPH_text.="
"._QXZ("CHAT ID").""._QXZ("CHAT START DATE").""._QXZ("MANAGER").""._QXZ("REPLIES")."  
$row[manager_chat_id]$row[chat_start_date]"._QXZ("$row[manager]")."$row[allow_replies]$selected_agents$selected_user_groups$selected_campaigns ["._QXZ("DOWNLOAD FULL LOG")."] ["._QXZ("SHOW INDIVIDUAL CHATS")."]
"; } } else if ($chat_log_type=="CUSTOMER") { # chat_id | chat_start_time | status | chat_creator | group_id | lead_id - vicidial_chat_archive $stmt="select vca.*, v.first_name, v.last_name from vicidial_chat_archive vca, vicidial_list v where chat_start_time>='$query_date 00:00:00' and chat_start_time<='$end_date 23:59:59' and vca.lead_id=v.lead_id $inbound_group_SQL$ingroup_SQL$customer_user_SQL$matching_text_SQL order by chat_start_time asc"; if ($DB) {echo "**********$stmt
\n";} $rslt=mysql_to_mysqli($stmt, $link); if (mysqli_num_rows($rslt)>0) { $ASCII_text.="$ASCII_rpt_header\n"; if ($DB) {$ASCII_text.=$stmt."\n";} if ($DB) {$GRAPH_text.=$stmt."\n";} $ASCII_border="+---------+---------------------+------------+----------------------------------------------------+$ASCII_border_header\n"; $ASCII_header="| "._QXZ("CHAT ID",7)." | "._QXZ("CHAT START DATE",19)." | "._QXZ("AGENT",10)." | "._QXZ("CUSTOMER",50)." |$ASCII_header\n"; $ASCII_text.=$ASCII_border.$ASCII_header.$ASCII_border; $GRAPH_text.="

"; $GRAPH_text.="$GRAPH_header"; while ($row=mysqli_fetch_array($rslt)) { $colspan='5'; $ASCII_text.="| ".sprintf("%7s", $row["chat_id"])." "; $ASCII_text.="| ".$row["chat_start_time"]." "; $ASCII_text.="| ".sprintf("%-10s", $row["chat_creator"])." "; $ASCII_text.="| ".sprintf("%-50s", "$row[first_name] $row[last_name]")." "; $selected_agents=preg_replace('/^\|$/', "ALL", $row["selected_agents"]); $selected_inbound_groups=preg_replace('/^\|$/', "ALL", $row["selected_inbound_groups"]); #$selected_campaigns=preg_replace('/^\|$/', "ALL", $row["selected_campaigns"]); $selected_agents=preg_replace('/^\||\|$/', '', $selected_agents); $selected_inbound_groups=preg_replace('/^\||\|$/', '', $selected_inbound_groups); #$selected_campaigns=preg_replace('/^\||\|$/', '', $selected_campaigns); $selected_agents=preg_replace('/\|/', ', ', $selected_agents); $selected_inbound_groups=preg_replace('/\|/', ', ', $selected_inbound_groups); #$selected_campaigns=preg_replace('/\|/', ', ', $selected_campaigns); $GRAPH_text.=""; if (!preg_match("/\-\-ALL\-\-/", $user_string)) { $ASCII_text.="| ".sprintf("%-50s", $selected_agents)." "; $GRAPH_text.=""; $colspan++; } if (!preg_match("/\-\-ALL\-\-/", $inbound_group_string)) { $ASCII_text.="| ".sprintf("%-50s", $selected_inbound_groups)." "; $GRAPH_text.=""; $colspan++; } $ASCII_text.="| ["._QXZ("DOWNLOAD FULL LOG")."]["._QXZ("SHOW CHAT")."]\n"; $GRAPH_text.=""; ### YOU LEFT OFF HERE 4/19 #message_row_id | chat_id | message | message_time | poster | chat_member_name | chat_level $sub_stmt="select message_time, chat_member_name, message, chat_id from vicidial_chat_log_archive where chat_id='".$row["chat_id"]."' $matching_text_subid_SQL order by message_time asc"; if ($DB) {echo "$sub_stmt
\n";} $sub_rslt=mysql_to_mysqli($sub_stmt, $link); $ASCII_text.=""; } $ASCII_text.=$ASCII_border; $GRAPH_text.="
"._QXZ("CHAT ID").""._QXZ("CHAT START DATE").""._QXZ("AGENT").""._QXZ("CUSTOMER")."  
$row[chat_id]$row[chat_start_time]$row[chat_creator]$selected_agents$selected_inbound_groups ["._QXZ("DOWNLOAD FULL LOG")."] ["._QXZ("SHOW CHAT")."]
"; } } if ($file_download == 1) { $CSV_text.="\""._QXZ("$chat_log_type Chat Log Report")." $NOW_TIME\"\n"; $CSV_text.="\""._QXZ("Time range").": $query_date_BEGIN "._QXZ("to")." $query_date_END\"\n"; $ASCII_rpt_header=preg_replace('/\s\s\s/i', "\",\"", $ASCII_rpt_header); $CSV_text.="\"".$ASCII_rpt_header."\"\n"; $mgr_stmt="select full_name from vicidial_users where user='$download_manager'"; $mgr_rslt=mysql_to_mysqli($mgr_stmt, $link); $mgr_row=mysqli_fetch_row($mgr_rslt); $mgr_name=$mgr_row[0]; if ($DB) {$CSV_text.="|$mgr_stmt|\n";} if ($chat_log_type=="INTERNAL") { $user_stmt="select vu.user, vu.full_name from vicidial_users vu, vicidial_manager_chat_log_archive v where manager_chat_id='$download_chat_id' and v.user=vu.user"; if ($download_chat_subid) {$user_stmt.=" and manager_chat_subid='$download_chat_subid' ";} $user_rslt=mysql_to_mysqli($user_stmt, $link); $user_name=array(); while ($user_row=mysqli_fetch_row($user_rslt)) { $user_name["$user_row[0]"]=$user_row[1]; } $csv_stmt="select distinct message_date, message_posted_by, message from vicidial_manager_chat_log_archive where manager_chat_id='$download_chat_id' "; if ($download_chat_subid) {$csv_stmt.=" and manager_chat_subid='$download_chat_subid' ";} $csv_stmt.=" order by message_date asc"; $csv_rslt=mysql_to_mysqli($csv_stmt, $link); if ($DB) {$CSV_text.="|$csv_stmt|\n";} $CSV_text.="\""._QXZ("MESSAGE DATE")."\",\""._QXZ("MESSAGE POSTED BY")."\",\""._QXZ("MESSAGE")."\"\n"; while($csv_row=mysqli_fetch_array($csv_rslt)) { if ($csv_row["message_posted_by"]==$download_manager) {$poster="$mgr_name";} else {$poster=$user_name["$csv_row[message_posted_by]"];} $CSV_text.="\"".$csv_row["message_date"]."\",\"".$poster."\",\"".$csv_row["message"]."\"\n"; } } else if ($chat_log_type=="CUSTOMER") { $csv_stmt="select * from vicidial_chat_log_archive where chat_id='$download_chat_id' order by message_time asc"; $csv_rslt=mysql_to_mysqli($csv_stmt, $link); $CSV_text.="\""._QXZ("MESSAGE TIME")."\",\""._QXZ("MESSAGE POSTED BY")."\",\""._QXZ("MESSAGE")."\"\n"; while($csv_row=mysqli_fetch_array($csv_rslt)) { $CSV_text.="\"".$csv_row["message_time"]."\",\"".$csv_row["chat_member_name"]."\",\"".$csv_row["message"]."\"\n"; } } $FILE_TIME = date("Ymd-His"); $CSVfilename = "AST_CHAT_LOG$US$FILE_TIME.csv"; // We'll be outputting a TXT file header('Content-type: application/octet-stream'); // It will be called LIST_101_20090209-121212.txt header("Content-Disposition: attachment; filename=\"$CSVfilename\""); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); ob_clean(); flush(); echo "$CSV_text"; if ($db_source == 'S') { mysqli_close($link); $use_slave_server=0; $db_source = 'M'; require("dbconnect_mysqli.php"); } $endMS = microtime(); $startMSary = explode(" ",$startMS); $endMSary = explode(" ",$endMS); $runS = ($endMSary[0] - $startMSary[0]); $runM = ($endMSary[1] - $startMSary[1]); $TOTALrun = ($runS + $runM); $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; if ($DB) {echo "|$stmt|\n";} $rslt=mysql_to_mysqli($stmt, $link); exit; } if ($report_display_type=="HTML") { $HTML_text.=$GRAPH_text; } else { $HTML_text.=$ASCII_text; } $HTML_text.="\n\n
$db_source"; $HTML_text.="
"; $HTML_text.=""; } if ($file_download == 0 || !$file_download) { echo $HTML_head; require("admin_header.php"); echo $HTML_text; } if ($db_source == 'S') { mysqli_close($link); $use_slave_server=0; $db_source = 'M'; require("dbconnect_mysqli.php"); } $endMS = microtime(); $startMSary = explode(" ",$startMS); $endMSary = explode(" ",$endMS); $runS = ($endMSary[0] - $startMSary[0]); $runM = ($endMSary[1] - $startMSary[1]); $TOTALrun = ($runS + $runM); $stmt="UPDATE vicidial_report_log set run_time='$TOTALrun' where report_log_id='$report_log_id';"; if ($DB) {echo "|$stmt|\n";} $rslt=mysql_to_mysqli($stmt, $link); exit; ?>