has("user", ["AND" => ["id" => $_POST['opid'], "available" => 1]]);
if (!$oponline) $print_offline = '
'.$jkl["g139"].'
';
$chatmsg = '';
// Load Messages
$resultm = $jakdb->select("operatorchat", ["[>]user" => ["fromid" => "id"]], ["operatorchat.id", "operatorchat.fromid", "operatorchat.message", "operatorchat.system_message", "operatorchat.sent", "user.username", "user.available"], ["AND #check" => ["OR #first" => ["operatorchat.fromid" => $_POST['uid'], "operatorchat.toid" => $_POST['uid']], "OR #second" => ["operatorchat.fromid" => $_POST['opid'], "operatorchat.toid" => $_POST['opid']], "operatorchat.opid" => $opcacheid, "operatorchat.sent[>]" => $sent_time, "operatorchat.msgpublic" => 0], "ORDER" => ["operatorchat.sent" => "ASC"]]);
if (isset($resultm) && !empty($resultm)) {
foreach ($resultm as $rowm) {
//print messages
if ($rowm['system_message'] != 'no') {
$chatmsg .= ''.$rowm['message'].'
';
} elseif ($rowm['fromid'] != $_POST['uid']) {
$chatmsg .= ''.$rowm['username'].' '.date("H:i", $rowm['sent']).'
'.$rowm['message'].'
';
} else {
$chatmsg .= ''.$jkl["g140"].' '.date("H:i", $rowm['sent']).'
'.$rowm['message'].'
';
}
$last_msg = $rowm['sent'];
}
//print last message time if older than 2 mins
$math = time() - $last_msg;
if ($math > 120) {
$chatmsg .= ''.str_replace("%s", date("H:i", $last_msg), $jkl["g141"]).'
';
}
if ($rowm["available"] == 0) {
$chatmsg .= $print_offline;
}
} else {
$chatmsg .= $print_offline;
}
$chatmsg .= '
';
echo $chatmsg;
}
break;
case 'send-msg':
if (empty($_POST['message'])) {
echo $jkl['e1'];
} else {
$message = trim($_POST['message']);
$message = filter_var($message, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$jakdb->insert("operatorchat", ["opid" => $opcacheid, "fromid" => $_POST['uid'], "toid" => $_POST['opid'], "message" => $message, "sent" => time()]);
$lastid = $jakdb->id();
if ($lastid) {
// 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)) {
unlink($chatsfile);
}
// Write the from to operator id
$opid = time().":#:".$_POST['uid'].":#:".$_POST['opid'].":#:".$_POST['uname']."\n";
// Create, write or append to the file.
file_put_contents($chatsfile, $opid, FILE_APPEND);
echo 'success';
} else {
echo $jkl['e1'];
}
}
break;
default:
return false;
}