<?php
require_once('../../../config.php');
require_once(FOLDER_RELATIVE_COMMON . 'authorization.php');
require_once(FOLDER_RELATIVE_COMMON . 'database.php');
require_once(FOLDER_RELATIVE_COMMON . 'html.php');
$exitearly = true;
$errors = '';
$request = isset($_GET['request']) ? $_GET['request'] : '';
$pane_id = isset($_GET['pane_id']) ? $_GET['pane_id'] : '';
if ($request == 'xml') {
$pane_description = '';
$pane_path = '';
$pane_privilege = '<span style="color: #FF6F82">unable to overwrite</span>';
$pane_content = '';
if ($pane_id == '') {
$pane_id = isset($_SESSION['pane_id']) ? $_SESSION['pane_id'] : '';
if ($pane_id == '') {
$pane_id = databaseGetValue('SELECT id FROM Panes WHERE id = (SELECT MIN(id) FROM Panes)', array());
}
}
$row = databaseGetRow('SELECT description, path FROM Panes WHERE id = ?', array($pane_id));
$pane_description = $row['description'];
$pane_path = $row['path'];
require_once(FOLDER_RELATIVE_COMMON . 'refolder.php');
if (file_exists(FOLDER_RELATIVE_BASE . 'app/user/user_story/' . $pane_path)) {
// Check that the file is writable.
if (is_writable(FOLDER_RELATIVE_BASE . 'app/user/user_story/' . $pane_path)) {
$pane_privilege = '<span style="color: #84FF6F">able to overwrite</span>';
}
// And cache the contents.
$pane_content = fileRead(FOLDER_RELATIVE_BASE . 'app/user/user_story/' . $pane_path);
} else {
// Check that the folder is writable.
if (is_writable(FOLDER_RELATIVE_BASE . 'app/user/user_story/')) {
$pane_privilege = '<span style="color: #84FF6F">able to overwrite</span>';
}
}
header('Content-Type: text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
$xml .= "<root>\n";
$xml .= " <controls_input>\n";
$xml .= " <record><key>pane_content</key><value><![CDATA[$pane_content]]></value></record>\n";
$xml .= " <record><key>request</key><value>save</value></record>\n";
$xml .= " </controls_input>\n";
$xml .= " <controls_id>\n";
$xml .= " <record><key>pane_description</key> <value><![CDATA[$pane_description]]></value></record>\n";
$xml .= " <record><key>pane_privilege</key> <value><![CDATA[$pane_privilege]]></value></record>\n";
$xml .= " </controls_id>\n";
// Populate the <select> with a list of available panes.
$sql = 'SELECT id, name FROM Panes ORDER BY id';
$rows = databaseGetRows($sql, array());
$captions = '';
$choices = '';
foreach ($rows as $row) {
$captions .= removeBreak($row['name'], false) . "|";
$choices .= $row['id'] . "|";
}
$xml .= " <controls_select>\n";
$xml .= " <record>";
$xml .= " <key>pane_id</key>";
$xml .= " <value>$pane_id</value>";
$xml .= " <captions><![CDATA[$captions]]></captions>";
$xml .= " <choices><![CDATA[$choices]]></choices>";
$xml .= " </record>\n";
if ($xml_delete_choice != null) $xml .= $xml_delete_choice;
$xml .= " </controls_select>\n";
$xml .= "</root>\n";
echo $xml;
exit;
}
if ($request == 'save') {
require_once(FOLDER_RELATIVE_COMMON . 'filesystem.php');
$pane_id = $_POST['pane_id'];
$pane_content = isset($_POST['pane_content']) ? stripslashes($_POST['pane_content']) : '';
$pane_path = databaseGetValue('SELECT path FROM Panes WHERE id = ?', array($pane_id));
$pane_path = FOLDER_RELATIVE_BASE . 'app/user/user_story/' . $pane_path;
if (!file_exists($pane_path)) {
touch($pane_path);
chmod($pane_path, 0664);
}
fileWrite($pane_path, $pane_content);
$_SESSION['pane_id'] = $pane_id;
header('location:../admin_panes/admin_panes.php');
exit;
}
// Show the files list form.
require_once(FOLDER_RELATIVE_COMMON . 'builder-admin.php');
$header = '<script language="Javascript" type="text/javascript" src="admin_panes.js"></script>' . "\n";
$onload = "jaxFormRegister('admin_panes.php?request=xml'); initializePage();";
$title = 'Panes';
$content = 'admin_panes.html';
$page = buildAdminPage($header, $onload, $title, $content);
echo $page;
?>