Files: index.html, carb1.html, carb2.html, save.html, carbon.cgi

index.html:

<HTML>

<HEAD><TITLE>Carbon Reduction Pledge Form</TITLE></HEAD>

<FRAMESET ROWS="*,0">

<FRAME SRC="carb1.html" NAME="main" NORESIZE BORDER=0>

<FRAME SRC="save.html" NAME="save" NORESIZE SCROLLING=NO BORDER=0>

</FRAMESET>

</HTML>

----------------------------------------------------------------------

 

carb1.html:

<HTML>

<HEAD>

<SCRIPT LANGUAGE=JAVASCRIPT>

function save() {

for (i=0;i<16;i++) {

window.parent.save.document.forms[0].elements[i].value=document.data.elements[i].value;

} window.parent.save.document.forms[0].state.value=document.data.state.options[document.data.state.selectedIndex].value;

return true;

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR="#DDDDDD"><CENTER>

<TABLE BORDER=0 BGCOLOR=#FFFFFF WIDTH=85%>

<TR><TD align=center><font size=+1><b>Welcome to CPR -Climate Protection Registry</b></font><br>A program of the Center for Environmental Economic Development (CEED)<p></td></tr>

<tr><td>Please use the calculator to estimate your household's carbon emissions. If you are interested in joining CPR, please fill out the entire form and submit your emissions data. If you simply want to calculate your total carbon, fill out all fields marked with an asterisk (<b>*</b>)<br>If you would like to work from a printed form, you can use our printable worksheets in <a href=worksheet.html>HTML</a> or <a href=worksheet.pdf>PDF</a> format.<br>If you have any questions or comments, contact ceed@humboldt1.com.

</td></tr></table></center><p>

<CENTER>

<TABLE BORDER=0 BGCOLOR=#FFFFFF WIDTH=85%>

<FORM NAME="data">

<TR>

<TD>Organization ID Number: (if you are filling this out for multiple organizations, seperate each ID with a comma)</TD>

<TD><INPUT TYPE=TEXT NAME="id"></TD>

</TR>

<TR>

<TD>If you don't have an ID Number, leave the previous field blank and enter the organization name here. If you are doing this as an individual, enter "Individual"</TD>

<TD><INPUT TYPE=TEXT NAME="organization_name"></TD>

</TR>

<TR>

<TD>First Name:</TD>

<TD><INPUT TYPE=TEXT NAME="first_name"></TD>

</TR>

<TR>

<TD>Last Name:</TD>

<TD><INPUT TYPE=TEXT NAME="last_name"></TD>

</TR>

<TR>

<TD>Street Address:</TD>

<TD><INPUT TYPE=TEXT NAME="address"></TD>

</TR>

<TR>

<TD>City:</TD>

<TD><INPUT TYPE=TEXT NAME="city"></TD>

</TR>

<TR>

<TD><b>*</b>State:</TD>

<TD><SELECT name=state>

<OPTION value='AL'>AL <OPTION value='AK'>AK <OPTION value='AZ'>AZ<OPTION value='AR'>AR

<OPTION value="CA" selected>CA <OPTION value='CO'>CO <OPTION value='CT'>CT

<OPTION value='DE'>DE <OPTION value='FL'>FL <OPTION value='GA'>GA <OPTION value='HI'>HI

<OPTION value='ID'>ID <OPTION value='IL'>IL <OPTION value='IN'>IN <OPTION value='IO'>IO

<OPTION value='KS'>KS <OPTION value='KY'>KY <OPTION value='LA'>LA <OPTION value='ME'>ME

<OPTION value='MD'>MD <OPTION value='MA'>MA <OPTION value='MI'>MI <OPTION value='MN'>MN

<OPTION value='MS'>MS <OPTION value='MO'>MO <OPTION value='MT'>MT <OPTION value='NE'>NE

<OPTION value='NV'>NV <OPTION value='NH'>NH <OPTION value='NJ'>NJ <OPTION value='NY'>NY

<OPTION value='NC'>NC <OPTION value='ND'>ND <OPTION value='OH'>OH <OPTION value='OK'>OK

<OPTION value='OR'>OR <OPTION value='PA'>PA <OPTION value='RI'>RI <OPTION value='SC'>SC

<OPTION value='SD'>SD <OPTION value='TN'>TN <OPTION value='TX'>TX <OPTION value='UT'>UT

<OPTION value='VT'>VT <OPTION value='VA'>VA <OPTION value='WA'>WA <OPTION value='WV'>WV<OPTION value='WI'>WI <OPTION value='WY'>WY </SELECT></TD>

</TR>

<TR>

<TD>Zip Code:</TD>

<TD><INPUT TYPE=TEXT NAME="zip"></TD>

</TR>

<TR>

<TD>Phone: (Optional and will not be given out to other organizations)</TD>

<TD>(<INPUT TYPE=TEXT NAME="area_code" size=3>)<INPUT TYPE=TEXT NAME="city_code" size=3>-<INPUT TYPE=TEXT NAME="phone" size=4></TD>

</TR>

<TR>

<TD>E-mail: (this will only be used to provide you with Climate Protection Registry updates)</TD>

<TD><INPUT TYPE=TEXT NAME="email"></TD>

</TR>

<TR>

<TD>Date: (MM/YY)</TD>

<TD><INPUT TYPE=TEXT NAME="month" size=2>/<input type=text name=year size=2></TD>

</TR>

<TR>

<TD><b>*</b>Number of permanent residents in your household</TD>

<TD><INPUT TYPE=TEXT NAME="members"></TD>

</TR>

<TR>

<TD><b>*</b>Number of cars in your household:</TD>

<TD><INPUT TYPE=TEXT NAME="cars"></TD>

</TR>

<TR>

<TD colspan=2><center><input type=button value="Next Page -->" onclick="save();location.href='carb2.html'"></center><p>

<b>*</b> Required in order to calculate<p>

</TD>

</TR>

</FORM>

</TABLE></CENTER>

<center>[Note: Individual information will be treated confidentially and not released to any party]</center>

</BODY>

</HTML>

----------------------------------------------------------------------

 

carb2.html:

<HTML>

<HEAD>

<TITLE>Carbon Reduction Pledge Form</TITLE>

<SCRIPT LANGUAGE=JAVASCRIPT>

done=false;

elect_coeff= new Array();

elect_coeff['AL']=1.347; elect_coeff['AK']=1.241;

elect_coeff['AR']=1.310; elect_coeff['CA']=0.305; elect_coeff['CO']=2.048;

elect_coeff['CT']=1.136; elect_coeff['DE']=1.857; elect_coeff['DC']=1.352;

elect_coeff['FL']=1.432; elect_coeff['GA']=1.420; elect_coeff['HI']=1.817;

elect_coeff['ID']=1.292; elect_coeff['IL']=1.177; elect_coeff['IN']=2.134;

elect_coeff['IA']=1.982; elect_coeff['KS']=1.741; elect_coeff['KY']=1.986;

elect_coeff['LA']=1.330; elect_coeff['ME']=0.900; elect_coeff['MD']=1.352;

elect_coeff['MA']=1.236; elect_coeff['MI']=1.742; elect_coeff['MN']=1.587;

elect_coeff['MS']=1.320; elect_coeff['MO']=1.900; elect_coeff['MT']=1.291;

elect_coeff['NE']=1.407; elect_coeff['NV']=1.664; elect_coeff['NH']=0.745;

elect_coeff['NJ']=0.566; elect_coeff['NM']=2.099; elect_coeff['NY']=0.796;

elect_coeff['NC']=1.244; elect_coeff['ND']=2.190; elect_coeff['OH']=1.815;

elect_coeff['OK']=1.768; elect_coeff['OR']=0.176; elect_coeff['PA']=1.292;

elect_coeff['RI']=0.921; elect_coeff['SC']=0.815; elect_coeff['SD']=0.718;

elect_coeff['TN']=1.245; elect_coeff['TX']=1.547; elect_coeff['UT']=1.939;

elect_coeff['VT']=0.017; elect_coeff['VA']=1.088; elect_coeff['WA']=0.183;

elect_coeff['WV']=1.973; elect_coeff['WI']=1.792; elect_coeff['WY']=2.193;

function entry(name, value, coeff, hasaQ) {

this.name=name;

this.value=value;

this.coeff=coeff;

this.hasaQ=hasaQ;

}

function toPounds(entry) {

if (entry.value.substring(0,3)=="mpg") {

miles=document.data.elements["car"+entry.value.substring(3,entry.value.length)].value;

pounds=(miles/((document.data.elements[entry.value].value)?document.data.elements[entry.value].value:1)*entry.coeff);

}

else {

pounds=document.data.elements[entry.value].value*entry.coeff*.2727;

}

return Math.round(pounds*10)/10;

}

function writeentries(entries) {

for (i=0;i<entries.length;i++) {

if (entries[i].value.substring(0,3)=="car") {

document.writeln("<TR><TD colspan=4><b>Information for car "+entries[i].value.substring(3,entries[i].value.length)+":</b></TD></TR>"); }

document.writeln("<TR>");

document.writeln("<TD"+((entries[i].hasaQ)?"":" Colspan=2")+">"+entries[i].name+":</TD>");

if (entries[i].hasaQ) {

document.writeln("<TD><a href=\"javascript:question('"+entries[i].value+"')\"><img src='howto.gif' border=0></a></TD>"); }

document.write("<TD"+((entries[i].coeff)?"":" Colspan=2")+"><INPUT TYPE=TEXT NAME='"+entries[i].value+"' size=15 ");

if (entries[i].coeff) {

document.write("onchange=document.data.elements['"+entries[i].value+"_lbs'].value=toPounds(entries["+i+"]);calculate(entries)"); }

document.writeln("></td>");

if (entries[i].coeff) {

document.writeln("<TD><INPUT TYPE=TEXT READONLY NAME="+entries[i].value+"_lbs size=15></TD>"); }

document.writeln("</TR>");

}

}

function calculate(entries) {

total=0;

for (i=0; i<entries.length; i++) {

if (entries[i].coeff) total+=parseInt((document.data.elements[entries[i].value+"_lbs"].value)?document.data.elements[entries[i].value+"_lbs"].value:0);

}

document.data.total.value=Math.round((total/((document.data.members.value!=0)?document.data.members.value:1))*10)/10;

}

function question(item) {

questionpage=window.open('','','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizeable=yes,copyhistory=no,width=420,height=450');

questionpage.document.clear();

questionpage.document.writeln ("<body bgcolor=#ddddd><center>");

questionpage.document.writeln ("<table width=95% height=95% bgcolor=#ffffff><tr><td>");

if (item=="electricity") {

questionpage.document.writeln ("In order to determine your electricity usage, you need to consult your electric bills. Total power used for the month is generally listed on it.<p>");

questionpage.document.writeln ("<form>If you would like to calculate your average monthly use, enter your yearly usage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='opener.document.data.electricity.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;'></form>");

}

if (item=="gas") {

questionpage.document.writeln ("In order to determine your gas usage, you need to consult your gas bills. Total power used for the month is generally listed as Therms. If your bill is listed in BTUs, devide by 100,000 to find out your usage in Therms.<p>");

questionpage.document.writeln ("<form>If you would like to calculate your average monthly use, enter your yearly usage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='opener.document.data.gas.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;'></form>");

}

if (item=="oil") {

questionpage.document.writeln ("<form>If you know how many gallons you buy each year, you can calculate your average monthly use by entering your yearly usage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='opener.document.data.oil.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;'></form>");

}

if (item=="propane") {

questionpage.document.writeln ("<form>If you know how many gallons you buy each year, you can calculate your average monthly use by entering your yearly usage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='opener.document.data.propane.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;'></form>");

}

if (item=="wood") {

questionpage.document.writeln ("<form>If you know how many cords you buy each year, you can calculate your average monthly use by entering your yearly usage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick=\"opener.document.data.wood.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;\"></form>");

}

if (item.substring(0,3)=="car") {

questionpage.document.writeln ("If you don't know what your average mileage is, you can find it out if you know <br>1) Your current odometer reading <br>2) What the odometer read when you bought it and <br>3) How many years you've owned your car.<p>");

for (i=1;i<=document.data.cars.value;i++) {

questionpage.document.writeln ("Car "+i+":<br><form name=car"+i+">Current reading:<input type=text name=current><br>");

questionpage.document.writeln ("Original reading:<input type=text name=former><br>");

questionpage.document.writeln ("Years Owned:<input type=text name=years><br>");

questionpage.document.writeln ("<b>Average monthly milage:</b><input type=text name=average><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='document.car"+i+".average.value=Math.round((document.car"+i+".current.value-document.car"+i+".former.value)/(document.car"+i+".years.value*12));opener.document.data.car"+i+".value=Math.round((document.car"+i+".current.value-document.car"+i+".former.value)/(document.car"+i+".years.value*12))'></form><p>");

}

}

if (item.substring(0,3)=="mpg") {

questionpage.document.writeln ("Often you can get you gas efficiency from the information provided to you when you buy a car. In California, new cars now have have their miles per gallons reported to the buyer.<p>");

questionpage.document.writeln ("If you don't have that information, an easy way to calculate your efficiency is by dividing the miles your car can go between fill-ups by the size of your tank. Here's a calculator to do it for you:<p>");

for (i=1;i<=document.data.cars.value;i++) {

questionpage.document.writeln ("Car "+i+":<br><form name=efficiency"+i+">Miles between fillups:<input type=text name=miles><br>");

questionpage.document.writeln ("Gallons needed to fill up tank:<input type=text name=gallons><br>");

questionpage.document.writeln ("<b>Miles per gallon:</b><input type=text name=mpg><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick='document.efficiency"+i+".mpg.value=Math.round(document.efficiency"+i+".miles.value/document.efficiency"+i+".gallons.value);opener.document.data.mpg"+i+".value=Math.round(document.efficiency"+i+".miles.value/document.efficiency"+i+".gallons.value)'></form><p>");

}

}

if (item=="airplane") {

questionpage.document.writeln ("If you still have the itineraries from your plane trips, it will list the mileage to and from each location<p>");

questionpage.document.writeln ("<form>If you know how many miles you travel each year, you can calculate your average monthly miles by entering your yearly mileage here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick=\"opener.document.data.airplane.value=Math.round(this.form.year.value/12);this.form.month.value=Math.round(this.form.year.value/12);\"></form>");

questionpage.document.writeln ("<\form>");

}

if (item=="legs") {

questionpage.document.writeln ("If you still have the itineraries from your plane trips, you can add up all the legs for each trip. A leg is each time the plane takes off and lands. For instance: if you take a trip to New York with stops in Pheonix and Cleveland, it would count as 3 trip segments each way, or 6 trip segments round trip<p>");

questionpage.document.writeln ("<form>If you know how many trip segments you took last year, you can calculate your average monthly miles by entering your annual total here:");

questionpage.document.writeln ("<input type=text size=15 name=year><br>");

questionpage.document.writeln ("Monthly Ave:<input type=text size=15 name=month><br>");

questionpage.document.writeln ("<input type=button value='Calculate' onclick=\"opener.document.data.legs.value=Math.round(this.form.year.value*1000/12)/1000;this.form.month.value=Math.round(this.form.year.value*1000/12)/1000;\"></form>");

}

questionpage.document.writeln ("</td></tr></table></center></body>");

}

function explain() {

explainpage= window.open('','','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizeable=yes,copyhistory=no,width=420,height=450');

explainpage.document.clear();

explainpage.document.writeln ("<body bgcolor=#ddddd><center>");

explainpage.document.writeln ("<table width=95% height=95% bgcolor=#ffffff><tr><td>");

explainpage.document.writeln ("Our numbers were compiled from a variety of sources, both in print and on-line<br>");

explainpage.document.writeln ("<hr>To calculate the carbon output that your use of electricity generates, we converted from Kilowatt hours to pounds of carbon dioxide using the following conversions, based on state:<br>");

explainpage.document.writeln ("<table border=0><tr>");

j=0;

for (i in elect_coeff) {

explainpage.document.writeln("<td>"+i+": "+ elect_coeff[i].toString()+"</td>");

if (!((++j)%3)) {explainpage.document.writeln("</tr><tr>");}

}

explainpage.document.writeln ("</tr></table>");

explainpage.document.writeln ("<hr>In order to find out how much carbon dioxide you generate from using natural gas, we use the conversion factor of 1 Therm of gas equaling 11.68 pounds of carbon dioxide");

explainpage.document.writeln ("<hr>The convesion factor for heating oil is 26.03 pound of CO<sub>2</sub> for 1 gallon of oil");

explainpage.document.writeln ("<hr>For propane, each gallon used adds 13.18 pounds of carbon dioxide to the air");

explainpage.document.writeln ("<hr>Each cord of wood that you burn is equivalent to 3,814 pounds of carbon dioxide. Pretty dirty heat.");

explainpage.document.writeln ("<hr>In order to find out how much CO<sub>2</sub> your car emits, we devide miles driven by miles per gallon and get the total gallons of gas you use. Gallons of gasoline are then converted to pounds of carbon by the ratio of 1 gallon of gas equaling 18.9189 pounds of carbon dioxide");

explainpage.document.writeln ("<hr>Each mile that you travel in an airplane injects .638893 pounds of carbon dioxide straight into the upper atmospere, and that's true for each of the 300 people on the plane. Additional, each take off and landing uses enough fuel to add 364.9 more pounds of carbon dioxide per person");

explainpage.document.writeln ("<hr>Finally, your total carbon dioxide is muliplied by .2727 to get pounds of carbon. Total pounds of carbon are a more accurate reflection of just what is being added to the atmosphere, since the 2 oxygens in carbon dioxide were already present in the air.<br>Your total household carbon is then devided by the number of individuals living in your house to get a per person total");

explainpage.document.writeln ("</td></tr></table></body>");

}

</SCRIPT>

</HEAD>

<BODY BGCOLOR=#DDDDDD>

<CENTER>

<TABLE BORDER=0 BGCOLOR=#FFFFFF WIDTH=85%>

<TR>

<TD>

<B>Thank you for taking the time to fill out this form. If you are need help filling out a field, hit the <img src="howto.gif"> button for more info.</B>

</TD>

</TR>

</TABLE>

<FORM NAME="data" method=post action="http://humboldt.edu/cgi-bin/cgiwrap/jpz2/ceed/carbon.cgi" onsubmit="if(!done){return false;}">

<INPUT TYPE=hidden name='id'>

<INPUT TYPE=hidden name='organization_name'>

<INPUT TYPE=hidden name='first_name'>

<INPUT TYPE=hidden name='last_name'>

<INPUT TYPE=hidden name='address'>

<INPUT TYPE=hidden name='city'>

<INPUT TYPE=hidden name='state'>

<INPUT TYPE=hidden name='zip'>

<INPUT TYPE=hidden name='area_code'>

<INPUT TYPE=hidden name='city_code'>

<INPUT TYPE=hidden name='phone'>

<INPUT TYPE=hidden name='email'>

<INPUT TYPE=hidden name='month'>

<INPUT TYPE=hidden name='year'>

<INPUT TYPE=hidden name='members'>

<INPUT TYPE=hidden name='cars'>

<TABLE BORDER=0 BGCOLOR=#FFFFFF WIDTH=85%>

<TR><TD></TD><TD></TD><TD></TD><TD>Pounds of Carbon</TD></TR>

<SCRIPT LANGUAGE=JAVASCRIPT>

for (i=0;i<16;i++) {

document.data.elements[i].value=window.parent.save.document.forms[0].elements[i].value;

}

entries= new Array();

entries[0]= new entry("Monthly electricity use in Kilowatt hours", 'electricity', elect_coeff[document.data.state.value], true);

entries[1]= new entry("Current electric meter reading", 'electric_reading', 0, false);

entries[2]= new entry("Monthly gas use in Therms", 'gas', 11.68, true);

entries[3]= new entry("Current gas meter reading", 'gas_reading', 0, false);

entries[4]= new entry("Monthly heating oil use in gallons", 'oil', 26.03, true);

entries[5]= new entry("Monthly propane use in gallons", 'propane', 13.18, true);

entries[6]= new entry("Cords of wood used each month", 'wood', 3814, true);

for (i=1; i<document.data.cars.value*2; i+=2) {

entries[i+5]= new entry("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Average miles driven per month", 'car'+Math.round(i/2), 0, true);

entries[i+6]= new entry("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Average miles per gallon your car gets", 'mpg'+Math.round(i/2), 18.9189, true);

}

entries[i+5]= new entry("Average miles flown in an airplane per month", 'airplane', .638893, true);

entries[i+6]= new entry("Average number of flight segments taken each month", 'legs', 364.9, true);

writeentries(entries);

</SCRIPT>

<TR>

<TD COLSPAN=2 valign=top><B>TOTAL LBS OF CARBON PER PERSON:</B>

</TD>

<TD></TD>

<TD><INPUT TYPE=TEXT NAME="total" readonly size=15><br>

<i>U.S. Ave is 415 lbs.<br>of carbon a month</i><br>

<INPUT TYPE=BUTTON VALUE="Calculate!" onclick="calculate(entries);done=true;">

</TD>

</TR>

<TR>

<TD COLSPAN=4 ALIGN=CENTER><input type=submit VALUE="Submit!" onclick="done=true;"><p>

<table border =1 width=25%>

<tr>

<td>

<table border=0>

<tr>

<td><a href="javascript:explain()">How this was calculated</a></td>

<td><a href="javascript:explain()"><img border=0 src=calculator.gif></a></td>

</tr>

</table>

</td>

</tr>

</table>

</TD>

</TR>

</TABLE></CENTER>

<center>[Note: Individual information will be treated confidentially and not released to any party]</center>

</FORM>

</BODY>

</HTML>

----------------------------------------------------------------------

save.html:

<HTML>

<BODY BGCOLOR="#DDDDDD">

<FORM NAME=save>

<input type=text name="id">

<input type=text name="organization_name">

<input type=text name="first_name">

<input type=text name="last_name">

<input type=text name="address">

<input type=text name="city">

<input type=text name="state">

<input type=text name="zip">

<input type=text name="area_code">

<input type=text name="city_code">

<input type=text name="phone">

<input type=text name="email">

<input type=text name="month">

<input type=text name="year">

<input type=text name="members">

<input type=text name="cars">

</FORM>

</BODY>

----------------------------------------------------------------------

carbon.cgi:

#!/usr/bin/perl

#######################################################

#

#

# Carbon Release Pledge Recorder

# ver0.2

# Jared Zyskowski for CEED

# 5/25/01

#

#######################################################

@list=("id","organization_name","first_name","last_name","address","city","state","zip","area_code","city_code","phone","email","month","year","members","cars","electricity","electric_reading","gas","gas_reading","oil","propane","wood","car1","mpg1","car2","mpg2","car3","mpg3","car4","mpg4","car5","mpg5","car6","mpg6","airplane","legs","total");

%list_names=("id"=>"Organization ID Number", "organization_name"=>"Organization Name","first_name"=>"First Name","last_name"=>"Last Name","address"=>"Street Address","city"=>"City","state"=>"State","zip"=>"Zip Code","area_code"=>"Phone: Area Code","city_code"=>"Phone: City Code","phone"=>"Phone: Local Code","email"=>"E-mail address","month"=>"Date: Month","year"=>"Date: Year","members"=>"People in your house","cars"=>"Cars","electricity"=>"Kilowatts of electricity","electric_reading"=>"Electric Meter Reading","gas"=>"Therms of gas","gas_reading"=>"Gas meter reading","oil"=>"Gallons of heating oil","propane"=>"Gallons of Propane","car1"=>"Miles driven in Car #1","mpg1"=>"Miles per gallon for Car #1","car2"=>"Miles driven in Car #2","mpg2"=>"Miles per gallon for Car #2","car3"=>"Miles driven in Car #3","mpg3"=>"Miles per gallon for Car #3","car4"=>"Miles driven in Car #4","mpg4"=>"Miles per gallon for Car #4","car5"=>"Miles driven in Car #5","mpg5"=>"Miles per gallon for Car #5","car6"=>"Miles driven in Car #6","mpg6"=>"Miles per gallon for Car #6","airplane"=>"Miles flown in an airplane","legs"=>"Flight segments","total"=>"Total Pounds of Carbon");

#######################################################

&writefile;

&thanks;

#######################################################

sub writefile {

%data=&getcgivars;

@id=split(",",$data{'id'});

push(@id,"master");

foreach (@id) {

if (!(-e "tables/$_.txt")) {

open (FILE, ">tables/$_.txt") || &HTMLdie ("problem opening $_.txt");

$list=join ("\t",@list);

print FILE "$list\n";

close (FILE);

}

open (FILE, ">>tables/$_.txt") || &HTMLdie ("problem opening $_.txt");

foreach $item (@list) {

print FILE "$data{$item}\t";

}

print FILE "\n";

close (FILE);

}

}

sub thanks {

print "Content-type: text/html\n\n";

print <<EOF;

<html><head><title>Your Information</title></head>

<body bgcolor=#dddddd><center>

<table bgcolor=#ffffff width=85%><tr><td>Please review what you submitted. If there are any errors, use your browser's "back" button to return to the form and make the corrections. If everything is fine, then you can print this page for your records.

<p>---Thank you for taking the time to fill out this form

</td></tr></table><p></p>

<table bgcolor=#ffffff width=85%><font face="Courier">

EOF

foreach $item (@list) {

if ($data{$item} ne "") {

print "<tr><td width=50%>$list_names{$item}";

print "."x(30-length($list_names{$item}));

print "</td><td with=50%>$data{$item}</td></tr>\n";

}

}

print "</font></table>"

}

 

sub getcgivars {

local($in, %in) ;

local($name, $value) ;

if ($ENV{'REQUEST_METHOD'} eq 'GET') {

$in= $ENV{'QUERY_STRING'} ;

} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {

if ($ENV{'CONTENT_TYPE'}=~ m#^application/x-www-form-urlencoded$#i) {

$ENV{'CONTENT_LENGTH'}

|| &HTMLdie("No Content-Length sent with the POST request.") ;

read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ;

} else {

&HTMLdie("Unsupported Content-Type: $ENV{'CONTENT_TYPE'}") ;

}

} else {

&HTMLdie("Script was called with unsupported REQUEST_METHOD.") ;

}

 

 

foreach (split('&', $in)) {

s/\+/ /g ;

($name, $value)= split('=', $_, 2) ;

$name=~ s/%(..)/chr(hex($1))/ge ;

$value=~ s/%(..)/chr(hex($1))/ge ;

$in{$name}.= "\0" if defined($in{$name}) ; # concatenate multiple vars

$in{$name}.= $value ;

}

return %in ;

}

 

sub HTMLdie {

local($msg,$title)= @_ ;

$title || ($title= "CGI Error") ;

print <<EOF ;

Content-type: text/html

<html>

<head>

<title>$title</title>

</head>

<body>

<h1>$title</h1>

<h3>$msg</h3>

</body>

</html>

EOF

exit ;

}