Mostly working now - as long as I use hacked xmms2
[adorno.git] / www / album.php
blob3f5f4b02689bbe41fc97e93848b0c8a94113963c
1 <?php
2 unset($altr); if ( isset($_GET['altr']) ) $altr = $_GET['altr'];
3 unset($lltr); if ( isset($_GET['lltr']) ) $lltr = $_GET['lltr'];
4 unset($a); if ( isset($_GET['a']) ) $a = $_GET['a'];
5 unset($l); if ( isset($_GET['l']) ) $l = $_GET['l'];
7 require_once("always.php");
8 require_once("Session.php");
9 require_once("PlayTracks.php");
11 $title = $system_name;
12 require_once("header.php");
15 if ( "$error_loc$error_msg" == "" ) {
17 function track_link( $trk, $link_title, $row_class = "" ) {
18 global $letter_get, $search;
20 $url_artist = urlencode($trk->artist);
21 $track_link_url = sprintf( "?l=%s&a=%s&t=%s", urlencode($trk->album), $url_artist, urlencode($trk->title) );
23 $link_title = ($trk->tracknum > 0 ? "$trk->tracknum: " : "") . $trk->title;
24 $safe_title = htmlspecialchars($link_title);
25 $safe_artist = htmlspecialchars($trk->artist);
27 if ( isset($search) ) {
28 $delimiter_list = '/#~`!@$%^&*_-=|';
29 for( $i=0; strpos($search,substr($delimiter_list,$i,1)) !== false; $i++ );
30 $delimiter = substr($delimiter_list,$i,1);
31 if ( preg_match($delimiter.$search.$delimiter.'i', $link_title) || preg_match($delimiter.$search.$delimiter.'i', $trk->artist) ) {
32 $row_class = "found";
36 $duration = preg_replace( "/^[0:]{1,4}/", "", $trk->duration );
37 $link = <<<EOHTML
38 <tr class="track$row_class">
39 <td class="track$row_class">
40 <a class="track$row_class" href="artist.php$track_link_url$letter_get" title="$trk->path_name">$safe_title</a>
42 <a class="track$row_class" href="artist.php?a=$url_artist$letter_get" title="Show tracks by $trk->artist">$safe_artist</a>
43 </td>
44 <td class="track$row_class">$duration</td>
45 <th class="track$row_class">
46 <a class="alphabetica" href="edit_track.php$track_link_url" title="Edit Track Info">E</a>
47 </th>
48 </tr>
50 EOHTML;
52 return $link;
56 echo "<table width=\"100%\"><tr valign=\"top\">\n";
58 echo "<td width=\"40%\">\n";
59 if ( isset($a) ) {
60 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
61 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
62 $qa .= "FROM tracks WHERE lower(artist) = lower('" . addslashes($a) . "') ";
63 $qa .= "ORDER BY lower(album), setpart, tracknum; ";
64 $qry = new PgQuery($qa);
65 if ( $qry->Exec() && $qry->rows > 0 ) {
66 echo "<h3>".htmlspecialchars($a)."</h3>\n";
67 $last_album = "";
68 while ( $track = $qry->Fetch() ) {
69 if ( $track->album != $last_album ) {
70 if ( $qry->rownum > 1 ) echo "</table>";
71 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4>";
72 echo "<a class=th4 href=\"album.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">";
73 echo "<td width=86% class=th4>";
74 echo htmlspecialchars($track->album);
75 echo "</td>\n";
76 echo "</a>";
77 echo "<td width=10% class=th4>&nbsp;</td>";
78 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>";
79 $last_album = $track->album;
81 else if ( $qry->rownum == 0 ) {
82 echo "<br><table width=100%><tr><td width=96% class=h4>";
83 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
85 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $qry->rownum % 2 );
87 echo "</table>";
90 else if ( isset( $l ) ) {
91 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
92 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
93 $qa .= "FROM tracks WHERE album = '" . addslashes($l) . "' ";
94 $qa .= "ORDER BY album, setpart, tracknum; ";
95 $qry = new PgQuery($qa);
96 if ( $qry->Exec() && $qry->rows > 0 ) {
97 echo "<h3><a class='th4' title='Add this whole album to the playlist.' href=\"album.php?play=1&l=" . urlencode($l) . "$letter_get\">$l</a></h3>\n";
98 $last_album = "";
99 while ( $track = $qry->Fetch() ) {
100 if ( $qry->rownum == 0 ) {
101 echo "<br /><table width=100%>";
103 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title / $track->artist", $qry->rownum % 2 );
105 echo "</table>";
108 else {
109 echo "&nbsp;";
111 echo "</td>";
113 echo "<td width=\"60%\">\n";
114 echo "<h3>Albums</h3>\n<p>";
115 if ( isset($altr) || isset($search) ) {
116 $altr = trim("$altr");
117 if ( isset($search) ) {
118 $sql = "SELECT distinct ON ( lower(album)) album FROM tracks ";
119 $sql .= "WHERE artist ~* ? OR album ~* ? OR title ~* ? OR path_name ~* ? ";
120 $sql .= "ORDER BY lower(album);";
121 $qry = new PgQuery( $sql, $search, $search, $search, $search );
123 else {
124 $qry = new PgQuery( "SELECT distinct ON ( lower(album)) album FROM tracks WHERE album ~* ? ORDER BY lower(album);", "^$altr");
126 if ( $qry->Exec('album') && $qry->rows > 0 ) {
127 while ( $album = $qry->Fetch() ) {
128 $display = htmlspecialchars($album->album);
129 if ( trim($display) == "" ) $display = "&laquo;unknown&raquo;";
130 echo " <a href=\"album.php?l=" . urlencode($album->album) . "$letter_get\" class=\"artist\">$display</a>\n";
134 echo "</td>\n";
136 echo "</tr></table>\n";
139 include("footers.php");