<?php

// -----------------------------------------------------------------------
// This file is part of Igloo
// 
// Copyright (C) 2003 - 2006 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.
// -----------------------------------------------------------------------
?>

<div class="col_main">
	<?php
	if (isset($library)) {
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $this->date->formatDate($library['library_create_datetime'], 1);?><br />
		</div>
			
		<div class="box_mid">
			<div class="content">
				<div class="metadata_top">
					<b><?php echo $lang['txt_item_options'];?></b> -&#62; 
					<?php
					if ($this->user_acs->checkPermission($resource_ids['library'], $privilege_ids['add_item'])) { //resourece_id, Priv_id
					?>
					<a href="lib_edit.php?library_id=<?php echo $library['library_id'];?>"><?php echo $lang['href_edit'];?></a>
					,&nbsp;
					<?php }?>
					
					
					<?php
					if (isset($me['user_id']) && $me['user_id'] > 0) { // we need to be logged in
					?>
					
					<?php
					if (isset($library['bookmark']['watch'])) {
					?>
					<a href="lib_view.php?library_id=<?php echo $library['library_id'];?>&amp;bookmark=del_mark"><?php echo $lang['href_unwatch_this'];?></a>
					<?php
					}
					else {
					?>
					<a href="lib_view.php?library_id=<?php echo $library['library_id'];?>&amp;bookmark=ins_mark"><?php echo $lang['href_watch_this'];?></a>
					<?php }?>
					
					<?php
					if ($me['user_id'] != $library['user_id']) {
					?>
					,&nbsp;
					<?php
					if (isset($library['bookmark']['recommend'])) {
					?>
					<a href="lib_view.php?library_id=<?php echo $library['library_id'];?>&amp;bookmark=del_tip"><?php echo $lang['href_unrecommend_this'];?></a>
					<?php
					}
					else {
					?>
					<a href="lib_view.php?library_id=<?php echo $library['library_id'];?>&amp;bookmark=ins_tip"><?php echo $lang['href_recommend_this'];?></a>
					<?php }}?>
					
					<?php
					if (!isset($library['bookmark']['watch']) && isset($batch_enabled) && $batch_enabled == true) {
					?>
					,&nbsp;
					<a href="lib_view.php?library_id=<?php echo $library['library_id'];?>&amp;bookmark=ins_mark&amp;notify=1"><?php echo $lang['href_watch_this_notify'];?></a>
					<?php }?>
					<?php }?>
					<br />
				</div>
				
				<p class="txt_item_title">
					<?php echo $library['library_title'];?><br />
				</p>
				
				<p>
					<?php echo $library['library_body_display'];?><br />
				</p>
				
				<div class="metadata">
					<?php
					if (isset($author)) {
						$profile_url = "sn_profile.php?user_id=" . $author['user_id'];
					?>
					<p>
						<b><?php echo $lang['txt_author'];?></b> -&#62; 
						<?php echo $lang['txt_profile_nic'];?>: 
						<a href="<?php echo $profile_url;?>"><?php echo $author['profile_nic'];?></a>, 
						<?php echo $lang['txt_profile_session_status'];?>: 
						<?php
						if ($author['online_status'] == 1) {
							echo "<b>" . $lang['arr_user_online_status'][1] . "</b>";
						}
						else {
								echo $lang['arr_user_online_status'][$author['online_status']];
						}
						?>, 
						<?php echo $lang['txt_hometown'];?>: 
						<?php echo $author['profile_hometown'];?>, 
						<?php echo $lang['txt_joined'];?>: 
						<?php echo $this->date->formatDate($author['profile_create_datetime']);?>
						<br />
					</p>
					<?php }?>
					
					<p>
						<b><?php echo $lang['hdr_library_item'];?></b> -&#62; 
						
						<?php echo $lang['txt_page_name'];?>:
						<?php echo $library['library_page_name'];?>, 
							
						<?php
						if (isset($newest)) {
							$url = "lib_view.php?view=history&amp;library_id=" . $library['library_id'];
						?>
						(<?php echo $lang['txt_version_lastest'];?>&nbsp;<a href="<?php echo $url;?>"><?php echo $lang['href_doc_history'];?></a> )
						<?php
						}
						else {
						?>
						(<?php echo $lang['txt_version_old'];?>&nbsp;<a href="lib_view.php?page=<?php echo $library['library_page_name'];?>"><span class="txt_error"><b><?php echo $lang['href_view_latest'];?></b></span></a> )
						
						<?php }?>, 
									
						<?php
						if (!empty($blog['bookmark'])) {
							echo $lang['txt_bookmarks'] . ": ";
							
							if (!empty($blog['bookmark']['watch'])) {
								echo $lang['txt_marked'];
							}
							
							if (!empty($blog['bookmark']['recommend'])) {
								echo $lang['txt_tipped'];
							}
							echo ", ";
						}
						?>
						
						<?php echo $lang['txt_published_to'];?>: 
						<?php
						if (isset($library['rsp'])) {
							foreach($library['rsp'] as $key => $i):
								if (!empty($i['degree_id']) && $i['level_id'] == $rspconfig['rsp_level']['node']) {
									echo $lang['rsp']['rsp_level_degree'][$i['degree_id']];
								}
								else {
									echo trim($lang['rsp']['rsp_level'][$i['level_id']]);
								}
								echo " (" .$lang['rsp']['status'][$i['status_id']];
								
								if (!empty($i['rsp_featured'])) {
									echo " &amp; " .  $lang['txt_featured'];
								}
								
								echo ")";
								if ($key+1 < count($library['rsp'])) {
									echo ", ";
								}
							endforeach;
						}
						?>
						<br />
					</p>
				</div>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_comments'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				//comments
				if (!empty($library['library_allow_comments'])) {
					$unlocked = 1;
				}
				
				$hidden_form = array(
					"library_id" => $library['library_id']
				);
				
				if (isset($_REQUEST['user_id'])) {
					$hidden_form['user_id'] = $_REQUEST['user_id'];
				}
				
				if (isset($library['user_id'])) {
					$hidden_form['item_user_id'] = $library['user_id'];
				}
				
				$comment_url = "lib_view.php?library_id=" . $library['library_id'];
				
				include $templatePath . "comment.inc.tpl.php";
				?>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	}
	elseif (isset($recommended_library_items)) { //list view sorted by group
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_library_items'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($lang['txt_intro'])) {
					echo "<p>" . $lang['txt_intro'] . "<br /></p>";
				}
				?>
				
				<?php
				if (!empty($recommended_library_items)) {
				?>
				
				<table border="0" cellspacing="0" cellpadding="4" width="100%">
					<?php
					foreach($recommended_library_items as $key => $g):
					if (!empty($g['library_items'])) {
					?>
					<tr>
						<td valign="top" width="32">
							<a href="sn_profile.php?user_id=<?php echo $g['user_id'];?>"><img src="get_file.php?file=<?php echo $g['image']['file'];?>" border="0" class="picture" alt="<?php echo $g['image']['file_title'];?>" /></a><br />
						</td>
						<td colspan="2">
							<?php
							if (!empty($g['am_relation_to_them']['relation_show_true_self'])) {
							?>
								<b><a href="sn_profile.php?user_id=<?php echo $g['user_id'];?>"><?php echo $g['user_firstname']. " " . $g['user_surname'];?></a></b>,
								
								
								<?php echo $this->date->formatDate($g['user_create_datetime']);?>,
								<?php echo $g['user_hometown'];?>,
							<?php
							}
							else {
							?>
							
								<a href="sn_profile.php?user_id=<?php echo $g['user_id'];?>"><b><?php echo $g['profile_nic'];?></b></a>,
								
								
								<?php echo $this->date->formatDate($g['user_create_datetime']);?>,
								<?php echo $g['profile_hometown'];?>,
							<?php }?>
							
							<?php
							if ($g['online_status'] == 1) {
								echo "<b>" . $lang['arr_user_online_status'][1] . "</b><br />";
							}
							else {
									echo $lang['arr_user_online_status'][$g['online_status']] . "<br />";
							}
							?>
						</td>
					</tr>
					<?php
					foreach($g['library_items'] as $key => $i):
					?>
					<tr>
						<td width="32" rowspan="2">
							<a href="lib_view.php?library_id=<?php echo $i['library_id'];?>"><img src="get_file.php?file=<?php echo $i['image']['file'];?>" border="0" alt="<?php echo $i['image']['file_title'];?>" /></a><br />
						</td>
						<td valign="top" nowrap="nowrap">
							<a href="lib_view.php?library_id=<?php echo $i['library_id'];?>"><?php echo $this->date->formatDate($i['library_create_datetime'], 1);?></a><br />
							<?php echo $i['library_title'];?><br />
						</td>
						<td valign="top">
							<?php echo $lang['href_comments'];?>&nbsp;(<?php if (!empty($i['comment_total'])) { echo $i['comment_total'];} else { echo "0";}?>)
							<br />
						</td>
					</tr>
					<tr>
						<td>
							<?php echo $lang['txt_tag'];?>: 

							<?php
							$tags = "";
							if (isset($i['tags'])) {
								foreach ($i['tags'] as $keyt => $t):
									$tags .= $t['tag_body'];
									
									if (count($i['tags']) > $keyt+1) {
										$tags .= ", ";
									}
								endforeach;
								
								if (isset($tag)) {
									$tags = searchTextFormat($tag, $tags);
								}
								echo $tags;
							}
							?>
						</td>
						<td>
							<br />
						</td>
					</tr>
					<?php
					endforeach;
					?>
					<tr>
						<td colspan="4">
							<hr />
							<img src="<?php echo $templatePath;?>img/pixel.png" width="1" height="10" alt="" /><br />
						</td>
					</tr>
					<?php
					}
					endforeach;
					?>
				</table>
				<?php }?>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	
	<?php
	}
	elseif (isset($library_items)) {
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_library'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($lang['txt_intro'])) {
				?>
				<p>
					<?php echo $lang['txt_intro'];?><br />
				</p>
				<?php }?>
				
				<table border="0" cellspacing="0" cellpadding="4" width="100%">
					<?
					foreach($library_items as $key => $i):
					?>
					<tr>
						<td valign="top">
							<?php
							if (isset($profile)) {
							?>
							<a href="lib_view.php?user_id=<?php echo $i['user_id'];?>&amp;library_id=<?php echo $i['library_id'];?>"><?php echo $i['library_create_datetime'];?></a><br />
							<?php
							}
							else {
							?>
							<a href="lib_view.php?library_id=<?php echo $i['library_id'];?>"><?php echo $this->date->formatDate($i['library_create_datetime']);?></a><br />
							<?php }?>
						</td>
						<td valign="top">
							<b><?php echo $i['library_title'];?></b><br />
							<?php echo $lang['txt_page_name'];?>: <?php echo $i['library_page_name'];?><br />
						</td>
						<td valign="top">
							<?php echo $lang['href_comments'];?>&nbsp;(<?php if (!empty($i['comment_total'])) { echo $i['comment_total'];} else { echo "0";}?>)
							<br />
						</td>
					</tr>
					<?php
					endforeach;
					?>
				</table>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	<?php
	}
	else {
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_library'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php echo $lang['err_no_items'];?><br />
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	<?php }?>
</div>


<div class="col_side">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_options'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<p>
					<b><?php echo $lang['txt_view'];?></b><br />
				</p>
				
				<?php
				if (isset($view) && $view == "firstpage") {
				?>
				<?php echo $lang['href_view_firstpage'];?><br />
				<?php
				}
				else {
					$url = "lib_view.php?view=firstpage";
				?>
				<a href="<?php echo $url;?>"><?php echo $lang['href_view_firstpage'];?></a><br />
				<?php }?>
				
				<?php
				if (isset($view) && $view == "contents") {
				?>
				<?php echo $lang['href_view_contents'];?><br />
				<?php
				}
				else {
				?>
				<a href="lib_view.php?view=contents"><?php echo $lang['href_view_contents'];?></a><br />
				<?php }?>
				
				<?php
				if (isset($me['user_id'])) {
				?>
				
				<?php
				if (isset($view) && $view == "my_library") {
				?>
				<?php echo $lang['href_my_library'];?><br />
				<?php
				}
				else {
				?>
				<a href="lib_view.php?view=my_library"><?php echo $lang['href_my_library'];?></a><br />
				<?php }?>
				
				<?php
				if (isset($view) && $view == "marked_library_items") {
				?>
				<?php echo $lang['href_marked'];?><br />
				<?php
				}
				else {
				?>
				<a href="lib_view.php?view=marked_library_items"><?php echo $lang['href_marked'];?></a><br />
				<?php }?>
				
				<?php
				if (isset($view) && $view == "tipped_library_items") {
				?>
				<?php echo $lang['href_tipped'];?><br />
				<?php
				}
				else {
				?>
				<a href="lib_view.php?view=tipped_library_items"><?php echo $lang['href_tipped'];?></a><br />
				<?php }?>
				
				<?php }?>
				
				<p>
					<b><?php echo $lang['txt_options'];?></b><br />
				</p>
				
				<?php
				if ($this->user_acs->checkPermission($resource_ids['library'], $privilege_ids['add_item'])) { //resourece_id, Priv_id
				?>
				<a href="lib_edit.php"><?php echo $lang['href_add_library'];?></a><br />
				<?php }?>
				
				<?php
				if (isset($library)) {
				?>
					<p>
						<b><?php echo $lang['hdr_tag'];?></b><br />
					</p>
					
					<p>
						<?php
						$tags = "";
						if (isset($item_tags)) {
							foreach ($item_tags as $key => $i):
								$tags .= "<a href='search.php?tag=" . $i['tag_body']. "'>" . $i['tag_body'] . "</a>";
								
								if (isset($me['user_id']) && $i['user_id'] == $me['user_id']) {
									$tags .= "*";
								}
								
								if (count($item_tags) > $key+1) {
									$tags .= ", ";
								}
							endforeach;
							echo $tags;
						}
						?>
					</p>
					
					<?php
					if ($this->user_acs->checkPermission($resource_ids['library'], $privilege_ids['allow_tagging'])) { //resourece_id, Priv_id
					$tags = "";
					if (isset($my_tags)) {
						foreach ($my_tags as $key => $i):
							$tags .= $i['tag_body'];
							if (count($my_tags) > $key+1) {
								$tags .= ", ";
							}
						endforeach;
					}
					?>
					
					
					<form action="lib_view.php" method="post" name="frm_view" id="id_frm_view">
					<input type="hidden" name="library_id" value="<?php if(isset($library['library_id'])) { echo $library['library_id'];}?>" />
					<input type="hidden" name="library_page_name" value="<?php if(isset($library['library_page_name'])) { echo $library['library_page_name'];}?>" />
					
					<p>
						<input width="30" class="input" name="tags" value="<?php echo $tags;?>" />
						<input type="image" src="<?php echo $templatePath;?>img/go.png" name="update_tag" value="1" class="go" /><br />
					</p>
					
					<?php }?>
				<?php }?>
				
				</form>
				
				<p>
					<b><?php echo $lang['hdr_search'];?></b><br />
				</p>
				
				<form action="search.php" method="post" name="search" id="id_search">
				<input type="hidden" name="search_type" value="library" />
				
				<p>
					<input type="text" class="input" name="search_text" size="20" value="<?php if (isset($search_text)) { echo $search_text;};?>" />
					<input type="image" src="<?php echo $templatePath;?>img/go.png" value="search" class="go" /><br />
				</p>
				
				</form>
			</div>
		</div>
	</div>
	
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	
	<?php
	if (isset($sidebar_items)) {
	?>
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_history'];?><br />
		</div>
			
		<div class="box_mid">
			<div class="content">
				<?php
				foreach($sidebar_items as $key => $i):
				?>
				<p>
					<a href="lib_view.php?library_id=<?php echo $i['library_id'];?>"><?php echo $this->date->formatDate($i['library_create_datetime'], 1);?></a><br />
					<?php echo $i['library_title'];?><br />
					<?php echo $lang['href_comments'];?>&nbsp;(<?php if (!empty($i['comment_total'])) { echo $i['comment_total'];} else { echo "0";}?>)
					<br />
				</p>
				<?php
				endforeach;
				?>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
	<?php }?>
</div>