Browse Source

Adding first draft for the user to user chat see #3565 (doesn't work yet)

Julio Montoya 13 years ago
parent
commit
d2b9f2d84b

+ 47 - 0
main/inc/ajax/chat.ajax.php

@@ -0,0 +1,47 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Responses to AJAX calls
+ */
+
+require_once '../global.inc.php';
+
+require_once api_get_path(LIBRARY_PATH).'chat.lib.php';
+
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
+
+if (api_is_anonymous()) {
+	exit;
+}
+
+$to_user_id = intval($_REQUEST['to']);
+$message = $_REQUEST['message'];
+
+if (!isset($_SESSION['chatHistory'])) {
+	$_SESSION['chatHistory'] = array();	
+}
+
+if (!isset($_SESSION['openChatBoxes'])) {
+	$_SESSION['openChatBoxes'] = array();	
+}
+	
+$chat = new Chat();
+
+switch ($action) {
+	case 'chatheartbeat':
+		$chat->heartbeat();			
+		break;		    		
+	case 'closechat':		
+		$chat->close();
+		break;		
+	case 'sendchat':		
+		$chat->send();
+		break;		
+	case 'startchatsession':
+		$chat->start_session();
+		break;		
+	default:
+        echo '';
+	
+}
+exit;

+ 8 - 0
main/inc/header.inc.php

@@ -143,6 +143,11 @@ 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>
 
+
+<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" />
+
 <script type="text/javascript">
 //<![CDATA[
 // This is a patch for the "__flash__removeCallback" bug, see FS#4378.
@@ -158,6 +163,9 @@ if ( ( navigator.userAgent.toLowerCase().indexOf('msie') != -1 ) && ( navigator.
             } ;
 	});
 }
+
+var ajax_url = '<?php echo api_get_path(WEB_AJAX_PATH).'chat.ajax.php'; ?>';
+
 //]]>
 </script>
 <?php

+ 143 - 0
main/inc/lib/chat.lib.php

@@ -0,0 +1,143 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+*	This is the array library for Chamilo.
+*	Include/require it in your code to use its functionality.
+*
+*	@package chamilo.library
+*/
+
+class Chat {
+	function __construct() {
+		
+	}
+	
+	function heartbeat() {
+		$to_user_id = api_get_user_id();
+	
+		$sql = "select * from chat where (chat.to = '".intval($to_user_id)."' AND recd = 0) order by id ASC";
+		$result = Database::query($sql);
+		$items = '';
+
+		$chatBoxes = array();
+		$items = array();
+		while ($chat = Database::fetch_array($result,'ASSOC')) {
+			if (!isset($_SESSION['openChatBoxes'][$chat['from']]) && isset($_SESSION['chatHistory'][$chat['from']])) {
+				$items = $_SESSION['chatHistory'][$chat['from']];
+			}
+			$chat['message'] = sanitize($chat['message']);
+			$item = array('s' => '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']] .= <<<EOD
+						   {
+				"s": "1",
+				"f": "{$to}",
+				"m": "{$messagesan}"
+		   },
+EOD;
+
+
+		unset($_SESSION['tsChatBoxes'][$_POST['to']]);
+
+		$sql = "insert into chat (chat.from,chat.to,message,sent) values ('".mysql_real_escape_string($from)."', '".mysql_real_escape_string($to)."','".mysql_real_escape_string($message)."',NOW())";
+		$query = mysql_query($sql);
+		echo "1";
+		exit;
+	}
+
+	function close() {
+		unset($_SESSION['openChatBoxes'][$_POST['chatbox']]);
+		echo "1";
+		exit;
+	}
+
+	function sanitize($text) {
+		$text = htmlspecialchars($text, ENT_QUOTES);
+		$text = str_replace("\n\r","\n",$text);
+		$text = str_replace("\r\n","\n",$text);
+		$text = str_replace("\n","<br>",$text);
+		return $text;
+	}
+}

+ 5 - 4
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;
 }

+ 104 - 90
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 <gugli100@gmail.com>
+
+
 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('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
+					} else {
+						$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
+					}
+				}
+			});
+
+			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_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
+			}
+			setTimeout('chatHeartbeat();',chatHeartbeatTime);
+		}		
+	}});
+}
+
+
 function restructureChatBoxes() {
 	align = 0;
 	for (x in chatBoxes) {
-		chatboxtitle = chatBoxes[x];
-
-		if ($("#chatbox_"+chatboxtitle).css('display') != 'none') {
+		user_id = chatBoxes[x];
+		if ($("#chatbox_"+user_id).css('display') != 'none') {
 			if (align == 0) {
-				$("#chatbox_"+chatboxtitle).css('right', '20px');
+				$("#chatbox_"+user_id).css('right', '20px');
 			} else {
 				width = (align)*(225+7)+20;
-				$("#chatbox_"+chatboxtitle).css('right', width+'px');
+				$("#chatbox_"+user_id).css('right', width+'px');
 			}
 			align++;
 		}
 	}
 }
 
-function chatWith(chatuser) {
-	createChatBox(chatuser);
-	$("#chatbox_"+chatuser+" .chatboxtextarea").focus();
+function chatWith(user_id, user_name) {
+	createChatBox(user_id, user_name);
+	$("#chatbox_"+user_id+" .chatboxtextarea").focus();
 }
 
-function createChatBox(chatboxtitle,minimizeChatBox) {
-	if ($("#chatbox_"+chatboxtitle).length > 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;
 	}
 
-	$(" <div />" ).attr("id","chatbox_"+chatboxtitle)
+	$("<div />" ).attr("id","chatbox_"+user_id)
 	.addClass("chatbox")
-	.html('<div class="chatboxhead"><div class="chatboxtitle">'+chatboxtitle+'</div><div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+chatboxtitle+'\')">-</a> <a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+chatboxtitle+'\')">X</a></div><br clear="all"/></div><div class="chatboxcontent"></div><div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+chatboxtitle+'\');"></textarea></div>')
+	.html('<div class="chatboxhead">\n\
+			<div class="chatboxtitle">'+chatboxtitle+'</div>\n\
+			<div class="chatboxoptions"><a href="javascript:void(0)" onclick="javascript:toggleChatBoxGrowth(\''+user_id+'\')"> _ </a>&nbsp;\n\
+			<a href="javascript:void(0)" onclick="javascript:closeChatBox(\''+user_id+'\')">X</a></div><br clear="all"/></div>\n\
+			<div class="chatboxcontent"></div>\n\
+			<div class="chatboxinput"><textarea class="chatboxtextarea" onkeydown="javascript:return checkChatBoxInputKey(event,this,\''+user_id+'\');"></textarea></div>')
 	.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<minimizedChatBoxes.length;j++) {
-			if (minimizedChatBoxes[j] == chatboxtitle) {
+			if (minimizedChatBoxes[j] == user_id) {
 				minimize = 1;
 			}
 		}
 
 		if (minimize == 1) {
-			$('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display','none');
-			$('#chatbox_'+chatboxtitle+' .chatboxinput').css('display','none');
+			$('#chatbox_'+user_id+' .chatboxcontent').css('display','none');
+			$('#chatbox_'+user_id+' .chatboxinput').css('display','none');
 		}
 	}
 
-	chatboxFocus[chatboxtitle] = false;
+	chatboxFocus[user_id] = false;
 
-	$("#chatbox_"+chatboxtitle+" .chatboxtextarea").blur(function(){
-		chatboxFocus[chatboxtitle] = false;
-		$("#chatbox_"+chatboxtitle+" .chatboxtextarea").removeClass('chatboxtextareaselected');
+	$("#chatbox_"+user_id+" .chatboxtextarea").blur(function(){
+		chatboxFocus[user_id] = false;
+		$("#chatbox_"+user_id+" .chatboxtextarea").removeClass('chatboxtextareaselected');
 	}).focus(function(){
-		chatboxFocus[chatboxtitle] = true;
-		newMessages[chatboxtitle] = false;
-		$('#chatbox_'+chatboxtitle+' .chatboxhead').removeClass('chatboxblink');
-		$("#chatbox_"+chatboxtitle+" .chatboxtextarea").addClass('chatboxtextareaselected');
+		chatboxFocus[user_id] = true;
+		newMessages[user_id] = false;
+		$('#chatbox_'+user_id+' .chatboxhead').removeClass('chatboxblink');
+		$("#chatbox_"+user_id+" .chatboxtextarea").addClass('chatboxtextareaselected');
 	});
 
-	$("#chatbox_"+chatboxtitle).click(function() {
-		if ($('#chatbox_'+chatboxtitle+' .chatboxcontent').css('display') != 'none') {
-			$("#chatbox_"+chatboxtitle+" .chatboxtextarea").focus();
+	$("#chatbox_"+user_id).click(function() {
+		if ($('#chatbox_'+user_id+' .chatboxcontent').css('display') != 'none') {
+			$("#chatbox_"+user_id+" .chatboxtextarea").focus();
 		}
 	});
 
-	$("#chatbox_"+chatboxtitle).show();
+	$("#chatbox_"+user_id).show();
 }
 
 
@@ -182,21 +233,21 @@ function chatHeartbeat(){
 	}
 	
 	$.ajax({
-	  url: "chat.php?action=chatheartbeat",
+	  url: ajax_url+"?action=chatheartbeat",
 	  cache: false,
 	  dataType: "json",
 	  success: function(data) {
 
-		$.each(data.items, function(i,item){
+		$.each(data.items, function(i, item) {
 			if (item)	{ // fix strange ie bug
 
-				chatboxtitle = item.f;
+				my_user_id = item.f;
 
-				if ($("#chatbox_"+chatboxtitle).length <= 0) {
-					createChatBox(chatboxtitle);
+				if ($("#chatbox_"+my_user_id).length <= 0) {
+					createChatBox(my_user_id);
 				}
-				if ($("#chatbox_"+chatboxtitle).css('display') == 'none') {
-					$("#chatbox_"+chatboxtitle).css('display','block');
+				if ($("#chatbox_"+my_user_id).css('display') == 'none') {
+					$("#chatbox_"+my_user_id).css('display','block');
 					restructureChatBoxes();
 				}
 				
@@ -205,14 +256,14 @@ function chatHeartbeat(){
 				}
 
 				if (item.s == 2) {
-					$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
+					$("#chatbox_"+my_user_id+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
 				} else {
-					newMessages[chatboxtitle] = true;
-					newMessagesWin[chatboxtitle] = true;
+					newMessages[my_user_id] = true;
+					newMessagesWin[my_user_id] = true;
 					$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
 				}
 
-				$("#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,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;");
-				$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+username+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+message+'</span></div>');
-				$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
+				$("#chatbox_"+user_id+" .chatboxcontent").append('<div class="chatboxmessage">\n\
+				<span class="chatboxmessagefrom">'+username+':&nbsp;&nbsp;</span>\n\
+				<span class="chatboxmessagecontent">'+message+'</span></div>');
+				$("#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('<div class="chatboxmessage"><span class="chatboxinfo">'+item.m+'</span></div>');
-				} else {
-					$("#chatbox_"+chatboxtitle+" .chatboxcontent").append('<div class="chatboxmessage"><span class="chatboxmessagefrom">'+item.f+':&nbsp;&nbsp;</span><span class="chatboxmessagecontent">'+item.m+'</span></div>');
-				}
-			}
-		});
-		
-		for (i=0;i<chatBoxes.length;i++) {
-			chatboxtitle = chatBoxes[i];
-			$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);
-			setTimeout('$("#chatbox_"+chatboxtitle+" .chatboxcontent").scrollTop($("#chatbox_"+chatboxtitle+" .chatboxcontent")[0].scrollHeight);', 100); // yet another strange ie bug
-		}
-	
-	setTimeout('chatHeartbeat();',chatHeartbeatTime);
-		
-	}});
-}
 
 /**
  * Cookie plugin

+ 6 - 3
main/inc/lib/social.lib.php

@@ -607,8 +607,7 @@ class SocialManager extends UserManager {
 		  	echo '</div>';
 		  	
 	  	} 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  '<li><a href="'.api_get_path(WEB_PATH).'main/messages/send_message_to_userfriend.inc.php?height=300&width=470&user_friend='.$user_id.'&view=profile&view_panel=1" class="thickbox" title="'.get_lang('SendMessage').'">';
-	  			echo  Display::return_icon('compose_message.png',get_lang('SendMessage')).'&nbsp;&nbsp;'.get_lang('SendMessage').'</a></li>';
+	  			echo  Display::return_icon('compose_message.png',get_lang('SendMessage')).'&nbsp;&nbsp;'.get_lang('SendMessage').'</a></li>';				
+				
+				$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