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

/**
 * General data
 *
 * @category   Extension (files)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-03-24
 */

	$pathinfo = pathinfo($_GET['path']);
	$pathinfo['dirname'] = $pathinfo['dirname'] . '/';
	$pathinfo['storage'] = $pathinfo['dirname'] . 'storage/';
	$pathinfo['xmlfile'] = $pathinfo['storage'] . $pathinfo['basename'] . '.xml';
	$pathinfo['xml'] = file_exists($pathinfo['xmlfile']) ? simplexml_load_file($pathinfo['xmlfile']) : simplexml_load_string('<?xml version="1.0" encoding="utf-8"?><file></file>');
	
/**
 * Save title and description
 *
 * @category   Extension (files)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-04-05
 */

	if(isset($_POST['save_properties'])) {
		if(!file_exists($pathinfo['storage'])) mkdir($pathinfo['storage']);
		
		$pathinfo['xml']->title[0] = xml_string(strip_tags(trim(stripslashes($_POST['title']))));
		$pathinfo['xml']->description[0] = strip_custom_tags(xml_string(stripslashes($_POST['description'])), true, true, true, false, true);
		$pathinfo['xml']->saveXML($pathinfo['xmlfile']);
		
		header('location: index.php?backend&actions=fileeditor.php&type=' . $_GET['type'] . '&path=' . $_GET['path']);
	}

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

?>

<!DOCTYPE html>
<html>

<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<meta name="language" content="<?php echo $user_data['backend language']; ?>">
	<meta name="generator" content="http://getpagemap.de/">
	
	<title><?php echo txt('global', 'Dateieigenschaften'); ?></title>
	
	<!-- TinyMCE -->
	<script type="text/javascript" src="<?php echo $system_data['folder']['plugins']; ?>tiny-mce/tiny_mce_gzip.js"></script>
	<script type="text/javascript">
		tinyMCE_GZ.init({
			plugins : "safari, advhr, advimage, advlink, autosave, contextmenu, emotions, fullscreen, insertdatetime, layer, media, nonbreaking, paste, safari, searchreplace, style, table, visualchars, xhtmlxtras",
		  	themes : "advanced",
		  	languages : "<?php echo substr($user_data["backend language"],0 , 2); ?>",
		  	disk_cache : false,
		  	debug : false
		  	
		});
	</script>

	<!-- BASICS -->	
	<link rel="stylesheet" type="text/css" media="all" href="<?php echo $system_data['folder']['backend']; ?>index.css">
	
	<style type="text/css">
		html, body {
			width: auto;
			height: auto;
		} 
		
		body {
			margin: 15px;
			background: #fff;
		}
	</style>
</head>

<body>
	
	<?php if(is_file($_GET['path'])) { ?>
		
		<?php
	
		/**
		 * Title and description
		 *
		 * @category   Extension (files)
		 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
		 * @version	   2009-06-14
		 */
	 	
		?>
		
		<!-- TinyMCE -->
		<script type="text/javascript">
			// Init TinyMCE
			tinyMCE.init({
				// General options
				mode : "exact",
				elements : "description",
				theme : "advanced",
				skin : 'pagemap',
				auto_reset_designmode : true,
				ask : false,
		
				language : '<?php echo substr($user_data["backend language"],0 , 2); ?>',
				button_tile_map : true,
				width : "635",
				height : "350",
				
				element_format : '<?php echo $template_data['syntax']; ?>',
				cleanup : true,
				cleanup_on_startup : true,
				paste_auto_cleanup_on_paste : true,
				entity_encoding : "raw",
		
				plugins : "safari, advhr, advimage, advlink, autosave, contextmenu, emotions, fullscreen, insertdatetime, layer, media, nonbreaking, paste, safari, searchreplace, style, table, visualchars, xhtmlxtras",
				
				// Plugin options
				plugin_insertdate_dateFormat : "%d.%m.%Y",
				plugin_insertdate_timeFormat : "%H:%M:%S",
				
				// Theme options
				theme_advanced_buttons1 : "fullscreen,|,undo,redo,|,pastetext,cleanup,removeformat,newdocument,|,replace,|,styleprops,attribs,code,|,image,media,advhr,|,link,unlink,anchor,|,charmap,nonbreaking,|,cite,abbr,acronym",
				theme_advanced_buttons2 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontselect,fontsizeselect,,styleselect,|,forecolor,backcolor",
				theme_advanced_buttons3 : "sub,sup,|,bullist,numlist,|,outdent,indent,|,visualaid,tablecontrols",
				
				theme_advanced_font_sizes : "9px,10px,11px,12px,14px,16px,18px,20px,22px,24px,26px,28px,30px,36px,48px,60px,72px",
				theme_advanced_blockformats : "div,p,blockquote,address,pre,h1,h2,h3,h4,h5,h6",
				theme_advanced_toolbar_location : "top",
				theme_advanced_toolbar_align : "left",
				theme_advanced_statusbar_location : "bottom",
				theme_advanced_resizing : false,
				
				// Drop lists
				external_link_list_url : "index.php?backend&actions=tinymce-filelist.php&action=filelist&type=all&path=<?php echo $pathinfo['dirname']; ?>",
				external_image_list_url : "index.php?backend&actions=tinymce-filelist.php&action=filelist&type=images&path=<?php echo $pathinfo['dirname']; ?>",
				media_external_list_url : "index.php?backend&actions=tinymce-filelist.php&action=filelist&type=multimedia&path=<?php echo $pathinfo['dirname']; ?>",
				
				// CSS
				content_css : "index.php?backend&actions=tinymce-content-css.php"
			});
		</script>
	
		<form accept-charset="utf-8" method="post" action="index.php?backend&amp;actions=fileeditor.php&amp;type=<?php echo $_GET['type']; ?>&amp;path=<?php echo $_GET['path']; ?>">
			<p>
				<label for="title"><?php echo txt('global', 'Titel'); ?>:</label><br>
				<input style="display: inline; width: 75%" type="text" id="title" name="title" value="<?php echo clean_output($pathinfo['xml']->title); ?>"> 
				<input name="save_properties" type="submit" value="<?php echo txt('global', 'Speichern'); ?>">
			</p>
							
			<p>
				<label for="description"><?php echo txt('global', 'Beschreibung'); ?>:</label>
				<textarea name="description" id="description" cols="10" rows="5"><?php echo $pathinfo['xml']->description; ?></textarea>
			</p>
		</form>
	
	<?php } else { ?>
			<p class="error"><?php echo txt('global', 'Die Datei konnte nicht gefunden werden.'); ?>
	<?php } ?>
	
</body>
</html>
