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

?>


<form action="g_library.php" method="post">
<input type="hidden" name="group_id" value="<?php echo $group['group_id'];?>" />
<?php
if (isset($library)) {
?>
<input type="hidden" name="library_id" value="<?php echo $library['library_id'];?>" />
<?php }?>

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

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

			<table border="0" cellspacing="0" cellpadding="4" width="100%">
				<tr>
					<td class="txt_title">
						<?php echo $lang['section_action'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<?php
						if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_edit']) && isset($library_first_page)) {
						?>
						<a href="g_library_edit.php?group_id=<?php echo $group['group_id'];?>&amp;page=<?php echo $library_first_page;?>" class="txt_sub_menu"><?php echo $lang['href_wiki_first_page'];?></a><br />
						<?php 
						}
						else {
						?>
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>" class="txt_sub_menu"><?php echo $lang['href_default'];?></a><br />
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;contents=1" class="txt_sub_menu"><?php echo $lang['href_contents'];?></a><br />
						<?php 
						if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_edit']) && isset($library['library_id'])) {
						?>
						<a href="g_library_edit.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>" class="txt_sub_menu"><?php echo $lang['href_edit_this'];?></a><br />
						<?php }}?>

						<?php
						if (isset($library['bookmark']['watch'])) {
						?>
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>&amp;unwatch=1" class="txt_sub_menu"><?php echo $lang['href_unwatch_this'];?></a><br />
						<?php
						}
						else {
						?>
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>&amp;watch=1" class="txt_sub_menu"><?php echo $lang['href_watch_this'];?></a><br />
						<?php
						}
						?>

						<?php
						if (isset($library['bookmark']['recommend'])) {
						?>
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>&amp;unrecommend=1" class="txt_sub_menu"><?php echo $lang['href_unrecommend_this'];?></a><br />
						<?php
						}
						else {
						?>
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>&amp;recommend=1" class="txt_sub_menu"><?php echo $lang['href_recommend_this'];?></a><br />
						<?php
						}
						?>
					</td>
				</tr>
			</table>

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

			<table border="0" width="100%" cellspacing="4" cellpadding="0">
				<tr>
					<td class="txt_title">
						<?php echo $lang['section_search'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<input type="text" name="search_text" size="18" class="formInput" value="<?php if(isset($search)) { echo $search;}?>" /><br />
					</td>
			    </tr>
				<tr>
					<td align="right">
						<input type="submit" name="search" value="<?php echo $lang['sub_search'];?>" class="formInput" /><br />
					</td>
				</tr>
			</table>

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

			<?php
			include $templatePath . "logo.inc.tpl.php";
			?>
		</td>

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

		<td width="570" valign="top">
			<?php
			if (isset($library['library_id'])) {
			?>
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $library['library_title'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<?php
					if (isset($library['image'])) {
					?>
					<td valign="top">
						<img src="get_file.php?file=<?php echo $library['image']['file'];?>" border="0" class="picture" alt="<?php echo $library['image']['file_title'];?>" /><br />
					</td>
					<td>
					<?php
					}
					else {
					?>
					<td colspan="2">
					<?php }?>
						<table width="100%" cellpadding="1" cellspacing="0" border="0">
							<tr>
								<td class="txt_footer" valign="top">
									<b><?php echo $lang['txt_synopsis'];?></b><br />
								</td>
								<td class="txt_footer">
									<?php echo $library['library_synopsis'];?><br />
								</td>
							</tr>
							<tr>
								<td class="txt_footer">
									<b><?php echo $lang['txt_pagename'];?></b><br />
								</td>
								<td class="txt_footer">
									<?php echo $library['library_page_name'];?><br />
								</td>
							</tr>
							<tr>
								<td class="txt_footer">
									<b><?php echo $lang['txt_date'];?></b><br />
								</td>
								<td class="txt_footer">
									<?php echo $library['library_create_datetime'];?><br />
								</td>

							</tr>
							<tr>
								<td class="txt_footer" valign="top">
									<b><?php echo $lang['txt_author'];?></b><br />
								</td>
								<td class="txt_footer" valign="top">
									<?php echo $lang['txt_last_edit'];?>: <a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&amp;user_id=<?php echo $author['user_id'];?>" class="txt_footer_link"><?php echo $author['profile_nic'];?></a>,
									<?php echo $lang['txt_joined'];?>: <?php echo $author['profile_create_datetime'];?>,
									<?php echo $lang['txt_hometown'];?>: <?php echo $author['profile_hometown'];?><br />
								</td>
							</tr>
							<tr>
								<td class="txt_footer" valign="top">
									<b><?php echo $lang['txt_version'];?></b><br />
								</td>
								<td class="txt_footer">
									<?php
									if (isset($newest)) {
									?>
									<?php echo $lang['txt_version_lastest'];?><br />
									<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;history_library_id=<?php echo $library['library_id'];?>"><?php echo $lang['href_doc_history'];?></a><br />
									<?php
									}
									else {
									?>
									<?php echo $lang['txt_version_old'];?><br />
									<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;page=<?php echo $library['library_page_name'];?>"><span class="error"><b><?php echo $lang['href_view_latest'];?></b></span></a><br />
									<?php
									}
									?>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<?php
			}
			?>


			<?php
			if (isset($display) && $display == "search") {
			?>
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td colspan="4" class="txt_title" align="right">
						<?php echo $lang['hdr_search_results'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($library_search_results[0])) {
				foreach($library_search_results as $key => $i):
				?>
				<tr>
					<td>
						<table cellpadding="4" cellspacing="0" border="0" width="100%">
							<tr>
								<?php
								if (isset($i['image'])) {
								?>
								<td valign="top" width="1%">
									<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $i['library_id'];?>"><img src="get_file.php?file=<?php echo $i['image']['image'];?>" border="0" class="picture" title="<?php echo $i['image']['image_title'];?>"></a><br />
								</td>
								<?
								}
								?>
								<td valign="top">
									<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $i['library_id'];?>"><?php echo $i['library_title'];?></a><br />
									<?php echo $i['library_synopsis'];?><br />
								</td>
								<td valign="top" align="right">
									<?php echo $i['display_library_create_datetime'];?><br />
									<a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&amp;user_id=<?php echo $i['user_id'];?>"><?php echo $i['user_nic'];?></a><br />
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td>
						<?php echo $lang['err_no_search_results'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>

			<?php
			}
			elseif (isset($display) && $display == "history") {
			?>
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td colspan="3" class="txt_title" align="right">
						<?php echo $lang['hdr_history'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($history[0])) {
				foreach($history as $key => $i):
				?>
				<tr>
					<td valign="top">
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $i['library_id'];?>"><?php echo $i['library_title'];?></a><br />
					</td>
					<td valign="top">
						<?php echo $i['display_library_create_datetime'];?><br />
					</td>
					<td valign="top">
						<a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&amp;user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
					</td>
				</tr>
				<tr>
					<td colspan="3">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td colspan="3">
						<?php echo $lang['err_no_history'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>


			<?php
			}
			elseif (isset($display) && $display == "contents") {
			?>
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td colspan="2" class="txt_title" align="right">
						<?php echo $lang['hdr_contents'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td class="txt_footer" align="right" colspan="2">
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>" class="txt_footer"><?php echo $lang['href_default'];?></a>&nbsp;
					</td>
				</tr>
				<?php
				if (isset($contents[0])) {
				foreach($contents as $key => $i):
				?>
				<tr>
					<td valign="top">
						<a href="g_library.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $i['library_id'];?>"><?php echo $i['library_title'];?></a><br />
					</td>
					<td valign="top" align="right" nowrap>
						<?php echo $i['display_library_create_datetime'];?><br />
					</td>
				</tr>
				<tr>
					<td valign="top" class="txt_footer">
						<?php echo $i['library_synopsis'];?><br />
					</td>
					<td valign="top" align="right">
						<a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&amp;user_id=<?php echo $i['user_id'];?>"><?php echo $i['profile_nic'];?></a><br />
					</td>

				</tr>
				<tr>
					<td colspan="2">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr>
					<td colspan="2">
						<?php echo $lang['err_no_contents'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>

			<?php
			}
			else {
			?>

			<table width="100%" border="0" cellspacing="0" cellpadding="4">

				<?php
				if (isset($library['library_id'])) {
				?>
				<tr>
					<td>
						<?php echo $library['library_body'];?><br />
					</td>
				</tr>
				<?php
				}
				else {
				?>
				<tr>
					<td colspan="4" class="txt_title" align="right">
						<?php echo $lang['hdr_library'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td>
						<?php echo $lang['err_no_library'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>
			
			<?php
			if (isset($library['library_id'])) {
			?>
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
			
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td colspan="3" class="txt_title" align="right">
						<?php echo $lang['section_comments'];?><br />
						<hr />
					</td>
				</tr>
				<?php
				if (isset($comments)) {
				foreach($comments as $key => $i):
				?>
				<tr class="bg_2">
					<td>
						<table width="100%" cellpadding="4" cellspacing="0" border="0">
							<tr>
								<td class="txt_footer" colspan="2">
									<?php echo $lang['txt_from'];?>: <a href="g_member_profile.php?group_id=<?php echo $group['group_id'];?>&user_id=<?php echo $i['user_id'];?>" class="txt_footer_link"><?php echo $i['profile_nic'];?></a>&nbsp;(joined: <?php echo $i['profile_create_datetime'];?>, hometown: <?php echo $i['profile_hometown'];?>)<br />
									<?php echo $lang['txt_comment_datetime'];?>: <?php echo $i['comment_create_datetime'];?><br />
								</td>
							</tr>
							<tr>
								<td valign="top">
									<?php echo $i['comment_body'];?><br />
								</td>
						    </tr>

						</table>
					</td>
				</tr>
				<tr>
					<td colspan="4">
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="4" alt="" /><br />
					</td>
				</tr>
				<?php
				endforeach;
				}
				else {
				?>
				<tr class="bg_2">
					<td colspan="2">
						<?php echo $lang['err_no_comments'];?><br />
					</td>
				</tr>
				<?php }?>
			</table>

			<?php
			if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_comment']) && empty($subject['subject_locked'])) {
			?>
			
			<input type="hidden" name="library_id" value="<?php echo $library['library_id'];?>" />
			<input type="hidden" name="data[comment_body]" value="<?php echo $comment['comment_body'];?>" />
						
			<img src=<?php echo $templatePath;?>img/pixel.png width="1" height="20"><br />

			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<?php
				if (isset($display) && $display == "preview_comment") {
				?>
				<tr>
					<td class="txt_title" align="right">
						<?php echo $lang['hdr_comment_preview'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td valign="top">
						<?php echo $comment['display_comment_body'];?><br />
					</td>
			    </tr>
				<tr>
					<td align="right">
						<input type="submit" name="edit_again" class="formInput" value="<?php echo $lang['sub_edit_again'];?>" />&nbsp;&nbsp;
						<input type="submit" name="insert" class="formInput" value="<?php echo $lang['sub_save'];?>" /><br />
					</td>
				</tr>
				<?php
				}
				else {
				?>

				<tr>
					<td class="txt_title" align="right">
						<?php echo $lang['section_add_comment'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<?php echo $lang['txt_comment_help'];?><br />
					</td>
				</tr>
				<tr>
					<td>
						<textarea name="data[comment_body]" rows="5" cols="70" class="formInput"><?php if(isset($comment['comment_body'])) { echo $comment['comment_body'];}?></textarea><br />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<?php echo $lang['txt_group_language'];?>: <?php echo $lang['arr_lang_name'][$group['language_id']];?><br />
					</td>
				</tr>
				<tr>
					<td align="right">
						<input type="submit" name="preview" class="formInput" value="<?php echo $lang['sub_preview'];?>">&nbsp;&nbsp;
						<input type="submit" name="insert" class="formInput" value="<?php echo $lang['sub_add'];?>"><br />
					</td>
				</tr>
				<?php
				}
				?>
			</table>
			<?php
			}
			else {
			?>
			<table width="100%" cellpadding="4" cellspacing="0" border="0">
				<tr>
					<td class="txt_title" align="right">
						<?php echo $lang['section_add_comment'];?><br />
						<hr />
					</td>
				</tr>
				<tr>
					<td class="txt_footer">
						<?php echo $lang['txt_no_comment_allowed'];?><br />
					</td>
				</tr>
			</table>
			<?php
			}}}
			?>
		</td>
	</tr>
</table>
</form>
