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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
#!/usr/bin/perl
#
# Page.pm:
# Various HTML stuff for the BCI site.
#
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: Page.pm,v 1.25 2006-10-06 15:58:28 matthew Exp $
#
package Page;
use strict;
use Carp;
use CGI::Fast qw(-no_xhtml);
use Error qw(:try);
use mySociety::WatchUpdate;
use mySociety::Web qw(ent NewURL);
sub do_fastcgi {
my $func = shift;
try {
my $W = new mySociety::WatchUpdate();
while (my $q = new CGI::Fast()) {
&$func($q);
$W->exit_if_changed();
}
} catch Error::Simple with {
my $E = shift;
my $msg = sprintf('%s:%d: %s', $E->file(), $E->line(), $E->text());
warn "caught fatal exception: $msg";
warn "aborting";
ent($msg);
print "Status: 500\nContent-Type: text/html; charset=iso-8859-1\n\n",
q(<html><head><title>Sorry! Something's gone wrong.</title></head></html>),
q(<body>),
q(<h1>Sorry! Something's gone wrong.</h1>),
q(<p>Please try again later, or <a href="mailto:team@neighbourhoodfixit.com">email us</a> to let us know.</p>),
q(<hr>),
q(<p>The text of the error was:</p>),
qq(<blockquote class="errortext">$msg</blockquote>),
q(</body></html);
};
}
=item header Q TITLE [PARAM VALUE ...]
Return HTML for the top of the page, given the TITLE text and optional PARAMs.
=cut
sub header ($$%) {
my ($q, $title, %params) = @_;
$title = '' unless $title;
$title .= ' - ' if $title;
my %permitted_params = map { $_ => 1 } qw();
foreach (keys %params) {
croak "bad parameter '$_'" if (!exists($permitted_params{$_}));
}
print $q->header(-charset=>'utf-8');
my $html = <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-gb">
<head>
EOF
# Causes onLoad never to fire in IE...
# <!--[if lt IE 7.]>
# <script defer type="text/javascript" src="/pngfix.js"></script>
# <![endif]-->
$html .= <<EOF;
<link type="text/css" rel="stylesheet" href="/yui/logger.css">
<script type="text/javascript" src="/yui/yahoo-min.js"></script>
<script type="text/javascript" src="/yui/dom-min.js"></script>
<script type="text/javascript" src="/yui/event-min.js"></script>
<script type="text/javascript" src="/yui/animation-min.js"></script>
<script type="text/javascript" src="/yui/dragdrop-min.js"></script>
<script type="text/javascript" src="/yui/logger-min.js"></script>
<script type="text/javascript" src="/js2.js"></script>
<script type="text/javascript" src="/jslib/utils.js"></script>
<title>${title}Neighbourhood Fix-It</title>
<style type="text/css">\@import url("/css.css");</style>
</head>
<body>
EOF
my $home = !$title && $ENV{SCRIPT_NAME} eq '/index.cgi' && !$ENV{QUERY_STRING};
$html .= $home ? '<h1 id="header">' : '<div id="header"><a href="/">';
$html .= 'Neighbourhood Fix-It';
$html .= $home ? '</h1>' : '</a></div>';
$html .= '<div id="wrapper"><div id="content">';
return $html;
}
=item footer
=cut
sub footer {
return <<EOF;
</div></div>
<h2 class="v">Navigation</h2>
<ul id="navigation">
<li><a href="/contact">Contact</a>
<li><a href="/faq">Information</a>
<li><a href="/">Home</a>
</ul>
<p id="footer">Built by <a href="http://www.mysociety.org/">mySociety</a>.
Using lots of <a href="http://www.ordnancesurvey.co.uk/">Ordnance Survey</a> data, under licence.
And some <a href="https://secure.mysociety.org/cvstrac/dir?d=mysociety/bci">very clever code</a>.</p>
</body>
</html>
EOF
}
=item error_page Q MESSAGE
=cut
sub error_page ($$) {
my ($q, $message);
my $html = header($q, "Error")
. $q->p($message)
. footer();
print $q->header(-content_length => length($html)), $html;
}
sub compass ($$$) {
my ($q, $x, $y) = @_;
my @compass;
for (my $i=$x-1; $i<=$x+1; $i++) {
for (my $j=$y-1; $j<=$y+1; $j++) {
$compass[$i][$j] = NewURL($q, x=>$i, y=>$j);
}
}
return <<EOF;
<table cellpadding="0" cellspacing="0" border="0" id="compass">
<tr valign="bottom">
<td align="right"><a href="${compass[$x-1][$y+1]}"><img src="i/arrow-northwest.gif" alt="NW"></a></td>
<td align="center"><a href="${compass[$x][$y+1]}"><img src="i/arrow-north.gif" vspace="3" alt="N"></a></td>
<td><a href="${compass[$x+1][$y+1]}"><img src="i/arrow-northeast.gif" alt="NE"></a></td>
</tr>
<tr>
<td><a href="${compass[$x-1][$y]}"><img src="i/arrow-west.gif" hspace="3" alt="W"></a></td>
<td align="center"><img src="i/rose.gif" alt=""></a></td>
<td><a href="${compass[$x+1][$y]}"><img src="i/arrow-east.gif" hspace="3" alt="E"></a></td>
</tr>
<tr valign="top">
<td align="right"><a href="${compass[$x-1][$y-1]}"><img src="i/arrow-southwest.gif" alt="SW"></a></td>
<td align="center"><a href="${compass[$x][$y-1]}"><img src="i/arrow-south.gif" vspace="3" alt="S"></a></td>
<td><a href="${compass[$x+1][$y-1]}"><img src="i/arrow-southeast.gif" alt="SE"></a></td>
</tr>
</table>
EOF
}
1;
|