Jakweb.ch stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

417 lines
22 KiB

<?php
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 6 May 1998 03:10:00 GMT");
/*===============================================*\
|| ############################################# ||
|| # JAKWEB.CH / Version 2.1.2 # ||
|| # ----------------------------------------- # ||
|| # Copyright 2023 JAKWEB All Rights Reserved # ||
|| ############################################# ||
\*===============================================*/
if (!file_exists('../../config.php')) die('ajax/[usronline.php] config.php not exist');
require_once '../../config.php';
if (!isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !isset($_SESSION['jak_lcp_idhash'])) die("Nothing to see here");
// Import the user or standard language file
if (isset($_SESSION['jak_lcp_lang']) && file_exists(APP_PATH.JAK_OPERATOR_LOC.'/lang/'.$_SESSION['jak_lcp_lang'].'.php')) {
include_once(APP_PATH.JAK_OPERATOR_LOC.'/lang/'.$_SESSION['jak_lcp_lang'].'.php');
} else {
include_once(APP_PATH.JAK_OPERATOR_LOC.'/lang/'.JAK_LANG.'.php');
}
// Get the current time
$currentime = time();
if (jak_get_access("leads", $jakuser->getVar("permissions"), JAK_MAIN_OP) && !is_numeric($_GET['uid'])) die("There is no such thing!");
$useronline = '';
$useronlinemap = array();
$userocount = 0;
if (isset($_GET['uonline']) && $_GET['uonline']) {
// 5 Minutes ago
$mino = date('Y-m-d H:i:s',$currentime - 5 * 60);
// Now only get the department for the user
if (isset($_SESSION['usr_department']) && is_numeric($_SESSION['usr_department']) && $_SESSION['usr_department'] != 0) {
$result = $jakdb->select("buttonstats", ["[>]sessions" => ["session" => "session"]], ["buttonstats.id", "buttonstats.referrer", "buttonstats.firstreferrer", "buttonstats.agent", "buttonstats.hits", "buttonstats.ip", "buttonstats.country", "buttonstats.countrycode", "buttonstats.latitude", "buttonstats.longitude", "buttonstats.lasttime", "buttonstats.time", "buttonstats.readtime", "sessions.initiated", "sessions.ended"], ["AND" => ["buttonstats.opid" => $opcacheid, "buttonstats.singleopid" => [0,$_GET['uid']], "buttonstats.depid" => [0,$_SESSION['usr_department']], "buttonstats.lasttime[>]" => $mino], "GROUP" => "buttonstats.session", "ORDER" => ["buttonstats.lasttime" => "DESC"], "LIMIT" => 50]);
} elseif (isset($_SESSION['usr_department']) && $_SESSION['usr_department'] == 0) {
$result = $jakdb->select("buttonstats", ["[>]sessions" => ["session" => "session"]], ["buttonstats.id", "buttonstats.referrer", "buttonstats.firstreferrer", "buttonstats.agent", "buttonstats.hits", "buttonstats.ip", "buttonstats.country", "buttonstats.countrycode", "buttonstats.latitude", "buttonstats.longitude", "buttonstats.lasttime", "buttonstats.time", "buttonstats.readtime", "sessions.initiated", "sessions.ended"], ["AND" => ["buttonstats.opid" => $opcacheid, "buttonstats.singleopid" => [0,$_GET['uid']], "#buttonstats.lasttime[>]" => $mino], "GROUP" => "buttonstats.session", "ORDER" => ["buttonstats.lasttime" => "DESC"], "LIMIT" => 50]);
} elseif (isset($_SESSION['usr_department'])) {
$result = $jakdb->select("buttonstats", ["[>]sessions" => ["session" => "session"]], ["buttonstats.id", "buttonstats.referrer", "buttonstats.firstreferrer", "buttonstats.agent", "buttonstats.hits", "buttonstats.ip", "buttonstats.country", "buttonstats.countrycode", "buttonstats.latitude", "buttonstats.longitude", "buttonstats.lasttime", "buttonstats.time", "buttonstats.readtime", "sessions.initiated", "sessions.ended"], ["AND" => ["buttonstats.opid" => $opcacheid, "buttonstats.singleopid" => [0,$_GET['uid']], "buttonstats.depid" => explode(",",$_SESSION['usr_department'].',0'), "buttonstats.lasttime[>]" => $mino], "GROUP" => "buttonstats.session", "ORDER" => ["buttonstats.lasttime" => "DESC"], "LIMIT" => 50]);
}
if (isset($result) && !empty($result)) {
$useronline = '<div class="table-responsive"><table class="table table-striped"><th>'.$jkl["g224"].'</th><th>'.$jkl["g169"].'</th><th>'.$jkl["g171"].'</th><th>'.$jkl["g172"].'</th><th>'.$jkl["g11"].'</th><th>'.$jkl["g173"].'</th><th>'.$jkl["g174"].'</th><th></th>';
foreach ($result as $row) {
// Convert time to minutes and hours
$row['lasttime'] = JAK_base::jakTimesince($row['lasttime'], JAK_DATEFORMAT, JAK_TIMEFORMAT);
$row['time'] = JAK_base::jakTimesince($row['time'], JAK_DATEFORMAT, JAK_TIMEFORMAT);
$uclass = '';
$button = '<a href="javascript:void(0)" id="usero-'.$row['id'].'" class="btn btn-secondary btn-sm jakweb-online-user"><i class="fa fa-user"></i></a>';
if ($row['readtime'] == 1) $uclass = ' class="table-warning"';
if ($row['readtime'] == 2) $uclass = ' class="table-success"';
if ($row['readtime'] == 3) $uclass = ' class="table-danger"';
if ($row['readtime'] >= 2) $button = '<a href="javascript:void(0)" class="btn btn-info btn-sm"><i class="fa fa-bell"></i></a>';
if ($row['initiated'] && $row['ended'] == 0) $button = '<a href="javascript:void(0)" class="btn btn-info btn-sm"><i class="fa fa-comment"></i></a>';
$useronline .= '<tr'.$uclass.'><td><img src="'.str_replace("ajax/", "", BASE_URL."img/blank.png").'" class="flag-big flag-'.$row['countrycode'].'" title="'.$row['country'].'" alt="'.$row['country'].'"></td><td><strong>'.$jkl["g169"].':</strong> '.$row['referrer'].'<br><strong>'.$jkl["g170"].':</strong> '.$row['firstreferrer'].'</td><td>'.$row['agent'].'</td><td>'.$row['hits'].'</td><td>'.$row['ip'].'</td><td>'.$row['time'].'</td><td>'.$row['lasttime'].'</td><td>'.$button.'</td></tr>';
// Get the map thing
if (JAK_SHOW_IPS && $row['latitude']) {
$popupd = '<div class="row"><div class="col-2"><a href="javascript:void(0)" id="usero-'.$row['id'].'" class="jakweb-online-user"><img src="'.str_replace("ajax/", "", BASE_URL."img/blank.png").'" class="flag-big flag-'.$row['countrycode'].'" title="'.$row['country'].'" alt="'.$row['country'].'"></a></div><div class="col-10">'.$jkl["g169"].': '.$row['referrer'].'</div></div>';
$useronlinemap[] = array('id' => 'm_'.$row['id'], 'lat' => $row['latitude'], 'lng' => $row['longitude'], 'popup' => $popupd);
}
$userocount++;
}
$useronline .= '</table></div>';
}
}
// We check if we have access to the operator chat and the operator list
$oponline = false;
$countop = 0;
$openop = "";
$newopmsg = "default";
if (isset($_GET['olist']) && $_GET['olist']) {
$resop = $jakdb->select("user", ["id", "username", "name", "operatorchat"], ["AND" => ["OR" => ["opid" => $opcacheid, "id" => $opcacheid], "available" => 1, "id[!]" => $_GET['uid']], "LIMIT" => 20]);
if (isset($resop) && !empty($resop)) {
$oponline = '<ul class="list-group">';
foreach ($resop as $row) {
if ($jakosub['operatorchat']) {
if (!JAK_OPENOP) {
// Pop up Window
if ($row['operatorchat']) $openop = ' <a href="javascript:void(0)" class="btn btn-info btn-sm jakweb-oponline" data-user="'.$row['id'].':#:'.$row['username'].'"><i class="fa fa-user"></i></a>';
} else {
// Slide Up Window
// Now let us add the active chat file so the operator can come online.
$chatsfile = APP_PATH.JAK_CACHE_DIRECTORY.'/chats'.$opcacheid.'.txt';
if (file_exists($chatsfile)) {
$trimmed = file($chatsfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($trimmed as $v) {
$opid = explode(":#:", $v);
// Check if we have a chat request
if ($row['operatorchat'] && $opid[2] == $_GET['uid'] && $opid[0] > ($currentime - 120)) {
$newopmsg = 'primary';
$countops++;
}
}
}
if ($row['operatorchat']) {
$openchat = " onclick=\"if(navigator.userAgent.toLowerCase().indexOf('opera') != -1 && window.event.preventDefault) window.event.preventDefault();this.newWindow = window.open('".str_replace('ajax/', '', JAK_rewrite::jakParseurl('chat', $_GET['uid'], $row['id']))."', 'lsr', 'toolbar=0,scrollbars=1,location=0,status=1,menubar=0,width=600,height=520,resizable=1');this.newWindow.focus();this.newWindow.opener=window;return false;\"";
$openop = '<a href="javascript:void(0)"'.$openchat.' class="btn btn-'.$newopmsg.'" data-user="'.$row['id'].':#:'.$row['username'].'"><i class="fa fa-user"></i></a>';
}
}
}
$oponline .= '<li class="list-group-item">'.$row['name'].' <div class="btn-group btn-group-sm"><a href="'.str_replace('ajax/', '', JAK_rewrite::jakParseurl('uonline', 'opstat', $row['id'])).'" data-toggle="modal" data-target="#jakModal" class="btn btn-info"><i class="fa fa-chart-bar"></i></a>'.$openop.'</div></li>';
$countop = $countop + 1;
}
$oponline .= '</ul>';
}
}
// Reset vars
$transfer_msg = $jsmsg = $newclient = $soundjs = $cname = $newmsg = $newtitle = $soundmsgjs = '';
$newConv = $transferid = $sendalert = 0;
$loadClients = false;
$convid = $answers = $typing = array();
$resnew = $jakdb->select("checkstatus", ["convid", "depid", "operatorid", "operator", "newo", "transferoid", "transferid", "typec", "alert", "statusc", "initiated"], ["AND" => ["opid" => $opcacheid, "hide" => 0, "denied" => 0]]);
if (isset($resnew) && !empty($resnew)) {
foreach ($resnew as $row) {
// We have a dead client connection cancel it.
if ($row['statusc'] && (($currentime - $row['statusc']) > JAK_CLIENT_LEFT)) {
$jakdb->update("sessions", ["status" => 0, "ended" => $currentime], ["id" => $row['convid']]);
$jakdb->update("checkstatus", ["hide" => 1], ["convid" => $row['convid']]);
$cname = $jakdb->get("sessions", "name", ["id" => $row['convid']]);
$jakdb->insert("transcript", [
"name" => $jkl['g274'],
"message" => sprintf($jkl['g168'], $cname),
"convid" => $row['convid'],
"class" => "notice",
"plevel" => 2,
"time" => $jakdb->raw("NOW()")]);
break;
}
// The client is expired
if ($row['statusc'] && (($currentime - $row['statusc']) > JAK_CLIENT_EXPIRED)) {
$jakdb->update("sessions", ["status" => 0, "ended" => $currentime], ["id" => $row['convid']]);
$jakdb->update("checkstatus", ["hide" => 1], ["convid" => $row['convid']]);
$jakdb->insert("transcript", [
"name" => $jkl['g274'],
"message" => $jkl['g72'],
"convid" => $row['convid'],
"class" => "notice",
"time" => $jakdb->raw("NOW()")]);
break;
}
// We have a transfer, need to display it!
if ($row['transferoid'] == $_GET['uid']) {
$trow = $jakdb->get("transfer", ["fromname", "message"], ["AND" => ["tooid" => $_GET['uid'], "convid" => $row['convid'], "used" => 0]]);
if (isset($trow) && !empty($trow)) {
// Display underneath the button
$transfer_msg = '<div class="alert alert-secondary"><h3 class="transfer-chat">'.sprintf($jkl['g110'], $trow["fromname"]).'</h3><p>'.$trow["message"].'</p><div class="transfer-btn"><a href="javascript:void(0)" class="btn btn-sm btn-danger" onclick="acceptTransfer(0, '.$row['transferoid'].', '.$row['convid'].');"><i class="fa fa-times"></i></a><a href="javascript:void(0)" class="btn btn-sm btn-success" onclick="acceptTransfer(1, '.$row['transferoid'].', '.$row['convid'].');"><i class="fa fa-check"></i></a></div></div>';
$transferid = $row['transferid'];
$jsmsg = sprintf($jkl['g110'], $trow["fromname"]);
$soundjs = JAK_RING_TONE;
}
}
// Only load if we are in the correct department
if (isset($_SESSION['usr_department']) && ($_SESSION['usr_department'] == 0 || $row["depid"] == $_SESSION['usr_department'] || in_array($row["depid"], explode(",", $_SESSION['usr_department'])) || $row["operatorid"] == $_GET['uid'])) {
// check for new conversations
if ($row['operatorid'] == 0 || ($row['operatorid'] == $_GET['uid'] && empty($row['operator']))) {
$newConv = 1;
if ($row["alert"] == 0) {
$jakdb->update("checkstatus", ["alert" => 1], ["convid" => $row['convid']]);
$sendalert = 1;
}
$newclient = $jkl['g69'];
$soundjs = JAK_RING_TONE;
if ($row['typec']) $typing[] = $row['convid'];
$convid[] = $row["convid"];
$loadClients = true;
}
if ($row['operatorid'] == $_GET['uid'] && !empty($row['operator'])) {
$jakdb->update("checkstatus", ["statuso" => $currentime], ["convid" => $row['convid']]);
if ($row['typec']) $typing[] = $row['convid'];
$convid[] = $row["convid"];
$loadClients = true;
}
if ($row['operatorid'] == $_GET['uid'] && $row['newo']) {
$msginfo = $jakdb->get("transcript", ["name", "message"], ["id" => $row['newo']]);
$newConv = 2;
$cname = $msginfo["name"];
$newmsg = $msginfo["message"];
$newtitle = $jkl['g70'];
$soundmsgjs = JAK_MSG_TONE;
$answers[] = $row['convid'];
if ($row['typec']) $typing[] = $row['convid'];
$convid[] = $row["convid"];
$loadClients = true;
}
}
}
}
// Reset convlist
$convlist = '';
// Now let's get the conversation list
$new = $updated = $current = array();
$count = 0;
// Only go for it if we want to
if ($loadClients) {
// Check if there is a new client, message or a transfer is awaiting for approval.
$resconv = $jakdb->select("sessions", ["[>]buttonstats" => ["session" => "session"]], ["sessions.id", "sessions.name", "sessions.operatorname", "sessions.countrycode", "sessions.status", "sessions.ended", "buttonstats.referrer"], ["sessions.id" => $convid]);
if (isset($resconv) && !empty($resconv)) {
foreach ($resconv as $row) {
if ($row['status']) {
// Get all available chats
if ($row['operatorname'] == "") {
$new[$count]["name"] = $row['name'];
$new[$count]["convid"] = $row['id'];
$new[$count]["countrycode"] = $row['countrycode'];
$new[$count]["referrer"] = $row['referrer'];
$new[$count]["typing"] = false;
if (!empty($typing) && in_array($row['id'], $typing)) $new[$count]["typing"] = true;
} elseif (!empty($answers) && $row['operatorname'] && in_array($row['id'], $answers)) {
$updated[$count]["name"] = $row['name'];
$updated[$count]["convid"] = $row['id'];
$updated[$count]["countrycode"] = $row['countrycode'];
$updated[$count]["referrer"] = $row['referrer'];
$updated[$count]["typing"] = false;
if (!empty($typing) && in_array($row['id'], $typing)) $updated[$count]["typing"] = true;
} else {
$current[$count]["name"] = $row['name'];
$current[$count]["convid"] = $row['id'];
$current[$count]["countrycode"] = $row['countrycode'];
$current[$count]["referrer"] = $row['referrer'];
$current[$count]["typing"] = false;
if (!empty($typing) && in_array($row['id'], $typing)) $current[$count]["typing"] = true;
}
}
if (!$row['status']) {
if ((($currentime - $row['ended']) > 300)) {
$jakdb->update("checkstatus", ["hide" => 1], ["convid" => $row['id']]);
$jakdb->insert("transcript", [
"name" => $jkl['g274'],
"message" => $jkl['g73'],
"convid" => $row['id'],
"class" => "notice",
"plevel" => 2,
"time" => $jakdb->raw("NOW()")]);
}
}
$count = $count + 1;
}
shuffle($new);
shuffle($updated);
shuffle($current);
sort($new);
sort($updated);
sort($current);
$newTotal = count($new);
$updatedTotal = count($updated);
$currentTotal = count($current);
for($i = 0; $i < $newTotal; $i ++ ) {
$convlist .= '<a href="'.str_replace('ajax/', '', JAK_rewrite::jakParseurl('live', $new[$i]["convid"])).'" class="dropdown-item a-confirm-chat" data-convid="'.$new[$i]["convid"].'" data-opid="'.$_GET['uid'].'" data-title="'.addslashes($jkl["g108"]).'" data-type="info" data-okbtn="'.addslashes($jkl["g283"]).'" data-cbtn="'.addslashes($jkl["g203"]).'">'.(isset($new[$i]['countrycode']) && !empty($new[$i]['countrycode'] && $new[$i]['countrycode'] != 'xx') ? '<img src="'.str_replace("ajax/", "", BASE_URL."img/blank.png").'" class="flag flag-'.$new[$i]['countrycode'].'"> ' : '').$new[$i]["name"].'<br>'.$new[$i]["referrer"].'&nbsp;<i class="material-icons">fiber_new</i></a>';
}
for($i = 0; $i < $updatedTotal; $i ++ ) {
$convlist .= '<a href="'.str_replace('ajax/', '', JAK_rewrite::jakParseurl('live', $updated[$i]["convid"])).'" class="dropdown-item">'.(isset($updated[$i]['countrycode']) && !empty($updated[$i]['countrycode'] && $updated[$i]['countrycode'] != 'xx') ? '<img src="'.str_replace("ajax/", "", BASE_URL."img/blank.png").'" class="flag flag-'.$updated[$i]['countrycode'].'"> ' : '').$updated[$i]["name"].'<br>'.$updated[$i]["referrer"].'&nbsp;<span class="badge badge-'.($updated[$i]["typing"] ? 'success' : 'secondary').'">...</span></a>';
}
for($i = 0; $i < $currentTotal; $i ++ ) {
$convlist .= '<a href="'.str_replace('ajax/', '', JAK_rewrite::jakParseurl('live', $current[$i]["convid"])).'" class="dropdown-item"> '.(isset($current[$i]['countrycode']) && !empty($current[$i]['countrycode'] && $current[$i]['countrycode'] != 'xx') ? '<img src="'.str_replace("ajax/", "", BASE_URL."img/blank.png").'" class="flag flag-'.$current[$i]['countrycode'].'"> ' : '').$current[$i]["name"].'<br>'.$current[$i]["referrer"].'&nbsp;<span class="badge badge-'.($current[$i]["typing"] ? 'success' : 'secondary').'">...</span></a>';
}
}
}
// Is the site we are on active or already expired
$activeconv = false;
if (is_array($convid) && in_array($_GET['activconv'], $convid)) $activeconv = true;
// Let us check the live preview file
$prevmsgonly = "";
$prevtxt = false;
if (isset($_GET['activconv']) && is_numeric($_GET['activconv']) && $activeconv) {
// Check the file from the cache directory
$livepreviewfile = APP_PATH.JAK_CACHE_DIRECTORY.'/livepreview'.$_GET['activconv'].'.txt';
if (file_exists($livepreviewfile)) {
$prev = $jakdb->get("sessions", ["name", "usr_avatar", "department"], ["id" => $_GET['activconv']]);
// Get the absolute url for the image
$ava_url = str_replace(JAK_OPERATOR_LOC.'/ajax/', '', BASE_URL);
$prevmsg = file_get_contents($livepreviewfile);
// We convert the br
$prevmsg = nl2br($prevmsg, false);
$prevtxt = '<div id="prevcontainer_'.$_GET['activconv'].'"><div class="media livepreview">
<img class="d-flex mr-3 img-thumbnail" src="'.$ava_url.$prev["usr_avatar"].'" width="53" height="53" alt="live preview">
<div class="media-body">
<h4 class="media-heading">'.$prev['name'].' <i class="fa fa-pencil"></i> <small>'.JAK_base::jakTimesince($currentime, "", JAK_TIMEFORMAT).'</small></h4>
<div class="media-text" id="prevmsg_'.$_GET['activconv'].'">'.stripcslashes($prevmsg).'</div>
</div>
</div>
<hr></div>';
$prevmsgonly = stripcslashes($prevmsg);
}
}
// Now get the new tickets that are not solved yet.
$tcount = 0;
$sup_tickets = array();
$utickets = "";
if (jak_get_access("support", $jakuser->getVar("permissions"), JAK_MAIN_OP)) {
// Now only get the department for the user
if (is_numeric($jakuser->getVar("support_dep")) && $jakuser->getVar("support_dep") != 0) {
$sup_tickets = $jakdb->select("support_tickets", ["[>]support_departments" => ["depid" => "id"]], ["support_tickets.id", "support_tickets.subject", "support_tickets.updated"], ["AND" => ["OR" => ["support_tickets.operatorid" => $jakuser->getVar("id"), "support_tickets.depid" => $jakuser->getVar("support_dep")], "support_tickets.opid" => $opcacheid, "support_tickets.status" => 1], "ORDER" => ["support_tickets.updated" => "DESC"], "LIMIT" => 10]);
} elseif (!((boolean)$jakuser->getVar("support_dep")) && $jakuser->getVar("support_dep") != 0) {
$sup_tickets = $jakdb->select("support_tickets", ["[>]support_departments" => ["depid" => "id"]], ["support_tickets.id", "support_tickets.subject", "support_tickets.updated"], ["AND" => ["OR" => ["support_tickets.operatorid" => $jakuser->getVar("id"), "support_tickets.depid" => [$jakuser->getVar("support_dep")]], "support_tickets.opid" => $opcacheid, "support_tickets.status" => 1], "ORDER" => ["support_tickets.updated" => "DESC"], "LIMIT" => 10]);
} else {
$sup_tickets = $jakdb->select("support_tickets", ["[>]support_departments" => ["depid" => "id"]], ["support_tickets.id", "support_tickets.subject", "support_tickets.updated"], ["AND" => ["support_tickets.opid" => $opcacheid, "support_tickets.status" => 1], "ORDER" => ["support_tickets.updated" => "DESC"], "LIMIT" => 10]);
}
if (isset($sup_tickets) && !empty($sup_tickets)) {
foreach ($sup_tickets as $ti) {
$utickets .= '<a href="'.str_replace('ajax/', '', JAK_rewrite::jakParseurl('support', 'read', $ti["id"])).'" class="dropdown-item">'.$ti["subject"].'&nbsp;<span class="badge badge-secondary">'.JAK_base::jakTimesince($ti["updated"], JAK_DATEFORMAT, JAK_TIMEFORMAT).'</span></a>';
$tcount = $tcount + 1;
}
}
}
die(json_encode(array("useronline" => $useronline, "useronlinemap" => $useronlinemap, "totalonline" => $userocount, "nouseronline" => $jkl['i3'], "oponline" => $oponline, 'newc' => $newConv, 'tid' => $transferid, 'tmsg' => $transfer_msg, 'jsmsg' => $jsmsg, 'newclient' => $newclient, 'soundjs' => $soundjs, 'soundalert' => $sendalert, 'cname' => $cname, 'newmsg' => $newmsg, 'newtitle' => $newtitle, 'soundmsgjs' => $soundmsgjs, "conversation" => $convlist, "tickets" => $utickets, "noconv" => $jkl['g79'], 'totalchats' => $count, 'totaltickets' => $tcount, 'totalops' => $countop, 'previewmsg' => $prevtxt, 'prevmsgonly' => $prevmsgonly)));
?>