get("sessions", ["[>]departments" => ["department" => "id"], "[>]buttonstats" => ["session" => "session"], "[>]checkstatus" => ["id" => "convid"], "[>]chatwidget" => ["widgetid" => "id"]], ["sessions.id", "sessions.department", "sessions.operatorid", "sessions.clientid", "sessions.usr_avatar", "sessions.name", "sessions.email", "sessions.country", "sessions.city", "sessions.latitude", "sessions.longitude", "sessions.countrycode", "sessions.lang", "sessions.initiated", "sessions.operatorname", "sessions.credits", "sessions.status", "departments.title(dep_title)", "buttonstats.referrer", "buttonstats.firstreferrer", "buttonstats.agent", "buttonstats.hits", "buttonstats.ip", "checkstatus.files", "chatwidget.title(widget_title)"], ["AND" => ["sessions.id" => $_POST['convid'], "sessions.opid" => $opcacheid]]);
if (isset($row) && !empty($row)) {
// Reset
$showphone = $showemail = $responses = $transferc = $knockknock = $endsess = $usrf = $blockip = '';
// Show standard flag
$usrc = $row['ip'];
// Show country code
if (isset($row['countrycode']) && !empty($row['countrycode']) && $row['countrycode'] != 'xx') $usrc = '
'.$row['ip'];
// Show email
if (filter_var($row['email'], FILTER_VALIDATE_EMAIL)) $showemail = '
'.$row['email'].'
';
// Chat is active
if ($row["status"]) {
// Show files
$usrf = ' '.$jkl['u9'].'';
// Allowed to send files
if ($row['files']) $usrf = ' '.$jkl['u9'].'';
$knockknock = ' '.$jkl['g223'].'';
// Can transfer clients
if ($jakuser->getVar("transferc")) $transferc = ' '.$jkl['g286'].'';
// end session
$endsess = ' '.$jkl['g62'].'';
}
// get the client button
if ($row['clientid'] != 0) {
$isclient = ' '.$jkl['g287'].'';
} else {
$isclient = ' '.$jkl['hd112'].'';
}
// Let's check if the ip is valid
if (filter_var($row["ip"], FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
$blockip = ' '.$jkl['g348'].'';
}
$clientinfo = '';
$clientinfo .= '
';
$clientinfo .= '
'.$usrf.$knockknock.$isclient.$blockip.'
'.$jkl['g181'].' '.$transferc.$endsess.'
';
if (JAK_SHOW_IPS && $row['latitude']) {
$clientinfo .= '
';
}
$clientinfo .= '
';
die(json_encode(array('status' => 1, 'html' => $clientinfo, 'title' => $jkl['g40'], 'icon' => 'info')));
}
die(json_encode(array('status' => 0, 'text' => $jkl['i2'])));
break;
case 'edit':
# code...
$row = $jakdb->get("sessions", ["id", "operatorid", "department", "lang", "name", "email", "phone", "notes"], ["AND" => ["id" => $_POST['convid'], "opid" => $opcacheid]]);
if (isset($row) && !empty($row)) {
// The language list
$allang = "";
foreach(jak_the_lang() as $k => $l) {
$allang .= '';
}
// Get all departments
$alldep = '';
if (isset($HD_DEPARTMENTS) && is_array($HD_DEPARTMENTS)) foreach($HD_DEPARTMENTS as $z) {
$alldep .= '';
}
$editclient = '';
die(json_encode(array('status' => 1, 'html' => $editclient, 'title' => $jkl['g287'], 'icon' => "person")));
}
die(json_encode(array('status' => 0, 'text' => $jkl['i2'])));
break;
case 'search':
# code...
$searchmsg = '';
// Name
$searchmsg .= '
';
$searchmsg .= '
';
$searchmsg .= '';
$searchmsg .= '
';
die(json_encode(array('status' => 1, 'html' => $searchmsg, 'title' => $jkl['s6'], 'icon' => 'search')));
break;
case 'files':
# code...
$result = $jakdb->select("transcript", ["[>]user" => ["operatorid" => "id"], "[>]sessions" => ["convid" => "id"]], ["transcript.id", "transcript.name", "transcript.message", "transcript.operatorid", "transcript.time", "transcript.class", "transcript.quoted", "transcript.edited", "transcript.editoid", "transcript.convid", "user.picture", "sessions.usr_avatar"], ["AND" => ["transcript.convid" => $_POST['convid'], "transcript.class" => "download", "sessions.opid" => $opcacheid], "ORDER" => ["transcript.id" => "ASC"]]);
if (isset($result) && !empty($result)) {
// Get the absolute url for the image
$base_url = str_replace(JAK_OPERATOR_LOC.'/ajax/', '', BASE_URL);
$sharedfiles = '';
foreach ($result as $row) {
// On which class to show a system image
$systemimg = array("bot", "notice", "url", "ended");
$oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.$row["usr_avatar"]);
if ($row["picture"] && $row["operatorid"]) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY.$row["picture"]);
if (in_array($row["class"], $systemimg)) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY."/system.jpg");
// Convert the message into something nice
$message = $row['message'];
$lightbox = "";
// Split message
$splitmsg = explode(":#:", $message);
if (file_exists(CLIENT_UPLOAD_DIR.$splitmsg[0])) {
// Get the file
$theupfile = $base_url.'_showfile.php?i='.jak_encrypt_decrypt($splitmsg[0].':#:'.$splitmsg[1].':#:'.$splitmsg[2]);
// We have an image
if (getimagesize(CLIENT_UPLOAD_DIR.$splitmsg[0])) {
$message = '

';
} else {
$message = '
'.basename($splitmsg[1]).'';
}
} else {
$message = $jkl['i16'];
}
$sharedfiles .= '
';
}
$sharedfiles .= '
';
die(json_encode(array('status' => 1, 'html' => $sharedfiles, 'title' => $jkl['g288'], 'icon' => 'attach_file')));
} else {
// Nothing available
die(json_encode(array('status' => 0, 'text' => $jkl["i3"])));
}
break;
case 'starred':
# code...
$result = $jakdb->select("transcript", ["[>]user" => ["operatorid" => "id"], "[>]sessions" => ["convid" => "id"]], ["transcript.id", "transcript.name", "transcript.message", "transcript.operatorid", "transcript.time", "transcript.class", "transcript.starred", "transcript.quoted", "transcript.edited", "transcript.editoid", "transcript.convid", "user.picture", "sessions.usr_avatar"], ["AND" => ["transcript.convid" => $_POST['convid'], "transcript.starred" => 1, "sessions.opid" => $opcacheid], "ORDER" => ["transcript.id" => "ASC"]]);
if (isset($result) && !empty($result)) {
// include the PHP library (if not autoloaded)
require('../../class/class.emoji.php');
$starredmsg = '';
foreach ($result as $row) {
// On which class to show a system image
$systemimg = array("bot", "notice", "url", "ended", "download");
$oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.$row["usr_avatar"]);
if ($row["picture"] && $row["operatorid"]) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY.$row["picture"]);
if (in_array($row["class"], $systemimg)) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY."/system.jpg");
// We convert the br
$message = nl2br($row['message'], false);
// we have file
if ($row['class'] == "download") {
// Split message
$splitmsg = explode(":#:", $message);
if (file_exists(CLIENT_UPLOAD_DIR.$splitmsg[0])) {
// Get the file
$theupfile = $base_url.'_showfile.php?i='.jak_encrypt_decrypt($splitmsg[0].':#:'.$splitmsg[1].':#:'.$splitmsg[2]);
// We have an image
if (getimagesize(CLIENT_UPLOAD_DIR.$splitmsg[0])) {
$messageemoji = '

';
} else {
$messageemoji = '
'.basename($splitmsg[1]).'';
}
} else {
$messageemoji = $jkl['i16'];
}
} else {
// We convert the urls
$messageemoji = replace_urls($message);
}
// Convert emotji
$messageemoji = Emojione\Emojione::toImage($messageemoji);
// Get the quote msg
$quotemsg = '';
if ($row['quoted']) {
$quotemsg = $jakdb->get("transcript", "message", ["id" => $row["quoted"]]);
// Convert urls
$quotemsg = nl2br(replace_urls($quotemsg), false);
// Convert emotji
$quotemsg = Emojione\Emojione::toImage($quotemsg);
}
$starredmsg .= '
';
}
$starredmsg .= '
';
die(json_encode(array('status' => 1, 'html' => $starredmsg, 'title' => $jkl['g275'], 'icon' => 'star')));
} else {
// Nothing available
die(json_encode(array('status' => 0, 'text' => $jkl["i3"])));
}
break;
case 'faq':
# code...
$faq_url = false;
$department = $jakdb->get("sessions", "department", ["AND" => ["id" => $_POST['convid'], "opid" => $opcacheid, "operatorid" => $_POST['uid']]]);
if ($department) {
foreach ($HD_DEPARTMENTS as $d) {
if (in_array($department, $d)) {
if ($d['faq_url']) $faq_url = $d['faq_url'];
}
}
}
if ($faq_url) {
$loadiframe = '';
die(json_encode(array('status' => 1, 'html' => $loadiframe, 'title' => $jkl['hd1'], 'icon' => 'help_outline')));
}
// Nothing worked cancel
die(json_encode(array('status' => 0, 'text' => $jkl["i2"])));
break;
case 'history':
# code...
$row = $jakdb->get("sessions", ["name", "email"], ["AND" => ["id" => $_POST['convid'], "opid" => $opcacheid]]);
if (isset($row) && !empty($row)) {
$email = '';
if (filter_var($row['email'], FILTER_VALIDATE_EMAIL)) $email = $row['email'];
$oldsessions = $jakdb->select("sessions", ["id", "name", "initiated"], ["OR #c" => ["AND #first" => ["id[!]" => $_POST['convid'], "name" => $row["name"], "opid" => $opcacheid], "AND #second" => ["id[!]" => $_POST['convid'], "email" => $email, "opid" => $opcacheid]], "ORDER" => ["initiated" => "DESC"], "LIMIT" => 5]);
if (isset($oldsessions) && !empty($oldsessions)) {
// include the PHP library (if not autoloaded)
require('../../class/class.emoji.php');
$historymsg = '';
foreach ($oldsessions as $rows) {
$historymsg .= '
'.JAK_base::jakTimesince($rows['initiated'], JAK_DATEFORMAT, JAK_TIMEFORMAT).'
';
$chatmsg = $jakdb->select("transcript", ["[>]user" => ["operatorid" => "id"], "[>]sessions" => ["convid" => "id"]], ["transcript.id", "transcript.name", "transcript.message", "transcript.operatorid", "transcript.time", "transcript.class", "transcript.quoted", "transcript.edited", "transcript.editoid", "transcript.convid", "user.picture", "sessions.usr_avatar"], ["transcript.convid" => $rows['id'], "ORDER" => ["transcript.id" => "ASC"]]);
if (isset($chatmsg) && !empty($chatmsg)) {
foreach ($chatmsg as $z) {
// On which class to show a system image
$systemimg = array("bot", "notice", "url", "ended");
$oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.$z["usr_avatar"]);
if ($z["picture"] && $z["operatorid"]) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY.$z["picture"]);
if (in_array($z["class"], $systemimg)) $oimage = str_replace(JAK_OPERATOR_LOC."/ajax/", "", BASE_URL.JAK_FILES_DIRECTORY."/system.jpg");
// We convert the urls/br
$message = nl2br(replace_urls($z['message']), false);
// Convert emotji
$messageemoji = Emojione\Emojione::toImage($message);
// Get the quote msg
$quotemsg = '';
if ($z['quoted']) {
$quotemsg = $jakdb->get("transcript", "message", ["id" => $z["quoted"]]);
// Convert urls
$quotemsg = nl2br(replace_urls($quotemsg), false);
// Convert emotji
$quotemsg = Emojione\Emojione::toImage($quotemsg);
}
$historymsg .= '
';
}
}
$historymsg .= '
';
}
$historymsg .= '
';
die(json_encode(array('status' => 1, 'html' => $historymsg, 'title' => $jkl['m1'], 'icon' => 'history')));
}
}
// Nothing available
die(json_encode(array('status' => 0, 'text' => $jkl["i3"])));
break;
default:
# code...
// Save client data
if (isset($_POST['edit_customer']) && is_numeric($_POST['convid'])) {
$jkp = $_POST;
$namechange = false;
$username = $jakdb->get("sessions", "name", ["AND" => ["id" => $jkp['convid'], "opid" => $opcacheid]]);
// Filter the new name
$newname = filter_var(jak_input_filter($jkp['name']), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
// Do we have a new name
if (isset($newname) && $newname != $username) $namechange = true;
// Change the name
if ($namechange) $jakdb->update("transcript", ["name" => $newname], ["AND" => ["convid" => $jkp['convid'], "class" => "user"]]);
// Now we have maybe a change in the department
if ($jkp['jak_depid'] != $jkp['olddepid']) {
// Let's figure out the new name from the department
$newdeptitle = $jakdb->get("departments", "title", ["id" => $jkp['jak_depid']]);
// Update the databases
$jakdb->update("checkstatus", ["depid" => $jkp['jak_depid'], "department" => $newdeptitle], ["convid" => $jkp['convid']]);
$jakdb->update("sessions", ["department" => $jkp['jak_depid']], ["AND" => ["id" => $jkp['convid'], "opid" => $opcacheid]]);
// We will run the new name change process
$namechange = true;
}
// Finally we change the rest of the session values
$result = $jakdb->update("sessions", ["lang" => $jkp['jak_lang'], "name" => $newname, "email" => filter_var($jkp['email'], FILTER_SANITIZE_EMAIL), "phone" => filter_var($jkp['phone'], FILTER_SANITIZE_NUMBER_INT), "notes" => filter_var($jkp['note'], FILTER_SANITIZE_FULL_SPECIAL_CHARS)], ["AND" => ["id" => $jkp['convid'], "opid" => $opcacheid]]);
// We can update the status to changed
$jakdb->update("checkstatus", ["datac" => 1], ["convid" => $jkp['convid']]);
if ($result) {
// Ajax Request
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
header('Cache-Control: no-cache');
die(json_encode(array('status' => 1, 'namechange' => $namechange, 'label' => "name")));
}
} else {
// Ajax Request
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
header('Cache-Control: no-cache');
die(json_encode(array('status' => 2, 'txt' => $jkl['i'])));
}
}
}
break;
}
?>