Adding a new user profile field to set the status of the chat (connect/disconnect) + some other fixes like the chat.js javascript is not loaded when there's no user

skala
Julio Montoya 13 years ago
parent 6c2f8172a7
commit f64fe41031
  1. 8
      main/inc/ajax/chat.ajax.php
  2. 18
      main/inc/header.inc.php
  3. 54
      main/inc/lib/chat.lib.php
  4. 35
      main/inc/lib/javascript/chat/css/chat.css
  5. 112
      main/inc/lib/javascript/chat/js/chat.js
  6. 19
      main/inc/lib/javascript/chat/js/jquery.js
  7. 41
      main/inc/lib/main_api.lib.php
  8. 2
      main/inc/lib/online.inc.php
  9. 12
      main/inc/lib/social.lib.php
  10. 7
      main/inc/lib/template.lib.php
  11. 1
      main/install/db_main.sql
  12. 5
      main/install/install.lib.php
  13. 5
      main/install/migrate-db-1.8.8-1.9.0-pre.sql
  14. 9
      main/template/default/layout/head.tpl

@ -7,7 +7,6 @@
$_dont_save_user_course_access = true;
require_once '../global.inc.php';
require_once api_get_path(LIBRARY_PATH).'chat.lib.php';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
@ -46,8 +45,11 @@ switch ($action) {
case 'startchatsession':
$chat->start_session();
break;
case 'set_status':
$status = isset($_REQUEST['status']) ? intval($_REQUEST['status']) : 0;
$chat->set_user_status($status);
break;
default:
echo '';
echo '';
}
exit;

@ -8,18 +8,6 @@
/* HEADERS SECTION */
// Server mode indicator.
/*
if (api_is_platform_admin()) {
if (api_get_setting('server_type') == 'test') {
error_reporting(E_ALL);
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
$_SESSION['page_start_time_execution'] = $starttime;
}
}*/
header('Content-Type: text/html; charset='.api_get_system_encoding());
//show the X-Powered-By header so that parsers can find it
global $_configuration, $this_section;
@ -143,7 +131,7 @@ if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']=
<meta name="Generator" content="<?php echo $_configuration['software_name'].' '.substr($_configuration['system_version'],0,1);?>" />
<script src= "<?php echo api_get_path(WEB_LIBRARY_PATH);?>javascript/jquery.menu.js" type="text/javascript"></script>
<?php if (api_get_setting('allow_global_chat') == 'true') { ?>
<?php if ((api_get_setting('allow_global_chat') == 'true' && !api_is_anonymous()) { ?>
<script src="<?php echo api_get_path(WEB_LIBRARY_PATH);?>javascript/chat/js/chat.js" type="text/javascript" ></script>
<link rel="stylesheet" href="<?php echo api_get_path(WEB_LIBRARY_PATH);?>javascript/chat/css/chat.css" type="text/css" media="projection, screen" />
<link rel="stylesheet" href="<?php echo api_get_path(WEB_LIBRARY_PATH);?>javascript/chat/css/screen.css" type="text/css" media="projection, screen" />
@ -165,10 +153,14 @@ if ( ( navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) && ( navigator.
});
}
/* Global chat variables */
var ajax_url = '<?php echo api_get_path(WEB_AJAX_PATH).'chat.ajax.php'; ?>';
var online_button = '<?php echo Security::remove_XSS(Display::return_icon('online.png')); ?>';
var offline_button = '<?php echo Security::remove_XSS(Display::return_icon('offline.png')); ?>';
var connect_lang = '<?php echo get_lang('ChatConnected');?>';
var disconnect_lang = '<?php echo get_lang('ChatDisconnected');?>';
//]]>
</script>

@ -10,50 +10,45 @@
class Chat extends Model {
var $table;
var $columns = array('id', 'from_user','to_user','message','sent','recd');
var $columns = array('id', 'from_user','to_user','message','sent','recd');
var $window_list = array();
public function __construct() {
$this->table = Database::get_main_table(TABLE_MAIN_CHAT);
$this->window_list = $_SESSION['window_list'] = isset($_SESSION['window_list']) ? $_SESSION['window_list'] : array();
}
function get_user_status() {
$status = UserManager::get_extra_user_data_by_field(api_get_user_id(), 'chat_user_status', false, true);
return $status['chat_user_status'];
//return isset($_SESSION['chat_user_status']) ? intval($_SESSION['chat_user_status']) : 0;
}
function set_user_status($status) {
//$_SESSION['chat_user_status'] = intval($status);
UserManager::update_extra_field_value(api_get_user_id(), 'chat_user_status', $status);
}
public function start_session() {
$items = array();
//unset($_SESSION['openChatBoxes']); unset($_SESSION['tsChatBoxes']); unset($_SESSION['chatHistory']);
/*$items = array();
if (!empty($_SESSION['openChatBoxes'])) {
foreach ($_SESSION['openChatBoxes'] as $user_id => $void) {
$item = self::box_session($user_id);
if (!empty($item)) {
$items[$user_id] = $item;
}
}
}*/
if (isset($_SESSION['chatHistory'])) {
$items = $_SESSION['chatHistory'];
}
$return = array('me' => get_lang('Me'), 'items' => $items);
echo json_encode($return);
}
$return = array('user_status' => $this->get_user_status(), 'me' => get_lang('Me'), 'items' => $items);
echo json_encode($return);
exit;
}
public function heartbeat() {
$to_user_id = api_get_user_id();
$my_user_info = api_get_user_info();
$minutes = 60;
$now = time() - $minutes*60;
$now = api_get_utc_datetime($now);
$to_user_id = api_get_user_id();
$minutes = 60;
$now = time() - $minutes*60;
$now = api_get_utc_datetime($now);
//OR sent > '$now'
$sql = "SELECT * FROM ".$this->table."
WHERE to_user = '".intval($to_user_id)."' AND ( recd = 0 ) ORDER BY id ASC";
WHERE to_user = '".intval($to_user_id)."' AND ( recd = 0 ) ORDER BY id ASC";
$result = Database::query($sql);
$chat_list = array();
@ -61,9 +56,6 @@ class Chat extends Model {
while ($chat = Database::fetch_array($result,'ASSOC')) {
$chat_list[$chat['from_user']]['items'][] = $chat;
}
//var_dump($chat_list);
$chatBoxes = array();
$items = array();

@ -1,3 +1,38 @@
.chatboxmain {
position: fixed;
position:expression("absolute");
width: 225px;
z-index: 9000;
bottom: 0px;
right: 20px;
display: block;
}
.chatboxheadmain {
padding:7px 7px 7px 0px;
color: #333333;
background-color: #EBEEF4;
border-top: 1px solid rgba(29, 49, 91, 0.3);
border-left: 1px solid rgba(29, 49, 91, 0.3);
border-right: 1px solid rgba(29, 49, 91, 0.3);
}
#chatboxtitlemain {
font-weight: bold;
float: left;
font-size: 13px;
width: 160px;
cursor:pointer;
}
.user_status_main {
width:16px;
display:inline;
float:left;
padding: 0px 4px 0px 4px;
}
.chatbox {
position: fixed;
position:expression("absolute");

@ -22,24 +22,42 @@ OTHER DEALINGS IN THE SOFTWARE.
var windowFocus = true;
var username;
var chatHeartbeatCount = 0;
var minChatHeartbeat = 4000;
var maxChatHeartbeat = 33000;
var chatHeartbeatTime = minChatHeartbeat;
var chatHeartbeatCount = 0;
var minChatHeartbeat = 4000;
var maxChatHeartbeat = 33000;
var chatHeartbeatTime = minChatHeartbeat;
var originalTitle;
var blinkOrder = 0;
var blinkOrder = 0;
var chatboxFocus = new Array();
var newMessages = new Array();
var newMessagesWin = new Array();
var chatBoxes = new Array();
var chatboxFocus = new Array();
var newMessages = new Array();
var newMessagesWin = new Array();
var chatBoxes = new Array();
var timer;
var user_status = 0;
//var ajax_url = 'chat.php'; // This variable is loaded in header.inc.php/ template/layout/head.tpl
function set_user_status(status) {
$.ajax({
url: ajax_url+"?action=set_status",
data: "status="+status,
cache: false,
success: function(data) {
}
});
user_status = status;
}
$(document).ready(function() {
originalTitle = document.title;
startChatSession();
//startChatHeartBeat();
//stopChatHeartBeat();
$([window, document]).blur(function(){
$([window, document]).blur(function() {
windowFocus = false;
}).focus(function(){
windowFocus = true;
@ -47,6 +65,21 @@ $(document).ready(function() {
});
/* Live conditions */
// User name header toogle
$('#chatboxtitlemain').live('click', function() {
if (user_status == 1) {
stopChatHeartBeat();
$('.user_status_main').html(offline_button);
$('#chatboxtitlemain').html(disconnect_lang);
set_user_status(0);
} else {
startChatHeartBeat();
$('.user_status_main').html(online_button);
$('#chatboxtitlemain').html(connect_lang);
set_user_status(1);
}
});
// User name header toogle
$('.chatboxtitle').live('click', function(){
@ -66,22 +99,44 @@ $(document).ready(function() {
$('.chatboxhead .closelink').live('click', function(){
var chat_id = $(this).attr('rel');
closeChatBox(chat_id);
});
});
});
function showChatConnect() {
if (user_status == 1) {
button = online_button;
label = connect_lang;
} else {
button = offline_button;
label = disconnect_lang;
}
$("<div />" ).attr("id","chatmain")
.addClass("chatboxmain")
.html('<div class="chatboxheadmain"><div class="user_status_main">'+button+'</div><div id="chatboxtitlemain">'+label+'</div><div class="chatboxoptions"></div><br clear="all"/></div></div>')
.appendTo($( "body" ));
}
/**
* Start chat session
*/
function startChatSession() {
function startChatSession() {
$.ajax({
url: ajax_url+"?action=startchatsession",
cache: false,
dataType: "json",
success: function(data) {
if (data) {
username = data.me;
username = data.me;
user_status = data.user_status;
showChatConnect();
if (user_status == 1) {
startChatHeartBeat();
} else {
stopChatHeartBeat();
}
$.each(data.items, function(my_user_id, user_items) {
//received_messages[item.f][item.id] = true;
$.each(user_items, function(i, item) {
@ -110,14 +165,18 @@ function startChatSession() {
for (i=0;i<chatBoxes.length;i++) {
my_user_id = chatBoxes[i];
$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);
//setTimeout('$("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
}
setTimeout('chatHeartbeat();', chatHeartbeatTime);
}
}});
}
function stopChatHeartBeat() {
clearInterval(timer);
timer = null;
}
function startChatHeartBeat() {
timer = setInterval('chatHeartbeat();', chatHeartbeatTime);
}
/*
* Shows the user messages in all windows
@ -226,15 +285,15 @@ function chatHeartbeat() {
}
}
setTimeout('chatHeartbeat();',chatHeartbeatTime);
//timer = setTimeout('chatHeartbeat();',chatHeartbeatTime);
}
}); //ajax
}
function closeChatBox(user_id) {
$('#chatbox_'+user_id).css('display','none');
restructureChatBoxes();
$.post(ajax_url+"?action=closechat", {chatbox: user_id} , function(data){
restructureChatBoxes();
$.post(ajax_url+"?action=closechat", {chatbox: user_id} , function(data){
});
}
@ -245,9 +304,9 @@ function restructureChatBoxes() {
user_id = chatBoxes[x];
if ($("#chatbox_"+user_id).css('display') != 'none') {
if (align == 0) {
$("#chatbox_"+user_id).css('right', '20px');
$("#chatbox_"+user_id).css('right', '245px');
} else {
width = (align)*(225+7)+20;
width = (align)*(225+7)+20 + 225;
$("#chatbox_"+user_id).css('right', width+'px');
}
align++;
@ -259,6 +318,7 @@ function restructureChatBoxes() {
* Function that fires the chat with an user (creates a chat bloclk)
* @param int user id
* @param string user's firstname + lastname
* @param status
*
**/
function chatWith(user_id, user_name, status) {
@ -305,9 +365,9 @@ function createChatBox(user_id, chatboxtitle, minimizeChatBox, online) {
}
if (chatBoxeslength == 0) {
$("#chatbox_"+user_id).css('right', '20px');
$("#chatbox_"+user_id).css('right', '245px');
} else {
width = (chatBoxeslength)*(225+7)+20;
width = (chatBoxeslength)*(225+7)+20 +225;
$("#chatbox_"+user_id).css('right', width+'px');
}
@ -349,12 +409,13 @@ function createChatBox(user_id, chatboxtitle, minimizeChatBox, online) {
$("#chatbox_"+user_id+" .chatboxtextarea").focus();
}
});
$("#chatbox_"+user_id).show();
}
/**
* Creates the div user status (green/gray button next to the user name)
* @param int user id
* @param int status 1 or 0
*/
function return_online_user(user_id, status) {
var div_wrapper = $("<div />" );
@ -421,7 +482,6 @@ function toggleChatBoxGrowth(user_id) {
}
function checkChatBoxInputKey(event, chatboxtextarea, user_id) {
if(event.keyCode == 13 && event.shiftKey == 0) {
message = $(chatboxtextarea).val();
message = message.replace(/^\s+|\s+$/g,"");

File diff suppressed because one or more lines are too long

@ -904,11 +904,11 @@ function _api_format_user($user) {
$result['lastName'] = $lastname;
if (isset($user['email'])) {
$result['mail'] = $user['email'];
$result['mail'] = $user['email'];
} else {
$result['mail'] = $user['mail'];
$result['mail'] = $user['mail'];
}
$user_id = intval($user['user_id']);
$user_id = intval($user['user_id']);
$result['picture_uri'] = $user['picture_uri'];
$result['user_id'] = $user_id;
$result['official_code'] = $user['official_code'];
@ -921,6 +921,7 @@ function _api_format_user($user) {
$result['theme'] = $user['theme'];
$result['language'] = $user['language'];
if (!isset($user['lastLogin']) && !isset($user['last_login'])) {
require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
$timestamp = Tracking::get_last_connection_date($result['user_id'], false, true);
@ -940,15 +941,17 @@ function _api_format_user($user) {
//Getting user avatar
$picture_filename = trim($user['picture_uri']);
$avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg';
$avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg';
$dir = 'upload/users/'.$user_id.'/';
$picture_filename = trim($user['picture_uri']);
$avatar = api_get_path(WEB_CODE_PATH).'img/unknown.jpg';
$avatar_small = api_get_path(WEB_CODE_PATH).'img/unknown_22.jpg';
$dir = 'upload/users/'.$user_id.'/';
if (!empty($picture_filename) && api_is_anonymous() ) {
if (api_get_setting('split_users_upload_directory') === 'true') {
$dir = 'upload/users/'.substr((string)$user_id, 0, 1).'/'.$user_id.'/';
}
}
$image_sys_path = api_get_path(SYS_CODE_PATH).$dir.$picture_filename;
if (file_exists($image_sys_path) && !is_dir($image_sys_path)) {
$avatar = api_get_path(WEB_CODE_PATH).$dir.$picture_filename;
@ -957,9 +960,14 @@ function _api_format_user($user) {
$result['avatar'] = $avatar;
$result['avatar_small'] = $avatar_small;
if (isset($user['user_is_online'])) {
$result['user_is_online'] = $user['user_is_online'] == true ? 1 : 0;
}
if (isset($user['user_is_online_in_chat'])) {
$result['user_is_online_in_chat'] = intval($user['user_is_online_in_chat']);
}
return $result;
}
@ -979,11 +987,22 @@ function api_get_user_info($user_id = '', $check_if_user_is_online = false) {
if (Database::num_rows($result) > 0) {
$result_array = Database::fetch_array($result);
if ($check_if_user_is_online) {
$result_array['user_is_online'] = user_is_online($user_id);
$use_status_in_platform = user_is_online($user_id);
$result_array['user_is_online'] = $use_status_in_platform;
$user_online_in_chat = 0;
if ($use_status_in_platform) {
$user_status = UserManager::get_extra_user_data_by_field($user_id, 'chat_user_status', false, true);
if (intval($user_status['chat_user_status']) == 1) {
$user_online_in_chat = 1;
}
}
$result_array['user_is_online_in_chat'] = $user_online_in_chat;
}
return _api_format_user($result_array);
}
$user = _api_format_user($result_array);
return $user;
}
return false;
}

@ -122,7 +122,7 @@ function user_is_online($user_id) {
$current_date = date('Y-m-d H:i:s',time());
$access_url_id = api_get_current_access_url_id();
$time_limit = api_get_setting('time_limit_whosonline');
//$time_limit = 1;
//$time_limit = 1; changing this value there is no time limit
$query = " SELECT login_user_id,login_date FROM ".$track_online_table ." track INNER JOIN ".$table_user ." u ON (u.user_id=track.login_user_id)
WHERE track.access_url_id = $access_url_id AND

@ -561,7 +561,8 @@ class SocialManager extends UserManager {
if (empty($user_id)) {
$user_id = api_get_user_id();
}
$user_info = api_get_user_info($user_id, true);
$user_info = api_get_user_info($user_id, true);
$show_groups = array('groups', 'group_messages', 'messages_list', 'group_add', 'mygroups', 'group_edit', 'member_list', 'invite_friends', 'waiting_list', 'browse_groups');
$show_messages = array('messages', 'messages_inbox', 'messages_outbox', 'messages_compose');
@ -697,10 +698,11 @@ class SocialManager extends UserManager {
//@todo check if user is online to show the chat link
if (api_get_setting('allow_global_chat') == 'true') {
if ($user_id != api_get_user_id()) {
$user_name = $user_info['complete_name'];
$options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online']."')");
$chat_icon = $user_info['user_is_online'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
if ($user_id != api_get_user_id()) {
$user_name = $user_info['complete_name'];
$options = array('onclick' => "javascript:chatWith('".$user_id."', '".Security::remove_XSS($user_name)."', '".$user_info['user_is_online_in_chat']."')");
$chat_icon = $user_info['user_is_online_in_chat'] ? Display::return_icon('online.png', get_lang('Online')) : Display::return_icon('offline.png', get_lang('Offline'));
$html .= Display::tag('li', Display::url($chat_icon.'&nbsp;&nbsp;'.get_lang('Chat'), 'javascript:void(0);', $options));
}
}

@ -216,7 +216,7 @@ class Template extends Smarty {
$this->assign('online_button', Security::remove_XSS(Display::return_icon('online.png')));
$this->assign('offline_button', Security::remove_XSS(Display::return_icon('offline.png')));
// Get language iso-code for this page - ignore errors
$this->assign('document_language', api_get_language_isocode());
@ -279,7 +279,10 @@ class Template extends Smarty {
);
if (api_get_setting('allow_global_chat') == 'true') {
$js_files[] = 'chat/js/chat.js';
if (!api_is_anonymous()) {
$js_files[] = 'chat/js/chat.js';
}
}
if (api_get_setting('accessibility_font_resize') == 'true') {

@ -1429,6 +1429,7 @@ INSERT INTO user_field (field_type, field_variable, field_display_text, field_vi
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (1, 'rssfeeds','RSS',0,0);
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (1, 'dashboard', 'Dashboard', 0, 0);
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (11, 'timezone', 'Timezone', 0, 0);
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (1, 'user_chat_status','User chat status',0,0);
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_invitation', 'MailNotifyInvitation',1,1,'1');
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_message', 'MailNotifyMessage',1,1,'1');
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable, field_default_value) values (4, 'mail_notify_group_message','MailNotifyGroupMessage',1,1,'1');

@ -1129,6 +1129,11 @@ function display_requirements($installType, $badUpdatePath, $updatePath = '', $u
<td class="requirements-item"><a href="http://xapian.org/" target="_blank">Xapian</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.check_extension('xapian', get_lang('Yes'), get_lang('No'), true).'</td>
</tr>
<tr>
<td class="requirements-item"><a href="http://php.net/manual/en/book.curl.php" target="_blank">cURL</a> '.get_lang('support').' ('.get_lang('Optional').')</td>
<td class="requirements-value">'.check_extension('curl', get_lang('Yes'), get_lang('No'), true).'</td>
</tr>
</table>';
echo ' </div>';

@ -15,7 +15,6 @@
-- xxMAINxx
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('filter_terms', NULL, 'textarea', 'Security', '', 'FilterTermsTitle', 'FilterTermsComment', NULL, NULL, 0);
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('header_extra_content', NULL, 'textarea', 'Tracking', '', 'HeaderExtraContentTitle', 'HeaderExtraContentComment', NULL, NULL, 1),('footer_extra_content', NULL, 'textarea', 'Tracking', '', 'FooterExtraContentTitle', 'FooterExtraContentComment', NULL, NULL,1);
ALTER TABLE personal_agenda ADD COLUMN all_day INTEGER NOT NULL DEFAULT 0;
@ -29,6 +28,7 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
INSERT INTO settings_options (variable, value, display_text) VALUES ('htmlpurifier_wiki', 'true', 'Yes');
INSERT INTO settings_options (variable, value, display_text) VALUES ('htmlpurifier_wiki', 'false', 'No');
-- CAS feature
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES('cas_activate', NULL, 'radio', 'CAS', 'false', 'CasMainActivateTitle', 'CasMainActivateComment', NULL, NULL, 0);
INSERT INTO settings_options (variable, value, display_text) values ('cas_activate', 'true', 'Yes');
@ -151,6 +151,9 @@ ALTER TABLE user_course_vote ADD INDEX idx_ucv_cuid (user_id, c_id);
ALTER TABLE track_e_default MODIFY COLUMN default_value TEXT;
--User chat status
INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (1, 'user_chat_status','User chat status', 0, 0);
-- Do not move this query
UPDATE settings_current SET selected_value = '1.9.0.16427' WHERE variable = 'chamilo_database_version';

@ -39,10 +39,13 @@ if ( ( navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) && ( navigator.
}
{/literal}
//]]>
/* global chat variables */
var ajax_url = '{$_p.web_ajax}chat.ajax.php';
var online_button = '{$online_button}';
var offline_button ='{$offline_button}';
var online_button = '{$online_button}';
var offline_button = '{$offline_button}';
var connect_lang = '{"ChatConnected"|get_lang}';
var disconnect_lang = '{"ChatDisconnected"|get_lang}';
</script>
{$js_file_to_string}

Loading…
Cancel
Save