<?php
header("Content-Type: text/html; charset=UTF-8");

require("common.php");

$userid = $_GET['userid'];
$buttonstyle = $_GET['buttonstyle'];
if ($buttonstyle == '') $buttonstyle = "small";

$methodname = 'WebVisitor.GetUserLoginStatus';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
	'<userid>' . $userid . '</userid>' . 
	'</request> ';
$responseinfo = '';
$responsexml = null;
$errorcode = ERRORCODE_UNKNOWN;

$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml = simplexml_load_string($responseinfo);
	$errorcode = $responsexml->errorcode;
}
$cmd = null;

switch($errorcode) {
	case ERRORCODE_OK: 
		switch ($responsexml->loginstatus) {
			case 0://OffLine
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_offline.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_offline.gif');
				}
				break;
			case 1://OnLine
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_online.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_online.gif');
				}
				break;
			case 2://Busy
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_busy.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_busy.gif');
				}
				break;
			case 3://Leave
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_leave.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_leave.gif');
				}
				break;
			case 4://Hide
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_offline.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_offline.gif');
				}
				break;
			case 5://Quiet
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_quiet.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_quiet.gif');
				}
				break;
			default:
				if ($buttonstyle == "large") {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_offline.gif');
				} else {
					header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_offline.gif');
				}
				break;
		}//switch
		break;
	default:
		if ($buttonstyle == "large") {
			header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/largebtn_offline.gif');
		} else {
			header('Location:http://' . $_SERVER['HTTP_HOST'] . '/webvisitor/tab/images/buttons/smallbtn_offline.gif');
		}
}//switch
?>