-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcongress.php
More file actions
508 lines (317 loc) · 16.5 KB
/
Copy pathcongress.php
File metadata and controls
508 lines (317 loc) · 16.5 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<HTML><HEAD>
<style>
p {
margin: 0;
padding: 0;
}
table{
border-collapse: collapse;
padding: 20px;
}
td{ width: 600px;
height: 20px;
}
.center {
margin: auto;
width: 50%;
padding: 20px;
}
</style>
<TITLE> Congress Information Search </TITLE></HEAD>
<BODY class ="center" >
<!-- THIS IS THE INITIAL FORM WHICH ALWAYS REMAINS AT THE TOP OF THE PAGE
THE OPTIONS SELECTED REMAIN SELECTED, UNLESS THE CLEAR BUTTON IS USED
OUTPUT IS DISPLAYED BELOW THIS INITIAL FORM........
-->
<H2>           Congress Information Search</H2>
<FORM METHOD="POST" ACTION="" id ="myForm" name="myForm" onsubmit="return validateMyForm();" >
<table border="1" align="center" width ="300px" style="margin-left: 200px;"><td>
Congress Database <SELECT id = 'opts' name="opts" >
<OPTION value="Select your option"> Select your option </option>
<OPTION value="legislators"> Legislators </option>
<OPTION value ="committees"> Committees </option>
<OPTION value ="bills"> Bills </option>
<OPTION value ="amendments"> Amendments </option>
</SELECT>
<!-- retain values -->
<script type="text/javascript">
document.getElementById('opts').value = "<?php echo $_POST['opts'];?>";
</script>
<!-- retain values -->
<br>  Chamber   <INPUT type=radio id='amount1' name= "senate/house" value= "senate"
<?php if (isset($_POST["senate/house"]) && $_POST["senate/house"] == "senate") { echo " checked = checked";} ?> > Senate </Input>
<INPUT type=radio id='amount2' name = "senate/house" value= "house" <?php if (isset($_POST["senate/house"]) && $_POST["senate/house"] =="house" )
{echo "checked = checked";} ?> > House </Input>
<!-- retain values -->
</br><span id ='keyword'> Keyword*   </span>
<INPUT type = "text" name= "Keyword*" id= 'Keyword*' value= "<?php echo isset($_POST["Keyword*"]) ? $_POST["Keyword*"] : "" ?>" > </INPUT></br>
<SCRIPT LANGUAGE="JavaScript">
//this is so keyword will have multiple options.........
//........depending upon dropdown menu
// works before form submit, upon change of dropdown menu.......
//select is pulldown option
select = document.getElementById('opts');
thisForm = document.myForm;
//vars to validate form......
keywrd = document.getElementById('Keyword*'); //amount1 amount2 Keyword*
amnt1 = document.getElementById('amount1');
amnt2 = document.getElementById('amount2');
function keyWord(){
if(select.value == "Select your option"){
document.getElementById('keyword').innerHTML="Keyword*   ";
}
else if(select.value =="legislators"){
document.getElementById('keyword').innerHTML="State/Representative*";
}
else if(select.value == "committees"){
document.getElementById('keyword').innerHTML="Committee ID*   ";
}
else if(select.value == "bills"){
document.getElementById('keyword').innerHTML="Bill ID*     ";
}
else if(select.value == "amendments"){
document.getElementById('keyword').innerHTML="Amendment ID*    ";
}
};
select.addEventListener('change', keyWord, false );
//function returnToPreviousPage() {
//window.history.back();
//actually just stay on current page.....
//}
//this function validates the form information
//upon submittal.....................
function validateMyForm()
{
var o ="";
var k =".";
var a ="";
if(select.value == "Select your option"){
o = "Congress Database, ";
}
if(keywrd.value ==""){
k ="keyword. ";
}
if(!amnt1.checked && !amnt2.checked){
a =" chamber, ";
}
if(select.value == "Select your option" || keywrd.value =="" || (amnt1.checked && amnt2.checked))
{
alert("Please enter the following missing information :" +o +a +k );
return false;
}
return true;
}
</script>
<!-- Continue form......submit -->
         <INPUT type="submit" name= "FORMsubmit" value="Search">
<INPUT type="button" id = "clear" value ="Clear"/>
<!-- function to clear the form with clear button -->
<br> <a href = "http://www.sunlightfoundation.com"> Powered By Sunlight Foundation </a><br>
</td></table>
<!-- End of initial form -->
<!-- This is called if form is submitted.... first time
Will display first table below form depending upon form options selected
Supportype is not yet set.... is for the second call back to the server -->
<p id ="outs1">
<?php if(isset($_POST["FORMsubmit"]) && !isset($_POST["supporttype"]) ): ?>
<table align="center" width = "700px"><td>
<!-- if statements to call script for committes/bills/amendments, in of the below script for legislators-->
<?php if( $_POST["opts"]== "committees" ): ?>
<?php include("/home/scf-09/jschnall/apache2/htdocs/Committees.php") ?>
<?php elseif( $_POST["opts"]== "bills" ): ?>
<?php include("/home/scf-09/jschnall/apache2/htdocs/Bills1.php") ?>
<?php elseif( $_POST["opts"]== "amendments" ): ?>
<?php include("/home/scf-09/jschnall/apache2/htdocs/Amendments.php") ?>
<?php else :?>
<?php
//Retrieve API json data using form input values........
//API Key: 52bf01e9cad0422c8e3c1faa809ad959
//parse form values for url
$formVals = array();
foreach($_POST as $key => $value) { //array of form values excluding submit button
if ($key != "submit") {
array_push($formVals,$value);
//print_r($formVals." ".$value);//DEBUG
}
}
//Call state keymap to get state abreviation........
$states = array("Alabama" => "AL", "Montana" => "MT", "Alaska" => "AK", "Nebraska" => "NE", "Arizona" => "AZ", "Nevada" => "NV",
"Mississippi" => "MS", "Wyoming" => "WY", "Missouri" => "MO", "Wisconsin" => "WI", "Minnesota" => "MN","West Virginia" => "WV",
"Michigan" => "MI", "Washington" => "WA", "Massachusetts" => "MA", "Virginia" => "VA", "Maryland" => "MD", "Vermont" => "VT", "Maine" => "ME",
"Louisiana" => "LA", "Tennessee" => "TN", "Kentucky" => "KY", "Utah" => "UT", "Texas" => "TX", "Kansas" => "KS", "South Dakota" => "SD",
"Iowa" => "IA", "South Carolina" => "SC", "Indiana" => "IN", "Rhode Island" => "RI", "Illinois" => "IL", "Pennsylvania" => "PA",
"Idaho" => "ID", "Oregon" => "OR", "Hawaii" => "HI", "Oklahoma" => "OK", "Georgia" => "GA", "Ohio" => "OH", "Florida" => "FL",
"North Dakota" => "ND", "District Of Columbia" => "DC", "North Carolina" => "NC", "Deleware" => "DE", "New York" => "NY",
"Connecticut" => "CT", "New Mexico" => "NM", "Colorado" => "CO", "New Jersey" => "NJ", "California" => "CA", "Arkansas" => "AR", "New Hampshire" => "NH");
//call url and get json object
//will be different for each drop down option
$url ="";
if( array_key_exists($formVals[2] , $states) ){
$stAbr = $states[$formVals[2]];
$url= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&state=" . $stAbr . "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
}else{
$stAbr = $formVals[2];
$url="http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&query=" . $stAbr . "&apikey=52bf01e9cad0422c8e3c1faa809ad959";
}
//$GLOBALS = array('state' => "");
//$GLOBALS['state'] = clone $states[$formVals[2]]; //make this global so can be used later
//$url= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&state=" . $stAbr . "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
$content = file_get_contents($url);
//load json object using json_decode........
$json = json_decode($content, true);
//write out html table....... columns are Name/State/Chamber/Details(links)
//....first put data into associative array.....
$nameRay = array();
$stateRay = array();
$chamberRay = array();
$detailsRay = array();
$legisTable = array( "Name" =>$nameRay , "State" =>$stateRay , "Chamber" =>$chamberRay , "Details"=>$detailsRay );
foreach($json['results'] as $item) {
array_push($legisTable["Name"], $item['first_name'] . " " . $item['last_name']);
array_push($legisTable["State"], $item['state_name']) ;
array_push($legisTable["Chamber"], $item['chamber']) ;
array_push($legisTable["Details"], $item['bioguide_id']);
}
?>
<!-- this creates a new form input type for the inital form, once this first table is displayed
will make it so that form will be resubmitted upon clicking bio link in the first table created -->
<input type="hidden" name="supporttype" id= "bioguide" />
<Script LANGUAGE="javascript">
function bioguide(idnum){
thisForm.supporttype.value = idnum; //get idnumber from link clicked on
thisForm.submit(); //resubmit form with old values and now this id number......
}
</script>
<!-- This is the php output for the first table created.....
which contains the links which resubmit the form using the input type hidden above -->
<?php
if(empty($json['results'])){
echo " <br> <br>            
        The API returned zero results for the request";
}else{
$i = 0;
echo "<br><br><table border ='2'><tbody>";
echo "<th>Name</th>";
echo "<th>State</th>";
echo "<th>Chamber</th>";
echo "<th>Details</th>";
foreach ($legisTable["Name"] as $row) {
echo "<tr>";
echo "<td> " . $legisTable["Name"][$i] . " </td>";
echo "<td> " . $legisTable["State"][$i] . " </td>";
echo "<td> " . $legisTable["Chamber"][$i] . " </td>";
$temp = $legisTable["Details"][$i];
echo "<td> " . "<a href= \"javascript:bioguide('".$temp."')\" > View Details</a>" . " </td>";
echo "</tr>";
$i = $i + 1;
}
echo "</tbody></table>";
}
?>
<?php endif; ?>
<?php endif; ?>
</p>
<!-- This PHP is called after the first table is created......
if there is now a hidden option to submit the form a second time, using supportype input in form -->
<p id = "outs2">
<?php if(isset($_POST["supporttype"])): ?>
<br><br>
<table align="center" border = "1" width = "500"><td>
<!-- if Bills is called as oposed to legislators below -->
<?php if( $_POST["opts"] == "bills"): ?>
<?php include("/home/scf-09/jschnall/apache2/htdocs/Bills2.php") ?>
<?php else: ?>
<?php
//create new table based on bioguide id
/*https://congress.api.sunlightfoundation.com/legislators?chamber=house&state=WA&bioguide_id=N000189&apikey=YOUR_API_KEY_HERE
*/
$formVals = array();
foreach($_POST as $key => $value) {
if ($key != "submit") {
array_push($formVals,$value);
}
}
//get idnum
foreach($_POST as $key => $value) {
if ($key == "supporttype") {
$idnum = $value;
}
}
//create new API call link
$states = array("Alabama" => "AL", "Montana" => "MT", "Alaska" => "AK", "Nebraska" => "NE", "Arizona" => "AZ", "Nevada" => "NV",
"Mississippi" => "MS", "Wyoming" => "WY", "Missouri" => "MO", "Wisconsin" => "WI", "Minnesota" => "MN","West Virginia" => "WV",
"Michigan" => "MI", "Washington" => "WA", "Massachusetts" => "MA", "Virginia" => "VA", "Maryland" => "MD", "Vermont" => "VT", "Maine" => "ME",
"Louisiana" => "LA", "Tennessee" => "TN", "Kentucky" => "KY", "Utah" => "UT", "Texas" => "TX", "Kansas" => "KS", "South Dakota" => "SD",
"Iowa" => "IA", "South Carolina" => "SC", "Indiana" => "IN", "Rhode Island" => "RI", "Illinois" => "IL", "Pennsylvania" => "PA",
"Idaho" => "ID", "Oregon" => "OR", "Hawaii" => "HI", "Oklahoma" => "OK", "Georgia" => "GA", "Ohio" => "OH", "Florida" => "FL",
"North Dakota" => "ND", "District Of Columbia" => "DC", "North Carolina" => "NC", "Deleware" => "DE", "New York" => "NY",
"Connecticut" => "CT", "New Mexico" => "NM", "Colorado" => "CO", "New Jersey" => "NJ", "California" => "CA", "Arkansas" => "AR", "New Hampshire" => "NH");
$urlnew ="";
if( array_key_exists($formVals[2] , $states) ){
$stAbr = $states[$formVals[2]];
//$url= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&state=" . $stAbr . "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
$urlnew= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&state=" . $stAbr . "&bioguide_id=" .$idnum. "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
}else{
$stAbr = $formVals[2];
//$url="http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&query=" . $stAbr . "&apikey=52bf01e9cad0422c8e3c1faa809ad959";
$urlnew= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&query=" . $stAbr . "&bioguide_id=" .$idnum. "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
}
//$stAbr = $states[$formVals[2]];
//$urlnew= "http://congress.api.sunlightfoundation.com/" . $formVals[0]. "?chamber=" . $formVals[1] . "&state=" . $stAbr . "&bioguide_id=" .$idnum. "&apikey=52bf01e9cad0422c8e3c1faa809ad959" ;
//print_r($urlnew); //DEBUG
//call for json
$content1 = file_get_contents($urlnew);
//load json object using json_decode........
$json1 = json_decode($content1, true);
//print_r($json1) ; DEBUG
//write out html table....... columns are Name/State/Chamber/Details(links)
//....first put data into associative array.....
$bioTable = array( "Image" => "" , "Name" => "" , "Term" => "" , "Website"=> "",
"Office" => "", "Facebook" => "", "Twitter" => "");
foreach($json1['results'] as $item) {
$bioTable["Name"] = $item['first_name'] . " " . $item['last_name'] ;
$bioTable["Image"]= $item["bioguide_id"];
//https://theunitedstates.io/images/congress/225x275/bioguide_id.jpg
$bioTable["Term"] = $item["term_end"];
$bioTable["Website"]= $item['website'];
$bioTable["Office"] = $item['office'];
$bioTable["Facebook"]= $item['facebook_id'];
//https://www.facebook.com/facebook_id
$bioTable["Twiter"]= $item['twitter_id'] ;
//https://www.twitter,com/twitter_id
}
//$i = 0;
echo "<br><br><table align =\"center\" width = 650px><tbody>";
echo "<center><img src=" . " \"http://theunitedstates.io/images/congress/225x275/" . $bioTable["Image"]. ".jpg\" " . " width = 220 height = 200 ></center>" ; //person image
echo "<center><tr><td> Full Name </td> <td align =\"right\"> " . $bioTable["Name"] . " </td></tr></center>";
echo "<center><tr><td> Term ends on </td> <td align =\"right\">" . $bioTable["Term"] . " </center></td></tr></center>";
echo "<center><tr><td> Website </td> <td align =\"right\">" . "<a href=\" " . $bioTable["Website"] . "\">". $bioTable["Website"]."<a/>". "</center></td></tr></center>";
echo "<center><tr><td> Office </td> <td align =\"right\">" . $bioTable["Office"] . " </center></td></tr></center>";
echo "<center><tr><td> Facebook </td> <td align =\"right\">" . "<a href=\"//https://www.facebook.com/". $bioTable["Facebook"] ."\">" .$bioTable["Name"] . "<a/>" . "</td></tr></center>";
echo "<center><tr><td> Twitter </td> <td align =\"right\">" . "<a href=\"//https://www.twitter.com/". $bioTable["Twitter"] ."\">" .$bioTable["Name"] . "<a/>" . "</td></tr></center>";
//$i = $i + 1;
echo "</tbody></table>";
?>
<?php endif; ?>
<?php endif; ?>
</p>
</td></table>
<script Language ="Javascript" >
var clear = document.getElementById("clear"); //id
var form = document.getElementById("myForm"); //id
function clearfield() {
form.reset();
//alert(document.getElementById('Keyword*').value);
document.getElementById('Keyword*').value ='';
//document.getElementById('amount1').removeAttr('checked');
//document.getElementById('amount2').removeAttr('checked');
//alert("HERE");
document.getElementById("outs1").innerHTML = ""; //document.body.removeChild
document.getElementById("outs2").innerHTML ="";
//return false;
}
clear.addEventListener("click", clearfield, false);
</Script>
</FORM>
</BODY>
</HTML>