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

?>

<style type="text/css">
<!--
@import url(<?php echo $template_path_core;?>css/aroundme_form.css);
-->
</style>


<form action="index.php?amn=core_people" method="post" name="frm" id="id_frm">

<?php
if (isset($display_allow_search)) {
?>

<div class="col_main">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_search_results'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<?php
				if (isset($display_allow_search)) {
				if (!empty($search_results)) { // list
				?>
				<table cellspacing="2" cellpadding="0" width="100%" border="0">
				<?php
				foreach ($search_results as $key => $i):
				?>
				<tr>
					<td valign="top">
						<a href="index.php?amn=core_profile&amp;identity_id=<?php echo $i['identity_id'];?>"><b><?php echo $i['identity_nic'];?></b></a><br />		
					</td>
					<td valign="top">
						<?php echo $i['location_name'];?><br />		
					</td>
					<td valign="top">
						<?php echo $this->date->formatDate($i['user_create_datetime'],1);?><br />		
					</td>				
				</tr>
				<tr>
					<td valign="top" colspan="3">
						<i><?php echo $i['identity_metadata'];?></i><br />		
					</td>				
				</tr>
				<?php
				endforeach;
				?>
				</table>
				<?php
				}
				elseif (isset($search_performed)) { // no search results
					echo $lang['template_error']['err_no_items'];
				}
				?>
				
				<hr />
				
				<?php
				if (isset($my_metadata)) {
				?>
				<p>
					<b><?php echo $lang['txt_my_metadata'];?></b><br />
					<?php
					$prnt = "";
					foreach($my_metadata as $key => $i) :
						$i = trim($i);
						$prnt .= "<a href='index.php?amn=core_people&amp;meta=" . $i . "'>" . $i . "</a>, ";
					endforeach;
					$prnt = substr($prnt, 0, -2);
					echo $prnt;
					?>
					<br />	
				</p>
				<?php }?>
				
				
				<?php
				if (isset($user_metadata)) {
				?>
				<p>
					<b><?php echo $lang['txt_user_metadata'];?></b><br />
					<?php
					if (isset($user_metadata)) {
					$prnt = "";
					foreach($user_metadata as $key => $i) :
						$i = trim($i);
						$prnt .= "<a href='index.php?amn=core_people&amp;meta=" . $i . "'>" . $i . "</a>, ";
					endforeach;
					$prnt = substr($prnt, 0, -2);
					echo $prnt;
					}
					?>	
				</p>
				<?php }?>
				
				<?php
				}
				else { // no search allowed
					echo $lang['txt_search_intro'];
				}
				?><br />
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<div class="col_side">
	<div class="box">
		<div class="box_top">
			<?php echo $lang['hdr_search'];?><br />
		</div>
		
		<div class="box_mid">
			<div class="content">
				<p>
					<?php echo $lang['txt_searchable_users'];?><br />		
				</p>
				
				<p>
					<b><?php echo $lang['txt_search_text'];?></b><br />
					<input type="text" class="input" name="search_text" value="<?php if(isset($search_text)) { echo $search_text;}?>" /><br />
				</p>
				
				<hr />
				
				<table cellspacing="0" cellpadding="0" boder="1" width="100%">
					<tr>
						<td valign="top">
							<a href="#" onClick="javascript:objShowHide('advanced_search');"><?php echo $lang['href_advanced_search'];?></a><br />
						</td>
						<td valign="top" align="right">
							<input name="search" type="submit" class="input_submit" value="<?php echo $lang['sub_search'];?>" /><br />
						</td>					
					</tr>				
				</table>
				
				<div id="advanced_search" style="display:none;">
					<?php
					if (isset($tags)) {
					?>
					<p>
						<b><?php echo $lang['txt_network_tags'];?></b><br />
						<select id="id_tags" name="tag_body">
							<option value="0"><?php echo $lang['txt_none'];?></option>
							<?php
							foreach($tags as $key => $i):
							?>
							<option value="<?php echo $i['tag_body'];?>"><?php echo $i['tag_body'];?></option>
							<?php
							endforeach;
							?>
						</select>	
					</p>
					<?php }?>
					
					<?php
					if (isset($locations)) {
					?>
					<p>
						<b><?php echo $lang['txt_location'];?></b><br />	
						<select id="id_location" name="location_id">
							<option value="0"><?php echo $lang['txt_none'];?></option>
							<?php
							foreach($locations as $key => $i):
							?>
							<option value="<?php echo $i['location_id'];?>"<?php if (isset($_POST['location_id']) && $_POST['location_id'] == $i['location_id']) { echo " selected=\"selected\"";}?>><?php echo $i['location_name'];?></option>
							<?php
							endforeach;
							?>
						</select>		
					</p>
					<?php }?>
					
					<?php
					if (isset($custom_fields)) {
					?>
					<p>
						<b><?php echo $lang['txt_identity_search'];?></b><br />	
						<select id="id_custom_fields" name="custom_fields_id">
							<option value="0"><?php echo $lang['txt_none'];?></option>
							<?php
							foreach($custom_fields as $key => $i):
							?>
							<option value="<?php echo $key;?>"><?php echo $i;?></option>
							<?php
							endforeach;
							?>
						</select>		
					</p>
					<?php }?>
					
					<p>
						<b><?php echo $lang['txt_sort'];?></b><br />
						<select name="sort_by">
							<option value="i.identity_nic">nic name</option>
							<option value="u.user_metadata">meta</option>
							<option value="l.location_name">location</option>
						</select>
					</p>
					
					<hr />
					
					<p align="right">
						<input name="search" type="submit" class="input_submit" value="<?php echo $lang['sub_search'];?>" /><br />
					</p>
				</div>
			</div>
		</div>
	</div>
		
	<div class="box_bottom">
		<span class="box_bottom_right"></span>
		<span class="box_bottom_left"></span>
	</div>
</div>

<?php
}
else { // user needs to set preference and fill metadata before search allowed
?>

<div class="box">
	<div class="box_top">
		<?php echo $lang['hdr_search_intro'];?><br />
	</div>
	
	<div class="box_mid">
		<div class="content">
			<?php echo $lang['txt_search_intro'];?><br />
		</div>
	</div>
</div>
	
<div class="box_bottom">
	<span class="box_bottom_right"></span>
	<span class="box_bottom_left"></span>
</div>

<?php }?>
			
</form>