<?php
require_once('includes/config.php');
require_once('includes/functions/func.global.php');
require_once('includes/classes/class.template_engine.php');
// Check if the script is installed
checkinstall($config);
// Check that they specified a manual
if(!isset($_GET['i']))
{
exit('No Manual Specified');
}
if(!isset($_GET['p']))
{
$_GET['p'] = '';
}
if(isset($_GET['page']))
{
if($_GET['page'] == 'left')
{
$_GET['page'] = 'left';
}
else
{
$_GET['page'] = 'content';
}
}
else
{
$_GET['page'] = 'index';
}
// Connect to the database
db_connect($config);
// Get Manual Info
$manual_info = mysql_fetch_row(mysql_query("SELECT manual_id,manual_tpl,manual_title FROM ".$config['db']['pre']."manuals WHERE manual_id='".validate_input($_GET['i'])."' LIMIT 1"));
if(!isset($manual_info[1]))
{
exit('Manual Not Found');
}
if($_GET['page'] == 'index')
{
// Display Manual
$page = new HtmlTemplate ("templates/" . $manual_info[1] . "/manual_index.html");
$page->SetParameter ('MANUAL_ID',stripslashes($manual_info[0]));
$page->SetParameter ('MANUAL_TITLE',stripslashes($manual_info[2]));
$page->SetParameter ('MANUAL_TEMPLATE',stripslashes($manual_info[1]));
$page->CreatePageEcho($config);
}
elseif($_GET['page'] == 'left')
{
$pages = array();
$pages2 = array();
$parents = array();
$sort = array();
$count = 0;
$query = "SELECT page_id,parent_id,page_title FROM ".$config['db']['pre']."pages WHERE manual_id='".validate_input($manual_info[0])."' ORDER BY sort DESC,page_title ASC";
$query_result = mysql_query($query);
while ($info = @mysql_fetch_array($query_result))
{
$pages[$info['parent_id']][$info['page_id']]['page_id'] = $info['page_id'];
$pages[$info['parent_id']][$info['page_id']]['page_title'] = $info['page_title'];
$pages[$info['parent_id']][$info['page_id']]['parent'] = $info['parent_id'];
if(isset($parents[$info['parent_id']]))
{
$parents[$info['parent_id']]++;
}
else
{
$parents[$info['parent_id']] = 0;
}
if($info['parent_id'] == 0)
{
$sort[$count] = $info['page_id'];
$count++;
}
}
$count = 0;
foreach ($sort as $key => $value)
{
$pages2[$count] = $pages[0][$value];
unset($pages[0][$value]);
$count++;
if(isset($pages[$value]))
{
$pages2[($count-1)]['cats'] = count($pages[$value]);
foreach ($pages[$value] as $key2 => $value2)
{
$pages2[$count] = $value2;
unset($pages[$value][$key2]);
$count++;
}
}
}
foreach ($pages as $key => $value)
{
foreach ($value as $key2 => $value2)
{
$pages2[$count] = $value2;
$count++;
unset($pages[$key][$key2]);
}
}
// Display Menu
$page = new HtmlTemplate ("templates/" . $manual_info[1] . "/manual_menu.html");
$page->SetParameter ('MANUAL_ID',$manual_info[0]);
$page->SetParameter ('MANUAL_TITLE',stripslashes($manual_info[2]));
$page->SetParameter ('MANUAL_TEMPLATE',$manual_info[1]);
$page->SetLoop ('PAGES',$pages2);
$page->CreatePageEcho($config);
}
elseif($_GET['page'] == 'content')
{
$query = "SELECT page_id,page_title,page_body FROM ".$config['db']['pre']."pages WHERE page_id='".validate_input($_GET['p'])."' LIMIT 1";
$query_result = mysql_query($query);
$info = @mysql_fetch_array($query_result);
if(!isset($info['page_id']))
{
exit();
}
$pages = array();
$query2 = "SELECT page_id,page_title FROM ".$config['db']['pre']."pages WHERE parent_id='".validate_input($info['page_id'])."'";
$query_result2 = mysql_query($query2);
while ($info2 = @mysql_fetch_array($query_result2))
{
$pages[$info2['page_id']]['page_id'] = $info2['page_id'];
$pages[$info2['page_id']]['page_title'] = $info2['page_title'];
}
// Display Menu
$page = new HtmlTemplate ("templates/" . $manual_info[1] . "/manual_page.html");
$page->SetParameter ('MANUAL_ID',$manual_info[0]);
$page->SetParameter ('MANUAL_TITLE',stripslashes($manual_info[2]));
$page->SetParameter ('MANUAL_TEMPLATE',$manual_info[1]);
$page->SetParameter ('PAGE_ID',$info['page_id']);
$page->SetParameter ('PAGE_TITLE',stripslashes($info['page_title']));
$page->SetParameter ('PAGE_BODY',stripslashes($info['page_body']));
$page->SetLoop ('PAGES',$pages);
$page->CreatePageEcho($config);
}
?>