(time() - 10)) { $nopid[] = $opid[1].":#:".$opid[3]; } else { $nopid = false; } } // If we have forward the new window array if (is_array($nopid)) { die(json_encode(array("startcalling" => true, "win" => $nopid))); } else { // Nothing to do, keep idle. die(json_encode(array("startcalling" => false))); } } else { // Nothing to do, keep idle. die(json_encode(array("startcalling" => false))); } } if (!is_numeric($_POST['uid'])) die("There is no such thing!"); // 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'); } $sent_time = time() - OPERATOR_CHAT_EXPIRE; $print_offline = ''; switch ($_POST['page']) { case 'load-msg': // Check if the Operater is still available $available = $jakdb->has("user", ["AND" => ["id" => $_POST['partner_id'], "available" => 1]]); if (!$available) { $print_offline = '
  • '.$jkl["g139"].'
  • '; } // A few vars $unreadmsg = false; $chatmsg = ""; // Load messages $resultu = $jakdb->select("operatorchat", "*", ["AND #check" => ["OR #first" => ["fromid" => $_POST['uid'], "toid" => $_POST['uid']], "OR #second" => ["operatorchat.fromid" => $_POST['opid'], "operatorchat.toid" => $_POST['opid']], "opid" => $opcacheid, "sent[>]" => $sent_time, "msgpublic" => 0], "ORDER" => ["sent" => "ASC"]]); if (isset($resultu) && !empty($resultu)) { foreach ($resultu as $rowu) { // check if current user has unreceived messages which are older than limit, if yes, display it with date if ($rowu["sent"] < $sent_time AND $rowu["received"] == 0) { $updatesqla .= sprintf("WHEN %d THEN '%s' ", $rowu['id'], time()); $updatesqla1 .= sprintf("WHEN %d THEN '%s' ", $rowu['id'], 1); $alloid[] = $rowu['id']; $unreadmsg = true; } // Load Messages if (($rowu["fromid"] == $_POST['uid'] && $rowu["toid"] == $_POST['partner_id']) || ($rowu["fromid"] == $_POST['partner_id'] && $rowu["toid"] == $_POST['uid'])) { //print messages if ($rowu['system_message'] != 'no') { $chatmsg .= '
  • '. stripcslashes($rowu['message']).'
  • '; } elseif ($rowu['fromid'] != $_POST['uid']) { $chatmsg .= '
  • '.$rowu['message'].'
  • '; } else { $chatmsg .= '
  • '.$rowu['message'].'
  • '; } // If message has been received mark it! if ($rowu['toid'] == $_POST['uid']) { $jakdb->update("operatorchat", ["received" => 1], ["AND" => ["id" => $rowu['id'], "opid" => $opcacheid, "received" => 0]]); } $last_msg = $rowu['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"]).'
  • '; } $chatmsg .= $print_offline; // Let's update the unread messages if ($unreadmsg && is_array($alloid)) { $realid = implode(',', $alloid); // Update in one query $jakdb->query('UPDATE '.DB_PREFIX.'operatorchat SET received = CASE id '.$updatesqla.' END, sent = CASE id '.$updatesqla1.' END WHERE id IN ('.$realid.') AND "opid" = '.$opcacheid); } die(json_encode(array("status" => true, "msg" => ''))); } else { die(json_encode(array("status" => false))); } 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['to_id'], "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['to_id'].":#:".$_POST['uname']."\n"; // Create, write or append to the file. file_put_contents($chatsfile, $opid, FILE_APPEND); die(json_encode(array("status" => true, "txt" => '
  • '.$message.'
  • '))); } else { die(json_encode(array("status" => false))); } } break; default: return false; }