PHP Source Code:
<?
/*
faq.php
read and display FAQ section on web page
(sample application for the yalst API)
Copyright (c) 2005-2008 by Dr. Markus Jasinski, rostock-digital
http://www.rostock-digital.com - http://www.yalst.com
permission to use this script on your own site
*/
// include XML-RPC library for PHP
//
// download URL:
// http://keithdevens.com/software/xmlrpc
include("xmlrpc.inc.php");
// define yalst site, API password and yalst server
$site="";
// yalst site number (e.g. "27000-1")
$passwd="";
// API password (as configured in your Customer Area)
$server="";
// use "en.livesupportserver.de" for Hosted Versions
// and your respective yalst domain for Download Versions
// for security reasons this three values are coming from an
// include file in this example; pleae comment out the following
// line in order to use this script
include("faq.inc.php");
// read parameters
$faqmode=$_GET["faqmode"]; // "article" or "category"
$faqitem=$_GET["faqitem"]; // nummber of article or category
// check parameters
$error="";
if (($faqmode!="article") and ($faqmode!="category"))
{$faqmode="category";}
$faqitem=intval($faqitem);
// API call
if ($faqmode=="category")
{$result=XMLRPC_request($server,'/yalst/api.php','faq.category',array(XMLRPC_prepare($site),XMLRPC_prepare(md5($passwd)),XMLRPC_prepare($faqitem),XMLRPC_prepare("1")));}
else
{$result=XMLRPC_request($server,'/yalst/api.php','faq.article',array(XMLRPC_prepare($site),XMLRPC_prepare(md5($passwd)),XMLRPC_prepare($faqitem),XMLRPC_prepare("0")));}
// API call OK?
if (!$result[0])
{$error=$result[1]["faultString"];}
?>
<html>
<head>
<title>FAQs</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- add more headers here (e.g. stylesheet definitions) -->
</head>
<body bgcolor="#ffffff">
<?
if ($error)
{echo "Error: $error";}
else
{
if ($faqmode=="category")
{
if ($faqitem>0)
{
// display name of category and link to parent category
echo "<p>";
echo "<b>".htmlentities($result[1][0]["category"])."</b> ".
"[<a href=\"faq.php?faqmode=category&faqitem=".$result[1][0]["pid"].
"\">Go Up One Level</a>]\n";
echo "</p>\n";
}
// display list of subsections
if ($result[1][0]["categories"]>0)
{
echo "<p>\n";
echo "Categories:<br>\n";
for ($i=0; $i<$result[1][0]["sum"]; $i++)
{
if ($result[1][0][$i+1]["type"]=="category")
{
echo "<a href=\"faq.php?faqmode=category&faqitem=".$result[1][0][$i+1]["id"].
"\">".htmlentities($result[1][0][$i+1]["name"])."</a>";
}
if (($i<($result[1][0]["sum"]-1)) and ($result[1][0][$i+1]["type"]=="category"))
{echo "<br>\n";}
}
echo "</p>\n";
}
// display list of articles
if ($result[1][0]["articles"]>0)
{
echo "<p>\n";
for ($i=0; $i<$result[1][0]["sum"]; $i++)
{
if ($result[1][0][$i+1]["type"]=="article")
{
echo "<a href=\"faq.php?faqmode=article&faqitem=".$result[1][0][$i+1]["id"].
"\">".htmlentities($result[1][0][$i+1]["name"])."</a>\n";
}
if (($i<($result[1][0]["sum"]-1)) and ($result[1][0][$i+1]["type"]=="article"))
{echo "<br>\n";}
}
echo "</p>\n";
}
}
else
{
// display article
echo "<p>\n";
if ($result[1][0]["category"])
{
echo "[<a href=\"faq.php?faqmode=category&faqitem=".$result[1][0]["cid"].
"\">".htmlentities($result[1][0]["category"])."</a>]\n";
}
else
{echo "[<a href=\"faq.php?faqmode=category&faqitem=0\">Back</a>]\n";}
echo "</p>\n";
echo "<p>\n";
echo "<b>".htmlentities($result[1][0]["question"])."</b>\n";
echo "</p>\n";
echo "<p>\n";
echo $result[1][0]["answer"];
echo "</p>\n";
// link popup version of this article
echo "<p>\n[".$result[1][0]["link"]."]\n<p>\n";
}
}
// show source code (remove on production servers!!!)
echo "<hr>\n";
echo "<p>\n";
echo "PHP Source Code:<br>\n";
show_source($_SERVER["SCRIPT_FILENAME"]);
echo "</p>\n";
?>
</body>
</html>