2012-04-23 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_users.php, operation/users/webchat.php: added
	list users in chat.
	
	MERGED FROM 4.0.2




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6097 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-04-23 12:36:53 +00:00
parent b3c1a4a3b9
commit 31843ad2a0
3 changed files with 156 additions and 4 deletions

View File

@ -1,3 +1,10 @@
2012-04-23 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_users.php, operation/users/webchat.php: added
list users in chat.
MERGED FROM 4.0.2
2012-04-23 Dario Rodriguez <dario.rodriguez@artica.es>
* godmode/reporting/visual_console_builder.wizard.php: Unsorted

View File

@ -295,23 +295,99 @@ function users_get_last_messages($last_time = false) {
function users_save_login() {
global $config;
$file_global_user_list = sys_get_temp_dir() . '/pandora_chat.user_list.json.txt';
$user = db_get_row_filter('tusuario',
array('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, "%s", $user_list_json);
$user_list = json_decode($user_list_json, true);
if (empty($user_list))
$user_list = array();
$user_list[$config['id_user']] = $user['fullname'];
//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() {
global $config;
$return = array('correct' => false, 'users' => array());
$file_global_user_list = sys_get_temp_dir() . '/pandora_chat.user_list.json.txt';
$user = db_get_row_filter('tusuario',
array('id_user' => $config['id_user']));
$message = sprintf(__('User %s logout 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, "%s", $user_list_json);
$user_list = json_decode($user_list_json, true);
if (empty($user_list))
$user_list = array();
unset($user_list[$config['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') {
@ -562,4 +638,45 @@ function users_is_last_system_message() {
else
return false;
}
function users_check_users() {
global $config;
$return = array('correct' => false, 'users' => '');
$file_global_user_list = sys_get_temp_dir() . '/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, "%s", $user_list_json);
$user_list = json_decode($user_list_json, true);
if (empty($user_list))
$user_list = array();
fclose($fp_user_list);
$return['correct'] = true;
$return['users'] = implode('<br />', $user_list);
echo json_encode($return);
return;
}
?>

View File

@ -28,6 +28,7 @@ if (is_ajax ()) {
$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);
@ -50,6 +51,10 @@ if (is_ajax ()) {
if ($get_last_global_counter) {
users_get_last_global_counter();
}
if ($check_users) {
users_check_users();
}
}
else {
echo json_encode(array('correct' => false));
@ -67,12 +72,15 @@ ui_print_page_header (__('Webchat'), "images/group.png", false, "", false, "");
$table = null;
$table->width = '95%';
$table->style[0][1] = 'text-align: right; vertical-align: top;';
$table->colspan[0][0] = 2;
$table->data[0][0] = '<div id="chat_box" style="width: 100%;
$table->data[0][0] = '<div id="chat_box" style="width: 95%;
height: 300px; background: #ffffff; border: 1px inset black;
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 inset black;
overflow: auto; padding: 10px;"></div>';
$table->data[1][0] = html_print_input_text('message_box', '', '',
100, 150, true);
$table->data[1][1] = html_print_button('send', 'send', false, 'send_message()',
@ -104,6 +112,25 @@ html_print_table($table);
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() {
@ -119,6 +146,8 @@ html_print_table($table);
dataType: "json",
success: function(data) {
if (data['correct'] == 1) {
check_users();
if (first_time) {
print_messages({
0: {'type' : 'notification',
@ -217,7 +246,6 @@ html_print_table($table);
}
}
});
}
function exit_webchat() {