Remove Session library as well.
[adorno.git] / www / album.php
blobb83fea68964a98ad9904f2349a91ab490a0ab668
1 <?php
2 require_once("always.php");
3 require_once("Session.php");
4 require_once("PlayTracks.php");
6 $title = $system_name;
7 require_once("header.php");
10 if ( "$error_loc$error_msg" == "" ) {
12 function track_link( $trk, $link_title, $row_class = "" ) {
13 global $letter_get;
15 $url_artist = urlencode($trk->artist);
16 $track_link_url = sprintf( "?l=%s&a=%s&t=%s", urlencode($trk->album), $url_artist, urlencode($trk->title) );
18 $link_title = ($trk->tracknum > 0 ? "$trk->tracknum: " : "") . $trk->title;
19 $safe_title = htmlspecialchars($link_title);
20 $safe_artist = htmlspecialchars($trk->artist);
22 $duration = preg_replace( "/^[0:]{1,4}/", "", $trk->duration );
23 $link = <<<EOHTML
24 <tr class="track$row_class">
25 <td class="track$row_class">
26 <a class="track$row_class" href="artist.php$track_link_url$letter_get" title="$trk->path_name">$safe_title</a>
28 <a class="track$row_class" href="artist.php?a=$url_artist$letter_get" title="Show tracks by $trk->artist">$safe_artist</a>
29 </td>
30 <td class="track$row_class">$duration</td>
31 <th class="track$row_class">
32 <a class="alphabetica" href="edit_track.php$track_link_url" title="Edit Track Info">E</a>
33 </th>
34 </tr>
36 EOHTML;
38 return $link;
42 echo "<table width=\"100%\"><tr valign=\"top\">\n";
44 echo "<td width=\"40%\">\n";
45 if ( isset($a) ) {
46 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
47 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
48 $qa .= "FROM tracks WHERE lower(artist) = lower('" . addslashes($a) . "') ";
49 $qa .= "ORDER BY lower(album), setpart, tracknum; ";
50 $res = awm_pgexec( $dbconn, $qa, "db");
51 if ( $res && pg_NumRows($res) > 0 ) {
52 echo "<h3>".htmlspecialchars($a)."</h3>\n";
53 $last_album = "";
54 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
55 $track = pg_Fetch_Object( $res, $i );
56 if ( $track->album != $last_album ) {
57 if ( $i > 1 ) echo "</table>";
58 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4>";
59 echo "<a class=th4 href=\"album.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">";
60 echo "<td width=86% class=th4>";
61 echo htmlspecialchars($track->album);
62 echo "</td>\n";
63 echo "</a>";
64 echo "<td width=10% class=th4>&nbsp;</td>";
65 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>";
66 $last_album = $track->album;
68 else if ( $i == 0 ) {
69 echo "<br><table width=100%><tr><td width=96% class=h4>";
70 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
72 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $i % 2 );
74 echo "</table>";
77 else if ( isset( $l ) ) {
78 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
79 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
80 $qa .= "FROM tracks WHERE album = '" . addslashes($l) . "' ";
81 $qa .= "ORDER BY album, setpart, tracknum; ";
82 $res = awm_pgexec( $dbconn, $qa, "db");
83 if ( $res && pg_NumRows($res) > 0 ) {
84 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";
85 $last_album = "";
86 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
87 $track = pg_Fetch_Object( $res, $i );
88 if ( $i == 0 ) {
89 echo "<br /><table width=100%>";
91 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title / $track->artist", $i % 2 );
93 echo "</table>";
96 else {
97 echo "&nbsp;";
99 echo "</td>";
101 echo "<td width=\"60%\">\n";
102 echo "<h3>Albums</h3>\n<p>";
103 if ( isset($altr) || isset($search) ) {
104 $altr = trim("$altr");
105 if ( isset($search) ) {
106 $sql = "SELECT distinct ON ( lower(album)) album FROM tracks ";
107 $sql .= "WHERE artist ~* ? OR album ~* ? OR title ~* ? OR path_name ~* ? ";
108 $sql .= "ORDER BY lower(album);";
109 $qry = new PgQuery( $sql, $search, $search, $search, $search );
111 else {
112 $qry = new PgQuery( "SELECT distinct ON ( lower(album)) album FROM tracks WHERE album ~* ? ORDER BY lower(album);", "^$altr");
114 if ( $qry->Exec('album') && $qry->rows > 0 ) {
115 while ( $album = $qry->Fetch() ) {
116 $display = htmlspecialchars($album->album);
117 if ( trim($display) == "" ) $display = "&laquo;unknown&raquo;";
118 echo " <a href=\"album.php?l=" . urlencode($album->album) . "$letter_get\" class=\"artist\">$display</a>\n";
122 echo "</td>\n";
124 echo "</tr></table>\n";
127 include("footers.php");