LICENSE: AGPLv2 # # This page is for managers (level 8 or higher) to chat with live agents # # changes: # 150608-2041 - First Build # 150909-0118 - Bug fixes, added feature to submit messages when Enter is pressed # 151219-0718 - Added vicidial_chat.js code, translation code where missing # 160107-2241 - Added realtime check to see whether sub chats are still running # 160108-2300 - Changed some mysqli_query to mysql_to_mysqli for consistency # 161029-2127 - Fixed menu displays, text sizes # 161217-0819 - Added chat-type to allow for multi-user internal chat sessions # 170409-1551 - Added IP List validation code # $admin_version = '2.14-8'; $build = '170409-1551'; $sh="managerchats"; 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']; if (isset($_GET["DB"])) {$DB=$_GET["DB"];} elseif (isset($_POST["DB"])) {$DB=$_POST["DB"];} if (isset($_GET["action"])) {$action=$_GET["action"];} elseif (isset($_POST["action"])) {$action=$_POST["action"];} if (isset($_GET["SUBMIT"])) {$SUBMIT=$_GET["SUBMIT"];} elseif (isset($_POST["SUBMIT"])) {$SUBMIT=$_POST["SUBMIT"];} if (isset($_GET["manager_chat_id"])) {$manager_chat_id=$_GET["manager_chat_id"];} elseif (isset($_POST["manager_chat_id"])) {$manager_chat_id=$_POST["manager_chat_id"];} if (isset($_GET["available_chat_agents"])) {$available_chat_agents=$_GET["available_chat_agents"];} elseif (isset($_POST["available_chat_agents"])) {$available_chat_agents=$_POST["available_chat_agents"];} if (isset($_GET["available_chat_groups"])) {$available_chat_groups=$_GET["available_chat_groups"];} elseif (isset($_POST["available_chat_groups"])) {$available_chat_groups=$_POST["available_chat_groups"];} if (isset($_GET["available_chat_campaigns"])) {$available_chat_campaigns=$_GET["available_chat_campaigns"];} elseif (isset($_POST["available_chat_campaigns"])) {$available_chat_campaigns=$_POST["available_chat_campaigns"];} if (isset($_GET["manager_message"])) {$manager_message=$_GET["manager_message"];} elseif (isset($_POST["manager_message"])) {$manager_message=$_POST["manager_message"];} if (isset($_GET["allow_replies"])) {$allow_replies=$_GET["allow_replies"];} elseif (isset($_POST["allow_replies"])) {$allow_replies=$_POST["allow_replies"];} if (isset($_GET["end_all_chats"])) {$end_all_chats=$_GET["end_all_chats"];} elseif (isset($_POST["end_all_chats"])) {$end_all_chats=$_POST["end_all_chats"];} if (isset($_GET["submit_chat"])) {$submit_chat=$_GET["submit_chat"];} elseif (isset($_POST["submit_chat"])) {$submit_chat=$_POST["submit_chat"];} if (!$allow_replies) {$allow_replies="N";} ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $VUselected_language = ''; $stmt = "SELECT use_non_latin,enable_queuemetrics_logging,enable_vtiger_integration,qc_features_active,outbound_autodial_active,sounds_central_control_active,enable_second_webform,user_territories_active,custom_fields_enabled,admin_web_directory,webphone_url,first_login_trigger,hosted_settings,default_phone_registration_password,default_phone_login_password,default_server_password,test_campaign_calls,active_voicemail_server,voicemail_timezones,default_voicemail_timezone,default_local_gmt,campaign_cid_areacodes_enabled,pllb_grouping_limit,did_ra_extensions_enabled,expanded_list_stats,contacts_enabled,alt_log_server_ip,alt_log_dbname,alt_log_login,alt_log_pass,tables_use_alt_log_db,allow_emails,allow_emails,level_8_disable_add,allow_chats,enable_languages,language_method,default_language FROM system_settings;"; $rslt=mysql_to_mysqli($stmt, $link); if ($DB) {echo "$stmt\n";} $qm_conf_ct = mysqli_num_rows($rslt); if ($qm_conf_ct > 0) { $row=mysqli_fetch_row($rslt); $non_latin = $row[0]; $SSenable_queuemetrics_logging = $row[1]; $SSenable_vtiger_integration = $row[2]; $SSqc_features_active = $row[3]; $SSoutbound_autodial_active = $row[4]; $SSsounds_central_control_active = $row[5]; $SSenable_second_webform = $row[6]; $SSuser_territories_active = $row[7]; $SScustom_fields_enabled = $row[8]; $SSadmin_web_directory = $row[9]; $SSwebphone_url = $row[10]; $SSfirst_login_trigger = $row[11]; $SShosted_settings = $row[12]; $SSdefault_phone_registration_password =$row[13]; $SSdefault_phone_login_password = $row[14]; $SSdefault_server_password = $row[15]; $SStest_campaign_calls = $row[16]; $SSactive_voicemail_server = $row[17]; $SSvoicemail_timezones = $row[18]; $SSdefault_voicemail_timezone = $row[19]; $SSdefault_local_gmt = $row[20]; $SScampaign_cid_areacodes_enabled = $row[21]; $SSpllb_grouping_limit = $row[22]; $SSdid_ra_extensions_enabled = $row[23]; $SSexpanded_list_stats = $row[24]; $SScontacts_enabled = $row[25]; $SSalt_log_server_ip = $row[26]; $SSalt_log_dbname = $row[27]; $SSalt_log_login = $row[28]; $SSalt_log_pass = $row[29]; $SStables_use_alt_log_db = $row[30]; $SSallow_emails = $row[31]; $SSemail_enabled = $row[32]; $SSlevel_8_disable_add = $row[33]; $SSallow_chats = $row[34]; $SSenable_languages = $row[35]; $SSlanguage_method = $row[36]; $SSdefault_language = $row[37]; } $VUselected_language = $SSdefault_language; ##### END SETTINGS LOOKUP ##### ########################################### if ($non_latin < 1) { $PHP_AUTH_USER = preg_replace("/[^-_0-9a-zA-Z]/", "",$PHP_AUTH_USER); $PHP_AUTH_PW = preg_replace("/[^-_0-9a-zA-Z]/", "",$PHP_AUTH_PW); } # end of non_latin else { $PHP_AUTH_USER = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_USER); $PHP_AUTH_PW = preg_replace("/'|\"|\\\\|;/","",$PHP_AUTH_PW); } $list_id = preg_replace("/[^0-9]/","",$list_id); $STARTtime = date("U"); $TODAY = date("Y-m-d"); $NOW_TIME = date("Y-m-d H:i:s"); $date = date("r"); $ip = getenv("REMOTE_ADDR"); $browser = getenv("HTTP_USER_AGENT"); $user = $PHP_AUTH_USER; $add_copy_disabled=0; $auth=0; $auth_message = user_authorization($PHP_AUTH_USER,$PHP_AUTH_PW,'',1,0); if ($auth_message == 'GOOD') {$auth=1;} if ($auth < 1) { $VDdisplayMESSAGE = _QXZ("Login incorrect, please try again"); if ($auth_message == 'LOCK') { $VDdisplayMESSAGE = _QXZ("Too many login attempts, try again in 15 minutes"); Header ("Content-type: text/html; charset=utf-8"); echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; exit; } if ($auth_message == 'IPBLOCK') { $VDdisplayMESSAGE = _QXZ("Your IP Address is not allowed") . ": $ip"; Header ("Content-type: text/html; charset=utf-8"); echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$auth_message|\n"; exit; } Header("WWW-Authenticate: Basic realm=\"CONTACT-CENTER-ADMIN\""); Header("HTTP/1.0 401 Unauthorized"); echo "$VDdisplayMESSAGE: |$PHP_AUTH_USER|$PHP_AUTH_PW|$auth_message|\n"; exit; } $user_stmt="select full_name,user_level,selected_language,qc_enabled from vicidial_users where user='$PHP_AUTH_USER'"; $user_level=0; $user_rslt=mysql_to_mysqli($user_stmt, $link); if (mysqli_num_rows($user_rslt)>0) { $user_row=mysqli_fetch_row($user_rslt); $full_name = $user_row[0]; $user_level = $user_row[1]; $VUselected_language = $user_row[2]; $qc_auth = $user_row[3]; } if ($SSallow_chats < 1) { header ("Content-type: text/html; charset=utf-8"); echo _QXZ("Error, chat disabled on this system"); exit; } if ($end_all_chats) { $archive_stmt="insert ignore into vicidial_manager_chat_log_archive select * from vicidial_manager_chat_log where manager_chat_id='$end_all_chats'"; $archive_rslt=mysql_to_mysqli($archive_stmt, $link); $archive_stmt="insert ignore into vicidial_manager_chats_archive select * from vicidial_manager_chats where manager_chat_id='$end_all_chats'"; $archive_rslt=mysql_to_mysqli($archive_stmt, $link); $delete_stmt="delete from vicidial_manager_chat_log where manager_chat_id='$end_all_chats'"; $delete_rslt=mysql_to_mysqli($delete_stmt, $link); $archive_stmt="delete from vicidial_manager_chats where manager_chat_id='$end_all_chats'"; $archive_rslt=mysql_to_mysqli($archive_stmt, $link); } if ($submit_chat == _QXZ("ALL LIVE AGENTS")) { $chat_agents_SQL_OR=""; $chat_groups_SQL_OR=""; $chat_campaigns_SQL_OR=""; $available_chat_agents_string='|'; $available_chat_groups_string='|'; $available_chat_campaigns_string='|'; } else if ($submit_chat) { $i=0; $available_chat_agents_string='|'; $available_chat_agents_ct = count($available_chat_agents); $chat_agents_SQL_OR="vicidial_live_agents.user in ('',"; while($i < $available_chat_agents_ct) { $available_chat_agents_string .= "$available_chat_agents[$i]|"; $chat_agents_SQL_OR.="'$available_chat_agents[$i]',"; $i++; } $chat_agents_SQL_OR=substr($chat_agents_SQL_OR, 0, -1); $chat_agents_SQL_OR.=") OR "; $i=0; $available_chat_groups_string='|'; $available_chat_groups_ct = count($available_chat_groups); $chat_groups_SQL_OR="vicidial_users.user_group in ('',"; while($i < $available_chat_groups_ct) { $available_chat_groups_string .= "$available_chat_groups[$i]|"; $chat_groups_SQL_OR.="'$available_chat_groups[$i]',"; $i++; } $chat_groups_SQL_OR=preg_replace("/,$/", "", $chat_groups_SQL_OR); $chat_groups_SQL_OR.=") OR "; $i=0; $available_chat_campaigns_string='|'; $available_chat_campaigns_ct = count($available_chat_campaigns); $chat_campaigns_SQL_OR="vicidial_live_agents.campaign_id in ('',"; while($i < $available_chat_campaigns_ct) { $available_chat_campaigns_string .= "$available_chat_campaigns[$i]|"; $chat_campaigns_SQL_OR.="'$available_chat_campaigns[$i]',"; $i++; } $chat_campaigns_SQL_OR=preg_replace("/,$/", "", $chat_campaigns_SQL_OR); $chat_campaigns_SQL_OR.=") "; } if (strlen($chat_agents_SQL_OR.$chat_groups_SQL_OR.$chat_campaigns_SQL_OR)>0) { $chat_query_SQL=" and (".$chat_agents_SQL_OR.$chat_groups_SQL_OR.$chat_campaigns_SQL_OR.")"; } else { $chat_query_SQL=""; } $check_stmt="select manager_chat_id from vicidial_manager_chats where manager='$PHP_AUTH_USER' limit 1"; $check_rslt=mysql_to_mysqli($check_stmt, $link); $active_chats=mysqli_num_rows($check_rslt); if ($active_chats>0) { $active_row=mysqli_fetch_row($check_rslt); $manager_chat_id=$active_row[0]; } if ($active_chats<1 && $manager_message && ($submit_chat== _QXZ("ALL LIVE AGENTS") || ($submit_chat== _QXZ("SELECTED AGENTS") && ($available_chat_agents_ct+$available_chat_groups_ct+$available_chat_campaigns_ct)>0))) { $stmt="select vicidial_live_agents.user, vicidial_users.full_name from vicidial_live_agents, vicidial_users where vicidial_live_agents.user=vicidial_users.user $chat_query_SQL and vicidial_users.user!='$PHP_AUTH_USER' order by vicidial_users.full_name asc"; $rslt=mysql_to_mysqli($stmt, $link); if (mysqli_num_rows($rslt)>0) { $ins_stmt="insert into vicidial_manager_chats(chat_start_date, manager, selected_agents, selected_user_groups, selected_campaigns, allow_replies, internal_chat_type) VALUES(now(), '$PHP_AUTH_USER', '$available_chat_agents_string', '$available_chat_groups_string', '$available_chat_campaigns_string', '$allow_replies', 'MANAGER')"; $ins_rslt=mysql_to_mysqli($ins_stmt, $link); $manager_chat_id=mysqli_insert_id($link); $subid=1; while($row=mysqli_fetch_row($rslt)) { $user=$row[0]; #$manager_message = preg_replace('/"/i','',$manager_message); #$manager_message = preg_replace("/'/i",'',$manager_message); # $manager_message = preg_replace('/;/i','',$manager_message); # $manager_message = preg_replace("/\\\\/i",' ',$manager_message); $manager_message = preg_replace("/\r/i",'',$manager_message); $manager_message = preg_replace("/\n/i",' ',$manager_message); # $manager_message=addslashes(trim("$manager_message")); $message_id=date("U").".".rand(10000000,99999999); $ins_chat_stmt="insert into vicidial_manager_chat_log(manager_chat_id, manager_chat_subid, manager, user, message, message_id, message_date, message_posted_by) VALUES('$manager_chat_id', '$subid', '".$PHP_AUTH_USER."', '$user', '".mysqli_real_escape_string($link, $manager_message)."', '$message_id', now(), '".$PHP_AUTH_USER."')"; $ins_chat_rslt=mysql_to_mysqli($ins_chat_stmt, $link); $subid++; } } } if (($LOGuser_level < 9) and ($SSlevel_8_disable_add > 0)) {$add_copy_disabled++;} $stmt="SELECT allowed_campaigns,allowed_reports,admin_viewable_groups,admin_viewable_call_times from vicidial_user_groups where user_group='$LOGuser_group';"; $rslt=mysql_to_mysqli($stmt, $link); $row=mysqli_fetch_row($rslt); $LOGallowed_campaigns = $row[0]; $LOGallowed_reports = $row[1]; $LOGadmin_viewable_groups = $row[2]; $LOGadmin_viewable_call_times = $row[3]; $admin_viewable_groupsALL=0; $LOGadmin_viewable_groupsSQL=''; $whereLOGadmin_viewable_groupsSQL=''; $valLOGadmin_viewable_groupsSQL=''; $vmLOGadmin_viewable_groupsSQL=''; if ( (!preg_match("/\-\-ALL\-\-/i",$LOGadmin_viewable_groups)) and (strlen($LOGadmin_viewable_groups) > 3) ) { $rawLOGadmin_viewable_groupsSQL = preg_replace("/ -/",'',$LOGadmin_viewable_groups); $rawLOGadmin_viewable_groupsSQL = preg_replace("/ /","','",$rawLOGadmin_viewable_groupsSQL); $LOGadmin_viewable_groupsSQL = "and user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; $whereLOGadmin_viewable_groupsSQL = "where user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; $valLOGadmin_viewable_groupsSQL = "and val.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; $vmLOGadmin_viewable_groupsSQL = "and vm.user_group IN('---ALL---','$rawLOGadmin_viewable_groupsSQL')"; } else {$admin_viewable_groupsALL=1;} $regexLOGadmin_viewable_groups = " $LOGadmin_viewable_groups "; $UUgroups_list=''; if ($admin_viewable_groupsALL > 0) {$UUgroups_list .= "\n";} $stmt="SELECT user_group,group_name from vicidial_user_groups $whereLOGadmin_viewable_groupsSQL order by user_group;"; $rslt=mysql_to_mysqli($stmt, $link); $UUgroups_to_print = mysqli_num_rows($rslt); $o=0; while ($UUgroups_to_print > $o) { $rowx=mysqli_fetch_row($rslt); $UUgroups_list .= "\n"; $o++; } header ("Content-type: text/html; charset=utf-8"); header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header ("Pragma: no-cache"); // HTTP/1.0 ?>
| "._QXZ("CURRENT CHAT")." #$manager_chat_id | \n"; echo "["._QXZ("END ALL CHATS")."] | "; echo "|||
| "._QXZ("Agent")." | \n"; echo "\t"._QXZ("Transcript")." | \n"; echo "\t"._QXZ("Message")." | \n"; echo "||
| $full_name | "; $chat_output_header[$chat_subid].="\t";
$chat_output_footer[$chat_subid]= " | ";
# $chat_output_footer[$chat_subid].="\t"; $chat_output_footer[$chat_subid].="\t | ||