Skip to content

Commit

Permalink
working on legislators table
Browse files Browse the repository at this point in the history
not going so well
  • Loading branch information
paleomedia committed Apr 6, 2015
1 parent 0e21f29 commit b1a7e85
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 53 deletions.
19 changes: 16 additions & 3 deletions dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class Dao {

public function getConnection () {
return
new PDO("mysql:host={$this->host};dbname={$this->db};port={$this->dbport}", $this->user, $this->pass);
new PDO("mysql:host={$this->host};dbname={$this->db};port={$this->dbport}", $this->user, $this->dbpassword);
}

public function saveComment ($comment) {
$conn = $this->getConnection();
$saveQuery =
"INSERT INTO comment
"INSERT INTO comments
(comment)
VALUES
(:comment)";
Expand All @@ -29,6 +29,19 @@ public function saveComment ($comment) {

public function getComments () {
$conn = $this->getConnection();
return $conn->query("SELECT * FROM comment");
return $conn->query("SELECT * FROM comments");
}

public function saveJson ($data) {
$conn = $this->getConnection();
foreach ($data as $item) {
$saveQuery = "INSERT INTO lawmakers
(first_name, last_name, middle_name, district, party, active, chamber, photo_url)
VALUES(:item['first_name']."', '".$item['last_name']."', '".$item['middle_name']."', '".$item['district']."', '".$item['party']."', '".$item['active']."', '".$item['chamber']."', '".$item['photo_url']."');
$q = $conn->prepare($saveQuery);
$q->bindParam(":item", $item);
$q->execute();
}


} // end Dao
18 changes: 18 additions & 0 deletions handler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
// handler.php
// handle comment posts, saving to MySQL and redirecting back to the list
require_once "Dao.php";

if (isset($_SESSION["name"]) && isset($_POST["commentButton"])) {
$comment = $_POST["comment"];
$comment_type = $_POST["vote"];

try {
$dao = new Dao();
$dao->saveComment($comment);
} catch (Exception $e) {
var_dump($e);
die;
}
}
header("Location:index.php");
43 changes: 20 additions & 23 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
$thisPage = 'Home';

require_once "Dao.php";
$dao = new Dao();
include 'top.php'; ?>

<body>
Expand All @@ -9,17 +10,15 @@

<?php include 'dash.php'; ?>


<div class="billmain">
<div class="active">
<p>Most Active</p>
<div class="billimage"><span>S 1081</span>
</div>
<div class="billimage"><span>S 1081</span></div>
<div class="lastaction">Passed Senate, 2/20/2015</div>
<div class="billsummary">Summary: HEALTH CARE - Amends existing law to provide reserves and surplus requirements of public postsecondary educational institutions with a public postsecondary educational institution plan for health care benefits.</div>
<div class="comments">
<div class="commentbox">
<form>
<form name="commentForm" action="handler.php" method="POST">
<textarea name="comment" rows="4" placeholder="Write comments or testimony here, select pro, neutral or anti, and press Go."></textarea>
<label>Yea or Nay?</label>
<label>
Expand All @@ -30,29 +29,27 @@
<label>
<input type="radio" name="vote" value="anti" /><img class="antilabel" src="images/thumbs_down.png" />
</label>


<input type="submit" value="Go" />
<input type="submit" name="commentButton" value="Comment" />
<input type="hidden" name="form" value="comment">
</form>
</div>
<div class="pro">
<span>Conrad says:</span> Best bill ever ... Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
</div>
<div class="neutral">
<span>Sarah says:</span> Could go either way... Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
</div>
<div class="anti">
<span>José says:</span> Impeach! Impeach! Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
<?php
$comments = $dao->getComments();
echo "<table>";
foreach ($comments as $comment) {
echo "<tr>";
echo "<td>" . $comment["comment"] . "</td>";
# echo "<td>" . $comment["created"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</div>
</div>
</div>

<div class="active">
<!-- <div class="active">
<p>Also Active</p>
<div class="billimage"><span>S 1081</span>
<div class="billimage"><span>S 1082</span>
</div>
<div class="lastaction">Passed Senate, 2/20/2015</div>
<div class="billsummary">Summary: HEALTH CARE - Amends existing law to provide reserves and surplus requirements of public postsecondary educational institutions with a public postsecondary educational institution plan for health care benefits.</div>
Expand Down Expand Up @@ -89,7 +86,7 @@
</div>
</div>

</div>
</div> -->

</div>

Expand Down
53 changes: 50 additions & 3 deletions lawmakers.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
<?php
$thisPage="Lawmakers";
include 'top.php'; ?>
include 'top.php';
require_once "Dao.php"; ?>

<div class="maincontainer">

<?php include 'dash.php'; ?>
<?php include 'dash.php';

/* read the json file contents */

$jsondata = file_get_contents('http://openstates.org/api/v1/legislators/?apikey=bcc2a830883c4f459dbffe94b2a3e90f&state=id');

//convert json object to php associative array
$data = json_decode($jsondata, true);

<?php include 'footer.php'; ?>
/* get the legislator details
// FIXXXXXX extra fields
$suffix = $data['personal']['address']['streetaddress'];
$nickname = $data['personal']['address']['city'];
$website = $data['personal']['address']['postalcode'];
$first_name = $data['first_name'];
$last_name = $data['last_name'];
$middle_name = $data['middle_name'];
$district = $data['district'];
$party = $data['party'];
$active = $data['active'];
$chamber = $data['chamber'];
$photo_url = $data['photo_url'];
$sql = "INSERT INTO lawmakers(first_name, last_name, middle_name, district, party, active, chamber, photo_url)
VALUES('$first_name', '$last_name', '$middle_name', '$district', '$party', '$active', '$chamber', '$photo_url')";
if(!mysql_query($sql,$con))
{
die('Error inserting data: ' . mysql_error());
}
}
VALUES('".$item['first_name']."', '".$item['last_name']."', '".$item['middle_name']."', '".$item['district']."', '".$item['party']."', '".$item['active']."', '".$item['chamber']."', '".$item['photo_url']."');
*/

try {
$dao = new Dao();
} catch (Exception $e) {
var_dump($e);
die;
}

//insert into mysql table
saveJson($data);



include 'footer.php'; ?>
22 changes: 0 additions & 22 deletions login_test.php

This file was deleted.

68 changes: 67 additions & 1 deletion newaccount.php
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
new user account
<?php
$thisPage="New_Account";
include 'top.php'; ?>

<div class="maincontainer">

<div class="dashboard">
<div class="dashhead" id="dashtop">
Legislative Dash
</div>

<div class="dashhead" id="login">Create new account</div>
<div class="loginbox">
<form action="newuser.php" method="POST">
<div class="loginbox">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="email" name="email" id="email" placeholder="Email" />
<input type="password" name="password" id="password" placeholder="Password">
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" />
<input type="text" name="username" id="username" placeholder="Username" />
</div>
<input type="submit" value="Go">
</form>
</div>
</div>

<div class="billmain">
<div class="active">
<p>Most Active</p>
<div class="billimage"><span>S 1081</span></div>
<div class="lastaction">Passed Senate, 2/20/2015</div>
<div class="billsummary">Summary: HEALTH CARE - Amends existing law to provide reserves and surplus requirements of public postsecondary educational institutions with a public postsecondary educational institution plan for health care benefits.</div>
<div class="comments">
<div class="commentbox">
<form>
<textarea name="comment" rows="4" placeholder="Write comments or testimony here, select pro, neutral or anti, and press Go."></textarea>
<label>Yea or Nay?</label>
<label>
<input type="radio" name="vote" value="pro" /><img class="prolabel" src="images/thumbs_up.png" />
</label>
<label class="neutrallabel">
<input type="radio" name="vote" value="neutral" />?</label>
<label>
<input type="radio" name="vote" value="anti" /><img class="antilabel" src="images/thumbs_down.png" />
</label>
<input type="submit" value="Go" />
</form>
</div>
<div class="pro">
<span>Conrad says:</span> Best bill ever ... Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
</div>
<div class="neutral">
<span>Sarah says:</span> Could go either way... Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
</div>
<div class="anti">
<span>José says:</span> Impeach! Impeach! Lorem ipsum dolor sit amet, nobis suavitate iracundia ei his, ad nihil eirmod quo, viris temporibus qui eu. Et idque omnes instructior usu, qui ut posse everti lobortis, id his deserunt assentior.
Quo oratio senserit te, verterem constituto usu ut. Te pro aeque equidem maluisset, ponderum consetetur sea no. At volutpat torquatos adipiscing est, tempor temporibus in cum.
</div>
</div>
</div>
</div>
</div>

<?php include 'footer.php'; ?>
2 changes: 1 addition & 1 deletion users.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ function redirect($url, $flash_message = NULL) {

function new_user($name, $password, $user_info) {
$db = new PDO("mysql:host=127.0.0.1;port=8889;dbname=idleg_test", "root", "root");

}
?>

0 comments on commit b1a7e85

Please sign in to comment.