LICENSE: AGPLv2 # # This page is for agents to chat with managers via the agent interface. # # changes: # 141212-2245 - First Build # 151213-1108 - Added variable filtering # 151218-1141 - Added missing translation code and user auth, merged js code into file # 151231-0842 - Added agent_allowed_chat_groups setting # 160108-2300 - Changed some mysqli_query to mysql_to_mysqli for consistency # 160523-0630 - Fixed vicidial_stylesheet issues # 161217-0827 - Added code for multi-user internal chat sessions # 161221-0801 - Added color-coding for users in internal chat sessions # 180927-0624 - Fix for missing translationm issue #1125 # 201117-2239 - Changes for better compatibility with non-latin data input # 210616-2056 - Added optional CORS support, see options.php for details # 220220-0855 - Added allow_web_debug system setting # 220518-2210 - Small fix for encrypted auth # 220922-1027 - Added BLANK action for first agent screen page load # $admin_version = '2.14-13'; $build = '220922-1027'; $php_script = 'agc_agent_manager_chat_interface.php'; $sh="managerchats"; require("dbconnect_mysqli.php"); require("functions.php"); 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["user"])) {$user=$_GET["user"];} elseif (isset($_POST["user"])) {$user=$_POST["user"];} if (isset($_GET["pass"])) {$pass=$_GET["pass"];} elseif (isset($_POST["pass"])) {$pass=$_POST["pass"];} if (!$user) {echo "Page should only be viewed through the agent interface."; die;} $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 ##### ########################################### $action = preg_replace('/[^-\_0-9a-zA-Z]/','',$action); $SUBMIT = preg_replace('/[^-\_0-9a-zA-Z]/','',$SUBMIT); if ($non_latin < 1) { $user=preg_replace("/[^-_0-9a-zA-Z]/","",$user); $pass=preg_replace("/[^-\.\+\/\=_0-9a-zA-Z]/","",$pass); $manager_chat_id = preg_replace('/[^- \_\.0-9a-zA-Z]/','',$user); } else { $user = preg_replace('/[^-_0-9\p{L}]/u','',$user); $pass = preg_replace('/[^-\.\+\/\=_0-9\p{L}]/u','',$pass); $manager_chat_id = preg_replace("/[^- \_\.0-9\p{L}]/u","",$user); } # 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'); } $manager_chat_refresh_milliseconds = ($manager_chat_refresh_seconds ? $manager_chat_refresh_seconds*1000 : 1000); if ($action == 'BLANK') { header ("Content-type: text/html; charset=utf-8"); exit; } $auth=0; $auth_message = user_authorization($user,$pass,'',0,1,0,0,'chat'); 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|$sh|\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 ($SSallow_chats < 1) { header ("Content-type: text/html; charset=utf-8"); echo _QXZ("Error, chat disabled on this system"); exit; } # Get a count on unread messages where the user is involved but not the chat manager/initiator in order to create the ChatReloadIDNumber variable $chat_reload_id_number_array=array(); $unread_stmt="select manager_chat_id, manager_chat_subid, sum(if(message_viewed_date is not null and vicidial_manager_chat_log.user='$user', 0, 1)) as unread_count from vicidial_manager_chat_log where vicidial_manager_chat_log.user='$user' group by manager_chat_id, manager_chat_subid order by manager_chat_id, manager_chat_subid"; $unread_rslt=mysql_to_mysqli($unread_stmt, $link); while ($unread_row=mysqli_fetch_array($unread_rslt)) { $IDNumber=$unread_row["manager_chat_id"]."-".$unread_row["manager_chat_subid"]."-".$unread_row["unread_count"]; array_push($chat_reload_id_number_array, "$IDNumber"); } # Pull the most recently posted-to chat that has not been viewed, then the most recent period, and display that as the default window $stmt="select distinct vicidial_manager_chat_log.manager_chat_id, vicidial_manager_chat_log.manager_chat_subid, vicidial_users.full_name, vicidial_manager_chats.chat_start_date, sum(if(vicidial_manager_chat_log.message_viewed_date is null and vicidial_manager_chat_log.user='$user', 1, 0)),vicidial_manager_chat_log.user from vicidial_manager_chat_log, vicidial_manager_chats, vicidial_users where vicidial_manager_chat_log.user='$user' and vicidial_manager_chat_log.manager_chat_id=vicidial_manager_chats.manager_chat_id and vicidial_manager_chats.manager=vicidial_users.user group by manager_chat_id, manager_chat_subid order by message_viewed_date asc, message_date desc"; $rslt=mysql_to_mysqli($stmt, $link); $active_chats_array=array(); $chat_subid_array=array(); $unread_chats_array=array(); $chat_managers_array=array(); $chat_start_date_array=array(); $agents_managers_array=array(); // for override $priority_chat=""; $priority_chat_subid=""; while ($row=mysqli_fetch_row($rslt)) { if ($row[0]!="") { if (!$priority_chat) {$priority_chat=$row[0];} # The priority_chat is the most recent chat that has not been viewed. if (!$priority_chat_subid) {$priority_chat_subid=$row[1];} # The priority_chat is the most recent chat that has not been viewed. if (!$agent_manager_override) {$agent_manager_override="0";} # The priority_chat is the most recent chat that has not been viewed. array_push($active_chats_array, "$row[0]"); $chat_subid_array[$row[0]]="$row[1]"; $chat_managers_array[$row[0]]="$row[2]"; $chat_start_date_array[$row[0]]="$row[3]"; if ($row[4]>0) {array_push($unread_chats_array, $row[0]);} # Store any chat with unread messages. $agents_managers_array[$row[0]]="0"; // not a chat where the agent is a manager } } # Get a count on unread messages where the user is the chat manager/initiator in order to create the ChatReloadIDNumber variable $unread_stmt="select manager_chat_id, manager_chat_subid, sum(if(message_viewed_date is not null and vicidial_manager_chat_log.user='$user', 0, 1)) as unread_count from vicidial_manager_chat_log where vicidial_manager_chat_log.manager='$user' group by manager_chat_id, manager_chat_subid order by manager_chat_id, manager_chat_subid"; $unread_rslt=mysql_to_mysqli($unread_stmt, $link); while ($unread_row=mysqli_fetch_array($unread_rslt)) { $IDNumber=$unread_row["manager_chat_id"]."-".$unread_row["manager_chat_subid"]."-".$unread_row["unread_count"]; array_push($chat_reload_id_number_array, "$IDNumber"); } ### This was added for agent to agent chats since there needs to be a list of open chats where the agent viewing this is also the manager, ### which will now happen because agents can now start their own chats. Added vicidial_manager_chat_log.user to this query on 2/4/15 for ### manager override $stmt="select distinct vicidial_manager_chat_log.manager_chat_id, vicidial_manager_chat_log.manager_chat_subid, vicidial_users.full_name, vicidial_manager_chats.chat_start_date, sum(if(vicidial_manager_chat_log.message_viewed_date is null and vicidial_manager_chat_log.user='$user', 1, 0)),vicidial_manager_chat_log.user from vicidial_manager_chat_log, vicidial_manager_chats, vicidial_users where vicidial_manager_chat_log.manager='$user' and vicidial_manager_chat_log.manager_chat_id=vicidial_manager_chats.manager_chat_id and vicidial_manager_chat_log.user=vicidial_users.user group by manager_chat_id, manager_chat_subid order by message_viewed_date asc, message_date desc"; $rslt=mysql_to_mysqli($stmt, $link); while ($row=mysqli_fetch_row($rslt)) { if ($row[0]!="") { if (!$priority_chat) {$priority_chat=$row[0];} # The priority_chat is the most recent chat that has not been viewed. if (!$priority_chat_subid) {$priority_chat_subid=$row[1];} # The priority_chat is the most recent chat that has not been viewed. if (!$agent_manager_override) {$agent_manager_override=$row[5];} # The priority_chat is the most recent chat that has not been viewed. array_push($active_chats_array, "$row[0]"); $chat_subid_array[$row[0]]="$row[1]"; // Added back in on 3/3 - why was this removed? $chat_managers_array[$row[0]]="$row[2]"; $chat_start_date_array[$row[0]]="$row[3]"; if ($row[4]>0) {array_push($unread_chats_array, $row[0]);} # Store any chat with unread messages. $agents_managers_array[$row[0]]="$row[5]"; // IS a chat where the agent is a manager } } ######### asort($active_chats_array); asort($chat_managers_array); asort($chat_reload_id_number_array); $ChatReloadIDNumber=""; #while (list($key, $id_number) = each($chat_reload_id_number_array)) { foreach($chat_reload_id_number_array as $key => $id_number) { $ChatReloadIDNumber.="$id_number."; } $ChatReloadIDNumber=substr($ChatReloadIDNumber,0,-1); 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("ADMINISTRATION: Agent/Manager Chat Interface"); ?> "; echo ""; echo "\n"; echo ""; echo ""; echo ""; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; #echo "\n"; #echo "\n"; #echo "\n"; echo "
"._QXZ("Chatting with").":
".$chat_managers_array[$priority_chat]."
"._QXZ("Chat started").":
".$chat_start_date_array[$priority_chat]."
"._QXZ("Your active chats").":
\n"; echo "\t

\n"; echo "\t\n"; echo "
\n"; echo "
\n"; echo "
    "; if (empty($chat_managers_array)) { echo "\t
  • "._QXZ("NO OPEN CHATS")."
  • \n"; } else { # while (list($manager_chat_id, $text) = each($chat_managers_array)) { foreach($chat_managers_array as $manager_chat_id => $text) { $manager_chat_subid=$chat_subid_array[$manager_chat_id]; if (!empty($unread_chats_array) && in_array($manager_chat_id, $unread_chats_array)) {$cclass="unreadchat";} else {$cclass="viewedchat";} echo "\t
  • Chat #".$manager_chat_id."
  • \n"; # $chat_managers_array[$manager_chat_id] $additional_agents_stmt="select concat(manager, selected_agents) as participants from vicidial_manager_chats where manager_chat_id='$manager_chat_id'"; $additional_agents_rslt=mysql_to_mysqli($additional_agents_stmt, $link); $aa_row=mysqli_fetch_row($additional_agents_rslt); $additional_agents=preg_replace("/^\||\|$/", "", $aa_row[0]); $additional_agents=preg_replace("/\|/", "','", $additional_agents); $full_name_stmt="select full_name from vicidial_users where user in ('$additional_agents') and user!='$user' order by full_name asc"; $full_name_rslt=mysql_to_mysqli($full_name_stmt, $link); while ($fname_row=mysqli_fetch_row($full_name_rslt)) { echo "\t
  • ".$fname_row[0]."
  • \n"; } $sid++; } } echo "
\n"; echo "\t
\n"; echo "("._QXZ("bolded chats = unread messages").")
"._QXZ("Mute alert sound")."
\n"; echo "\t
\n"; echo "\t"; echo "\t\n"; echo "
"; echo "
 \n"; #echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; ?>