From 5e3c15d43cc0c6c6203dd060a7920ba49f57827d Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 18 Jun 2012 12:36:18 +0000 Subject: [PATCH] 2012-06-18 Miguel de Dios * include/auth/ldap.php, include/javascript/pandora.js, include/functions_incidents.php: cleaned source code style. * include/functions_users.php, operation/users/webchat.php: a lot of fixes, the "error connection" don't appear when timeout the connection for to get new messages, fixed empty messages, and fixed when make freak actions with user connect in webchat for example delete. And the most important the chat files (logs and others) now Pandora save this files in attachment dir instead the tmp system dir. * godmode/users/user_list.php: added to call to delete from the chat user list when delete a user. MERGED from 4.0.2 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6570 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 18 ++++ pandora_console/godmode/users/user_list.php | 16 ++- pandora_console/include/auth/ldap.php | 1 - .../include/functions_incidents.php | 2 +- pandora_console/include/functions_users.php | 99 +++++++++++++------ pandora_console/include/javascript/pandora.js | 58 +++++------ pandora_console/operation/users/webchat.php | 15 +-- 7 files changed, 139 insertions(+), 70 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f3b6b78baf..dec496495d 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,21 @@ +2012-06-18 Miguel de Dios + + * include/auth/ldap.php, include/javascript/pandora.js, + include/functions_incidents.php: cleaned source code style. + + * include/functions_users.php, operation/users/webchat.php: a lot of + fixes, the "error connection" don't appear when timeout the + connection for to get new messages, fixed empty messages, and + fixed when make freak actions with user connect in webchat for + example delete. And the most important the chat files (logs and + others) now Pandora save this files in attachment dir instead the + tmp system dir. + + * godmode/users/user_list.php: added to call to delete from the + chat user list when delete a user. + + MERGED from 4.0.2 + 2012-06-18 Juan Manuel Ramon * include/functions_html.php diff --git a/pandora_console/godmode/users/user_list.php b/pandora_console/godmode/users/user_list.php index c08d321248..19daa809ba 100644 --- a/pandora_console/godmode/users/user_list.php +++ b/pandora_console/godmode/users/user_list.php @@ -110,19 +110,25 @@ $disable_user = get_parameter ("disable_user", false); if (isset ($_GET["user_del"])) { //delete user $id_user = get_parameter ("delete_user", 0); // Only allow delete user if is not the actual user - if($id_user != $config['id_user']){ + if ($id_user != $config['id_user']) { + + $user_row = users_get_user_by_id($id_user); + $result = delete_user ($id_user); - + + if ($result) { + users_save_logout($user_row, true); + } + db_pandora_audit("User management", "Deleted user ".io_safe_input($id_user)); - + ui_print_result_message ($result, __('Successfully deleted'), __('There was a problem deleting the user')); } else ui_print_error_message (__('There was a problem deleting the user')); - } elseif (isset ($_GET["profile_del"])) { //delete profile $id_profile = (int) get_parameter_post ("delete_profile"); @@ -183,7 +189,7 @@ $table->size[5] = '65px'; $info1 = array (); $info1 = get_users ($order, array ('offset' => (int) get_parameter ('offset'), - 'limit' => (int) $config['block_size'])); + 'limit' => (int) $config['block_size'])); $info = array(); $own_info = get_user_info ($config['id_user']); diff --git a/pandora_console/include/auth/ldap.php b/pandora_console/include/auth/ldap.php index 95b4709528..bbf263270f 100644 --- a/pandora_console/include/auth/ldap.php +++ b/pandora_console/include/auth/ldap.php @@ -107,7 +107,6 @@ foreach ($opt_keys as $key) { $config["auth_error"] = &$ldap_cache["error"]; unset ($req_keys, $opt_keys); - /** * process_user_login accepts $login and $pass and handles it according to current authentication scheme diff --git a/pandora_console/include/functions_incidents.php b/pandora_console/include/functions_incidents.php index a91c1c5f58..a89d0ee4e9 100644 --- a/pandora_console/include/functions_incidents.php +++ b/pandora_console/include/functions_incidents.php @@ -339,7 +339,7 @@ function incidents_delete_attach ($id_attach, $transact = true) { } unlink ($config["attachment_store"]."/pand".$id."_".$filename); } - + if ($transact == true && $errors > 0) { db_process_sql_rollback (); return false; diff --git a/pandora_console/include/functions_users.php b/pandora_console/include/functions_users.php index 1c5ef5d3c6..8a87c242fa 100644 --- a/pandora_console/include/functions_users.php +++ b/pandora_console/include/functions_users.php @@ -232,7 +232,7 @@ define("MAX_TIMES", 10); //////////////////////WEBCHAT FUNCTIONS///////////////////////////////// //////////////////////////////////////////////////////////////////////// function users_get_last_messages($last_time = false) { - $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; + $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+"); @@ -263,7 +263,7 @@ function users_get_last_messages($last_time = false) { $last_time = 24 * 60 * 60; $from = $timestamp - $last_time; - $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + $log_chat_file = $config["attachment_store"] . '/pandora_chat.log.json.txt'; $return = array('correct' => false, 'log' => array()); @@ -300,7 +300,7 @@ 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'; + $file_global_user_list = $config["attachment_store"] . '/pandora_chat.user_list.json.txt'; $user = db_get_row_filter('tusuario', array('id_user' => $config['id_user'])); @@ -329,7 +329,14 @@ function users_save_login() { $user_list = json_decode($user_list_json, true); if (empty($user_list)) $user_list = array(); - $user_list[$config['id_user']] = $user['fullname']; + + if (isset($user_list[$config['id_user']])) { + $user_list[$config['id_user']]['count']++; + } + else { + $user_list[$config['id_user']] = array('name' => $user['fullname'], + 'count' => 1); + } //Clean the file ftruncate($fp_user_list, 0); @@ -345,19 +352,30 @@ function users_save_login() { fclose($fp_user_list); } -function users_save_logout() { +function users_save_logout($user = false, $delete = false) { global $config; $return = array('correct' => false, 'users' => array()); - $file_global_user_list = sys_get_temp_dir() . '/pandora_chat.user_list.json.txt'; + $file_global_user_list = $config["attachment_store"] . '/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'); + if (empty($user)) { + $user = db_get_row_filter('tusuario', + array('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+"); @@ -379,7 +397,19 @@ function users_save_logout() { $user_list = json_decode($user_list_json, true); if (empty($user_list)) $user_list = array(); - unset($user_list[$config['id_user']]); + + if ($delete) { + unset($user_list[$user['id_user']]); + } + else { + if (isset($user_list[$config['id_user']])) { + $user_list[$config['id_user']]['count']--; + } + + if ($user_list[$config['id_user']]['count'] <= 0) { + unset($user_list[$user['id_user']]); + } + } //Clean the file ftruncate($fp_user_list, 0); @@ -395,11 +425,11 @@ function users_save_logout() { fclose($fp_user_list); } -function users_save_text_message($message = false, $type = 'message') { +function users_save_text_message($message = false, $type = 'message', $no_json_output = false) { global $config; - $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; - $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + $file_global_counter_chat = $config["attachment_store"] . '/pandora_chat.global_counter.txt'; + $log_chat_file = $config["attachment_store"] . '/pandora_chat.log.json.txt'; $return = array('correct' => false); @@ -419,7 +449,8 @@ function users_save_text_message($message = false, $type = 'message') { //First lock the file $fp_global_counter = @fopen($file_global_counter_chat, "a+"); if ($fp_global_counter === false) { - echo json_encode($return); + if (!$no_json_output) + echo json_encode($return); return; } @@ -428,7 +459,8 @@ function users_save_text_message($message = false, $type = 'message') { while (!flock($fp_global_counter, LOCK_EX)) { $tries++; if ($tries > MAX_TIMES) { - echo json_encode($return); + if (!$no_json_output) + echo json_encode($return); return; } @@ -453,7 +485,8 @@ function users_save_text_message($message = false, $type = 'message') { if ($status === false) { fclose($fp_global_counter); - echo json_encode($return); + if (!$no_json_output) + echo json_encode($return); return; } @@ -466,7 +499,8 @@ function users_save_text_message($message = false, $type = 'message') { fclose($fp_global_counter); $return['correct'] = true; - echo json_encode($return); + if (!$no_json_output) + echo json_encode($return); } return; @@ -475,13 +509,15 @@ function users_save_text_message($message = false, $type = 'message') { function users_long_polling_check_messages($global_counter) { global $config; - $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; - $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + $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+"); @@ -493,6 +529,7 @@ function users_long_polling_check_messages($global_counter) { $tries++; if ($tries > MAX_TIMES) { $lock = false; + $error = true; break; } @@ -541,7 +578,8 @@ function users_long_polling_check_messages($global_counter) { } } - echo json_encode(array('correct' => false)); + //Because maybe the exit of loop for exaust. + echo json_encode(array('correct' => false, 'error' => $error)); return; } @@ -554,7 +592,7 @@ function users_long_polling_check_messages($global_counter) { function users_get_last_global_counter($mode = 'json') { global $config; - $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; + $file_global_counter_chat = $config["attachment_store"] . '/pandora_chat.global_counter.txt'; $global_counter_file = 0; @@ -605,8 +643,8 @@ function users_get_last_type_message() { $return = 'false'; - $file_global_counter_chat = sys_get_temp_dir() . '/pandora_chat.global_counter.txt'; - $log_chat_file = sys_get_temp_dir() . '/pandora_chat.log.json.txt'; + $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; @@ -653,7 +691,7 @@ function users_check_users() { $return = array('correct' => false, 'users' => ''); - $file_global_user_list = sys_get_temp_dir() . '/pandora_chat.user_list.json.txt'; + $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+"); @@ -682,8 +720,13 @@ function users_check_users() { fclose($fp_user_list); + $user_name_list = array(); + foreach ($user_list as $user) { + $user_name_list[] = $user['name']; + } + $return['correct'] = true; - $return['users'] = implode('
', $user_list); + $return['users'] = implode('
', $user_name_list); echo json_encode($return); return; diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index f17a6b287e..1466f01010 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -310,35 +310,35 @@ function module_changed_by_multiple_modules (event, id_module, selected) { selection_mode = 'common'; } - jQuery.post ('ajax.php', - {"page": "operation/agentes/ver_agente", - "get_agents_json_for_multiple_modules": 1, - "module_name[]": idModules, - "selection_mode": selection_mode - }, - function (data) { - $('#agents').append ($('').html ("Loading...").attr ("value", 0)); - - $('#agents').empty (); - - if (isEmptyObject(data)) { - var noneText = $("#none_text").html(); //Trick for catch the translate text. - - if (noneText == null) { - noneText = 'None'; - } - - $('#agents').append ($('').html (noneText).attr ("None", "").attr('selected', true)); - - return; - } - - if (typeof($(document).data('text_for_module')) != 'undefined') { - $('#agents').append ($('').html ($(document).data('text_for_module')).attr("value", 0).attr('selected', true)); - } - else { - if (typeof(data['any_text']) != 'undefined') { - $('#agents').append ($('').html (data['any_text']).attr ("value", 0).attr('selected', true)); + jQuery.post('ajax.php', + {"page": "operation/agentes/ver_agente", + "get_agents_json_for_multiple_modules": 1, + "module_name[]": idModules, + "selection_mode": selection_mode + }, + function (data) { + $('#agents').append ($('').html ("Loading...").attr ("value", 0)); + + $('#agents').empty (); + + if (isEmptyObject(data)) { + var noneText = $("#none_text").html(); //Trick for catch the translate text. + + if (noneText == null) { + noneText = 'None'; + } + + $('#agents').append ($('').html (noneText).attr ("None", "").attr('selected', true)); + + return; + } + + if (typeof($(document).data('text_for_module')) != 'undefined') { + $('#agents').append ($('').html ($(document).data('text_for_module')).attr("value", 0).attr('selected', true)); + } + else { + if (typeof(data['any_text']) != 'undefined') { + $('#agents').append ($('').html (data['any_text']).attr ("value", 0).attr('selected', true)); } else { var anyText = $("#any_text").html(); //Trick for catch the translate text. diff --git a/pandora_console/operation/users/webchat.php b/pandora_console/operation/users/webchat.php index 1c8f4afc40..21ee43d9b0 100644 --- a/pandora_console/operation/users/webchat.php +++ b/pandora_console/operation/users/webchat.php @@ -36,7 +36,8 @@ if (is_ajax ()) { } if ($send_message) { $message = get_parameter('message', false); - users_save_text_message($message); + if (!empty($message)) + users_save_text_message($message); } if ($send_login) { users_save_login(); @@ -95,7 +96,7 @@ html_print_table($table); var first_time = true; $(document).ready(function() { - $("input[name=\"message_box\"]").keydown(function(e){ + $("input[name=\"message_box\"]").keydown(function(e) { //Enter key. if (e.keyCode == 13) { send_message(); @@ -159,10 +160,12 @@ html_print_table($table); print_messages(data['log']); } else { - print_messages({ - 0: {'type' : 'error', - 'text': ''} - }, false); + if (data['error']) { + print_messages({ + 0: {'type' : 'error', + 'text': ''} + }, false); + } } long_polling_check_messages(); },