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

/**
 * Copyright (C) Nico Wenig
 * All rights reserved
 *
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @filesource
 */



/**
 * Load stylesheet
 *
 * @category   Extension (files)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-07-11
 */

	$system_data['backend']['header'] .= '
		<link rel="MoreCSS" href="' . $system_data['folder']['extensions'] . 'files/MoreCSS.css">
		<link rel="stylesheet" type="text/css" media="all" href="' . $system_data['folder']['extensions'] . 'files/index.css">
	';

/**
 * Get pages list
 *
 * @category   Extension (files)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-29
 */
	
	// Defaults
    $catalogue_label = '';

   	$catalogue_list = array();
    $pages_list = array();

    $_GET['pagetype'] = isset($_GET['pagetype']) && $_GET['pagetype'] != '' ? $_GET['pagetype'] : 'standard';
    
    // Get standard pages
    if($_GET['pagetype'] == 'standard') {
    	$catalogue_label = txt('files', 'Kategorie');
    	
    	foreach($database_categories->cfile as $category_entry) $catalogue_list[] = $category_entry;
    	
    	if(isset($_GET['catalogue']) && $_GET['catalogue'] != '') {
	    	$database_folder = $system_data['folder']['database'] . 'standard/';
    		$catalogue_file = $database_folder . $_GET['catalogue'] . '.cat';
    		$pages_dump = is_file($catalogue_file) ? file($catalogue_file) : array();
    		
    		foreach($pages_dump as $page_entry) $pages_list[] = get_page_info(trim($page_entry));
    	}
    }

    // Get news pages
    if($_GET['pagetype'] == 'news') {
    	$catalogue_label = txt('files', 'Zeitraum');
    	
		$news_database_folder = $system_data['folder']['database'] . 'news/';
		$news_database_files = filelist($news_database_folder, 'xml', 0, array('topics.xml'), true);
		
		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->title = translate_keyword('month: ' . $month) . ' ' . $year;
			$cat_xml->id = basename($news_database_file);
			
			$catalogue_list[] = $cat_xml;
		}
    	
    	if(isset($_GET['catalogue']) && $_GET['catalogue'] != '') {
    		$catalogue_file = $news_database_folder . $_GET['catalogue'];
    		$catalogue_xml = is_file($catalogue_file) ? simplexml_load_file($catalogue_file) : simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><pages></pages>');
    		
    		foreach($catalogue_xml as $page_entry) $pages_list[] = $page_entry;
    	}
    }
    
    connector('files get pages');

?>