2007-10-10 19:15:47 +04:00
|
|
|
<?php
|
|
|
|
/*
|
2009-06-04 02:44:32 +04:00
|
|
|
* This file is part of Mibew Messenger project.
|
2007-10-10 19:15:47 +04:00
|
|
|
*
|
2009-06-04 02:44:32 +04:00
|
|
|
* Copyright (c) 2005-2009 Mibew Messenger Community
|
2007-10-10 19:15:47 +04:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
2009-08-04 17:38:37 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* the GNU General Public License Version 2 or later (the "GPL"), in which case
|
|
|
|
* the provisions of the GPL are applicable instead of those above. If you wish
|
|
|
|
* to allow use of your version of this file only under the terms of the GPL, and
|
|
|
|
* not to allow others to use your version of this file under the terms of the
|
|
|
|
* EPL, indicate your decision by deleting the provisions above and replace them
|
|
|
|
* with the notice and other provisions required by the GPL.
|
|
|
|
*
|
2007-10-10 19:15:47 +04:00
|
|
|
* Contributors:
|
|
|
|
* Evgeny Gryaznov - initial API and implementation
|
|
|
|
*/
|
|
|
|
|
2008-06-05 01:36:54 +04:00
|
|
|
require_once('libs/common.php');
|
|
|
|
require_once('libs/chat.php');
|
|
|
|
require_once('libs/operator.php');
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2008-09-30 03:11:56 +04:00
|
|
|
$act = verifyparam( "act", "/^(refresh|post|rename|close|ping)$/");
|
2007-10-10 19:15:47 +04:00
|
|
|
$token = verifyparam( "token", "/^\d{1,9}$/");
|
|
|
|
$threadid = verifyparam( "thread", "/^\d{1,9}$/");
|
|
|
|
$isuser = verifyparam( "user", "/^true$/", "false") == 'true';
|
2008-09-30 03:11:56 +04:00
|
|
|
$outformat = ((verifyparam( "html", "/^on$/", "off") == 'on') ? "html" : "xml");
|
2008-05-06 01:08:57 +04:00
|
|
|
$istyping = verifyparam( "typed", "/^1$/", "") == '1';
|
2008-03-05 01:22:48 +03:00
|
|
|
|
2008-10-12 19:03:13 +04:00
|
|
|
if($threadid == 0 && ($token == 123 || $token == 124)) {
|
|
|
|
require_once('libs/demothread.php');
|
|
|
|
$lastid = verifyparam( "lastid", "/^\d{1,9}$/", 0);
|
2008-10-13 03:05:47 +04:00
|
|
|
demo_process_thread($act,$outformat,$lastid,$isuser,$token == 123,$istyping,$act=="post"?getrawparam('message') : "");
|
2008-10-12 19:03:13 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2007-10-10 19:15:47 +04:00
|
|
|
$thread = thread_by_id($threadid);
|
|
|
|
if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
|
|
|
|
die("wrong thread");
|
|
|
|
}
|
|
|
|
|
2008-09-30 03:11:56 +04:00
|
|
|
function show_ok_result($resid) {
|
|
|
|
start_xml_output();
|
|
|
|
echo "<$resid></$resid>";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_error($message) {
|
|
|
|
start_xml_output();
|
|
|
|
echo "<error><descr>$message</descr></error>";
|
|
|
|
exit;
|
|
|
|
}
|
2007-10-10 19:15:47 +04:00
|
|
|
|
2008-05-06 01:08:57 +04:00
|
|
|
ping_thread($thread, $isuser,$istyping);
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
if( !$isuser && $act != "rename" ) {
|
|
|
|
$operator = check_login();
|
|
|
|
check_for_reassign($thread,$operator);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $act == "refresh" ) {
|
|
|
|
$lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1);
|
2008-10-03 02:41:35 +04:00
|
|
|
print_thread_messages($thread, $token, $lastid, $isuser,$outformat, $isuser ? null : $operator['operatorid']);
|
2007-10-10 19:15:47 +04:00
|
|
|
exit;
|
|
|
|
|
|
|
|
} else if( $act == "post" ) {
|
|
|
|
$lastid = verifyparam( "lastid", "/^\d{1,9}$/", -1);
|
|
|
|
$message = getrawparam('message');
|
|
|
|
|
|
|
|
$kind = $isuser ? $kind_user : $kind_agent;
|
|
|
|
$from = $isuser ? $thread['userName'] : $thread['agentName'];
|
2008-09-30 03:11:56 +04:00
|
|
|
|
2008-10-02 17:25:26 +04:00
|
|
|
if(!$isuser && $operator['operatorid'] != $thread['agentId']) {
|
|
|
|
show_error("cannot send");
|
|
|
|
}
|
|
|
|
|
2009-04-05 18:20:34 +04:00
|
|
|
$link = connect();
|
|
|
|
$postedid = post_message_($threadid,$kind,$message,$link,$from,null,$isuser ? null : $operator['operatorid'] );
|
2008-10-03 19:11:02 +04:00
|
|
|
if($isuser && $thread["shownmessageid"] == 0) {
|
|
|
|
commit_thread( $thread['threadid'], array('shownmessageid' => $postedid), $link);
|
|
|
|
}
|
2009-04-05 18:20:34 +04:00
|
|
|
mysql_close($link);
|
2008-10-03 02:41:35 +04:00
|
|
|
print_thread_messages($thread, $token, $lastid, $isuser, $outformat, $isuser ? null : $operator['operatorid']);
|
2007-10-10 19:15:47 +04:00
|
|
|
exit;
|
|
|
|
|
|
|
|
} else if( $act == "rename" ) {
|
|
|
|
|
2008-10-12 05:21:37 +04:00
|
|
|
loadsettings();
|
|
|
|
if( $settings['usercanchangename'] != "1" ) {
|
2008-09-30 03:11:56 +04:00
|
|
|
show_error("server: forbidden to change name");
|
2007-10-10 19:15:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$newname = getrawparam('name');
|
|
|
|
|
|
|
|
rename_user($thread, $newname);
|
2008-05-12 13:23:16 +04:00
|
|
|
$data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,');
|
2008-09-30 03:11:56 +04:00
|
|
|
setcookie($namecookie, $data, time()+60*60*24*365);
|
|
|
|
show_ok_result("rename");
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
} else if( $act == "ping" ) {
|
2008-09-30 03:11:56 +04:00
|
|
|
show_ok_result("ping");
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
} else if( $act == "close" ) {
|
2008-09-30 03:11:56 +04:00
|
|
|
|
2007-12-03 00:32:47 +03:00
|
|
|
if( $isuser || $thread['agentId'] == $operator['operatorid']) {
|
|
|
|
close_thread($thread, $isuser);
|
|
|
|
}
|
2008-09-30 03:11:56 +04:00
|
|
|
show_ok_result("closed");
|
2007-10-10 19:15:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-05-12 13:23:16 +04:00
|
|
|
?>
|