<?
setcookie("TestCookie","Test Value");
?>
<!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>GiantDisc Web Interface</title>
<link href="gdweb.css" rel="stylesheet" type="text/css">
</head>
<body>

<h2>GiantDisc Web Interface: Select Tracks</h2>
<!--
<p>The cookieval is &quot;<? echo $HTTP_COOKIE_VARS["TestCookie"]; ?>&quot; </p>
<p><a href="gdtrid2mp3.php">redir-link</a></p>
-->
<? 
include "gdweb.php";

#phpinfo();

function show_selform($showartist, $artist, $showtitle, $title, $showgenre, $genre, 
			 $showlang, $lang, $showyear, $yearfrom, $yearto, $showrating, $rating,
			 $showbpm, $bpmfrom, $bpmto, $showsource, $source,
			 $showcreated, $created, $showmodified, $modified){
?>
<table border="0">
<tr>
<td class="selformtit">show</td>
<td class="selformtit"><b>query</b> </td>
<td class="selform"> &nbsp;
</td></tr>

<tr>
<td class="selform"><input type="checkbox" name="showartist" 
  <?if (strcmp($showartist, "on")==0){ ?>checked <?}?>></td>
<td class="selformtit"><b>Artist</b> </td>
<td class="selform"> <input type="text" name="artist" value="<?echo $artist ?>" size="20" maxlength="200">
</td></tr>

<tr>
<td class="selform"><input type="checkbox" name="showtitle"
  <?if (strcmp($showtitle, "on")==0){ ?>checked <?}?>></td>
<td class="selformtit"><b>Title</b></td>
<td class="selform"> <input type="text" name="title"  value="<?echo $title  ?>" size="20" maxlength="200">
</td></tr>

<tr>
<td class="selform"><input type="checkbox" name="showgenre"
  <?if (strcmp($showgenre, "on")==0){ ?>checked <?}?>></td>
<td class="selformtit"><b>Genre</b></td>
<td class="selform"> 
<select name="genre"><? print_genre_options($genre); ?></select>
</td></tr>

<tr>
<td class="selform"><input type="checkbox" name="showrating"
  <?if (strcmp($showrating, "on")==0){ ?>checked <?}?>></td>
<td class="selformtit"><b>Rating</b></td>
<td class="selform"> 
<select name="rating"><? 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;Query&nbsp;&nbsp;"></td></tr>
</table>
<?
} # END OF show_selform
?>


<form action="gdsel.php" method="get">

<? 

show_selform($showartist, $artist, $showtitle, $title, $showgenre, $genre, 
			 $showlang, $lang, $showyear, $yearfrom, $yearto, $showrating, $rating,
			 $showbpm, $bpmfrom, $bpmto, $showsource, $source,
			 $showcreated, $created, $showmodified, $modified);

# set default val for mp3 Play-Method
if(!isset($playtp)){ $playtp="df"; } 

if(isset($artist)){
  # open data source
  $ds = 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." ");

  
  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\">";
	}
	if (strlen($row["year"])>2){ $yearstr = "'".substr($row["year"], 2, 2);}
	else                       { $yearstr = $row["year"];}
    $evenln = 1-$evenln; #toggle $evenln

    if (strcmp($playtp, "dl")==0){$mp3path = full_mp3_fname($row["mp3file"]);}
    
    if (strcmp($showartist, "on")==0){
      print "<td class=\"trklst\">&nbsp;".$row["artist"]." </td>";
	}
    if (strcmp($showtitle, "on")==0){
	  print "<td class=\"trklst\">&nbsp;".$row["title"]." </td>";
	}
    if (strcmp($showgenre, "on")==0){
	  print "<td class=\"trklst\">&nbsp;";
      if (strlen($row["genre1"])>0){
	    print_genre_string($row["genre1"]);
	  }
      if (strlen($row["genre1"])>0 && strlen($row["genre2"])>0){print "<br>";}
      if (strlen($row["genre2"])>0){
	    print "&nbsp;";
	    print_genre_string($row["genre2"]);
	  }
	  print "</td>";
	}
    if (strcmp($showrating, "on")==0){
	  print "<td class=\"trklst\">&nbsp;";
      print_rating_string($row["rating"]);
	  print "</td>";
	}
	  print "<td class=\"trklst\">&nbsp;".$yearstr." </td>";
	  print "<td class=\"trklst\">&nbsp;".seconds2time($row["length"])." </td>";
#	  print "<td class=\"trklst\">&nbsp;<a href=\"gdedittrack.php?id="
#		   		.$row["id"]."\"><img border=\"0\" src=\"img/view-c.gif\"></a></td>";
	  print "<td class=\"trklst\">&nbsp;<a href=\"gdedittrack.php?id="
		   		.$row["id"]."\"><img border=\"0\" src=\"img/edit-c.gif\"></a></td>";
      # Download mp3
	  # types: playtp = dl, rd, df, dl or dr
      if (strcmp($playtp, "dl")==0){
	    print "<td class=\"trklst\">&nbsp;<a href=\"".$mp3path."\">"
		     ."<img border=\"0\" src=\"img/play-c.gif\"></a></td>";
	  }
      else{ # all other playtypes handled by "gdtrid2mp3.php"
	    print "<td class=\"trklst\">&nbsp;<a href=\"gdtrid2mp3.php?playtp=$playtp"
				."&id=".$row["id"]
				."&mp3f=".$row["mp3file"]
				."\">"."<img border=\"0\" src=\"img/play-c.gif\"></a></td>";
	  }
	print "</tr>\n";
  }
  print("</table>\n");
/*
*/
  mysql_free_result($recset);
}
?>

<hr noshade>

<p>
<table>
<tr>
<td class="trklst">
<img border="0" src="img/play-c.gif">
</td>
<td class="trklst">
mp3 file play method<br>
<input type="radio" name="playtp" value="dl" <?if (strcmp($playtp, "dl")==0){ ?>checked <?}?>>
Download URL (slow query, slow download))<br>
<input type="radio" name="playtp" value="rd" <?if (strcmp($playtp, "rd")==0){ ?>checked <?}?>>
Redirect URL (clumsy, slow download)<br>
<input type="radio" name="playtp" value="df" <?if (strcmp($playtp, "df")==0){ ?>checked <?}?>>
Dynamically generate mp3 file (slow download)<br>
<input type="radio" name="playtp" value="pr" <?if (strcmp($playtp, "pr")==0){ ?>checked <?}?>>
Winamp Playlist remote file (URL) (Netscape only)<br>
<!--
<input type="radio" name="playtp" value="pl" <?if (strcmp($playtp, "pl")==0){ ?>checked <?}?>>
Winamp Playlist local file [not implemented]<br>
-->
</td></tr>
</table>

</form>

<? 
?>
</body>
</html>