<?php
///////////////////////////////////////////////////////////////////////////////////////
// PHPizabi 0.848b C1 [ALICIA]                               http://www.phpizabi.net //
///////////////////////////////////////////////////////////////////////////////////////
// Please read the license.txt file before using / modifying this software           //
// Original author:         Claude Desjardins, R - feedback@realitymedias.com        //
// Last modification date:  August 13th 2006                                         //
// Version:                 PHPizabi 0.848b C1                                       //
//                                                                                   //
// (C) 2005, 2006 Real!ty Medias / PHPizabi - All rights reserved                    //
///////////////////////////////////////////////////////////////////////////////////////

	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");
	
	$tpl = new template;
	$tpl -> Load("match");
	
	// RUN THE QUERY //////////////////////////////////////////////////////////////
	/*
		Run the query
	*/
	$select = myQ("
		SELECT SQL_CALC_FOUND_ROWS *, MATCH (`profile_data`) AGAINST ('".me("profile_data")."' IN BOOLEAN MODE) AS `score`
		FROM `[x]users` 
		WHERE MATCH (`profile_data`) AGAINST ('".me("profile_data")."' IN BOOLEAN MODE) 
		ORDER BY `score` DESC
		LIMIT 50
	");
		
	/*
		Find out how many rows we would have got
		without the limit statement
	*/
	$countRowsSelect = myQ("SELECT FOUND_ROWS()");
	$countRowsResult = mysql_fetch_row($countRowsSelect);
	$totalRows = $countRowsResult[0];
	
	$tpl->AssignArray(array("users.onlineCount" => $totalRows));

	// ASSIGN AND LOOP ///////////////////////////////////////////////////////////
	$i=0;
	while ($row = myF($select)) {
		
		if ($i==0) $fullMatchPoints = $row["score"];
		
		$resultsLoopArray[$i]["user.matchScore"] = round($row["score"] / $fullMatchPoints * 100, 1);
		$resultsLoopArray[$i]["user.username"] = $row["username"];
		$resultsLoopArray[$i]["user.id"] = $row["id"];
		$resultsLoopArray[$i]["user.mainpicture"] = $row["mainpicture"];
		$resultsLoopArray[$i]["user.quote"] = _fnc("strtrim", $row["quote"], 40);
		$resultsLoopArray[$i]["user.gender"] = $row["gender"];
		$resultsLoopArray[$i]["user.age"] = $row["age"];
		$resultsLoopArray[$i]["user.header"] = _fnc("strtrim", _fnc("clearBodyCodes", $row["header"]), 100);
				
		$i++;
	}
			
	/*
		if there was results, let's loop them
	*/
	if (isset($resultsLoopArray)) {
		$tpl->Zone("searchResults", "enabled");
		$tpl->Loop("searchResultsLoop", $resultsLoopArray);
	}
		
	/*
		No results? Show a message
	*/
	else $tpl->Zone("searchResults", "noResult");
	
	
	


	
	$tpl -> Flush();

?>