From a3297ee3ea98d16fbd010ea93a8e824a09c92e72 Mon Sep 17 00:00:00 2001 From: Evgeny Gryaznov Date: Fri, 3 Oct 2008 15:11:02 +0000 Subject: [PATCH] first message, user agent, userid git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@150 c66351dc-e62f-0410-b875-e3a5c0b9693f --- src/messenger/js/users.js | 5 +++ src/messenger/webim/client.php | 7 +++- src/messenger/webim/install/dbinfo.php | 5 ++- src/messenger/webim/install/dbperform.php | 12 +++++++ src/messenger/webim/js/brws.js | 2 +- src/messenger/webim/js/users.js | 2 +- src/messenger/webim/libs/chat.php | 37 +++++++++++++------ src/messenger/webim/operator/update.php | 43 +++++++++++++++++++++-- src/messenger/webim/thread.php | 7 +++- 9 files changed, 102 insertions(+), 18 deletions(-) diff --git a/src/messenger/js/users.js b/src/messenger/js/users.js index 8bbc29cd..84abcf1f 100644 --- a/src/messenger/js/users.js +++ b/src/messenger/js/users.js @@ -113,6 +113,11 @@ var HtmlGenerationUtils = { gen += ''; cellsCount++; } + if( message != "" ) { + gen += ''; + gen += message.length > 30 ? message.substring(0,30) + '...' : message; + gen += ''; + } return HtmlGenerationUtils.generateOneRowTable(gen); } }; diff --git a/src/messenger/webim/client.php b/src/messenger/webim/client.php index f1bf0cc8..c4d1fa7f 100644 --- a/src/messenger/webim/client.php +++ b/src/messenger/webim/client.php @@ -32,9 +32,14 @@ if( !isset($_GET['token']) || !isset($_GET['thread']) ) { $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; $extAddr = $_SERVER['REMOTE_ADDR']; + if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && + $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) { + $extAddr = $_SERVER['REMOTE_ADDR'].' ('.$_SERVER['HTTP_X_FORWARDED_FOR'].')'; + } + $userbrowser = $_SERVER['HTTP_USER_AGENT']; $remoteHost = isset($_SERVER['REMOTE_HOST']) ? $_SERVER['REMOTE_HOST'] : $extAddr; $visitor = $remote_visitor(); - $thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale); + $thread = create_thread($visitor['name'], $remoteHost, $referer,$current_locale,$visitor['id'], $userbrowser); $_SESSION['threadid'] = $thread['threadid']; if( $referer ) { post_message($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referer))); diff --git a/src/messenger/webim/install/dbinfo.php b/src/messenger/webim/install/dbinfo.php index 8602469d..7bb18de8 100644 --- a/src/messenger/webim/install/dbinfo.php +++ b/src/messenger/webim/install/dbinfo.php @@ -16,6 +16,7 @@ $dbtables = array( "chatthread" => array( "threadid" => "int NOT NULL auto_increment PRIMARY KEY", "userName" => "varchar(64) NOT NULL", + "userid" => "varchar(255)", "agentName" => "varchar(64)", "agentId" => "int NOT NULL DEFAULT 0", "dtmcreated" => "datetime DEFAULT 0", @@ -31,6 +32,8 @@ $dbtables = array( "lastpingagent" => "datetime DEFAULT 0", "userTyping" => "int DEFAULT 0", "agentTyping" => "int DEFAULT 0", + "shownmessageid" => "int NOT NULL DEFAULT 0", + "userAgent" => "varchar(255)", "messageCount" => "varchar(16)" ), @@ -67,7 +70,7 @@ $dbtables = array( $memtables = array(); $dbtables_can_update = array( - "chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent"), + "chatthread" => array("agentId", "userTyping", "agentTyping", "messageCount", "nextagent", "shownmessageid", "userid", "userAgent"), "chatmessage" => array("agentId"), ); diff --git a/src/messenger/webim/install/dbperform.php b/src/messenger/webim/install/dbperform.php index 9e198ec1..934aa097 100644 --- a/src/messenger/webim/install/dbperform.php +++ b/src/messenger/webim/install/dbperform.php @@ -98,6 +98,18 @@ if ($act == "silentcreateall") { runsql("ALTER TABLE chatthread ADD nextagent int NOT NULL DEFAULT 0", $link); } + if( in_array("chatthread.shownmessageid", $absent) ) { + runsql("ALTER TABLE chatthread ADD shownmessageid int NOT NULL DEFAULT 0", $link); + } + + if( in_array("chatthread.userid", $absent) ) { + runsql("ALTER TABLE chatthread ADD userid varchar(255) DEFAULT \"\"", $link); + } + + if( in_array("chatthread.userAgent", $absent) ) { + runsql("ALTER TABLE chatthread ADD userAgent varchar(255)", $link); + } + $res = runsql("select null from information_schema.statistics where table_name = 'chatmessage' and index_name = 'idx_agentid'", $link); if(mysql_num_rows($res) == 0) { runsql("ALTER TABLE chatmessage ADD INDEX idx_agentid (agentid)", $link); diff --git a/src/messenger/webim/js/brws.js b/src/messenger/webim/js/brws.js index 20e92b21..dbbf770e 100644 --- a/src/messenger/webim/js/brws.js +++ b/src/messenger/webim/js/brws.js @@ -1 +1 @@ -var myAgent="";var rk=0;var myRealAgent="";function sk(){var tk=["\u006f\u0070\145r\u0061","\u006d\163\151\u0065","\u0073af\u0061\u0072\151","\u0066i\162\u0065\u0066\u006fx","\u006eet\u0073\143a\160\145","\155\u006f\172i\u006cl\141"];var lj=navigator.userAgent.toLowerCase();for(var i=0;i';} ,di:function(content){return'\074\u0074ab\u006c\145 w\u0069dth\075"\06100%"\040ce\u006cl\u0073\u0070a\143\u0069ng\u003d"\u0030"\u0020\u0063e\154\u006c\u0070\141dd\u0069\156g\u003d"\060"\040bo\162d\145\162\u003d"\u0030"\076\074\164r\u003e'+content+'\074/\164\141\142le>';} ,ei:function(fi,gi,id,ai,bi,ci,ct,vi){var wi=2;var link=gi+"\077\164\150\162e\141\u0064\075"+id;var xi='\074t\u0064\u0020c\154a\163s\075"ta\u0062l\u0065"\040\u0073\164\u0079le\u003d"\160a\144\u0064\151ng-\u006ce\u0066t\u003a0p\170\073\040\u0070\141\144ding-\162i\147\150t\072\u0030\u0070x\u003b"\076';xi+=si.ki((vi||!ai)?link:link+"\046\u0076\151ew\u006f\156\154y=\164ru\u0065",localized[bi?0:1],"I\155Ce\u006e\u0074er"+id,fi,01130,0644,ci);xi+='\074/\164d\076<\057\164d\u003e';if(bi){xi+='';xi+=si.ki(link,localized[0],"ImCe\156\u0074\145r"+id,'\074\151m\147\u0020sr\143\075"'+st+'\u002fi\u006dag\u0065\u0073\u002ft\142li\143\u006c\u0073\160\u0065ak\u002e\147i\146"\040\u0077i\u0064t\u0068\u003d"\061\065"\040\u0068\145\151\u0067\u0068\164\u003d"1\u0035" bo\u0072de\u0072="0"\040\141\154\164\u003d"'+localized[0]+'"\076',01130,0644,null);xi+='<\057\u0074d\076';wi++;} if(ai){xi+='';xi+=si.ki(link+"\046v\151\u0065wo\u006e\u006c\u0079=\u0074ru\u0065",localized[1],"\u0049\u006d\u0043\u0065n\164e\u0072"+id,'\074\u0069\u006d\u0067 \163\u0072\143="'+st+'\057\151m\141\147e\163\u002ft\u0062\154i\143lr\145a\144\056gif"\040\167\u0069d\u0074\150="\0615"\u0020\150e\u0069ght="\061\065" \u0062or\144\145\u0072\075"\u0030"\u0020\141\154t\075"'+localized[1]+'"\076',0x258,0644,null);xi+='\074/\164\144\076';wi++;} return si.di(xi);} } ;sq.yi=mn.nn();mn.sn(sq.yi,sq.lq,{qn:function(pq){this.oq(pq);this.pq.ri=this.ri.on(this);this.pq.iu=this.iu.on(this);this.pq.hu=this.hu.on(this);this.pq.zi=0;this.$i=new Object();this._i=0;this.t=this.pq.mj;this.nj=new sq.qi(this.pq);} ,ri:function(){return"co\155pan\u0079="+this.pq.company+"\u0026\u0073\u0069nc\145="+this.pq.zi;} ,$t:function(ku){this.pq.status.innerHTML=ku;} ,iu:function(s){this.$t(s);} ,qj:function(rh){var id,rj,sj,ai=false,bi=false,ci=null;for(var i=0;i=ej.rowIndex)){si.ui(this.t,ji.rowIndex+1);this.t.deleteRow(ji.rowIndex);this.$i[id]=null;ji=null;} if(ji==null){ji=this.t.insertRow(dj.rowIndex+1);si.ii(this.t,dj.rowIndex+2);ji.id="t\u0068\u0072"+id;this.$i[id]=new Array(kj,oj,rj);ls.insertCell(ji,"n\u0061\u006de","\164ab\154e",null,(20+10),si.ei(ij,this.pq.agentservl,id,ai,bi,ci,ct,rj!='c\u0068\u0061\164'));si.ti(ji);ls.insertCell(ji,"c\157\156\164i\144","t\141ble","\143e\156\164e\162",null,jj);si.ti(ji);ls.insertCell(ji,"\u0073tate","\u0074\u0061b\154e","\143\145\u006e\u0074er",null,sj);si.ti(ji);ls.insertCell(ji,"\u006f\160","\u0074a\142\u006c\u0065","\u0063e\156\u0074\145\162",null,lj);si.ti(ji);ls.insertCell(ji,"\u0074i\155e","t\u0061\u0062\u006ce","\143\u0065nt\145\162",null,this.fj(kj));si.ti(ji);ls.insertCell(ji,"w\u0061it","\164a\u0062l\145","\143\u0065\u006ete\u0072",null,(rj!='\u0063\150\141t'?this.fj(oj):'\055'));si.ti(ji);ls.insertCell(ji,"\145t\u0063","t\u0061\142\u006c\145","\u0063\145nte\u0072",null,pj);if(rj=='\u0077\u0061\u0069\164'||rj=='\u0070\162\151\u006f')return true;} else{this.$i[id]=new Array(kj,oj,rj);uj(this.t,ji,"\u006e\141me",si.ei(ij,this.pq.agentservl,id,ai,bi,ci,ct,rj!='\143\u0068a\u0074'));uj(this.t,ji,"\143ont\u0069\144",jj);uj(this.t,ji,"\u0073\u0074a\u0074\145",sj);uj(this.t,ji,"\u006fp",lj);uj(this.t,ji,"ti\155\u0065",this.fj(kj));uj(this.t,ji,"\167ai\u0074",(rj!='c\150a\164'?this.fj(oj):'-'));uj(this.t,ji,"\145\u0074\u0063",pj);} return false;} ,gj:function(){function aj(t,id,bj){var dj=t.rows[id];var ej=t.rows[id+"e\u006ed"];if(dj==null||ej==null)return;var cj=ej.cells["s\164\141\164u\u0073"];if(cj==null)return;cj.innerHTML=(dj.rowIndex+1==ej.rowIndex)?bj:"";cj.height=(dj.rowIndex+1==ej.rowIndex)?0x1e:(9+1);} aj(this.t,"\167ai\u0074",this.pq.noclients);aj(this.t,"\u0070\162\151\u006f",this.pq.noclients);aj(this.t,"\u0063\u0068\141\u0074",this.pq.noclients);} ,fj:function(vj){var wj=Math.floor(((new Date()).getTime()-vj-this._i)/0x3e8);var xj=Math.floor(wj/(46+14));var yj="";wj=wj%074;if(wj<(6+4))wj="0"+wj;if(xj>=074){var zj=Math.floor(xj/(55+5));xj=xj%074;if(xj<012)xj="\060"+xj;yj=zj+"\072";} return yj+xj+"\072"+wj;} ,$j:function(){for(var i in this.$i){if(this.$i[i]!=null){var value=this.$i[i];var ji=ls.os("\164\u0068r"+i,this.t);if(ji!=null){function uj(ds,ji,id,hj){var ws=ls.fs(id,ji,ds);if(ws)ws.innerHTML=hj;} uj(this.t,ji,"\164\u0069\u006d\145",this.fj(value[0]));uj(this.t,ji,"\u0077\u0061i\u0074",(value[2]!='\u0063\u0068\u0061\164'?this.fj(value[1]):'-'));} } } } ,hu:function(_j){var mk=false;if(_j.tagName=='t\u0068\u0072e\141d\u0073'){var nk=qs.ks(_j,"time");var qk=qs.ks(_j,"rev\u0069si\u006f\u006e");if(nk)this._i=(new Date()).getTime()-nk;if(qk)this.pq.zi=qk;for(var i=0;i<_j.childNodes.length;i++){var rh=_j.childNodes[i];if(rh.tagName=='\164hr\145ad')if(this.qj(rh))mk=true;} this.gj();this.$j();this.$t("\125\160 \164\157\040\144a\u0074\145");if(mk){xs(st+'\057\u0073o\u0075\u006e\144\163\u002f\156ew\137\u0075\u0073er.\u0077\141\166');window.focus();} } else if(_j.tagName=='e\u0072ro\162'){this.$t(qs.rs(_j,"de\163\u0063\u0072"));} else{this.$t("\u0072\145\u0063o\156n\145\143\164\u0069n\147");} } } );var st="";kr.lr(window,'on\u006c\u006f\u0061\144',function(){st=updaterOptions.wroot;new sq.yi(({mj:$("\u0074\u0068r\u0065a\144l\151st"),status:$("co\u006e\u006es\164\141\u0074u\163")} ).un(updaterOptions||{} ));} ); \ No newline at end of file +sq.qi=mn.nn();mn.sn(sq.qi,sq.lq,{qn:function(pq){this.oq(pq);this.pq.onComplete=this.ot.on(this);this.pq.jr=this.pt.on(this);this.pq.hr=this._q.on(this);this.pq.timeout=(3262+1738);this.frequency=(this.pq.frequency||2);this.dt={} ;this.xt();} ,pt:function(yt,zt){if(this.pq.iu)this.pq.iu("\u006fffli\156\u0065\054\040\162\u0065\143\u006f\156n\u0065c\u0074\151\156g");this._t();this.mu=setTimeout(this.xt.on(this),(723+277));} ,_q:function(yt){if(this.pq.iu)this.pq.iu("\164i\u006de\157\165\164\u002c\u0020\162\145c\157\u006e\156\u0065c\u0074i\u006e\147");this._t();this.mu=setTimeout(this.xt.on(this),(692+308));} ,_t:function(){if(this.dt.pq)this.dt.pq.onComplete=undefined;clearTimeout(this.mu);} ,xt:function(){if(this.pq.ri)this.pq.fq=(this.pq.ri)();this.dt=new sq.vq(this.pq.url,this.pq);} ,ot:function(ou){try{var uu=sq.uq(ou);if(uu){(this.pq.hu||sq.kq)(uu);} else{if(this.pq.iu)this.pq.iu("\u0072e\u0063onne\143\u0074\u0069\156\u0067");} } catch(e){} this.mu=setTimeout(this.xt.on(this),this.frequency*(667+333));} } );var si={ti:function(es){var ws=es.insertCell(-1);ws.style.backgroundImage='\u0075\u0072\154('+st+'/\151mag\145\163\057ta\142l\u0065\144i\u0076\u0033\056gi\146\u0029';ws.innerHTML='\u003ci\u006d\147\040src\075"'+st+'\057\u0069\155a\u0067es\u002f\u0066r\145\u0065\056\147\u0069\u0066"\040\u0077\151\144\u0074\u0068\075"\063"\040h\u0065\151\u0067\150t\u003d"\u0031"\u0020\142ord\145r="0"\040\u0061\154t\u003d""\u003e';} ,ui:function(ds,hi){ds.deleteRow(hi+2);ds.deleteRow(hi+1);ds.deleteRow(hi);} ,ii:function(ds,hi){var ji=ds.insertRow(hi);var ws=ji.insertCell(-1);ws.colSpan=015;ws.height=2;ji=ds.insertRow(hi);ws=ji.insertCell(-1);ws.colSpan=(12+1);ws.style.backgroundColor='\043\u00451E\u0031E1';ws.innerHTML='\u003c\u0069\155g \163\u0072\143\075"'+st+'/i\u006d\141\u0067\145\u0073/f\u0072\145e\u002e\u0067\u0069f" \u0077\u0069dt\u0068\075"\061"\040\150e\u0069g\u0068\164\u003d"\061" \142or\u0064e\u0072="\u0030" \u0061\154t=""\076';ji=ds.insertRow(hi);ws=ji.insertCell(-1);ws.colSpan=(9+4);ws.height=2;} ,ki:function(link,title,li,oi,width,height,pi){return'\074a \150r\u0065\u0066="'+link+'"'+(pi!=null?'\u0020\u0063l\141\163s\u003d"'+pi+'"':'')+' t\141\162\u0067e\164\075"\u005fb\u006can\153" \u0074i\u0074\154\145="'+title+'" onc\154i\u0063\u006b="\u0074\150\u0069s\056\156\145\u0077\127\151nd\157\167 \u003d \u0077i\156dow\u002e\157\160\145n\u0028\''+link+'\'\u002c\u0020\''+li+'\'\u002c\040\'\164oo\u006c\u0062a\u0072\075\060\054s\u0063\162\u006fl\154\u0062\u0061r\163\u003d\060,loc\141t\u0069on\u003d\u0030,s\u0074at\165s\075\061,\u006d\u0065\u006eu\142\141\162\u003d\u0030\054\u0077\u0069dt\u0068\075'+width+',\150eig\u0068\164='+height+',\162e\u0073i\172\u0061\142le\u003d\u0031\');\u0074h\u0069\u0073\056\u006eew\u0057ind\u006fw.\146\157c\165\163\u0028\u0029\u003bt\u0068\u0069\163\u002e\156\u0065\167\u0057\u0069\156d\157w\056o\u0070e\156e\162\u003d\167\151\u006e\u0064\157w;\u0072e\u0074urn \u0066\u0061\u006cs\u0065;"\u003e'+oi+'\074\u002f\u0061>';} ,di:function(content){return'\074\u0074ab\u006c\145 w\u0069dth\075"\06100%"\040ce\u006cl\u0073\u0070a\143\u0069ng\u003d"\u0030"\u0020\u0063e\154\u006c\u0070\141dd\u0069\156g\u003d"\060"\040bo\162d\145\162\u003d"\u0030"\076\074\164r\u003e'+content+'\074/\164\141\142le>';} ,ei:function(fi,gi,id,ai,bi,ci,ct,vi){var wi=2;var link=gi+"\077\164\150\162e\141\u0064\075"+id;var xi='\074t\u0064\u0020c\154a\163s\075"ta\u0062l\u0065"\040\u0073\164\u0079le\u003d"\160a\144\u0064\151ng-\u006ce\u0066t\u003a0p\170\073\040\u0070\141\144ding-\162i\147\150t\072\u0030\u0070x\u003b"\076';xi+=si.ki((vi||!ai)?link:link+"\046\u0076\151ew\u006f\156\154y=\164ru\u0065",localized[bi?0:1],"I\155Ce\u006e\u0074er"+id,fi,01130,0644,ci);xi+='\074/\164d\076<\057\164d\u003e';if(bi){xi+='';xi+=si.ki(link,localized[0],"ImCe\156\u0074\145r"+id,'\074\151m\147\u0020sr\143\075"'+st+'\u002fi\u006dag\u0065\u0073\u002ft\142li\143\u006c\u0073\160\u0065ak\u002e\147i\146"\040\u0077i\u0064t\u0068\u003d"\061\065"\040\u0068\145\151\u0067\u0068\164\u003d"1\u0035" bo\u0072de\u0072="0"\040\141\154\164\u003d"'+localized[0]+'"\076',01130,0644,null);xi+='<\057\u0074d\076';wi++;} if(ai){xi+='';xi+=si.ki(link+"\046v\151\u0065wo\u006e\u006c\u0079=\u0074ru\u0065",localized[1],"\u0049\u006d\u0043\u0065n\164e\u0072"+id,'\074\u0069\u006d\u0067 \163\u0072\143="'+st+'\057\151m\141\147e\163\u002ft\u0062\154i\143lr\145a\144\056gif"\040\167\u0069d\u0074\150="\0615"\u0020\150e\u0069ght="\061\065" \u0062or\144\145\u0072\075"\u0030"\u0020\141\154t\075"'+localized[1]+'"\076',0x258,0644,null);xi+='\074/\164\144\076';wi++;} if(ct!=""){xi+='\074/tr>\074\164\u0072\u003e<\164\144\u0020\u0063\154\141s\u0073="\146\151rstme\u0073\163\141g\145"\u0020al\151\147n\u003d"r\u0069\u0067h\164"\040\143ols\160\u0061\156\u003d"'+wi+'">\074\141\u0020h\u0072\145f="\152\u0061v\u0061sc\u0072ipt:\166\157\u0069\u0064\0500\u0029"\040t\151\164\u006ce="'+ct+'" o\156\u0063l\151\u0063\153\075"a\u006ce\162\u0074\u0028t\150\u0069\u0073.\164\u0069\164\u006ce\u0029\073\u0072\145\u0074urn f\141\u006c\u0073\145;">';xi+=ct.length>036?ct.substring(0,0x1e)+'.\056\056':ct;xi+='<\u002fa><\057\u0074d>';} return si.di(xi);} } ;sq.yi=mn.nn();mn.sn(sq.yi,sq.lq,{qn:function(pq){this.oq(pq);this.pq.ri=this.ri.on(this);this.pq.iu=this.iu.on(this);this.pq.hu=this.hu.on(this);this.pq.zi=0;this.$i=new Object();this._i=0;this.t=this.pq.mj;this.nj=new sq.qi(this.pq);} ,ri:function(){return"\u0063\157\155p\u0061n\171\u003d"+this.pq.company+"&s\u0069\156c\u0065\075"+this.pq.zi;} ,$t:function(ku){this.pq.status.innerHTML=ku;} ,iu:function(s){this.$t(s);} ,qj:function(rh){var id,rj,sj,ai=false,bi=false,ci=null;for(var i=0;i=ej.rowIndex)){si.ui(this.t,ji.rowIndex+1);this.t.deleteRow(ji.rowIndex);this.$i[id]=null;ji=null;} if(ji==null){ji=this.t.insertRow(dj.rowIndex+1);si.ii(this.t,dj.rowIndex+2);ji.id="t\150\162"+id;this.$i[id]=new Array(kj,oj,rj);ls.insertCell(ji,"\u006e\141\155\u0065","ta\u0062\u006c\u0065",null,(27+3),si.ei(ij,this.pq.agentservl,id,ai,bi,ci,ct,rj!='\u0063\u0068\u0061\u0074'));si.ti(ji);ls.insertCell(ji,"c\u006f\156\164id","t\141\u0062\u006c\145","\143\u0065n\u0074e\u0072",null,jj);si.ti(ji);ls.insertCell(ji,"\u0073\u0074\141\u0074\u0065","\164\u0061b\154\u0065","\u0063\145\u006eter",null,sj);si.ti(ji);ls.insertCell(ji,"\u006f\160","ta\u0062\154e","c\145nt\u0065r",null,lj);si.ti(ji);ls.insertCell(ji,"\u0074\u0069\u006d\145","t\141ble","c\145\156\u0074\145r",null,this.fj(kj));si.ti(ji);ls.insertCell(ji,"\167\u0061it","\u0074a\u0062l\145","c\u0065\u006e\164\145r",null,(rj!='\143\150at'?this.fj(oj):'-'));si.ti(ji);ls.insertCell(ji,"\u0065\164c","ta\u0062\154\145","c\u0065nt\145\162",null,pj);if(rj=='\167\u0061\u0069\u0074'||rj=='\160\u0072i\157')return true;} else{this.$i[id]=new Array(kj,oj,rj);uj(this.t,ji,"\156\141\155\u0065",si.ei(ij,this.pq.agentservl,id,ai,bi,ci,ct,rj!='\143\150a\u0074'));uj(this.t,ji,"\u0063\157\u006e\u0074\u0069d",jj);uj(this.t,ji,"\163\164a\164e",sj);uj(this.t,ji,"\157p",lj);uj(this.t,ji,"\u0074\151\155\145",this.fj(kj));uj(this.t,ji,"\167\141\151\u0074",(rj!='\u0063ha\u0074'?this.fj(oj):'\u002d'));uj(this.t,ji,"e\164\u0063",pj);} return false;} ,gj:function(){function aj(t,id,bj){var dj=t.rows[id];var ej=t.rows[id+"\u0065nd"];if(dj==null||ej==null)return;var cj=ej.cells["\u0073\u0074at\u0075s"];if(cj==null)return;cj.innerHTML=(dj.rowIndex+1==ej.rowIndex)?bj:"";cj.height=(dj.rowIndex+1==ej.rowIndex)?036:012;} aj(this.t,"\u0077\141\u0069\164",this.pq.noclients);aj(this.t,"\u0070\162i\157",this.pq.noclients);aj(this.t,"\143\150\u0061\164",this.pq.noclients);} ,fj:function(vj){var wj=Math.floor(((new Date()).getTime()-vj-this._i)/(684+316));var xj=Math.floor(wj/0x3c);var yj="";wj=wj%074;if(wj<(7+3))wj="\u0030"+wj;if(xj>=074){var zj=Math.floor(xj/(54+6));xj=xj%0x3c;if(xj<012)xj="\u0030"+xj;yj=zj+":";} return yj+xj+":"+wj;} ,$j:function(){for(var i in this.$i){if(this.$i[i]!=null){var value=this.$i[i];var ji=ls.os("t\150r"+i,this.t);if(ji!=null){function uj(ds,ji,id,hj){var ws=ls.fs(id,ji,ds);if(ws)ws.innerHTML=hj;} uj(this.t,ji,"tim\145",this.fj(value[0]));uj(this.t,ji,"w\u0061i\u0074",(value[2]!='\143hat'?this.fj(value[1]):'\u002d'));} } } } ,hu:function(_j){var mk=false;if(_j.tagName=='t\u0068r\145\u0061\u0064s'){var nk=qs.ks(_j,"\164\u0069m\u0065");var qk=qs.ks(_j,"r\145\u0076\u0069s\151\157\u006e");if(nk)this._i=(new Date()).getTime()-nk;if(qk)this.pq.zi=qk;for(var i=0;i<_j.childNodes.length;i++){var rh=_j.childNodes[i];if(rh.tagName=='\164\150\u0072\u0065\u0061d')if(this.qj(rh))mk=true;} this.gj();this.$j();this.$t("U\u0070 \u0074o\u0020\144\u0061\u0074e");if(mk){xs(st+'\057\163o\u0075\u006eds\057n\u0065\167\137u\u0073\u0065\162\056\167\u0061\166');window.focus();} } else if(_j.tagName=='e\u0072\u0072o\162'){this.$t(qs.rs(_j,"d\145s\u0063r"));} else{this.$t("rec\157\u006e\156\145\u0063t\151\156\147");} } } );var st="";kr.lr(window,'\u006fnl\157\u0061d',function(){st=updaterOptions.wroot;new sq.yi(({mj:$("\164hre\u0061d\u006c\u0069st"),status:$("\u0063o\156n\u0073t\141\164u\u0073")} ).un(updaterOptions||{} ));} ); \ No newline at end of file diff --git a/src/messenger/webim/libs/chat.php b/src/messenger/webim/libs/chat.php index 6d26d777..35e77b03 100644 --- a/src/messenger/webim/libs/chat.php +++ b/src/messenger/webim/libs/chat.php @@ -17,6 +17,7 @@ $connection_timeout = 30; // sec $simplenamecookie = "WEBIM_Name"; // 1.0.8 and earlier $namecookie = "WEBIM_Data"; // 1.0.9+ +$usercookie = "WEBIM_UserID"; $state_queue = 0; $state_waiting = 1; @@ -34,6 +35,10 @@ $kind_events = 6; $kind_to_string = array( $kind_user => "user", $kind_agent => "agent", $kind_for_agent => "hidden", $kind_info => "inf", $kind_conn => "conn", $kind_events => "event" ); +function get_user_id() { + return (time() + microtime()).rand(0,99999999); +} + function next_token() { return rand(99999,99999999); } @@ -165,10 +170,11 @@ function print_thread_messages($thread, $token, $lastid, $isuser, $format, $agen } } -function get_user_name($username, $addr) { +function get_user_name($username, $addr, $id) { global $presentable_name_pattern; return str_replace("{addr}", $addr, - str_replace("{name}", $username, $presentable_name_pattern)); + str_replace("{id}", $id, + str_replace("{name}", $username, $presentable_name_pattern))); } function is_ajax_browser($browserid,$ver,$useragent) { @@ -273,7 +279,7 @@ function setup_chatview_for_operator($thread,$operator) { $page['canpost'] = $thread['agentId'] == $operator['operatorid']; $page['ct.chatThreadId'] = $thread['threadid']; $page['ct.token'] = $thread['ltoken']; - $page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote'])); + $page['ct.user.name'] = topage(get_user_name($thread['userName'],$thread['remote'],$thread['userid'])); $page['ct.company.name'] = topage($settings['title']); $page['ct.company.chatLogoURL'] = topage($settings['logo']); @@ -281,7 +287,7 @@ function setup_chatview_for_operator($thread,$operator) { $page['send_shortcut'] = "Ctrl-Enter"; $page['isOpera95'] = is_agent_opera95(); $page['neediframesrc'] = needsFramesrc(); - + $page['historyParams'] = array("userid" => "".$thread['userid']); $page['predefinedList'] = explode("\n", getlocal_('chat.predefined_answers', $thread['locale'])); $params = "thread=".$thread['threadid']."&token=".$thread['ltoken']; $page['selfLink'] = "$webimroot/operator/agent.php?".$params; @@ -378,7 +384,7 @@ function close_thread($thread,$isuser) { function thread_by_id_($id,$link) { return select_one_row("select threadid,userName,agentName,agentId,lrevision,istate,ltoken,userTyping,agentTyping". - ",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent". + ",remote,referer,locale,unix_timestamp(lastpinguser) as lpuser,unix_timestamp(lastpingagent) as lpagent, unix_timestamp(CURRENT_TIMESTAMP) as current,nextagent,shownmessageid,userid,userAgent". " from chatthread where threadid = ". $id, $link ); } @@ -389,19 +395,21 @@ function thread_by_id($id) { return $thread; } -function create_thread($username,$remoteHost,$referer,$lang) { +function create_thread($username,$remoteHost,$referer,$lang,$userid,$userbrowser) { global $state_loading; $link = connect(); $query = sprintf( - "insert into chatthread (userName,ltoken,remote,referer,lrevision,locale,dtmcreated,dtmmodified,istate) values ". - "('%s',%s,'%s','%s',%s,'%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)", + "insert into chatthread (userName,userid,ltoken,remote,referer,lrevision,locale,userAgent,dtmcreated,dtmmodified,istate) values ". + "('%s','%s',%s,'%s','%s',%s,'%s','%s',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,$state_loading)", mysql_real_escape_string($username), + mysql_real_escape_string($userid), next_token(), mysql_real_escape_string($remoteHost), mysql_real_escape_string($referer), next_revision($link), - mysql_real_escape_string($lang) ); + mysql_real_escape_string($lang), + mysql_real_escape_string($userbrowser)); perform_query($query,$link); $id = mysql_insert_id($link); @@ -496,7 +504,7 @@ function check_for_reassign($thread,$operator) { } function visitor_from_request() { - global $namecookie, $simplenamecookie, $compatibility_encoding, $webim_encoding; + global $namecookie, $simplenamecookie, $compatibility_encoding, $webim_encoding, $usercookie; $userName = getstring("chat.default.username"); if( isset($_COOKIE[$namecookie]) ) { $data = base64_decode(strtr($_COOKIE[$namecookie],'-_,', '+/=')); @@ -507,7 +515,14 @@ function visitor_from_request() { $userName = myiconv($compatibility_encoding,$webim_encoding,$_COOKIE[$simplenamecookie]); } - return array( 'name' => $userName ); + $userId = ""; + if (isset($_COOKIE[$usercookie])) { + $userId = $_COOKIE[$usercookie]; + } else { + $userId = get_user_id(); + setcookie($usercookie, $userId, time()+60*60*24*365); + } + return array( 'id' => $userId, 'name' => $userName ); } ?> diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php index 295f56b4..5d444847 100644 --- a/src/messenger/webim/operator/update.php +++ b/src/messenger/webim/operator/update.php @@ -39,6 +39,35 @@ $threadstate_key = array( $state_loading => "chat.thread.state_loading" ); +function get_useragent_version($userAgent) { + global $knownAgents; + if (is_array($knownAgents)) { + $userAgent = strtolower($userAgent); + foreach( $knownAgents as $agent ) { + if( strstr($userAgent,$agent) ) { + if( preg_match( "/".$agent."[\\s\/]?(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches ) ) { + $ver = $matches[1]; + if($agent=='safari') { + if(preg_match( "/version\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) { + $ver = $matches[1]; + } else { + $ver = "1 or 2 (build ".$ver.")"; + } + if(preg_match( "/mobile\/(\\d+(\\.\\d+(\\.\\d+)?)?)/", $userAgent, $matches)) { + $userAgent = "iPhone ".$matches[1]." ($agent $ver)"; + break; + } + } + + $userAgent = ucfirst($agent)." ".$ver; + break; + } + } + } + } + return $userAgent; +} + function thread_to_xml($thread,$link) { global $threadstate_to_string, $threadstate_key, $webim_encoding, $operator; $state = $threadstate_to_string[$thread['istate']]; @@ -57,12 +86,22 @@ function thread_to_xml($thread,$link) { } $result .= " state=\"$state\" typing=\"".$thread['userTyping']."\">"; - $result .= "".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote']))).""; + $result .= "".htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'],$thread['remote'], $thread['userid']))).""; $result .= "".htmlspecialchars(htmlspecialchars($thread['remote'])).""; $result .= "".htmlspecialchars(htmlspecialchars($threadoperator)).""; $result .= ""; $result .= "".$thread['unix_timestamp(dtmmodified)']."000"; + $userAgent = get_useragent_version($thread['userAgent']); + $result .= "".$userAgent.""; + if( $thread["shownmessageid"] != 0 ) { + $query = "select tmessage from chatmessage where messageid = ".$thread["shownmessageid"]; + $line = select_one_row($query, $link); + if( $line ) { + $message = preg_replace("/[\r\n\t]+/", " ", $line["tmessage"]); + $result .= "".htmlspecialchars(htmlspecialchars($message)).""; + } + } $result .= ""; return $result; } @@ -74,7 +113,7 @@ function print_pending_threads($since) { $revision = $since; $output = array(); $query = "select threadid, userName, agentName, unix_timestamp(dtmcreated), userTyping, ". - "unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId ". + "unix_timestamp(dtmmodified), lrevision, istate, remote, nextagent, agentId, userid, shownmessageid, userAgent ". "from chatthread where lrevision > $since ORDER BY threadid"; $rows = select_multi_assoc($query, $link); foreach ($rows as $row) { diff --git a/src/messenger/webim/thread.php b/src/messenger/webim/thread.php index 6e1b6283..b00c6616 100644 --- a/src/messenger/webim/thread.php +++ b/src/messenger/webim/thread.php @@ -63,7 +63,12 @@ if( $act == "refresh" ) { show_error("cannot send"); } - post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] ); + $postedid = post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] ); + if($isuser && $thread["shownmessageid"] == 0) { + $link = connect(); + commit_thread( $thread['threadid'], array('shownmessageid' => $postedid), $link); + mysql_close($link); + } print_thread_messages($thread, $token, $lastid, $isuser, $outformat, $isuser ? null : $operator['operatorid']); exit;