<?php

// -----------------------------------------------------------------------
// This file is part of aroundme
// 
// Copyright (C) 2003, 2005 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
// 
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option) any
// later version.
// 
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
// -----------------------------------------------------------------------

?>

<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />

<div id="comment">
<?php
if (isset($comments)) {
?>
	<div class="box_top" style="margin:0px">
		<?php echo $lang['section_comments'];?><br />
	</div>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<?php
	foreach($comments as $key => $i):
	?>
	<tr>
		<td valign="top">
			<table width="100%" cellpadding="2" cellspacing="0" border="0">
				<tr>
					<td class="header_box" colspan="2">
						<?php echo $i['comment_create_datetime'];?><br />
					</td>
				</tr>
				<tr>
					<td valign="top" class="profile_box">
						<span class="profile_txt">
						<?php echo $lang['txt_from'];?>: 
						<?php
						if (isset($group['group_id']) && isset($i['membership_id'])) {
						?>
						<a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
						<?php 
						}
						else {
							if (isset($print_view)) {
								echo $i['profile_nic'] . "<br />";
							}
							else {
						?>
						<a href="sn_profile.php?user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
						<?php 
						
						if (isset($group['group_id']) && !isset($i['membership_id'])) {
							echo $lang['txt_non_member'] . "<br />";
						}
						
						}}?>
						<?php echo $lang['txt_joined'] . ": " . $i['profile_create_datetime'];?><br />
						<?php echo $lang['txt_hometown'] . ": " . $i['profile_hometown'];?>)<br />
						</span>
					</td>
					<td valign="top" class="comment_box" width="80%">
						<?php echo $i['comment_body'];?><br />
					</td>
				</tr>
				<?php
				if (isset($poll) && empty($poll['poll_anon'])) {
				?>
				<tr>
					<td class="vote_results_box" valign="top" colspan="2">
						<?php echo $lang['hdr_vote_history'];?>: 
						<?php
						if (isset($i['vote'])) {
							$separator = ", ";
							foreach($i['vote'] as $key => $r):
								if ($key == (count($i['vote'])-1)) {
								    $separator=".";
								}
								echo $r['option_body'] . " (" . $r['answer_create_datetime'] . ")" . $separator;
							endforeach;
						}
						?>
					</td>
				</tr>
				<?php }?>
			</table>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
		</td>
	</tr>
	<?php
	endforeach;
	?>
</table>
<?php }?>


<div class="box_top">
	<?php
	if (isset($display) && $display == "preview_comment") {
	?>
	<?php echo $lang['hdr_comment_preview'];?>
	<?php
	}
	else {
	?>
	<?php echo $lang['section_add_comment'];?>
	<?php }?>
	<br />
</div>
			
<div class="comment_form">
	<?php
	if (!empty($unlocked)) {
	if (isset($poll) && isset($poll['vote_required']) && !isset($poll['current_answer']['answer_id'])) {
	?>
	
	<?php echo $lang['txt_poll_required'];?><br />
	
	<?php
	}
	else {
	?>
	
	<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" name="comment" id="id_frm_comment">
	
	<?php
	if (isset($hidden_form)) {
		foreach($hidden_form as $key => $i):
	?>
	<input type="hidden" name="<?php echo $key?>" value="<?php echo $i;?>" />
	<?php 
		endforeach;
	}
	?>
	
	<table width="100%" cellpadding="2" cellspacing="0" border="0">
		<?php
		if (isset($display) && $display == "preview_comment") {
		?>
		<tr>
			<td valign="top">
				<input type="hidden" name="comment_body" value="<?php echo $comment['comment_body'];?>" />
		
				<?php echo $comment['display_comment_body'];?><br />
			</td>
	    </tr>
		<tr>
			<td align="right">
				<input type="submit" name="edit_again" class="button_urgent" value="<?php echo $lang['sub_edit_again'];?>" />&nbsp;&nbsp;
				<input type="submit" name="insert" class="button_urgent" value="<?php echo $lang['sub_save'];?>" /><br />
			</td>
		</tr>
		<?php
		}
		else {
		?>
		<tr>
			<td align="center">
				<table cellpadding="0" cellspacing="0" border="0" width="10">
					<tr>
						<td nowrap="nowrap">
							<b><label for="id_comment"><?php echo $lang['section_add_comment'];?></label></b><br />
						</td>
						<td align="right">
							<script language="JavaScript" type="text/javascript">
							var displayType = 'comment';
							</script>
							<script language="JavaScript" type="text/javascript" src="js/gui_wiki.js"></script><br />
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<textarea id="id_comment" name="comment_body" rows="5" cols="70"><?php if(isset($comment['comment_body'])) { echo $comment['comment_body'];}?></textarea><br />
							<script language="JavaScript" type="text/javascript">
								var txtarea = document.comment.comment_body;
							</script>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<?php echo $lang['txt_comment_help'];?>
							<?php
							if (isset($requested_comment_language_id)) {  
							?>
								<?php echo $lang['txt_group_language'];?>: <?php echo $lang['arr_lang_name'][$requested_comment_language_id];?>
							<?php }?>
							<br />
							</td>
					</tr>
					<tr>
						<td align="right" colspan="2">
							<?php if (isset($allow_spellcheck)) {?>
							<input type="button" value="<?php echo $lang['txt_check_spelling'];?>" class="button_light" onClick="openSpellChecker();" />&nbsp;&nbsp;
							<?php }?>
							<input type="submit" name="preview" class="button_light" value="<?php echo $lang['sub_preview'];?>" />&nbsp;&nbsp;
							<input type="submit" name="insert" class="button_urgent" value="<?php echo $lang['sub_add'];?>" /><br />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<?php
		}
		?>
	</table>
	</form>
	<?php
	}}
	else {
	?>
	<table width="100%" cellpadding="4" cellspacing="0" border="0">
		<tr>
			<td>
				<?php echo $lang['txt_no_comment_allowed'];?><br />
			</td>
		</tr>
	</table>
	<?php }?>

</div>
</div>