Ent 5701 quitar feature de chat
This commit is contained in:
parent
b655094f3a
commit
1f16abd4bd
|
@ -1 +1,6 @@
|
|||
operation/servers/recon_view.php
|
||||
operation/servers/recon_view.php
|
||||
operation/users/webchat.php
|
||||
include/javascript/webchat.js
|
||||
attachment/pandora_chat.log.json.txt
|
||||
attachment/pandora_chat.user_list.json.txt
|
||||
attachment/pandora_chat.global_counter.txt
|
|
@ -81,13 +81,6 @@ if ($config['menu_type'] == 'classic') {
|
|||
}
|
||||
|
||||
|
||||
// Chat messages.
|
||||
$header_chat = "<div id='header_chat'><span id='icon_new_messages_chat' style='display: none;'>";
|
||||
$header_chat .= "<a href='index.php?sec=workspace&sec2=operation/users/webchat'>";
|
||||
$header_chat .= html_print_image('images/header_chat_gray.png', true, ['title' => __('New chat message')]);
|
||||
$header_chat .= '</a></span></div>';
|
||||
|
||||
|
||||
// Search.
|
||||
$acl_head_search = true;
|
||||
if ($config['acl_enterprise'] == 1 && !users_is_admin()) {
|
||||
|
@ -417,7 +410,7 @@ if ($config['menu_type'] == 'classic') {
|
|||
|
||||
echo '<div class="header_left"><span class="header_title">'.$config['custom_title_header'].'</span><span class="header_subtitle">'.$config['custom_subtitle_header'].'</span></div>
|
||||
<div class="header_center">'.$header_searchbar.'</div>
|
||||
<div class="header_right">'.$header_chat, $header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'</div>';
|
||||
<div class="header_right">'.$header_autorefresh, $header_autorefresh_counter, $header_discovery, $servers_list, $header_feedback, $header_support, $header_docu, $header_user, $header_logout.'</div>';
|
||||
?>
|
||||
</div> <!-- Closes #table_header_inner -->
|
||||
</div> <!-- Closes #table_header -->
|
||||
|
@ -640,8 +633,6 @@ if ($config['menu_type'] == 'classic') {
|
|||
|
||||
var fixed_header = <?php echo json_encode((bool) $config_fixed_header); ?>;
|
||||
|
||||
var new_chat = <?php echo (int) $_SESSION['new_chat']; ?>;
|
||||
|
||||
function showinterpreter(){
|
||||
|
||||
document.onclick = function(e) {
|
||||
|
@ -789,9 +780,7 @@ if ($config['menu_type'] == 'classic') {
|
|||
$('div#head').addClass('fixed_header');
|
||||
$('div#main').css('padding-top', $('div#head').innerHeight() + 'px');
|
||||
}
|
||||
|
||||
check_new_chats_icon('icon_new_messages_chat');
|
||||
|
||||
|
||||
/* Temporal fix to hide graphics when ui_dialog are displayed */
|
||||
$("#yougotalert").click(function () {
|
||||
$("#agent_access").css("display", "none");
|
||||
|
|
|
@ -160,8 +160,6 @@ if (isset($_GET['user_del'])) {
|
|||
$result = delete_user($id_user);
|
||||
|
||||
if ($result) {
|
||||
users_save_logout($user_row, true);
|
||||
|
||||
db_pandora_audit(
|
||||
'User management',
|
||||
__('Deleted user %s', io_safe_input($id_user))
|
||||
|
|
|
@ -1908,8 +1908,6 @@ function ui_process_page_head($string, $bitfield)
|
|||
);
|
||||
// Load base64 javascript library.
|
||||
$config['js']['base64'] = 'include/javascript/encode_decode_base64.js';
|
||||
// Load webchat javascript library.
|
||||
$config['js']['webchat'] = 'include/javascript/webchat.js';
|
||||
// Load qrcode library.
|
||||
$config['js']['qrcode'] = 'include/javascript/qrcode.js';
|
||||
// Load intro.js library (for bubbles and clippy).
|
||||
|
|
|
@ -497,508 +497,6 @@ function users_get_user_by_id($id_user)
|
|||
}
|
||||
|
||||
|
||||
define('MAX_TIMES', 10);
|
||||
|
||||
//
|
||||
// WEBCHAT FUNCTIONS/////////////////////////////////
|
||||
//
|
||||
function users_get_last_messages($last_time=false)
|
||||
{
|
||||
$file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt';
|
||||
|
||||
// First lock the file
|
||||
$fp_global_counter = @fopen($file_global_counter_chat, 'a+');
|
||||
if ($fp_global_counter === false) {
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
while (!flock($fp_global_counter, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
fscanf($fp_global_counter, '%d', $global_counter_file);
|
||||
if (empty($global_counter_file)) {
|
||||
$global_counter_file = 0;
|
||||
}
|
||||
|
||||
$timestamp = time();
|
||||
if ($last_time === false) {
|
||||
$last_time = (24 * 60 * 60);
|
||||
}
|
||||
|
||||
$from = ($timestamp - $last_time);
|
||||
|
||||
$log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt';
|
||||
|
||||
$return = [
|
||||
'correct' => false,
|
||||
'log' => [],
|
||||
];
|
||||
|
||||
if (!file_exists($log_chat_file)) {
|
||||
touch($log_chat_file);
|
||||
}
|
||||
|
||||
$text_encode = @file_get_contents($log_chat_file);
|
||||
$log = json_decode($text_encode, true);
|
||||
|
||||
if ($log !== false) {
|
||||
if ($log === null) {
|
||||
$log = [];
|
||||
}
|
||||
|
||||
$log_last_time = [];
|
||||
foreach ($log as $message) {
|
||||
if ($message['timestamp'] >= $from) {
|
||||
$log_last_time[] = $message;
|
||||
}
|
||||
}
|
||||
|
||||
$return['correct'] = true;
|
||||
$return['log'] = $log_last_time;
|
||||
$return['global_counter'] = $global_counter_file;
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
|
||||
fclose($fp_global_counter);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
function users_save_login()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt';
|
||||
|
||||
$user = db_get_row_filter(
|
||||
'tusuario',
|
||||
['id_user' => $config['id_user']]
|
||||
);
|
||||
|
||||
$message = sprintf(
|
||||
__('User %s login at %s'),
|
||||
$user['fullname'],
|
||||
date($config['date_format'])
|
||||
);
|
||||
users_save_text_message($message, 'notification');
|
||||
|
||||
// First lock the file
|
||||
$fp_user_list = @fopen($file_global_user_list, 'a+');
|
||||
if ($fp_user_list === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
while (!flock($fp_user_list, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
return;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
@fscanf($fp_user_list, "%[^\n]", $user_list_json);
|
||||
|
||||
$user_list = json_decode($user_list_json, true);
|
||||
if (empty($user_list)) {
|
||||
$user_list[$config['id_user']] = [
|
||||
'name' => $user['fullname'],
|
||||
'count' => 1,
|
||||
];
|
||||
} else if (isset($user_list[$config['id_user']])) {
|
||||
$user_list[$config['id_user']] = [
|
||||
'name' => $user['fullname'],
|
||||
'count' => $user_list[$config['id_user']]['count'],
|
||||
];
|
||||
} else {
|
||||
$users_count = count($user_list);
|
||||
$user_list[$config['id_user']] = [
|
||||
'name' => $user['fullname'],
|
||||
'count' => ++$users_count,
|
||||
];
|
||||
}
|
||||
|
||||
// Clean the file
|
||||
ftruncate($fp_user_list, 0);
|
||||
|
||||
$status = fwrite($fp_user_list, json_encode($user_list));
|
||||
|
||||
if ($status === false) {
|
||||
fclose($fp_user_list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fclose($fp_user_list);
|
||||
}
|
||||
|
||||
|
||||
function users_save_logout($user=false, $delete=false)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$return = [
|
||||
'correct' => false,
|
||||
'users' => [],
|
||||
];
|
||||
|
||||
$file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt';
|
||||
|
||||
if (empty($user)) {
|
||||
$user = db_get_row_filter(
|
||||
'tusuario',
|
||||
['id_user' => $config['id_user']]
|
||||
);
|
||||
}
|
||||
|
||||
if ($delete) {
|
||||
$no_json_output = true;
|
||||
$message = sprintf(
|
||||
__('User %s was deleted in the DB at %s'),
|
||||
$user['fullname'],
|
||||
date($config['date_format'])
|
||||
);
|
||||
} else {
|
||||
$no_json_output = false;
|
||||
$message = sprintf(
|
||||
__('User %s logout at %s'),
|
||||
$user['fullname'],
|
||||
date($config['date_format'])
|
||||
);
|
||||
}
|
||||
|
||||
users_save_text_message($message, 'notification', $no_json_output);
|
||||
|
||||
// First lock the file
|
||||
$fp_user_list = @fopen($file_global_user_list, 'a+');
|
||||
if ($fp_user_list === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
while (!flock($fp_user_list, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
return;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
@fscanf($fp_user_list, "%[^\n]", $user_list_json);
|
||||
|
||||
$user_list = json_decode($user_list_json, true);
|
||||
if (empty($user_list)) {
|
||||
$user_list = [];
|
||||
}
|
||||
|
||||
unset($user_list[$user['id_user']]);
|
||||
|
||||
// Clean the file
|
||||
ftruncate($fp_user_list, 0);
|
||||
|
||||
$status = fwrite($fp_user_list, json_encode($user_list));
|
||||
|
||||
if ($status === false) {
|
||||
fclose($fp_user_list);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fclose($fp_user_list);
|
||||
}
|
||||
|
||||
|
||||
function users_save_text_message($message=false, $type='message', $no_json_output=false)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt';
|
||||
$log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt';
|
||||
|
||||
$return = ['correct' => false];
|
||||
|
||||
$id_user = $config['id_user'];
|
||||
$user = db_get_row_filter(
|
||||
'tusuario',
|
||||
['id_user' => $id_user]
|
||||
);
|
||||
|
||||
$message_data = [];
|
||||
$message_data['type'] = $type;
|
||||
$message_data['id_user'] = $id_user;
|
||||
$message_data['user_name'] = $user['fullname'];
|
||||
$message_data['text'] = io_safe_input_html($message);
|
||||
// The $message_data['timestamp'] set when adquire the files to save.
|
||||
// First lock the file
|
||||
$fp_global_counter = @fopen($file_global_counter_chat, 'a+');
|
||||
if ($fp_global_counter === false) {
|
||||
if (!$no_json_output) {
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
while (!flock($fp_global_counter, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
if (!$no_json_output) {
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
@fscanf($fp_global_counter, '%d', $global_counter_file);
|
||||
if (empty($global_counter_file)) {
|
||||
$global_counter_file = 0;
|
||||
}
|
||||
|
||||
// Clean the file
|
||||
ftruncate($fp_global_counter, 0);
|
||||
|
||||
$message_data['timestamp'] = time();
|
||||
$message_data['human_time'] = date($config['date_format'], $message_data['timestamp']);
|
||||
|
||||
$global_counter = ($global_counter_file + 1);
|
||||
|
||||
$status = fwrite($fp_global_counter, $global_counter);
|
||||
|
||||
if ($status === false) {
|
||||
fclose($fp_global_counter);
|
||||
|
||||
if (!$no_json_output) {
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
$text_encode = @file_get_contents($log_chat_file);
|
||||
$log = json_decode($text_encode, true);
|
||||
$log[$global_counter] = $message_data;
|
||||
$status = file_put_contents($log_chat_file, json_encode($log));
|
||||
|
||||
fclose($fp_global_counter);
|
||||
|
||||
$return['correct'] = true;
|
||||
if (!$no_json_output) {
|
||||
echo json_encode($return);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
function users_long_polling_check_messages($global_counter)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt';
|
||||
$log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt';
|
||||
|
||||
$changes = false;
|
||||
|
||||
$tries_general = 0;
|
||||
|
||||
$error = false;
|
||||
|
||||
while (!$changes) {
|
||||
// First lock the file
|
||||
$fp_global_counter = @fopen($file_global_counter_chat, 'a+');
|
||||
if ($fp_global_counter) {
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
$lock = true;
|
||||
while (!flock($fp_global_counter, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
$lock = false;
|
||||
$error = true;
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if ($lock) {
|
||||
@fscanf($fp_global_counter, '%d', $global_counter_file);
|
||||
if (empty($global_counter_file)) {
|
||||
$global_counter_file = 0;
|
||||
}
|
||||
|
||||
if ($global_counter_file > $global_counter) {
|
||||
// TODO Optimize slice the array.
|
||||
$text_encode = @file_get_contents($log_chat_file);
|
||||
$log = json_decode($text_encode, true);
|
||||
|
||||
$return_log = [];
|
||||
foreach ($log as $key => $message) {
|
||||
if ($key <= $global_counter) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$return_log[] = $message;
|
||||
}
|
||||
|
||||
$return = [
|
||||
'correct' => true,
|
||||
'global_counter' => $global_counter_file,
|
||||
'log' => $return_log,
|
||||
];
|
||||
|
||||
echo json_encode($return);
|
||||
|
||||
fclose($fp_global_counter);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fp_global_counter);
|
||||
}
|
||||
|
||||
sleep(3);
|
||||
$tries_general = ($tries_general + 3);
|
||||
|
||||
if ($tries_general > MAX_TIMES) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Because maybe the exit of loop for exaust.
|
||||
echo json_encode(['correct' => false, 'error' => $error]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the last global counter for chat.
|
||||
*
|
||||
* @param string $mode There are two modes 'json', 'return' and 'session'. And json is by default.
|
||||
*/
|
||||
function users_get_last_global_counter($mode='json')
|
||||
{
|
||||
global $config;
|
||||
|
||||
$file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt';
|
||||
|
||||
$global_counter_file = 0;
|
||||
|
||||
$fp_global_counter = @fopen($file_global_counter_chat, 'a+');
|
||||
if ($fp_global_counter) {
|
||||
$tries = 0;
|
||||
$lock = true;
|
||||
while (!flock($fp_global_counter, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
$lock = false;
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if ($lock) {
|
||||
@fscanf($fp_global_counter, '%d', $global_counter_file);
|
||||
if (empty($global_counter_file)) {
|
||||
$global_counter_file = 0;
|
||||
}
|
||||
|
||||
fclose($fp_global_counter);
|
||||
}
|
||||
}
|
||||
|
||||
switch ($mode) {
|
||||
case 'json':
|
||||
echo json_encode(['correct' => true, 'global_counter' => $global_counter_file]);
|
||||
break;
|
||||
|
||||
case 'return':
|
||||
return $global_counter_file;
|
||||
|
||||
break;
|
||||
case 'session':
|
||||
$_SESSION['global_counter_chat'] = $global_counter_file;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the last global counter for chat.
|
||||
*
|
||||
* @param string $mode There are two modes 'json', 'return' and 'session'. And json is by default.
|
||||
*/
|
||||
function users_get_last_type_message()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$return = 'false';
|
||||
|
||||
$file_global_counter_chat = $config['attachment_store'].'/pandora_chat.global_counter.txt';
|
||||
$log_chat_file = $config['attachment_store'].'/pandora_chat.log.json.txt';
|
||||
|
||||
$global_counter_file = 0;
|
||||
|
||||
$fp_global_counter = @fopen($file_global_counter_chat, 'a+');
|
||||
if ($fp_global_counter) {
|
||||
$tries = 0;
|
||||
$lock = true;
|
||||
while (!flock($fp_global_counter, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
$lock = false;
|
||||
break;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
if ($lock) {
|
||||
$text_encode = @file_get_contents($log_chat_file);
|
||||
$log = json_decode($text_encode, true);
|
||||
|
||||
// Prevent from error when chat file log doesn't exists
|
||||
if (empty($log)) {
|
||||
$return = false;
|
||||
} else {
|
||||
$last = end($log);
|
||||
$return = $last['type'];
|
||||
}
|
||||
|
||||
fclose($fp_global_counter);
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
||||
function users_is_admin($id_user=false)
|
||||
{
|
||||
global $config;
|
||||
|
@ -1026,98 +524,6 @@ function users_is_admin($id_user=false)
|
|||
}
|
||||
|
||||
|
||||
function users_is_last_system_message()
|
||||
{
|
||||
$type = users_get_last_type_message();
|
||||
|
||||
if ($type != 'message') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function users_check_users()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$return = [
|
||||
'correct' => false,
|
||||
'users' => '',
|
||||
];
|
||||
|
||||
$users_with_session = db_get_all_rows_sql('SELECT tsessions_php.data FROM pandora.tsessions_php;');
|
||||
$users_logged_now = [];
|
||||
foreach ($users_with_session as $user_with_session) {
|
||||
$tmp_id_user = explode('"', $user_with_session['data']);
|
||||
array_push($users_logged_now, $tmp_id_user[1]);
|
||||
}
|
||||
|
||||
$file_global_user_list = $config['attachment_store'].'/pandora_chat.user_list.json.txt';
|
||||
|
||||
// First lock the file
|
||||
$fp_user_list = @fopen($file_global_user_list, 'a+');
|
||||
if ($fp_user_list === false) {
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to look MAX_TIMES times
|
||||
$tries = 0;
|
||||
while (!flock($fp_user_list, LOCK_EX)) {
|
||||
$tries++;
|
||||
if ($tries > MAX_TIMES) {
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
@fscanf($fp_user_list, "%[^\n]", $user_list_json);
|
||||
|
||||
$user_list = json_decode($user_list_json, true);
|
||||
if (empty($user_list)) {
|
||||
$user_list = [];
|
||||
}
|
||||
|
||||
// Compare both user list. Meanwhile the user from chat file have an active
|
||||
// session, his continue in the list of active chat users
|
||||
$user_name_list = [];
|
||||
foreach ($user_list as $key => $user) {
|
||||
if (in_array($key, $users_logged_now)) {
|
||||
array_push($user_name_list, $user['name']);
|
||||
} else {
|
||||
unset($user_list[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the file
|
||||
ftruncate($fp_user_list, 0);
|
||||
|
||||
// Update the file with the correct list of users
|
||||
$status = fwrite($fp_user_list, json_encode($user_list));
|
||||
|
||||
/*
|
||||
if ($status === false) {
|
||||
fclose($fp_user_list);
|
||||
|
||||
return;
|
||||
} */
|
||||
// Closing the resource
|
||||
fclose($fp_user_list);
|
||||
|
||||
$return['correct'] = true;
|
||||
$return['users'] = implode('<br />', $user_name_list);
|
||||
echo json_encode($return);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Check if a user can manage a group when group is all
|
||||
// This function dont check acls of the group, only if the
|
||||
// user is admin or pandora manager and the group is all
|
||||
|
|
|
@ -1,47 +0,0 @@
|
|||
function check_new_chats_icon(id_icon) {
|
||||
if (new_chat) {
|
||||
$("#" + id_icon).pulsate();
|
||||
}
|
||||
}
|
||||
|
||||
function check_new_chats_icon_ajax(id_icon) {
|
||||
var exit = false;
|
||||
|
||||
url_chunks = location.href.split("&");
|
||||
$.each(url_chunks, function(key, chunk) {
|
||||
if (chunk == "sec2=operation/users/webchat") exit = true;
|
||||
return;
|
||||
});
|
||||
|
||||
if (exit) {
|
||||
return;
|
||||
}
|
||||
|
||||
old = global_counter_chat;
|
||||
get_last_global_counter();
|
||||
|
||||
if (old < global_counter_chat) {
|
||||
$("#" + id_icon).pulsate();
|
||||
}
|
||||
|
||||
setTimeout('check_new_chats_icon("' + id_icon + '")', 5000);
|
||||
}
|
||||
|
||||
function get_last_global_counter() {
|
||||
var parameters = {};
|
||||
parameters["page"] = "operation/users/webchat";
|
||||
parameters["get_last_global_counter"] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
async: false,
|
||||
success: function(data) {
|
||||
if (data["correct"] == 1) {
|
||||
global_counter_chat = data["global_counter"];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1002,60 +1002,9 @@ if ($process_login) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set the initial global counter for chat.
|
||||
users_get_last_global_counter('session');
|
||||
|
||||
$config['logged'] = true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Get old parameters before navigation.
|
||||
$old_sec = '';
|
||||
$old_sec2 = '';
|
||||
$old_page = '';
|
||||
if (isset($_SERVER['HTTP_REFERER'])) {
|
||||
$old_page = $_SERVER['HTTP_REFERER'];
|
||||
}
|
||||
|
||||
$chunks = explode('?', $old_page);
|
||||
if (count($chunks) == 2) {
|
||||
$chunks = explode('&', $chunks[1]);
|
||||
|
||||
foreach ($chunks as $chunk) {
|
||||
if (strstr($chunk, 'sec=') !== false) {
|
||||
$old_sec = str_replace('sec=', '', $chunk);
|
||||
}
|
||||
|
||||
if (strstr($chunk, 'sec2=') !== false) {
|
||||
$old_sec = str_replace('sec2=', '', $chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['new_chat'] = false;
|
||||
if ($old_sec2 == 'operation/users/webchat') {
|
||||
users_get_last_global_counter('session');
|
||||
}
|
||||
|
||||
if ($page == 'operation/users/webchat') {
|
||||
// Reload the global counter.
|
||||
users_get_last_global_counter('session');
|
||||
}
|
||||
|
||||
if (isset($_SESSION['global_counter_chat'])) {
|
||||
$old_global_counter_chat = $_SESSION['global_counter_chat'];
|
||||
} else {
|
||||
$old_global_counter_chat = users_get_last_global_counter('return');
|
||||
}
|
||||
|
||||
$now_global_counter_chat = users_get_last_global_counter('return');
|
||||
|
||||
if ($old_global_counter_chat != $now_global_counter_chat) {
|
||||
if (!users_is_last_system_message()) {
|
||||
$_SESSION['new_chat'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'general/register.php';
|
||||
|
||||
if (get_parameter('login', 0) !== 0) {
|
||||
|
|
|
@ -482,12 +482,6 @@ $sub['operation/users/user_edit_notifications']['text'] = __('Configure user not
|
|||
$sub['operation/users/user_edit_notifications']['id'] = 'Configure user notifications';
|
||||
$sub['operation/users/user_edit_notifications']['refr'] = 0;
|
||||
|
||||
// ANY user can chat with other user and dogs.
|
||||
// Users.
|
||||
$sub['operation/users/webchat']['text'] = __('WebChat');
|
||||
$sub['operation/users/webchat']['id'] = 'WebChat';
|
||||
$sub['operation/users/webchat']['refr'] = 0;
|
||||
|
||||
|
||||
// Incidents.
|
||||
if (check_acl($config['id_user'], 0, 'IR')
|
||||
|
|
|
@ -1,345 +0,0 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; version 2
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
if (is_ajax()) {
|
||||
global $config;
|
||||
|
||||
include_once 'include/functions_users.php';
|
||||
|
||||
$status = check_login(false);
|
||||
|
||||
if ($status) {
|
||||
$get_last_messages = (bool) get_parameter('get_last_messages', 0);
|
||||
$send_message = (bool) get_parameter('send_message', 0);
|
||||
$send_login = (bool) get_parameter('send_login', 0);
|
||||
$send_logout = (bool) get_parameter('send_logout', 0);
|
||||
$long_polling_check_messages = (bool) get_parameter('long_polling_check_messages', 0);
|
||||
$get_last_global_counter = (bool) get_parameter('get_last_global_counter', 0);
|
||||
$check_users = (bool) get_parameter('check_users', 0);
|
||||
|
||||
if ($get_last_messages) {
|
||||
$time = (int) get_parameter('time', (24 * 60 * 60));
|
||||
users_get_last_messages($time);
|
||||
}
|
||||
|
||||
if ($send_message) {
|
||||
$message = get_parameter('message', false);
|
||||
if (!empty($message)) {
|
||||
users_save_text_message($message);
|
||||
}
|
||||
}
|
||||
|
||||
if ($send_login) {
|
||||
users_save_login();
|
||||
}
|
||||
|
||||
if ($send_logout) {
|
||||
users_save_logout();
|
||||
}
|
||||
|
||||
if ($long_polling_check_messages) {
|
||||
$global_counter = (int) get_parameter('global_counter', 0);
|
||||
users_long_polling_check_messages($global_counter);
|
||||
}
|
||||
|
||||
if ($get_last_global_counter) {
|
||||
users_get_last_global_counter();
|
||||
}
|
||||
|
||||
if ($check_users) {
|
||||
users_check_users();
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['correct' => false]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
global $config;
|
||||
|
||||
check_login();
|
||||
|
||||
ui_print_page_header(__('Webchat'), 'images/comments.png', false, '', false, '');
|
||||
|
||||
$table = new stdClass();
|
||||
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox filters';
|
||||
$table->style[0][1] = 'text-align: right; vertical-align: top;';
|
||||
|
||||
$table->data[0][0] = '<div id="chat_box" style="width: 95%;
|
||||
height: 300px; background: #ffffff; border: 1px solid #cbcbcb; border-radius: 5px;
|
||||
overflow: auto; padding: 10px;"></div>';
|
||||
$table->data[0][1] = '<h4>'.__('Users Online').'</h4>'.'<div id="userlist_box" style="width: 90% !important; height: 200px !important;
|
||||
height: 300px; background: #ffffff; border: 1px solid #cbcbcb; border-radius: 5px;
|
||||
overflow: auto; padding-right: 10px;"></div>';
|
||||
$table->data[1][0] = '<b>'.__('Message').'</b> '.html_print_input_text(
|
||||
'message_box',
|
||||
'',
|
||||
'',
|
||||
100,
|
||||
150,
|
||||
true
|
||||
);
|
||||
html_print_table($table);
|
||||
|
||||
echo "<div style='width:100%'>".html_print_button(
|
||||
__('Send message'),
|
||||
'send',
|
||||
false,
|
||||
'send_message()',
|
||||
'class="sub next" style="float:right"',
|
||||
true
|
||||
).'</div>';
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var global_counter_chat = 0;
|
||||
var chat_log = '';
|
||||
var user_move_scroll = false;
|
||||
var first_time = true;
|
||||
|
||||
$(document).ready(function() {
|
||||
confirmDialog({
|
||||
title: "Attention",
|
||||
message:
|
||||
"<h4 style='text-align: center;'>This feature will be removed from the console in the next version of Pandora FMS.<br><br> If you want to keep the history, make a backup.</h4>",
|
||||
cancel: "Cancel",
|
||||
ok: "Ok",
|
||||
onAccept: function() {
|
||||
// Nothing to do.
|
||||
}
|
||||
});
|
||||
$("input[name=\"message_box\"]").keydown(function(e) {
|
||||
//Enter key.
|
||||
if (e.keyCode == 13) {
|
||||
send_message();
|
||||
check_users();
|
||||
}
|
||||
});
|
||||
|
||||
init_webchat();
|
||||
});
|
||||
$(window).on("beforeunload",function () {
|
||||
exit_webchat();
|
||||
});
|
||||
|
||||
function init_webchat() {
|
||||
send_login_message();
|
||||
long_polling_check_messages();
|
||||
check_users();
|
||||
}
|
||||
|
||||
function check_users() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "operation/users/webchat";
|
||||
parameters['check_users'] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
$("#userlist_box").html(data['users']);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function long_polling_check_messages() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "operation/users/webchat";
|
||||
parameters['long_polling_check_messages'] = 1;
|
||||
parameters['global_counter'] = global_counter_chat;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
check_users();
|
||||
|
||||
if (first_time) {
|
||||
var date_first_message = unix_timestamp(data['log'][0]['timestamp']);
|
||||
if(!date_first_message){
|
||||
date_first_message = unix_timestamp(new Date()/1000);
|
||||
}
|
||||
print_messages({
|
||||
0: {'type' : 'notification',
|
||||
'text': '<?php echo __('Connection established - Retrieving messages since '); ?>'+date_first_message}
|
||||
}, true);
|
||||
first_time = false;
|
||||
}
|
||||
global_counter_chat = data['global_counter'];
|
||||
print_messages(data['log']);
|
||||
}
|
||||
else {
|
||||
if (data['error']) {
|
||||
print_messages({
|
||||
0: {'type' : 'error',
|
||||
'text': '<?php echo __('Error in connection.'); ?>'}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
long_polling_check_messages();
|
||||
},
|
||||
error: function(request, status, err) {
|
||||
long_polling_check_messages();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function print_messages(messages, clear_chat_box) {
|
||||
//event_add_text = true;
|
||||
|
||||
if (typeof(clear_chat_box) == 'undefined') {
|
||||
clear_chat_box = false;
|
||||
}
|
||||
|
||||
var html = '';
|
||||
|
||||
$.each(messages, function(key, message) {
|
||||
html = html + '<div ';
|
||||
|
||||
if (message['type'] == 'error') {
|
||||
html = html + "style='color: red; font-style: italic;'";
|
||||
}
|
||||
else if (message['type'] == 'notification') {
|
||||
html = html + "style='color: grey; font-style: italic;'";
|
||||
}
|
||||
else if (message['type'] == 'message') {
|
||||
html = html + "style='color: black; font-style: normal;'";
|
||||
}
|
||||
html = html + '>';
|
||||
|
||||
if (message['type'] != 'message') {
|
||||
html = html + message['text'];
|
||||
}
|
||||
else {
|
||||
html = html +
|
||||
'<span style="color: grey; font-style: italic;">' +
|
||||
message['human_time'] + '</span>';
|
||||
html = html + ' ' +
|
||||
'<span style="color: black; font-weight: bolder;">' +
|
||||
message['user_name'] + ':> </span>';
|
||||
html = html + ' ' + message['text'];
|
||||
}
|
||||
|
||||
html = html + '</div>';
|
||||
});
|
||||
|
||||
|
||||
|
||||
if (clear_chat_box) {
|
||||
$("#chat_box").html(html);
|
||||
}
|
||||
else {
|
||||
$("#chat_box").append(html);
|
||||
}
|
||||
|
||||
$("#chat_box").scrollTop($("#chat_box").attr('scrollHeight'));
|
||||
}
|
||||
|
||||
function send_message() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "operation/users/webchat";
|
||||
parameters['send_message'] = 1;
|
||||
parameters['message'] = $("input[name=\"message_box\"]").val();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
$("input[name=\"message_box\"]").val('');
|
||||
}
|
||||
else {
|
||||
print_messages({
|
||||
0: {'type' : 'error',
|
||||
'text': '<?php echo __('Error sendding message.'); ?>'}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function exit_webchat() {
|
||||
send_logout_message();
|
||||
get_last_global_counter();
|
||||
}
|
||||
|
||||
function send_login_message() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "operation/users/webchat";
|
||||
parameters['send_login'] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
if (data['correct'] == 1) {
|
||||
}
|
||||
else {
|
||||
print_messages({
|
||||
0: {'type' : 'error',
|
||||
'text': '<?php echo __('Error login.'); ?>'}
|
||||
}, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function send_logout_message() {
|
||||
var parameters = {};
|
||||
parameters['page'] = "operation/users/webchat";
|
||||
parameters['send_logout'] = 1;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
data: parameters,
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Function to convert a timestamp to human date.
|
||||
function unix_timestamp(timestamp){
|
||||
var date = new Date(timestamp*1000);
|
||||
|
||||
const monthNames = [
|
||||
"January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December"
|
||||
];
|
||||
var month = monthNames[date.getMonth()];
|
||||
|
||||
var day = date.getDate();
|
||||
var year = date.getFullYear();
|
||||
|
||||
var hour = date.getHours();
|
||||
var min = date.getMinutes();
|
||||
|
||||
return month + ' ' + day + ', '+ year + ', ' + hour+ ':' + min;
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue