<?php
// +------------------------------------------------------------------------+
// | PHP Melody version 1.6.7 ( www.phpsugar.com )
// +------------------------------------------------------------------------+
// | PHP Melody IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than www.phpsugar.com or if you have received
// | this software from someone who is not a representative of
// | phpSugar, you are involved in an illegal activity.
// | ---
// | In such case, please contact: support@phpsugar.com.
// +------------------------------------------------------------------------+
// | Developed by: phpSugar (www.phpsugar.com) / support@phpsugar.com
// | Copyright: (c) 2004-2011 PhpSugar.com. All rights reserved.
// +------------------------------------------------------------------------+

require_once('config.php');
require_once('include/functions.php');
ob_end_clean();

$output 	 = '';

$queryString = trim($_POST['queryString']);

// Is there a posted query string?
if($queryString != '') 
{
	error_reporting(0);
	$queryString = secure_sql($queryString);
	$queryString = str_replace(array('%', ','), '', $queryString);
	
	//	only perform queries if the length of the search string is greather than 3 characters
	if(strlen($queryString) >= 3)
	{
		$num_res = 0;
		if(strlen($queryString) > 3)
		{
			$sql	 = "SELECT uniq_id, artist, video_title FROM pm_videos 
						WHERE MATCH(artist, video_title) 
						AGAINST ('$queryString') AS score ORDER BY score ASC LIMIT 10";
			$query	 = @mysql_query($sql);
			$num_res = @mysql_num_rows($query);
		}
		if($num_res == 0)
		{
			$query = @mysql_query("SELECT artist, video_title, uniq_id FROM pm_videos WHERE artist LIKE '$queryString%' OR video_title LIKE '%$queryString%' LIMIT 10");
		}
		
		if($query)
		{
			while($result = mysql_fetch_array($query))
			{
				$output .= '<li onClick="fill(\''.$result['artist'].' - '.$result['video_title'].'\');">';
				
				if (_THUMB_FROM == 2)	//	Localhost
				{
					$output .= '<img src="'. show_thumb($result['uniq_id']) .'" width="32" align="absmiddle" style="margin: 1px 4px;" alt="'.$result['artist'].' - '.$result['video_title'].'" />';
				}
				$output .= '<a href="'.makevideolink($result['uniq_id'], $result['artist'], $result['video_title']).'" title="'.$result['artist'].' - '.$result['video_title'].'">'.fewchars("".$result['artist']." - ".$result['video_title']."", 35).'</a>';
				$output .= '</li>';
			}
		} 
		else 
		{
			$output = $lang['search_results_msg3'];
		}
	}
}
echo $output;
exit();
?>