<?php if(!defined('master_script')) die(); global $system_data, $modules, $comments, $id, $user_data, $page_info; ?>

<div class="comments-form" id="comments-form-<?php echo $id; ?>" <?php if($module_settings["comments"]["embedded"] == 1) { ?>style="display: none"<?php } ?>>
	<div class="comments">
		<h4 class="module-title"><?php echo txt('comments', 'Kommentare'); ?></h4>
		<div class="container" id="comments-<?php echo $id; ?>">
			<?php for($i = 0; $i < count($comments); $i++) { ?>
				<div class="comment">
					<span class="number"><?php echo $i + 1; ?></span>

					<p class="headline">
						<?php if($comments[$i]['website'] != '') { ?><a href="<?php echo $comments[$i]['website']; ?>"><?php } ?><?php echo $comments[$i]['name']; ?><?php if($comments[$i]['website'] != '') { ?></a><?php } ?>
						<span><?php echo $comments[$i]['timestamp']; ?></span>
					</p>
					
					<div class="text"><?php echo htmlspecialchars_decode($comments[$i]['text']); ?></div>
				</div>
			<?php } ?>
			
			<?php if(count($comments) == 0) { ?>
				<p class="no-comment"><?php echo txt('comments', 'Bisher keine Kommentare.'); ?></p>
			<?php } ?>
		</div>
	</div>
	
	<div class="comments-form-container" id="comments-form-container-<?php echo $id; ?>">
		<?php if($module_settings["comments"]["closed"] == 0) { ?>
			<?php if(!isset($module_settings["comments"]["comment submitted"])) { ?>
			    <form accept-charset="utf-8" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">
			    	<fieldset>
						<legend><?php echo txt('comments', 'Kommentar schreiben'); ?>:</legend>

						<?php if(isset($module_settings["comments"]["message"])) { ?>
							<p class="error"><?php echo $module_settings["comments"]["message"]; ?></p>
						<?php } ?>
			    		
			    		<p class="text required"><label for="name"><?php echo txt('comments', 'Name'); ?>*</label><br>
			    		<input type="text" id="name" name="name" value="<?php echo clean_output($module_settings["comments"]["comment name"]); ?>"></p>
		
			    		<p class="text required"><label for="email"><?php echo txt('comments', 'E-Mail-Adresse'); ?>* <small>(<?php echo txt('comments', 'Wird nicht angezeigt'); ?>)</small></label><br>
			    		<input type="text" id="email" name="email" value="<?php echo clean_output($module_settings["comments"]["comment email"]); ?>"></p>
			    	
			    		<p class="text"><label for="website"><?php echo txt('comments', 'Website'); ?></label><br>
			    		<input type="text" id="website" name="website" value="<?php echo clean_output($module_settings["comments"]["comment website"]); ?>"></p>
			    	
			    		<p class="required textarea"><label for="text"><?php echo txt('comments', 'Text'); ?>*</label><br>
			    		<textarea id="text" name="text" cols="50" rows="10"><?php echo $module_settings["comments"]["comment text"]; ?></textarea></p>
			    		
			    		<p class="meta small">
			    			<?php echo txt('comments', 'Erlaubte HTML-Tags'); ?>:<br>
			    			<?php echo implode(', ', $module_settings["comments"]["allowed tags"]); ?><br>
			    			<?php echo txt('comments', 'Markierte Felder müssen ausgefüllt werden.'); ?>
			    		</p>
			    		
			    		<div style="position: absolute; visibility: hidden">
			    			<input type="hidden" name="required" value="<?php echo time(); ?>">
			    			<input type="button" id="load_comments" onclick="loadComments()">
			    			<input type="text" name="current_url" id="current_url" value="<?php echo clean_output('http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); ?>">
			    			<input type="text" name="comments_xml_file" id="comments_xml_file" value="<?php echo $system_data['folder']['pages'] . $page_info->alias . '/storage/' . $page_info->alias; ?>.xml">
			    		</div>
			    		
			    		<?php connector('comments frontend comment form'); ?>
			    		
			    		<p class="submit"><input type="submit" name="submit_comment" value="<?php echo txt('comments', 'Abschicken'); ?>"></p>
			    	</fieldset>
				</form>
			<?php } else { ?>
				<p class="comment-submitted"><?php echo txt('comments', 'Danke für Ihren Kommentar.'); ?> <a id="comments-back-link" href="<?php echo $page_info->href; ?>"><?php echo txt('comments', 'Seite neu laden.'); ?></a></p> 
			<?php } ?>
		<?php } else { ?>
			<p><?php echo txt('comments', 'Kommentare geschlossen'); ?></p>
		<?php } ?>
	</div>
</div>

<?php if($module_settings["comments"]["embedded"] == 1) { ?>
	<!-- JS ACTIONS -->
	<script type="text/javascript">
	    // Defaults
	    var dateFormat = '<?php echo $user_data["date format print"]; ?>';
	    var commentsContainer = document.getElementById('comments-<?php echo $id; ?>');
	    var commentsFormContainer = document.getElementById('comments-form-<?php echo $id; ?>');
		
		// Hide comment form on load
	    if(commentsFormContainer) commentsFormContainer.style.display = 'none';
	        
	    // Template for comments
	    var includeTemplate = function(number, name, website, timestamp, text) {
		    template = '<div class="comment">';
		    template += '<span class="number">' + number + '</span>';
		    template += '<p class="headline">' + (website != '' ? '<a href="' + website + '">' : '') + name + (website != '' ? '</a>' : '') + ' <span>' + timestamp + '</span></p>';
		    template += '<div class="text">' + htmlspecialcharsDecode(text) + '</div>';
		    template += '</div>';
		    commentsContainer.innerHTML += template;
	    };
	</script>
	
	<script type="text/javascript" src="<?php echo $system_data['folder']['modules']; ?>comments/sources/actions.js"></script>
<?php } ?>