<?php
	$hostname = "jomora.net";
	//$hostname = $_SERVER['SERVER_NAME'];

	// for PHP5 SOAP extension
	$soapclient = new SoapClient('http://' . $hostname . '/Quiz/QuizService.asmx?wsdl'); //for .NET 1.0 SoapBinding
	//$soapclient = new SoapClient('http://' . $hostname . '/quiz/services/QuizService?wsdl'); //for Apache AXIS 1.1 SoapBinding

	$question = $soapclient->getQuestion();

	$html = "";
	if ($question->choices == null) {
		$html = "Now loading...";
	} else {
		$html = "<form name=\"QuizForm\" action=\"\">\r\n";
		$html .= "($question->quizTitle : $question->groupName) " . str_replace("\n","<br />", htmlentities($question->sentence, ENT_QUOTES, "UTF-8")) . "<br />\r\n";
		foreach ($question->choices as $choice) {
			$html .= "<input type=\"checkbox\" name=\"cb\" value=\"$choice->correct\" />" . str_replace("\n","<br />\n", htmlentities($choice->text, ENT_QUOTES, "UTF-8")) . "<br />\r\n";
		}
		$html .= "<input type=\"hidden\" name=\"comment\" value=\"" . str_replace("\n","<br />", htmlentities(htmlentities($question->comment, ENT_QUOTES, "UTF-8"), ENT_QUOTES, "UTF-8")) . "\" />\r\n";
		$html .= "<div id=\"qanswer\"><input type=\"button\" name=\"submit\" value=\"判定\" onclick=\"answer();\" style=\"BACKGROUND:#ddffee; BORDER-LEFT:1px; BORDER-TOP:1px;\" /><noscript style=\"color:red;\">　判定にはJavaScriptを使用します。</noscript></div>\r\n";
		$html .= "</form>\n";
		$html .= <<<EOD
<script language="JavaScript" type="text/javascript"><!--
function answer() {
	var correct = true;
	for (i = 0; i < document.QuizForm.cb.length; i++) {
		if ((document.QuizForm.cb[i].checked == true
			&& document.QuizForm.cb[i].value == "")
			|| (document.QuizForm.cb[i].checked == false
			&& document.QuizForm.cb[i].value == "1")) {
			correct = false;break;
		}
	}
	if (correct) {
		document.getElementById('qanswer').innerHTML = "<span style=\"font-size:large;\">正解！(^^)/</span><br />\\r\\n" + document.QuizForm.comment.value;
	} else {
		alert("不正解 (++)");
	}
}
//--></script>
EOD;
	}

	print $html;
?>
<div align="right" style="font-size:80%;">powered by <a href="http://<?php echo $hostname ?>/wiki/?QuizML">Quiz Web Service</a></div>
