<?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.
// -----------------------------------------------------------------------

?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="180" valign="top">
			<?php
			include $templatePath . "g_menu.inc.tpl.php";
			?>
		</td>

		<td width="20">&nbsp;</td>

		<td width="570" valign="top">
			<?php
			if (isset($topic)) {
			?>
			
			<div class="box_top">
				<?php echo $topic['topic_title'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td>
						<?php echo $topic['topic_synopsis'];?><br />
					</td>
				</tr>
				<?php
				if (!empty($topic['subjects'])) {
				foreach($topic['subjects'] as $key => $i):
				
				if (isset($group)) {
					$url = "frm_item.php?group_id=" . $group['group_id'] . "&amp;subject_id=" . $i['subject_id'];
				}
				else {
					$url = "frm_item.php?subject_id=" . $i['subject_id'];
				}
				?>
				<tr>
					<td colspan="2">
						<table width="100%" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td>
									<table width="100%" cellpadding="4" cellspacing="2" border="0">
										<tr>
											
											<td width="28" valign="middle" align="center">
												<a href="<?php echo $url;?>" title="<?php echo $i['subject_title'];?>"><img src="get_file.php?file=<?php echo $i['image']['file'];?>" border="0" class="picture" title="<?php echo $i['image']['file_title'];?>"></a><br />
											</td>
											<td valign="top">
												<?php echo $lang['txt_subject_datetime'];?>: <?php echo $i['subject_create_datetime'];?><br />
												<a href="<?php echo $url;?>" title="<?php echo $i['subject_title'];?>"><?php echo $i['subject_title'];?></a><br />
												<?php echo dots(140,$i['subject_body']);?><br />
											</td>
											<td valign="top" width="20%">
												<?php echo $lang['txt_comment_total'];?>: <?php echo $i['comment_total'];?><br />
												<?php if (!empty($i['last_comment']['comment_create_datetime'])) { echo $lang['txt_last_comment'] . ": " . $i['last_comment']['comment_create_datetime'] . "<br />";}?>
												
												<?php
												if (isset($i['movement']['lastview_datetime'])) {
													echo $lang['txt_watching'] . ": " . $lang['txt_lastview'] . " " . $i['movement']['lastview_datetime'] . "<br />";
													echo "(" . $lang['txt_movement'] . " ". $i['movement']['movement'] . ")";
												}
												?>
												
												<?php
												if (isset($i['subject_sticky'])) {
													echo $lang['txt_sticky'] . ", ";
												}
						
												if (isset($i['subject_locked'])) {
													echo $lang['txt_locked'] . ", ";
												}
						
												if (isset($i['subject_hidden'])) {
													echo $lang['txt_hidden'];
												}
												?>
												<br />
											</td>
									    </tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_subjects'];?><br />
					</td>
				</tr>
				<?php 
				}
			}
			elseif (isset($topics)) {
			?>
			<div class="box_top">
				<?php echo $lang['section_forum'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<?php
				foreach($topics as $key => $r):
				?>
				<tr>
					<td>
						<span class="txt_item_title">
							<?php echo $r['topic_title'];?><br />
						</span>
						<?php echo $r['topic_synopsis'];?><br />
					</td>
					<td align="right">
						<?php if ($r['topic_hidden'] == 1) { echo $lang['txt_hidden'];}?><br />
					</td>
				</tr>
				<?php
				if (!empty($r['subjects'])) {
				foreach($r['subjects'] as $key => $i):
				
				if (isset($group)) {
					$url = "frm_item.php?group_id=" . $group['group_id'] . "&amp;subject_id=" . $i['subject_id'];
				}
				else {
					$url = "frm_item.php?subject_id=" . $i['subject_id'];
				}
				?>
				<tr>
					<td colspan="2">
						<table width="100%" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td>
									<table width="100%" cellpadding="4" cellspacing="2" border="0">
										<tr>
											
											<td width="28" valign="middle" align="center">
												<a href="<?php echo $url;?>" title="<?php echo $i['subject_title'];?>"><img src="get_file.php?file=<?php echo $i['image']['file'];?>" border="0" class="picture" title="<?php echo $i['image']['file_title'];?>"></a><br />
											</td>
											<td valign="top">
												<?php echo $lang['txt_subject_datetime'];?>: <?php echo $i['subject_create_datetime'];?><br />
												<a href="<?php echo $url;?>" title="<?php echo $i['subject_title'];?>"><?php echo $i['subject_title'];?></a><br />
												<?php echo dots(140,$i['subject_body']);?><br />
											</td>
											<td valign="top" width="20%">
												<?php echo $lang['txt_comment_total'];?>: <?php echo $i['comment_total'];?><br />
												<?php if (!empty($i['last_comment']['comment_create_datetime'])) { echo $lang['txt_last_comment'] . ": " . $i['last_comment']['comment_create_datetime'] . "<br />";}?>
												
												<?php
												if (isset($i['movement']['lastview_datetime'])) {
													echo $lang['txt_watching'] . ": " . $lang['txt_lastview'] . " " . $i['movement']['lastview_datetime'] . "<br />";
													echo "(" . $lang['txt_movement'] . " ". $i['movement']['movement'] . ")";
												}
												?>
												
												<?php
												if (isset($i['subject_sticky'])) {
													echo $lang['txt_sticky'] . ", ";
												}
						
												if (isset($i['subject_locked'])) {
													echo $lang['txt_locked'] . ", ";
												}
						
												if (isset($i['subject_hidden'])) {
													echo $lang['txt_hidden'];
												}
												?>
												<br />
											</td>
									    </tr>
									</table>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_subjects'];?><br />
					</td>
				</tr>
				<?php }?>
				<?php
				if (isset($group)) {
					$url = "frm_list.php?group_id=" . $group['group_id'] . "&amp;topic_id=" . $r['topic_id'];
				}
				else {
					$url = "frm_list.php?topic_id=" . $r['topic_id'];
				}
				?>
				<tr>
					<td colspan="2" align="right">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="3" alt="" border="0" /><br />
						<a href="<?php echo $url;?>" class="link_stnd"><?php echo $lang['href_see_all_sub'];?></a><br />
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="6" alt="" border="0" /><br />
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<hr />
					</td>
				</tr>
 			<?php
 			endforeach;
			}
			else {
			?>
			<div class="box_top">
				<?php echo $lang['section_forum'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td class="txt_title" align="right">
						<?php echo $lang['hdr_topics'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<?php echo $lang['err_no_topics'];?><br />
					</td>
				</tr>
			<?php }?>
			
			
			
				<tr>
					<td colspan="2">
						<div class="box_edit">
							<table cellpadding="4" cellspacing="0" border="0" width="100%">
								<tr>
									<td valign="top">
										<?php
										if (isset($topic_roles)) {
										?>
												<?php echo $lang['txt_topic_role_add'];?>: 
												<?php
												foreach($topic_roles as $key => $tr):
													echo $tr['role_name'];
													if ($key+1 < count($topic_roles)) {
														echo ", ";
													}
												endforeach;
												?>
												<br />
										<?php }?>
									</td>
									<td align="right" nowrap="nowrap" valign="top">
										<?php
										if ($this->group_acs->checkPermission($resource_ids['group_forum'], $privilege_ids['allow_edit'])) { //resource_id, Priv_id
										?>
										<a href="frm_edit.php?add_topic=1&amp;group_id=<?php echo $group['group_id'];?>" class="link_stnd"><?php echo $lang['href_edit_topics'];?></a>
										&nbsp;
										<?php 
										}
										
										if (isset($topic['add_subject'])) {
										?>
										<a href="frm_edit.php?group_id=<?php echo $group['group_id'];?>&amp;topic_id=<?php echo $topic['topic_id'];?>&amp;add_subject=1" class="link_stnd"><?php echo $lang['href_add_subject'];?></a>
										&nbsp;
										<?php
										}
										
										if (isset($topic)) {
										?>
										<a href="frm_list.php?group_id=<?php echo $group['group_id'];?>" class="link_stnd"><?php echo $lang['menu_latest_discussions'];?></a>
										<?php }?>
										<br />
									</td>
								</tr>
							</table>
						</div>
					</td>
				</tr>
			</table>
			</div>
			
			<div id="box_bottom">
				<table cellpadding="0" cellspacing="0" border="0" width="100%">
					<tr>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/box_bottom_left.png" width="5" height="18" alt="" border="0" /><br />
						</td>
						<td align="left">
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" border="0" /><br />
						</td>
						<td align="right">
							<img src="<?php echo $templatePath;?>img/box_bottom_right.png" width="5" height="18" alt="" border="0" /><br />
						</td>
					</tr>
				</table>
			</div>
		</td>
	</tr>
</table>
