\n
How SLO County Voted
";
$contestData=getLocalContest($xml, urldecode($_GET['name']),"San Luis Obispo");
outputData($contestData, "small");
print "";
}
if($_GET['page']=="listContests")
{
$contests=listContests($url);
outputContestsForm($contests);
}
if($_GET['page']=="getSmallContest")
{
$contestData=getContest($xml, urldecode($_GET['name']));
outputData($contestData, "small");
}
if($_GET['page']=="getMainContests")
{
$contests=explode(",",$_GET['contests']);
foreach($contests as $contest)
{
$contestData[$contest]=getContest($xml,$contest);
//echo "contest: $contest
";
}
//var_dump($contestData);
outputBarGraph($contestData);
}
}
function listContests($url) // Returns an array of all contests, used to populate menus
{
$xml = file_get_contents($url);
$xml=simplexml_load_string($xml);
$output=array();
//var_dump($xml);
$i=0;
foreach($xml as $reportingUnits)
{
foreach ($reportingUnits as $reportingUnit)
{
foreach($reportingUnit as $contest)
{
//echo "Contest: $contest->name
";
if(!multidimArrayLocate((string)$contest['id'],$output))
{
//var_dump($contest);
//echo "
*** id : ".(string)$contest['id']." ***
";
$output[$i]['name']=(string)$contest->name;
$output[$i]['id']=$contest['id'];
//echo "adding: $output[$i]
\n";
$i++;
}
//else echo "$contest->name already in array
";
}
}
}
return $output;
}
function getContest($xml,$name)
{
$output=array();
//var_dump($xml);
foreach($xml as $reportingUnits)
{
foreach ($reportingUnits as $reportingUnit)
{
//echo "(string)$reportingUnit
";
//var_dump ($reportingUnit); echo "
--------------------------
";
foreach($reportingUnit as $contest)
{
//var_dump ($contest); echo "
--------------------------
";
//echo "$contest
";
if($contest['id'] == $name )
{
$output['name']=$contest->name;
//echo "found $name";
if ($contest->type == "candidate")
{
foreach ($contest->selections as $selection)
{
$selections=$contest->selections;
foreach ($selections->selection as $selection)
{
$candidateName=$selection->candidateName;
$output['candidates'][(string)$candidateName][voteCount]+=$selection->voteCount;
$output['candidates']->$candidateName->percentWithinRace=$selection->percentWithinRace;
}
}
}
else if ($contest->type == "referendum")
{
//var_dump($contest);
//echo "
--------------------------
";
foreach ($contest->selections as $selection)
{
//echo "selection: $selection->id
";
foreach ($selection as $val)
{
//var_dump($val);
$id =$val['id'];
//echo "
-----****------------------****---
";
//echo "ID: $id
";
//echo "voteCount: $val->voteCount";
$output['candidates'][(string)$id][voteCount]+=$val->voteCount;
}
}
}
else echo $contest->type;
}
}
}
}
return $output;
}
function getLocalContest($xml,$name,$reportingUnitName)
{
$output=array();
foreach($xml as $reportingUnits)
{
if ($reportingUnits->name==$reportingUnitName)
{
foreach ($reportingUnits as $reportingUnit)
{
foreach($reportingUnit as $contest)
{
if($contest['id'] == $name )
{
$output['name']=$contest->name;
//echo "found $name";
if ($contest->type == "candidate")
{
foreach ($contest->selections as $selection)
{
$selections=$contest->selections;
foreach ($selections->selection as $selection)
{
$candidateName=$selection->candidateName;
$output['candidates'][(string)$candidateName][voteCount]+=$selection->voteCount;
$output['candidates']->$candidateName->percentWithinRace=$selection->percentWithinRace;
}
}
}
else if ($contest->type == "referendum")
{
//var_dump($contest);
//echo "
--------------------------
";
foreach ($contest->selections as $selection)
{
//echo "selection: $selection->id
";
foreach ($selection as $val)
{
//var_dump($val);
$id =$val['id'];
//echo "
-----****------------------****---
";
//echo "ID: $id
";
//echo "voteCount: $val->voteCount";
$output['candidates'][(string)$id][voteCount]+=$val->voteCount;
}
}
}
else echo $contest->type;
}
}
}
}
}
return $output;
}
function outputData($contestData, $size="big")
{
print '';
$i=0;
$name=str_replace("'","`",$contestData['name']);
$candidates=$contestData['candidates'];
print '';
print '";
print "";
}
else
{
print "var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 600, height: 400,colors:['#4D5E6E','#CB6C18'], is3D: true, title: 'Election Results: $name'}); }";
print "";
print "\n
";
foreach ($candidates as $candidate => $var)
{
$votes=$var['voteCount'];
print "| $candidate | $votes votes |
";
}
print "
\n
";
}
}
function outputBarGraph($contests)
{
$i=0;
print '
";
print "";
}
function outputContestsForm($contests)
{
echo '';
}
function multidimArrayLocate($text,$array)
{
//echo "$key : looking for $text
";
$theResult=false;
foreach($array as $key => $arrayValue)
{
$id=$arrayValue['id'];
//echo "$key : $id : looking for $text
";
if ($arrayValue['id'] == $text) $theResult = true;
}
return $theResult;
}
function getPropNames($name)
{
if (strstr($name,"Farm Animals")) return "Prop. 2";
if (strstr($name,"Parent Notif")) return "Prop. 4";
if (strstr($name,"Same-Sex")) return "Prop. 8";
if (strstr($name,"Redistricting")) return "Prop. 11";
}
?>