Remove Session library as well.
[adorno.git] / www / edit_track.php
blob3f591b87de844a068cd95789f1a7c6c140d1719a
1 <?php
2 $refresh = false;
3 $page_title = "Edit Track Information";
4 include("always.php");
6 if ( isset( $submit ) && $submit == "update" ) {
7 // update the track
8 // $actions = "<p>Updating tracks";
9 for ( $i=0 ; isset( $hash[$i] ); $i++ ) {
10 $q = "SELECT * FROM tracks WHERE hash_key='$hash[$i]';";
11 $res = awm_pgexec( $dbconn, $q );
12 // $actions .= "<p>Query: $q";
13 if ( $res && pg_NumRows( $res) == 1 ) {
14 $track = pg_Fetch_Object( $res, 0 );
15 // $actions .= "<p>Editing: $track->title";
16 if ( ! isset( $artist[$i] ) ) $artist[$i] = $artist[0];
17 if ( ! isset( $album[$i] ) ) $album[$i] = $album[0];
18 if ( ereg( "\.ogg$", $track->path_name ) ) {
19 // Update the details on an ogg file
20 $command = "/usr/bin/vorbiscomment -w " . escapeshellarg($track->path_name);
21 $command .= " -t " . escapeshellarg( "ARTIST=$artist[$i]" );
22 $command .= " -t " . escapeshellarg( "ALBUM=$album[$i]" );
23 $command .= " -t " . escapeshellarg( "TITLE=$title[$i]" );
24 $command .= " -t " . escapeshellarg( "TRACKNUMBER=$tracknum[$i]" );
26 else {
27 // Update the details on an mp3 file
28 $command = "/usr/bin/id3v2 -a " . escapeshellarg($artist[$i]) . " -A " . escapeshellarg($album[$i]);
29 $command .= " -t " . escapeshellarg($title[$i]) . " -T " . escapeshellarg($tracknum[$i]) . " ". escapeshellarg($track->path_name);
31 // $actions .= "<p>Command: $command";
32 $result = `$command`;
33 if ( eregi( "error.*opening", $result ) ) {
34 $actions .= "<p class=error>Error opening file - are your files / directories mode 666 / 777?";
36 $command = "/usr/bin/md5sum " . escapeshellarg($track->path_name);
37 $md5 = `$command`;
38 // $actions .= "<p>Command: $command";
39 list( $newhashkey, $track) = explode( " ", trim($md5), 2);
40 $q = "UPDATE played SET hash_key = '$newhashkey' WHERE hash_key = '" . pg_escape_string($hash[$i]) . "'; ";
41 $q .= "UPDATE tracks SET hash_key = '$newhashkey', ";
42 $q .= "artist = '" . pg_escape_string($artist[$i]) . "', ";
43 $q .= "album = '" . pg_escape_string($album[$i]) . "', ";
44 $q .= "title = '" . pg_escape_string($title[$i]) . "', ";
45 $q .= "tracknum = '" . pg_escape_string($tracknum[$i]) . "' ";
46 $q .= "WHERE hash_key = '" . pg_escape_string($hash[$i]) . "'; ";
47 $res = awm_pgexec( $dbconn, $q );
48 // $actions .= "<p>Query: $q";
49 $actions .= "<p>Updated $title[$i]";
51 else if ( $res ) {
52 $actions .= "<p class=error>Looks like the hash $hash[$i] is insufficiently unique!";
54 else {
55 $actions .= "<p class=error>No tracks found for hash $hash[$i] !";
60 include("header.php");
62 echo "$actions";
64 $letter_get = ( "$altr" == "" ? "" : "&altr=$altr" ) . ( "$lltr" == "" ? "" : "&lltr=$lltr" );
66 function show_edit( $i, $trk ) {
67 echo "<input type=hidden name=hash[$i] value=$trk->hash_key>\n";
68 if ( $i == 0 ) {
69 echo "<tr class=row" . ($i%2) . "><th class=row" . ($i%2) . " align=right>Artist:</th>";
70 echo "<td class=row" . ($i%2) . "><input class=row" . ($i%2) . " type=text size=60 name=artist[$i] value=\"" . htmlentities($trk->artist) . "\"></td></tr>\n";
71 echo "<tr class=row" . ($i%2) . "><th class=row" . ($i%2) . " align=right>Album:</th>";
72 echo "<td class=row" . ($i%2) . "><input type=text size=60 name=album[$i] value=\"" . htmlentities($trk->album) . "\"></td></tr>\n";
74 echo "<tr class=row" . ($i%2) . "><th class=row" . ($i%2) . " align=right>Title:</th>";
75 echo "<td class=row" . ($i%2) . "><input type=text size=60 name=title[$i] value=\"" . htmlentities($trk->title) . "\"></td></tr>\n";
76 echo "<tr class=row" . ($i%2) . "><th class=row" . ($i%2) . " align=right>Number:</th>";
77 echo "<td class=row" . ($i%2) . "><input class=row" . ($i%2) . " type=text size=5 name=tracknum[$i] value=\"" . htmlentities($trk->tracknum) . "\"></td></tr>\n";
78 echo "<tr class=row" . ($i%2) . "><td colspan=2><hr></td></tr>\n";
81 if ( isset($l) && isset($a) ) {
82 $q = "SELECT * FROM tracks WHERE album = '" . addslashes($l) . "' AND artist = '" . addslashes($a) . "' ";
83 if ( isset($t) ) {
84 $q .= "AND title='" . addslashes($t) . "' ";
86 $q .= "ORDER BY tracknum; ";
87 $res = awm_pgexec( $dbconn, $q, "db");
88 if ( $res && pg_NumRows($res) > 0 ) {
89 echo "<form method=post>\n";
90 echo "<table width=100%>\n";
91 for ( $i=0; $i < pg_NumRows($res); $i++ ) {
92 $track = pg_Fetch_Object( $res, $i );
93 show_edit( $i, $track );
95 echo "<tr><td>&nbsp;</td><td align=left><input type=submit name=submit value=update></td></tr>\n";
96 echo "</table>\n";
97 echo "</form>\n";
100 else {
101 echo "<h1>Error: No Album Selected</h1>
102 <p>You will need to select an album or a track for editing";
105 show_queue();
108 </body>
109 </html>