custom icons for each zoom level
[google-map-tiles.git] / koha.pl
diff --git a/koha.pl b/koha.pl
index 72f7681..8310329 100755 (executable)
--- a/koha.pl
+++ b/koha.pl
@@ -7,9 +7,8 @@ use CGI qw/:standard *table/;
 use strict ;
 use DBI ;
 use USNaviguide_Google_Tiles ;
-use XML::FeedPP;
 
-my $dbh        = DBI->connect ( "dbi:Pg:dbname=koha" , "" , "" , { AutoCommit => 1 } ) ;
+my $dbh        = DBI->connect ( "dbi:Pg:dbname=koha" , "dpavlin" , "" , { AutoCommit => 1 } ) ;
 my $point      = param('POINT') ;
 my $zoom       = param('ZOOM') ;
 
@@ -26,7 +25,6 @@ my $vlngpix   = 0 ;
 
 my $value      = '' ;
 my $maxpix     = 15 ;                                  # Maximum pixels between click and point
-my $name       = '' ;
 my $descript   = '' ;
 my $x          = '' ;
 my $i          = 0 ;
@@ -52,9 +50,9 @@ if ( $point =~ /(.*),(.*)/ )
 
  ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ;      # Convert coordinate to pixel location
  
- $x = "select name,descript,volpnt,point'($lat,$lng)' <-> volpnt as distance from gvp_world order by distance limit 1" ;
+ $x = "select city,country,count,point,point'($lat,$lng)' <-> point as distance from geo_count order by distance limit 1" ;
 
- if ( ($name,$descript,$volpnt,$i) = $dbh->selectrow_array($x) )       # Got one
+ if ( my ($city,$country,$count,$volpnt,$i) = $dbh->selectrow_array($x) )      # Got one
  {
   $volpnt =~ /\((.*),(.*)\)/ ; 
   $vlat = $1 ;
@@ -69,25 +67,29 @@ if ( $point =~ /(.*),(.*)/ )
   } else                                                               # Good point found
   {
 
-       my $hash = eval $descript;
-
-       my $feed = XML::FeedPP->new( "http://koha.ffzg.hr/cgi-bin/koha/opac-search.pl?idx=pl&format=rss2&q=$name" );
-
-       my @links;
-       foreach my $item ( $feed->get_item ) {
-               push @links, sprintf qq|<li><a target="koha" href="%s">%s</a> %s|,
-                       $item->link, $item->title, $item->description
+       my $sth = $dbh->prepare(qq{
+select
+       author, title, bi.biblionumber
+from geo_city c
+join geo_biblioitems bi on bi.city = c.city_koha
+join biblio b on b.biblionumber = bi.biblionumber
+where c.city = ? and country = ?
+order by timestamp
+limit 100
+       });
+       $sth->execute( $city, $country );
+
+       my $descript = "<b>$city</b> <em>$country</em> $count items\n<ol>";
+
+       while ( my $row = $sth->fetchrow_hashref ) {
+               $descript .= sprintf qq|<li><a target="koha" href="http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=%d">%s</a> %s\n|,
+                       $row->{biblionumber}, $row->{title}, $row->{author}
                ;
        }
-       $descript = join("\n"
-               , "<b>$name</b>"
-               , " " . @links
-               , "<ol>"
-               , @links
-               , "</ol>"
-       );
-
-   print qq!<info error = "" name = "$name" lat="$vlat" lng="$vlng">\n! ;
+
+       $descript .= "\n</ol>\n";
+
+   print qq!<info error=""  name="${city}_${country}" lat="$vlat" lng="$vlng">\n! ;
    print qq! <description><\![CDATA[$descript]]></description>\n! ;
    print qq!</info>\n! ;
   }