<?php

include "gdweb.php";
include "gdwebdef.php";

$playtp = set_get_cookie($setplaytp, "playtp", "dl", $HTTP_COOKIE_VARS);

print_header ("search");

#phpinfo();

#######################################################################################
### Functions

function show_searchform($artist, $title, $genre, $lang, $yearfrom, $yearto, $rating,
                         $bpmfrom, $bpmto, $source, $created, $modified){
?>
<table border="0">
<tr>
<td class="selformtit"><b>Artist</b> </td>
<td class="selform"> <input type="text" name="artist" value="<?php echo $artist ?>" size="20" maxlength="200">
</td></tr>

<tr>
<td class="selformtit"><b>Title</b></td>
<td class="selform"> <input type="text" name="title"  value="<?php echo $title  ?>" size="20" maxlength="200">
</td></tr>

<tr>
<td class="selformtit"><b>Genre</b></td>
<td class="selform"> 
<select name="genre"><?php print_genre_options($genre); ?></select>
</td></tr>

<tr>
<td class="selformtit"><b>Rating</b></td>
<td class="selform"> 
<select name="rating"><?php print_rating_options($rating); ?></select>
</td></tr>

<tr><td colspan="2" class="selform">
<!--input type="reset" value="Clear">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-->
<input type="submit" value="&nbsp;&nbsp;Search&nbsp;&nbsp;"></td></tr>
</table>
<?php
} # END OF show_selform

#######################################################################################

?>

<p>
<form action="index.php" method="get">

<?php 

show_searchform($artist, $title, $genre, $lang, $yearfrom, $yearto, $rating,
			    $bpmfrom, $bpmto, $source, $created, $modified);
			
#print "Cookie: playtp".$playtp.", showartist ".$showartist." <br>";

if(isset($artist)){
  # open data source
  $dbh = mysql_connect();	

  ### VERY preliminary query
  if (strlen($rating)==0){$rating=0;}
  $recset = mysql_db_query ("GiantDisc", "SELECT * FROM tracks WHERE artist LIKE '%$artist%' AND title LIKE '%".$title."%' AND (genre1 LIKE '".$genre."%' OR genre2 LIKE '".$genre."%') AND rating>=".$rating." ");

  
  if (mysql_affected_rows()>0){print "<hr noshade>";}else{print "<p>&nbsp;</p>";}
  print("<p><small><b>".mysql_affected_rows()." machting tracks</b></small></p>");
  print("<table border=\"0\" cellspacing=\"0\">\n");
  $evenln = 1;
  while($row = mysql_fetch_array($recset)) {
    if ($evenln){
      print "<tr class=\"lneven\">";
	}
	else{
      print "<tr class=\"lnodd\">";
	}
    show_trackrow($row,
	          $showartist, $showtitle, $showgenre, $showlang, $showyear, $showrating,
			  $showbpm, $showsource, $showcreated, $showmodified, $showlength,
			  $showedit, $showdownload, $playtp, $showtoplaylist);
    $evenln = 1-$evenln; #toggle $evenln
	
	print "</tr>\n";
  }
  print("</table>\n");
/*
*/
  mysql_free_result($recset);
}
?>

<hr noshade>

<p>
<?php
#show_showform($showartist, $showtitle, $showgenre, $showlang, $showyear, $showrating,
#			  $showbpm, $showsource, $showcreated, $showmodified, $showlength,
#			  $showedit, $showdownload, $showtoplaylist);
?>
</form>

<?php 
print_footer ("search");
?>
