Nicer (?) button.
[adorno.git] / www / artist.php
blob508dd827cafbf61f1f76124657b7674578ff1507
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 $track_link_url = sprintf( "?l=%s&a=%s&t=%s", urlencode($trk->album), urlencode($trk->artist), urlencode($trk->title) );
16 $safe_title = htmlspecialchars($link_title);
17 $duration = preg_replace( "/^[0:]{1,4}/", "", $trk->duration );
18 $link = <<<EOHTML
19 <tr class="track$row_class">
20 <td class="track$row_class">
21 <a class="track$row_class" href="artist.php$track_link_url$letter_get" title="$trk->path_name">$safe_title</a>
22 </td>
23 <td class="track$row_class">$duration</td>
24 <th class="track$row_class">
25 <a class="alphabetica" href="edit_track.php$track_link_url" title="Edit Track Info">E</a>
26 </th>
27 </tr>
29 EOHTML;
31 return $link;
35 echo "<table width=\"100%\"><tr valign=\"top\">\n";
37 echo "<td width=\"40%\">\n";
38 if ( isset($a) ) {
39 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
40 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
41 $qa .= "FROM tracks WHERE lower(artist) = lower('" . addslashes($a) . "') ";
42 $qa .= "ORDER BY lower(album), setpart, tracknum; ";
43 $res = awm_pgexec( $dbconn, $qa, "db");
44 if ( $res && pg_NumRows($res) > 0 ) {
45 echo "<h3>".htmlspecialchars($a)."</h3>\n";
46 $last_album = "";
47 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
48 $track = pg_Fetch_Object( $res, $i );
49 if ( $track->album != "" && $track->album != $last_album ) {
50 if ( $i > 1 ) echo "</table>";
51 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4><td width=86% class=th4>";
52 echo "<a class=th4 href=\"artist.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">".htmlspecialchars($track->album)."</a></td>\n";
53 echo "<td width=10% class=th4>&nbsp;</td>";
54 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>";
55 $last_album = $track->album;
57 else if ( $i == 0 ) {
58 echo "<br><table width=100%><tr><td width=96% class=h4>";
59 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
61 // echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", " bgcolor=" . $colors["bg".($i%2)] );
62 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $i % 2 );
64 echo "</table>";
67 else if ( isset( $l ) ) {
68 $qa = "SELECT artist, album, title, tracknum, path_name, duration::interval(0), ";
69 $qa .= "extract( EPOCH FROM duration)::int AS secs, quality ";
70 $qa .= "FROM tracks WHERE album = '" . addslashes($l) . "' ";
71 $qa .= "ORDER BY album, setpart, tracknum; ";
72 $res = awm_pgexec( $dbconn, $qa, "db");
73 if ( $res && pg_NumRows($res) > 0 ) {
74 echo "<h3><a class=th4 href=\"artist.php?play=1&l=" . urlencode($l) . "$letter_get\">$l</a></h3>\n";
75 $last_artist = "";
76 for ( $i = 0; $i < pg_NumRows($res); $i++ ) {
77 $track = pg_Fetch_Object( $res, $i );
78 if ( $track->artist != "" && $track->artist != $last_artist ) {
79 echo "<br><table width=100% cellspacing=0 cellpadding=0><tr class=th4><td width=86% class=th4>";
80 echo "<a class=h4 href=\"artist.php?a=" . urlencode($track->artist) . "&l=" . urlencode($track->album) . "$letter_get\">$track->artist</a></td>\n";
81 echo "<td width=10% class=th4>&nbsp;</td>";
82 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>";
83 $last_artist = $track->artist;
85 else if ( $i == 0 ) {
86 echo "<br><table width=100%><tr><td width=96% class=h4>";
87 echo "<h4>Unkown Album</h4></td><td width=4%>&nbsp;</td></tr>\n";
89 echo track_link($track, ($track->tracknum > 0 ? "$track->tracknum: " : "") . "$track->title", $i % 2 );
91 echo "</table>";
94 else {
95 echo "&nbsp;";
97 echo "</td>";
99 echo "<td width=\"60%\">\n";
100 echo "<h3>Artists</h3>\n<p>";
101 if ( isset($altr) || isset($search) ) {
102 $altr = trim("$altr");
103 if ( isset($search) ) {
104 $sql = "SELECT distinct ON ( lower(artist)) artist FROM tracks ";
105 $sql .= "WHERE artist ~* ? OR album ~* ? OR title ~* ? OR path_name ~* ? ";
106 $sql .= "ORDER BY lower(artist);";
107 $qry = new PgQuery( $sql, $search, $search, $search, $search );
109 else {
110 $qry = new PgQuery( "SELECT distinct ON ( lower(artist)) artist FROM tracks WHERE artist ~* ? ORDER BY lower(artist);", "^$altr");
112 if ( $qry->Exec('artist') && $qry->rows > 0 ) {
113 while ( $artist = $qry->Fetch() ) {
114 $display = htmlspecialchars($artist->artist);
115 if ( trim($display) == "" ) $display = "&laquo;unknown&raquo;";
116 echo " <a href=\"artist.php?a=" . urlencode($artist->artist) . "$letter_get\" class=\"artist\">$display</a>\n";
120 echo "</td>\n";
122 echo "</tr></table>\n";
125 include("footers.php");