<?php if(!defined('master_script')) die();

/**
 * Backend template
 *
 * @category   Extension (pages)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-11-06
 */

?>

<!-- EXTENSION: pages -->

<div id="pages">
	<?php connector('pages before'); ?>

	<h3><?php echo txt('pages', 'Werkzeuge'); ?></h3>

    <ul>
    	<li class="files <?php if($_GET['backend'] == 'files') echo 'active'; ?>"><a href="index.php?backend=files&amp;pagetype=<?php if(isset($page_info)) echo $page_info->pagetype; ?>&amp;catalogue=<?php if(isset($page_info)) echo $page_info->catalogue; ?>&amp;page=<?php if(isset($page_info)) echo $page_info->alias; ?>"><?php echo txt('pages', 'Dateiverwaltung'); ?></a></li>
		<li class="trashcan <?php if($_GET['backend'] == 'trashcan') echo 'active'; ?>"><a href="index.php?backend=trashcan"><?php echo txt('pages', 'Papierkorb'); ?></a></li>
	</ul>

	<?php connector('pages tools'); ?>

	<?php
		// Get news catalogue
		$news_database_folder = $system_data['folder']['database'] . 'news/';
		$news_database_files = filelist($news_database_folder, 'xml', 0, array('topics.xml'), true);
		
		rsort($news_database_files);
		
		foreach($news_database_files as $news_database_file) {
			$year = substr(basename($news_database_file), 0, 4);
			$month = substr(basename($news_database_file), 5, 2);
			
			$cat_xml = simplexml_load_file($news_database_file);
			$cat_xml->year = $year;
			$cat_xml->month = $month;
			$cat_xml->catalogue = basename($news_database_file);
			
			$news_database[$year][] = $cat_xml;
		}
	?>
	
	<?php if(isset($news_database)) { ?>
		<h3><?php echo txt('pages', 'Nachrichtenseiten'); ?></h3>
		
		<ul class="news-pages-years">
		<?php foreach($news_database as $year => $month) { ?>
			<li class="year">
				<a><span class="year"><?php echo $year; ?></span></a>
				
				<ul class="news-pages-months <?php if(isset($_GET['year']) && $_GET['year'] == $year || (isset($page_info) && substr($page_info->catalogue, 0, 4) == $year)) echo 'active'; ?>">
				<?php foreach($month as $month_entry) { ?>
					<li class="month <?php if(isset($_GET['catalogue']) && $_GET['catalogue'] == $month_entry->catalogue || (isset($page_info) && $page_info->catalogue == strval($month_entry->catalogue))) echo 'active'; ?>"><a href="index.php?backend=news-pages&amp;year=<?php echo $month_entry->year; ?>&amp;catalogue=<?php echo $month_entry->catalogue; ?>"><?php echo translate_keyword('month: ' . $month_entry->month); ?></a></li>
				<?php } ?>
				</ul>
			</li>
		<?php } ?>
		</ul>
	<?php } ?>

	<h3><?php echo txt('pages', 'Standardseiten'); ?></h3>
		    
    <?php foreach($database_categories->cfile as $category_entry) { ?>
	    <ul>
   			<li class="category<?php if(isset($category_info) && $category_info->id == $category_entry->id) echo ' active'; if($category_entry->published == 0) echo ' hidden '; if($category_entry->id == $system_data['backend']['info pages id']) echo ' info-pages ';?>">
   				<?php
   					$status = (isset($category_info) && $category_info->id == $category_entry->id) || (isset($page_info) && strval($page_info->catalogue) == strval($category_entry->id)) ? 'active' : '';
					
    				$database_category_file = $system_data['folder']['database'] . 'standard/' . $category_entry->id . '.cat';
    				$database_category = is_file($database_category_file) ? file($database_category_file) : array();
   				?>
   				
   				<span class="collapse <?php echo $status; ?>"></span>
   				<a class="category-name" href="index.php?backend=edit-category&amp;category=<?php echo $category_entry->id; ?>" title="<?php echo $category_entry->title; ?>"><?php echo limit_text($category_entry->title, 21, '…'); ?> (<?php echo count($database_category); ?>)</a>
    			
	    		<ul class="category-pages <?php echo $status; ?>">
		    		<?php foreach($database_category as $page_entry) { ?>
		    			<?php
		    				$page_entry = trim($page_entry);
		    				$page_entry_info = get_page_info($page_entry);
		    			?>
		    			
			        	<li class="page <?php if(isset($page_info) && $page_info->alias == $page_entry) echo 'active'; if($page_entry_info->published == 0) echo ' hidden'; if($page_entry == $system_data['file']['404']) echo ' error-404 '; if($page_entry == $system_data['file']['homepage']) echo ' homepage '; ?>"><a href="index.php?backend=edit-page&amp;page=<?php echo $page_entry; ?>&amp;pagetype=<?php echo $page_entry_info->pagetype; ?>" title="<?php echo $page_entry_info->title; ?> (<?php echo $page_entry_info->alias; ?>)"><?php echo limit_text($page_entry_info->title != '' ? $page_entry_info->title : $page_entry, 21, '…'); ?></a></li>
		    		<?php } ?>
	    		</ul>
	    	</li>
		</ul>
    <?php } ?>

	<?php connector('pages after'); ?>
</div>