function do_albums_from_database($why, $what, $who, $fragment = false, $use_artistindex = false) { global $prefs; $singleheader = array(); if ($prefs['sortcollectionby'] == "artist") { $singleheader['type'] = 'insertAtStart'; $singleheader['where'] = $why . $what . $who; } else { $singleheader['type'] = 'insertAfter'; $singleheader['where'] = 'fothergill'; } debuglog("Generating albums for " . $why . $what . $who . " from database", "DUMPALBUMS", 7); $sflag = $why == "b" ? "AND Tracktable.isSearchResult > 0" : "AND Tracktable.isSearchResult < 2"; $qstring = "SELECT Albumtable.*, Artisttable.Artistname FROM Albumtable JOIN Artisttable ON\n\t\t\t(Albumtable.AlbumArtistindex = Artisttable.Artistindex) WHERE "; if (!$use_artistindex && $who != "root" && $prefs['sortcollectionby'] != 'album' && $prefs['sortcollectionby'] != 'albumbyartist') { $qstring .= "AlbumArtistindex = '" . $who . "' AND "; } if ($use_artistindex) { $qstring .= "Albumindex IN (SELECT DISTINCT Albumindex FROM Tracktable WHERE\n\t\t\tTracktable.Artistindex = " . $who . " AND "; } else { $qstring .= "Albumindex IN (SELECT Albumindex FROM Tracktable WHERE\n\t\t\tTracktable.Albumindex = Albumtable.Albumindex AND "; } $qstring .= "Tracktable.Uri IS NOT NULL AND Tracktable.Hidden = 0 " . $sflag . ")"; $qstring .= " ORDER BY "; if ($prefs['sortcollectionby'] == "albumbyartist" && !$use_artistindex) { foreach ($prefs['artistsatstart'] as $a) { $qstring .= "CASE WHEN LOWER(Artisttable.Artistname) = LOWER('" . $a . "') THEN 1 ELSE 2 END, "; } if (count($prefs['nosortprefixes']) > 0) { $qstring .= "(CASE "; foreach ($prefs['nosortprefixes'] as $p) { $phpisshitsometimes = strlen($p) + 2; $qstring .= "WHEN LOWER(Artisttable.Artistname) LIKE '" . strtolower($p) . " %' THEN LOWER(SUBSTR(Artisttable.Artistname," . $phpisshitsometimes . ")) "; } $qstring .= "ELSE LOWER(Artisttable.Artistname) END),"; } else { $qstring .= "LOWER(Artisttable.Artistname),"; } } $qstring .= " CASE WHEN Albumname LIKE '" . get_int_text('label_allartist') . "%' THEN 1 ELSE 2 END,"; if ($prefs['sortbydate']) { if ($prefs['notvabydate']) { $qstring .= " CASE WHEN Artisttable.Artistname = 'Various Artists' THEN LOWER(Albumname) ELSE Year END,"; } else { $qstring .= ' Year,'; } } $qstring .= ' LOWER(Albumname)'; $count = 0; if ($result = generic_sql_query($qstring)) { while ($obj = $result->fetch(PDO::FETCH_OBJ)) { $artistthing = !$use_artistindex && ($prefs['sortcollectionby'] == "album" || $prefs['sortcollectionby'] == "albumbyartist") ? $obj->Artistname : null; $exists = $obj->Image && $obj->Image !== "" ? "yes" : "no"; $albumlink = $why == "a" || preg_match('/:album:|:artist:/', $obj->AlbumUri) || preg_match('/^podcast/', $obj->AlbumUri) ? rawurlencode($obj->AlbumUri) : null; if ($fragment === false) { print albumHeader($obj->Albumname, $albumlink, $why . $what . $obj->Albumindex, $exists, $obj->Searched == 1 || $exists == "yes" ? "yes" : "no", $obj->ImgKey, $obj->Image, $obj->Year, null, $artistthing); } else { if ($obj->Albumindex != $fragment) { $singleheader['where'] = 'aalbum' . $obj->Albumindex; $singleheader['type'] = 'insertAfter'; } else { $singleheader['html'] = albumHeader($obj->Albumname, $albumlink, $why . $what . $obj->Albumindex, $exists, $obj->Searched == 1 || $exists == "yes" ? "yes" : "no", $obj->ImgKey, $obj->Image, $obj->Year, null, $artistthing); return $singleheader; } } $count++; } if ($count == 0 && !($why == 'a' && $who == 'root')) { noAlbumsHeader(); } } else { print '<h3>' . get_int_text("label_general_error") . '</h3>'; } return $count; }
function getWishlist() { global $mysqlc, $divtype, $prefs; if ($mysqlc === null) { connect_to_database(); } $qstring = 'SELECT wishlist.*, Ratingtable.Rating FROM (SELECT Tracktable.TTindex AS ttindex, Tracktable.Title AS track, Tracktable.TrackNo AS num, Tracktable.Duration AS time, Tracktable.Disc as disc, Artisttable.Artistname AS artist, Albumtable.Albumname AS album, Albumtable.Image AS image, Albumtable.ImgKey AS imgkey FROM Tracktable JOIN Artisttable USING (Artistindex) JOIN Albumtable ON Tracktable.Albumindex = Albumtable.Albumindex WHERE Uri IS NULL AND Hidden = 0 UNION SELECT Tracktable.TTindex AS ttindex, Tracktable.Title AS track, Tracktable.TrackNo AS num, Tracktable.Duration AS time, Tracktable.Disc as disc, Artisttable.Artistname AS artist, "" AS Albumname, NULL as Image, NULL AS ImgKey FROM Tracktable JOIN Artisttable USING (Artistindex) WHERE Albumindex IS NULL AND Uri IS NULL AND Hidden = 0) AS wishlist LEFT JOIN Ratingtable ON Ratingtable.TTindex = wishlist.ttindex ORDER BY '; foreach ($prefs['artistsatstart'] as $a) { $qstring .= "CASE WHEN LOWER(artist) = LOWER('" . $a . "') THEN 1 ELSE 2 END, "; } if (count($prefs['nosortprefixes']) > 0) { $qstring .= "(CASE "; foreach ($prefs['nosortprefixes'] as $p) { $phpisshitsometimes = strlen($p) + 2; $qstring .= "WHEN LOWER(artist) LIKE '" . strtolower($p) . " %' THEN LOWER(SUBSTR(artist," . $phpisshitsometimes . ")) "; } $qstring .= "ELSE LOWER(artist) END)"; } else { $qstring .= "LOWER(artist)"; } $qstring .= ', LOWER (album), num'; $current_artist = ""; $current_album = ""; $count = 0; if ($result = generic_sql_query($qstring)) { while ($obj = $result->fetch(PDO::FETCH_OBJ)) { $bothclosed = false; debuglog("Found Track " . $obj->track, "WISHLIST"); if ($current_artist != $obj->artist) { if ($current_artist != "") { print '</div></div>'; $bothclosed = true; } $current_artist = $obj->artist; print artistHeader("wishlistartist_" . $count, $obj->artist); print '<div id="wishlistartist_' . $count . '" class="dropmenu ' . $divtype . '">'; $count++; $divtype = $divtype == "album1" ? "album2" : "album1"; } if ($current_album != $obj->album) { if (!$bothclosed && $current_album != "") { print '</div>'; } $current_album = $obj->album; print albumHeader($obj->album, null, 'wishlistalbum_' . $count, $obj->image === null ? "no" : "yes", $obj->album == "" ? "yes" : "no", $obj->imgkey, $obj->image, null, null, null); print '<div id="wishlistalbum_' . $count . '" class="dropmenu">'; $count++; } albumTrack(null, $obj->Rating, null, 0, $obj->num, $obj->track, 0, null, null); } } }