Fix stream playing
[adorno.git] / www / db.php
blob8f00f36579efb0a1f48f1ab76b21025bcc2868a9
1 <?php
2 include("always.php");
3 include("header.php");
5 $letter_get = ( "$altr" == "" ? "" : "&altr=$altr" ) . ( "$lltr" == "" ? "" : "&lltr=$lltr" );
7 function track_link( $trk, $link_title, $row_class = "" ) {
8 global $letter_get;
9 $link = "<tr class=track$row_class><td class=track$row_class><a class=track$row_class href=\"db.php?l=" . urlencode($trk->album) . "&a=" . urlencode($trk->artist) . "&t=" . urlencode($trk->title) . "$letter_get\" title=\"$trk->path_name\">";
10 // $link .= str_replace( " ", "&nbsp;", $link_title);
11 $link .= $link_title;
12 $link .= "</a></td>";
13 $link .= "<th class=track><a class=alphabetica class=track$row_class href=\"edit_track.php?l=" . urlencode($trk->album) . "&a=" . urlencode($trk->artist) . "&t=" . urlencode($trk->title) . "\" title=\"Edit Track Info\">E</a></th>";
14 $link .= "</tr>\n";
16 return $link;
19 if ( isset($l) && isset($a) && isset($t) ) {
20 $q = "SELECT * FROM tracks WHERE album = '" . addslashes($l) . "' AND artist = '" . addslashes($a) . "' AND title='" . addslashes($t) . "' ";
21 $res = awm_pgexec( $dbconn, $q, "db");
22 if ( $res && pg_NumRows($res) > 0 ) {
23 $track = pg_Fetch_Object( $res, 0 );
24 $fifo = fopen( "/var/run/adorno/fifo", "w" );
25 fputs( $fifo, "queue $track->path_name\n" );
26 fclose($fifo);
27 $q = "SELECT track_played( '" . addslashes($track->hash_key) . "'); ";
28 $res = awm_pgexec( $dbconn, $q, "db");
32 echo "<table><tr valign=top>\n";
33 $widthused=0;
35 if ( isset($l) || isset($a) || isset($t) ) {
36 echo "<td width=40%>\n";
37 $widthused += 40;
38 if ( (isset($a) || isset($play)) && isset($l) && ! isset($t) ) {
39 // Play all of the tracks for this alum
40 $q = "SELECT * FROM tracks WHERE album = '" . addslashes($l) . "' ";
41 if ( isset($a) ) $q .= "AND artist = '" . addslashes($a) . "'";
42 $q .= "ORDER BY setpart, tracknum; ";
43 $res = awm_pgexec( $dbconn, $q, "db");
44 if ( $res && pg_NumRows($res) > 0 ) {
45 $fifo = fopen( "/var/run/adorno/fifo", "w" );
46 $q = "";
47 for ( $i=0; $i < pg_NumRows($res); $i ++ ) {
48 $track = pg_Fetch_Object( $res, $i );
49 fputs( $fifo, "queue $track->path_name\n" );
50 $q .= "SELECT track_played( '" . addslashes($track->hash_key) . "'); ";
52 fclose($fifo);
53 $res = awm_pgexec( $dbconn, $q, "db");
57 if ( isset($a) ) {
58 $qa = "SELECT * FROM tracks WHERE artist = '" . addslashes($a) . "' ";
59 $qa .= "ORDER BY album, setpart, tracknum; ";
60 $res = awm_pgexec( $dbconn, $qa, "db");
61 if ( $res && pg_NumRows($res) > 0 ) {
62 echo "<h3>$a</h3>\n";
63 $last_album = "";
64 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
65 $track = pg_Fetch_Object( $res, $i );
66 if ( $track->album != "" && $track->album != $last_album ) {
67 if ( $i > 1 ) echo "</table>";
68 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4><td width=96% class=th4>";
69 echo "<a class=th4 href=\"db.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">$track->album</a></td>\n";
70 echo "<td width=4% class=th4><a class=alphabetica class=track href=\"edit_track.php?l=" . urlencode($track->album) . "&a=" . urlencode($track->artist) . "\" title=\"Edit Album Info\">E</a></td></tr>";
71 $last_album = $track->album;
73 else if ( $i == 0 ) {
74 echo "<br><table width=100%><tr><td width=96% class=h4>";
75 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
77 // echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", " bgcolor=" . $colors["bg".($i%2)] );
78 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $i % 2 );
80 echo "</table>";
83 else if ( isset( $l ) ) {
84 $qa = "SELECT * FROM tracks WHERE album = '" . addslashes($l) . "' ";
85 $qa .= "ORDER BY album, setpart, tracknum; ";
86 $res = awm_pgexec( $dbconn, $qa, "db");
87 if ( $res && pg_NumRows($res) > 0 ) {
88 echo "<h3><a class=th4 href=\"db.php?play=1&l=" . urlencode($l) . "$letter_get\">$l</a></h3>\n";
89 $last_artist = "";
90 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
91 $track = pg_Fetch_Object( $res, $i );
92 if ( $track->artist != "" && $track->artist != $last_artist ) {
93 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4><td width=96% class=th4>";
94 echo "<a class=h4 href=\"db.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">$track->artist</a></td>\n";
95 echo "<td width=4% class=th4><a class=alphabetica class=track href=\"edit_track.php?l=" . urlencode($track->album) . "&a=" . urlencode($track->artist) . "\" title=\"Edit Album Info\">E</a></td></tr>";
96 $last_artist = $track->artist;
98 else if ( $i == 0 ) {
99 echo "<br><table width=100%><tr><td width=96% class=h4>";
100 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
102 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $i % 2 );
104 echo "</table>";
109 echo "<td width=" . ((100 - $widthused) / 2) . "%>\n";
110 echo "<h3>Artists</h3>\n<p>";
111 $qa = "SELECT distinct upper(substring(artist from 1 for 1)) AS altr FROM tracks ORDER BY 1;";
112 $res = awm_pgexec( $dbconn, $qa, "db");
113 if ( $res && pg_NumRows($res) > 0 ) {
114 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
115 $artist = pg_Fetch_Object( $res, $i );
116 if ( "$artist->altr" == "" ) continue;
117 echo "<a class=alphabetica href=\"db.php?altr=" . urlencode($artist->altr);
118 if ( "$lltr" <> "" ) {
119 echo "&lltr=" . urlencode($lltr);
121 if ( "$a" <> "" ) {
122 echo "&a=" . urlencode($a);
124 elseif ( "$l" <> "" ) {
125 echo "&l=" . urlencode($l);
127 echo "\">$artist->altr</a>\n";
130 echo "</p>\n<p>";
131 if ( isset($altr) ) {
132 $qa = "SELECT distinct artist FROM tracks WHERE artist ilike '$altr%' ORDER BY 1;";
133 $res = awm_pgexec( $dbconn, $qa, "db");
134 if ( $res && pg_NumRows($res) > 0 ) {
135 // echo "<p><b>ARTISTS &nbsp;&gt; &gt;</b> &nbsp;\n";
136 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
137 $artist = pg_Fetch_Object( $res, $i );
138 if ( $i > 0 ) echo " - ";
139 echo "<a href=\"db.php?a=" . urlencode($artist->artist) . "$letter_get\">[" . str_replace(" ", " ", $artist->artist) . "]</a>\n";
143 echo "</td>\n";
145 echo "<td width=" . ((100 - $widthused) / 2) . "%>\n";
146 echo "<h3>Albums</h3>\n<p>";
147 $qa = "SELECT distinct upper(substring(album from 1 for 1)) AS lltr FROM tracks ORDER BY 1;";
148 $res = awm_pgexec( $dbconn, $qa, "db");
149 if ( $res && pg_NumRows($res) > 0 ) {
150 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
151 $artist = pg_Fetch_Object( $res, $i );
152 if ( "$artist->lltr" == "" ) continue;
153 echo "<a class=alphabetica href=\"db.php?lltr=" . urlencode($artist->lltr);
154 if ( "$altr" <> "" ) {
155 echo "&altr=" . urlencode($altr);
157 if ( "$a" <> "" ) {
158 echo "&a=" . urlencode($a);
160 elseif ( "$l" <> "" ) {
161 echo "&l=" . urlencode($l);
163 echo "\">$artist->lltr</a>\n";
166 echo "</h3>\n<p>";
167 if ( isset($lltr) ) {
168 $qa = "SELECT distinct album FROM tracks WHERE album ilike '$lltr%' ORDER BY 1;";
169 $res = awm_pgexec( $dbconn, $qa, "db");
170 if ( $res && pg_NumRows($res) > 0 ) {
171 echo "<p><b>ALBUMS &nbsp;&gt; &gt;</b> &nbsp;\n";
172 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
173 $album = pg_Fetch_Object( $res, $i );
174 echo "<a href=\"db.php?l=" . urlencode($album->album) . "$letter_get\">[" . str_replace(" ", " ", $album->album) . "]</a> &nbsp;\n";
178 echo "</td>\n";
179 echo "</tr></table>\n";
180 show_queue();
183 </body>
184 </html>