<?php /*
##################################################################
#                       PHP 4&5 MySQL 4&5                        #
##################################################################
#           Copyright (c) 2004-2008 Armia Systems Inc            #
##################################################################
#               This file is part of Cybermatch site             #
##################################################################
#    Developed By: simi (simi@armia.com)                         #
##################################################################
#               Developed On:   03-04-2008                       #
##################################################################
#               Modified By:                                     #
##################################################################
#               Modified On:                                     #
##################################################################
# This script may not be distributed, sold, given away for free  #
# to third party, or used as a part of any internet services 	 #
# such as webdesign etc.                                         #
##################################################################
*/

require_once ("config.inc.php");
/*
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter("must-revalidate");
*/
header('Expires: Mon, 14 Oct 2002 05:00:00 GMT');              // Date in the past
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT'); // always modified
header('Cache-Control: no-store, no-cache, must-revalidate');  // HTTP 1.1
header('Cache-Control: post-check=0, pre-check=0', false);

header("Cache-control: max-age=600");

//when search come from index page if user not login store value for after login
//echo"<pre>";print_r($_SESSION);echo"</pre>";
if (!isset($_SESSION['userlogged']) OR $_SESSION['userlogged'] <> "YES") 
{
    
	$_SESSION['ss_check_Flag']=','.true;
        /*
         * For Search Criteria to work properly
         */
        foreach ($_POST as $key => $value) {
            //echo $key.'=>'.$value;
            $_SESSION[$key] = $value;
        }

        if(isset($_POST['vSG'])){
            if($_SESSION['vSP'] == $_POST['vSP'])
                $_SESSION['vSP']        =   $_SESSION['vSP'];
            else
                $_SESSION['vSP']        =   $_POST['vSP'];
        }        
        else
            $_SESSION['vSP']        =   isset($_SESSION['vSP'])	?	$_SESSION['vSP']:	"";
        
        $_SESSION['gender_search']  =   $_SESSION['vSG'];
	$_SESSION['agefrom']        =   $_SESSION['vSAF'];
	$_SESSION['ageto']          =   $_SESSION['vSAT'];
        

}//end if
//echo"inn";



//require_once ("includes/userlogincheck.inc.php");
require_once ("includes/mysql.inc.php");
require_once ("includes/arrays.inc.php");
require_once ("classes/userside.class.php");
require_once ("includes/Pager/Pager.php");
require_once ("classes/misc.class.php");
require_once ("classes/timespamp.php");
$ds = new FuzzyTime();

$message	= "";
$script		= "";
$pages		= "";
$data		= array();
$array		= array();
$page		= isset($_REQUEST['page'])	?	trim($_REQUEST['page'])	:	"1";
$name		= isset($_POST['vUN'])	?	stripslashes(trim($_POST['vUN']))	:	"";

if (!$objDB) {
	$message	= "Unable to Locate Database Server.";
} else {
	$objC		= new check();
	$objU		= new userside($objDB);
        $objSR		= new settings($objDB);
	$objM		= new misc($objDB);
        $settingDetail	= $objSR->select();
        //echo "usearch",$settingDetail['enable_user_search'];exit;
        //echo"<pre>";print_r($_SESSION);exit;
         $array	= $objU->select($_SESSION['user_id']);
          //print_r($array); 
        
	if ($objU->is_expired($_SESSION['user_id'])) {
		$message	= "Your profile has been expired, please renew your profile for using this service.";	
	}
        //register before search checking
        if($settingDetail['enable_user_search']=='No' AND (!isset($_SESSION['user_id']) OR $_SESSION['user_id']=="" OR $_SESSION['user_id']<=0) ){           
            $_SESSION['searchPOST']	= $_POST;
            header("Location:login.php");
            exit();
        } else if(!isset($_POST))
        {
            $_POST = $_SESSION['searchPOST'];           
        }        
        unset($_SESSION['searchPOST']);
	
		

                    //$array		= $objU->search_profiles($_POST, true);
//                    $cntUsers       = $objU->search_profiles_count($_POST,true); 
//                    $pageCount      = ceil($cntUsers / PAGESIZE); 
//                    $pageMaxCount   = PAGESIZE;
                    $data1           = $objU->search_profiles_matching($array,true,'',$page,$pageMaxCount);
                    
                    $data = $data1['data'];
                    
                    $_SESSION['gender_search']	= $_POST['vSG'];
                    $_SESSION['agefrom']	= $_POST['vSAF'];
                    $_SESSION['ageto']          = $_POST['vSAT'];
			
		
  
//		$params 	= array(
//			'mode'      => 'Sliding',
//			'perPage'   => PAGESIZE,
//			'urlVar'    => 'page',
//			'extraVars' => array(),
//			'itemData'  => $array
//		);
//		$objP 		= & Pager::factory($params);
//		$data  		= $objP->getPageData();	
		if (empty($data))
			$message	.= "No profile(s) exists.<br>";
		else
			$pages	= $objP->links;;		
			
		if (isset($_POST['VP'])) {
                    if($name==""){
                        $message	= "Please enter username.<br>";
                        header("Location:search.php?message=$message");
                        exit();
                        
                    }else{
			$id	= $objU->get_profile_id($name);
			if ($id > 0) {
				header("Location:profile.php?id=$id");
				exit();
			} else {
				$message	= "Invalid username.<br>";
                                header("Location:search.php?message=$message");
				exit();
                                
			}
                    }
		}
	
	$script		= $objU->get_script($message);
	$message	= $objU->remove_script($message);
}
include_once ("title.inc.php");
include_once ("tophtml.inc.php");
?>

<div class="row">
	
	<div class="eight columns">
		
		<div class="newdesignforinput maintext1">
		
					<?php if(isset($message) && trim($message)!='')
					      {
					?>
					  <div class="full_row">
						<div class="maintext1 warning"><?php echo $message;?></div>
					</div>
					<?php }//end if?>
					
					
					 <?php if (!empty($data)) 
					   { 
					   ?>
					<div class="inenr-hd"><h2>Matching Profiles(<?php echo $data1['count'];?>)</h2></div>
					<?php }?>
				<div class="search-rslts">
				 <?php if (!empty($data)) 
					   { 
					  		foreach ($data as  $value) 
							{ 
								
							 
				?>
				
				
				
				<!--table width="100%"  border="0" cellspacing="0" cellpadding="0" align="center" class="bordernew"-->
				<div class="row search-rslts-row">
                  <div class="three columns">
				  
					<div class="profile-img"><a href="profile.php?id=<?php echo $value['nUser_Id']?>"><img src="<?php echo $objU->get_pimage_url(PROFILE_IMAGE_URL, $value['nPhoto_Id'], $value['vGender']);?>" width="165" height="125" title="<?php echo $value['vLogin']?>" alt="<?php echo $value['vLogin']?>" border="0"></a></div>
						
                      <!--
                      <tr>
                        <td align="right" class="profilenumber"><table width="100%"  border="0" cellspacing="0" cellpadding="3">
                            <tr>
                              <td align="right"><?php //echo $value['nUser_Id']?></td>
                            </tr>
                        </table></td>
                      </tr>
                      -->
                  </div>
                  <!--td width="86%" valign="top" class="box2"><table width="100%"  border="0" cellspacing="0" cellpadding="3"-->
                  <div class="nine columns">
					<div class="profile_L eight columns">
						<div class="eleven columns">
							<div class="profile-name">
								<h5><a href="profile.php?id=<?php echo $value['nUser_Id']?>"><?php echo $value['vLogin']?></a></h5>
							</div>
							  
						</div>
						<div class="clear"></div>
						<div class="twelve gray_normal_txt">
							<div class="nine columns">
								<?php echo $value['vAge']?>-year-old <?php echo $value['vGender']?>&nbsp;&nbsp;
								Height : <?php echo $value['nHeight'] <> "" ? $objU->get_height($value['nHeight']) : "--"?><br>
								<?php echo ($value['vCounty']!='')?$value['vCounty'].",":"";?>
								<?php echo ($value['vState']!='')?$value['vState'].",":"";?>
								<?php echo $value['vCountry']?>
							</div>
						</div>
						<div class="clear"></div>
						<div class="twelve gray_normal_txt">
							<?php echo $value['vTitle']?>
						</div>
						<div class="clear"></div>
						<div class="view-pro-row"><a href="profile.php?id=<?php echo $value['nUser_Id']?>" class="view-pro-btn" title="View Full Profile">view profile</a></div>
					</div>
					<div class="profile_R four columns">
						<div class="full_row">
							<div class="ten columns gray_normal_txt" align="right">
								<?php
								if($value['dLast_Login_Time'] != '')
								$loginTime = $value['dLast_Login_Time'];
								else
								$loginTime = $value['dLLogin'];
								?>
							</div>
							<div class="one columns featured_img"><?php echo $objU->get_bgcheck_image($value['nUser_Id'])?></div>
						</div>
						<div class="twelve">
							<?php if(isset($_SESSION['user_id']) && $_SESSION['user_id']!='')
								  {
							?>
							  <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&EI=yes" class="express-interest-btn" title="Express Interest">Express Interest</a></div>
							  <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&SM=yes" class="send-mail-btn" title="Send An Email">Send An Email</a></div>
						 <!--td><a title="Add as favourite" href="profile.php?id=<?php echo $value['nUser_Id']?>&AF=yes"><img src="images/addasfav.gif" alt="Add to favourite list" width="23" height="22" border="0" title="Add to favourite list">Add to favourite list</a></td-->
							 <div class="full_row icon_txt"><a title="Add as favourite" href="profile.php?id=<?php echo $value['nUser_Id']?>&AF=yes" class="favourites-btn">Add to favourite list</a></div>
							  <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&AH=yes" class="hotlist-btn" title="Add To Hot List">Add To Hot List</a></div>
							  <div class="full_row icon_txt"><a href="profile.php?id=<?php echo $value['nUser_Id']?>&ATF=yes" class="im-btn" title="Add To IM List">Add To IM List</a></div>
							 <?php }//end if?>
							
						</div>
					</div>
				  </div>
            </div>
             
			<?php }//end foreach
				}//end fi
//		       if ($pages <> "") 
//			   {
		   ?>
		   <!--<div class="clear"></div>
		   </div>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="78%">&nbsp;</td>
                        <td width="22%"><table width="100%"  border="0" cellspacing="2" cellpadding="0">
                          <tr align="center" class="textbox">
                            <td><?php echo $pages?></td>
                          </tr>
                        </table></td>
                      </tr>
                    </table>-->
 				<?php // } 
 				
 				if (!empty($data)) 
					   { 
 				?>
 				
 				
<!--                   <div class="pagination maintext">
                        <ul>
                        <?php if ($page != 1) { ?>
                                <li><a href="search_profiles.php?page=1" class="page_first" >First</a></li>
                                <li><a class="page_prev" href="search_profiles.php?page=<?php if ($page != 1) echo $page - 1; else echo $page; ?>" >Previous</a></li>
                                <?php }
                            ?>
                            <li class="pageinfo"><div id="page-info">Page <strong><?php echo $page; ?></strong> / <?php echo $pageCount; ?></div></li>
                            <?php if ($pageCount != $page) { ?>
                                <li><a class="page_next" href="search_profiles.php?page=<?php if ($pageCount != $page) echo $page + 1; else echo $pageCount; ?>">Next</a></li>
                                <li><a class="page_last" href="search_profiles.php?page=<?php echo $pageCount; ?>" >Last</a></li>
                                <?php }
                            ?>
                        </ul>
                        <div class="clear"></div>
                    </div> -->
                    <?php } ?>
				</div>
			</div>
		</div>
       
		<div class="four columns right search_result_R">
			<?php include_once ("left.inc.php");?>
		</div>
		    
    </div>
	
<?php include_once('bottomhtml.inc.php');?>
