Test
\n"; print "List Available Images
\n"; print "Add request for Maple 10
\n"; print "Get status of request
\n"; print "Get connection data
\n"; print "End request
\n"; print "
\n";

// test
if($_GET['state'] == 'test') {
	$rc = remoteVCLCall('XMLRPCtest', array('foo'));
	print_r($rc);
}
// list images
elseif($_GET['state'] == 'listimages') {
	$rc = remoteVCLCall('XMLRPCgetImages', array());
	print_r($rc);
}
// add request
elseif($_GET['state'] == 'addrequest') {
	$rc = remoteVCLCall('XMLRPCaddRequest', array(98, 'now', 60));
	if($rc['status'] == 'success') {
		print "request id is {$rc['requestid']}
\n"; $_SESSION['requestid'] = $rc['requestid']; } else { print_r($rc); } } // get request status elseif($_GET['state'] == 'requeststatus') { if(! array_key_exists('requestid', $_SESSION)) { print "no request created
\n"; exit; } $rc = remoteVCLCall('XMLRPCgetRequestStatus', array($_SESSION['requestid'])); print "current status of request {$_SESSION['requestid']} is {$rc['status']}"; } // get connection data elseif($_GET['state'] == 'connectdata') { if(! array_key_exists('requestid', $_SESSION)) { print "no request created
\n"; exit; } $rc = remoteVCLCall('XMLRPCgetRequestConnectData', array($_SESSION['requestid'], $_SERVER["REMOTE_ADDR"])); if($rc['status'] == 'ready') print_r($rc); else print "status of request is {$rc['status']}"; } // end request elseif($_GET['state'] == 'endrequest') { if(! array_key_exists('requestid', $_SESSION)) { print "no request created
\n"; exit; } $rc = remoteVCLCall('XMLRPCendRequest', array($_SESSION['requestid'])); if($rc['status'] == 'error') print_r($rc); else { print "request ended
\n"; unset($_SESSION['requestid']); } } print "
\n"; function remoteVCLCall($method, $args) { $request = xmlrpc_encode_request($method, $args); $header = "Content-Type: text/xml\r\n"; $header .= "X-User: userid\r\n"; // user your userid here $header .= "X-Pass: password\r\n"; // user your password here $header .= "X-APIVERSION: 1"; // this is to allow for future changes to the api $context = stream_context_create( array( 'http' => array( 'method' => "POST", 'header' => $header, 'content' => $request ) ) ); $file = file_get_contents("https://vcl.ncsu.edu/scheduling/index.php?mode=xmlrpccall", false, $context); $response = xmlrpc_decode($file); if(xmlrpc_is_fault($response)) { trigger_error("xmlrpc: {$response['faultString']} ({$response['faultCode']})"); exit; } return $response; } ?>