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();
}

/**
* Display HTML form to the user
**/
function showForm($condition=null)
{
if ($condition == 'fail') {
echo <<

Oops! We couldn’t find that address. Make sure you -

  • left out your apartment number and/or town/city/boro/neighborhood name
  • used St./Ave./Rd. or N./W./E./S. instead of Street/Avenue/Road or North/West/East/South
  • Check your spelling

If you’re still experiencing a problem, you can search for candidates from a list by region, or contact us at clenchner2@workingfamiliesparty.org.
EOT;

}
if ($condition == ‘validation’) {
echo “

Please fill out all form fields and try again.

“;
}
echo <<




House number & name of St./Ave./Rd. No Apt.


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;

}

/**
* 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();

if (strlen($_POST['address']) < 1 ||
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);

// look for a matching record in the voter table
$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']).”%’”;

$result = mysql_query($sql, $link);
if (!$result) {
fatalError( “Could not successfully run voter query from DB: “);
}

if (mysql_num_rows($result) == 0) {
showForm(‘fail’);
exit();
}
$voter = mysql_fetch_assoc($result);

// list of all matching candidates, to be sorted later.
$candidates = array();

// 1. NYC
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;
}
}

// 2. candidate.JurisdictionCountyFips equals voter.CountyFips
$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;
}

// 3. if candidate.JurisdictionTownCity equals voter.Township
// 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;
}

// 4. ALBANY RULE
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;
}
}

// 5. NYC RULE
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;
}
}

// 6. if candidate.LD equals voter.District2
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;
}
}

// send data to Salsa
$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 “

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.

“;
showTellAFriend();
exit;
}

//echo “

"; print_r($candidates); echo "

“;
// Get a list of columns
foreach ($candidates as $key => $row) {
$ordinal[$key] = $row['ordinal'];
}
array_multisort($ordinal, SORT_ASC, $candidates);

echo(“

WFP ENDORSED CANDIDATES WHERE YOU LIVE:
——————————————————————————

\n”);

$candidateText = ”;
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”;
}

echo(“
“);
// 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);

showDisclaimer();
//showTellAFriend();
}

function showDisclaimer()
{
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!

EOT;

echo <<

We’ll keep you posted with election updates. Thank you for using MyWFP.

Questions or concerns? Contact us at clenchner2@workingfamiliesparty.org.

EOT;
}

/**
* Display the SALSA form
**/
function showTellAFriend()
{
echo <<

Don’t keep it a secret – let your friends know too

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.


Send mail using your own address book.

Enter your information:

First Name:

Last Name:

Email*:


Do you know who Working Families is supporting?


use comma, space or semi-colon (, ;) to separate your email addresses

value="manual_challenge">

EOT;
}

/**
* 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.”);
}

$db_selected = mysql_select_db($dbConnectionData['database'], $link);
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['organization_KEY'] = $salsa['organization_KEY'];
$post_data['table'] = $salsa['table'];
$post_data['link']=’custom’;
$post_data['linkKey']=’0′;

foreach ( $post_data as $key => $value) {
$post_items[] = $key . ‘=’ . urlencode($value);
}

//create the final string to be posted using implode()
$post_string = implode (‘&’, $post_items);

//create cURL connection
$curl_connection = curl_init($salsa['URL']);

//set options
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);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//close the connection
curl_close($curl_connection);
}

/**
* Trap fatal errors
**/
function fatalError($msg)
{
die($msg);
}

?>

© 2007–2014 Working Families Party | Privacy Policy

design by theCoup.org