\r\n";
echo "\r\n";
echo " \r\n";
}
function aaiFile2Canonical(){
$strFileBuffer=file_get_contents(dirname(__FILE__).'/CanonicalByCounty.txt');
$foobar = preg_match_all('/(\S+)\t(.*)\r\n/', $strFileBuffer, $pairs);
return aaiCombine($pairs[1], $pairs[2]);
}
function aaiFile2DemogData($setNum, $area){
$strFileBuffer=file_get_contents(dirname(__FILE__).'/'.$area.'/'.$area.'_'.$setNum.'.txt');
$foobar = preg_match_all('/(\S+)\t(.*)\r\n/', $strFileBuffer, $pairs);
return aaiCombine($pairs[1], $pairs[2]);
}
function aaiInfoDataGet($area){
$strFileBuffer=file_get_contents(dirname(__FILE__).'/'.$area.'/info.txt');
$foobar = preg_match_all('/(\S+)\t(.*)\r\n/', $strFileBuffer, $pairs);
return aaiCombine($pairs[1], $pairs[2]);
}
function aaiFile2MetaData($setNum){
$strFileBuffer=file_get_contents(dirname(__FILE__).'/MetaData_'.$setNum.'.txt');
$foobar = preg_match_all('/(\S+)\t(.*)\r\n/', $strFileBuffer, $pairs);
return aaiCombine($pairs[1], $pairs[2]);
}
function aaiCombine($array1, $array2) {
if(count($array1) == count($array2)) {
$assocArray = array();
for($Ix=0;$Ixread()){
switch(filetype($ThisDir.'/'.$ItemName)){
case 'file':
$Files[$iIxF++]=$ItemName;
break;
case 'dir':
if($ItemName<>'.' && $ItemName<>'..')
$Directories[$iIxD++]=$ItemName;
break;
default:
break;
}
}
$DirObj->close();
if($iIxD>0)sort($Directories, SORT_STRING);
return count($Files);
}
//////////////////// Preamble //////////////////////
if(!empty($_GET)) extract($_GET);
if(!empty($_POST)) extract($_POST);
if(!empty($_COOKIE)) extract($_COOKIE);
$ThisFileName=basename(__FILE__);
$ThisDirectory=dirname(__FILE__);
$LibraryDirectory="../../htm/library/USCensus";
//////////////////// Preamble //////////////////////
$FileSetDesc1[1]="U.S. Census Bureau2010 Census ";
$FileSetDesc1[2]="U.S. Census Bureau2007-2011 American Community Survey - 5 Year Estimates ";
$FileSetDesc1[3]="U.S. Census Bureau2007-2011 American Community Survey - 5 Year Estimates ";
$FileSetDesc1[4]="U.S. Census Bureau2007-2011 American Community Survey - 5 Year Estimates ";
$FileSetDesc1[5]="U.S. Census Bureau2007-2011 American Community Survey - 5 Year Estimates ";
$FileSetDesc2[1]="Profile of General Population and Housing Characteristics: 2010 ";
$FileSetDesc2[2]="Selected Social Characteristics ";
$FileSetDesc2[3]="Selected Economic Characteristics ";
$FileSetDesc2[4]="Selected Housing Characteristics ";
$FileSetDesc2[5]="ACS Demographic AND Housing Estimates ";
$FileSetDesc3[1]="Population, Age, Sex, Race, Households and Housing ";
$FileSetDesc3[2]="Education, Marital Status, Relationships, Fertility, Grandparents ";
$FileSetDesc3[3]="Income, Employment, Occupation, Commuting to Work ";
$FileSetDesc3[4]="Occupancy and Structure, Housing Value and Costs, Utilities ";
$FileSetDesc3[5]="Sex and Age, Race, Hispanic Origin, Housing Units ";
//////////////////// Preamble //////////////////////
$DirectoriesDemog=array();
$FilesDemog=array();
$DirectoriesLibrary=array();
$FilesLibrary=array();
$CountiesHRV=array();
$ZipCodesHRV=array();
dirWalk($ThisDirectory, $DirectoriesDemog, $FilesDemog);
dirWalk($LibraryDirectory, $DirectoriesLibrary, $FilesLibrary);
foreach($DirectoriesDemog as $Directory){
if(is_numeric($Directory)){
$ZipCodesHRV[count($ZipCodesHRV)]=$Directory;
}else{
if(strlen($Directory)>3){
$CountiesHRV[count($CountiesHRV)]=$Directory;
}
}
}
if(isset($_GET['set'])){
$FileSet=$_GET['set'];
}else{
$FileSet=1;
}
$AdCt=0;
$RowCt=0;
$iCtReqAreas=0;
$CountiesReq=array();
$SectionHead='';
$Canonical=aaiFile2Canonical();
$MD_pairs=aaiFile2MetaData($FileSet);
$iZipCodeCt=0;
$Areas=explode(',', $_GET['area']);
$iCtReqAreas=count($Areas);
//echo "$Canonical ";
//var_dump($Canonical);
//echo " ";
//echo "CountiesHRV ";
//var_dump($CountiesHRV);
//echo " ";
//echo "ZipCodesHRV ";
//var_dump($ZipCodesHRV);
//echo " ";
foreach($Areas as $Area){
if(in_array($Area, $DirectoriesDemog)){
if(is_numeric($Area))$iZipCodeCt++;
}
}
if(count($Areas)==1 && $iZipCodeCt==1){
$Info_pairs[$Area]=aaiInfoDataGet($Areas[0]);
$Areas[1]=$Info_pairs[$Areas[0]]['County'];
if(!in_array($Areas[1], $CountiesReq)){
$CountiesReq[count($CountiesReq)]=$Areas[1];
}
$Areas[2]=$Info_pairs[$Areas[0]]['ST'];
}
//Gather required data from appropriate folder/file
foreach($Areas as $Area){
if(in_array($Area, $DirectoriesDemog)){
if(strlen($Area)>3){
if($iZipCodeCt==1 && $Area==$Areas[0] && $iCtReqAreas==1){
//We already did this
}else{
$Info_pairs[$Area]=aaiInfoDataGet($Area);
if(is_numeric($Area)){
if(!in_array($Info_pairs[$Area]['County'], $CountiesReq)){
$CountiesReq[count($CountiesReq)]=$Info_pairs[$Area]['County'];
}
}else{
if(!in_array($Area, $CountiesReq)){
$CountiesReq[count($CountiesReq)]=$Area;
}
}
}
}
$KV_pairs[$Area]=aaiFile2DemogData($FileSet, $Area);
}
}
//foreach($CountiesReq as $County){
// if(isset($Info_pairs[$County])){
// }else{
// $Info_pairs[$County]=aaiInfoDataGet($County);
// }
//}
//echo "Info_pairs ";
//var_dump($Info_pairs);
//echo " ";
//if($Info_pairs[$CountiesReq[0]]>0){
// $selectorRows=$Info_pairs[$CountiesReq[0]];
// foreach($selectorRows as $key => $value){
// $selectorRows[$key]=$value.= " - ($key)";
// }
// asort($selectorRows);
// $ZipSelector="\r\n";
// $ZipSelector.="Compare Area\r\n";
// foreach($selectorRows as $key => $value){
// if(!in_array($key, $Areas)){
// $ZipSelector.=" $value\r\n";
// }
// }
// $ZipSelector.=" \r\n";
//}
//Fixup template with this location
$strFileBuffer=file_get_contents(dirname(__FILE__).'/DemogHead.htm');
if(is_numeric($Areas[0])){
$strFileBuffer=str_replace('%%%ZipCode%%%', $Areas[0], $strFileBuffer);
$strFileBuffer=str_replace('%%%Locality%%%', $Info_pairs[$Areas[0]]['Locality'], $strFileBuffer);
}else{
$strFileBuffer=str_replace('%%%Locality%%%', '', $strFileBuffer);
$strFileBuffer=str_replace('%%%ZipCode%%%', '', $strFileBuffer);
$strFileBuffer=str_replace('Zip', '', $strFileBuffer);
}
$strFileBuffer=str_replace('%%%YYYY%%%', date('Y'), $strFileBuffer);
$strFileBuffer=str_replace('%%%County%%%', $CountiesReq[0], $strFileBuffer);
$strFileBuffer=str_replace('%%%Canonical%%%', $Canonical[$CountiesReq[0]].$_SERVER['REQUEST_URI'], $strFileBuffer);
$strFileBuffer=str_replace('%%%FileSetDesc1%%%', $FileSetDesc1[$FileSet], $strFileBuffer);
$strFileBuffer=str_replace('%%%FileSetDesc2%%%', $FileSetDesc2[$FileSet], $strFileBuffer);
$strFileBuffer=str_replace('%%%FileSetDesc3%%%', $FileSetDesc3[$FileSet], $strFileBuffer);
$strFileBuffer=str_replace('', ' ', $strFileBuffer);
$strFileBuffer=str_replace(' '.$CountiesReq[0], ' '.$CountiesReq[0], $strFileBuffer);
//$strFileBuffer=str_replace('%%%ZipCodeSelect%%%', $ZipSelector, $strFileBuffer);
//$strFileBuffer=str_replace('%%%CodeSelect%%%', '', $strFileBuffer);
for($Ix1=1;$Ix1<=count($FileSetDesc2);$Ix1++){
$strFileBuffer=str_replace('%%%FileSet'.$Ix1.'Desc%%%', strip_tags($FileSetDesc2[$Ix1]), $strFileBuffer);
}
echo $strFileBuffer;
echo "\r\n";
$MD_Keys=array_keys($MD_pairs);
foreach($MD_Keys as $MD_Key){
if($MD_Key=='Seq'){
$HD_Items=explode("\t",$MD_pairs[$MD_Key]);
}else{
$MD_Items=explode("\t",$MD_pairs[$MD_Key]);
$Descriptions=explode(' - ', $MD_Items[0]);
if($SectionHead!=$Descriptions[0]){
if($RowCt>16 && $AdCt<3){
echo "";
echo "";
BannerDisplay();
echo " \r\n";
$RowCt=0;
$AdCt++;
}
echo "";
echo "$FileSetDesc2[$FileSet] ";
echo " \r\n";
echo "";
echo " $Descriptions[0] ";
echo " \r\n";
echo "";
if($iZipCodeCt==1){
echo "".$Info_pairs[$Areas[0]]['Locality']." ";
}else{
echo "Location ";
}
foreach($Areas as $Area){
echo "";
echo $Area;
if(is_numeric($Area) && $iZipCodeCt>1){
echo " ".$Info_pairs[$Area]['Locality'];
}
echo " ";
}
echo " \r\n";
echo "";
echo "$HD_Items[0] ";
foreach($Areas as $Area){
for($Ix1=1;$Ix1$HD_Items[$Ix1]";
}
}
echo " \r\n";
$SectionHead=$Descriptions[0];
}
$RowCt++;
echo "";
echo "".str_repeat("-", count($Descriptions)-2).$Descriptions[count($Descriptions)-1]." "; //" \r\n";
foreach($Areas as $Area){
for($Ix1=1;$Ix1';
if($KV_pairs[$Area][$MD_Items[$Ix1]]==''){
echo ' ';
}else{
if(strpos($KV_pairs[$Area][$MD_Items[$Ix1]],'.')>0){
echo number_format($KV_pairs[$Area][$MD_Items[$Ix1]], 1);
}else{
echo number_format($KV_pairs[$Area][$MD_Items[$Ix1]]);
}
}
echo '';
}
}
echo " \r\n";
}
}
echo "
\r\n";
if($AdCt<3){
echo "";
echo "";
BannerDisplay();
echo " \r\n";
}
if(in_array('DemographicNotes_'.$FileSet.'.htm', $FilesLibrary)){
echo " \r\n";
echo " \r\n";
echo "\r\n";
echo "\r\n";
echo "\r\n";
echo file_get_contents($LibraryDirectory.'/DemographicNotes_'.$FileSet.'.htm');
echo " \r\n";
echo " \r\n";
echo " \r\n";
echo "
\r\n";
echo " \r\n";
//Replaced with above to Format as Category Write-ups
// echo "";
// echo "";
// echo "";
// echo file_get_contents(dirname(__FILE__).'/DemographicNotes_'.$FileSet.'.htm');
// echo " ";
// echo " \r\n";
}
//Output page footer fixed up to include copyright information ...
$strFileBuffer=file_get_contents(dirname(__FILE__).'/DemogFoot.htm');
$ArgNeedle='