<!-- MODULE: image -->

<?php quick_help(txt('image', 'quick-help: image')); ?>

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

/**
 * Default settings
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-08-31
 */

	if(!isset($module_settings['image']['show image'])) $module_settings['image']['show image'] = '';
	if(!isset($module_settings['image']['image width'])) $module_settings['image']['image width'] = 800;
	if(!isset($module_settings['image']['image height'])) $module_settings['image']['image height'] = 0;
	if(!isset($module_settings['image']['show image title'])) $module_settings['image']['show image title'] = 1;
	if(!isset($module_settings['image']['show image description'])) $module_settings['image']['show image description'] = 1;

/**
 * Get images in folder
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-05
 */

	$page_folder_images = array();
	$page_folder = $system_data['folder']['pages'] . $_GET['page'] . '/';
	
	if(file_exists($page_folder)) {
		$page_folder_open = opendir($page_folder);
	   	
	   	while($entry = readdir($page_folder_open)) {
	   		if(is_file($page_folder . $entry)) {
	   			$path_parts = pathinfo($entry);
	   			if(get_file_type($path_parts['extension']) == 'image') $page_folder_images[] = $entry;
	   		}
	   	}
	   	
		closedir($page_folder_open);
	}

/**
 * Backend template
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-09-07
 */
	
?>

<form accept-charset="utf-8" method="post" action="index.php?backend=edit-content&amp;page=<?php echo $_GET['page']; ?>&amp;module-to-edit=<?php echo $_GET['module-to-edit']; ?>&amp;module-position=<?php echo $_GET['module-position']; ?>" onsubmit="return this.confirm">
	<?php include($system_data['folder']['modules'] . 'module-properties/backend-template.tpl'); ?>
	
	<h4><?php echo txt('image', 'title: image'); ?></h4>

	<div class="column">
		<div class="drop-down">
			<label><?php echo txt('image', 'Pfad'); ?>:</label>
			<input type="text" name="show_image" id="show_image" value="<?php echo clean_output($module_settings['image']['show image']); ?>">
			<?php if(count($page_folder_images) > 0) { ?>
				<a class="toggler for-input" href="#show_image">&nbsp;</a><br>
				<div class="list custom-list" style="padding-right: 10px">
					<div id="filetree" class="dir closed">
					</div>
				</div>
			<?php } ?>
		</div>

		<script type="text/javascript">
			// Global data
			var imageExtensions = { 'jpg' : 1, 'jpeg' : 1, 'png' : 1, 'gif' : 1, 'bmp' : 1 };
			
			// Load filetree
			MoreCSS.filetree(document.getElementById('filetree'), ['filetree: pages/<?php echo $_GET['page']; ?>/', 'filetree-server: index.php?backend&actions=morecss-filelist.php&path=', 'filetree-callback: pastePath']);
			
			// Paste image path
			var pastePath = function(type, element) {
				// Add tooltip to all image links
				var links = document.getElementById('filetree').getElementsByTagName('A');
				for(var i = 0; i < links.length; i++) {
					if(imageExtensions[links[i].className])
						MoreCSS.tooltip(links[i], ['tooltip-class:filetree-preview', 'tooltip-opacity:0.85'], '<img src="' + links[i].rel + '">');
				}

				if(type == 'file') {
					var imagePath = addslashes(element.firstChild.rel);
					var imageExtension = imagePath.substring(imagePath.lastIndexOf('.') + 1).toLowerCase();
					
					switch(imageExtension) {
						case 'jpg' : case 'jpeg' : case 'gif' : case 'png' : case 'bmp' :
							document.getElementById('show_image').value = imagePath;
					}
				}
			};
		</script>
		
		<?php connector('image left'); ?>
	</div>

	<div class="column last-column">
		<table style="width: 100%">
			<tr>
				<td>
					<label for="image_width"><?php echo txt('images', 'Bildgröße'); ?>:</label>
				</td>
				<td style="text-align: right">
					<input type="text" id="image_width" name="image_width" class="number" value="<?php echo clean_output($module_settings["image"]["image width"]); ?>"> × <input type="text" id="image_height" name="image_height" class="number" value="<?php echo clean_output($module_settings["image"]["image height"]); ?>"> px
				</td>
			</tr>
		</table>
		
		<hr>

		<p>
			<input name="show_image_title" id="show_image_title" type="checkbox" <?php if($module_settings['image']['show image title'] == 1) echo 'checked="checked"'; ?>>
			<label class="checkbox" for="show_image_title"><?php echo txt('image', 'Bildtitel anzeigen'); ?></label>
		</p>
	
		<p>
			<input name="show_image_description" id="show_image_description" type="checkbox" <?php if($module_settings['image']['show image description'] == 1) echo 'checked="checked"'; ?>>
			<label class="checkbox" for="show_image_description"><?php echo txt('image', 'Bildbeschreibung anzeigen'); ?></label>
		</p>
		
		<?php connector('image right'); ?>
	</div>

	<div style="clear: both"></div>
	
	<!-- Save -->
	<input name="save_image" type="hidden">
	<input id="save" name="save_content" type="submit" value="<?php echo txt('image', 'Speichern'); ?>">
	<input id="delete" name="delete_content" type="submit" value="<?php echo txt('image', 'Löschen'); ?>" onclick="this.form.confirm = window.confirm('<?php echo txt('image', 'Soll das Inhaltselement wirklich gelöscht werden?'); ?>')">
</form>