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

$showm = '2';
include('header.php');

$action = '';
$action = trim($_GET['action']);

$post_n_get = 0;
$post_n_get = count($_POST) + count($_GET);

set_time_limit(120);
/*
 ** Define Local Functions Here **
 */
function get_micro_time()
{
	list($microsec, $sec) = explode(" ", microtime());
	return ((float)$microsec + (float)$sec);
}

function get_exec_time($end, $start)
{
	return round($end - $start, 2);
}

function startElement($parser, $name, $attrs) 
{
	global $youtube, $youtube_array_counter, $youtube_index;
	switch($name) 
	{
		case 'ENTRY':
			$youtube_index = "";
			break;
		case 'YT:DURATION':
			$youtube_index = $name;
			$youtube[$youtube_array_counter][$youtube_index] = $attrs['SECONDS'];
			break;
		case 'MEDIA:RESTRICTION':
			$youtube_index = $name;
			$youtube[$youtube_array_counter][$youtube_index] = array('TYPE' => $attrs['TYPE'],
																	 'RELATIONSHIP' => $attrs['RELATIONSHIP'],
																	 'LIST' => ''
																	);
			break;
		case 'YT:STATE':
			$youtube_index = $name;
			$youtube[$youtube_array_counter][$youtube_index] = array('NAME' => $attrs['NAME'],
																	 'REASONCODE' => $attrs['REASONCODE'],
																	 'REASON' => ''
																	);
			break;
		case 'MEDIA:CONTENT':
			$youtube_index = $name;
			$youtube[$youtube_array_counter][$youtube_index][$attrs['YT:FORMAT']] = array('URL' => $attrs['URL'],
																	 'TYPE' => $attrs['TYPE']
																	);
		break;
		default:
			$youtube_index = $name;
			$youtube[$youtube_array_counter][$youtube_index] = "";
			break;
	}
}

function endElement($parser, $name) 
{
	global $youtube, $youtube_index, $youtube_array_counter;
	switch($name) 
	{
		case "ENTRY":
			$youtube_array_counter++;
			break;
	}
	$youtube_index = "";
}

function characterData($parser, $data) 
{
	global $youtube, $youtube_array_counter, $youtube_index;
	if ($youtube_index != "")
	{
		if ($youtube_index == 'MEDIA:RESTRICTION')
		{
			$youtube[$youtube_array_counter][$youtube_index]['LIST'] .= trim($data);
		}
		else if ($youtube_index == 'YT:STATE')
		{
			$youtube[$youtube_array_counter][$youtube_index]['REASON'] .= trim($data);
		}
		else
		{
			$youtube[$youtube_array_counter][$youtube_index] .= trim($data);
		}
	}
}
/*
	** Finish defining Local Functions **
*/

?>
<div id="sub_menu">
<li><a href="addvideo.php">Add new video</a></li>
<li><a href="embedvideo.php">Embed new video</a></li>
<li><a href="import.php">Import from Youtube</a></li>
<li><a href="import_user.php">Import from Youtube User</a></li>
<li><a href="reports.php">Reported Videos</a></li>
<li><a href="approve.php">Approve Videos</a></li>
</div>
<div id="content">
<h2>Import from Youtube</h2>
<br />
<?php echo $info_msg; ?>
<form name="search_yt_videos" action="import.php?action=search" method="post">
 <input name="keyword" type="text" value="<?php echo ($_POST['keyword'] != '') ? $_POST['keyword'] : str_replace("+", " ", $_GET['keyword']); ?>" size="35" />
 <select name="results">
  <option value="10" <?php if($_POST['results'] == 10 || $_GET['results'] == 10) echo 'selected="selected"'; ?>>10 results</option>
  <option value="20" <?php if($_POST['results'] == 20 || $_GET['results'] == 20 || $post_n_get == 0) echo 'selected="selected"'; ?>>20 results</option>
  <option value="30" <?php if($_POST['results'] == 30 || $_GET['results'] == 30) echo 'selected="selected"'; ?>>30 results</option>
  <option value="50" <?php if($_POST['results'] == 50 || $_GET['results'] == 50) echo 'selected="selected"'; ?>>50 results</option>
 </select>
 <input name="submit" type="submit" value="Find" class="inputbutton" />
 <br />
 <small>Example: Frank Sinatra - Sugar Town</small>
 <div id="instructions">
 <h2 class="">Options</h2>
 <input type="checkbox" name="autofilling" id="autofilling" value="1" <?php if($_POST['autofilling'] == "1" || $_GET['autofilling'] == "1" || $post_n_get == 0) echo 'checked="checked"'; ?> />
 <label for="autofilling">Auto-populate 'Artist name' & 'Video Title'</label>
 <br />
 <input type="checkbox" name="autodata" id="autodata" value="1" <?php if($_POST['autodata'] == "1" || $_GET['autodata'] == "1" || $post_n_get == 0) echo 'checked="checked"'; ?> />
 <label for="autodata">Auto-populate 'Tags' & 'Description' from Youtube</label>
 <br />
 <label>Auto-populate for this category</label>
 <?php 
 	$selected_categories = array();
	if (is_array($_POST['use_this_category']))
	{
		$selected_categories = $_POST['use_this_category'];
	}
	else if (is_string($_POST['use_this_category']) && $_POST['use_this_category'] != '') 
	{
		$selected_categories = (array) explode(',', $_POST['use_this_category']);
	}
	if ($_GET['utc'] != '')
	{
		$selected_categories = (array) explode(',', $_GET['utc']);
	}
	
	$categories_dropdown_options = array(
									'attr_name' => 'use_this_category[]',
									'attr_id' => 'main_select_category',
									'select_all_option' => false,
									'spacer' => '&mdash;',
									'selected' => $selected_categories,
									'other_attr' => 'multiple="multiple" size="3"',
									'option_attr_id' => 'check_ignore'
									);
	echo categories_dropdown($categories_dropdown_options);
 ?>
</form>
</div>
<?php

/*
 *  Import
 */  
if($_POST['submit'] == 'Import' && ($action == 'import'))
{
	$exec_start = get_micro_time();
		
	$arr_artist		 = $_POST['artist'];
	$arr_video_title = $_POST['video_title'];
	$arr_description = $_POST['description'];
	$arr_tags		 = $_POST['tags'];
	$arr_category	 = $_POST['genre'];
	$arr_url		 = $_POST['video_ids'];
	$yt_username	 = $_POST['yt_username'];
	$featured		 = $_POST['featured'];
	$thumb_url		 = $_POST['thumb_url'];
	
	$sources = a_fetch_video_sources();
	$source_id = $sources['youtube']['source_id'];

	$total_videos = count($arr_url);
	$imported_total = 0;
	
	define('PHPMELODY', true);
	require_once( "./src/youtube.php");
	
	$duplicate = 0;

	if(is_array($arr_url))
	foreach($arr_url as $i => $v)
	{	
		$duplicate = count_entries('pm_videos_urls', 'direct', $arr_url[$i]);
		
		if($duplicate == 0)
		{
			$video_details = array(	
								'uniq_id' => '',	
								'artist' => '',	
								'video_title' => '',	
								'description' => '',	
								'yt_id' => '',	
								'yt_length' => '',	
								'category' => '',	
								'submitted' => '',	
								'source_id' => '',	
								'language' => '',	
								'age_verification' => '',
								'url_flv' => '',	
								'yt_thumb' => '',
								'mp4' => '',	
								'direct' => '',	
								'tags' => '', 
								'featured' => 0,
								'restricted' => 0 
								);
			
			$video_details['artist']	  = trim( $arr_artist[$i]	   );
			$video_details['video_title'] = trim( $arr_video_title[$i] );
			$video_details['description'] = trim( $arr_description[$i] );
			$video_details['tags'] 		  = trim( $arr_tags[$i]		   );
			$video_details['category'] 	  = is_array($arr_category[$i]) ? implode(',', $arr_category[$i]) : '';
			$video_details['direct'] 	  = trim( $arr_url[$i]		   );
			$video_details['source_id']	  = $source_id;
			$video_details['language']	  = 1;
			$video_details['submitted']	  = $userdata['username'];

			$video_details['description'] = nl2br($video_details['description']);
			
			//	generate unique id;
			$found = 0;
			$uniq_id = '';
			//$i = 0;
			do
			{
				$found = 0;
				if(function_exists('microtime'))
					$str = microtime();
				else
					$str = time();
				$str = md5($str);
				$uniq_id = substr($str, 0, 9);
				if(count_entries('pm_videos', 'uniq_id', $uniq_id) > 0)
					$found = 1;
			} while($found === 1);
	
			$video_details['uniq_id'] = $uniq_id;
			
			if($video_details['artist'] != '' && $video_details['video_title'] != '')
			{
				$temp = array();
				//	grab video information
				do_main($temp, $video_details['direct'], false);
				
				$video_details['url_flv']	=	$temp['url_flv'];
				$video_details['mp4']		=	$temp['mp4'];
				$video_details['yt_length']	=	$temp['yt_length'];
				$video_details['yt_thumb']	=	$temp['yt_thumb'];
				$video_details['yt_id']	=	$temp['yt_id'];
				
				if($video_details['tags'] == '')
				{
					$video_details['tags']	=	$temp['tags'];
				}
				
				if ($thumb_url[$i] != '')
				{
					$video_details['yt_thumb'] = $thumb_url[$i];
				}
				
				//	download thumbnail
				$img = download_thumb($video_details['yt_thumb'], _THUMBS_DIR_PATH, $uniq_id);
				
				if ($featured[$i] == "1")
				{	
					$video_details['featured'] = 1;
				}

				$new_video = insert_new_video($video_details);
				if($new_video !== true)
				{
					echo '<div class="info_msg_err"><em>A problem occurred! Could not insert new video in your database;</em><br /><strong>MySQL Reported:</strong> "'.$new_video[0].'"<br /><strong>Error Number:</strong> '.$new_video[1].'</div>';
				}
				else
				{
					//	tags?
					if($video_details['tags'] != '')
					{
						$tags = explode(",", $video_details['tags']);
						foreach($tags as $k => $tag)
						{
							$tags[$k] = stripslashes(trim($tag));
						}
						//	remove duplicates and 'empty' tags
						$temp = array();
						for($i = 0; $i < count($tags); $i++)
						{
							if($tags[$i] != '')
								if($i <= (count($tags)-1))
								{
									$found = 0;
									for($j = $i + 1; $j < count($tags); $j++)
									{
										if(strcmp($tags[$i], $tags[$j]) == 0)
											$found++;
									}
									if($found == 0)
										$temp[] = $tags[$i];
								}
						}
						$tags = $temp;
						//	insert tags
						if(count($tags) > 0)
							insert_tags($video_details['uniq_id'], $tags);
					}
					$imported_total++;
				}
				unset($video_details, $temp);
			}
		}
		sleep(1);
	}	//	end for()
	
	$exec_end = get_micro_time();
	
	$info_msg = '<div class="info_msg_ok">Imported <strong>'.$imported_total.'</strong> out of <strong>'.$total_videos.'</strong> videos.';
	if($imported_total < $total_videos)
	{
		$info_msg .= '<br />Videos found in your database were avoided. Also, checked videos that were missing Artist or Video Title were avoided.';
	}
	
	$info_msg .= '<br />Import took <strong>' . get_exec_time($exec_end, $exec_start) . '</strong> seconds.';

	if($yt_username != '') 
	{
		$params = '';
		$params .= 'action=search&username='. $yt_username;
		$params .= '&results=' .$_POST['results'];
		$params .= '&autofilling=' .$_POST['autofilling'];
		$params .= '&autodata='. $_POST['autodata'];
		$params .= (is_array($_POST['use_this_category'])) ? '&oc=1&utc='. implode(',', $_POST['use_this_category']) : '&oc=0&utc=';
		$info_msg .= '<br /><br /><strong><a href="import_user.php?'. $params .'">Return to <em>'. $yt_username .'\'s</em> videos</a></strong>.';
	}
	$info_msg .= '</div></div>';
	echo $info_msg;
}

/*
 *  Search
 */ 
if($action == 'search' && ($_POST['keyword'] != '' || $_GET['keyword'] != ''))
{
   ?>
   <br />
   <form name="import_videos" action="import.php?action=import" method="post">
	<table width="100%" border="0" cellspacing="2" cellpadding="10">
	  <tr class="table_head">
	    <td width="30%">Youtube Title / Thumbnails</td>
	    <td>Import</td>
	    <td width="2%" align="center"><input type="checkbox" name="checkall" onclick="checkUncheckAll(this);"/></td>
	    <td width="2%" align="center"><a href="#import_button" class="anchorLink"><img src="images/ico_arr_down.gif" border="0" width="11" height="11" /></a></td>
	  </tr>
	<?php
	
	$page = (int) $_GET['page'];

	if(empty($page))
		$page = 1;
	
	$autodata = 0;
	$autofilling = 0;
	$overwrite_category = array();
	
	if(isset($_POST['submit']) && !empty($_POST['keyword']))
	{
		$v				= trim($_POST['keyword']);
		$import_results	= $_POST['results'];
		
		if($_POST['autofilling'] == '1') 
		{
			$autofill = explode("-", $_POST['keyword'], 2);
			$autofill[0] = trim($autofill[0]);
			$autofill[1] = trim($autofill[1]);
			$autofilling = 1;
		}
		if($_POST['autodata'] == '1')
		{
			$autodata = 1;
		}
		if (is_array($_POST['use_this_category']))
		{
			$overwrite_category = $_POST['use_this_category'];
		}
	}
	elseif($_GET['keyword'] != '')
	{
		$v				= urldecode($_GET['keyword']);
		//$v				= str_replace(" ", "+", $v);
		
		if($_GET['results'] != '')
		{
			$import_results	= (int) $_GET['results'];
		}
		else
		{
			$import_results = 20;
		}
		
		if($_GET['autofilling'] == 1)
		{
			$autofill = explode("-", urldecode($_GET['keyword']), 2);
			$autofill[0] = trim($autofill[0]);
			$autofill[1] = trim($autofill[1]);
			$autofilling = 1;
		}
		if($_GET['autodata'] == 1)
		{
			$autodata = 1;
		}
		if($_GET['oc'] == 1)	//	oc = overwrite_category
		{
			$overwrite_category = (array) explode(',', $_GET['utc']);	//	utc = use_this_cateogory
		}
	}

	$start_from = ($page * $import_results) - $import_results + 1;
	
	//	Send Request
	$search_term = str_replace("-", " ", $v);	
	$search_term = urlencode($search_term);
	$v 		 = urlencode($v);
	$file 	 = "http://gdata.youtube.com/feeds/api/videos?vq=".$search_term."&start-index=".$start_from."&max-results=".$import_results;
	$file 	.= '&format=5';
	$youtube = array();
	$youtube_index = "";
	$youtube_array_counter = 0;
	
	$xml_parser = xml_parser_create();
	xml_set_element_handler($xml_parser, "startElement", "endElement");
	xml_set_character_data_handler($xml_parser, "characterData");
	$error = 0;
	
	if ( function_exists('curl_init') ) 
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $file);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20041107 Firefox/1.0');
		
		$data = curl_exec($ch);
		curl_close($ch);
		
		if ( !xml_parse($xml_parser, $data, TRUE) ) 
		{
		   die(sprintf('<div class="info_msg_err">XML error: %s at line %d</div>',
		       xml_error_string(xml_get_error_code($xml_parser)),
		       xml_get_current_line_number($xml_parser)));
		}
	}
	else if ( ini_get('allow_url_fopen') == 1 ) 
	{
	   if ( $fp = @fopen($file, "r") ) 
	   {
	      while ($data = fread($fp, 4096)) 
	      {
	        if ( !xml_parse($xml_parser, $data, feof($fp)) ) 
	        {
	           die(sprintf('<div class="info_msg_err">XML error: %s at line %d</div>',
	            xml_error_string(xml_get_error_code($xml_parser)),
	            xml_get_current_line_number($xml_parser)));
	         }
	      }
	   }
	   else 
	   {
	      $error = 1;
	   }
	   @fclose($fp);
	}
	else 
	{
		$error = 1;
	}

	if( $error == 1 )
	{
	   // fopen failed, cURL failed, there's nothing else to do but quit
	   die( '<div class="info_msg_err">
	   			fopen() failed;<br />
				cURL failed.<br />
				Unable to connect to retrieve data. <b>Please try again in a few moments. <a href="sys_phpinfo.php">See if your hosting account has <em>allow_url_fopen</em> or <em>cURL</em> enabled</a>.</b></div>' );
	}
	xml_parser_free($xml_parser);

	// begin formatting
	$alt = 0;
	$total_results = count($youtube);
	$counter = 1;
	$duplicates = 0;
	$total_search_results = $youtube[0]['OPENSEARCH:TOTALRESULTS'];
	
	if($youtube[0]['OPENSEARCH:TOTALRESULTS'] != 0 && $youtube[0]['OPENSEARCH:TOTALRESULTS'] > $start_from)
	{	
		for($i = 0; $i < $total_results; $i++) 
		{
			$yid		 = explode("/", $youtube[$i]["ID"]);
			$id 		 = $yid[ count($yid)-1 ];
			$count_vids	 = 0;
			$count_vids	 = count_entries('pm_videos', 'yt_id', $id);
			if($count_vids == 0)
			{
				$title		 = $youtube[$i]["MEDIA:TITLE"];
				$url		 = 'http://www.youtube.com/watch?v='.$id;
				$description = $youtube[$i]["MEDIA:DESCRIPTION"];
				$keywords	 = $youtube[$i]["MEDIA:KEYWORDS"];		
				$restriction = $youtube[$i]['MEDIA:RESTRICTION'];
				
				$no_embed	 = 0;
				if(array_key_exists('YT:NOEMBED', $youtube[$i]))
				{
					$no_embed = 1;
				}
				
				$private	 = 0;
				if(array_key_exists('YT:NOEMBED', $youtube[$i]))
				{
					$private = 1;
				}
				$col = ($alt % 2) ? 'table_row1' : 'table_row2';
				$alt++;		
				
				if (trim($autofill[1]) == '')
				{
					$buff_video_title = str_ireplace($autofill[0], '', $youtube[$i]['MEDIA:TITLE']);
					$buff_video_title = trim($buff_video_title, ' -');
				}
				else
				{
					$buff_video_title = $autofill[1];
				}
				
		?>
			  <tr class="<?php echo $col; ?>">
				<td valign="top">
				<h3><a href="http://www.youtube.com/v/<?php echo $id; ?>&autoplay=1&v=<?php echo $id; ?>" rel="prettyPop[flash]" title="<?php echo $title; ?>" class="<?php echo $h3class; ?>"> <?php echo $title; ?></a></h3>
 				<ul class="thumbs_ul">
				  <li class="thumbs_li_selected"><img src="images/bg_selected_thumb.gif" alt="" border="0" style="display:none" /><img src="http://img.youtube.com/vi/<?php echo $id; ?>/1.jpg" alt="Thumb 1" width="100" height="76" border="0" name="video_thumbnail" videoid="<?php echo $id; ?>" /></li>
				  <li class="thumbs_li_default"><img src="images/bg_selected_thumb.gif" alt="" border="0" style="display:none" /><img src="http://img.youtube.com/vi/<?php echo $id; ?>/2.jpg" alt="Thumb 2" width="100" height="76" border="0" name="video_thumbnail" videoid="<?php echo $id; ?>" /></li>
				  <li class="thumbs_li_default"><img src="images/bg_selected_thumb.gif" alt="" border="0" style="display:none" /><img src="http://img.youtube.com/vi/<?php echo $id; ?>/3.jpg" alt="Thumb 3" width="100" height="76" border="0" name="video_thumbnail" videoid="<?php echo $id; ?>" /></li>
				 </ul>
				<br />
				<a href="http://www.youtube.com/v/<?php echo $id; ?>&autoplay=1&v=<?php echo $id; ?>" rel="prettyPop[flash]"  title="<?php echo $title; ?>"><img src="images/ico_preview.gif" width="72" height="18" alt="Preview This Video" border="0" /></a>
				<input type="hidden" name="thumb_url[<?php echo $counter;?>]" value="http://img.youtube.com/vi/<?php echo $id; ?>/1.jpg" />
				<?php
				 	$col_unembed = '';
					if($no_embed == 1 || $private == 1)
					{
						$col_unembed = 'table_row_unembed';
						?>
						<br />
						<div class="css_yellow_warn"><span onMouseover="showhint('This video will not work since the owner decided to disable embedding.', this, event, '350px')">YouTube disabled embedding for this video.</span></div>
						<?php 
					}
					
					if(is_array($restriction))
					{
						$col_unembed = 'table_row_unembed';
						?>
						<div class="css_yellow_warn">
							<span onMouseover="showhint('Access <b><?php echo ($restriction['RELATIONSHIP'] == 'deny') ? 'denied' : 'granted';?></b> in the following countries: <?php echo $restriction['LIST'];?>.', this, event, '350px')">This video is geo-restricted.</span>
						</div>
						<?php
					}
				?>
				</td>
				<td class="<?php echo $col_unembed; ?>">
				 <table width="100%" border="0" cellspacing="5" cellpadding="0">
                   <tr>
                     <td width="15%">
						<small>Artist name (<em>required</em>):</small><br />
						<input name="artist[<?php echo $counter;?>]" type="text" value="<?php echo $autofill[0]; ?>" size="20" class="required_field" /> 
					 </td>
                     <td width="15%">
						<small>Video title (<em>required</em>):</small><br />
						<input name="video_title[<?php echo $counter;?>]" type="text" value="<?php echo ucwords(strtolower($buff_video_title)); ?>" size="20" class="required_field" />
					 </td>
                     <td width="70%">
						<small>Category (<em>required</em>):</small><br />
						
						<?php
						$categories_dropdown_options = array(
									'attr_name' => 'genre['. $counter .'][]',
									'attr_id' => 'select_category-'. $counter,
									'select_all_option' => false,
									'spacer' => '&mdash;',
									'selected' => $overwrite_category,
									'other_attr' => 'multiple="multiple" size="3"',
									'option_attr_id' => 'check_ignore'
									);
						echo categories_dropdown($categories_dropdown_options);
						?>
					 </td>
                   </tr>
                   <tr>
                     <td colspan="3">
						 <small>Tags:</small><br />
						 <input name="tags[<?php echo $counter;?>]" type="text" value="<?php if($autodata) echo $keywords;?>" size="70" maxlength="70" />
					 </td>
                   </tr>
                   <tr>
                     <td colspan="3">
						 <small>Description:</small><br />
						 <textarea name="description[<?php echo $counter;?>]" cols="70" rows="4" id="description[<?php echo $counter;?>]" style="height:50px"><?php if($autodata) echo $description;?></textarea>
					 </td>
                   </tr>
				   <tr>
                     <td colspan="3">
						 <label>
						  <input type="checkbox" name="featured[<?php echo $counter;?>]" id="check_ignore" value="1" /> Mark video as <span class="b_featured">featured</span>
						</label>
					 </td>
                   </tr>
                 </table>
			</td>
				<td align="center" class="table_row_check">
					<input name="video_ids[<?php echo $counter;?>]" type="checkbox" value="<?php echo $url.'" '; if($no_embed == 1 || $private == 1) echo 'disabled="disabled" id="check_ignore"'; ?>"/>
				</td>
				<td align="center">
					<a href="#import_button" class="anchorLink"><img src="images/ico_arr_down.gif" border="0" width="11" height="11" /></a>
				</td>
			  </tr>
		<?php
				$counter++;
			}
			else
			{
				$duplicates++;
			}
		}	//	end for()
	}	//	end if()
	else
	{
		?>
		<tr>
		<td colspan="2" align="center">
		Sorry, no results were found! Try again using different keywords.
		</td>
		</tr>
		<?php
	}
	
	if($duplicates == $total_results)
	{
		//	All videos found 
		?>
		<tr>
		<td colspan="2" align="center">
		You already have these videos in your database.<br />
		Please try again by selecting more than <?php echo $import_results; ?> results or by using different keywords.
		</td>
		</tr>
		<?php
	}
?>
	</table>
	<?php
		//	generate pagination	
		if($total_search_results > 0)
		{
		 if($total_search_results > 1000)
		 {
			$total_search_results = 999 - $import_results;
		 }
		?>
		<br />
		<?php if($duplicates != $total_results) : ?>
		<a name="import_button" id="import_button"></a>
		<div align="right"><input type="submit" name="submit" value="Import" class="approvebutton"></div>
		<?php endif; ?>
		<div align="center">
		 <div class="pagination">
		  <?php
		  
		  	// generate smart pagination
			$filename = 'import.php';
			$ext = 'action=search&keyword='.$v.'&results='.$import_results.'&page='.$page.'&autofilling='.$autofilling.'&autodata='.$autodata;
			$ext .= (count($overwrite_category) > 0) ? '&oc=1&utc='. implode(',', $overwrite_category) : '&oc=0&utc=';
			$pagination = '';
			$pagination = a_generate_smart_pagination($page, $total_search_results, $import_results, 1, $filename, $ext);
			echo $pagination;
		  ?>
		 </div>
		</div>
		<?php
		} // end if($youtube[0]['OPENSEARCH:TOTALRESULTS'] > 0)
		?>
	<!-- search form information -->
	<input type="hidden" name="keyword" value="<?php echo htmlentities(urldecode($v), ENT_COMPAT); ?>" />
	<input type="hidden" name="results" value="<?php echo $import_results; ?>" />
	<input type="hidden" name="autofilling" value="<?php echo $autofilling; ?>" />
	<input type="hidden" name="autodata" value="<?php echo $autodata; ?>" />
	<input type="hidden" name="overwrite_category" value="<?php echo ($_GET['oc'] == 1 || is_array($_POST['use_this_category'])) ? '1' : '0'; ?>" />
	<input type="hidden" name="use_this_category" value="<?php echo implode(',', $overwrite_category); ?>" />

   </form>

<?php
}
?>
</div>
<?php
include('footer.php');
?>