Contributions > Plugins, tips, and tricks

No Operator Answer Redirect

<< < (3/3)

wooshman:
Hi Sabyre and thanks for posting after so long.

That is some great news that this mod is still alive so to speak.  It does try to do something, but being so new to Mibew I am a bit lost as to what, where and why.

I look forwards to an update.

wooshman:
FULL credit to Sabyre for original coding and idea.

OK fixed it.  It was all to do with the creation of the opAnswer_xxx.txt file.  It was not being created upon the client chat window being opened.

In chatnoop.php I have also added  a mysql line which clears the operators screen of the visit.  Without this the operator has to open the conversation to close it.  I have also made it add "y" to txt file in newchattimer.php upon operator entering chat to prevent the script going to leave message even when chatting.

Please remove existing files and code and use new code for ease:

Create: newchattimer.php - paste the following and save to root of Mibew

--- Code: ---<?php 
include('libs/config.php');
include('libs/common.php');

$threadid = ($_SESSION['threadid']);
$link = connect();
$query = mysql_query("SELECT * FROM chatmessage WHERE threadid ='" . $threadid . "' AND tmessage LIKE '%Operator%%joined the chat%'");


if(mysql_num_rows($query) == 0) {
  $opjoined = 'n'; 
 } else {
  $opjoined = 'y'; // added this so that the script does not send to leave message page after an operator has answered.
 }
mysql_close($link);

$myFile = "ajaxfiles/opAnswer_";
$myFile .= $threadid;
//$myFile .= "12";
$myFile .= ".txt";  

$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $opjoined;
fwrite($fh, $stringData);
fclose($fh);
chmod($myFile, 0777);

$oldthread = "ajaxfiles/opAnswer_";
$oldthread .= ($threadid - 1);
$oldthread .= ".txt";
unlink($oldthread);
?>
--- End code ---

Create: chatnoop.php - paste the following code and save to root of Mibew

--- Code: ---<?php

require_once('libs/common.php');
require_once('libs/chat.php');
require_once('libs/operator.php');
require_once('libs/groups.php');
require_once('libs/expand.php');
require_once('libs/captcha.php');

$dtmcreated = date('Y-m-d H:i:s');
$page = array();
setup_logo();

// added to clear Operator screen of waiting chat after timeout.
$link = connect();
$query = mysql_query("INSERT INTO chatmessage (threadid, ikind, tmessage, dtmcreated) VALUES ('$threadid', '6', 'Visitor left the chat', '$dtmcreated')") or die(mysql_error());
mysql_close($link);
//

setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha());
expand("styles", getchatstyle(), "leavemessage.tpl");
?>
--- End code ---

Now open client.php and at the very end ( after the closing ?> ) add the following and save

--- Code: ---<script>
function opCheck()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
{
       
   opCheck();
           
}
}
opjoined = "newchattimer.php";

xmlhttp.open("GET",opjoined,true);
xmlhttp.send(null);
}

opCheck(); // This has been added to run newchattimer.php upon the client chat window opening

function opResult()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Your browser does not support XMLHTTP!");
  }
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4)
  {
   
   if (xmlhttp.responseText == 'n') window.location.replace("chatnoop.php");

 }
}
ajaxurl = "ajaxfiles/opAnswer_<?php echo $threadid;?>.txt";
xmlhttp.open("GET",ajaxurl,true);
xmlhttp.send(null);
}

setTimeout(function() {
opCheck();
opResult();

}, 30000); // This is how long you have to wait until it redirects to leave message page (chatnoop.php)  30000 = 30 seconds
clearTimeout();
</script>
--- End code ---

create folder called ajaxfiles in the root of Mibew and chmod to 777 or 755.

Upload your new files / folders and also client.php and test.

The first time you run it you may see an error message in your logs about a missing file.  This will not happen after the first run.  It is trying to delete the old chat thread txt file.

yaisel:
there is some errors in the file chatnoop.php in the version 1.6.11.

Notice: Undefined variable: visitor in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 15

Notice: Undefined variable: threadid in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 17

Notice: Undefined variable: visitor in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: email in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: firstmessage in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: groupid in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: groupname in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: info in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

Notice: Undefined variable: referrer in C:\xampp\htdocs\roltec-css\webim\chatnoop.php on line 21

add this code line before setup_logo(); and this errors are gone but the visitors continued on visitors waiting list until an operator opens and closes a chat with him.


--- Code: ---$threadid = ($_SESSION['threadid']);
$visitor = visitor_from_request();
$firstmessage = NULL;
$info = getgetparam('info');
$email = getgetparam('email');
$groupid = "";
$groupname = "";
if($settings['enablegroups'] == '1') {
$groupid = verifyparam( "group", "/^\d{1,10}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$groupid = "";
} else {
$groupname = get_group_name($group);
}
}
}
$referrer = isset($_GET['url']) ? $_GET['url'] :
(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
if(isset($_GET['referrer']) && $_GET['referrer']) {
$referrer .= "\n".$_GET['referrer'];
}

--- End code ---

yaisel:
with these changes in the file chatnoop.php works quite stable in 1.6.11, eliminating vistante list of visitors is expected to pass the time and be redirected to the sending message window.


--- Code: ---<?php

require_once('libs/common.php');
require_once('libs/chat.php');
require_once('libs/operator.php');
require_once('libs/groups.php');
require_once('libs/expand.php');
require_once('libs/captcha.php');

$dtmcreated = date('Y-m-d H:i:s');
$page = array();
setup_logo();
//added to obtain the values ​​of these varibles
$threadid = ($_SESSION['threadid']);
$visitor = visitor_from_request();
$firstmessage = NULL;
$info = getgetparam('info');
$email = getgetparam('email');
$groupid = "";
$groupname = "";
if($settings['enablegroups'] == '1') {
$groupid = verifyparam( "group", "/^\d{1,10}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$groupid = "";
} else {
$groupname = get_group_name($group);
}
}
}
$referrer = isset($_GET['url']) ? $_GET['url'] :
(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
if(isset($_GET['referrer']) && $_GET['referrer']) {
$referrer .= "\n".$_GET['referrer'];
}
// added to clear Operator screen of waiting chat after timeout.
$thread = reopen_thread($_SESSION['threadid']);
close_thread($thread,true);
//

setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha());
expand("styles", getchatstyle(), "leavemessage.tpl");
?>

--- End code ---

Sabyre:
Thanks folks for all the feedback, I am sorry for the delays. I have modified the script. It is now functional. Please see the first post in this thread for the updated version.


Navigation

[0] Message Index

[*] Previous page

Go to full version