Hi,
I've had a go at implementing a simple search facility for
obsequim. My first effort is attached as search.pl, and should be placed
in the cgi-bin directory of the source tree. The diff will update the
install-www.pl script and top.html.
Let me know what you think. It's a bit rudimentary, but it fills a
gap.
Rob
--
\ Robert Hart
___\______ [EMAIL PROTECTED]
/ ^ \_]======] http://www.nott.ac.uk/~enxrah
____[##########\_____
/ ___________________ \ 15 Benington Drive
\/{oOOOOOOOOOOOOOOOo}\/ Wollaton
\o%%%%%%%%%%%%%%%o/ Nottingham
~~~~~~~~~~~~~~~~~ NG8 2TF
#!/usr/bin/perl
#____________________________________________________________________________
#
# Obsequeium -- the Internet MP3 Jukebox
#
# Copyright (C) 1998 Robert Kaye
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: album.pl,v 1.7 2001/09/09 01:03:31 robert Exp $
#____________________________________________________________________________
use CGI;
use DBI;
use Obs::Defs;
use strict;
sub SecsToTimeString
{
my $time=pop @_;
my ($secs, $mins, $hours, $days);
$secs=$time % 60;
$mins=int($time/60) % 60;
$hours=int($time/3600) % 24;
$days=int($time/24/3600);
if ($secs<10){ $secs="0$secs"; }
if ($hours && $mins < 10){ $mins="0$mins"; }
if ($hours) {
$hours="$hours:"; }
else {
$hours=""; }
if ($days>1) {
$days="$days days "; }
elsif ($days==1) {
$days="1 day ";}
else {
$days=""; }
return "$days$hours$mins\:$secs";
}
my $o;
my $num_tracks;
my ($i, $searchword);
my ($dbh, $sth, $rv);
my $sched = 0;
$o = new CGI;
$searchword = $o->param('search');
print $o->header();
print $o->start_html(-title=>'Search Results',
-text=>'#FFFFFF',
-bgcolor=>'#000000',
-link=>'#FF0000',
-vlink=>'#E00000',
-alink=>'#FFFF00');
print "\n";
print $o->start_form(-action=>'search.pl');
print "\nSearch:";
print "<input name=\"search\" type=text size=15 value=\"$searchword\">";
print "<input type=\"\Submit\" value=\"Go\">\n";
print $o->end_form() . "\n";
if ($searchword eq "") {
print $o->end_html();
exit;
}
$dbh = DBI->connect(Obs::Defs::DSN,Obs::Defs::DB_USER,Obs::Defs::DB_PASSWD);
if (!$dbh)
{
print "<font size=+1 color=red>Sorry, the database is currently ";
print "not available. Please try again in a few minutes.</font>";
print "(Error: ",$DBI::errstr,")";
print $o->end_html();
exit;
}
print "<table border=0 cellpadding=1 cellspacing=2 width=100%>\n";
print "<tr><td colspan=2> </td></tr>\n";
print "<tr><td colspan=2 bgcolor=\"#cccccc\" align=right>";
print '<font face="helvetica" color="red" size=2>';
print "Artists</font><br></td></tr>\n";
$sth = $dbh->prepare("select id, name from Artist where " .
"name LIKE \"%$searchword%\" order by name");
if ($sth->execute())
{
my @row;
for(;@row = $sth->fetchrow_array;)
{
print "<tr><td bgcolor=white width=16 height=16>";
print "<a target=albums href=\"album.pl?show=";
print $row[0] . "\">";
print "\n\t<img src=\"/obs/images/quest.gif\" border=0 ";
print 'alt="View albums by this artist"></a>';
print "</td><td bgcolor=white width=100%>";
print "\n\t<font face=\"helvetica\" color=black link=black size=2>";
if (Obs::Defs::IsAdmin)
{
print "<a target=playlist href=";
print "\"editartist.pl?artist=$row[0]\">";
}
print $o->escapeHTML($row[1]);
if (Obs::Defs::IsAdmin)
{
print "</a>";
}
print "</td></tr>\n";
}
$sth->finish;
}
print "</table>\n<table border=0 cellpadding=1 cellspacing=2 width=100%>\n";
print "<tr><td colspan=3> </td></tr>\n";
print '<tr><td colspan=3 bgcolor="#cccccc" align=right>';
print '<font face="helvetica" color="red" size=2>';
print "Tracks</font><br></td></tr>\n";
$sth = $dbh->prepare("select id, name, length from Track where " .
"name like \"%$searchword%\" order by name");
if ($sth->execute())
{
my @row;
my $i;
for(;@row = $sth->fetchrow_array;)
{
print "<tr><td bgcolor=white width=16 height=16>";
print '<a target=playlist href="playlist.pl?add=';
print $row[0] . "\">\n\t";
print "<img src=\"/obs/images/add.gif\" border=0 ";
print "alt=\"Add track to playlist\"></a>";
print "</td>\n\t<td bgcolor=white width=100%>";
print '<font face="helvetica" color=black link=black size=2>';
if (Obs::Defs::IsAdmin)
{
print "<a target=playlist href=";
print "\"edittrack.pl?track=$row[0]\">";
}
print $o->escapeHTML($row[1]);
if (Obs::Defs::IsAdmin)
{
print "</a>";
}
print "</td>\n\t<td bgcolor=white width=40><font " .
"face=\"helvetica\" color=black link=black size=2>";
print SecsToTimeString($row[2] / 10) . "</font>";
print "</td></tr>\n";
}
$sth->finish();
}
print "</table>\n<table border=0 cellpadding=1 cellspacing=2 width=100%>\n";
print "<tr><td colspan=3> </td></tr>\n";
print "<tr><td colspan=3 bgcolor=\"#cccccc\" align=right>";
print '<font face="helvetica" color="red" size=2>';
print "Albums</font><br></td></tr>\n";
$sth = $dbh->prepare("select id, name, artist from Album where " .
"name LIKE \"%$searchword%\" order by name");
if ($sth->execute())
{
my @row;
for(;@row = $sth->fetchrow_array;)
{
print "<tr><td bgcolor=white width=16 height=16>";
print "<a target=albums href=\"album.pl?show=";
print $row[2] . "\">";
print "\n\t<img src=\"/obs/images/quest.gif\" border=0 ";
print 'alt="View albums by this artist"></a></td>';
print "\n\t<td bgcolor=white width=16 height=16>";
print '<a target=playlist href="playlist.pl?add_album';
print "=$row[0]\">\n\t<img src=\"/obs/images/add.gif\" border=0 ";
print "alt=\"Add this Album\"></a>\n";
print "</td><td colspan=2 bgcolor=white width=100%>";
print "\n\t<font face=\"helvetica\" color=black link=black size=2>";
print $o->escapeHTML($row[1]);
print "</td></tr>\n";
}
$sth->finish;
}
print "</table>\n";
print $o->end_html;
if ($dbh)
{
$dbh->disconnect();
}
Index: install-www.pl
===================================================================
RCS file: /src/repository/obs/install-www.pl,v
retrieving revision 1.17
diff -u -r1.17 install-www.pl
--- install-www.pl 2000/07/13 17:41:24 1.17
+++ install-www.pl 2001/09/12 17:18:04
@@ -63,6 +63,7 @@
newlist.pl
playlist.pl
history.pl
+search.pl
toptracks.pl
);
@@ -71,6 +72,7 @@
artist.pl admin/artist.pl
listsel.pl admin/listsel.pl
playlist.pl admin/playlist.pl
+search.pl admin/search.pl
djr/artist.pl djr/admin/artist.pl
djr/djrandom.pl djr/admin/djrandom.pl
djr/newset.pl djr/admin/newset.pl
Index: www/top.html
===================================================================
RCS file: /src/repository/obs/www/top.html,v
retrieving revision 1.4
diff -u -r1.4 top.html
--- www/top.html 2001/07/19 03:10:55 1.4
+++ www/top.html 2001/09/12 17:18:04
@@ -28,6 +28,10 @@
<A HREF="/cgi-bin/obs/history.pl" target="albums">History</A>
</TD>
<TD>
+ <A HREF="/cgi-bin/obs/search.pl" target="albums">Search</A>
+ </TD>
+
+ <TD>
<A HREF="help.html" target="_parent">
Help
</A>