<?php 
/*
Fast Edit 1.0 - An "edit in place" tool with extended CMS capabilities (C) 2010 Beverley Hooton
(author website - http://fast-edit.co.uk/)

    Fast Edit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

include('fast_edit_config.php');
include('tinymce_3_3_7/tinymce/jscripts/tiny_mce/plugins/tinybrowser/config_tinybrowser.php');

if ( $basepage != 'page_preview' ) {

if($_SESSION['username']) 
	{
	$data = file_get_contents($contentpage); // populate fast-edit textarea with content.txt page
	if ( (isset($_GET['action'])) && ($_GET['action']=='save') ) // save changes to fast-edit textarea
		{
		$content = $contentpage;
		$data = $_POST['fastedit'];
		$fp = fopen($content,'w');
		$data = stripslashes($data);
		fwrite($fp,$data);
		fclose($fp);
		if ($_POST['menu_alias'] != '')
			{
			$aliasname = $_POST['alias_name'];
			$menu_alias_content = $menu_alias.$aliasname.'.txt';
			$menu_alias_fp = fopen($menu_alias_content,'w');
			$menu_alias_data = $_POST['menu_alias'];
			$menu_alias_data = stripslashes($menu_alias_data);
			fwrite($menu_alias_fp,$menu_alias_data);
			fclose($menu_alias_fp);
			}
			else
			{
			$aliasname = $_POST['alias_name'];
			@unlink($menu_alias.$aliasname.'.txt');
			}
		$url_save = str_replace('?action=save', '', $url);
		echo "<div class=\"saving\">Saving changes...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
		echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_save#go_edit \">";
		exit();
		}

	if ( (isset($_GET['action'])) && ($_GET['action']=='create') ) // create new web page
		{
		if (empty($_POST['file_name'])) // error message if no page title is entered
			{ 
    			$no_title_message = "<center><div class='error'>No title entered for new web page.</div></center><br/>";
    			echo "<script type='text/javascript'>window.alert('Sorry, you must first enter a web page title to create a new web page.')</script>"; 
			} 
			else if ( ($_POST['file_name']=='index')||($_POST['file_name']=='Index') ) // error message if "index" is used	
			{ 
    			$no_title_message = "<center><div class='error'>\"Index\" name is in use (it's your home page!). Choose a different name for your new web page.</div></center><br/>";
    			echo "<script type='text/javascript'>window.alert('Sorry, you must must use a different name for your new web page.')</script>";
			} 
			else if ( ($_POST['file_name']=='page preview')||($_POST['file_name']=='page_preview')||($_POST['file_name']=='Page Preview')||($_POST['file_name']=='Page_Preview') ) // error message if "page preview" is used	
			{ 
    			$no_title_message = "<center><div class='error'>\"Page Preview\" name is in use. Choose a different name for your new web page.</div></center><br/>";
    			echo "<script type='text/javascript'>window.alert('Sorry, you must must use a different name for your new web page.')</script>"; 
			} 
			else 
			{
			$page_title = $_POST['file_name'];
			$base_file_name = str_replace(' ', '_', strtolower( strip_tags( preg_replace('/[^a-zA-Z0-9\s\-\_]/', '', ($_POST['file_name'])) ) )); // create base.php page
			$base_file = $rooturl.$base_file_name.'.php'; 
			$create_base_file = fopen($base_file, 'w+');
			$chmod = chmod($base_file, 0755); // start content to write to base.php page
			fwrite($create_base_file, "<?php include('includes/header.html');?>
				<div class=\"editable\">
					<?php include(\$contentpage);?>
				</div>
			<?php include('includes/footer.html');?>
			"); // end content to write to base.php page
			fclose($create_base_file);

			$content_file_name = str_replace(' ', '_', strtolower( strip_tags( preg_replace('/[^a-zA-Z0-9\s\-\_]/', '', ($_POST['file_name'])) ) )); // create content.txt page
			$content_file = $root.$content_file_name.'.txt';
			if (!file_exists($content_file)) 
				{
			  	$create_content_file = fopen($content_file, 'w+');
				$chmod = chmod($content_file, 0755);
				fwrite($create_content_file, "<h1 class='title'>$page_title</h1><p>This page is currently under construction.</p>"); // content to write to content.txt page
				fclose($create_content_file);
				}
			echo "<div class=\"saving\">Creating new page...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$base_file_name.php \">";
			exit();
			}
		}

	if ($use_template_manager == '1') 
		{
		$template_data=file_get_contents('fast_edit/editable_site_styles.css'); // populate template-manager textarea with editable_site_styles.css page
		if( (isset($_POST['submit_template'])=='Save Template Changes') || ( (isset($_GET['action'])) && ($_GET['action']=='save_template') ) ) // save changes to template-manager textarea
			{
			$template_content = 'fast_edit/editable_site_styles.css';
			$template_data = $_POST['template'];
			$template_fp = fopen($template_content,'w');
			$template_data = stripslashes($template_data);
			fwrite($template_fp,$template_data);
			fclose($template_fp);
			$url_save_template = str_replace('?action=save_template', '', $url);
			echo "<div class=\"saving\">Saving changes...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_save_template \">";
			exit();
			}

		$template = (isset($_GET['template'])) ? $_GET['template'] : '';
		switch($template) 
			{
				case 'backup_template':
			$backupfile_template = $_GET['backupfile_template'];
			copy('fast_edit/editable_site_styles.css', $rootbackup.'editable_site_styles.css');
			copy('fast_edit/editable_site_styles.css', $rootbackup.'editable_site_styles.txt');
			$url_backup_template = $basepage.'.php';
			break;
				case 'restore_template':
			$restorefile_template = $_GET['restorefile_template'];
			copy($rootbackup.'editable_site_styles.css', 'fast_edit/editable_site_styles.css');
			$url_restore_template = $basepage.'.php';
			echo "<div class=\"saving\">Restoring backup...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_restore_template \">";
			exit();
			break;
				default:
			break;
			}

		}

?>


<!-- Preload saving icon -->
<div id="saving-icon"></div>

<div class="fast-edit-container">
	<form id="formeditor1" name="formeditor1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?action=save">
	Welcome back&nbsp;<?php echo $_SESSION["username"];?>&nbsp;&nbsp;|&nbsp;&nbsp;
	Fast&nbsp;Edit:&nbsp;<img src="fast_edit/images/page_edit.png" alt="Fast Edit" title="Fast Edit" class="edit" /><img src="fast_edit/images/page_edit.png" alt="Fast Edit" title="Fast Edit" class="close-edit" />&nbsp;&nbsp;|&nbsp;&nbsp;
	File&nbsp;Manager:&nbsp;<img src="fast_edit/images/folder.png" alt="File Manager" title="File Manager" class="file-manager" /><img src="fast_edit/images/folder.png" alt="File Manager" title="File Manager" class="close-file-manager" />&nbsp;&nbsp;|&nbsp;&nbsp;
	<?php if ($use_template_manager == '1') { echo 'Template Manager:&nbsp;<img src="fast_edit/images/color.png" alt="Template Manager" title="Template Manager" class="template-manager" /><img src="fast_edit/images/color.png" alt="Template Manager" title="Template Manager" class="close-template-manager" />&nbsp;&nbsp;|&nbsp;&nbsp;'; } ;?>
	Page&nbsp;Manager:&nbsp;<img src="fast_edit/images/pages.png" alt="Page Manager" title="Page Manager" class="page-manager" /><img src="fast_edit/images/pages.png" alt="Page Manager" title="Page Manager" class="close-page-manager" />&nbsp;&nbsp;|&nbsp;&nbsp;
	Logout&nbsp;<?php echo $_SESSION['username'];?>:&nbsp;<a href="?action=logout"><img src="fast_edit/images/lock_open.png" alt="Logout <?php echo $_SESSION['username'];?>" title="Logout <?php echo $_SESSION['username'];?>" class="logout" /></a>
	<a href="" name="go_edit" class="close-edit x" title="Close Fast Edit">X</a><br/>
	<?php 
	$last_modified = filemtime($contentpage);
	echo "<div class='last-updated'>This page was last updated at ".gmdate("h:ia, F jS\, Y", ($last_modified+($gmt_offset*3600)))."</div>";
	?>
		<div class="editor">
			<textarea name="fastedit" cols="80" rows="10"><?php echo $data ?></textarea> 
			<?php if ( ($adv_page_manager == '1') && ($title != 'index') ) { ?>
				<div class="alias-manager-container">
					<div class="alias-manager-bg">
						<span class="alias-manager-bar">
						<?php
						$aliasfile = htmlentities(file_get_contents($menu_alias.$title.'.txt'), ENT_QUOTES); // populate alias text field
						echo "Menu Alias: <input type='hidden' id='alias_name' name='alias_name' value='$title' /><input type='text' name='menu_alias' size='30' value='$aliasfile' /> &nbsp;<span style='font-size:8pt;'>(Custom formatted menu button text)</span>";
						?>
						</span>
					</div>
				</div>
			<?php } ?>
		</div>
	</form>





<?php 
function ByteSize($bytes)  // http://www.phpfront.com/php/Convert-Bytes-to-corresponding-size/
	{ 
	$size = $bytes / 1024; 
	if($size < 1024) 
		{ 
		$size = number_format($size, 0); // format to 0 decimal places
		$size .= 'KB'; 
		}  
		else  
		{ 
		if($size / 1024 < 1024)  
			{ 
			$size = number_format($size / 1024, 0); // format to 0 decimal places
			$size .= 'MB'; 
			}  
			else if ($size / 1024 / 1024 < 1024)   
			{ 
			$size = number_format($size / 1024 / 1024, 2); 
			$size .= 'GB'; 
			}  
		} 
	return $size; 
	} 
// Returns '19.28mb' 
//print ByteSize('20211982'); 
?> 

<div class="file-manager-container">
	<span class="heading">File Manager</span>
	<a href="" class="close-file-manager" title="Close File Manager">X</a><br style="clear:both"/><br/>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	   <tr>
		<td align="right">Manage&nbsp;Images:</td>
		<td style="padding:0"><a href="" onclick="javascript:tinyBrowserPopUp('image','img'); return false;" title="Manage Images"><img src='fast_edit/images/images.png' alt='Manage Images' class='images'/></a></td>
		<td><span class="last-updated">(Upload size limit = <?php echo ByteSize($tinybrowser['maxsize']['image']);?>. Allowed file types = <?php echo $tinybrowser['filetype']['image'];?>)</span></td>
	   </tr>
	   <tr>
		<td align="right">Manage&nbsp;Documents:</td>
		<td style="padding:0"><a href="" onclick="javascript:tinyBrowserPopUp('file','img'); return false;" title="Manage Documents"><img src='fast_edit/images/files.png' alt='Manage Documents' class='docs'/></a></td>
		<td><span class="last-updated">(Upload size limit = <?php echo ByteSize($tinybrowser['maxsize']['file']);?>. Allowed file types = <?php echo $tinybrowser['filetype']['file'];?>)</span></td>
	   </tr>
	   <tr>
		<td align="right">Manage&nbsp;Media:</td>
		<td style="padding:0"><a href="" onclick="javascript:tinyBrowserPopUp('media','img'); return false;" title="Manage Media"><img src='fast_edit/images/media.png' alt='Manage Media' class='media'/></td>
		<td><span class="last-updated"></a>(Upload size limit = <?php echo ByteSize($tinybrowser['maxsize']['media']);?>. Allowed file types = <?php echo $tinybrowser['filetype']['media'];?>)</span></td>
	   </tr>
	</table>
		
	<div class="file-manager-more"><img class="file-manager-more-img" src="fast_edit/images/info.png" alt="More Info" title="More Info" />More information</div>
		<div class="file-manager-info">
			<ul>
			<li>While using the File Manager you can perform the following actions;</li>
				<ul>
				<?php if ($tinybrowser['allowupload'] == true) { echo '<li>Upload the file types specified above</li>'; } ;?>
				<?php if ($tinybrowser['allowdelete'] == true) { echo '<li>Delete and move your uploaded files</li>'; } ;?>
				<?php if ($tinybrowser['allowfolders'] == true) { echo '<li>Create, delete and rename folders to order your content</li>'; } ;?>
				</ul>
			</ul>
		</div>
</div>

<?php if ($use_template_manager == '1') { ?>
	<div class="template-manager-container">
		<div class="template-manager-container-inner">
			<span class="heading">Template Manager</span>
			<a href="" class="close-template-manager" title="Close Template Manager">X</a><br/>
			<form id="template-manager" name="template-manager" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?action=save_template">
				<div class="template-manager-bg">
					<span class="template-manager-bar">
					Save Changes: <input type="image" src="fast_edit/images/disk.png" name="submit_template" value="Save Template Changes" title="Save Template Changes" class="save-template" /> &nbsp;|&nbsp; 
					Backup: <a href='javascript:confirmBackupTemplate("<?php echo $_SERVER['PHP_SELF'];?>?template=backup_template&backupfile_template")' title='Backup Template'><img src='fast_edit/images/page_save.png' alt='Backup Template' class='backup'/></a> &nbsp;|&nbsp; 
					Preview Backup: <a href='<?php echo $siteurl?>fast_edit/_backup/editable_site_styles.txt' target='_blank' title='Preview Template Backup (new window)'><img src='fast_edit/images/preview.png' alt='Preview Template Backup (new window)' class='preview'/></a> &nbsp;|&nbsp; 
					Restore: <a href='javascript:confirmRestoreTemplate("<?php echo $_SERVER['PHP_SELF'];?>?template=restore_template&restorefile_template")' title='Restore Template Backup'><img src='fast_edit/images/page_go.png' alt='Restore Template Backup' class='restore'/></a>
					</span>
					<div class="templatemanager">
						<textarea name="template" cols="80" rows="10"><?php echo $template_data ?></textarea> 
					</div>
				</div>
			</form>
		</div>
		<div class="template-manager-more">
			<img class="template-manager-more-img" src="fast_edit/images/info.png" alt="More Info" title="More Info" />
			Tip: Depending on your browser, if your saved template changes do not immediately show, please do a hard-refresh (CTRL+F5) to reload the updates.
		</div>
	</div>
<?php } ?>

	<div class="page-manager-container">
		<span class="heading">Page Manager</span>
		<a href="" class="close-page-manager" title="Close Page Manager">X</a><br style="clear:both"/> <!--[if lte IE 7]><br/><![endif]-->
		<?php if ($adv_page_manager == '1') { ?>
		<form id="page-creator" name="page-creator" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>?action=create">
			<?php echo $no_title_message;?>
			Title of New Page: <input type="text" name="file_name" size="30" class="create" /> &nbsp;
			Create New Page: <input type="image" src="fast_edit/images/page_add.png" name="submit_create" value="Create" title="Create" /> &nbsp;
		<?php if ($menu_sort == '1') 
			{ 
			echo '<span class="last-updated">(New pages automatically appear in the menu, sorted alphabetically by page title)</span>';
			}
			else
			{
			echo '<span class="last-updated">(New pages automatically appear in the menu, arranged manually)</span>';
			}; ?>
		</form>
		<?php } ?>
		<?php if ($adv_page_manager == '0') { echo '<br/>'; }; ?>

<?php 
	if($_SESSION['username']) 
		{
		$action = (isset($_GET['action'])) ? $_GET['action'] : '';
		switch($action) 
			{
				case 'delete':
			if ($adv_page_manager == '1') 
				{
			$delfile = $_GET['delfile'];
			@unlink($rooturl.$delfile);
			$basepage_del = substr($delfile, 0, strpos($delfile, '.'));
			$contentpage_del = $basepage_del.'.txt'; 
			@unlink($root.$contentpage_del);
			@unlink($rootbackup.$contentpage_del);
			@unlink($menu_status.$contentpage_del);
			@unlink($menu_alias.$contentpage_del);
			if ( $basepage == $basepage_del ) 
				{
				$url_del = 'index.php'; 
				} 
				else 
				{
				$url_del = $basepage.'.php'; 
				}
			echo "<div class=\"saving\">Deleting page...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_del \">";
			exit();
				}
			break;
				case 'hide':
			if ($adv_page_manager == '1') 
				{
			$hidefile = $_GET['hidefile'];
			$basepage_hide = substr($hidefile, 0, strpos($hidefile, '.'));
			$contentpage_hide = $basepage_hide.'.txt'; 
			$fp = fopen($menu_status.$contentpage_hide, 'w');
			fwrite($fp, "hidden");
			fclose($fp);
			$url_hide = $basepage.'.php'; 
			echo "<div class=\"saving\">Updating menu status...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_hide \">";
			exit();
				}
			break;
				case 'unhide':
			if ($adv_page_manager == '1') 
				{
			$unhidefile = $_GET['unhidefile'];
			$basepage_unhide = substr($unhidefile, 0, strpos($unhidefile, '.'));
			$contentpage_unhide = $basepage_unhide.'.txt'; 
			unlink($menu_status.$contentpage_unhide);
			$url_unhide = $basepage.'.php'; 
			echo "<div class=\"saving\">Updating menu status...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_unhide \">";
			exit();
				}
			break;
				case 'order':
			if ($adv_page_manager == '1') 
				{
				$orderfile = $_GET['orderfile'];
				copy($rooturl.$orderfile, $root.$orderfile);
				copy($root.$orderfile, $rooturl.$orderfile);
				unlink($root.$orderfile);
				$url_order = $basepage.'.php';
				echo "<div class=\"saving\">Updating menu order...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
				echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_order \">";
				exit();
				}
			break;
				case 'backup':
			$backupfile = $_GET['backupfile'];
			$basepage_backup = substr($backupfile, 0, strpos($backupfile, '.'));
			$contentpage_backup = $basepage_backup.'.txt'; 
			copy($root.$contentpage_backup, $rootbackup.$contentpage_backup);
			$url_backup = $basepage.'.php';
			echo "<div class=\"saving\">Creating backup...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_backup \">";
			exit();
			break;
				case 'restore':
			$restorefile = $_GET['restorefile'];
			$basepage_restore = substr($restorefile, 0, strpos($restorefile, '.'));
			$contentpage_restore = $basepage_restore.'.txt'; 
			copy($rootbackup.$contentpage_restore, $root.$contentpage_restore);
			$url_restore = $basepage.'.php';
			echo "<div class=\"saving\">Restoring backup...<br/><br/><img src=\"fast_edit/images/saving.gif\" height=\"32\" width=\"32\" alt=\"Please Wait\" /><br/><br/>please wait</div>";
			echo "<meta http-equiv=\"refresh\" content=\"0; url=$url_restore \">";
			exit();
			break;
				default:
			$dir = opendir($rooturl); 
			while (false !== ($page = readdir($dir)))
				{
				if (strpos($page, '.php',1)) 
					{ 
					if ( ($page!='..') && ($page!='.') && ($page!='index.php') && ($page!='page_preview.php') && ($page!='_site_admin.php') ) // add .php files to exclude from page manager as required
						{

						// dynamic auto title script 
						$title = substr($page,0,strrpos($page,'.')); // strip the .php extension
						$title1 = str_replace('_and_', ' & ', $title); // convert 'and' to &
						$title2 = str_replace('_', ' ', strtolower($title1)); // convert name to lowercase and replace underscores with space
						$dynamic_title = ucwords($title2); // capitalize first letter 

						$aliasfile = file_get_contents($menu_alias.$title.'.txt');
						if ( $aliasfile != '' )
							{
							$alias_title = "title=\"Menu Alias = '$aliasfile'\"";
							$alias_indicator = "<span class='indicator'>*</span>";
							}
							else
							{
							$alias_title = "title=\"No Menu Alias\"";
							$alias_indicator = "";
							}

						$menu_status_file = $menu_status.$title.'.txt';
						$status = @file_get_contents($menu_status_file);
						if ( $status == 'hidden' )
							{ 
							$hide_page = "<a href='".$_SERVER['PHP_SELF']."?action=unhide&unhidefile=$page' title='Hidden (click to unhide)'><img src='fast_edit/images/lightbulb_off.png' alt='Hidden (click to unhide)' class='hidden'/></a>"; 
							} 
							else 
							{ 
							$hide_page = "<a href='".$_SERVER['PHP_SELF']."?action=hide&hidefile=$page' title='Visible (click to hide)'><img src='fast_edit/images/lightbulb.png' alt='Visible (click to hide)' class='visible'/></a>"; 
							}

						$basepage_backup = substr($page,0,strpos($page, '.'));
						$contentpage_backup = $rootbackup.$basepage_backup.'.txt';
						$backup_time = gmdate("h:ia", (@filemtime($contentpage_backup)+($gmt_offset*3600)));
						$backup_date = gmdate("d-M-y", (@filemtime($contentpage_backup)+($gmt_offset*3600)));
						$contentpage_current = $root.$basepage_backup.'.txt';
						$current_time = gmdate("h:ia", (filemtime($contentpage_current)+($gmt_offset*3600)));
						$current_date = gmdate("d-M-y", (filemtime($contentpage_current)+($gmt_offset*3600)));

						if ( file_exists($contentpage_backup) )
							{
							if ( filemtime($contentpage_backup) < filemtime($contentpage_current) ) 
								{  
								$bclass = 'backup-old';
								}
								else
								{  
								$bclass = 'yes-backup';
								}
							$backup_page = "<a href='javascript:confirmBackup(\"".$_SERVER['PHP_SELF']."?action=backup&backupfile=$page\")' title='Backup Page'><img src='fast_edit/images/page_save.png' alt='Backup Page' class='backup'/></a>";
							$backup_time_status = '<span class="mini">'.filemtime($contentpage_backup).'</span><br/><span class="'.$bclass.'">'.$backup_date.'<br/>'.$backup_time.'</span>';
							$preview_page = "<a href='".$siteurl."page_preview.php?previewfile=$page' target='_blank' title='Preview Backup (new window)'><img src='fast_edit/images/preview.png' alt='Preview Backup (new window)' class='preview'/></a>";
							$restore_page = "<a href='javascript:confirmRestore(\"".$_SERVER['PHP_SELF']."?action=restore&restorefile=$page\")' title='Restore Backup'><img src='fast_edit/images/page_go.png' alt='Restore Backup' class='restore'/></a>";
							}
							else
							{
							$backup_page = "<a href='".$_SERVER['PHP_SELF']."?action=backup&backupfile=$page' title='Backup Page'><img src='fast_edit/images/page_save.png' alt='Backup Page' class='backup'/></a>";
							$backup_time_status = '<span class="no-backup">no backup</span>';
							$preview_page = "<img src='fast_edit/images/preview_bw.png' alt='No Preview (backup required first)' title='No Preview (backup required first)' class='preview'/>";
							$restore_page = "<img src='fast_edit/images/page_white.png' alt='No Restore (backup required first)' title='No Restore (backup required first)' class='restore'/>";
							}

						if ( $menu_sort == '0' ) 
							{
							$secret_menu_order = "<td align='left' class='x'><span class='mini'>".filemtime($rooturl.$page)."</span></td>\n";
							$menu_order = "<td align='center'><a href='".$_SERVER['PHP_SELF']."?action=order&orderfile=$page' title='Move To End'><span class='mini'>".filemtime($rooturl.$page)."</span><br/><img src='fast_edit/images/down.png' alt='Move To End' class='order'/></a></td>\n";
							}
			
						if ($adv_page_manager == '1') 
							{
							$list .= "<tr>$secret_menu_order<td align='left'><span class='mini'>$dynamic_title</span><br/><a href='$siteurl$page' $alias_title>$alias_indicator$dynamic_title</a></td> <!-- <td><a href='$siteurl$page'>$siteurl$page</a></td> --> <td align='center'><span class='mini'>".filemtime($contentpage_current)."</span><br/>$current_date<br/>$current_time</td>$menu_order<td align='center'>$hide_page</td><td align='center'>$backup_page</td><td align='center'>$backup_time_status</td><td align='center'>$preview_page</td><td align='center'>$restore_page</td><td align='center'><a href='javascript:confirmDelete(\"".$_SERVER['PHP_SELF']."?action=delete&delfile=$page\")' title='Delete Page'><img src='fast_edit/images/cross.png' alt='Delete Page' class='delete'/></a></td></tr>";
							}
							else
							{
							$list .= "<tr>$secret_menu_order<td align='left'><span class='mini'>$dynamic_title</span><br/><a href='$siteurl$page' $alias_title>$alias_indicator$dynamic_title</a></td> <!-- <td><a href='$siteurl$page'>$siteurl$page</a></td> --> <td align='center'><span class='mini'>".filemtime($contentpage_current)."</span><br/>$current_date<br/>$current_time</td><td align='center'>$backup_page</td><td align='center'>$backup_time_status</td><td align='center'>$preview_page</td><td align='center'>$restore_page</td></tr>";
							}
						} 	
					}
				}

			if ( $menu_sort == '0' ) 
				{
				$secret_menu_order = "<th align='left' style='width:0; padding:0; border:0;'><a href='' title='Click to Sort'></a></th>\n";
				$menu_order_title = "<th><a href='' title='Click to Sort'>Menu Order</a></th>\n";
				}

			if ($adv_page_manager == '1') 
				{
				echo "<center><table id='page-list' class='tablesorter'><thead><tr>$secret_menu_order<th align='left'><a href='' title='Click to Sort'>Page Title</a></th> <!-- <th align='left'><a href='' title='Click to Sort'>Page URL</a></th> --> <th><a href='' title='Click to Sort'>Last Update</a></th>$menu_order_title<th><a href='' title='Click to Sort'>Menu Status</a></th><th><a href='' title='Click to Sort'>Backup?</a></th><th><a href='' title='Click to Sort'>Last Backup</a></th><th><a href='' title='Click to Sort'>Preview?</a></th><th><a href='' title='Click to Sort'>Restore?</a></th><th><a href='' title='Click to Sort'>Delete?</a></th></tr></thead><tbody>";
				}
				else
				{
				echo "<center><table id='page-list' class='tablesorter'><thead><tr>$secret_menu_order<th align='left'><a href='' title='Click to Sort'>Page Title</a></th> <!-- <th align='left'><a href='' title='Click to Sort'>Page URL</a></th> --> <th><a href='' title='Click to Sort'>Last Update</a></th><th><a href='' title='Click to Sort'>Backup?</a></th><th><a href='' title='Click to Sort'>Last Backup</a></th><th><a href='' title='Click to Sort'>Preview?</a></th><th><a href='' title='Click to Sort'>Restore?</a></th></tr></thead><tbody>";
				}
// start special functions and hard coding for index.php page to disable menu visibility switch and delete
			$contentpage_backup_index = $rootbackup.'index.txt';
			$backup_time_index = gmdate("h:ia", (@filemtime($rootbackup.'index.txt')+($gmt_offset*3600)));
			$backup_date_index = gmdate("d-M-y", (@filemtime($rootbackup.'index.txt')+($gmt_offset*3600)));
			$current_time_index = gmdate("h:ia", (filemtime($root.'index.txt')+($gmt_offset*3600)));
			$current_date_index = gmdate("d-M-y", (filemtime($root.'index.txt')+($gmt_offset*3600)));

			if ( file_exists($rootbackup.'index.txt') )
				{
				if ( filemtime($rootbackup.'index.txt') < filemtime($root.'index.txt') ) 
					{  
					$bclass = 'backup-old';
					}
					else
					{  
					$bclass = 'yes-backup';
					}
				$backup_index_page = "<a href='javascript:confirmBackup(\"".$_SERVER['PHP_SELF']."?action=backup&backupfile=index.php\")' title='Backup Page'><img src='fast_edit/images/page_save.png' alt='Backup Page' class='backup'/></a>";
				$backup_time_index_status = '<span class="mini">'.filemtime($rootbackup.'index.txt').'</span><br/><span class="'.$bclass.'">'.$backup_date_index.'<br/>'.$backup_time_index.'</span>';
				$preview_index_page = "<a href='".$siteurl."page_preview.php?previewfile=index.php' target='_blank' title='Preview Backup (new window)'><img src='fast_edit/images/preview.png' alt='Preview Backup (new window)' class='preview'/></a>";
				$restore_index_page = "<a href='javascript:confirmRestore(\"".$_SERVER['PHP_SELF']."?action=restore&restorefile=index.php\")' title='Restore Backup'><img src='fast_edit/images/page_go.png' alt='Restore Backup' class='restore'/></a>";
				}
				else
				{
				$backup_index_page = "<a href='".$_SERVER['PHP_SELF']."?action=backup&backupfile=index.php' title='Backup Page'><img src='fast_edit/images/page_save.png' alt='Backup Page' class='backup'/></a>";
				$backup_time_index_status = '<span class="no-backup">no backup</span>';
				$preview_index_page = "<img src='fast_edit/images/preview_bw.png' alt='No Preview (backup required first)' title='No Preview (backup required first)' class='preview'/>";
				$restore_index_page = "<img src='fast_edit/images/page_white.png' alt='No Restore (backup required first)' title='No Restore (backup required first)' class='restore'/>";
				}

			if ( $menu_sort == '0' ) 
				{ 
				$secret_menu_order = "<td align='left' class='x'><span class='mini'>0</span></td>\n";
				$menu_order_index = "<td align='center'><img src='fast_edit/images/cross_bw.png' alt='Always First' title='Always First' class='order'/></td>\n";
				}

			if ($adv_page_manager == '1') 
				{
				echo "<tr>$secret_menu_order<td align='left'><span class='mini'>0</span><br/><a href='$siteurl'>Home</a></td> <!-- <td><a href='$siteurl'>$siteurl</a></td> --> <td align='center'><span class='mini'>".filemtime($root.'index.txt')."</span><br/>$current_date_index<br/>$current_time_index</td>$menu_order_index<td align='center'><img src='fast_edit/images/lightbulb.png' alt='Always Visible' title='Always Visible' class='visible'/></td><td align='center'>$backup_index_page</td><td align='center'>$backup_time_index_status</td><td align='center'>$preview_index_page</td><td align='center'>$restore_index_page</td><td align='center'><img src='fast_edit/images/cross_bw.png' alt='No Delete' title='No Delete' class='delete'/></td></tr>";
				}
				else
				{
				echo "<tr>$secret_menu_order<td align='left'><span class='mini'>0</span><br/><a href='$siteurl'>Home</a></td> <!-- <td><a href='$siteurl'>$siteurl</a></td> --> <td align='center'><span class='mini'>".filemtime($root.'index.txt')."</span><br/>$current_date_index<br/>$current_time_index</td><td align='center'>$backup_index_page</td><td align='center'>$backup_time_index_status</td><td align='center'>$preview_index_page</td><td align='center'>$restore_index_page</td></tr>";
				}
// end special functions and hard coding for index.php page to disable menu visibility switch and delete

			echo $list;
			echo "</tbody></table></center>";
			break;
			}
?>

		<br/>
		<div id="pager" class="pager">
			<form>
				<img src="fast_edit/images/first.png" title="First Page" alt="First Page" class="first"/>
				<img src="fast_edit/images/prev.png" title="Previous Page" alt="Previous Page" class="prev"/>
				<input type="text" class="pagedisplay"/>
				<img src="fast_edit/images/next.png" title="Next Page" alt="Next Page" class="next"/>
				<img src="fast_edit/images/last.png" title="Last Page" alt="Last Page" class="last"/>
				<select class="pagesize">
					<option value="10">> Limit</option>
					<option value="5">5 per page</option>
					<option value="10">10 per page *</option>
					<option value="15">15 per page</option>	
					<option value="20">20 per page</option>
					<option value="25">25 per page</option>	
					<option value="1000">All pages</option>	
				</select> <span class="last-updated">(* default limit is 10 per page)</span>
			</form>
		</div>
	</div>

<?php 
		}
?>


</div>
<?php } } ?>
