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]; $chat_url = $row[4]; $SSallow_chats = $row[5]; } $VUselected_language = $SSdefault_language; ##### END SETTINGS LOOKUP ##### ########################################### if (strlen($language) > 1) { $stmt = "SELECT language_code,language_description FROM vicidial_languages where language_id='$language' and active='Y';"; $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";} $lang_good_ct = mysqli_num_rows($rslt); if ($lang_good_ct > 0) { $row=mysqli_fetch_row($rslt); $language_code = $row[0]; $language_description = $row[1]; $VUselected_language = $language; } } if ($SSallow_chats < 1) { header ("Content-type: text/html; charset=utf-8"); echo _QXZ("Error, chat disabled on this system"); exit; } if ($action=="send_message" && $chat_id) { $live_stmt="SELECT status from vicidial_live_chats where chat_id='$chat_id'"; $live_rslt=mysql_to_mysqli($live_stmt, $link); if ($user && $chat_message && $chat_id && mysqli_num_rows($live_rslt)>0) { $live_row=mysqli_fetch_row($live_rslt); $status=$live_row[0]; if ($status=="WAITING") { echo _QXZ("Chat is waiting for an agent").": $chat_id"; } else { if ($status=="LIVE") { # Check that the customer is still in the chat. $active_stmt="SELECT * from vicidial_chat_participants where chat_id='$chat_id' and chat_member='$user'"; $active_rslt=mysql_to_mysqli($active_stmt, $link); if (mysqli_num_rows($active_rslt)>0) { $ins_stmt="INSERT IGNORE INTO vicidial_chat_log(chat_id, message, poster, chat_member_name, chat_level) VALUES('$chat_id', '".mysqli_real_escape_string($link, $chat_message)."', '$user', '".mysqli_real_escape_string($link, $chat_member_name)."', '$chat_level')"; $ins_rslt=mysql_to_mysqli($ins_stmt, $link); if (mysqli_affected_rows($link)<1) { echo ""._QXZ("SYSTEM ERROR")."
\n"; } } } else { echo ""._QXZ("SYSTEM ERROR")."
\n"; } } } else if (mysqli_num_rows($rslt)==0) { echo _QXZ("Chat has been closed").": $chat_id"; } } if ($action=="leave_chat" && $user && $chat_id) { if (!$chat_member_name) {$chat_member_name="Customer";} $del_stmt2="DELETE from vicidial_chat_participants where chat_id='$chat_id' and chat_member='$user'"; $del_rslt2=mysql_to_mysqli($del_stmt2, $link); $deleted_participants=mysqli_affected_rows($link); if ($deleted_participants>0) { # ERASE THE CHAT IF THE PERSON NEVER GOT PICKED UP - I DON'T REMEMBER WHY I MOVED customer_leave_chat TO leave_chat $stmt="SELECT lead_id, status, chat_creator from vicidial_live_chats where chat_id='$chat_id'"; # and status='WAITING' and chat_creator='NONE' $rslt=mysql_to_mysqli($stmt, $link); if (mysqli_num_rows($rslt)>0) { $row=mysqli_fetch_row($rslt); $lead_id=$row[0]; $chat_status=$row[1]; $chat_creator=$row[2]; if ($chat_status=="WAITING" && $chat_creator=="NONE") { # USE SPECIAL DROP STATUS 'CDROP' FOR DROPPED CHATS WHERE NO AGENT RESPONDED TO CHAT $upd_stmt="UPDATE vicidial_list set status='CDROP' where lead_id='$lead_id'"; $upd_rslt=mysql_to_mysqli($upd_stmt, $link); $ins_stmt="INSERT IGNORE INTO vicidial_chat_archive SELECT chat_id, chat_start_time, 'DROP', chat_creator, group_id, lead_id, transferring_agent, user_direct, user_direct_group_id From vicidial_live_chats where chat_id='$chat_id'"; $ins_rslt=mysql_to_mysqli($ins_stmt, $link); $del_stmt="DELETE from vicidial_live_chats where chat_id='$chat_id'"; $del_rslt=mysql_to_mysqli($del_stmt, $link); # ARCHIVE CHAT IN CASE CUSTOMER IS LEAVING WHILE BEING TRANSFERRED $archive_log_stmt="insert ignore into vicidial_chat_log_archive select * from vicidial_chat_log where chat_id='$chat_id'"; $archive_log_rslt=mysql_to_mysqli($archive_log_stmt, $link); $del_log_stmt="delete from vicidial_chat_log where chat_id='$chat_id'"; $del_log_rslt=mysql_to_mysqli($del_log_stmt, $link); } else { # CHAT IS LIVE/AGENT NEEDS NOTIFICATION $ins_alert_stmt="INSERT INTO vicidial_chat_log(poster, chat_member_name, message_time, message, chat_id, chat_level) SELECT '$chat_creator', full_name, now(), '$chat_member_name has left chat', '$chat_id', '1' from vicidial_users where user='$chat_creator'"; $ins_alert_rslt=mysql_to_mysqli($ins_alert_stmt, $link); } } } } if ($action=="update_chat_window" && $chat_id) { $status_stmt="SELECT status, chat_creator, transferring_agent from vicidial_live_chats where chat_id='$chat_id'"; $status_rslt=mysql_to_mysqli($status_stmt, $link); if (mysqli_num_rows($status_rslt)==0) { # JCJ - comment out to display in Javascript function that calls this in parent page. echo "Error|"; # Create color-coding for archived chat $stmt="SELECT * from vicidial_chat_log_archive where chat_id='$chat_id' order by message_time asc"; $rslt=mysql_to_mysqli($stmt, $link); $chat_members=array(); while ($row=mysqli_fetch_row($rslt)) { if (!in_array("$row[4]", $chat_members)) { array_push($chat_members, "$row[4]"); } } ## DISPLAY LOGO ON SCREEN EVEN AFTER CHAT IS ENDED $chat_color_stmt="select menu_background, frame_background, std_row1_background, std_row2_background, std_row3_background, std_row4_background, std_row5_background, web_logo from vicidial_inbound_groups vig, vicidial_screen_colors v where vig.group_id='$group_id' and vig.customer_chat_screen_colors=v.colors_id and length(frame_background)=6 and length(menu_background)=6 limit 1;"; $color_rslt=mysql_to_mysqli($chat_color_stmt, $link); $web_logo=""; $filepath="vicidial/images"; if(mysqli_num_rows($color_rslt)>0 && $use_agent_colors>0) { $color_row=mysqli_fetch_array($color_rslt); $color_array=array("#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"); $chat_background_array=array("#$color_row[std_row1_background]", "#$color_row[std_row2_background]", "#$color_row[std_row3_background]", "#$color_row[std_row4_background]", "#$color_row[std_row5_background]", "#$color_row[frame_background]", "#$color_row[menu_background]"); # switch ($color_row["web_logo"]) { # case "default_new": # $color_row["web_logo"]=".png"; # break; # case "default_old"; # $color_row["web_logo"]=".gif"; # $filepath="vicidial"; # break; # } # $web_logo=$color_row["web_logo"]; } else { # if(mysqli_num_rows($color_rslt)>0) { # $color_row=mysqli_fetch_array($color_rslt); # switch ($color_row["web_logo"]) { # case "default_new": # $color_row["web_logo"]=".png"; # break; # case "default_old"; # $color_row["web_logo"]=".gif"; # $filepath="vicidial"; # break; # } # $web_logo=$color_row["web_logo"]; # } $color_array=array("#FF0000", "#0000FF", "#009900", "#990099", "#009999", "#666600", "#999999"); $chat_background_array=array("#FFCCCC", "#CCCCFF", "#CCFFCC", "#FFCCFF", "#CCFFFF", "#CCCC99", "#CCCCCC"); } # if (!preg_match("/\.(jpg|gif|png|bmp)$/", $web_logo)) {$web_logo.=".png";} $chat_status="INACTIVE"; echo "$chat_status|"; # echo "\n"; # echo "\n"; # echo "\n"; # echo "\n"; # echo "\n
\n"; # echo ""._QXZ("Current chat").": INACTIVE\n"; # echo "\n"; # if (file_exists("../$filepath/vicidial_admin_web_logo$web_logo")) # { # echo "\n"; # } # else # { # if (file_exists("./images/vicidial_admin_web_logo$web_logo")) # { # echo "\n"; # } # } # echo "
\n"; ## GRAB ARCHIVED CHAT MESSAGES AND DISPLAY THEM if (!$user_level || $user_level==0) {$user_level_clause=" and chat_level='0' ";} else {$user_level_clause="";} $stmt="SELECT * from vicidial_chat_log_archive where chat_id='$chat_id' $user_level_clause order by message_time asc"; $rslt=mysql_to_mysqli($stmt, $link); while ($row=mysqli_fetch_row($rslt)) { $chat_color_key=array_search("$row[4]", $chat_members); $row[2]=preg_replace('/\n/', '
', $row[2]); echo "
  • $row[5] ($row[3]) - $row[2]
  • \n"; } } else { $status_row=mysqli_fetch_row($status_rslt); ## Modify user's ping date to verify they are still participating if ($user && $keepalive) { $upd_stmt="UPDATE vicidial_chat_participants set ping_date=now() where chat_member='$user' and chat_id='$chat_id'"; $upd_rslt=mysql_to_mysqli($upd_stmt, $link); } ## CHECK IF CHAT IS ACTIVE, IF SO GRAB DISTINCT USERS IN ORDER OF POST TO ASSIGN COLORS if ($status_row[0]=="LIVE" || ($status_row[0]=="WAITING" && $status_row[2]!="")) { $live_stmt="SELECT * from vicidial_live_chats vlc, vicidial_chat_participants vcp where vlc.chat_id='$chat_id' and (status='LIVE' or (status='WAITING' and transferring_agent is not null)) and vlc.chat_id=vcp.chat_id and vcp.chat_member='$user'"; $live_rslt=mysql_to_mysqli($live_stmt, $link); if (mysqli_num_rows($live_rslt)>0) { $chat_color_stmt="select menu_background, frame_background, std_row1_background, std_row2_background, std_row3_background, std_row4_background, std_row5_background, web_logo from vicidial_inbound_groups vig, vicidial_screen_colors v where vig.group_id='$group_id' and vig.customer_chat_screen_colors=v.colors_id and length(frame_background)=6 and length(menu_background)=6 limit 1;"; $color_rslt=mysql_to_mysqli($chat_color_stmt, $link); # $web_logo=""; $filepath="vicidial/images"; if(mysqli_num_rows($color_rslt)>0 && $use_agent_colors>0) { $color_row=mysqli_fetch_array($color_rslt); $color_array=array("#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"); $chat_background_array=array("#$color_row[std_row1_background]", "#$color_row[std_row2_background]", "#$color_row[std_row3_background]", "#$color_row[std_row4_background]", "#$color_row[std_row5_background]", "#$color_row[frame_background]", "#$color_row[menu_background]"); # switch ($color_row["web_logo"]) { # case "default_new": # $color_row["web_logo"]=".png"; # break; # case "default_old"; # $color_row["web_logo"]=".gif"; # $filepath="vicidial"; # break; # } # $web_logo=$color_row["web_logo"]; } else { # if(mysqli_num_rows($color_rslt)>0) { # $color_row=mysqli_fetch_array($color_rslt); # switch ($color_row["web_logo"]) { # case "default_new": # $color_row["web_logo"]=".png"; # break; # case "default_old"; # $color_row["web_logo"]=".gif"; # $filepath="vicidial"; # break; # # } # $web_logo=$color_row["web_logo"]; # } $color_array=array("#FF0000", "#0000FF", "#009900", "#990099", "#009999", "#666600", "#999999"); $chat_background_array=array("#FFCCCC", "#CCCCFF", "#CCFFCC", "#FFCCFF", "#CCFFFF", "#CCCC99", "#CCCCCC"); } # if (!preg_match("/\.(jpg|gif|png|bmp)$/", $web_logo)) {$web_logo.=".png";} $chat_status="ACTIVE"; echo "$chat_status|"; # Create color-coding for chat $stmt="SELECT * from vicidial_chat_log where chat_id='$chat_id' order by message_time asc"; $rslt=mysql_to_mysqli($stmt, $link); $chat_members=array(); while ($row=mysqli_fetch_row($rslt)) { if (!in_array("$row[4]", $chat_members)) { array_push($chat_members, "$row[4]"); } } ## GRAB CHAT MESSAGES AND DISPLAY THEM if (!$user_level || $user_level==0) {$user_level_clause=" and chat_level='0' ";} else {$user_level_clause="";} $stmt="SELECT * from vicidial_chat_log where chat_id='$chat_id' $user_level_clause order by message_time asc"; echo "\n"; $rslt=mysql_to_mysqli($stmt, $link); while ($row=mysqli_fetch_row($rslt)) { $chat_color_key=array_search("$row[4]", $chat_members); $row[2]=preg_replace('/\n/', '
    ', $row[2]); echo "\n"; } echo "
  • $row[5] ($row[3]) - $row[2]
  • \n"; if ($status_row[0]=="WAITING" && $status_row[2]!="") { echo "
    "._QXZ("Currently being transferred, waiting for agent...")."
    \n"; } ## PLAY AUDIO FILE IF THERE ARE NEW MESSAGES $current_messages=mysqli_num_rows($rslt); echo "\n"; } else { $chat_status="INACTIVE"; echo "$chat_status|"; $live_stmt="SELECT * from vicidial_live_chats vlc, vicidial_chat_participants vcp where vlc.chat_id='$chat_id' and (status='LIVE' or (status='WAITING' and transferring_agent is not null)) and vlc.chat_id=vcp.chat_id and vcp.chat_member='$user'"; $live_rslt=mysql_to_mysqli($live_stmt, $link); if (mysqli_num_rows($live_rslt)>0) { $chat_color_stmt="select menu_background, frame_background, std_row1_background, std_row2_background, std_row3_background, std_row4_background, std_row5_background, web_logo from vicidial_inbound_groups vig, vicidial_screen_colors v where vig.group_id='$group_id' and vig.customer_chat_screen_colors=v.colors_id and length(frame_background)=6 and length(menu_background)=6 limit 1;"; $color_rslt=mysql_to_mysqli($chat_color_stmt, $link); if(mysqli_num_rows($color_rslt)>0 && $use_agent_colors>0) { $color_row=mysqli_fetch_array($color_rslt); $color_array=array("#000000", "#000000", "#000000", "#000000", "#000000", "#000000", "#000000"); $chat_background_array=array("#$color_row[std_row1_background]", "#$color_row[std_row2_background]", "#$color_row[std_row3_background]", "#$color_row[std_row4_background]", "#$color_row[std_row5_background]", "#$color_row[frame_background]", "#$color_row[menu_background]"); } else { $color_array=array("#FF0000", "#0000FF", "#009900", "#990099", "#009999", "#666600", "#999999"); $chat_background_array=array("#FFCCCC", "#CCCCFF", "#CCFFCC", "#FFCCFF", "#CCFFFF", "#CCCC99", "#CCCCCC"); } } # Create color-coding for chat $stmt="SELECT * from vicidial_chat_log where chat_id='$chat_id' order by message_time asc"; $rslt=mysql_to_mysqli($stmt, $link); $chat_members=array(); while ($row=mysqli_fetch_row($rslt)) { if (!in_array("$row[4]", $chat_members)) { array_push($chat_members, "$row[4]"); } } ## GRAB CHAT MESSAGES AND DISPLAY THEM if (!$user_level || $user_level==0) {$user_level_clause=" and chat_level='0' ";} else {$user_level_clause="";} $stmt="SELECT * from vicidial_chat_log where chat_id='$chat_id' $user_level_clause order by message_time asc"; echo "\n"; $rslt=mysql_to_mysqli($stmt, $link); while ($row=mysqli_fetch_row($rslt)) { $chat_color_key=array_search("$row[4]", $chat_members); $row[2]=preg_replace('/\n/', '
    ', $row[2]); echo "\n"; } echo "
  • $row[5] ($row[3]) - $row[2]
  • \n"; # $survey_stmt="select customer_chat_survey_link, customer_chat_survey_text from vicidial_inbound_groups where group_id='$group_id'"; # $survey_rslt=mysql_to_mysqli($survey_stmt, $link); # $survey_row=mysqli_fetch_array($survey_rslt); # if (strlen($survey_row["customer_chat_survey_link"])>0) { # echo "

    "; # if (strlen($survey_row["customer_chat_survey_text"])>0) { # echo $survey_row["customer_chat_survey_text"]; # } else { # echo _QXZ("PLEASE TAKE OUR SURVEY"); # } # echo "

    "; # } # echo ""._QXZ("You have left chat").": $chat_id."; # echo "

    "._QXZ("GO BACK TO CHAT FORM")."
    \n"; } } else { if ($status_row[1]=="NONE") { # $chat_color_stmt="select menu_background, frame_background, std_row1_background, std_row2_background, std_row3_background, std_row4_background, std_row5_background, web_logo from vicidial_inbound_groups vig, vicidial_screen_colors v where vig.group_id='$group_id' and vig.customer_chat_screen_colors=v.colors_id and length(frame_background)=6 and length(menu_background)=6 limit 1;"; # $color_rslt=mysql_to_mysqli($chat_color_stmt, $link); # $web_logo=""; $filepath="vicidial/images"; # if(mysqli_num_rows($color_rslt)>0) { # $color_row=mysqli_fetch_array($color_rslt); # switch ($color_row["web_logo"]) { # case "default_new": # $color_row["web_logo"]=".png"; # break; # case "default_old"; # $color_row["web_logo"]=".gif"; # $filepath="vicidial"; # break; # } # $web_logo=$color_row["web_logo"]; # } # if (!preg_match("/\.(jpg|gif|png|bmp)$/", $web_logo)) {$web_logo.=".png";} # echo "\n"; # echo "\n"; # echo "\n"; # echo "\n"; # echo "\n
    \n"; # echo ""._QXZ("Waiting for next available agent...")."
    \n"; $chat_status=""._QXZ("WAITING").""; echo "$chat_status|"; $chat_count_stmt="SELECT chat_id from vicidial_live_chats vlc, vicidial_inbound_groups vig where vlc.status='WAITING' and (vlc.group_id='$group_id' or (vlc.group_id='AGENTDIRECT_CHAT')) and (transferring_agent is null or transferring_agent!='$user') and vlc.group_id=vig.group_id order by queue_priority desc, chat_id asc"; $chat_count_rslt=mysql_to_mysqli($chat_count_stmt, $link); $people_ahead_of_you=0; while($chat_count_row=mysqli_fetch_row($chat_count_rslt)) { if ($chat_count_row[0]!=$chat_id) { $people_ahead_of_you++; } else { break; } } if ($people_ahead_of_you>0) { echo ""._QXZ("There are")." $people_ahead_of_you "._QXZ("customer(s) in chat queue ahead of you").""; } else { echo ""._QXZ("You are the next customer in line").""; } # echo "
    \n"; # if (file_exists("../$filepath/vicidial_admin_web_logo$web_logo")) { # echo "\n"; # } else { # if (file_exists("./images/vicidial_admin_web_logo$web_logo")) # { # echo "\n"; # } # } # echo "
    \n"; } else { echo ""._QXZ("SYSTEM ERROR")."
    \n"; } } } } ?>