<?php
require_once('../../../config.php');
require_once(FOLDER_RELATIVE_COMMON . 'authorization.php');
require_once(FOLDER_RELATIVE_COMMON . 'database.php');
// Check for XML request (XMLHttpRequest).
$request = isset($_GET['request']) ? $_GET['request'] : '';
if ($request == 'xml') {
header('Content-Type: text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
$sql = 'SELECT id, title, ' . databaseGetDate('stamp') . ' AS stamp FROM Stories ORDER BY stamp';
$rows = databaseGetRows($sql, array());
if (count($rows) == 0) {
echo "<root></root>\n";
exit;
}
$xml .= "<root>\n";
$xml .= " <list_titles>\n";
$xml .= " <record>ID</record>\n";
$xml .= " <record>Modified</record>\n";
$xml .= " <record>Title</record>\n";
$xml .= " <record>Pages</record>\n";
$xml .= " </list_titles>\n";
$xml .= " <list_data>\n";
foreach ($rows as $row) {
$story_id = $row['id'];
$story_date = $row['stamp'];
$story_title = isset($row['title']) && $row['title'] != '' ? $row['title'] : '<i>< no title ></i>';
$sql = '';
$sql .= 'SELECT p.id AS id, p.title AS title ';
$sql .= 'FROM PageToStory t, Pages p ';
$sql .= 'WHERE p.id = t.page_id and t.story_id = ?';
$pages = databaseGetRows($sql, array($story_id));
$page_title = '';
foreach ($pages as $page){
$page_title .= $page['title'] . ', ';
}
if (strlen($page_title) > 0) {
$page_title = substr($page_title, 0, strlen($page_title) - 2);
} else {
$page_title = ' ';
}
$xml .= " <record>\n";
$xml .= " <a0>$story_id</a0>\n";
$xml .= " <a1>$story_date</a1>\n";
$xml .= " <a2><![CDATA[$story_title]]></a2>\n";
$xml .= " <a3><![CDATA[$page_title]]></a3>\n";
$xml .= " </record>\n";
}
$xml .= " </list_data>\n";
$xml .= "</root>\n";
echo $xml;
exit;
}
// Show the pages list form.
require_once(FOLDER_RELATIVE_COMMON . 'builder-admin.php');
$header = '';
$onload = '';
$onload .= "jaxTableSetSuppressId(); ";
$onload .= "jaxTableSetLinkColumn(1, 'admin_stories.php?request=edit&id='); ";
$onload .= "jaxTableSetDateColumn(0, 'table_date'); ";
$onload .= "jaxTableSetSortColumn('');";
$onload .= "jaxTableRegister('admin_stories_list.php?request=xml', 'storylist');";
$title = 'Stories';
$content = 'admin_stories_list.html';
$page = buildAdminPage($header, $onload, $title, $content);
echo $page;
?>