diff --git a/main/inc/ajax/chat.ajax.php b/main/inc/ajax/chat.ajax.php new file mode 100644 index 0000000000..48d575f791 --- /dev/null +++ b/main/inc/ajax/chat.ajax.php @@ -0,0 +1,47 @@ +heartbeat(); + break; + case 'closechat': + $chat->close(); + break; + case 'sendchat': + $chat->send(); + break; + case 'startchatsession': + $chat->start_session(); + break; + default: + echo ''; + +} +exit; \ No newline at end of file diff --git a/main/inc/header.inc.php b/main/inc/header.inc.php index 2387845e9c..bb46962a4c 100644 --- a/main/inc/header.inc.php +++ b/main/inc/header.inc.php @@ -143,6 +143,11 @@ if ($navigator_info['name']=='Internet Explorer' && $navigator_info['version']= + + + + + '0', 'f' => $chat['from'], 'm' => $chat['message'] ); + $items[] = $item; + + if (!isset($_SESSION['chatHistory'][$chat['from']])) { + $_SESSION['chatHistory'][$chat['from']] = ''; + } + + $_SESSION['chatHistory'][$chat['from']] .= json_encode($item); + + + unset($_SESSION['tsChatBoxes'][$chat['from']]); + $_SESSION['openChatBoxes'][$chat['from']] = $chat['sent']; + } + + if (!empty($_SESSION['openChatBoxes'])) { + foreach ($_SESSION['openChatBoxes'] as $chatbox => $time) { + if (!isset($_SESSION['tsChatBoxes'][$chatbox])) { + $now = time()-strtotime($time); + $time = date('g:iA M dS', strtotime($time)); + + $message = "Sent at $time"; + if ($now > 180) { + + $item = array('s' => '2', 'f' => $chatbox, 'm' => $message); + $items[] = $item; + if (!isset($_SESSION['chatHistory'][$chatbox])) { + $_SESSION['chatHistory'][$chatbox] = ''; + } + + $_SESSION['chatHistory'][$chatbox] .= json_encode($item); + $_SESSION['tsChatBoxes'][$chatbox] = 1; + } + } + } + } + + + $sql = "update chat set recd = 1 where chat.to = '".mysql_real_escape_string($to_user_id)."' and recd = 0"; + $query = Database::query($sql); + if ($items != '') { + //$items = substr($items, 0, -1); + } + + echo json_encode(array('items' => $items)); + } + + function chatBoxSession($chatbox) { + $items = ''; + if (isset($_SESSION['chatHistory'][$chatbox])) { + $items = $_SESSION['chatHistory'][$chatbox]; + } + return $items; + } + + function start_session() { + $items = ''; + if (!empty($_SESSION['openChatBoxes'])) { + foreach ($_SESSION['openChatBoxes'] as $chatbox => $void) { + $items .= chatBoxSession($chatbox); + } + } + + if ($items != '') { + $items = substr($items, 0, -1); + } + + $return = array('username' => api_get_user_id(), 'items' => $items); + echo json_encode($return); + exit; + } + + function send($from_user_id, $to_user_id, $message) { + $from = $_SESSION['username']; + $to = $_POST['to']; + $message = $_POST['message']; + + $_SESSION['openChatBoxes'][$_POST['to']] = date('Y-m-d H:i:s', time()); + + $messagesan = sanitize($message); + + if (!isset($_SESSION['chatHistory'][$_POST['to']])) { + $_SESSION['chatHistory'][$_POST['to']] = ''; + } + + $_SESSION['chatHistory'][$_POST['to']] .= <<",$text); + return $text; + } +} \ No newline at end of file diff --git a/main/inc/lib/javascript/chat/css/chat.css b/main/inc/lib/javascript/chat/css/chat.css index eee0055ba0..9dfd3acfc7 100644 --- a/main/inc/lib/javascript/chat/css/chat.css +++ b/main/inc/lib/javascript/chat/css/chat.css @@ -6,12 +6,11 @@ } .chatboxhead { - background-color: #f99d39; + background-color: #222; padding:7px; color: #ffffff; - - border-right:1px solid #f99d39; - border-left:1px solid #f99d39; + border-right:1px solid #222; + border-left:1px solid #222; } .chatboxblink { @@ -88,5 +87,7 @@ } .chatboxtitle { + font-weight: bold; float: left; + font-size: 13px; } \ No newline at end of file diff --git a/main/inc/lib/javascript/chat/js/chat.js b/main/inc/lib/javascript/chat/js/chat.js index 341517c003..f01cd5f579 100644 --- a/main/inc/lib/javascript/chat/js/chat.js +++ b/main/inc/lib/javascript/chat/js/chat.js @@ -6,6 +6,9 @@ This script may be used for non-commercial purposes only. For any commercial purposes, please contact the author at anant.garg@inscripts.com +Changes and Chamilo Integration: Julio Montoya + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -31,6 +34,8 @@ var newMessages = new Array(); var newMessagesWin = new Array(); var chatBoxes = new Array(); +//var ajax_url = 'chat.php'; variable loaded in header.inc.php + $(document).ready(function(){ originalTitle = document.title; startChatSession(); @@ -43,44 +48,90 @@ $(document).ready(function(){ }); }); + + +function startChatSession(){ + $.ajax({ + url: ajax_url+"?action=startchatsession", + cache: false, + dataType: "json", + success: function(data) { + if (data) { + username = data.username; + + $.each(data.items, function(i,item){ + if (item) { // fix strange ie bug + my_user_id = item.f; + + if ($("#chatbox_"+my_user_id).length <= 0) { + createChatBox(my_user_id, chatboxtitle, 1); + } + + if (item.s == 1) { + item.f = username; + } + + if (item.s == 2) { + $("#chatbox_"+my_user_id+" .chatboxcontent").append('
'+item.m+'
'); + } else { + $("#chatbox_"+my_user_id+" .chatboxcontent").append('
'+item.f+':  '+item.m+'
'); + } + } + }); + + for (i=0;i 0) { - if ($("#chatbox_"+chatboxtitle).css('display') == 'none') { - $("#chatbox_"+chatboxtitle).css('display','block'); +function createChatBox(user_id, chatboxtitle, minimizeChatBox) { + if ($("#chatbox_"+user_id).length > 0) { + if ($("#chatbox_"+user_id).css('display') == 'none') { + $("#chatbox_"+user_id).css('display','block'); restructureChatBoxes(); } - $("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus(); + $("#chatbox_"+user_id+" .chatboxtextarea").focus(); return; } - $("
" ).attr("id","chatbox_"+chatboxtitle) + $("
" ).attr("id","chatbox_"+user_id) .addClass("chatbox") - .html('
'+chatboxtitle+'

') + .html('
\n\ +
'+chatboxtitle+'
\n\ +
_  \n\ + X

\n\ +
\n\ +
') .appendTo($( "body" )); - $("#chatbox_"+chatboxtitle).css('bottom', '0px'); + $("#chatbox_"+user_id).css('bottom', '0px'); chatBoxeslength = 0; @@ -91,13 +142,13 @@ function createChatBox(chatboxtitle,minimizeChatBox) { } if (chatBoxeslength == 0) { - $("#chatbox_"+chatboxtitle).css('right', '20px'); + $("#chatbox_"+user_id).css('right', '20px'); } else { width = (chatBoxeslength)*(225+7)+20; - $("#chatbox_"+chatboxtitle).css('right', width+'px'); + $("#chatbox_"+user_id).css('right', width+'px'); } - chatBoxes.push(chatboxtitle); + chatBoxes.push(user_id); if (minimizeChatBox == 1) { minimizedChatBoxes = new Array(); @@ -107,36 +158,36 @@ function createChatBox(chatboxtitle,minimizeChatBox) { } minimize = 0; for (j=0;j'+item.m+'
'); + $("#chatbox_"+my_user_id+" .chatboxcontent").append('
'+item.m+'
'); } else { - newMessages[chatboxtitle] = true; - newMessagesWin[chatboxtitle] = true; + newMessages[my_user_id] = true; + newMessagesWin[my_user_id] = true; $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.f+':  '+item.m+'
'); } - $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight); + $("#chatbox_"+my_user_id+" .chatboxcontent").scrollTop($("#chatbox_"+my_user_id+" .chatboxcontent")[0].scrollHeight); itemsfound += 1; } }); @@ -238,7 +289,7 @@ function closeChatBox(chatboxtitle) { $('#chatbox_'+chatboxtitle).css('display','none'); restructureChatBoxes(); - $.post("chat.php?action=closechat", { chatbox: chatboxtitle} , function(data){ + $.post(ajax_url+"?action=closechat", { chatbox: chatboxtitle} , function(data){ }); } @@ -283,7 +334,7 @@ function toggleChatBoxGrowth(chatboxtitle) { } -function checkChatBoxInputKey(event,chatboxtextarea,chatboxtitle) { +function checkChatBoxInputKey(event,chatboxtextarea, user_id) { if(event.keyCode == 13 && event.shiftKey == 0) { message = $(chatboxtextarea).val(); @@ -292,11 +343,14 @@ function checkChatBoxInputKey(event,chatboxtextarea,chatboxtitle) { $(chatboxtextarea).val(''); $(chatboxtextarea).focus(); $(chatboxtextarea).css('height','44px'); + if (message != '') { - $.post("chat.php?action=sendchat", {to: chatboxtitle, message: message} , function(data){ + $.post(ajax_url + "?action=sendchat", {to: user_id, message: message} , function(data){ message = message.replace(//g,">").replace(/\"/g,"""); - $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+username+':  '+message+'
'); - $("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight); + $("#chatbox_"+user_id+" .chatboxcontent").append('
\n\ + '+username+':  \n\ + '+message+'
'); + $("#chatbox_"+user_id+" .chatboxcontent").scrollTop($("#chatbox_"+user_id+" .chatboxcontent")[0].scrollHeight); }); } chatHeartbeatTime = minChatHeartbeat; @@ -320,46 +374,6 @@ function checkChatBoxInputKey(event,chatboxtextarea,chatboxtitle) { } -function startChatSession(){ - $.ajax({ - url: "chat.php?action=startchatsession", - cache: false, - dataType: "json", - success: function(data) { - - username = data.username; - - $.each(data.items, function(i,item){ - if (item) { // fix strange ie bug - - chatboxtitle = item.f; - - if ($("#chatbox_"+chatboxtitle).length <= 0) { - createChatBox(chatboxtitle,1); - } - - if (item.s == 1) { - item.f = username; - } - - if (item.s == 2) { - $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.m+'
'); - } else { - $("#chatbox_"+chatboxtitle+" .chatboxcontent").append('
'+item.f+':  '+item.m+'
'); - } - } - }); - - for (i=0;i'; } else { - $img_array = UserManager::get_user_picture_path_by_id($user_id,'web',true,true); - + $img_array = UserManager::get_user_picture_path_by_id($user_id,'web',true,true); $big_image = UserManager::get_picture_user($user_id, $img_array['file'],'', USER_IMAGE_SIZE_BIG); $big_image = $big_image['file'].'?'.uniqid(); $normal_image = $img_array['dir'].$img_array['file'].'?'.uniqid(); @@ -684,7 +683,11 @@ class SocialManager extends UserManager { if ($user_id != api_get_user_id()) { echo '
  • '; - echo Display::return_icon('compose_message.png',get_lang('SendMessage')).'  '.get_lang('SendMessage').'
  • '; + echo Display::return_icon('compose_message.png',get_lang('SendMessage')).'  '.get_lang('SendMessage').''; + + $user_info = api_get_user_info($user_id); + $user_name =$user_info['complete_name']; + echo Display::tag('li', Display::url(Display::return_icon('chat.gif').get_lang('chat'), 'javascript:void(0);', array('onclick' => "javascript:chatWith('".$user_id."', '".$user_name."')"))); } //check if I already sent an invitation message