/* geoShowVals.php - 12/14/06 - n:\phpapps\990search\ - Shows presentation-quality org-level output in Form-view (used for showing ntee example orgs)
Summary:
Directory:
Input Files:
Output Files:
Preliminaries:
Next steps:
Notes:
*/
session_start();
$debug = 0;
/***********************************************************/
$bcolor = '#FFFFCC';
$white = '#FFFFFF';
$hdgBck = 'BLUE';
$align = 'LEFT';
$max_num_records = 20;
$bmfFile = 'bmf.bm0701';
$coreFile = 'nccs.core2005pc';
$coreFilePf = 'nccs.core2004pf';
$coreYear = '2005';
$coreYearPf = '2004';
/***********************************************************/
$flds = array(
'Name' => 'Name;70',
'Street' => 'Street;70',
'Zipcode' => 'Zipcode;10',
'Phone' => 'Phone;20',
'Program1' => 'Program 1;TEXT',
'Activity1' => 'Activity code;SELECT;Arts,Education,Environment,Health,Human services',
'PopServed1' => 'Population Served;SELECT;Infants,Preschool children,School-age children,Adults,Elderly,Disabled;',
'RegServed1' => 'Region served;TEXT;',
'AreaType1' => 'Area Type;SELECT;Zipcode,County,State;',
'Area1' => 'Area;50',
'Program2' => 'Program 2;TEXT',
'Activity2' => 'Activity code;SELECT;Arts,Education,Environment,Health,Human services',
'PopServed2' => 'Population Served;SELECT;Infants,Preschool children,School-age children,Adults,Elderly,Disabled;',
'RegServed2' => 'Region served;TEXT;',
'AreaType2' => 'Area Type;SELECT;Zipcode,County,State;',
'Area2' => 'Area;50',
'Program3' => 'Program 3;TEXT',
'Activity3' => 'Activity code;SELECT;Arts,Education,Environment,Health,Human services',
'PopServed3' => 'Population Served;SELECT;Infants,Preschool children,School-age children,Adults,Elderly,Disabled;',
'RegServed3' => 'Region served;TEXT;',
'AreaType3' => 'Area Type;SELECT;Zipcode,County,State;',
'Area3' => 'Area;50',);
/***********************************************************/
$view = $_GET['v'];
$id = $_GET['id'];
$ntee = $_GET['ntee'];
$ntee1 = $_GET['ntee1'];
$ft = $_GET['ft'];
$code2 = $_GET['code'];
/***********************************************************/
// echo "code: $code
ntee: $ntee
";
include('../new/head.php');
include('datacon.php');
require('proclib.php');
$date = date('m/d/y H:i');
$title = "NCCS - Add Organization";
echo "
$title\n";
echo "$title
\n";
echo "";
return;
/***********************************************************/
function showRec(){
global $row, $ein, $linecounter, $bcolor, $white, $ft, $flds, $code2, $debug, $ntee, $ntee1,
$coreYear, $coreFile, $coreFilePf, $coreYearPf, $bmfFile, $code2, $view;
$linecounter = 0;
$geoscaleid = $row['geoscaleid'];
$key = $row['NccsLabel'];
$stateCity = $row['stusab'].$row['NccsLabel'];
$totPop = $row['TotPop'];
while ($label = current($flds)) {
if (key($flds) == 'NccsLabel'){
// showHdg('Basics','');
showHdg('Basics','');
} elseif ( key($flds) == 'PopUnder5Years'){
showHdg('Population Segments','');
} elseif ( key($flds) == 'PopPoorPersons'){
showHdg('Poverty, Education & Disability','');
}
if (key($flds) == 'NccsLabel'){
// show fips or msa code:
$showCode = '';
if ($code2 > 0 ){
$showCode = " ($code2)";
}
showVal( $row['NccsLabel'].$showCode, substr($label,1), substr($label,0,1));
} else {
showVal( $row[key($flds)], substr($label,1), substr($label,0,1));
}
next($flds);
}
// geoscaleid- 4:state, 6:US, 3:COUNTY, 5 or 11: MSA
if ($geoscaleid == 6 ){
$q = '1';
} elseif ($geoscaleid == 4 ){
$q = "state = substring('$key',1,2)";
} elseif ($geoscaleid == 3 ){
$q = "fips = '$code2'";
} elseif ($geoscaleid == 11 ){
$q = "msa_nech = '$code2' OR pmsa = '$code2'";
} elseif ($geoscaleid == 5 or $geoscaleid == 11 ){
$q = "msa_nech = '$code2' OR pmsa = '$code2'";
} elseif ($geoscaleid == 7 ){
$q = "zip5 = '$code2'";
} elseif ($geoscaleid == 2 ){
// places
$q = "concat(STATE,CITY) = '$stateCity'";
} else {$q = '2'; }
$geoQry = $q;
$ntee2 = '';
if (strlen(trim($ntee))>0){
$ntees = explode(',', $ntee);
$q2 = '(';
for ( $k=0; $k < count($ntees); $k++){
if ($k>0){
$q2 =$q2. ' OR ';
}
$q2 = $q2." nteecc LIKE '". trim($ntees[$k])."%'";
}
$q2 = $q2. ')';
$q = $q. " AND $q2";
$ntee2 = " - NTEE=$ntee";
}
if (strlen(trim($ntee1))>0){
$q = $q. " AND (LOCATE( SUBSTRING(nteecc,1,1), '$ntee1')>0) ";
$ntee2 = $ntee2.' - ';
if (substr($ntee1,0,1) == 'A') {
$ntee2 = $ntee2. ' Arts';
} elseif ( substr($ntee1,0,1) == 'B'){
$ntee2 = $ntee2. ' Education';
} elseif ( substr($ntee1,0,1) == 'C'){
$ntee2 = $ntee2. ' Environment';
} elseif ( substr($ntee1,0,1) == 'E'){
$ntee2 = $ntee2. ' Health';
} elseif ( substr($ntee1,0,1) == 'I'){
$ntee2 = $ntee2. ' Human services';
} elseif ( substr($ntee1,0,1) == 'Q'){
$ntee2 = $ntee2. ' International';
} elseif ( substr($ntee1,0,1) == 'R'){
$ntee2 = $ntee2. ' Civil rights & social action';
} elseif ( substr($ntee1,0,1) == 'S'){
$ntee2 = $ntee2. ' Other';
}
}
$query = "SELECT count(*) as Num_Orgs, SUM(exps) as Total_Expenses, sum(ass_eoy) as Total_assets,
sum(cont) as cont, sum(totrev) as totrev
FROM $coreFile WHERE $q";
if ($debug ==1 ){ echo $query.'
'; }
$results2 = runSql($query);
$num_results2 = mysql_num_rows($results2);
for ( $k=0; $k < $num_results2; $k++) {
$row2 = mysql_fetch_array($results2);
showHdg("Nonprofit Activities $ntee2 ($coreYear)",'');
showVal( $row2['Num_Orgs'] , 'Number of organizations',1);
showVal( $row2['cont'] , 'Contributions & grants',1);
showVal( $row2['totrev'] , 'Total revenue',1);
showVal( $row2['Total_Expenses'] , 'Total expenses',1);
showVal( $row2['Total_assets'] , 'Total assets',1);
showHdg("Nonprofit Activities per Capita $ntee2 ($coreYear)",'');
showVal( $row2['Num_Orgs']/$totPop * 10000 , 'Number of organizations (per 10,000 persons)',3);
showVal( $row2['cont']/$totPop , 'Contributions & grants',1);
showVal( $row2['totrev']/$totPop , 'Total revenue',1);
showVal( $row2['Total_Expenses']/$totPop , 'Total expenses',1);
showVal( $row2['Total_assets'] /$totPop, 'Total assets',1);
}
/***********************************************************/
// private foundations --
/***********************************************************/
if ($view == 'pf'){
$query = "SELECT count(*) as Num_Orgs, SUM(p1totexp - p1contpd) as OtherExp,
sum(p2tAsFmv) as Total_assets,
sum(p1contpd) as contpd, sum(p1totrev) as totrev
FROM $coreFilePf WHERE $q";
if ($debug ==1 ){ echo $query.'
'; }
$results2 = runSql($query);
$num_results2 = mysql_num_rows($results2);
for ( $k=0; $k < $num_results2; $k++) {
$row2 = mysql_fetch_array($results2);
showHdg("Private Foundation Activities ($coreYearPf)",'');
showVal( $row2['Num_Orgs'] , 'Number of foundations',1);
showVal( $row2['Total_assets'] , 'Total assets (FMV)',1);
showVal( $row2['totrev'] , 'Total revenue',1);
showVal( $row2['contpd'] , 'Contributions & grants made',1);
showVal( $row2['OtherExp'] , 'Other expenses',1);
showHdg("Foundation Activities per Capita $ntee2 ($coreYearPf)",'');
showVal( $row2['Num_Orgs']/$totPop * 10000 , 'Number of organizations (per 10,000 persons)',3);
showVal( $row2['contpd']/$totPop , 'Contributions & grants',1);
showVal( $row2['totrev']/$totPop , 'Total revenue',1);
showVal( $row2['Total_assets'] /$totPop, 'Total assets',1);
}
}
/***********************************************************/
// congregations
/***********************************************************/
if ($view == 'cong'){
$query = "SELECT count(*) as Num_Orgs, SUM( IF( nteecc like 'X2%', 1,0)) as Congs
FROM $bmfFile WHERE ($geoQry) AND SUBSTRING(nteecc,1,1) = 'X'";
if ($debug ==1 ){ echo $query.'
'; }
$results2 = runSql($query);
$num_results2 = mysql_num_rows($results2);
for ( $k=0; $k < $num_results2; $k++) {
$row2 = mysql_fetch_array($results2);
showHdg("Congregations and Other Religious Organizations ($bmfYear)",'');
showVal( $row2['Congs'] , 'Number of congregations',1);
showVal( $row2['Num_Orgs'] - $row2['Congs'] , 'Number of other religious organizations',1);
showVal( $row2['Num_Orgs'] , 'Total',1);
showVal( $row2['Congs']/$totPop * 10000 , 'Number of congregations per 10,000 persons',3);
showVal( $row2['Num_Orgs']/$totPop * 10000 , 'Number of organizations per 10,000 persons',3);
}
}
/***********************************************************/
// FIPS CHAR(5), ADD INDEX (ZIP), add index (STATE), ADD INDEX (AGISize);
$query = '';
if ($geoscaleid == 11 or $geoscaleid == 5 ){
$query = "SELECT sum(TotReturns2) as TotReturns2, sum(SchANum2) as SchANum2,
SUM( ContNum2) as ContNum2, SUM( AGI2) as AGI2, SUM(Cont2) as Cont2
FROM indiv.irs1040zip2004 a, lookup.lu_zip2006 b
WHERE
a.zip = b.zip5 AND
(b.msa = '$code2' or b.pmsa = '$code2' or b.cmsa = '$code2')
and a.agilev2 = 'tot'";
}
// county:
if ($geoscaleid == 3 ){
$query = "SELECT sum(TotReturns2) as TotReturns2, sum(SchANum2) as SchANum2,
SUM( ContNum2) as ContNum2, SUM( AGI2) as AGI2, SUM(Cont2) as Cont2
FROM indiv.irs1040zip2004 a, lookup.lu_zip2006 b
WHERE
a.zip = b.zip5 AND
(b.fips = '$code2')
and a.agilev2 = 'tot'";
}
// state:
if ($geoscaleid == 4 ){
$query = "SELECT sum(TotReturns2) as TotReturns2, sum(SchANum2) as SchANum2,
SUM( ContNum2) as ContNum2, SUM( AGI2) as AGI2, SUM(Cont2) as Cont2
FROM indiv.irs1040zip2004 a
WHERE state = '$code2'
and a.agilev2 = 'tot'";
}
if ($geoscaleid == 7 ){
$query = "SELECT * FROM indiv.irs1040zip2004
WHERE ZIP = '$code2' and agilev2 = 'tot'";
}
if (strlen($query)>0){
// echo $query."
";
$results2 = mysql_query($query);
$num_results2 = mysql_num_rows($results2);
for ( $k=0; $k < $num_results2; $k++) {
$row2 = mysql_fetch_array($results2);
if ($row2['TotReturns2'] == 0 ){
echo 'Total returns='.$row2['TotReturns2']."
";
echo $query."
";
// return 0;
}
showHdg("Household Giving (2004)",'');
showVal( $row2['TotReturns2'] , 'Number of households',1);
showVal( $row2['SchANum2'] , 'Number of households itemizing deductions',1);
showVal( $row2['SchANum2']/$row2['TotReturns2'] * 100 , '% of households itemizing',3);
showVal( $row2['ContNum2']/ $row2['SchANum2'] *100 , 'Percentage reporting contributions',3);
showVal( $row2['AGI2'], 'Total AGI ($ thousands)',1);
showVal( $row2['Cont2'], 'Total contributions ($ thousands)',1);
showVal( $row2['Cont2']/$row2['AGI2']*100 , 'Contributions as a % of AGI',3);
}
}
// echo "geoscaleid: $geoscaleid
";
}
/***********************************************************/
// show values
function showVal($val, $alias, $options){
global $linecounter, $bcolor, $white;
if ($val == null){
return;
}
$linecounter++;
if ($linecounter % 2 == 1) { $color = $bcolor; } else {$color = $white;}
print "\t$linecounter. $alias | \n";
$align = 'LEFT';
if ($options == 1){
$val = number_format($val);
$align = 'RIGHT';
} elseif ($options == 2) {
$val = fixcase($val);
}
if ($options == 3){
$val = number_format($val,2);
$align = 'RIGHT';
}
if ($val == null) {$val = '-';}
print "\t\t$val | ";
// show state
// show U.S.
echo "
\n";
}
// show heading:
function showHdg($val, $options){
global $linecounter, $bcolor, $white;
//$linecounter++;
//if ($linecounter % 2 == 1) { $color = $bcolor; } else {$color = $white;}
$bgcolor = '#99CCFF';
if ( strpos(strtolower($options), 'white')=== true){
$bgcolor = 'WHITE';
}
print "\t$val |
\n";
}
?>