Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 402 lines (359 sloc) 15.451 kB
e0cbced putting in designated voter into a division page
goatchurch authored
1 <?php
6381c58 Stuff found on live
publicwhip authored
2 # $Id: decodeids.inc,v 1.50 2011/03/20 14:43:34 publicwhip Exp $
e0cbced putting in designated voter into a division page
goatchurch authored
3
4 # The Public Whip, Copyright (C) 2005 Francis Irving and Julian Todd
5 # This is free software, and you are welcome to redistribute it under
6 # certain conditions. However, it comes with ABSOLUTELY NO WARRANTY.
7 # For details see the file LICENSE.html in the top level of the source.
8
0153919 Change over from include/require/include_once to require_once
frabcus authored
9 require_once $toppath . "parliaments.inc";
10 require_once $toppath . "postcode.inc";
e0cbced putting in designated voter into a division page
goatchurch authored
11 require_once $toppath . "wiki.inc";
12 require_once $toppath . "links.inc";
13
14 # this maps all constituency names to numbers
15 require_once $toppath . "constituencies.inc";
16
17 # get the constituency and names to use from an mpid
18 # mpgen says the equivalence class is by constituency or by person
19 function get_mpid_attr($db, $db2, $mpid, $bbyconstituency, $i, $voter2dream_overlap)
20 {
21 global $bdebug;
22 # convert the mpid into a person-id
23 $query = "SELECT title, first_name, last_name, constituency, person, party, house, mp_id
24 FROM pw_mp
25 WHERE mp_id = $mpid";
26
27 if ($bdebug == 1)
28 print "<h1>getmpattr: $query</h1>\n";
29 $row = $db->query_one_row_assoc($query);
30
31 # build the anchor tag
32 $mpname = $row['title'].' '.$row['first_name'].' '.$row['last_name'];
33 $constituency = $row['constituency'];
34 $person = $row['person'];
35 $party = $row['party'];
7445437 Lots more MP/Lords detail fixes
publicwhip authored
36 $house = $row['house'];
e0cbced putting in designated voter into a division page
goatchurch authored
37
38 # get the mpids in this class, for the person, or all reps of a constituency
39 if ($bbyconstituency)
2174d5a The canonical form of the Scottish Parliament constituencies uses " a…
marklon authored
40 $qwhere = "constituency = '".db_scrub($constituency)."' AND house = '".db_scrub($house)."'";
e0cbced putting in designated voter into a division page
goatchurch authored
41 else
42 $qwhere = "person = $person";
43
97ed2cc upgrade the links on the mp pages
goatchurch authored
44 $qselect = "pw_mp.mp_id AS mpid, title, first_name, last_name, constituency, person, party, house,
e0cbced putting in designated voter into a division page
goatchurch authored
45 entered_house, left_house, party, entered_reason, left_reason,
46 rebellions, votes_attended, votes_possible, tells";
47 $query = "SELECT $qselect
48 FROM pw_mp
49 LEFT JOIN pw_cache_mpinfo ON pw_mp.mp_id = pw_cache_mpinfo.mp_id
50 WHERE $qwhere
51 ORDER BY entered_house DESC";
52 if ($bdebug == 1)
53 print "<h1>decode person: $query</h1>\n";
54 $row = $db->query($query);
55
56 # build a set of data for each mpid in this group
57 $mpids = array();
58 $mpprops = array();
59 $bmultiperson = false; # record if this set really does cover more than one person
a729f77 editing in windows because vim is too unreliable.
goatchurch authored
60 $bmulithouse = false;
7445437 Lots more MP/Lords detail fixes
publicwhip authored
61 $thismpprop = null;
a729f77 editing in windows because vim is too unreliable.
goatchurch authored
62 $minentered_house = "9999-12-31";
e0cbced putting in designated voter into a division page
goatchurch authored
63 while ($row = $db->fetch_row_assoc())
64 {
65 $mppropname = trim($row['title'].' '.$row['first_name'].' '.$row['last_name']);
66 $mppropanchor = link_to_mp($row, 1);
67 $mppropanchor2 = link_to_mp($row, 2);
68 $mpprop = array("mpid" => $row['mpid'],
69 "title" => $row['title'],
70 "name" => $mppropname,
71 "person" => $row['person'],
72 "party" => $row['party'],
73 "constituency" => $row['constituency'],
97ed2cc upgrade the links on the mp pages
goatchurch authored
74 "house" => $row['house'], # appeared to be missing
e0cbced putting in designated voter into a division page
goatchurch authored
75 "mpanchor" => $mppropanchor,
76 "mpanchor2" => $mppropanchor2,
7e542b0 fix parliament selection on MP page, fix wrong ministerial markups fo…
publicwhip authored
77 "parliament" => date_to_parliament($row["entered_house"]),
e0cbced putting in designated voter into a division page
goatchurch authored
78 "enteredhouse" => $row['entered_house'],
79 "lefthouse" => $row['left_house'],
80 "enteredreason" => $row['entered_reason'],
81 "leftreason" => $row['left_reason'],
82 "rebellions" => $row['rebellions'],
83 "votesattended" => $row['votes_attended'],
84 "votespossible" => $row['votes_possible'],
97ed2cc upgrade the links on the mp pages
goatchurch authored
85 "tells" => $row['tells']);
86 if ($row['house'] == 'commons')
87 {
88 $mpprop['housenamesuffix'] = 'MP';
89 $mpprop['housenoun'] = 'MP';
2cf31e1 changes in wordings, links in policy comparisons
publicwhip authored
90 $mpprop['housenounplural'] = 'MPs';
97ed2cc upgrade the links on the mp pages
goatchurch authored
91 $mpprop['fullname'] = "$mppropname MP, ".$row['constituency'];
92 }
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
93 elseif ($row['house'] == 'scotland')
94 {
95 $mpprop['housenamesuffix'] = 'MSP';
96 $mpprop['housenoun'] = 'MSP';
97 $mpprop['housenounplural'] = 'MSPs';
98 $mpprop['fullname'] = "$mppropname MSP, ".$row['constituency'];
99 }
97ed2cc upgrade the links on the mp pages
goatchurch authored
100 else
101 {
102 $mpprop['housenamesuffix'] = '';
7445437 Lots more MP/Lords detail fixes
publicwhip authored
103 $mpprop['housenoun'] = 'Lord';
935eb05 Lots of text fix ups for Lords
publicwhip authored
104 $mpprop['housenounplural'] = 'Lords';
97ed2cc upgrade the links on the mp pages
goatchurch authored
105 $mpprop['fullname'] = $mppropname;
106 }
e0cbced putting in designated voter into a division page
goatchurch authored
107
108 # check for an over-lap with the dreammp
109 if ($voter2dream_overlap)
110 {
111 $query = "SELECT vote FROM pw_dyn_dreamvote
112 WHERE division_date >= \"".$row['entered_house']."\" AND division_date < \"".$row['left_house']."\"
113 AND dream_id = ".$voter2dream_overlap['dreammpid']."
114 LIMIT 1";
115 if ($bdebug)
116 print "<h1>$query</h1>\n";
117 $row2 = $db2->query_onez_row_assoc($query);
118 if ($row2 == null)
119 continue;
120 }
121
122 if ($bdebug == 1)
123 {
7445437 Lots more MP/Lords detail fixes
publicwhip authored
124 print "<h4>prop:";
e0cbced putting in designated voter into a division page
goatchurch authored
125 print_r($mpprop);
7445437 Lots more MP/Lords detail fixes
publicwhip authored
126 print "</h4>\n";
e0cbced putting in designated voter into a division page
goatchurch authored
127 }
128
129 array_push($mpprops, $mpprop);
130 if (($mpprop['mpid'] == $mpid) || ($thismpprop == null)) # recover the original mp, or the most recent
131 $thismpprop = $mpprop;
5a0605b more work
publicwhip authored
132 if (($mpprop['person'] == $thismpprop["person"])) # && ($minentered_house == "9999-12-31"))
9a2f674 pass back to windows
publicwhip authored
133 $minentered_house = $mpprop['enteredhouse'];
e0cbced putting in designated voter into a division page
goatchurch authored
134
135 array_push($mpids, $row['mp_id']);
136 if ($person != $row['person'])
137 $bmultiperson = true;
7445437 Lots more MP/Lords detail fixes
publicwhip authored
138 if ($house != $row['house'])
a729f77 editing in windows because vim is too unreliable.
goatchurch authored
139 $bmultihouse = true;
e0cbced putting in designated voter into a division page
goatchurch authored
140 }
141
142 if ($bdebug == 1)
143 print "<h1>$mpname, $constituency, multiperson:".($multiperson ? "yes" : "no")."</h1>\n";
144
145 return array("mpprops" => $mpprops,
146 "mpprop" => $thismpprop,
a729f77 editing in windows because vim is too unreliable.
goatchurch authored
147 "minentered_house" => $minentered_house,
7445437 Lots more MP/Lords detail fixes
publicwhip authored
148 "bmultiperson" => $bmultiperson,
149 "bmultihouse" => $bmultihouse);
e0cbced putting in designated voter into a division page
goatchurch authored
150 }
151
152 # this is used for getting mpids from links prior to 2005-03
153 function decode_mpid_legacy($db)
154 {
155 global $bdebug;
156
157 $id = db_scrub($_GET["id"]);
158 if ($id != "")
159 {
160 # value from theyworkforyou
161 if (stristr($id, "uk.org.publicwhip/member/"))
162 return str_replace("uk.org.publicwhip/member/", "", $id);
163 if ($bdebug == 1)
164 print "<h1>unrecognized id=$id";
165 return null;
166 }
167
168 # For a while we allowed this style for MPs
169 $mpurlid = db_scrub($_GET["mpid"]);
170 if ($mpurlid) {
171 # By identifier directly
172 $mpid = $mpurlid;
dd651de Cope with links in to Lords from TWFY
publicwhip authored
173 $query = "SELECT mp_id FROM pw_mp WHERE gid='uk.org.publicwhip/member/".$mpurlid."'
174 or gid='uk.org.publicwhip/lord/".$mpurlid."'";
e0cbced putting in designated voter into a division page
goatchurch authored
175 $row = $db->query_one_row_assoc($query);
176 return db_scrub($row["mp_id"]);
177 }
178
179 # get the name and constituency
180 $constituency = $_GET["constituency"];
181 if ($constituency == "")
182 return null;
183 $constituency = strtolower(stripslashes(html_entity_decode($constituency)));
184 $constituency = normalise_constituency_name($db, $constituency);
185 $constituency = db_scrub($constituency);
186 $first_name = db_scrub($_GET["firstname"]);
187 $last_name = db_scrub($_GET["lastname"]);
188 if ($bdebug == 1)
189 print "<h1> FN=$first_name LN=$last_name CO=$constituency</h1>";
190
f412270 Slightly improve legacy decode ids
theyworkforyou authored
191 $qwhere = "WHERE ";
192 if ($constituency)
193 $qwhere .= "constituency = '$constituency'";
194 else
195 $qwhere .= "1 = 1";
e0cbced putting in designated voter into a division page
goatchurch authored
196 if ($first_name != "")
197 $qwhere .= " AND first_name = '$first_name' AND last_name = '$last_name'";
198
199 $query = "SELECT mp_id
200 FROM pw_mp
201 $qwhere
202 ORDER BY entered_house DESC LIMIT 1";
203 $row = $db->query_one_row_assoc($query);
204 $id = db_scrub($row["mp_id"]);
205 return $id;
206 }
207
208
209 # returns the ith mpid from the link (0th is blank)
109f821 Kind of fix up election.php, use two postcode lookup.
frabcus authored
210 # pc_parl is parliament to do any postcode lookup in (default = current)
211 function get_mpid_attr_decode($db, $db2, $i, $voter2dream_overlap=null, $pc_parl=null)
e0cbced putting in designated voter into a division page
goatchurch authored
212 {
213 global $bdebug;
214
215 $mpname = db_scrub($_GET["mpn$i"]);
216 $mpconstituency = db_scrub($_GET["mpc$i"]);
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
217 $mphouse = db_scrub($_GET["house$i"]);
e0cbced putting in designated voter into a division page
goatchurch authored
218 $mppostcode = db_scrub($_GET["mppc$i"]);
219 if ($bdebug == 1)
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
220 print "<h1> MPN=".html_scrub($mpname)." MPC=".html_scrub($mpconstituency)." MPPC=".html_scrub($mppostcode)." HOUSE=".html_scrub($mphouse)."</h1>";
e0cbced putting in designated voter into a division page
goatchurch authored
221
222 if (is_postcode($mppostcode)) {
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
223 $pccons = postcode_to_constituency($db, $mppostcode, $pc_parl, $mphouse);
e0cbced putting in designated voter into a division page
goatchurch authored
224 if (isset($pccons)) {
225 $mpconstituency = $pccons;
226 }
227 }
228
6381c58 Stuff found on live
publicwhip authored
229 # fix incoming broken link
230 if ($mpname == "Robert_Wilson")
231 $mpname = "Rob_Wilson";
232
e0cbced putting in designated voter into a division page
goatchurch authored
233 if ($mpname == "" and $mpconstituency == "")
234 {
235 if ($i != "") # legacy doesn't apply to second and third entries which may be blank
236 return null;
237 $mpid = decode_mpid_legacy($db);
238 if ($mpid == null)
239 return null;
240 $bbyconstituency = false;
241 }
242
243 # this is stable for one or both matching labels being present
244 # hard case is two mps in same constituency at different times with same name
245
246 # extract the constituency
247 else
248 {
249 $qwhere = "";
250 if ($mpconstituency != "" && $mpconstituency != "Lords")
251 {
252 $constituency = strtolower(stripslashes(html_entity_decode($mpconstituency)));
253 $constituency = str_replace("_", " ", $constituency);
2174d5a The canonical form of the Scottish Parliament constituencies uses " a…
marklon authored
254 $constituency = normalise_constituency_name($db, $constituency, $mphouse);
e0cbced putting in designated voter into a division page
goatchurch authored
255 $constituency = db_scrub($constituency);
256 if ($constituency == "")
257 {
258 print "Error, constituency " . $mpconstituency . " not found";
259 exit;
260 }
d3c3a89 Formatting change
frabcus authored
261 $qwhere = "constituency = '$constituency'";
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
262 if ($mphouse=='scotland') {
263 $qwhere .= " and house = 'scotland'";
264 } elseif ($mphouse=='commons') {
265 $qwhere .= " and house = 'commons'";
266 }
e0cbced putting in designated voter into a division page
goatchurch authored
267 }
268 if ($mpname != "")
269 {
270 if ($qwhere != "")
271 $qwhere .= " and ";
272 $mpname = str_replace("_", " ", $mpname);
273 $qwhere .= "('$mpname' = CONCAT(first_name, ' ', last_name)";
274 $qwhere .= " OR '$mpname' = CONCAT(title, ' ', first_name, ' ', last_name))";
275 }
276
277 $query = "SELECT mp_id
278 FROM pw_mp
279 WHERE $qwhere
280 ORDER BY entered_house
281 DESC LIMIT 1";
282 $row = $db->query_one_row($query);
283 $mpid = db_scrub($row[0]);
284 $bbyconstituency = ($mpname == "");
285 }
286
287 return get_mpid_attr($db, $db2, $mpid, $bbyconstituency, $i, $voter2dream_overlap);
288 }
289
290 # do the attributes for a dream mp
291 function get_dreammpid_attr_decode($db, $i)
292 {
1448acc allows all cross-over pages to be reached
goatchurch authored
293 $dreammpid = db_scrub($_GET[($i == "id" ? $i : "dmp$i")]); # so we can choose to look for id= instead of dmp=
59dafa7 debugged policy.php
publicwhip authored
294 if ($dreammpid == "" && $i == "id")
295 $dreammpid = db_scrub($_POST[$i]);
e0cbced putting in designated voter into a division page
goatchurch authored
296 if ($dreammpid == "")
297 return null;
1f7916c Fix injection.
publicwhip authored
298 $dreammpid = intval($dreammpid);
1448acc allows all cross-over pages to be reached
goatchurch authored
299 $qselect = "SELECT pw_dyn_dreammp.name AS name, pw_dyn_dreammp.description AS description,
300 pw_dyn_user.user_id AS user_id, user_name,
301 votes_count, edited_motions_count,
302 private";
303 $qfrom = " FROM pw_dyn_dreammp";
304 $qjoin = " LEFT JOIN pw_cache_dreaminfo ON pw_cache_dreaminfo.dream_id = pw_dyn_dreammp.dream_id";
305 $qjoin .= " LEFT JOIN pw_dyn_user ON pw_dyn_user.user_id = pw_dyn_dreammp.user_id";
306 $qwhere = " WHERE pw_dyn_dreammp.dream_id = $dreammpid";
307 $query = $qselect.$qfrom.$qjoin.$qwhere;
308
e0cbced putting in designated voter into a division page
goatchurch authored
309 $row = $db->query_one_row_assoc($query);
310 $dmp_name = $row[0];
311
312 return array("dreammpid" => $dreammpid,
313 "name" => $row['name'],
314 "description" => $row['description'],
1448acc allows all cross-over pages to be reached
goatchurch authored
315 "userid" => $row['user_id'],
e0cbced putting in designated voter into a division page
goatchurch authored
316 "user_name" => $row['user_name'],
1448acc allows all cross-over pages to be reached
goatchurch authored
317 "private" => $row['private'],
318 "votes_count" => $row['votes_count'],
319 "edited_count" => $row['edited_motions_count'],
e0cbced putting in designated voter into a division page
goatchurch authored
320 "anchor" => "dmp$i=".urlencode($dreammpid));
321 }
322
c2a1bb4 a division list for lords should be functional
goatchurch authored
323 # do the attributes for a division listing, use defaults when $i is set
e0cbced putting in designated voter into a division page
goatchurch authored
324 function get_division_attr_decode($db, $i)
325 {
326 global $bdebug;
327 $div_date = db_scrub($_GET["date$i"]);
328 $div_no = db_scrub($_GET["number$i"]);
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
329 $div_house = db_scrub($_GET["house$i"]);
c2a1bb4 a division list for lords should be functional
goatchurch authored
330 if (!$div_house)
331 $div_house = "commons";
e0cbced putting in designated voter into a division page
goatchurch authored
332 if (!$div_date and $i != "")
333 $div_date = db_scrub($_GET["date"]);
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
334 if (!$div_date or ($div_no != 0 && !$div_no))
e0cbced putting in designated voter into a division page
goatchurch authored
335 return none;
336
337 $query = "SELECT division_date, division_number, house,
338 pw_division.division_id AS division_id,
339 division_name, motion, notes,
340 source_url, debate_url, source_gid, debate_gid,
ab14db4 make slab work for policy comparisons
publicwhip authored
341 rebellions, turnout, aye_majority, clock_time
e0cbced putting in designated voter into a division page
goatchurch authored
342 FROM pw_division
343 LEFT JOIN pw_cache_divinfo
344 ON pw_cache_divinfo.division_id = pw_division.division_id
c2a1bb4 a division list for lords should be functional
goatchurch authored
345 WHERE division_date = '$div_date' AND division_number = '$div_no' AND house = '$div_house'";
e0cbced putting in designated voter into a division page
goatchurch authored
346
347 # warning error shows up from this line if in debug since it comes before the first characters that set the type in head.inc
348 if ($bdebug == 1)
349 print "<h5>$query</h5>";
2f604fc Print error message when division not found
theyworkforyou authored
350 $row = $db->query_onez_row_assoc($query);
351 if (!$row)
0587ff5 Sort by clock time and display it
publicwhip authored
352 return "none";
e0cbced putting in designated voter into a division page
goatchurch authored
353
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
354 $house_paramter = "";
355 if ($row['house'] == "lords") {
356 $house_parameter = "&house=lords";
357 } elseif ($row['house'] == "scotland") {
358 $house_parameter = "&house=scotland";
359 }
360
e0cbced putting in designated voter into a division page
goatchurch authored
361 return array("division_date" => $row["division_date"],
362 "division_number" => $row['division_number'],
363 "house" => $row['house'],
364 "division_id" => $row['division_id'],
365 "prettydate" => date("j M Y", strtotime($row["division_date"])),
749c4bd two division tables better work
goatchurch authored
366 "parliament" => date_to_parliament($row["division_date"]),
e0cbced putting in designated voter into a division page
goatchurch authored
367 "name" => $row["division_name"],
368 "debate_url" => $row["debate_url"],
369 "source_url" => $row["source_url"],
370 "debate_gid" => $row["debate_gid"],
371 "source_gid" => $row["source_gid"],
372 "rebellions" => $row["rebellions"],
373 "turnout" => $row["turnout"],
ab14db4 make slab work for policy comparisons
publicwhip authored
374 "aye_majority" => $row["aye_majority"],
0587ff5 Sort by clock time and display it
publicwhip authored
375 "clock_time" => $row["clock_time"],
25ee5a3 Changes required to support the Scottish Parliament as well
marklon authored
376 "divhref" => "division.php?date=".urlencode($row["division_date"])."&number=".urlencode($row["division_number"]).$house_parameter,
e0cbced putting in designated voter into a division page
goatchurch authored
377 "original_motion" => $row["motion"]);
378 }
59de258 Tooltips on second tier navigation.
frabcus authored
379
ab14db4 make slab work for policy comparisons
publicwhip authored
380 function dismodes_to_second_links($thispage, $dismodes, $tpsort, $display)
381 {
59de258 Tooltips on second tier navigation.
frabcus authored
382 $second_links = array();
383 foreach ($dismodes as $ldisplay => $ldismode)
384 {
e482aa0 have been building backlink technology
publicwhip authored
385 # hack to avoid dangling dmps
386 if ($ldisplay == "alldreams")
387 $thispage = preg_replace("/&dmp=\d+/", "", $thispage);
388
59de258 Tooltips on second tier navigation.
frabcus authored
389 $dlink = $thispage.($ldisplay == "summary" ? "" : "&display=$ldisplay").$tpsort;
68ba927 Make second level navigation use proper parameters list
frabcus authored
390 array_push($second_links, array(
391 'tooltip' => $ldismode["tooltip"],
392 'current' => ($ldisplay == $display ? "on" : "off"),
393 'href' => $dlink,
394 'text' => $ldismode["description"]));
59de258 Tooltips on second tier navigation.
frabcus authored
395 }
396 if (count($second_links) <= 1)
397 return array();
398 return $second_links;
399 }
400
e0cbced putting in designated voter into a division page
goatchurch authored
401 ?>
Something went wrong with that request. Please try again.