#!/usr/bin/perl #$mail_prog = '/usr/sbin/sendmail' ; &GetFormInput; $sp = $field{'sp'}; if ($sp eq "" || $sp == 0 || $sp> 4) { $sp=1;} use Mysql; $DBHOST = "AEGS2.db.4473351.hostedresource.com"; $DBNAME = "AEGS2"; $DBUSER = "AEGS2"; $DBPASS = "Cbears55"; $DB = Mysql->connect($DBHOST, $DBNAME, $DBUSER, $DBPASS); $DB->selectdb($DBNAME, $DB); $execute = $DB->query("Select COUNT(text) from tips"); $numt = $execute->fetchrow(); while ($y < 10) { $id=int(rand($numt)+1); $execute = $DB->query("SELECT text FROM tips where id=$id"); $v = $execute->fetchrow(); if (length($v) > 10) { $text=$v; $y=10;} $y++; } $prodfile="../data/aegsprods.txt"; $datafile="../data/earthupl.txt"; open (FILE,"$prodfile"); @prod=; close(FILE); $prsz=@prod; open (FILE,"$datafile"); @inv=; close (FILE); $invsz=@inv; for ($i=0;$i<$invsz-1;$i++) { for ($j=0;$j<$invsz-1-$i;$j++) { @d = split (/\|/o, $inv[$j]); @dx = split (/\|/o, $inv[$j+1]); if ($dx[2]=~/^$sp/ && $d[2]!~/^$sp/) { $t=$inv[$j+1]; $inv[$j+1]=$inv[$j]; $inv[$j]=$t; } } @d = split (/\|/o, $inv[0]); if ($d[2] == $sp) { $i=$invsz;} } $ti[1]="Household"; $ti[2]="Lights"; $ti[3]="Kits"; $ti[4]="Inventors Corner"; $tx[1]="Household products for daily use that will help save energy. There are dozens of ways you can save energy and reduce carbon emissions by changing the household goods that you use. Fluorescent bulbs, LED lights, solar powered gadgets, and rechargeable batteries are just a few."; $tx[2]="Switching to compact fluorescent (CFL) or LED lights is a simple way to help reduce the demand for fossil fuel power and CO2 emissions. AEGS has an attractive selection of bulbs for your everyday needs that typically reduce your use of watts by 80% with an average life of 6 years when used normally. From baby’s rooms to ceiling fans we have bulbs for you. "; $tx[3]="The ultimate solution to the energy and global warming crisis will come from the power of the human mind. These kits will inspire you to understand how alternative energy works, and lead you in the direction of finding solutions."; $tx[4]="For those ready to take the next step and begin building their own alternative energy solutions, we offer an array of the components you will need to make that happen."; &header; for ($i=0;$i<$invsz;$i++) { chomp($inv[$i]); @d = split (/\|/o, $inv[$i]); if ($d[1] > 0) { @dx = split (/\|/o, $inv[$i+1]); $dx[2]=substr($dx[2],0,1); for ($j=0;$j<$prsz;$j++) { @p = split (/\|/, $prod[$j]); if ($p[0] eq $d[0]) { &prtitem;} } } } &footer; goto DONE; ERR:; print "Location: http://www.alternativeenergygeneralstore.com\nURI: http://www.alternativeenergygeneralstore.com\n\n"; DONE:; sub prtitem { @pdesc = split (/\|/, $prod[$j]); chomp($pdesc[10]); $pdesc[2] =~s/\"//g; $pdesc[1] =~s/\"//g; $pic=lc($pdesc[0]).".jpg"; print ""; print "
$pdesc[0]"; print "$pdesc[1]
\n"; print "Item no: $pdesc[0]
\n"; print "$pdesc[2]
\n"; print ""; print "In stock for immediate shipment.
\n"; print "Suggested retail pr: \$$pdesc[4]
\n"; $prout=sprintf("\$%.2f",$pdesc[3]); print "Our Price: $prout
"; print "$pdesc[11]\n"; print "
\n"; print "
\n"; if ($dx[2] ne $hdg) { $hdg=$dx[2]; print "Back to the top
\n"; print "
\n"; print "
$ti[$hdg]

\n"; print "$tx[$hdg]\n";} } sub header { print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "Alternative Energy General Store\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "
\n"; print "
\n"; print "

Alternative Energy General Store

\n"; print "
Green Tip #$id
\n"; print "
$text
\n"; print "
\n"; print "
\n"; @d = split (/\|/, $inv[0]); $hdg=substr($d[2],0,1); print "
$ti[$hdg]

\n"; print "
\n"; print "$tx[$hdg]
\n"; } sub footer{ print "
\n"; } sub GetFormInput { (*fval) = @_ if @_ ; local ($buf); if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN,$buf,$ENV{'CONTENT_LENGTH'}); } else { $buf=$ENV{'QUERY_STRING'}; } if ($buf eq "") { return 0 ; } else { @fval=split(/&/,$buf); foreach $i (0 .. $#fval){ ($name,$val)=split (/=/,$fval[$i],2); $val=~tr/+/ /; $val=~ s/%(..)/pack("c",hex($1))/ge; $name=~tr/+/ /; $name=~ s/%(..)/pack("c",hex($1))/ge; if (!defined($field{$name})) { $field{$name}=$val; } else { $field{$name} .= ",$val"; #if you want multi-selects to goto into an array change to: #$field{$name} .= "\0$val"; } } } return 1; }