aboutsummaryrefslogtreecommitdiffstats
path: root/web/ajax.cgi
blob: a25269070e905d742e14f2b8396aa3c685e6c191 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# #!/usr/bin/perl -w -I../perllib
# 
# # ajax.cgi:
# # Updating the pins as you drag the map
# #
# # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# # Email: matthew@mysociety.org. WWW: http://www.mysociety.org
# #
# # $Id: ajax.cgi,v 1.19 2009-12-15 17:53:52 louise Exp $
# 
# use strict;
# use Standard;
# use mySociety::Web qw(ent NewURL);
# 
# sub main {
#     my $q = shift;
# 
#     my @vars = qw(x y sx sy all_pins);
#     my %input = map { $_ => $q->param($_) || '' } @vars;
#     my %input_h = map { $_ => $q->param($_) ? ent($q->param($_)) : '' } @vars;
# 
#     # Our current X/Y middle of visible map
#     my $x = $input{x};
#     my $y = $input{y};
#     $x ||= 0; $x += 0;
#     $y ||= 0; $y += 0;
# 
#     # Where we started as that's the (0,0) we have to work to
#     my $sx = $input{sx};
#     my $sy = $input{sy};
#     $sx ||= 0; $sx += 0;
#     $sy ||= 0; $sy += 0;
# 
#     my $interval;
#     unless ($input{all_pins}) {
#         $interval = '6 months';
#     }
#     my ($pins, $on_map, $around_map, $dist) = FixMyStreet::Map::map_pins($q, $x, $y, $sx, $sy, $interval);
#     my $cobrand = Page::get_cobrand($q);
#     my $list = '';
#     my $link = '';
#     foreach (@$on_map) {
#         $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, 
#                                                   -url => '/report/' . $_->{id}, 
#                                                   pc => undef, 
#                                                   x => undef, 
#                                                   y => undef, 
#                                                   sx => undef, 
#                                                   sy => undef, 
#                                                   all_pins => undef, 
#                                                   no_pins => undef), $q);  
#         $list .= '<li><a href="' . $link . '">';
#         $list .= ent($_->{title}) . '</a> <small>(';
#         $list .= Page::prettify_epoch($q, $_->{time}, 1) . ')</small>';
#         $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed';
#         $list .= '</li>';
#     }
#     my $om_list = $list;
# 
#     $list = '';
#     foreach (@$around_map) {
#         my $dist = int($_->{distance}*10+.5)/10;
#         $link = Cobrand::url($cobrand, NewURL($q, -retain => 1, 
#                                                   -url => '/report/' . $_->{id}, 
#                                                   pc => undef, 
#                                                   x => undef, 
#                                                   y => undef, 
#                                                   sx => undef, 
#                                                   sy => undef, 
#                                                   all_pins => undef, 
#                                                   no_pins => undef), $q);  
#         $list .= '<li><a href="' . $link . '">';
#         $list .= ent($_->{title}) . '</a> <small>(';
#         $list .= Page::prettify_epoch($q, $_->{time}, 1) . ', ';
#         $list .= $dist . 'km)</small>';
#         $list .= ' <small>' . _('(fixed)') . '</small>' if $_->{state} eq 'fixed';
#         $list .= '</li>';
#     }
#     my $am_list = $list;
# 
#     #$list = '';
#     #foreach (@$fixed) {
#     #    $list .= '<li><a href="/report/' . $_->{id} . '">';
#     #    $list .= $_->{title} . ' <small>(' . int($_->{distance}*10+.5)/10 . 'km)</small>';
#     #    $list .= '</a></li>';
#     #}
#     #my $f_list = $list;
# 
#     # For now, assume this is not cacheable - may need to be more fine-grained later
#     print $q->header(-charset => 'utf-8', -content_type => 'text/javascript', -Cache_Control => 'max-age=0');
#   
# 
#     $pins =~ s/'/\\'/g;
#     $om_list =~ s/'/\\'/g;
#     $am_list =~ s/'/\\'/g;
#     #$f_list =~ s/'/\\'/g;
#     print <<EOF;
# ({
# 'pins': '$pins',
# 'current': '$om_list',
# 'current_near': '$am_list'
# })
# EOF
# }
# 
# Page::do_fastcgi(\&main);
#