<!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>GiantDisc: Edit Album</title>
<link href="gdweb.css" rel="stylesheet" type="text/css">
</head>
<body>

<h5>GiantDisc Web Interface</h5>
<h2>Edit Album Details</h2>

<? 
include "gdweb.php";
$dbh = mysql_connect();	

#phpinfo();
?>


<? 
### Edit Album
if(isset($edtartist)){
  $sqlcmd= "UPDATE album SET "
          ."artist='$edtartist', title='$edttitle', modified=CURDATE() "
		  ."WHERE cddbid='$cddbid'";

  print ("<p>SQL-COMMAND: ". $sqlcmd."</p>");

  if(! mysql_db_query ("GiantDisc", $sqlcmd)){
    echo "<p><b>Error: </b>".mysql_errno()." - ".mysql_error()."</p>";
  }
  else{
    echo "<p><b>Record sucessfully updated</b><br>\n";
  }
}



### Download Cover Image
if(isset($getremotecover) and (strlen($getremotecover)>11)){
  $pgnum="00";
  if(isset($front) and ($front==0)){
    $pgnum="99";
  }
  $file = fopen ($getremotecover, "r");
  if (!$file) {
      echo "<p>Unable to open remote file '$getremotecover'.\n";
      exit;
  }
  $destfp = fopen ("$global_writable_dir/img0x$cddbid-$pgnum.jpg", "w");
  print "<p><small>Read $getremotecover and save it to $global_writable_dir/img0x$cddbid-$pgnum.jpg</small><p>";
  while (!feof ($file)) {
    $chunk = fread ($file, 1024);
    fwrite ($destfp, $chunk);
  }
  fclose($destfp);
  fclose($file);
  
  if ($pgnum == "00"){
    mysql_db_query ("GiantDisc", 
                    "UPDATE album SET "
                   ."coverimg='img0x$cddbid-$pgnum.jpg', modified=CURDATE() "
		           ."WHERE cddbid='$cddbid'");
  }
}




### Show Album
if(isset($cddbid)){
  # open data source

  print "<form action='gdeditalbum.php' method='put'>";
  
  print "<table border=\"0\" cellspacing=\"0\">\n";
  $recset = mysql_db_query ("GiantDisc", "SELECT * FROM album WHERE cddbid='$cddbid'");
  if($row = mysql_fetch_array($recset)) {
    print "<td class='plformtit'>Artist: </td><td class='plform'>";
    print "<input type='text' name='edtartist' value='".$row["artist"]."' size='40' maxlength='200'>";
    print "</td></tr>";

    print "<td class='plformtit'>Title: </td><td class='plform'>";
    print "<input type='text' name='edttitle' value='".$row["title"]."' size='40' maxlength='200'>";
    print "</td></tr>";

    print "<tr><td>cddb-id:</td><td>".$row["cddbid"]."</td></tr>";
    print "<tr><td>cover-img:</td><td>".$row["coverimg"]."</td></tr>";
    print "<tr><td>last modified:</td><td>".$row["modified"]."</td></tr>";
    
    # hidden fields
    print "<input type='hidden' name='cddbid' value='$cddbid'>";
  }
  print "</table>\n";
  print "<p><input type='submit' value='Update' style='size: small;'></p>";
  print "</form>";



  print "<h5>Download Cover Image from Remote Location</h5>";
  print "<form action='gdeditalbum.php' method='get'>";
  print "<p><small>";
  print "<input type='text' name='getremotecover' value='http://' size='40' maxlength='400'>&nbsp;&nbsp;&nbsp;";
  print "<input type='submit' value='Download' style='size: small;'><br>";
  print "<input type='radio' name='front' value='1' checked>front&nbsp;&nbsp;";
  print "<input type='radio' name='front' value='0' >back";
  print "<input type='hidden' name='cddbid' value='$cddbid'>";
  print "</small></p>";
  print "</form>";



  if (strlen($cddbid)>=8){
    exec("/bin/ls musichome/??/img??".$cddbid."-??.jpg", $imglist);
    #print_r ($imglist);
    print "<h5>cover images</h5>";
    reset($imglist);
    print "<p>";
    foreach($imglist as $image){
      print " <a href='?cddbid=$cddbid&fullsz=$image'><img border='0' height='80' src=\"$image\"></a>&nbsp; ";
    }
    print "</p>";
  }
  
  if (isset($fullsz)){
    print "<p><img src=\"$fullsz\"></p>";
  }

  
  mysql_free_result($recset);
  
}
?>



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