Accessing OGo with PHP via XML-RPC
Some sample scripts how to remotely use OGo via XML-RPC
Note that the PEAR class "XML_RPC" has to be installed. Also make sure that the ogo-xmlrpc daemon is running. Normally it's located in
Note that you will have to change the mktime(...) command to a recent date.
/usr/local/sbin/ogo-xmlrpcd-1.0a
Listing available methods
We just list the available methods via thesystem.listMethods function.
<?php
error_reporting(E_ALL | E_NOTICE);
require_once "XML/RPC.php";
/**
* The ogo_xmlrpcd needs to be runnning!
* (located at "/usr/local/sbin/ogo-xmlrpcd-1.0a")
*/
$client = new XML_RPC_Client("/x/xmlrpc", "localhost", 22000);
$client->setCredentials('rpc', 'rpc');
//$client->setDebug(true);
if(isset($_GET['signature'])) {
/**
* get the signature of a method
*/
$params = array(new XML_RPC_Value($_GET['signature'], "string"));
$msg = new XML_RPC_Message("system.methodSignature", $params);
$response = $client->send($msg);
$v = $response->value();
if (!$response->faultCode()) {
echo $_GET['signature'] . '(';
$v = $v->me['array'][0];
$nSize = $v->arraysize();
for($nA = 0; $nA < $nSize; $nA++) {
$val = $v->arraymem($nA);
echo $val->scalarval() . ' ';
}
echo ')';
} else {
print "Fault: ";
print "Code: " . $response->faultCode() . " Reason '" . $response->faultString() . "'\n";
var_dump($response);
}
echo '<br/><br/><a href="test.php">zurück</a>';
} else {
$params = array();
$msg = new XML_RPC_Message("system.listMethods", $params);
//system.methodSignature
//system.methodHelp
$response = $client->send($msg);
$v = $response->value();
if (!$response->faultCode()) {
// var_dump( $v);
foreach($v->me['array'] as $function) {
$strFunc = $function->me['string'];
echo '<a href="test.php?signature=' . $strFunc . '">' . $strFunc . '</a><br/>';
}
} else {
print "Fault: ";
print "Code: " . $response->faultCode() . " Reason '" . $response->faultString() . "'\n";
var_dump($response);
}
}
?>
Adding an appointment
In this script we use PHP to list the appointments in a simple HTML table, and give the user the ability to add entries.Note that you will have to change the mktime(...) command to a recent date.
<?php
require_once "XML/RPC.php";
/**
* The ogo_xmlrpcd needs to be runnning!
* (located at "/usr/local/sbin/ogo-xmlrpcd-1.0a")
*/
$client = new XML_RPC_Client("/x/xmlrpc", "localhost", 22000);
$client->setCredentials('rpc', 'rpc');
//$client->setDebug(true);
/**
* Insert appointment?
*/
if (isset($_POST['title']) && $_POST['title'] != '') {
$strTitle = $_POST['title'];
$strBeginn = $_POST['beginn'];
$strEnde = $_POST['ende'];
$params = array(
new XML_RPC_Value(array(
'title' =>new XML_RPC_Value($strTitle, 'string'),
'startDate'=>new XML_RPC_Value($strBeginn, 'dateTime.iso8601'),
'endDate' =>new XML_RPC_Value($strEnde, 'dateTime.iso8601'))
,'struct')
);
$insmsg = new XML_RPC_Message("appointment.insert", $params);
$response = $client->send($insmsg);
if ($response->faultCode()) {
print "Fault: ";
print "Code: " . $response->faultCode() . " Reason '" . $response->faultString() . "'\n";
var_dump($response);
}
}
/**
* fetch appointments
*/
$params = array(
new XML_RPC_Value( XML_RPC_iso8601_encode(mktime(0, 0, 0, 11, 11, 2004)), 'dateTime.iso8601'),
new XML_RPC_Value( XML_RPC_iso8601_encode(mktime(0, 0, 0, 13, 11, 2004)), 'dateTime.iso8601')
);
$msg = new XML_RPC_Message("appointment.fetchOverview", $params);
$response = $client->send($msg);
$v = $response->value();
if (!$response->faultCode()) {
?><table border="1"><caption>Termine für <?php echo $user; ?></caption><thead><tr><th>Name</th><th>Beginn</th><th>Ende</th></tr><?php
$nSize = $v->arraysize();
for($nA = 0; $nA < $nSize; $nA++) {
$val = $v->arraymem($nA);
$objTitle = $val->structmem('title');
$objBeginn = $val->structmem('startDate');
$objEnd = $val->structmem('endDate');
echo '<tr><td>' . $objTitle->scalarval() . '</td><td>' . $objBeginn->scalarval() . '</td><td>' . $objEnd->scalarval() . '</td></tr>';
// var_dump($val);
}
?></table><?php
} else {
print "Fault: ";
print "Code: " . $response->faultCode() . " Reason '" . $response->faultString() . "'\n";
var_dump($response);
}
?>
<h2>Eintrag hinzufügen</h2>
<style type="text/css">
label {
width:100px;
}
</style>
<form method="post" action="appointment.php">
<label for="title">Titel:</label><input type="text" name="title" id="title" /><br/>
<label for="beginn">Beginn:</label><input type="text" name="beginn" id="beginn" value="20041115T13:00:00" /><br/>
<label for="ende">Ende:</label><input type="text" name="ende" id="ende" value="20041115T14:00:00" /><br/>
<input type="submit" value="Eintragen" />
</form>