[Vtigercrm-commits] [vtiger-commits] r7887 - in /branches/VTIGERCRM-5.0.2-MMBRICH: Smarty/templates/Header.tpl Smarty/templates/HomePage.tpl include/js/objects/CommSystem.js modules/CommSystem/CommSystem.php modules/CommSystem/CommSystemAjax.php themes/blue/header.php
vtigercrm-commits at vtiger.fosslabs.com
vtigercrm-commits at vtiger.fosslabs.com
Fri Jul 7 04:24:19 EDT 2006
Author: mmbrich
Date: Fri Jul 7 02:24:18 2006
New Revision: 7887
Log:
partially working communications system with simple peer2peer IM
Modified:
branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/Header.tpl
branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/HomePage.tpl
branches/VTIGERCRM-5.0.2-MMBRICH/include/js/objects/CommSystem.js
branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystem.php
branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystemAjax.php
branches/VTIGERCRM-5.0.2-MMBRICH/themes/blue/header.php
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/Header.tpl
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/Header.tpl (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/Header.tpl Fri Jul 7 02:24:18 2006
@@ -427,7 +427,6 @@
return true;
}
-try {
/* START COMMUNICATIONS SYSTEM */
function openCommSystem() {
CS.OpenSlider();
@@ -437,7 +436,6 @@
addOnloadEvent(function() {
CS = new CommSystem("CommSliderDiv",VtUser);
});
-}catch(m){alert(m);}
</SCRIPT>
{/literal}
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/HomePage.tpl
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/HomePage.tpl (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/Smarty/templates/HomePage.tpl Fri Jul 7 02:24:18 2006
@@ -85,7 +85,12 @@
<td style="padding-right:0px;padding-left:10px;"><a href="javascript:;" onClick='fnvshobj(this,"miniCal");getMiniCal();'><img src="{$IMAGE_PATH}btnL3Calendar.gif" alt="{$APP.LBL_CALENDAR_ALT}" title="{$APP.LBL_CALENDAR_TITLE}" border=0></a></a></td>
<td style="padding-right:0px"><a href="javascript:;"><img src="{$IMAGE_PATH}btnL3Clock.gif" alt="{$APP.LBL_CLOCK_ALT}" title="{$APP.LBL_CLOCK_TITLE}" border=0 onClick="fnvshobj(this,'wclock');"></a></a></td>
<td style="padding-right:0px"><a href="#"><img src="{$IMAGE_PATH}btnL3Calc.gif" alt="{$APP.LBL_CALCULATOR_ALT}" title="{$APP.LBL_CALCULATOR_TITLE}" border=0 onClick="fnvshobj(this,'calculator_cont');fetch_calc();"></a></td>
- <td style="padding-right:10px"><a href="javascript:;" onClick='return window.open("index.php?module=Contacts&action=vtchat","Chat","width=450,height=400,resizable=1,scrollbars=1");'><img src="{$IMAGE_PATH}tbarChat.gif" alt="{$APP.LBL_CHAT_ALT}" title="{$APP.LBL_CHAT_TITLE}" border=0></a></td>
+ <td style="padding-right:10px">
+ <a href="javascript:;" onClick='openCommSystem();'>
+ <img src="{$IMAGE_PATH}tbarChat.gif" alt="{$APP.LBL_CHAT_ALT}" title="{$APP.LBL_CHAT_TITLE}" border=0>
+ </a>
+ </td>
+ <!-- <td style="padding-right:10px"><a href="javascript:;" onClick='return window.open("index.php?module=Contacts&action=vtchat","Chat","width=450,height=400,resizable=1,scrollbars=1");'><img src="{$IMAGE_PATH}tbarChat.gif" alt="{$APP.LBL_CHAT_ALT}" title="{$APP.LBL_CHAT_TITLE}" border=0></a></td> -->
<td style="padding-right:10px"><img src="{$IMAGE_PATH}btnL3Tracker.gif" alt="{$APP.LBL_LAST_VIEWED}" title="{$APP.LBL_LAST_VIEWED}" border=0 onClick="fnvshobj(this,'tracker');"></td>
</tr>
</table>
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/include/js/objects/CommSystem.js
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/include/js/objects/CommSystem.js (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/include/js/objects/CommSystem.js Fri Jul 7 02:24:18 2006
@@ -1,8 +1,10 @@
+try {
CommSystem = Class.create();
+} catch(r){alert(r);}
CommSystem.prototype = {
initialize: function(element,CurrentUser) {
this.debug=true;
- this.refreshtime = '5000';
+ this.refreshtime = '2000';
this.username = VtUser.user_name;
this.sliderElement = element;
this.CheckSession();
@@ -11,6 +13,7 @@
this.keycount=0;
this.keytimer;
this.user=CurrentUser;
+ this.tmpCount=0;
},
/*
@@ -19,15 +22,16 @@
*
*/
CommUpdate: function() {
+ window.clearTimeout(this.timer);
globalCommSystem = this;
- window.clearTimeout(this.timer);
new Ajax.Request(
'index.php',
{queue: {position: 'end', scope: 'commsys'},
method: 'post',
postBody: 'module=CommSystem&action=CommSystemAjax&command=getPeriodicalInfo',
- onComplete: this.HandleEvent,
+ onComplete: globalCommSystem.HandleEvent,
onFailure: function() {
+ alert("Failed");
window.clearTimeout(globalCommSystem.timer);
}
}
@@ -77,8 +81,8 @@
* Creates elements and populates with past info
*/
CheckSession: function() {
- window.clearTimeout(this.timer);
- this.CommUpdate();
+ window.clearTimeout(this.timer);
+ this.CommUpdate();
},
/*
@@ -90,7 +94,8 @@
msgStruct = {
sending_user: otheruser,
msg_data: msg,
- msg_type: 'P2PIM'
+ msg_type: 'P2PIM',
+ user_name: ''
}
globalCommSystem = this;
new Ajax.Request(
@@ -112,20 +117,21 @@
}
,
SendMsg: function(evt) {
- var dat = $("msg_input_"+Event.element(evt).name);
try {
- globalCommSystem.SendChatMessage(Event.element(evt).name,dat.value);
- }catch(e){alert(e);}
+ var dat = $("msg_input_"+Event.element(evt).name);
+ globalCommSystem.SendChatMessage(Event.element(evt).name,dat.value);
+ }catch(p){alert(p);}
dat.value = "";
},
- OpenChatSession: function(receivers) {
+ OpenChatSession: function(receivers,usr_name) {
msgStruct = {
sending_user: receivers,
msg_data: '',
- msg_type: 'P2PIM'
- }
- this.ShowNewChatMessage(msgStruct,"Chatting with: "+receivers);
+ msg_type: 'P2PIM',
+ user_name: usr_name
+ }
+ this.ShowNewChatMessage(msgStruct, "Chatting with "+usr_name);
},
/*
@@ -137,7 +143,12 @@
Try.these (
function() {
new Effect.Appear("msgwindow_"+msg.sending_user,{duration:'0.2'});
- $("chat_data_"+msg.sending_user).innerHTML += "<br>"+msg.msg_data;
+ if(msg.user_name != globalCommSystem.user.user_name)
+ msg.msg_data = "<BR><font color='red'>"+msg.user_name+"</font> "+msg.msg_data;
+ else
+ msg.msg_data = "<br>"+msg.msg_data;
+
+ $("chat_data_"+msg.sending_user).innerHTML += msg.msg_data;
globalCommSystem.ScrollChatWindow($("chat_data_"+msg.sending_user));
},
function() {
@@ -183,7 +194,15 @@
);
main_table.appendChild(top_bar);
- msg.msg_data +="<BR>";
+ Try.these (
+ function() {
+ if(msg.user_name != globalCommSystem.user.user_name) {return false;}
+ msg.msg_data = "<BR><font color='red'>"+msg.user_name+"</font>: "+msg.msg_data;
+ },
+ function() {
+ msg.msg_data += "<BR>";
+ }
+ );
var chat_data = Builder.node(
'tr',
{
@@ -228,7 +247,7 @@
$("msg_wrapper_"+msg.sending_user).innerHTML += '<input type="submit" class="button" value="Send" id="send_button_'+msg.sending_user+'" name="'+msg.sending_user+'">';
Event.observe($("msg_input_"+msg.sending_user), 'keypress', globalCommSystem.UserTyping.bindAsEventListener(this));
Event.observe($("send_button_"+msg.sending_user), 'click', globalCommSystem.SendMsg.bindAsEventListener(this));
- }catch(f){alert(f);}
+ }catch(g){alert(g);}
new Effect.Appear(main_table,{duration:'0.2'});
new Draggable(main_table);
@@ -267,6 +286,19 @@
$("status_bar_"+sending_user).innerHTML = "Stopped typing...";
},
+ MarkAsRead: function(msgid) {
+ new Ajax.Request(
+ 'index.php',
+ {queue: {position: 'end', scope: 'commsys'},
+ method: 'post',
+ postBody: 'module=CommSystem&action=CommSystemAjax&command=markAsRead&msgid='+msgid,
+ onComplete: function(response) {
+
+ }
+ }
+ );
+ },
+
/*
* function to parse JSON msg data
* and act on alerts or messages
@@ -275,15 +307,21 @@
* for messages (IMs) a window object will be built for the message.
*/
HandleEvent: function(responseData) {
+ globalCommSystem.tmpCount++;
if(!responseData.responseText.match(/none/)) {
var msgs = eval('(' + responseData.responseText + ')');
for (var i=0;i<msgs.CommSysMessages.length;i++) {
var msg = msgs.CommSysMessages[i].message;
var msgid = msg.msgid;
var msg_type = msg.msg_type;
+ if(globalCommSystem.tmpCount >= 2) {
+ globalCommSystem.tmpCount = 0;
+ //globalCommSystem.MarkAsRead(msgid);
+ }
+ if(msg.sending_user == globalCommSystem.user.user_id) {return;}
switch(msg_type) {
case 'P2PIM':
- globalCommSystem.ShowNewChatMessage(msg,"Message from matt");
+ globalCommSystem.ShowNewChatMessage(msg,"Chatting with "+msg.user_name);
break;
case 'GRPIM':
alert(msgs.CommSysMessages[i].message.msg_data);
@@ -297,11 +335,9 @@
case 'VOICEMAIL':
alert(msgs.CommSysMessages[i].message.msg_data);
break;
- default:
- break;
}
}
}
- this.timer = window.setTimeout('globalCommSystem.CommUpdate()',this.refreshtime);
+ globalCommSystem.timer = window.setTimeout('globalCommSystem.CommUpdate()',globalCommSystem.refreshtime);
}
}
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystem.php
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystem.php (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystem.php Fri Jul 7 02:24:18 2006
@@ -40,7 +40,7 @@
$q = "INSERT INTO vtiger_comm_system
(msg_type,sending_user,receivers,msg_data,sentdate)
VALUES
- ('".$msg_type."','".$sending_user."','".$receivers."','".$msg_data."','".$nowdate."')";
+ ('".$msg_type."','".$sending_user."','".$receivers."','".addslashes($msg_data)."','".$nowdate."')";
break;
case 'EMAIL':
if($recordid == 0 || $sending_user == 0) { return "false"; }
@@ -79,11 +79,11 @@
function GetNewAlerts($userid) {
// This query will get all non-group/non-broadcast messages
- $q = "SELECT * FROM vtiger_comm_system WHERE receivers='".$userid."' AND viewed = '0'";
+ $q = "SELECT vtiger_comm_system.*,vtiger_users.user_name FROM vtiger_comm_system INNER JOIN vtiger_users ON vtiger_users.id=vtiger_comm_system.sending_user WHERE receivers='".$userid."' AND viewed = '0'";
$p2p = $this->db->query($q);
// This query will get all group/broadcast messages
- $q = "SELECT * FROM vtiger_comm_system WHERE receivers LIKE '%,".$userid.",%' OR receivers LIKE '".$userid.",%' OR receivers LIKE '%,".$userid."' AND viewed = '0'";
+ $q = "SELECT vtiger_comm_system.*,vtiger_users.user_name FROM vtiger_comm_system INNER JOIN vtiger_users ON vtiger_users.id=vtiger_comm_system.sending_user WHERE receivers LIKE '%,".$userid.",%' OR receivers LIKE '".$userid.",%' OR receivers LIKE '%,".$userid."' AND viewed = '0'";
$grp = $this->db->query($q);
$ret = array();
@@ -96,6 +96,7 @@
$ret[$c]["msg_data"] = $row["msg_data"];
$ret[$c]["recordid"] = $row["recordid"];
$ret[$c]["sending_user"] = $row["sending_user"];
+ $ret[$c]["user_name"] = $row["user_name"];
$ret[$c]["sentdate"] = $row["sentdate"];
$c++;
}
@@ -109,6 +110,7 @@
$ret[$c]["msg_data"] = $row["msg_data"];
$ret[$c]["recordid"] = $row["recordid"];
$ret[$c]["sending_user"] = $row["sending_user"];
+ $ret[$c]["user_name"] = $row["user_name"];
$ret[$c]["sentdate"] = $row["sentdate"];
$c++;
}
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystemAjax.php
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystemAjax.php (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/modules/CommSystem/CommSystemAjax.php Fri Jul 7 02:24:18 2006
@@ -43,6 +43,7 @@
$ret .= '"msg_type":"'.$msg[$i]["msg_type"].'",';
$ret .= '"recordid":"'.$msg[$i]["recordid"].'",';
$ret .= '"sending_user":"'.$msg[$i]["sending_user"].'",';
+ $ret .= '"user_name":"'.$msg[$i]["user_name"].'",';
$ret .= '"timestamp":"'.$msg[$i]["sentdate"].'",';
$ret .= '"msg_data":"'.$msg[$i]["msg_data"].'"}';
@@ -63,4 +64,9 @@
else
echo nl2br($_REQUEST["msg"]);
}
+if($_REQUEST["command"] == "markAsRead") {
+ $q="Update vtiger_comm_system set viewed='2' where msgid='".$_REQUEST["msgid"]."'";
+ $adb->query($q);
+ echo "success";
+}
?>
Modified: branches/VTIGERCRM-5.0.2-MMBRICH/themes/blue/header.php
==============================================================================
--- branches/VTIGERCRM-5.0.2-MMBRICH/themes/blue/header.php (original)
+++ branches/VTIGERCRM-5.0.2-MMBRICH/themes/blue/header.php Fri Jul 7 02:24:18 2006
@@ -105,7 +105,7 @@
$rs = $adb->query($q);
$list = "<center><b>CRM Users:</b>";
while($row=$adb->fetch_array($rs)) {
- $list .= "<br><a href='javascript:;' onclick='CS.OpenChatSession(\"".$row["id"]."\");'>".$row["user_name"]."</a>";
+ $list .= "<br><a href='javascript:;' onclick='CS.OpenChatSession(\"".$row["id"]."\",\"".$row["user_name"]."\");'>".$row["user_name"]."</a>";
}
$list .= "</center>";
More information about the vtigercrm-commits
mailing list