<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
// 
// Copyright (C) 2003 - 2007 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., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

?>

<?php

function getChildren($comments, $parent_id, $level_id, $date, $profile_url) {
	
	global $lang, $template_path, $output_poll, $template_path_core;
	
	foreach($comments as $key => $i):
	
	?>
		
			<?php
			if (empty($i['comment_parent_id'])) {
				$i['comment_parent_id'] = 0;
			}
			
			if ($key !=0 && $parent_id == 0 && $i['comment_parent_id'] == $parent_id) {
				echo "<hr />";
			}
			
			if ($i['comment_parent_id'] == $parent_id) {
			
				if ($parent_id == 0) {
					
				unset($thread_view);
				?>
			<div class="comment">
			<a name="comment_id<?php echo $i['comment_id'];?>"></a>
			<a href="javascript:setCommentParent(<?php echo $i['comment_id'];?>, <?php echo $i['comment_parent_id'];?>)" style="float:right;" id="comment_link_id_<?php echo $i['comment_id'];?>"><?php echo $lang['href_comment_reply'];?></a>
			
			<span class="comment_author">
				<b><?php echo $lang['txt_dated'];?></b> -&#62; 
				<?php echo $date->formatDate($i['comment_create_datetime'], 1);?><br />
				<?php
				if (empty($poll['poll_anon'])) {
				?>
				<b><?php echo $lang['txt_from'];?></b> -&#62;
				<a href="<?php echo $profile_url;?>&amp;identity_id=<?php echo $i['identity_id'];?>"><?php echo $i['identity_nic'];?></a>, 
				<?php echo $lang['txt_joined'] . ": " . $date->formatDate($i['participation_create_datetime']);?>, 
				<?php 
				if (isset($i['location_name'])) {
					echo $lang['txt_location'] . ": " . $i['location_name'];
				}
				?><br />
				<?php }?>
				
				<?php
				if (isset($output_poll) && empty($output_poll['poll_anon'])) {
				?>
				<b><?php echo $lang['txt_vote_history'];?></b> -&#62; 
				<?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;
				}
				?>
				<br />
				<?php }?>
			</span>
			
			<div style="overflow:auto; width:500px; padding-top:10px; padding-bottom:10px;" id="comment_body_id_<?php echo $i['comment_id'];?>">
				<p>
					<?php echo $i['comment_body'];?><br />
				</p>
			</div>
			</div>
			<?php 
			}
			else {
			?>
			
			<?php
			$indent_calc =20*$level_id;
			$width_calc = 480-$indent_calc;
			?>
			
			<div class="comment_child" id="comment_id_<?php echo $i['comment_id'];?>">
			<a name="comment_id<?php echo $i['comment_id'];?>"></a>
				<?php
				if (!isset($new_level)) {
				?>
				
				<img src="<?php echo $template_path_core;?>img/drop_arrow.png" style="margin-left:<?php echo $indent_calc+5;?>px;" width="10" height="10" alt="indent" border="0" /><br />
				
				<?php
				$new_level = 1;
				}?>
				<div style="margin-left:<?php echo $indent_calc+20;?>px;">
				
				<a href="javascript:setCommentParent(<?php echo $i['comment_id'];?>, <?php echo $i['comment_parent_id'];?>)" style="float:right;" id="comment_link_id_<?php echo $i['comment_id'];?>"><?php echo $lang['href_comment_reply'];?></a>
				<i><b><?php echo $lang['txt_dated'];?></b> -&#62; 
						<?php echo $date->formatDate($i['comment_create_datetime'], 1);?><br />
						<?php
						if (empty($output_poll['poll_anon'])) {
						?>
						<b><?php echo $lang['txt_from'];?></b> -&#62;
						<a href="<?php echo $profile_url;?>&amp;identity_id=<?php echo $i['identity_id'];?>"><?php echo $i['identity_nic'];?></a>, 
						<?php echo $lang['txt_joined'] . ": " . $date->formatDate($i['participation_create_datetime']);?>, 
						<?php 
						if (isset($i['location_name'])) {
							echo $lang['txt_location'] . ": " . $i['location_name'];
						}
						?><br />
						<?php }?>
						
						<?php
				if (isset($output_poll) && empty($output_poll['poll_anon'])) {
				?>
				<b><?php echo $lang['txt_vote_history'];?></b> -&#62; 
				<?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;
				}
				?>
				<br />
				<?php }?>
				
					<div style="width:<?php echo $width_calc;?>px;margin-top:10px;margin-bottom:10px;" id="comment_body_id_<?php echo $i['comment_id'];?>">
						<?php echo $i['comment_body'];?><br />
					</div>
					</i>
				</div>
			</div>
		<?php }?>
		<?php
		getChildren($comments, $i['comment_id'], $level_id+1, $date, $profile_url);
		}
		unset($new_level);
   endforeach;
}
?>


<?php
if (isset($comments)) {
	getChildren($comments, 0,0, $this->date, $profile_url);
}
?>