MyWFP Candidate Finder
Find candidates with the WFP “Seal of Approval” where you live:
/**
* @author: bill.eberle@gmail.com
*
* TODO: Figure out county/borough issue.
* "Each borough is coextensive with a respective county of New York State"
* New York City equals counties of: Manhattan, Brooklyn, Queens, Bronx, Richmond
**/
// by default, show form.
if (empty($_POST)) {
showForm();
} else {
validateForm();
}
/** Oops! We couldn’t find that address. Make sure you - If you’re still experiencing a problem, you can search for candidates from a list by region, or contact us at clenchner2@workingfamiliesparty.org. } Please fill out all form fields and try again. “; Our Process: In the spring hundreds of our members from across the state get together to screen candidates seeking our endorsement. More than 1600 applied, from Montauk to Niagara Falls. Our Issues: We asked each candidate about the most important issues facting working families: housing, jobs, transportation, sustainability, education and social services. Our Choices: No candidate is perfect. But we’ve made the commitment to researching each one, learning about their record and personal philosophy. When it comes to picking the best choices for middle-class and working families – no one beats the Working Families Party. EOT; } /** if (strlen($_POST['address']) < 1 || // look for a matching record in the voter table $result = mysql_query($sql, $link); if (mysql_num_rows($result) == 0) { // list of all matching candidates, to be sorted later. // 1. NYC // 2. candidate.JurisdictionCountyFips equals voter.CountyFips // 3. if candidate.JurisdictionTownCity equals voter.Township // 4. ALBANY RULE // 5. NYC RULE // 6. if candidate.LD equals voter.District2 // send data to Salsa /** We aren’t endorsing anyone in your voting district. Thank you for taking the time to use MyWFP, the Working Families candidate finder. Please help us get the word out by telling your friends to use MyWFP to find good candidates where they live. “; //echo “
“; echo(“
WFP ENDORSED CANDIDATES WHERE YOU LIVE: \n”); $candidateText = ”; echo(“ showDisclaimer(); function showDisclaimer() EOT; echo << We’ll keep you posted with election updates. Thank you for using MyWFP. EOT; /** Everyone who cares about a better New York deserves to find out who Working Families is endorsing in their area. And you can help. Take one more minute to tell others about the WFP endorsement finder.
EOT; /** $db_selected = mysql_select_db($dbConnectionData['database'], $link); } /** $post_data['organization_KEY'] = $salsa['organization_KEY']; foreach ( $post_data as $key => $value) { //create the final string to be posted using implode() //create cURL connection //set options //set data to be posted //perform our request //close the connection /** ?>
* Display HTML form to the user
**/
function showForm($condition=null)
{
if ($condition == 'fail') {
echo <<
EOT;
if ($condition == ‘validation’) {
echo “
}
echo <<
* Attempt to match address to voter record; voter record to candidates.
* If no match can be made, return form and prompt user to re-enter address.
**/
function validateForm()
{
$buroughs = array(‘005′,’047′,’061′,’081′,’085′);
$link = connectToDatabase();
strlen($_POST['zip']) < 5 ||
strlen($_POST['email']) < 1) {
showForm('validation');
exit();
}
// matches postal address and breaks out into appropriate pieces
// index 1: number
// index 3: predirectional
// index 4: street name
// index 5: street type
// index 7: street postdirectional
$addressRegex = '/([0-9\-]+)( (E|N|S|W|NE|SW|NW|SE))* ([a-zA-Z0-9 ]+) (ST|AVE|RD|PL|DR|LN|BLVD|CT|PARK|PKWY|CRES|LOOP|OVAL|EXPY|WAY|TRL|TER|SQ|EST|CP|CRSE|CIR|PLZ|TPKE|FWY|LK|FT|PT|BR|GDNS|KNL|RUN|SPG|RDG|XING|HTS|BND|MDWS|EXT|IS|FRK|HOLW|PATH|HL|PASS|STA|GRV|VW|MNR|SHR|CV|CRK|HLS|HWY|GRN|GLN|WALK|BRK|BCH|RTE|MDW|MLS|ROW|VLG|ESTS|MALL|LF|SPUR|ANX|LNDG|PNES|RST|VLY|PLNS|FLD|HBR|CMN|FLS|BRG|ALY|LCK|CRST|VIS|KNLS|SHRS|CLFS|TRCE|HVN|CTR|FRST|CURV|BLF|XRD|TRAK|CLB|INLT|CTS|CORS|RIV|DM|LDG|WL|ISLE|TRLR|ARC|ORCH|UPAS|BTM|MEWS|MT|GDN|COR|CMNS|BLFS|NCK|GRNS|BYP|PIKE|VL|FLDS|DL|ML|MTN|FLT|RUE|CLF|UN|PNE|PSGE|WLS)( (E|N|S|W|NE|SW|NW|SE))*/';
$_POST['address'] = preg_replace('/\./', '', $_POST['address']);
//echo $_POST['address']."
\n”;
preg_match($addressRegex,strtoupper($_POST['address']),$matches);
$sql = “SELECT * FROM `voter_temp` WHERE
RegAddrStreetNum = ‘”.$matches[1].”‘ AND
RegAddrPredirectional = ‘”.$matches[3].”‘ AND
RegAddrStreetName = ‘”.$matches[4].”‘ AND
RegAddrStreetType = ‘”.$matches[5].”‘ AND
RegAddrPostdirectional = ‘”.$matches[7].”‘ AND
RegAddrZip like ‘”.mysql_real_escape_string($_POST['zip']).”%’”;
if (!$result) {
fatalError( “Could not successfully run voter query from DB: “);
}
showForm(‘fail’);
exit();
}
$voter = mysql_fetch_assoc($result);
$candidates = array();
if (in_array($voter['CountyFips'],$buroughs)) {
$sql = “SELECT * FROM `candidate_temp` WHERE JurisdictionCounty = ” AND CandidateCounty =””;
//echo(“1: $sql
\n”);
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
//echo(“{$row['Title']}
“);
if(preg_match(‘/Mayor/i’,$row['Title']) ) {
$row['ordinal'] = 11;
} elseif(preg_match(‘/Public Advocate/i’,$row['Title']) ) {
$row['ordinal'] = 12;
} elseif(preg_match(‘/City Comptroller/i’,$row['Title']) ) {
$row['ordinal'] = 13;
} else {
$row['ordinal'] = 14;
}
$row['type']=’city’;
$candidates[$row['rowID']] = $row;
}
}
$sql = “SELECT * FROM `candidate_temp` WHERE JurisdictionCountyFips = ‘{$voter['CountyFips']}’ AND ( LD = ‘0′ OR LD is NULL )”;
//echo(“2: $sql
\n”);
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
//echo(“{$row['Title']}
“);
if(preg_match(‘/District Attorney/i’,$row['Title']) ) {
$row['ordinal'] = 16;
} elseif (preg_match(‘/Executive/i’,$row['Title']) ) {
$row['ordinal'] = 17;
} elseif (preg_match(‘/Supervisor/i’,$row['Title']) ) {
$row['ordinal'] = 18;
} elseif (preg_match(‘/At Large/i’,$row['Title']) ) {
$row['ordinal'] = 19;
} elseif (preg_match(‘/Sheriff/i’,$row['Title']) ) {
$row['ordinal'] = 20;
} elseif (preg_match(‘/Treasurer/i’,$row['Title']) ) {
$row['ordinal'] = 21;
} else {
$row['ordinal'] = 22;
}
$row['type']=’county’;
$candidates[$row['rowID']] = $row;
}
// AND candidate.CandidateCountyFips equals voter.CountyFips
$sql = “SELECT * FROM `candidate_temp` WHERE CandidateCountyFips = ‘{$voter['CountyFips']}’
AND JurisdictionTownCity = ‘{$voter['Township']}’
AND ( LD = ‘0′ OR LD is NULL )”;
//echo(“3. $sql
\n”);
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
// echo(“{$row['Title']}
“);
if(preg_match(‘/Mayor/i’,$row['Title']) ) {
$row['ordinal'] = 23;
} elseif(preg_match(‘/Supervisor/i’,$row['Title']) ) {
$row['ordinal'] = 24;
} elseif(preg_match(‘/Treasurer/i’,$row['Title']) ) {
$row['ordinal'] = 25;
} elseif(preg_match(‘/Judge/i’,$row['Title']) ) {
$row['ordinal'] = 26;
} elseif(preg_match(‘/Justice/i’,$row['Title']) ) {
$row['ordinal'] = 27;
} elseif(preg_match(‘/Town Councilmember/i’,$row['Title']) ) {
$row['ordinal'] = 31;
} elseif(preg_match(‘/Council/i’,$row['Title']) ) {
$row['ordinal'] = 28;
} elseif(preg_match(‘/Alderman/i’,$row['Title']) ) {
$row['ordinal'] = 29;
} elseif(preg_match(‘/Town Board/i’,$row['Title']) ) {
$row['ordinal'] = 30;
} else {
$row['ordinal'] = 32;
}
$row['type']=’city’;
$candidates[$row['rowID']] = $row;
}
if ($voter['Township'] == ‘ALBANY’ ) {
$sql = “SELECT * FROM `candidate_temp` WHERE JurisdictionTownCity = ‘ALBANY’
AND Ward = ‘{$voter['Ward']}’”;
$result = mysql_query($sql, $link);
//echo( “4: $sql
\n”);
while ($row = mysql_fetch_assoc($result)) {
//echo(“{$row['Title']}
“);
if(preg_match(‘/Mayor/i’,$row['Title']) ) {
$row['ordinal'] = 23;
} elseif(preg_match(‘/Supervisor/i’,$row['Title']) ) {
$row['ordinal'] = 24;
} elseif(preg_match(‘/Treasurer/i’,$row['Title']) ) {
$row['ordinal'] = 25;
} elseif(preg_match(‘/Judge/i’,$row['Title']) ) {
$row['ordinal'] = 26;
} elseif(preg_match(‘/Justice/i’,$row['Title']) ) {
$row['ordinal'] = 27;
} elseif(preg_match(‘/Town Councilmember/i’,$row['Title']) ) {
$row['ordinal'] = 31;
} elseif(preg_match(‘/Council/i’,$row['Title']) ) {
$row['ordinal'] = 28;
} elseif(preg_match(‘/Alderman/i’,$row['Title']) ) {
$row['ordinal'] = 29;
} elseif(preg_match(‘/Town Board/i’,$row['Title']) ) {
$row['ordinal'] = 30;
} else {
$row['ordinal'] = 32;
}
$row['type']=’city’;
$candidates[$row['rowID']] = $row;
}
}
if (in_array($voter['CountyFips'],$buroughs) && !empty($voter['District3']) ) {
$sql = “SELECT * FROM `candidate_temp` WHERE CouncilDist = ‘{$voter['District3']}’ AND CandidateCountyFips in (‘005′,’047′,’061′,’081′,’085′) “;
// echo(“$sql
\n”);
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
//echo(“{$row['Title']}
“);
if(preg_match(‘/Mayor/i’,$row['Title']) ) {
$row['ordinal'] = 1;
} elseif(preg_match(‘/Supervisor/i’,$row['Title']) ) {
$row['ordinal'] = 2;
} elseif(preg_match(‘/Treasurer/i’,$row['Title']) ) {
$row['ordinal'] = 3;
} elseif(preg_match(‘/Judge/i’,$row['Title']) ) {
$row['ordinal'] = 4;
} elseif(preg_match(‘/Justice/i’,$row['Title']) ) {
$row['ordinal'] = 5;
} elseif(preg_match(‘/Councilman/i’,$row['Title']) ) {
$row['ordinal'] = 6;
} elseif(preg_match(‘/Alderman/i’,$row['Title']) ) {
$row['ordinal'] = 7;
} elseif(preg_match(‘/Town Board/i’,$row['Title']) ) {
$row['ordinal'] = 8;
} elseif(preg_match(‘/Town Councilmember/i’,$row['Title']) ) {
$row['ordinal'] = 9;
} else {
$row['ordinal'] = 10;
}
$row['type']=’city’;
$candidates[$row['rowID']] = $row;
}
}
if (!empty($voter['District2']) ) {
$sql = “SELECT * FROM `candidate_temp` WHERE LD = ‘{$voter['District2']}’ AND CandidateCountyFips = ‘{$voter['CountyFips']}’”;
//echo(“$sql
“);
$result = mysql_query($sql, $link);
while ($row = mysql_fetch_assoc($result)) {
// echo(“{$row['Title']}
“);
if(preg_match(‘/at large/i’,$row['Title']) ) {
$row['ordinal'] = 34;
} else {
$row['ordinal'] = 33;
}
$row['type'] = ‘LD’;
$candidates[$row['rowID']] = $row;
}
}
$post_data['Email'] = $_POST['email'];
$post_data['Zip'] = $_POST['zip'];
$post_data['Street'] = $_POST['address'];
submitDataToSalsa($post_data);
showResult($candidates);
}
* Show the candidates
**/
function showResult($candidates) {
if ( empty($candidates) ) {
// Display some generic text here
echo “
showTellAFriend();
exit;
}"; print_r($candidates); echo "
// Get a list of columns
foreach ($candidates as $key => $row) {
$ordinal[$key] = $row['ordinal'];
}
array_multisort($ordinal, SORT_ASC, $candidates);
——————————————————————————
foreach($candidates as $row) {
//print_r($row);
$name = “{$row['FirstName']} “;
$name .= ($row['MiddleName']) ? “{$row['MiddleName']} ” : ”;
$name .= “{$row['LastName']}”;
/**
* If the candidate is for a county, then it’s For OFFICE, COUNTY: CANDIDATE NAME
* If the candidate is for a town/city, then it’s For OFFICE, TOWN: Candidate name
* If the candidate is for a county LD, then it’s For OFFICE: Candidate Name
*/
if ($row['type'] == ‘county’) {
if (! empty($row['BoroughOf']) ) {
$display = “For “.$row['Title'].’, ‘.$row['BoroughOf'].’: ‘.$name.”
\n”;
} else {
$display = “For “.$row['Title'].’, ‘.$row['JurisdictionCounty'].’: ‘.$name.”
\n”;
}
} elseif ($row['type'] == ‘city’) {
if (in_array($row['ordinal'],array(11,12,13,14))) {
$row['JurisdictionTownCity'] = ‘New York City’;
}
if (in_array($row['ordinal'],array(1,2,3,4,5,6,7,8,9,10))) {
if (! empty($row['BoroughOf']) ) {
$display = “For “.$row['Title'].’, ‘.$row['BoroughOf'].’: ‘.$name.”
\n”;
} else {
$display = “For “.$row['Title'].’, ‘.$row['JurisdictionTownCity'].’: ‘.$name.”
\n”;
}
} else {
$display = “For “.$row['Title'].’: ‘.$name.”
\n”;
}
$display = “For “.$row['Title'].’, ‘.$row['JurisdictionTownCity'].’: ‘.$name.”
\n”;
} elseif ($row['type'] == ‘LD’) {
$display = “For “.$row['Title'].’: ‘.$name.”
\n”;
}
echo $display;
if ($row['Comments']) {
echo(“ {$row['Comments']}
“);
}
$candidateText .= $display.”\n”;
}
“);
// send data to Salsa
$post_data['DATETIME1'] = date(‘Y-m-d’);
$post_data['BLOB8'] = strip_tags($candidateText);
$post_data['Email'] = $_POST['email'];
$post_data['Zip'] = $_POST['zip'];
$post_data['Street'] = $_POST['address'];
submitDataToSalsa($post_data);
//showTellAFriend();
}
{
echo <<
Share MyWFP – help your friends find the progressive candidates where they live.
Click here to open an email and send MyWFP to New Yorkers that share our values.
Print this page for election day.
Share MyWFP on Facebook
Tweet: Just used MyWFP!
Questions or concerns? Contact us at clenchner2@workingfamiliesparty.org.
}
* Display the SALSA form
**/
function showTellAFriend()
{
echo <<Don’t keep it a secret – let your friends know too
Send mail using your own address book.
}
* Establish a database connection.
**/
function connectToDatabase()
{
//require_once(‘private/db.conf’); // pull in db conf info
$dbConnectionData['hostname'] = ‘10.6.166.53′;
$dbConnectionData['username'] = ‘AsherAliza’;
$dbConnectionData['database'] = ‘AsherAliza’;
$dbConnectionData['password'] = ‘gOmperz1984′;
$link = mysql_connect($dbConnectionData['hostname'], $dbConnectionData['username'], $dbConnectionData['password']);
if (!$link) {
fatalError(“Could not connect to database.”);
}
if (!$db_selected) {
fatalError(“Can’t select database.”);
}
return $link;
* Add/Update record through Salsa.
**/
function submitDataToSalsa($post_data){
// config data for Salsa
$salsa['organization_KEY'] = ‘1306′;
$salsa['table'] = ’supporter’;
$salsa['URL'] = ‘http://salsa.wiredforchange.com/dia/processEditValues.jsp’;
$post_data['table'] = $salsa['table'];
$post_data['link']=’custom’;
$post_data['linkKey']=’0′;
$post_items[] = $key . ‘=’ . urlencode($value);
}
$post_string = implode (‘&’, $post_items);
$curl_connection = curl_init($salsa['URL']);
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)”);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
curl_close($curl_connection);
}
* Trap fatal errors
**/
function fatalError($msg)
{
die($msg);
}




