I feel that I must be missing something here. And I'd like to preface by saying I am at advanced beginner level when it comes to PHP but have been making sites a long time and I have a firm grasp of file structures, codes, blah blah blah, but not really the inner workings of java or php. That being said I can normally reverse engineer most things.
Problem: No visible effect at all.
Mibew version 1.6.5.
I have created the two files (newchattimer.php & chatnoop.php) and have placed them in my root webim folder, I have also created the specified folder (ajaxfiles) and CHMOD'd it to 777. Additionally I have added the javascript to the end of client.php.
I am able to see the javascript when i view source on the chat page, I have had a file created inside the ajaxfiles folder, but it doesn't seem to redirect! I tried chrome and firefox.
I assume the numbers at the end of the client.php file is the actual "x" number of milliseconds to wait. I lowered this down to 20 seconds worth of milliseconds, no change. I'm at a loss on this one as no errors are being thrown, the java comes through to the viewsource and the ajaxfiles folder is gaining files but no redirection is happening.
All I can imagine is that I've made a directory mistake or perhaps your code was not meant for my version of Mibew.
I appreciate any help you guys can offer, this is exactly the mod I need because my staff tends to walk off with the chat on far too often. I have included the files in question below.
root/webim/newchattime.php:
<?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';
}
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);
?>
root/webim/chatnoop.php:
<?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');
$page = array();
setup_logo();
setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha());
expand("styles", getchatstyle(), "leavemessage.tpl");
?>
root/webim/client.php:
<?php
/*
* Copyright 2005-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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');
require_once('libs/notify.php');
loadsettings();
if($settings['enablessl'] == "1" && $settings['forcessl'] == "1") {
if(!is_secure_request()) {
$requested = $_SERVER['PHP_SELF'];
if($_SERVER['REQUEST_METHOD'] == 'GET' && $_SERVER['QUERY_STRING']) {
header("Location: ".get_app_location(true,true)."/client.php?".$_SERVER['QUERY_STRING']);
} else {
die("only https connections are handled");
}
exit;
}
}
if( !isset($_GET['token']) || !isset($_GET['thread']) ) {
$thread = NULL;
if( isset($_SESSION['threadid']) ) {
$thread = reopen_thread($_SESSION['threadid']);
}
if( !$thread ) {
$groupid = "";
$groupname = "";
if($settings['enablegroups'] == '1') {
$groupid = verifyparam( "group", "/^\d{1,8}$/", "");
if($groupid) {
$group = group_by_id($groupid);
if(!$group) {
$groupid = "";
} else {
$groupname = get_group_name($group);
}
}
}
$visitor = visitor_from_request();
if(isset($_POST['survey']) && $_POST['survey'] == 'on') {
$firstmessage = getparam("message");
$info = getparam("info");
$email = getparam("email");
$referrer = urldecode(getparam("referrer"));
if($settings['usercanchangename'] == "1" && isset($_POST['name'])) {
$newname = getparam("name");
if($newname != $visitor['name']) {
$data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,');
setcookie($namecookie, $data, time()+60*60*24*365);
$visitor['name'] = $newname;
}
}
} else {
$firstmessage = NULL;
$info = getgetparam('info');
$email = getgetparam('email');
$referrer = isset($_GET['url']) ? $_GET['url'] :
(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "");
if(isset($_GET['referrer']) && $_GET['referrer']) {
$referrer .= "\n".$_GET['referrer'];
}
}
if(!has_online_operators($groupid)) {
$page = array();
setup_logo();
setup_leavemessage($visitor['name'],$email,$firstmessage,$groupid,$groupname,$info,$referrer,can_show_captcha());
expand("styles", getchatstyle(), "leavemessage.tpl");
exit;
}
if($settings['enablepresurvey'] == '1' && !(isset($_POST['survey']) && $_POST['survey'] == 'on')) {
$page = array();
setup_logo();
setup_survey($visitor['name'], $email, $groupid, $info, $referrer);
expand("styles", getchatstyle(), "survey.tpl");
exit;
}
$remoteHost = get_remote_host();
$userbrowser = $_SERVER['HTTP_USER_AGENT'];
$link = connect();
if(!check_connections_from_remote($remoteHost, $link)) {
mysql_close($link);
die("number of connections from your IP is exceeded, try again later");
}
$thread = create_thread($groupid,$visitor['name'], $remoteHost, $referrer,$current_locale,$visitor['id'], $userbrowser,$state_loading,$link);
$_SESSION['threadid'] = $thread['threadid'];
if( $referrer ) {
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.came.from',array($referrer)),$link);
}
post_message_($thread['threadid'],$kind_info,getstring('chat.wait'),$link);
if($email) {
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.email',array($email)),$link);
}
if($info) {
post_message_($thread['threadid'],$kind_for_agent,getstring2('chat.visitor.info',array($info)),$link);
}
if($firstmessage) {
$postedid = post_message_($thread['threadid'],$kind_user,$firstmessage,$link,$visitor['name']);
commit_thread( $thread['threadid'], array('shownmessageid' => $postedid), $link);
}
notify_operators($thread, $firstmessage, $link);
mysql_close($link);
}
$threadid = $thread['threadid'];
$token = $thread['ltoken'];
$level = get_remote_level($_SERVER['HTTP_USER_AGENT']);
$chatstyle = verifyparam( "style", "/^\w+$/", "");
header("Location: $webimroot/client.php?thread=$threadid&token=$token&level=$level".($chatstyle ? "&style=$chatstyle" : ""));
exit;
}
$token = verifyparam( "token", "/^\d{1,8}$/");
$threadid = verifyparam( "thread", "/^\d{1,8}$/");
$level = verifyparam( "level", "/^(ajaxed|simple|old)$/");
$thread = thread_by_id($threadid);
if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
die("wrong thread");
}
setup_chatview_for_user($thread, $level);
$pparam = verifyparam( "act", "/^(mailthread)$/", "default");
if( $pparam == "mailthread" ) {
expand("styles", getchatstyle(), "mail.tpl");
} else if( $level == "ajaxed" ) {
expand("styles", getchatstyle(), "chat.tpl");
} else if( $level == "simple" ) {
expand("styles", getchatstyle(), "chatsimple.tpl");
} else if( $level == "old" ) {
expand("styles", getchatstyle(), "nochat.tpl");
}
?>
<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();
// alert('working2');
}
}
opjoined = "newchattimer.php";
xmlhttp.open("GET",opjoined,true);
xmlhttp.send(null);
}
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();
//alert(op);
}, 150000);
clearTimeout();
</script>