Location: PHPKode > projects > JaxBlog > JaxBlog/app/admin/admin_panes/admin_panes.php
<?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'] : '';

if ($request == 'xml') {

	$pane_id          = isset($_GET['pane_id']) ? $_GET['pane_id'] : '';
	$pane_description = '';
	$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());
		}
	}
	
	// Grab pane information from the db.
	$row = databaseGetRow('SELECT description, display, disabled, page_id, story_id, file_id, folder_path, content FROM Panes WHERE id = ?', array($pane_id));
	$pane_description  = $row['description'];
	$pane_display      = isset($row['display']) ? $row['display'] : 0;
	$pane_disabled     = isset($row['disabled']) ? $row['disabled'] : 'N';
	$pane_page_id      = isset($row['page_id']) ? $row['page_id'] : '';
	$pane_story_id     = isset($row['story_id']) ? $row['story_id'] : '';
	$pane_file_id      = isset($row['file_id']) ? $row['file_id'] : '';
	$pane_folder_path  = isset($row['folder_path']) ? $row['folder_path'] : '';
	$pane_content      = $row['content'];
	
	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>request</key>            <value>save</value></record>' . "\n";
	$xml .= '		<record><key>pane_folder_path</key>   <value><![CDATA[' . $pane_folder_path . ']]></value></record>' . "\n";
	$xml .= '		<record><key>pane_display</key>       <value><![CDATA[' . $pane_display . ']]></value></record>' . "\n";
	$xml .= '		<record><key>pane_disabled</key>      <value><![CDATA[' . $pane_disabled . ']]></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_video_links</key>   <value><![CDATA[' . ( $pane_display == 6 ? $pane_content : '') . ']]></value></record>' . "\n";
	$xml .= '		<record><key>pane_raw_html</key>      <value><![CDATA[' . ( $pane_display == 100 ? $pane_content : '') . ']]></value></record>' . "\n";
	$xml .= '	</controls_id>' . "\n";

	// Populate the pane_id <select> with a list of available panes.
	$rows = databaseGetRows('SELECT id, name FROM Panes ORDER BY id', array());
	$pane_id_captions = '';
	$pane_id_choices = '';
	foreach ($rows as $row) {
		$pane_id_captions .= removeBreak($row['name'], false) . '|';
		$pane_id_choices .= $row['id'] . '|';
	}

//	// Populate the pane type <select>.
//	$pane_display_captions = 'Main Navigation Bar|Navigation Bar Child Pages|Navigation Bar Stories|Single Story|Slideshow|Video Links|Calendar|Search|Raw HTML|';
//	$pane_display_choices  = '1|2|3|4|5|6|7|9|100|';
	
	// Populate the pane_story_id <select> with a list of stories.
	$rows = databaseGetRows('SELECT id, title FROM Stories ORDER BY title', array());
	$pane_story_id_captions = '';
	$pane_story_id_choices  = '';
	foreach ($rows as $row) {
		if (isset($row['title']) && $row['title'] != '') {
			$pane_story_id_captions .= str_replace('|', '', $row['title']) . '|';
		} else {
			$pane_story_id_captions .= 'no title|';
		}
		$pane_story_id_choices  .= $row['id'] . '|';
	}
	
	// Populate the pane_page_id <select> with a list of stories.
	$rows = databaseGetRows('SELECT id, title FROM Pages ORDER BY title', array());
	$pane_page_id_captions = '';
	$pane_page_id_choices  = '';
	foreach ($rows as $row) {
		if (isset($row['title']) && $row['title'] != '') {
			$pane_page_id_captions .= str_replace('|', '', $row['title']) . '|';
		} else {
			$pane_page_id_captions .= 'no title|';
		}
		$pane_page_id_choices  .= $row['id'] . '|';
	}
	
	// Populate the pane slideshow_id <select> with a list of folders.
	$sql = 'SELECT id, title FROM Files WHERE id <> 1 AND is_file = \'N\' ORDER BY id';
	$rows = databaseGetRows($sql, array());
	$pane_file_id_captions = '';
	$pane_file_id_choices  = '';
	foreach ($rows as $row) {
		$pane_file_id_captions .= str_replace('|', '', $row['title']) . '|';
		$pane_file_id_choices  .= $row['id'] . '|';
	}

	$xml .= '	<controls_select>' . "\n";
	$xml .= '		<record>';
	$xml .= '			<key>pane_id</key>';
	$xml .= '			<value>' . $pane_id . '</value>';
	$xml .= '			<captions><![CDATA[' . $pane_id_captions . ']]></captions>';
	$xml .= '			<choices><![CDATA[' . $pane_id_choices . ']]></choices>';
	$xml .= '		</record>' . "\n";
//	$xml .= '		<record>';
//	$xml .= '			<key>pane_display</key>';
//	$xml .= '			<value>' . $pane_display . '</value>';
//	$xml .= '			<captions><![CDATA[' . $pane_display_captions . ']]></captions>';
//	$xml .= '			<choices><![CDATA[' . $pane_display_choices . ']]></choices>';
//	$xml .= '		</record>' . "\n";
	$xml .= '		<record>';
	$xml .= '			<key>pane_page_id</key>';
	$xml .= '			<value>' . $pane_page_id . '</value>';
	$xml .= '			<captions><![CDATA[' . $pane_page_id_captions . ']]></captions>';
	$xml .= '			<choices><![CDATA[' . $pane_page_id_choices . ']]></choices>';
	$xml .= '		</record>' . "\n";
	$xml .= '		<record>';
	$xml .= '			<key>pane_story_id</key>';
	$xml .= '			<value>' . $pane_story_id . '</value>';
	$xml .= '			<captions><![CDATA[' . $pane_story_id_captions . ']]></captions>';
	$xml .= '			<choices><![CDATA[' . $pane_story_id_choices . ']]></choices>';
	$xml .= '		</record>' . "\n";
	$xml .= '		<record>';
	$xml .= '			<key>pane_file_id</key>';
	$xml .= '			<value>' . $pane_file_id . '</value>';
	$xml .= '			<captions><![CDATA[' . $pane_file_id_captions . ']]></captions>';
	$xml .= '			<choices><![CDATA[' . $pane_file_id_choices . ']]></choices>';
	$xml .= '		</record>' . "\n";
	
	$xml .= '	</controls_select>' . "\n";

	$xml .= '</root>' . "\n";
	echo $xml;

	$_SESSION['pane_id'] = $pane_id;
	exit;
}

if ($request == 'save') {
	require_once(FOLDER_RELATIVE_COMMON . 'filesystem.php');
	
	$sql            = 'UPDATE Panes SET display = ?, disabled = ?, page_id = ?, story_id = ?, file_id = ?, folder_path = ?, content = ? WHERE id = ?';
	$sql_array      = null;
	$pane_id        = $_POST['pane_id'];
	$pane_display   = $_POST['pane_display'];
	$pane_disabled  = isset($_POST['pane_disabled']) && ($_POST['pane_disabled'] == 'on') ? 'Y' : 'N';
	
	switch($pane_display) {
		case '1':   // Main Navigation Bar
			$sql_array        = array($pane_display, $pane_disabled, null, null, null, null, null, $pane_id);
			break;
		case '2':   // Navigation Bar Child Pages
			$pane_page_id     = isset($_POST['pane_page_id']) ? $_POST['pane_page_id'] : null;
			$sql_array        = array($pane_display, $pane_disabled, $pane_page_id, null, null, null, null, $pane_id);
			break;
		case '3':   // Navigation Bar Stories
			$pane_page_id     = isset($_POST['pane_page_id']) ? $_POST['pane_page_id'] : null;
			$sql_array        = array($pane_display, $pane_disabled, $pane_page_id, null, null, null, null, $pane_id);
			break;
		case '4':   // Single Story
			$pane_story_id    = isset($_POST['pane_story_id']) ? $_POST['pane_story_id'] : null;
			$sql_array        = array($pane_display, $pane_disabled, null, $pane_story_id, null, null, null, $pane_id);
			break;
		case '5':   // Slideshow
			$pane_file_id     = isset($_POST['pane_file_id']) ? $_POST['pane_file_id'] : null;
			$pane_folder_path = isset($_POST['pane_folder_path']) ? $_POST['pane_folder_path'] : null;
			$sql_array        = array($pane_display, $pane_disabled, null, null, $pane_file_id, $pane_folder_path, null, $pane_id);
			break;
		case '6':   // Video Links
			$pane_content     = isset($_POST['pane_video_links']) ? stripslashes($_POST['pane_video_links']) : '';
			$sql_array        = array($pane_display, $pane_disabled, null, null, null, null, $pane_content, $pane_id);
			break;
		case '7':   // Calendar
		case '8':   // Scoreboard
		case '9':   // Search
		case '10':  // Login
			$sql_array        = array($pane_display, $pane_disabled, null, null, null, null, null, $pane_id);
			break;
		case '100': // Raw HTML
			$pane_content     = isset($_POST['pane_raw_html']) ? stripslashes($_POST['pane_raw_html']) : '';
			$sql_array        = array($pane_display, $pane_disabled, null, null, null, null, $pane_content, $pane_id);
			break;
	}
	databaseExecute($sql, $sql_array);
	
	$_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   = '';
$header  .= '<script language="Javascript" type="text/javascript" src="admin_panes.js"></script>' . "\n";
$onload   = "initializePage();";
$title    = 'Panes';
$content  = 'admin_panes.html';
$page     = buildAdminPage($header, $onload, $title, $content);

echo $page;

?>
Return current item: JaxBlog