[Vtigercrm-commits] [vtiger-commits] r7903 - in /branches/VTIGERCRM-5.0.2-MMBRICH: include/js/objects/CommSystem.js modules/CommSystem/CommSystem.php modules/CommSystem/CommSystemAjax.php
vtigercrm-commits at vtiger.fosslabs.com
vtigercrm-commits at vtiger.fosslabs.com
Fri Jul 7 18:59:59 EDT 2006
Author: mmbrich
Date: Fri Jul 7 16:59:58 2006
New Revision: 7903
Log:
added ability to send "User typing" status messages
Modified:
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
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 16:59:58 2006
@@ -4,7 +4,7 @@
CommSystem.prototype = {
initialize: function(element,CurrentUser) {
this.debug=true;
- this.refreshtime = '2000';
+ this.refreshtime = '1000';
this.username = VtUser.user_name;
this.sliderElement = element;
this.CheckSession();
@@ -108,12 +108,26 @@
this.Focused='false';
},
+ SendStatusMessage: function(period,users) {
+ new Ajax.Request(
+ 'index.php',
+ {queue: {position: 'end', scope: 'commsys'},
+ method: 'post',
+ postBody: 'module=CommSystem&action=CommSystemAjax&command=sendStatusMessage&receivers='+users+'&period='+period,
+ onComplete: function(response) {
+ //alert(response.responseText);
+ }
+ }
+ );
+ },
+
/*
* Function to send an instant message to another
* user and update the chat window element with
* message text.
*/
SendChatMessage: function(otheruser,msg) {
+ if(msg == "") {return;}
var myDate=new Date();
msgStruct = {
sending_user: otheruser,
@@ -339,17 +353,17 @@
var tname = "status_bar_"+Event.element(evt).name;
if(evt.type === "keypress") {
if(globalCommSystem.keycount == 0) {
- $(tname).innerHTML = "User is typing";
- this.keycount++;
- }
- this.keytimer = window.setTimeout('globalCommSystem.UserStopTyping("'+Event.element(evt).name+'")',2000);
+ globalCommSystem.SendStatusMessage('begin',Event.element(evt).name);
+ globalCommSystem.keycount++;
+ }
+ globalCommSystem.keytimer = window.setTimeout('globalCommSystem.UserStopTyping("'+Event.element(evt).name+'")',2000);
}
},
UserStopTyping: function(sending_user) {
- window.clearTimeout(this.keytimer);
- this.keycount=0;
- $("status_bar_"+sending_user).innerHTML = "Stopped typing...";
+ window.clearTimeout(globalCommSystem.keytimer);
+ globalCommSystem.keycount=0;
+ globalCommSystem.SendStatusMessage('end',sending_user);
},
MarkAsRead: function(msgid) {
@@ -373,6 +387,7 @@
//$("debug_win").innerHTML += "<BR>"+responseData.responseText;
try {
if(!responseData.responseText.match(/none/)) {
+ //alert(responseData.responseText);
var msgs = eval('(' + responseData.responseText + ')');
for (var i=0;i<msgs.CommSysMessages.length;i++) {
try {
@@ -401,6 +416,14 @@
window.setTimeout('globalCommSystem.MarkAsRead("'+msgid+'")',3000);
globalCommSystem.ShowAlertSlider("<b>New Voicemial:</b><br> "+msgs.CommSysMessages[i].message.msg_data);
break;
+ case 'GENERAL':
+ window.setTimeout('globalCommSystem.MarkAsRead("'+msgid+'")',3000);
+ globalCommSystem.ShowAlertSlider("<b>New Voicemial:</b><br> "+msgs.CommSysMessages[i].message.msg_data);
+ break;
+ case 'STATUS':
+ $("status_bar_"+msg.sending_user).innerHTML = msg.msg_data;
+ window.setTimeout('globalCommSystem.MarkAsRead("'+msgid+'")',3000);
+ break;
}
}catch(h){}
Try.these (
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 16:59:58 2006
@@ -5,11 +5,10 @@
msg_type: P2PIM = Peer to Peer Instant Message;
GRPIM = Group IM (receiver list is comma separated)
EMAIL = Email Alert (recordid is the related email ID)
- BATTACH = Attachment (msg_data == blob)
- RATTACH = Attachment (recordid == attachment recordid)
GENERAL = General Alert
INPHONE = Incoming Call Alert
VOICEMAIL = Voicemail Alert
+ STATUS = chat status messages (user it typing, etc)
recordid: record id of related CRM entity (if any)
sending_user: record id of the user sending the message
receivers: single or comma separated list of receiving CRM users
@@ -44,31 +43,27 @@
('".$msg_type."','".$sending_user."','".$receivers."','".addslashes($msg_data)."','".$nowdate."')";
break;
case 'EMAIL':
- if($recordid == 0 || $sending_user == 0) { return "false"; }
+ if($recordid == 0 || $sending_user == 0 || $receivers == 0) { return "false"; }
+ $q = "INSERT INTO vtiger_comm_system
+ (msg_type,sending_user,recordid,receivers,sentdate)
+ VALUES
+ ('".$msg_type."','".$sending_user."','".$recordid."','".$receivers."','".$nowdate."')";
+ break;
+ case 'GENERAL':
+ case 'INPHONE':
+ case 'VOICEMAIL':
+ if($receivers == 0 || $sending_user == 0) { return "false"; }
$q = "INSERT INTO vtiger_comm_system
(msg_type,sending_user,recordid,sentdate)
VALUES
- ('".$msg_type."','".$sending_user."','".$recordid."','".$nowdate."')";
+ ('".$msg_type."','".$sending_user."','".$receivers."','".$nowdate."')";
break;
- case 'BATTACH':
- if($sending_user == 0 || $receivers == 0) { return "false"; }
+ case 'STATUS':
+ if($receivers == 0 || $sending_user == 0) { return "false"; }
$q = "INSERT INTO vtiger_comm_system
- (msg_type,sending_user,receivers,msg_data,sentdate)
+ (msg_data,msg_type,sending_user,receivers,sentdate)
VALUES
- ('".$msg_type."','".$sending_user."','".$receivers."','".$msg_data."','".$nowdate."')";
- break;
- case 'RATTACH':
- if($sending_user == 0 || $recordid == 0 || $receivers == 0) { return "false"; }
- $q = "INSERT INTO vtiger_comm_system
- (msg_type,sending_user,receivers,recordid,sentdate)
- VALUES
- ('".$msg_type."','".$sending_user."','".$receivers."','".$recordid."','".$nowdate."')";
- break;
- case 'GENERAL':
- break;
- case 'INPHONE':
- break;
- case 'VOICEMAIL':
+ ('".$msg_data."','".$msg_type."','".$sending_user."','".$receivers."','".$nowdate."')";
break;
}
if(isset($q) && $q != "") {
@@ -81,17 +76,21 @@
function GetNewAlerts($userid,$get_old='') {
// This query will get all non-group/non-broadcast messages
if($get_old == 'true')
- $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' OR viewed = '1' AND msg_type='P2PIM'";
+ $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' OR viewed = '1' AND msg_type='P2PIM' ORDER BY sentdate";
else
- $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' AND msg_type='P2PIM'";
+ $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' AND msg_type='P2PIM' ORDER BY sentdate";
$p2p = $this->db->query($q);
// This query will get all group/broadcast messages
if($get_old == 'true')
- $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' OR viewed = '1' AND msg_type='GRPIM'";
+ $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' OR viewed = '1' AND msg_type='GRPIM' ORDER BY sentdate";
else
- $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' AND msg_type='GRPIM'";
+ $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' AND msg_type='GRPIM' ORDER BY sentdate";
$grp = $this->db->query($q);
+
+ // GET STATUS MESSAGES
+ $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' AND msg_type='STATUS' ORDER BY sentdate";
+ $stat = $this->db->query($q);
$ret = array();
// load return array with p2p messages
@@ -123,10 +122,24 @@
}
}
- if($get_old == 'true')
- $viewed='2';
- else
+ // load return array with status messages
+ while($row = $this->db->fetch_array($stat)) {
+ if($row["msgid"] != "" && isset($row["msgid"])) {
+ $ret[$c]["msgid"] = $row["msgid"];
+ $ret[$c]["msg_type"] = $row["msg_type"];
+ $ret[$c]["msg_data"] = $row["msg_data"];
+ $ret[$c]["sending_user"] = $row["sending_user"];
+ $ret[$c]["user_name"] = $row["user_name"];
+ $ret[$c]["sentdate"] = $row["sentdate"];
+ $c++;
+ }
+ }
+
+ //if($get_old == 'true')
+ //$viewed='2';
+ //else
$viewed='1';
+
$q = "UPDATE vtiger_comm_system SET viewed='".$viewed."' WHERE ";
for($i=0,$cnt=count($ret);$i<$cnt;$i++) {
if($i==0)
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 16:59:58 2006
@@ -4,10 +4,6 @@
require_once('include/utils/utils.php');
global $adb;
-
-//if($_POST["command"] == "getSessionValue" && $_POST["module"] == "User") {
- //echo "HellO";
-//}
if($_REQUEST["command"] == "getDbValues") {
$rs = $adb->query("select * from vtiger_users where id='".$_SESSION["authenticated_user_id"]."'");
@@ -103,6 +99,11 @@
else
echo nl2br($_REQUEST["msg"]);
}
+if($_REQUEST["command"] == "sendStatusMessage") {
+ $ret = send_typing_message($_REQUEST["receivers"]);
+ echo $ret;
+}
+
if($_REQUEST["command"] == "markAsRead") {
$q="Update vtiger_comm_system set viewed='2' where msgid='".$_REQUEST["msgid"]."'";
$adb->query($q);
@@ -114,4 +115,21 @@
$commSys = new CommSystem();
echo $commSys->CheckEmails();
}
+function send_typing_message($receivers) {
+ require_once("modules/CommSystem/CommSystem.php");
+ global $adb;
+ $commSys = new CommSystem();
+
+ if($_REQUEST["period"] == "begin")
+ $tmsg = "User is typing a message";
+ else
+ $tmsg = "User stopped typing";
+
+ $adb->query("delete from vtiger_comm_system where msg_type='STATUS' AND sending_user='".$_SESSION["authenticated_user_id"]."' AND receivers='".$receivers."'");
+
+ if($commSys->SendAlert($tmsg,'STATUS','0',$_SESSION["authenticated_user_id"],$receivers) == "false")
+ return "failed";
+ else
+ return "success";
+}
?>
More information about the vtigercrm-commits
mailing list