2
0
mirror of https://github.com/ACSPRI/queXS synced 2024-04-02 12:12:16 +00:00

Added a backport of Limesurvey CI Remote Control 2 functionality for adding a response.

Can be used to insert a new response into a questionnaire via XML-RPC
Added xmlrpc package from: http://phpxmlrpc.sourceforge.net (new BSD licence compatible with GPL)
This commit is contained in:
azammitdcarf
2011-11-11 05:26:58 +00:00
parent a4935b7f08
commit bfe3f2470f
100 changed files with 20723 additions and 0 deletions

View File

@@ -0,0 +1 @@
<html><head><title>xmlrpc</title></head><body><h1>Agesort demo</h1><h2>Send an array of 'name' => 'age' pairs to the server that will send it back sorted.</h2><h3>The source code demonstrates basic lib usage, including handling of xmlrpc arrays and structs</h3><p></p><?phpinclude("xmlrpc.inc");$inAr=array("Dave" => 24, "Edd" => 45, "Joe" => 37, "Fred" => 27);reset($inAr);print "This is the input data:<br/><pre>";while (list($key, $val)=each($inAr)) { print $key . ", " . $val . "\n";}print "</pre>";// create parameters from the input array: an xmlrpc array of xmlrpc structs$p=array();foreach($inAr as $key => $val) { $p[]=new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct");}$v=new xmlrpcval($p, "array");print "Encoded into xmlrpc format it looks like this: <pre>\n" . htmlentities($v->serialize()). "</pre>\n";// create client and message objects$f=new xmlrpcmsg('examples.sortByAge', array($v));$c=new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);// set maximum debug level, to have the complete communication printed to screen$c->setDebug(2);// send requestprint "Now sending request (detailed debug info follows)";$r=&$c->send($f);// check response for errors, and take appropriate actionif (!$r->faultCode()) { print "The server gave me these results:<pre>"; $v=$r->value(); $max=$v->arraysize(); for($i=0; $i<$max; $i++) { $rec=$v->arraymem($i); $n=$rec->structmem("name"); $a=$rec->structmem("age"); print htmlspecialchars($n->scalarval()) . ", " . htmlspecialchars($a->scalarval()) . "\n"; } print "<hr/>For nerds: I got this value back<br/><pre>" . htmlentities($r->serialize()). "</pre><hr/>\n";} else { print "An error occurred:<pre>"; print "Code: " . htmlspecialchars($r->faultCode()) . "\nReason: '" . htmlspecialchars($r->faultString()).'\'</pre><hr/>';}?><em>$Id: agesort.php 2 2009-03-16 20:22:51Z ggiunta $</em></body></html>

View File

@@ -0,0 +1,54 @@
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Getstatename demo</h1>
<h2>Send a U.S. state number to the server and get back the state name</h2>
<h3>The code demonstrates usage of the php_xmlrpc_encode function</h3>
<?php
include("xmlrpc.inc");
// Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off
if(!isset($HTTP_POST_VARS) && isset($_POST))
{
$HTTP_POST_VARS = $_POST;
}
if(isset($HTTP_POST_VARS["stateno"]) && $HTTP_POST_VARS["stateno"]!="")
{
$stateno=(integer)$HTTP_POST_VARS["stateno"];
$f=new xmlrpcmsg('examples.getStateName',
array(php_xmlrpc_encode($stateno))
);
print "<pre>Sending the following request:\n\n" . htmlentities($f->serialize()) . "\n\nDebug info of server data follows...\n\n";
$c=new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
$c->setDebug(1);
$r=&$c->send($f);
if(!$r->faultCode())
{
$v=$r->value();
print "</pre><br/>State number " . $stateno . " is "
. htmlspecialchars($v->scalarval()) . "<br/>";
// print "<HR>I got this value back<BR><PRE>" .
// htmlentities($r->serialize()). "</PRE><HR>\n";
}
else
{
print "An error occurred: ";
print "Code: " . htmlspecialchars($r->faultCode())
. " Reason: '" . htmlspecialchars($r->faultString()) . "'</pre><br/>";
}
}
else
{
$stateno = "";
}
print "<form action=\"client.php\" method=\"POST\">
<input name=\"stateno\" value=\"" . $stateno . "\"><input type=\"submit\" value=\"go\" name=\"submit\"></form>
<p>Enter a state number to query its name</p>";
?>
<hr/>
<em>$Id: client.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>

View File

@@ -0,0 +1,185 @@
<?php
include("xmlrpc.inc");
$mydir="/demo";
// define some utility functions
function bomb() { print "</body></html>"; exit(); }
function dispatch($client, $method, $args) {
$msg=new xmlrpcmsg($method, $args);
$resp=$client->send($msg);
if (!$resp) { print "<p>IO error: ".$client->errstr."</p>"; bomb(); }
if ($resp->faultCode()) {
print "<p>There was an error: " . $resp->faultCode() . " " .
$resp->faultString() . "</p>";
bomb();
}
return php_xmlrpc_decode($resp->value());
}
// create client for discussion server
$dclient=new xmlrpc_client("${mydir}/discuss.php",
"xmlrpc.usefulinc.com", 80);
// check if we're posting a comment, and send it if so
@$storyid=$_POST["storyid"];
if ($storyid) {
// print "Returning to " . $HTTP_POST_VARS["returnto"];
$res=dispatch($dclient, "discuss.addComment",
array(new xmlrpcval($storyid),
new xmlrpcval(stripslashes
(@$_POST["name"])),
new xmlrpcval(stripslashes
(@$_POST["commenttext"]))));
// send the browser back to the originating page
Header("Location: ${mydir}/comment.php?catid=" .
$_POST["catid"] . "&chanid=" .
$_POST["chanid"] . "&oc=" .
$_POST["catid"]);
exit(0);
}
// now we've got here, we're exploring the story store
?>
<html><head><title>meerkat browser</title></head>
<body bgcolor="#ffffff">
<h2>Meerkat integration</h2>
<?php
@$catid=$_GET["catid"];
if (@$_GET["oc"]==$catid)
@$chanid=$_GET["chanid"];
else
$chanid=0;
$client=new xmlrpc_client("/meerkat/xml-rpc/server.php",
"www.oreillynet.com", 80);
if (@$_GET["comment"] &&
(!@$_GET["cdone"])) {
// we're making a comment on a story,
// so display a comment form
?>
<h3>Make a comment on the story</h3>
<form method="post">
<p>Your name:<br /><input type="text" size="30" name="name" /></p>
<p>Your comment:<br /><textarea rows="5" cols="60"
name="commenttext"></textarea></p>
<input type="submit" value="Send comment" />
<input type="hidden" name="storyid"
value="<?php echo @$_GET["comment"];?>" />
<input type="hidden" name="chanid"
value="<?php echo $chanid; ?>" />
<input type="hidden" name="catid"
value="<?php echo $catid; ?>" />
</form>
<?php
} else {
$categories=dispatch($client, "meerkat.getCategories", array());
if ($catid)
$sources = dispatch($client, "meerkat.getChannelsByCategory",
array(new xmlrpcval($catid, "int")));
if ($chanid) {
$stories = dispatch($client, "meerkat.getItems",
array(new xmlrpcval(
array(
"channel" => new xmlrpcval($chanid, "int"),
"ids" => new xmlrpcval(1, "int"),
"descriptions" => new xmlrpcval(200, "int"),
"num_items" => new xmlrpcval(5, "int"),
"dates" => new xmlrpcval(0, "int")
), "struct")));
}
?>
<form>
<p>Subject area:<br />
<select name="catid">
<?php
if (!$catid)
print "<option value=\"0\">Choose a category</option>\n";
while(list($k,$v) = each($categories)) {
print "<option value=\"" . $v['id'] ."\"";
if ($v['id']==$catid) print " selected=\"selected\"";
print ">". $v['title'] . "</option>\n";
}
?>
</select></p>
<?php
if ($catid) {
?>
<p>News source:<br />
<select name="chanid">
<?php
if (!$chanid)
print "<option value=\"0\">Choose a source</option>\n";
while(list($k,$v) = each($sources)) {
print "<option value=\"" . $v['id'] ."\"";
if ($v['id']==$chanid) print "\" selected=\"selected\"";
print ">". $v['title'] . "</option>\n";
}
?>
</select>
</p>
<?php
} // end if ($catid)
?>
<p><input type="submit" value="Update" /></p>
<input type="hidden" name="oc" value="<?php echo $catid; ?>" />
</form>
<?php
if ($chanid) {
?>
<h2>Stories available</h2>
<table>
<?php
while(list($k,$v) = each($stories)) {
print "<tr>";
print "<td><b>" . $v['title'] . "</b><br />";
print $v['description'] . "<br />";
print "<em><a target=\"_blank\" href=\"" .
$v['link'] . "\">Read full story</a> ";
print "<a href=\"comment.php?catid=${catid}&chanid=${chanid}&" .
"oc=${oc}&comment=" . $v['id'] . "\">Comment on this story</a>";
print "</em>";
print "</td>";
print "</tr>\n";
// now look for existing comments
$res=dispatch($dclient, "discuss.getComments",
array(new xmlrpcval($v['id'])));
if (sizeof($res)>0) {
print "<tr><td bgcolor=\"#dddddd\"><p><b><i>" .
"Comments on this story:</i></b></p>";
for($i=0; $i<sizeof($res); $i++) {
$s=$res[$i];
print "<p><b>From:</b> " . htmlentities($s['name']) . "<br />";
print "<b>Comment:</b> " . htmlentities($s['comment']) . "</p>";
}
print "</td></tr>\n";
}
print "<tr><td><hr /></td></tr>\n";
}
?>
</table>
<?php
} // end if ($chanid)
} // end if comment
?>
<hr />
<p>
<a href="http://meerkat.oreillynet.com"><img align="right"
src="http://meerkat.oreillynet.com/icons/meerkat-powered.jpg"
height="31" width="88" alt="Meerkat powered, yeah!"
border="0" hspace="8" /></a>
<em>$Id: comment.php 2 2009-03-16 20:22:51Z ggiunta $</em></p>
</body>
</html>

View File

@@ -0,0 +1,108 @@
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Introspect demo</h1>
<h2>Query server for available methods and their description</h2>
<h3>The code demonstrates usage of multicall and introspection methods</h3>
<?php
include("xmlrpc.inc");
function display_error($r)
{
print "An error occurred: ";
print "Code: " . $r->faultCode()
. " Reason: '" .$r->faultString()."'<br/>";
}
// 'new style' client constuctor
$c = new xmlrpc_client("http://phpxmlrpc.sourceforge.net/server.php");
print "<h3>methods available at http://" . $c->server . $c->path . "</h3>\n";
$m = new xmlrpcmsg('system.listMethods');
$r =& $c->send($m);
if($r->faultCode())
{
display_error($r);
}
else
{
$v=$r->value();
for($i=0; $i<$v->arraysize(); $i++)
{
$mname=$v->arraymem($i);
print "<h4>" . $mname->scalarval() . "</h4>\n";
// build messages first, add params later
$m1 = new xmlrpcmsg('system.methodHelp');
$m2 = new xmlrpcmsg('system.methodSignature');
$val = new xmlrpcval($mname->scalarval(), "string");
$m1->addParam($val);
$m2->addParam($val);
// send multiple messages in one pass.
// If server does not support multicall, client will fall back to 2 separate calls
$ms = array($m1, $m2);
$rs =& $c->send($ms);
if($rs[0]->faultCode())
{
display_error($rs[0]);
}
else
{
$val=$rs[0]->value();
$txt=$val->scalarval();
if($txt != "")
{
print "<h4>Documentation</h4><p>${txt}</p>\n";
}
else
{
print "<p>No documentation available.</p>\n";
}
}
if($rs[1]->faultCode())
{
display_error($rs[1]);
}
else
{
print "<h4>Signature</h4><p>\n";
$val = $rs[1]->value();
if($val->kindOf()=="array")
{
for($j=0; $j<$val->arraysize(); $j++)
{
$x = $val->arraymem($j);
$ret = $x->arraymem(0);
print "<code>" . $ret->scalarval() . " "
. $mname->scalarval() . "(";
if($x->arraysize()>1)
{
for($k=1; $k<$x->arraysize(); $k++)
{
$y = $x->arraymem($k);
print $y->scalarval();
if($k < $x->arraysize()-1)
{
print ", ";
}
}
}
print ")</code><br/>\n";
}
}
else
{
print "Signature unknown\n";
}
print "</p>\n";
}
}
}
?>
<hr/>
<em>$Id: introspect.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>

View File

@@ -0,0 +1,71 @@
<?php
// Allow users to see the source of this file even if PHP is not configured for it
if ((isset($HTTP_GET_VARS['showSource']) && $HTTP_GET_VARS['showSource']) ||
(isset($_GET['showSource']) && $_GET['showSource']))
{ highlight_file(__FILE__); die(); }
?>
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Mail demo</h1>
<p>This form enables you to send mail via an XML-RPC server. For public use
only the "Userland" server will work (see <a href="http://www.xmlrpc.com/discuss/msgReader$598">Dave Winer's message</a>).
When you press <kbd>Send</kbd> this page will reload, showing you the XML-RPC request sent to the host server, the XML-RPC response received and the internal evaluation done by the PHP implementation.</p>
<p>You can find the source to this page here: <a href="mail.php?showSource=1">mail.php</a><br/>
And the source to a functionally identical mail-by-XML-RPC server in the file <a href="../server/server.php?showSource=1">server.php</a> included with the library (look for the 'mail_send' method)</p>
<?php
include("xmlrpc.inc");
// Play nice to PHP 5 installations with REGISTER_LONG_ARRAYS off
if (!isset($HTTP_POST_VARS) && isset($_POST))
$HTTP_POST_VARS = $_POST;
if (isset($HTTP_POST_VARS["server"]) && $HTTP_POST_VARS["server"]) {
if ($HTTP_POST_VARS["server"]=="Userland") {
$XP="/RPC2"; $XS="206.204.24.2";
} else {
$XP="/xmlrpc/server.php"; $XS="pingu.heddley.com";
}
$f=new xmlrpcmsg('mail.send');
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailto"]));
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailsub"]));
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailmsg"]));
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailfrom"]));
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailcc"]));
$f->addParam(new xmlrpcval($HTTP_POST_VARS["mailbcc"]));
$f->addParam(new xmlrpcval("text/plain"));
$c=new xmlrpc_client($XP, $XS, 80);
$c->setDebug(2);
$r=&$c->send($f);
if (!$r->faultCode()) {
print "Mail sent OK<br/>\n";
} else {
print "<fonr color=\"red\">";
print "Mail send failed<br/>\n";
print "Fault: ";
print "Code: " . htmlspecialchars($r->faultCode()) .
" Reason: '" . htmlspecialchars($r->faultString()) . "'<br/>";
print "</font><br/>";
}
}
?>
<form method="POST">
Server <select name="server"><option value="Userland">Userland</option>
<option value="UsefulInc">UsefulInc private server</option></select>
<hr/>
From <input size="60" name="mailfrom" value=""/><br/>
<hr/>
To <input size="60" name="mailto" value=""/><br/>
Cc <input size="60" name="mailcc" value=""/><br/>
Bcc <input size="60" name="mailbcc" value=""/><br/>
<hr/>
Subject <input size="60" name="mailsub" value="A message from xmlrpc"/>
<hr/>
Body <textarea rows="7" cols="60" name="mailmsg">Your message here</textarea><br/>
<input type="Submit" value="Send"/>
</form>
<hr/>
<em>$Id: mail.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>

View File

@@ -0,0 +1,59 @@
<?php
/**
* Helper function for the terminally lazy
*
* @version $Id: simple_call.php 2 2009-03-16 20:22:51Z ggiunta $
* @copyright (c) 2006-2008 G. Giunta
* @license code licensed under the BSD License: http://phpxmlrpc.sourceforge.net/license.txt
*/
/**
* Takes a client object, a remote method name, and a variable numbers of
* php values, and calls the method with the supplied parameters. The
* parameters are native php values and the result is an xmlrpcresp object.
*
* Notes:
* The function encodes the received parameters using php_xmlrpc_encode:
* the limitations of automatic encoding apply to this function too);
*
* the type of the value returned by the function can be changed setting
* beforehand the 'return_type' member of the client object to 'phpvals' -
* see the manual for more details about this capability).
*
*
* @author Toth Istvan
*
* @param xmlrpc_client client object, properly set up to connect to server
* @param string remote function name
* @param mixed $parameter1
* @param mixed $parameter2
* @param mixed $parameter3 ...
* @return xmlrpcresp or false on error
*/
function xmlrpccall_simple()
{
if(func_num_args() < 2)
{
// Incorrect
return false;
}
else
{
$varargs = func_get_args();
$client = array_shift($varargs);
$remote_function_name = array_shift($varargs);
if (!is_a($client, 'xmlrpc_client') || !is_string($remote_function_name))
{
return false;
}
$xmlrpcval_array = array();
foreach($varargs as $parameter)
{
$xmlrpcval_array[] = php_xmlrpc_encode($parameter);
}
return $client->send(new xmlrpcmsg($remote_function_name, $xmlrpcval_array));
}
}
?>

View File

@@ -0,0 +1,32 @@
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Which toolkit demo</h1>
<h2>Query server for toolkit information</h2>
<h3>The code demonstrates usage of the php_xmlrpc_decode function</h3>
<?php
include("xmlrpc.inc");
$f = new xmlrpcmsg('interopEchoTests.whichToolkit', array());
$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
$r = $c->send($f);
if(!$r->faultCode())
{
$v = php_xmlrpc_decode($r->value());
print "<pre>";
print "name: " . htmlspecialchars($v["toolkitName"]) . "\n";
print "version: " . htmlspecialchars($v["toolkitVersion"]) . "\n";
print "docs: " . htmlspecialchars($v["toolkitDocsUrl"]) . "\n";
print "os: " . htmlspecialchars($v["toolkitOperatingSystem"]) . "\n";
print "</pre>";
}
else
{
print "An error occurred: ";
print "Code: " . htmlspecialchars($r->faultCode()) . " Reason: '" . htmlspecialchars($r->faultString()) . "'\n";
}
?>
<hr/>
<em>$Id: which.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>

View File

@@ -0,0 +1,58 @@
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Webservice wrappper demo</h1>
<h2>Wrap methods exposed by server into php functions</h2>
<h3>The code demonstrates usage of the most automagic client usage possible:<br/>
1) client that returns php values instead of xmlrpcval objects<br/>
2) wrapping of remote methods into php functions
</h3>
<?php
include("xmlrpc.inc");
include("xmlrpc_wrappers.inc");
$c = new xmlrpc_client("/server.php", "phpxmlrpc.sourceforge.net", 80);
$c->return_type = 'phpvals'; // let client give us back php values instead of xmlrpcvals
$r =& $c->send(new xmlrpcmsg('system.listMethods'));
if($r->faultCode())
{
echo "<p>Server methods list could not be retrieved: error '".htmlspecialchars($r->faultString())."'</p>\n";
}
else
{
$testcase = '';
echo "<p>Server methods list retrieved, now wrapping it up...</p>\n<ul>\n";
foreach($r->value() as $methodname) // $r->value is an array of strings
{
// do not wrap remote server system methods
if (strpos($methodname, 'system.') !== 0)
{
$funcname = wrap_xmlrpc_method($c, $methodname);
if($funcname)
{
echo "<li>Remote server method ".htmlspecialchars($methodname)." wrapped into php function ".$funcname."</li>\n";
}
else
{
echo "<li>Remote server method ".htmlspecialchars($methodname)." could not be wrapped!</li>\n";
}
if($methodname == 'examples.getStateName')
{
$testcase = $funcname;
}
}
}
echo "</ul>\n";
if($testcase)
{
echo "Now testing function $testcase: remote method to convert U.S. state number into state name";
$statenum = 25;
$statename = $testcase($statenum, 2);
echo "State number $statenum is ".htmlspecialchars($statename);
}
}
?>
<hr/>
<em>$Id: wrap.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>

View File

@@ -0,0 +1,31 @@
<html>
<head><title>xmlrpc</title></head>
<body>
<h1>Zope test demo</h1>
<h3>The code demonstrates usage of basic authentication to connect to the server</h3>
<?php
include("xmlrpc.inc");
$f = new xmlrpcmsg('document_src', array());
$c = new xmlrpc_client("/index_html", "pingu.heddley.com", 9080);
$c->setCredentials("username", "password");
$c->setDebug(2);
$r = $c->send($f);
if(!$r->faultCode())
{
$v = $r->value();
print "I received:" . htmlspecialchars($v->scalarval()) . "<br/>";
print "<hr/>I got this value back<br/>pre>" .
htmlentities($r->serialize()). "</pre>\n";
}
else
{
print "An error occurred: ";
print "Code: " . htmlspecialchars($r->faultCode())
. " Reason: '" . ($r->faultString()) . "'<br/>";
}
?>
<hr/>
<em>$Id: zopetest.php 2 2009-03-16 20:22:51Z ggiunta $</em>
</body>
</html>