<!-- MODULE: form -->

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

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

/**
 * Default settings
 *
 * @category   Module (form)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-05-16
 */

	if(!isset($module_settings['form']['template'])) $module_settings['form']['template'] = '';
	if(!isset($module_settings['form']['send to'])) $module_settings['form']['send to'] = 'email';
	if(!isset($module_settings['form']['email address'])) $module_settings['form']['email address'] = '';
	if(!isset($module_settings['form']['url address'])) $module_settings['form']['url address'] = '';
	if(!isset($module_settings['form']['message sent'])) $module_settings['form']['message sent'] = txt('form', 'Danke, wir haben Ihre Nachricht erhalten.');

/**
 * Get templates for form
 *
 * @category   Module (form)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-09-10
 */

	// Get form templates
	$form_templates_default = filelist($system_data['folder']['modules'] . 'form/form-templates/', 'tpl', array(), array(), true);
	$form_templates_custom = filelist($system_data['folder']['templates'] . $user_data["frontend template"] . '/modules/form/form-templates/', 'tpl', array(), array(), true);
	
	$form_template_files = array_merge($form_templates_default, $form_templates_custom);

/**
 * Backend template
 *
 * @category   Module (form)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-10-11
 */
	
?>

<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('form', 'title: form'); ?></h4>
	
	<div class="column">
		<p>
			<label for="send_to"><?php echo txt('form', 'Senden an'); ?>:</label>
			<select size="1" name="send_to" id="send_to" onchange="showSendToOptions()">
				<option value="email" <?php if($module_settings['form']['send to'] == 'email') echo 'selected="selected"'; ?>><?php echo txt('form', 'E-Mail-Adresse'); ?></option>
				<option value="url" <?php if($module_settings['form']['send to'] == 'url') echo 'selected="selected"'; ?>><?php echo txt('form', 'Adresse (URL)'); ?></option>
			</select>
		</p>
		
		<p id="email-field" style="display: none">
			<label for="email_address"><?php echo txt('form', 'E-Mail-Adresse'); ?>:</label>
			<input type="text" class="text" name="email_address" id="email_address" value="<?php echo clean_output($module_settings['form']['email address']); ?>">
		</p>
	
		<p id="url-field" style="display: none">
			<label for="url_address"><?php echo txt('form', 'Adresse (URL)'); ?>:</label>
			<input type="text" class="text" name="url_address" id="url_address" value="<?php echo clean_output($module_settings['form']['url address']); ?>">
		</p>
		
		<?php connector('form left'); ?>
	</div>
	
	<div class="column last-column">
		<p>
			<label for="template"><?php echo txt('form', 'Formularvorlage'); ?>:</label>
			<select size="1" name="template" id="template" onchange="showTemplatePreview()">
				<?php foreach($form_template_files as $form_template) { ?>
					<option value="<?php echo clean_output($form_template); ?>" <?php if($form_template == $module_settings['form']['template']) echo 'selected="selected"'; ?>><?php echo substr($form_template, strrpos($form_template, '/') + 1); ?></option>
				<?php } ?>
			</select>
		</p>
		
		<?php connector('form right'); ?>
	</div>

	<div style="clear: both"></div>
	
	<div id="message-field">
		<br>
		<h4 for="message_sent"><?php echo txt('form', 'Meldung nach dem Senden'); ?></h4>
		<textarea name="message_sent" id="message_sent" cols="30" rows="10"><?php echo strip_custom_tags(stripslashes($module_settings['form']['message sent']), true, false, true, false, false); ?></textarea>
	</div>
	
	<!-- Save -->
	<input name="save_form" type="hidden">
	<input id="save" name="save_content" type="submit" value="<?php echo txt('form', 'Speichern'); ?>">
	<input id="delete" name="delete_content" type="submit" value="<?php echo txt('form', 'Löschen'); ?>" onclick="this.form.confirm = window.confirm('<?php echo txt('form', 'Soll das Inhaltselement wirklich gelöscht werden?'); ?>')">
</form>

<br>

<h4><?php echo txt('form', 'Gewählte Formularvorlage'); ?></h4>
<div id="template-preview" style="width: 75%"></div>

<script type="text/javascript">
    // Show template preview
    var showTemplatePreview = function() {
    	var templateSelector = document.getElementById('template');
    	var templateName = templateSelector.options[templateSelector.selectedIndex].value;
	    var templatePreview = document.getElementById('template-preview');
    
    	templatePreview.innerHTML = '<div class="loading"></div>';
    	
		var templateContent = MoreCSS.createXMLHttpRequest();
	   	templateContent.open('get', noCache(templateName), true);
	   	
		templateContent.onreadystatechange = function() {
			if(templateContent.readyState == 4 && templateContent.status == 200) {
				templatePreview.innerHTML = templateContent.responseText;
			}
		};

		templateContent.send(null);
    };
    
    // Show options for Send To
    var showSendToOptions = function() {
    	var sendToSelector = document.getElementById('send_to');
    	var value = sendToSelector.options[sendToSelector.selectedIndex].value;
    	var emailField = document.getElementById('email-field');
    	var urlField = document.getElementById('url-field');
    	var messageField = document.getElementById('message-field');

		emailField.style.display = 'none';
		urlField.style.display = 'none';
		messageField.style.display = 'none';
    	
    	switch(value) {
    		case 'email' : emailField.style.display = 'block'; messageField.style.display = 'block'; break;
    		case 'url' : urlField.style.display = 'block'; break;
    	}
    };
    
    // Start
    showTemplatePreview();
    showSendToOptions();
</script>

<!-- TinyMCE -->
<script type="text/javascript">
	// Init TinyMCE
	tinyMCE.init({
		// General options
		mode : 'exact',
		elements : 'message_sent',
		theme : 'advanced',
		skin : 'pagemap',

		language : '<?php echo substr($user_data['backend language'],0 , 2); ?>',
		button_tile_map : true,
		width : '625',
		height : '350',
		
		element_format : '<?php echo $template_data['syntax']; ?>',
		cleanup : true,
		cleanup_on_startup : true,

		plugins : '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,|,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 : true,
		
		// Drop lists
		external_link_list_url : 'index.php?backend&actions=tinymce-filelist.php&action=filelist&type=all&path=<?php echo $system_data['folder']['pages'] . $_GET['page']; ?>/',
		external_image_list_url : 'index.php?backend&actions=tinymce-filelist.php&action=filelist&type=images&path=<?php echo $system_data['folder']['pages'] . $_GET['page']; ?>/',
		media_external_list_url : 'index.php?backend&actions=tinymce-filelist.php&action=filelist&type=multimedia&path=<?php echo $system_data['folder']['pages'] . $_GET['page']; ?>/',
		
		// CSS
		content_css : 'index.php?backend&actions=tinymce-content-css.php'
	});
</script>