2 # Deliver click values to volcano.htm...
3 # Author. John D. Coryat 02/2010...
4 # Copyright 2010 USNaviguide LLC. All rights reserved...
6 use CGI qw/:standard *table/;
9 use USNaviguide_Google_Tiles ;
11 my $dbh = DBI->connect ( "dbi:Pg:dbname=koha" , "dpavlin" , "" , { AutoCommit => 1 } ) ;
12 my $point = param('POINT') ;
13 my $zoom = param('ZOOM') ;
15 my $maxpix = 15 ; # Maximum pixels between click and point
17 my $limit_books = 100; # max. for one click
19 print qq{Content-type: text/xml\r\n\r\n};
20 print qq{<?xml version="1.0" encoding="UTF-8"?>\n} ;
25 print qq!<info error="No point passed..."/>\n! ;
31 if ( $point =~ /(.*),(.*)/ )
36 my $value = &Google_Tile_Factors($zoom) ; # Calculate Tile Factors
38 my ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ; # Convert coordinate to pixel location
46 ,point'($lat,$lng)' <-> point as distance
52 if ( my ($city,$country,$count,$volpnt,$i) = $dbh->selectrow_array($sql) ) # Got one
54 $volpnt =~ /\((.*),(.*)\)/ ;
58 my ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ; # Convert coordinate to pixel location
60 if ( sqrt(($vlatpix - $latpix)**2 + ($vlngpix - $lngpix)**2) > $maxpix )
62 # Click not within maxpix of point...
63 print qq!<info error="No publisher is within range of your click, please try again."/>\n! ;
64 } else # Good point found
67 my $sth = $dbh->prepare(qq{
69 author, title, max(bi.biblionumber) as biblionumber, count(title)
71 join geo_biblioitems bi on bi.city = c.city_koha
72 join biblio b on b.biblionumber = bi.biblionumber
73 where c.city_koha = ? and country = ?
74 group by author, title
75 order by min(timestamp)
78 $sth->execute( $city, $country );
80 my $rows = $sth->rows;
81 if ( $rows == $limit_books ) {
82 $rows = "more than $rows";
83 $rows = $count if $count > $rows;
86 $books = 'book' if $rows == 1;
88 my $descript = "<b>$city</b> <em>$country</em> <small>$rows $books</small>\n<ol>";
90 while ( my $row = $sth->fetchrow_hashref ) {
91 $descript .= sprintf qq|<li><a target="koha" href="http://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=%d">%s</a> %s\n|,
92 $row->{biblionumber}, $row->{title}, $row->{author}
96 $descript .= "\n</ol>\n";
98 print qq!<info error="" name="${city}_${country}" lat="$vlat" lng="$vlng">\n! ;
99 print qq! <description><\![CDATA[$descript]]></description>\n! ;
100 print qq!</info>\n! ;
105 print qq!<info error="No valid point ($point) passed. Should be: (lat,lng) format."/>\n! ;