<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	//  forum search functions
	// ========================================================================================
	
	
	$PageTitle = '<div align="'.$AlignmentCodes[$mbSettings['TitleAlignment']].'">'.$mbSettings['PageTitle'].' Search (BETA)</div>';
	$BrowserTitle = $mbSettings['PageTitle'] . ' Search (BETA) - '.$MsgText[2][59];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="'.$MainURL.'/forum.html">'.$mbSettings['PageTitle'].'</a> > Search (BETA)';
	
	ReadFormArguments();
	Global $FormArguments;
			
	if (count($FormArguments) > 0 && $FormArguments['SearchString'] != '' && $UserLevel >= 50) {
	
		$query = "select * from `".$Settings['DBPrefix']."mb-Messages` where Subject LIKE '%".$FormArguments['SearchString']."%' or Message LIKE '%".$FormArguments['SearchString']."%'";
		$result = mysql_query($query) or die (mysql_error());
		if (mysql_num_rows($result) > 0) {
		
			$MatchesCount = mysql_num_rows($result);
					
			$PageContents .= '<b>Your Search For "'.$FormArguments['SearchString'].'" Returned '.number_format($MatchesCount,0).' Results</b><br><br>';
		
			while ($row = mysql_fetch_array($result)) {
			
				if ($row['Subject'] == '') {
					$row['Subject'] = '[No Subject]';
				}
		
				if (strlen($row['Message']) > 100) {
					$row['Message'] = substr($row['Message'],0,100) . '...';
					
					$row['Message'] = str_replace('<','&lt;',$row['Message']);
				}
				
				
				$query2 = "select * from `".$Settings['DBPrefix']."mb-Threads` where RecordNumber='".$row['ThreadID']."' limit 1";
				$result2 = mysql_query($query2) or die (mysql_error());
				$row2 = mysql_fetch_array($result2);
				
				$query3 = "select * from `".$Settings['DBPrefix']."mb-Boards` where RecordNumber='".$row2['BoardID']."' limit 1";
				$result3 = mysql_query($query3) or die (mysql_error());
				$row3 = mysql_fetch_array($result3);
				
				$query4 = "select RecordNumber from `".$Settings['DBPrefix']."mb-Messages` where ThreadID='".$row['ThreadID']."' and DateCode<'".$row['DateCode']."'";
				$result4 = mysql_query($query4) or die (mysql_error());
				$MessageNumber = mysql_num_rows($result4)+1;
				
				
				if ($Usernames[$row['Poster']] != '') {
					if ($LoggedIn == 'y' && $row['Poster'] > 0) {
						$PosterLink = '<a href="'.$MainURL.'/profile/'.$Usernames[$row['Poster']].'.html">'.$DisplayNames[$row['Poster']].'</a>';
					}
					else {
						$PosterLink = $DisplayNames[$row['Poster']];
					}
				}
				else {
					$PosterLink = $MsgText[2][65];
				}
				
				// set up the date display ("today", "yesterday", or the actual date, followed by the time)
				if (date("j/n/Y", time()) == date("j/n/Y", $row['DateCode'])) {
					$PostDate = $MsgText[2][66].' @ '.date("g:ia", $row['DateCode']);
				}
				else if (date("j/n/Y", (time()-(60*60*24))) == date("j/n/Y", $row['DateCode'])) {
					$PostDate = $MsgText[2][67].' @ '.date("g:ia", $row['DateCode']);
				}
				else {
					$PostDate = $MsgText[0][33+date("n",$row['DateCode'])].' '.date("j, Y @ g:ia", $row['DateCode']);
				}
				
				
				$PageContents .= '<br><a href="'.$MainURL.'/forum/thread/'.$row['ThreadID'].'.html#'.$MessageNumber.'"><b>'.$row['Subject'].'</b></a><br><font size="1"><b>Thread <a href="'.$MainURL.'/forum/thread/'.$row['ThreadID'].'.html">'.$row2['Title'].'</a> In <a href="'.$MainURL.'/forum/'.$row2['BoardID'].'.html">'.$row3['Title'].'</a></b></font><br><font size="1">'.$row['Message'].'<br><b>By: '.$PosterLink.' on '.$PostDate.'</b><br></font>';
		
			}
		}
		else {
		
			$PageContents .= '<b>Your Search For "'.$FormArguments['SearchString'].'" Returned No Results</b><br><br>';
			
		}
				
				
	}
	else {
			
		$PageContents = $MsgText[0][98];
			
	}
	
	
?>