#!/usr/bin/perl require strict; require DBI; require CGI; my $query = CGI::new(); my $section = $query->param('section'); my $AlbumID = $query->param('albumid'); my $ArtistID = $query->param('artistid'); my $SongID = $query->param('songid'); my $By = $query->param('by'); my $albumsearch = $query->param('albumsearch'); my $bandsearch = $query->param('bandsearch'); my $lyricsearch = $query->param('lyricsearch'); my $songsearch = $query->param('songsearch'); my $dbh = DBI->connect("DBI:mysql:database=music;host=loke","sql-query","",{'RaiseError' => 0}); my $Script = $ENV{'SCRIPT_NAME'}; &CheckQuery; &PrintPage; sub CheckQuery { unless(($ArtistID) || ($AlbumID)) { unless ($section) { $section = "Main"; } # unless() } # unless() else { unless($section) { $section = "Search"; } # unless() } # else() if(($albumsearch) || ($bandsearch) || ($lyricsearch) || ($songsearch)) { $section = "Search"; } # if() } # CheckQuery() sub CheckDBConn { if(!$sth) { &error("\"$dbh->errstr\""); } # if() else { if(!$sth->execute) { &error("\"$sth->errstr\""); } # if() else { return(1); } # else() } # else() return(0); } # sub CheckDBConn() sub error { print "
"; print @_; print "
","\n"; return(0); } # sub error() sub PrintPage { print "Content-type: text/html","\n\n"; print "","\n"; print '',"\n"; print "","\n"; print "| ',"\n"; print ''; print "Home"; print "","\n"; print " "," "; print ''; print "Browse"; print "","\n"; if($section eq "Show") { if($ArtistID) { print " "," "; print ''; print "List all albums by this artist"; print "","\n"; } # if() if($AlbumID) { $sth = $dbh->prepare (" SELECT artistid FROM album WHERE id = \"$AlbumID\" "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print " "," "; print ''; print "List all albums by this artist"; print "","\n"; } # while() } # if() } # unless() print " | "; print "
';
print "
";
print "
| ',"\n";
print ' '; print "Powered by: Apache and MySQL"; print " ","\n"; print ''; print "All songs, albums, lyrics and art: "; print '©'; print " the respective band"," ","\n"; print ''; print '© '; print ''; print "Daniel Lysfjord"; print ""; print " ","\n"; print " | ";
print "
',"\n";
print ''; print ''; print $$ref{'artistname'}; print ""; print "","\n"; print ''; print $$ref{'albumname'}; print "","\n"; print " | ","\n";
if($SongID) {
print '',"\n"; &GetLyrics; } # if() print " |
|---|---|
| ',"\n";
print ' ';
print " ';
print " | ","\n";
print "|
| ',"\n";
print " ","\n"; print $$ref{'lineup'},"\n"; print " ","\n"; print " | ","\n";
print "
";
print '';
print "
'; if($$ref{'track'} < 10) { print "0"; } # if() print $$ref{'track'}; print " - "; print ''; print $$ref{'songname'}; print ""; print "
","\n"; } # while() } # GetTracks() sub GetLyrics { $sth = $dbh->prepare (" SELECT name, lyrics FROM song WHERE id = \"$SongID\" "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print '"; print $$ref{'lyrics'}; print "
"; print "\n"; } # if() else { print ""; print "No Lyrics found."; print "
","\n"; } # else() } # while() } # GetLyrics() sub PrintBandInfo { $sth = $dbh->prepare (" SELECT id, name, logo, info, homepage FROM artist WHERE id = \"$ArtistID\" "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { unless($$ref{'logo'} eq "") { print '| ',"\n";
print ' | ";
print "
| ","\n";
unless($$ref{'info'} eq "") {
print " "; print $$ref{'info'}; print " ","\n"; } # unless() else { print ""; print "No Info available.."; print " ","\n"; } print " | ";
print "
","\n"; print "Search for bands (freetext):","\n"; print "
","\n"; print '","\n"; print "","
","\n";
print "Search for albums (freetext):","\n";
print "
","
","\n";
print "Search for songs (freetext):","\n";
print "
","
","\n";
print "Search for lyrics (freetext):","\n";
print "
","
","\n";
print "Wildcard is : %";
print "
"; print 'If you have to use " somewhere in the search write it like this '; print '\"'; print "
","\n"; print ""; print "The Database contains :","\n"; print &RecordCount("artist"); print " artists, ","\n"; print &RecordCount("album"); print " albums, ","\n"; print &RecordCount("song"); print " songs where ","\n"; print &RecordCount('song WHERE lyrics != ""'); print " has lyrics.","\n"; print "
","\n"; } # Search() sub RecordCount { my $rows; $sth = $dbh->prepare (" SELECT COUNT(*) FROM @_ "); &CheckDBConn; $rows = $sth->fetchrow(); $sth->finish(); return $rows; } sub Browse { $sth = $dbh->prepare (" SELECT name, id, homepage FROM artist ORDER BY name "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print ''; print ''; print $$ref{'name'}; print ""; print " - "; print ''; print "List all albums"; print ""; unless($$ref{'homepage'} eq "") { print " - "; print ''; print "Homepage"; print ""; } # unless() print "
","\n"; } # while() } # Browse() sub AlbumsByArtistList { $sth = $dbh->prepare (" SELECT album.id AS albumid, album.name AS albumname, album.artistid AS artistid, artist.name AS artistname FROM album, artist WHERE album.artistid = \"$ArtistID\" AND artist.id = \"$ArtistID\" ORDER BY album.name, artist.name "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print ""; print ''; print $$ref{'artistname'}; print " - "; print $$ref{'albumname'}; print ""; print "
","\n"; my $cnt = $cnt ++; } # while() print ''; print "Found "; print $cnt; print " albums."; print "
","\n"; } # AlbumsByArtistSearch() sub AlbumSearch { print ''; print "'Searching..."; print "
","\n"; $sth = $dbh->prepare (" SELECT album.id AS albumid, album.name AS albumname, album.artistid AS albumartistid, artist.id AS artistid, artist.name AS artistname FROM album,artist WHERE (album.name like \"%$albumsearch%\" AND artist.id = album.artistid) OR (artist.name like \"%albumsearch%\" AND album.artistid = artist.id) ORDER BY artist.name, album.name "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print ""; print ''; print $$ref{'artistname'}; print " - "; print $$ref{'albumname'}; print ""; print "
","\n"; my $cnt = $cnt ++; } # while() print ''; print "Search done...Found "; print $cnt; print " albums matching your search."; print "
","\n"; } # TextSearch() sub BandSearch { print ''; print "Searching..."; print "
","\n"; $sth = $dbh->prepare (" SELECT id, name, homepage FROM artist WHERE name like \"%$bandsearch%\" ORDER BY name "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print ''; print ''; print $$ref{'name'}; print ""; print " - "; print ''; print "List all albums"; print ""; unless($$ref{'homepage'} eq "") { print " - "; print ''; print "Homepage"; print ""; } # unless() print "
","\n"; my $cnt = $cnt ++; } # while() print ''; print "Search done...Found "; unless($cnt) { print "no"; } # unless() print $cnt; print " artists matching your search."; print "
","\n"; } # BandSearch() sub LyricSearch { print ''; print "Searching..."; print "
","\n"; $sth = $dbh->prepare (" SELECT song.lyrics AS songlyrics, song.albumid AS albumid, song.name AS songname, song.id AS songid, song.track AS track, album.name AS albumname, artist.name AS artistname FROM song, album, artist WHERE lyrics like \"%$lyricsearch%\" AND album.id = song.albumid AND artist.id = album.artistid ORDER BY artist.name, album.name, song.track "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print "","\n"; my $cnt = $cnt ++; } # while() print ''; print "Search done...Found "; unless($cnt) { print "no"; } # unless() print $cnt; print " songs with lyrics matching your search."; print "
","\n"; } # LyricSearch() sub SongSearch { print ''; print 'Searching...'; print "
","\n"; $sth = $dbh->prepare ("SELECT song.albumid AS albumid, song.name AS songname, song.id AS songid, album.name AS albumname, artist.name AS artistname, song.track AS track FROM song, album, artist WHERE song.name like \"%$songsearch%\" AND album.id = song.albumid AND artist.id = album.artistid ORDER BY artist.name, album.name, song.track "); &CheckDBConn; while(my $ref = $sth->fetchrow_hashref) { print "","\n"; my $cnt = $cnt ++; } # while() print ''; print "Search done...Found "; unless($cnt) { print "no"; } # unless() print $cnt; print " songs matching your search."; print "
","\n"; } # SongSearc;