<?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
			if (isset($group)) {
			include $templatePath . "g_menu.inc.tpl.php";
			}
			elseif (isset($profile)) {
			include $templatePath . "sn_menu.inc.tpl.php";
			}
			
			if (isset($group) || isset($profile)) {
			?>
			<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="9" alt="" /><br />
			<?php }?>
			
			<?php
			if (isset($library)) {
			if (isset($group)) {
				$hidden_form = array(
					"item_name" => $library['library_page_name'], 
					"item_id" => $library['library_id'], 
					"group_id" => $group['group_id'],
					"page" => $library['library_page_name']
				);
			}
			else {
				$hidden_form = array(
					"item_name" => $library['library_page_name'],
					"item_id" => $library['library_id'], 
					"page" => $library['library_page_name']
				);
			}
			
			if (isset($_REQUEST['user_id'])) {
				$hidden_form['user_id'] = $_REQUEST['user_id'];
			}
			
			$show_network = 1;
			
			include $templatePath . "tag.inc.tpl.php";
			}
			?>
		</td>

		<td width="20">
			<img src="<?php echo $templatePath;?>img/pixel.png" width="20" height="1" alt="" /><br />
		</td>
		
		<td width="560" valign="top">
			<div class="box_top">
				<?php echo $lang['hdr_library'];?><br />
			</div>
			
			<div class="box_mid" style="padding: 9px;">
			<span style="float:right">
			<?php
			if (isset($group)) {
				if (isset($library)) {
			?>
				<a href="lib_item.php?group_id=<?php echo $group['group_id'];?>" class="link_stnd"><?php echo $lang['href_default'];?></a>&nbsp;
				<a href="lib_list.php?group_id=<?php echo $group['group_id'];?>&amp;contents=1" class="link_stnd"><?php echo $lang['href_contents'];?></a>
				<?php
				}
				if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_edit']) && isset($library_first_page)) {
				?>
				&nbsp;<a href="lib_edit.php?group_id=<?php echo $group['group_id'];?>&amp;page=<?php echo $library_first_page;?>" class="link_urgent"><?php echo $lang['href_wiki_first_page'];?></a>
				<?php 
				}
			}
			?>
			
			<?php
			if (!isset($group)) {
				$lnk = "";
				if (isset($profile)) {
					$lnk = "user_id=" . $profile['user_id'];
				}
			?>
			<a href="lib_item.php<?php echo "?" . $lnk;?>" class="link_stnd"><?php echo $lang['href_default'];?></a>&nbsp;
			<a href="lib_list.php?contents=1<?php echo "&amp;" . $lnk;?>" class="link_stnd"><?php echo $lang['href_contents'];?></a>
			<?php }?>
			
			<?php
			if (!isset($group) && !isset($profile) && isset($library_first_page)) {
			?>
			&nbsp;<a href="lib_edit.php?page=<?php echo $library_first_page;?>" class="link_urgent"><?php echo $lang['href_wiki_first_page'];?></a>
			<?php }?>
			</span><br />
			
			
			<?php
			if (isset($library)) {
			?>
			<table width="100%" border="0" cellspacing="0" cellpadding="4">
				<tr>
					<td>
						<?php
						if (isset($group)) {
						?>
						<a href="g_profile.php?group_id=<?php echo $group['group_id'];?>&amp;user_id=<?php echo $author['user_id'];?>"><?php echo $author['profile_nic'];?></a>:&nbsp;
						<?php }?>
						<?php echo $library['display_library_create_datetime'];?><br />
					</td>
				</tr>
				<tr>
					<td>
						<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="12" alt="" /><br />
					</td>
				</tr>
				<tr>
					<td>
						<span class="txt_item_title">
						<?php echo $library['library_title'];?><br />
						</span>
						<?php echo $library['library_body_display'];?><br />
					</td>
				</tr>
				
				<tr>
					<td>
						<div class="box_edit">
							<span style="float: right">
							<?php
							if (isset($group)) {
							if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_edit']) && isset($library['library_id'])) {
							?>
							<a href="lib_edit.php?group_id=<?php echo $group['group_id'];?>&amp;library_id=<?php echo $library['library_id'];?>" class="link_urgent"><?php echo $lang['href_edit_library'];?></a>
							<?php 
							}}
							elseif ($library['user_id'] == $me['user_id']) {
							?>
							<a href="lib_edit.php?library_id=<?php echo $library['library_id'];?>" class="link_urgent"><?php echo $lang['href_edit_library'];?></a>
							<?php }?>	
							</span>
							
							
							<?php echo $lang['txt_page_name'];?>: 
							<?php echo $library['library_page_name'];?>
							&nbsp;
							<?php
							if (isset($group)) {
								if (isset($newest)) {
								?>
								(<?php echo $lang['txt_version_lastest'];?>&nbsp;<a href="lib_item.php?group_id=<?php echo $group['group_id'];?>&amp;history_library_id=<?php echo $library['library_id'];?>"><?php echo $lang['href_doc_history'];?></a> )
								<?php
								}
								else {
								?>
								(<?php echo $lang['txt_version_old'];?>&nbsp;<a href="lib_item.php?group_id=<?php echo $group['group_id'];?>&amp;page=<?php echo $library['library_page_name'];?>"><span class="txt_error"><b><?php echo $lang['href_view_latest'];?></b></span></a> )
								<?php 
								}
							}
							else {
								$lnk = "";
								if (isset($profile)) {
									$lnk = "&amp;user_id=" . $profile['user_id'];
								}
								
								if (isset($newest)) {
								?>
								(<?php echo $lang['txt_version_lastest'];?>&nbsp;<a href="lib_list.php?history_library_id=<?php echo $library['library_id'] . $lnk;?>"><?php echo $lang['href_doc_history'];?></a> )
								<?php
								}
								else {
								?>
								(<?php echo $lang['txt_version_old'];?>&nbsp;<a href="lib_item.php?page=<?php echo $library['library_page_name'] . $lnk;?>"><span class="txt_error"><b><?php echo $lang['href_view_latest'];?></b></span></a> )
								
								<?php }?>
							<?php }?>
							<br />
							
							<?php
							if (isset($library['rsp'])) {
								echo "<b>" . $lang['txt_published_to']. ": </b>";
							    foreach($library['rsp'] as $key => $i):
									
									echo trim($lang['rsp']['rsp_level'][$i['level_id']] . " " . $i['degree_id']);
									echo " (" .$lang['rsp']['status'][$i['status_id']] . ")";
									if ($key+1 < count($library['rsp'])) {
									    echo ", ";
									}
									
								endforeach;
							}
							?><br />
							
						</div>
					</td>
				</tr>
			</table>
			<?php }?>
			</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>
			
			
			<?php
			if (isset($library['library_id'])) {
				//comments
				if ($library['user_id'] == $me['user_id']) {
					$unlocked = 1;
				}
					
				if (isset($group)) {
					if ($this->group_acs->checkPermission($resource_ids['group_library'], $privilege_ids['allow_comment']) && !empty($library['library_allow_comments'])) {
					   $unlocked = 1;
					}
					
					$hidden_form = array(
						"library_id" => $library['library_id'], 
						"group_id" => $group['group_id']
					);
					
					$requested_comment_language_id = $group['language_id'];
				}
				else {
					if (!empty($library['library_allow_comments'])) {
					    $unlocked = 1;
					}
					
					$hidden_form = array(
						"library_id" => $library['library_id']
					);
					
					$requested_comment_language_id = $me['language_id'];
				}
				
				if (isset($_REQUEST['user_id'])) {
					$hidden_form['user_id'] = $_REQUEST['user_id'];
				}
				
				include $templatePath . "comment.inc.tpl.php";
			}
			?>
		</td>
	</tr>
</table>