LICENSE: AGPLv2 # # This is the interface for agents to chat with customers and each other. It's separate from the manager-to-agent # chat interface out of necessity and calls the chat_db_query.php page to send information and display it. It will # display any open chat the agent has, and of those open chats the full conversation of the current active chat # will be displayed. It will also show when an agent has a new unread message in any of his conversations and # allow the agent to toggle between them. They can also initiate chats with any agent currently logged into a # campaign through the agent interface. # # Builds: # 150903-2349 - First build # 151213-1107 - Added variable filtering # 151218-0913 - Added missing translation code and user auth # 160303-0051 - Added code for chat transfers # 160818-1235 - Added line colors and scrolling # 170528-1001 - Added variable filtering # 190902-0914 - Fix for PHP 7.2 # 201117-2207 - Changes for better compatibility with non-latin data input # 210616-2040 - Added optional CORS support, see options.php for details # 220220-0928 - Added allow_web_debug system setting # 220518-2211 - Small fix for encrypted auth # 230518-2002 - Added customer_chat_refresh_seconds options.php setting, and message display # require("dbconnect_mysqli.php"); require("functions.php"); $php_script = 'vdc_chat_display.php'; $MT[0]=''; $chat_group_ids=$MT; if (isset($_GET["email"])) {$email=$_GET["email"];} elseif (isset($_POST["email"])) {$email=$_POST["email"];} if (isset($_GET["email_invite_lead_id"])) {$email_invite_lead_id=$_GET["email_invite_lead_id"];} elseif (isset($_POST["email_invite_lead_id"])) {$email_invite_lead_id=$_POST["email_invite_lead_id"];} if (isset($_GET["chat_id"])) {$chat_id=$_GET["chat_id"];} elseif (isset($_POST["chat_id"])) {$chat_id=$_POST["chat_id"];} if (isset($_GET["chat_group_id"])) {$chat_group_id=$_GET["chat_group_id"];} elseif (isset($_POST["chat_group_id"])) {$chat_group_id=$_POST["chat_group_id"];} if (isset($_GET["chat_group_ids"])) {$chat_group_ids=$_GET["chat_group_ids"];} elseif (isset($_POST["chat_group_ids"])) {$chat_group_ids=$_POST["chat_group_ids"];} if (isset($_GET["server_ip"])) {$server_ip=$_GET["server_ip"];} elseif (isset($_POST["server_ip"])) {$server_ip=$_POST["server_ip"];} if (isset($_GET["lead_id"])) {$lead_id=$_GET["lead_id"];} elseif (isset($_POST["lead_id"])) {$lead_id=$_POST["lead_id"];} if (isset($_GET["user"])) {$user=$_GET["user"];} elseif (isset($_POST["user"])) {$user=$_POST["user"];} if (isset($_GET["campaign"])) {$campaign=$_GET["campaign"];} elseif (isset($_POST["campaign"])) {$campaign=$_POST["campaign"];} if (isset($_GET["dial_method"])) {$dial_method=$_GET["dial_method"];} elseif (isset($_POST["dial_method"])) {$dial_method=$_POST["dial_method"];} if (isset($_GET["pass"])) {$pass=$_GET["pass"];} elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];} if (isset($_GET["child_window"])) {$child_window=$_GET["child_window"];} elseif (isset($_POST["child_window"])) {$child_window=$_POST["child_window"];} if (isset($_GET["outside_user_name"])) {$outside_user_name=$_GET["outside_user_name"];} elseif (isset($_POST["outside_user_name"])) {$outside_user_name=$_POST["outside_user_name"];} if (isset($_GET["first_name"])) {$first_name=$_GET["first_name"];} elseif (isset($_POST["first_name"])) {$first_name=$_POST["first_name"];} if (isset($_GET["last_name"])) {$last_name=$_GET["last_name"];} elseif (isset($_POST["last_name"])) {$last_name=$_POST["last_name"];} if (isset($_GET["clickmute"])) {$clickmute=$_GET["clickmute"];} elseif (isset($_POST["clickmute"])) {$clickmute=$_POST["clickmute"];} if (isset($_GET["stage"])) {$stage=$_GET["stage"];} elseif (isset($_POST["stage"])) {$stage=$_POST["stage"];} $PHP_SELF=$_SERVER['PHP_SELF']; $PHP_SELF = preg_replace('/\.php.*/i','.php',$PHP_SELF); $DB=preg_replace("/[^0-9a-zA-Z]/","",$DB); $user=preg_replace("/\'|\"|\\\\|;| /","",$user); $pass=preg_replace("/\'|\"|\\\\|;| /","",$pass); ############################################# ##### START SYSTEM_SETTINGS LOOKUP ##### $VUselected_language = ''; $stmt = "SELECT use_non_latin,enable_languages,language_method,default_language,allow_chats,allow_web_debug FROM system_settings;"; $rslt=mysql_to_mysqli($stmt, $link); if ($mel > 0) {mysql_error_logging($NOW_TIME,$link,$mel,$stmt,'00XXX',$user,$server_ip,$session_name,$one_mysql_log);} #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_languages = $row[1]; $SSlanguage_method = $row[2]; $SSdefault_language = $row[3]; $SSallow_chats = $row[4]; $SSallow_web_debug = $row[5]; } $VUselected_language = $SSdefault_language; if ($SSallow_web_debug < 1) {$DB=0;} ##### END SETTINGS LOOKUP ##### ########################################### # if options file exists, use the override values for the above variables # see the options-example.php file for more information if (file_exists('options.php')) { require_once('options.php'); } 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 if ($clickmute!="1") {$clickmute="0";} // Prevents annoying quirk of playing the audio cue every time you click the tab to view this $lead_id = preg_replace("/[^0-9]/","",$lead_id); $chat_id = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$chat_id); $server_ip = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$server_ip); $email = preg_replace("/\'|\"|\\\\|;/","",$email); $dial_method = preg_replace('/[^-\_0-9a-zA-Z]/','',$dial_method); $clickmute = preg_replace("/\'|\"|\\\\|;/","",$clickmute); $stage = preg_replace('/[^-\_0-9a-zA-Z]/','',$stage); $email_invite_lead_id = preg_replace("/\'|\"|\\\\|;/","",$email_invite_lead_id); $child_window = preg_replace('/[^-\_0-9a-zA-Z]/','',$child_window); $chat_group_ids = preg_replace("/\"|\\\\|;/","",$chat_group_ids); $customer_chat_refresh_seconds=preg_replace("/[^0-9\.]/", "", $customer_chat_refresh_seconds); if (!$customer_chat_refresh_seconds) {$customer_chat_refresh_seconds=1;} $customer_chat_refresh_milliseconds = $customer_chat_refresh_seconds*1000; if ($non_latin < 1) { $user = preg_replace('/[^-\_0-9a-zA-Z]/','',$user); $pass=preg_replace("/[^-\.\+\/\=_0-9a-zA-Z]/","",$pass); $outside_user_name = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$user); $first_name = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$first_name); $last_name = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$last_name); $campaign = preg_replace('/[^-\_0-9a-zA-Z]/','',$campaign); $chat_group_id = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$chat_group_id); } else { $user = preg_replace('/[^-_0-9\p{L}]/u','',$user); $pass = preg_replace('/[^-\.\+\/\=_0-9\p{L}]/u','',$pass); $outside_user_name = preg_replace("/\'|\"|\\\\|;/","",$user); $first_name = preg_replace('/[^- \_\.0-9\p{L}]/u','',$first_name); $last_name = preg_replace('/[^- \_\.0-9\p{L}]/u','',$last_name); $campaign = preg_replace('/[^-\_0-9\p{L}]/u','',$campaign); $chat_group_id = preg_replace('/[^- \_\.0-9\p{L}]/u','',$chat_group_id); } if( (strlen($stage) > 0) and ($stage == 'WELCOME') ) { echo _QXZ("Customer Chat Frame"); exit; } if ($SSallow_chats < 1) { header ("Content-type: text/html; charset=utf-8"); echo _QXZ("Error, chat disabled on this system"); exit; } $auth=0; $auth_message = user_authorization($user,$pass,'',0,1,0,0,'vdc_chat_display'); if ($auth_message == 'GOOD') {$auth=1;} if( (strlen($user)<2) or (strlen($pass)<2) or ($auth==0)) { echo _QXZ("Invalid Username/Password:")." |$user|$pass|$auth_message|vdc_chat_display|\n"; exit; } $user_stmt="SELECT full_name,user_level,selected_language from vicidial_users where user='$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]; if ($chat_id) { $chat_stmt="SELECT * from vicidial_live_chats where chat_creator='$user' and chat_id='$chat_id';"; # echo "\n"; } else { # echo "Waiting for chat request..."; exit; } } else { unset($pass); ## Since user is not a vicidial user, check to see if they belong to another chat and use that as the default chat variable. $chat_stmt="SELECT chat_id from vicidial_chat_participants where chat_member='$user';"; $chat_rslt=mysql_to_mysqli($chat_stmt, $link); if (mysqli_num_rows($chat_rslt)>0) { $chat_row=mysqli_fetch_row($chat_rslt); $chat_id=$chat_row[0]; } } $stmt="SELECT * from vicidial_list where lead_id='$lead_id';"; $rslt=mysql_to_mysqli($stmt, $link); if (mysqli_num_rows($rslt)>0) { $row=mysqli_fetch_array($rslt); $first_name=$row["first_name"]; $last_name=$row["last_name"]; if (!$full_name) {$full_name=trim("$first_name $last_name");} if (!$email) {$email=$row["email"];} } 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 echo ' '; ?> <?php echo _QXZ("Agent Chat Interface"); ?> "._QXZ("No user ID - no chat access. Sorry").""; exit; } $user_stmt="SELECT if(user_nickname!='' and user_nickname is not null, user_nickname, full_name) from vicidial_users where user='$user' limit 1;"; $user_rslt=mysql_to_mysqli($user_stmt, $link); $inchat_html=""; $nochat_html=""; $autojoin_js_fx="StartRefresh();"; if (mysqli_num_rows($user_rslt)==0) { if($outside_user_name && $chat_id) { $inchat_html.=""; $autojoin_js_fx.="JoinChat('$chat_id');"; } else { $chat_stmt="SELECT chat_member_name from vicidial_chat_log where poster='$user' order by message_time desc limit 1;"; $chat_rslt=mysql_to_mysqli($chat_stmt, $link); if (mysqli_num_rows($chat_rslt)==0) { $nochat_html.="Please enter your name below before joining a chat:
"; $nochat_html.=""; } else { $chat_row=mysqli_fetch_row($chat_rslt); $outside_user_name=$chat_row[0]; $inchat_html.=""; $autojoin_js_fx.="JoinChat('$chat_id');"; } } } else { $user_row=mysqli_fetch_row($user_rslt); $inchat_html.=""; $autojoin_js_fx.="JoinChat('$chat_id');"; } if($child_window) { $inchat_html.="

"; } ?> \n"; ?>
** "._QXZ("Messages are on a")." ".$customer_chat_refresh_seconds."-"._QXZ("second delay")." **" : ""); ?>
" onClick="SendMessage(this.form.chat_id.value, this.form.user.value, this.form.chat_message.value)">

" onClick="document.getElementById('chat_message').value=''">

"._QXZ("Privacy ON"); } ?>
" onClick="ToggleSpan('ChatConsoleSpan'); ToggleSpan('XferConsoleSpan'); LoadXferOptions();">

"; if (!$chat_id) { echo "

"; echo "

\n"; } if ($chat_creator && $chat_creator==$user) { if (!$email_invite_lead_id) { # Flag from sending an invite - this page reloads as a result and this below INVITE button must be prevented from being loaded echo "

"; } echo "

"; } echo ""; } ?>