use koha rss results to return popup
[google-map-tiles.git] / koha.pl
1 #!/usr/bin/perl
2 # Deliver click values to volcano.htm...
3 # Author. John D. Coryat 02/2010...
4 # Copyright 2010 USNaviguide LLC. All rights reserved...
5
6 use CGI qw/:standard *table/;
7 use strict ;
8 use DBI ;
9 use USNaviguide_Google_Tiles ;
10 use XML::FeedPP;
11
12 my $dbh         = DBI->connect ( "dbi:Pg:dbname=koha" , "" , "" , { AutoCommit => 1 } ) ;
13 my $point       = param('POINT') ;
14 my $zoom        = param('ZOOM') ;
15
16 my $lat         = 0 ;
17 my $lng         = 0 ;
18 my $latpix      = 0 ;
19 my $lngpix      = 0 ;
20
21 my $volpnt      = '' ;
22 my $vlat        = 0 ;
23 my $vlng        = 0 ;
24 my $vlatpix     = 0 ;
25 my $vlngpix     = 0 ;
26
27 my $value       = '' ;
28 my $maxpix      = 15 ;                                  # Maximum pixels between click and point
29 my $name        = '' ;
30 my $descript    = '' ;
31 my $x           = '' ;
32 my $i           = 0 ;
33
34 print qq{Content-type: text/xml\r\n\r\n};
35 print qq{<?xml version="1.0" encoding="UTF-8"?>\n} ;
36 print qq!<map>\n! ;
37
38 if ( !$point )
39 {
40  print qq!<info error="No point passed..."/>\n! ;
41  print qq!</map>\n! ;
42  $dbh->disconnect ;
43  exit ;
44 }
45
46 if ( $point =~ /(.*),(.*)/ )
47 {
48  $lat   = $1 ;
49  $lng   = $2 ;
50
51  $value = &Google_Tile_Factors($zoom) ;                                 # Calculate Tile Factors
52
53  ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ;       # Convert coordinate to pixel location
54  
55  $x = "select name,descript,volpnt,point'($lat,$lng)' <-> volpnt as distance from gvp_world order by distance limit 1" ;
56
57  if ( ($name,$descript,$volpnt,$i) = $dbh->selectrow_array($x) )        # Got one
58  {
59   $volpnt =~ /\((.*),(.*)\)/ ; 
60   $vlat = $1 ;
61   $vlng = $2 ;
62
63   ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ;  # Convert coordinate to pixel location
64
65   if ( sqrt(($vlatpix - $latpix)**2  + ($vlngpix - $lngpix)**2) > $maxpix )
66   {
67    # Click not within maxpix of point...
68    print qq!<info error="No publisher is within range of your click, please try again."/>\n! ;
69   } else                                                                # Good point found
70   {
71
72         my $hash = eval $descript;
73
74         my $feed = XML::FeedPP->new( "http://koha.ffzg.hr/cgi-bin/koha/opac-search.pl?idx=pl&format=rss2&q=$name" );
75
76         my @links;
77         foreach my $item ( $feed->get_item ) {
78                 push @links, sprintf qq|<li><a target="koha" href="%s">%s</a> %s|,
79                         $item->link, $item->title, $item->description
80                 ;
81         }
82         $descript = join("\n"
83                 , "<b>$name</b>"
84                 , " " . @links
85                 , "<ol>"
86                 , @links
87                 , "</ol>"
88         );
89
90    print qq!<info error = "" name = "$name" lat="$vlat" lng="$vlng">\n! ;
91    print qq! <description><\![CDATA[$descript]]></description>\n! ;
92    print qq!</info>\n! ;
93   }
94  }
95 } else
96 {
97  print qq!<info error="No valid point ($point) passed. Should be: (lat,lng) format."/>\n! ;
98 }
99 $dbh->disconnect ;
100
101 print "</map>\n\n" ;
102