thread.php: extract ok/error methods

git-svn-id: https://webim.svn.sourceforge.net/svnroot/webim/trunk@119 c66351dc-e62f-0410-b875-e3a5c0b9693f
This commit is contained in:
Evgeny Gryaznov 2008-09-29 23:11:56 +00:00
parent 96519f6158
commit cf1068db58

View File

@ -16,11 +16,11 @@ require_once('libs/common.php');
require_once('libs/chat.php'); require_once('libs/chat.php');
require_once('libs/operator.php'); require_once('libs/operator.php');
$act = verifyparam( "act", "/^(refresh|post|rename|close|ping".")$/"); $act = verifyparam( "act", "/^(refresh|post|rename|close|ping)$/");
$token = verifyparam( "token", "/^\d{1,9}$/"); $token = verifyparam( "token", "/^\d{1,9}$/");
$threadid = verifyparam( "thread", "/^\d{1,9}$/"); $threadid = verifyparam( "thread", "/^\d{1,9}$/");
$isuser = verifyparam( "user", "/^true$/", "false") == 'true'; $isuser = verifyparam( "user", "/^true$/", "false") == 'true';
$outformat = (verifyparam( "html", "/^on$/", "off") == 'on') ? "html" : "xml"; $outformat = ((verifyparam( "html", "/^on$/", "off") == 'on') ? "html" : "xml");
$istyping = verifyparam( "typed", "/^1$/", "") == '1'; $istyping = verifyparam( "typed", "/^1$/", "") == '1';
$thread = thread_by_id($threadid); $thread = thread_by_id($threadid);
@ -28,8 +28,17 @@ if( !$thread || !isset($thread['ltoken']) || $token != $thread['ltoken'] ) {
die("wrong thread"); die("wrong thread");
} }
# This code helps in simulation of operator connection problems function show_ok_result($resid) {
# if( !$isuser ) die("error"); start_xml_output();
echo "<$resid></$resid>";
exit;
}
function show_error($message) {
start_xml_output();
echo "<error><descr>$message</descr></error>";
exit;
}
ping_thread($thread, $isuser,$istyping); ping_thread($thread, $isuser,$istyping);
@ -49,7 +58,7 @@ if( $act == "refresh" ) {
$kind = $isuser ? $kind_user : $kind_agent; $kind = $isuser ? $kind_user : $kind_agent;
$from = $isuser ? $thread['userName'] : $thread['agentName']; $from = $isuser ? $thread['userName'] : $thread['agentName'];
post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] ); post_message($threadid,$kind,$message,$from, $isuser ? null : $operator['operatorid'] );
print_thread_messages($thread, $token, $lastid, $isuser, $outformat); print_thread_messages($thread, $token, $lastid, $isuser, $outformat);
exit; exit;
@ -57,35 +66,25 @@ if( $act == "refresh" ) {
} else if( $act == "rename" ) { } else if( $act == "rename" ) {
if( !$user_can_change_name ) { if( !$user_can_change_name ) {
start_xml_output(); show_error("server: forbidden to change name");
echo "<error></error>";
exit;
} }
$newname = getrawparam('name'); $newname = getrawparam('name');
rename_user($thread, $newname); rename_user($thread, $newname);
$data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,'); $data = strtr(base64_encode(myiconv($webim_encoding,"utf-8",$newname)), '+/=', '-_,');
setcookie($namecookie, $data, time()+60*60*24*365); setcookie($namecookie, $data, time()+60*60*24*365);
start_xml_output(); show_ok_result("rename");
echo "<changedname></changedname>";
exit;
} else if( $act == "ping" ) { } else if( $act == "ping" ) {
show_ok_result("ping");
start_xml_output();
echo "<ping></ping>";
exit;
} else if( $act == "close" ) { } else if( $act == "close" ) {
if( $isuser || $thread['agentId'] == $operator['operatorid']) { if( $isuser || $thread['agentId'] == $operator['operatorid']) {
close_thread($thread, $isuser); close_thread($thread, $isuser);
} }
show_ok_result("closed");
start_xml_output();
echo "<closed></closed>";
exit;
} }