X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=koha.pl;h=7e3482190fde7072e000129d402cd69221483580;hb=c75406fc0566fc14eda5033029f3768e7609b8c2;hp=72f7681c40e1f0148bf33cf465228d40bd2635c6;hpb=2daf090e203fd4506a1776f31f0bd79dc89f9e11;p=google-map-tiles.git diff --git a/koha.pl b/koha.pl index 72f7681..7e34821 100755 --- a/koha.pl +++ b/koha.pl @@ -7,29 +7,14 @@ 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') ; -my $lat = 0 ; -my $lng = 0 ; -my $latpix = 0 ; -my $lngpix = 0 ; - -my $volpnt = '' ; -my $vlat = 0 ; -my $vlng = 0 ; -my $vlatpix = 0 ; -my $vlngpix = 0 ; - -my $value = '' ; my $maxpix = 15 ; # Maximum pixels between click and point -my $name = '' ; -my $descript = '' ; -my $x = '' ; -my $i = 0 ; + +my $limit_books = 100; # max. for one click print qq{Content-type: text/xml\r\n\r\n}; print qq{\n} ; @@ -45,22 +30,32 @@ if ( !$point ) if ( $point =~ /(.*),(.*)/ ) { - $lat = $1 ; - $lng = $2 ; + my $lat = $1 ; + my $lng = $2 ; - $value = &Google_Tile_Factors($zoom) ; # Calculate Tile Factors + my $value = &Google_Tile_Factors($zoom) ; # Calculate Tile Factors - ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ; # Convert coordinate to pixel location + my ($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" ; - - if ( ($name,$descript,$volpnt,$i) = $dbh->selectrow_array($x) ) # Got one + my $sql = qq{ +select + city_koha + ,country + ,count + ,point + ,point'($lat,$lng)' <-> point as distance +from geo_count +order by distance +limit 1 + }; + + if ( my ($city,$country,$count,$volpnt,$i) = $dbh->selectrow_array($sql) ) # Got one { $volpnt =~ /\((.*),(.*)\)/ ; - $vlat = $1 ; - $vlng = $2 ; + my $vlat = $1 ; + my $vlng = $2 ; - ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ; # Convert coordinate to pixel location + my ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ; # Convert coordinate to pixel location if ( sqrt(($vlatpix - $latpix)**2 + ($vlngpix - $lngpix)**2) > $maxpix ) { @@ -69,25 +64,38 @@ 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|
  • %s %s|, - $item->link, $item->title, $item->description + my $sth = $dbh->prepare(qq{ +select + author, title, max(bi.biblionumber) as biblionumber, count(title) +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_koha = ? and country = ? +group by author, title +order by min(timestamp) +limit $limit_books + }); + $sth->execute( $city, $country ); + + my $rows = $sth->rows; + if ( $rows == $limit_books ) { + $rows = "more than $rows"; + $rows = $count if $count > $rows; + }; + my $books = 'books'; + $books = 'book' if $rows == 1; + + my $descript = "$city $country $rows $books\n
      "; + + while ( my $row = $sth->fetchrow_hashref ) { + $descript .= sprintf qq|
    1. %s %s\n|, + $row->{biblionumber}, $row->{title}, $row->{author} ; } - $descript = join("\n" - , "$name" - , " " . @links - , "
        " - , @links - , "
      " - ); - - print qq!\n! ; + + $descript .= "\n
    \n"; + + print qq!\n! ; print qq! <\![CDATA[$descript]]>\n! ; print qq!\n! ; }