#!/usr/local/bin/perl
use strict;
use CGI;
use DBI;
use Switch;

my $q = CGI->new;
#survey hashes
my %cc_hash;
my %st_hash;
my %ap_hash;
my %os_hash;
my %sim_hash;
my %cp_hash;
my %sx_hash;
my %pilot_hash;
my %ac_hash;

#hash vars

my $cc;		# country code
my $ccode;	# country code from db
my $ccname;	# country name
my $ac;		# aircraft code
my $ax;		# axes
my $acmo;
my $flag;
my $err;
my $count;
my $v0;		#user_ID
my $v1;		#city
my $v2;		#state
my $v3;		#country
my $v4;		#airport
my $v5;		#aircraft_manufacture
my $v6;		#aircraft_manufacture_opt
my $v7;		#aircraft_type
my $v8;		#platform
my $v9;		#software
my $v10;	#network	FS
my $v11;	#network	ethernet
my $v12;	#network	afdx
my $v13;	#network	mil 1553
my $v14;	#network	airnic
my $v15;	#Base	Hydro
my $v16;	#Base	Phematics
my $v17;	#Base	Motors
my $v18;	#Axes
my $v19;	#cockpit
my $v20;	#Pilot
my $v21;	#AC_flown

my $vt10 = 0;
my $vt11 = 0;
my $vt12 = 0;
my $vt13 = 0;
my $vt14 = 0;
my $vt15 = 0;
my $vt16 = 0;
my $vt17 = 0;
my $vt18 = 0;
my $vt19;
my $vt20;
my $vt21;
my $cp1;
my $cp2;
my $cp3;
my $cp4;
my $cpt1;
my $cpt2;
my $cpt3;
my $cpt4;
my $cpt5;
my $ax1;
my $ax2;
my $ax3;
my $ax4;
my $vm1;
my $vm2;

my $p1;
my $p2;
my $p3;
my $p4;
my $p5;

my $acf1;
my $acf2;
my $acf3;
my $acf4;
my $acf5;
my $acf6;
my $acf7;
my $acf8;
my $acf9;
my $acf10;

my $os1;
my $os2;
my $os3;
my $os4;
my $os5;

my $sim1;
my $sim2;
my $sim3;
my $sim4;
my $sim5;
my $sim6;
my $sim7;
my $sim8;
my $sim9;
my $sim10;
my $sim11;
my $sim12;
my $sim13;
my $sim14;



print "Content-type: text/html\n\n";
print  <<ENDHEADER;
<html><head><title>Phoenix Aerospace - Simulation Group</title>
	<meta http-equiv=pragma content=no-cache>
	<meta http-equiv=cache-control content=no-cache>
	<style type="text/css">
		.menus A:link {text-decoration: none}
		.menus A:visited {text-decoration: none}
		.menus A:active {text-decoration: none}
		.menus A:hover {text-decoration: none;} </style>
	<SCRIPT LANGUAGE="JavaScript">
		var home_on  = "../images/buttons/hover/home.gif";
		var home_off  = "../images/buttons/home.gif";

		function activate(imgName) {
			document.images[imgName].src = eval(imgName + "_on");}

		function deactivate(imgName) {
			document.images[imgName].src = eval(imgName + "_off");}</SCRIPT> </head>
<body style="background-color: rgb(232, 232, 232);">
<table border="0" cellpadding="3" cellspacing="3" style="width: 900px;"><tbody>
<tr>
<td style="width: 100%;"><img src="../images/phaero.jpg"><br>
<img src="../images/simgrp.jpg"></td>
<td align="right" width="70%">

<table style="width: 110px; height: 74px;" border="0"cellpadding="0" cellspacing="3"><tbody>
   <tr>
        <td><b><!--#echo var="DATE_LOCAL"--></b></td></tr>
   <tr>
       <td width=100px align=center  style="vertical-align: top;">
       <A HREF="../index.shtml" onMouseOver="activate('home')"  onMouseOut="deactivate('home')" >
<img src="../images/buttons/home.gif" name=home border = 0></A><br></td></tr>
</tbody></table>

</td></tr>
</tbody></table>

<table ="" cellpadding="0" cellspacing="3" style="width: 870px;"><tbody>
<tr>
<!--#include virtual="../menus/main.mnu"-->
</tr>
</tbody></table>
ENDHEADER

$err =0;
my $dbh=DBI->connect("DBI:mysql:phnxaero:localhost","root");
# First Test to see if we have DB connection
if (defined ($dbh)) {
	#get every thing from the survey
	#vars 
	

	my $count = 1;
	my $sth = $dbh->prepare("select * from user_survey");
	
	$sth->execute();
	print "<center><font size=+2 color=RED><b>Simulation Survey Results</b></font><br>";
	print "<i>To take part in this survey you must <a href=register/index.shtml>register!</a></i><p>";
	print "<table cellpadding=3 cellspacing=3 border=1><tbody>";
	print "<tr><td align=center colspan=20><b>Raw Data</b></td></tr>";
	print "<tr><td><br></td><td colspan=2 >Country</td><td>State</td>";
	print "<td>Airport</td><td>Manufacture</td><td>Other Manufacture</td><td>Type</td>";
	print"<td>O/S</td><td>SIM</td><td>MS/FS<br>NET</td><td>Ethernet</td>";
	print"<td>AFDX</td><td>1553</td><td>429</td><td>Hydraulics</td>";
	print"<td>Pneumatics</td><td>Electric<br>Motors</td><td>Axes</td><td>Cockpit</td>";
	print"<td>Pilot?</td><td>Planes Flown</td></tr>";
	while (($v0, $v1, $v2, $v3, $v4, $v5, $v6, $v7, $v8, $v9, $v10, $v11, $v12, $v13, $v14, $v15, $v16, $v17, $v18, $v19, $v20, $v21 ) = $sth->fetchrow()) {
		my $sth_cflag = $dbh->prepare("select flag from countrys where country_code = ?");
		$sth_cflag->execute($v3);
		($flag ) = $sth_cflag->fetchrow();
		if ($v3 ne '' ) { ++ $cc_hash{$v3}}; # country hash 
		if ($v2 ne '' ) { ++ $st_hash{$v2}}; # state hash
		if ($v8 ne '' ) { ++ $os_hash{$v8}}; 
		if ($v9 ne '' ) { ++ $sim_hash{$v9}};
		if ($v10 eq 'T') { $vt10++;}
		if ($v11 eq 'T') { $vt11++;}
		if ($v12 eq 'T') { $vt12++;}
		if ($v13 eq 'T') { $vt13++;}
		if ($v14 eq 'T') { $vt14++;}
		if ($v15 eq 'T') { $vt15++;}
		if ($v16 eq 'T') { $vt16++;}
		if ($v17 eq 'T') { $vt17++;}
		if ($v18 ne '' ) { ++ $sx_hash{$v18}}
		if ($v19 ne '' ) { ++ $cp_hash{$v19}};
		if ($v20 != 0 ) { ++ $pilot_hash{$v20}};
		if ($v21 != 0 ) { ++ $ac_hash{$v21}};
		my $flagstring = 'images/ISO_3166-1_files/$flag';

		print "<tr><td>$count</td>";
		print "<td><img src=images/ISO_3166-1_files/$flag></td>";
		print "<td>$v3</td>"; #Country
		print "<td>$v2</td>"; #State
		print "<td>$v4</td>"; #airport
		print "<td align=center>$v5 &nbsp;</td>"; #manufac
		print "<td align=center>$v6 &nbsp;</td>"; #other manufac
		print "<td>$v7</td>"; #type
		print"<td>$v8</td>";
		print "<td>$v9</td>";
		print "<td>$v10 &nbsp;</td>";
		print "<td>$v11 &nbsp;</td>";
		print"<td>$v12 &nbsp;</td>";
		print "<td>$v13 &nbsp;</td>";
		print "<td>$v14 &nbsp;</td>";
		print "<td>$v15 &nbsp;</td>";
		print"<td>$v16 &nbsp;</td>";
		print "<td>$v17 &nbsp;</td>";
		print "<td>$v18 &nbsp;</td>";
		print "<td>$v19 &nbsp;</td>";
		print "<td>$v20 &nbsp;</td>";
		print "<td>$v21 &nbsp;</td></tr>";
		$count++;
	}
	print "</tbody></table></center>";
} else { $err = 15;}

my $sth_m = $dbh->prepare("select * from manufacture");
$sth_m->execute();
while(( $vm1, $vm2 ) = $sth_m->fetchrow()){ 
	$ap_hash{$vm2} = $vm1;
}



print "<center><p><HR width=80%><br><table cellpadding=3 cellspacing=3 border=0><tbody><tr>";
print "<td valign=top><table cellpadding=3 cellspacing=3 border=1><tbody>";
print "<tr><td colspan=3 align=center><b>Survey Results by State (US/CAN )</b></td></tr>";
foreach $cc (sort keys %st_hash) {
	my $hashval = $st_hash{ $cc };
	my $sth_cflag = $dbh->prepare("select * from uscanstates where state = ?");
	$sth_cflag->execute($cc);
	($ccode, $ccname, $flag  ) = $sth_cflag->fetchrow();
print "<tr><td><img src=images/uscan/$flag> </td><td> $ccname </td><td> $hashval </td></tr>";
}
print "</tbody></table></td>";
print "<td valign=top><table cellpadding=3 cellspacing=3 border=1><tbody>";
print "<tr><td colspan=3 align=center><b>Survey Results by Country</b></td></tr>";
foreach $cc (sort keys %cc_hash) {
	my $hashval = $cc_hash{ $cc };
	my $sth_cflag = $dbh->prepare("select country_code, flag, country from countrys where country_code = ?");
	$sth_cflag->execute($cc);
	($ccode, $flag, $ccname  ) = $sth_cflag->fetchrow();
print "<tr><td><img  width=22px height=12px src=images/ISO_3166-1_files/$flag> </td><td> $ccname </td><td> $hashval </td></tr>";
}
my $sth_ac = $dbh->prepare("select count(*), aircraft_manufacture, aircraft_manufacture_opt, aircraft_type from user_survey group by aircraft_manufacture, aircraft_type" );
$sth_ac->execute();
my $acc;
my $acm;
my $act;
print "</tbody></table></td></tr></tbody></table>";


print "<p><HR width=80%><br>";
print "<p><center><table cellspacing=3 cellpadding=3 border=0><tbody>";
print" <tr><td valign=top><table cellpadding=3 cellspacing=3 border=1><tbody>";
print "<tr><td colspan=4 align=center><b>Survey Results by Aircraft Types</b></td></tr>";
my $sth_acm = $dbh->prepare("select  man_name from manufacture where man_id = ?");
while  (($acc, $acm, $acmo, $act) = $sth_ac->fetchrow()) {
$sth_acm->execute( $acm );
my $ac_name  = $sth_acm->fetchrow();

	if ( $acm ne 'OT' ) {
		print "<tr><td>$acc</td><td> $ac_name </td><td>&nbsp;</td><td>$act</td></tr>";
	}else{
		print "<tr><td>$acc</td><td> $ac_name </td><td> $acmo </td><td>$act</td></tr>";
	}}
print "</tbody></table></td>";

print" <td valign=top><table cellpadding=3 cellspacing=3 border=1 bgcolor=pink><tbody>";
print "<tr><td colspan=2 align=center><b>Survey Results for Pilots </b></td></tr>";
foreach $cc (sort keys %pilot_hash) {
	my $hashval = $pilot_hash{ $cc };
	if ($cc == 1) {$p1 = $hashval;}
	if ($cc == 2) {$p2 = $hashval;}
	if ($cc == 3) {$p3 = $hashval;}
	if ($cc == 4) {$p4 = $hashval;}
	if ($cc == 5) {$p5 = $hashval;}}
print "<tr><td>NO</td><td>$p1 &nbsp;</td></tr>";
print "<tr><td>YES: Recreational Licence</td><td>$p2 &nbsp;</td></tr>";
print "<tr><td>YES: Private license</td><td>$p3 &nbsp;</td></tr>";
print "<tr><td>YES: Commercial Licence</td><td>$p4 &nbsp;</td></tr>";
print "<tr><td>YES: Military Wings</td><td>$p5 &nbsp;</td></tr>";
print "</tbody></table></td>";

print" <td valign=top><table cellpadding=3 cellspacing=3 border=1 bgcolor=pink><tbody>";

print "<tr><td colspan=2 align=center><b>Survey Results Aircraft Types Flown</b></td></tr>";
foreach $cc (sort keys %ac_hash) {
	my $hashvalacf = $ac_hash{ $cc };
	if ($cc == 1) {$acf1 = $hashvalacf;}
	if ($cc == 2) {$acf2 = $hashvalacf;}
	if ($cc == 3) {$acf3 = $hashvalacf;}
	if ($cc == 4) {$acf4 = $hashvalacf;}
	if ($cc == 5) {$acf5 = $hashvalacf;}
	if ($cc == 6) {$acf6 = $hashvalacf;}
	if ($cc == 7) {$acf7 = $hashvalacf;}
	if ($cc == 8) {$acf8 = $hashvalacf;}
	if ($cc == 9) {$acf9 = $hashvalacf;}
	if ($cc == 10) {$acf10 = $hashvalacf;}}
print "<tr><td>Glider</td><td>$acf1 &nbsp;</td></tr>";
print "<tr><td>Ultra-Light</td><td>$acf2 &nbsp;</td></tr>";
print "<tr><td>Experimental</td><td>$acf3 &nbsp;</td></tr>";
print "<tr><td>Helicopter</td><td>$acf4 &nbsp;</td></tr>";
print "<tr><td>Single Engine</td><td>$acf5 &nbsp;</td></tr>";
print "<tr><td>Twin Engine</td><td>$acf6 &nbsp;</td></tr>";
print "<tr><td>Biz Jet</td><td>$acf10 &nbsp;</td></tr>";
print "<tr><td>Commercial Airliner</td><td>$acf7 &nbsp;</td></tr>";
print "<tr><td>Military Fighters</td><td>$acf8 &nbsp;</td></tr>";
print "<tr><td>Military Other</td><td>$acf9 &nbsp;</td></tr>";
print "</tbody></table></td></tr></tbody></table>";

print "<p><HR width=80%>";

print "<p><center><table cellspacing=3 cellpadding=3 border=0><tbody>";
print "<tr><td valign=top><table cellspacing=3 cellpadding=3 border=1><tbody>";
print "<tr><td colspan=2 align=center><b>Survey Results by Operating Systems</b></td></tr>";
foreach $cc (sort keys %os_hash) {
	my $hashval = $os_hash{ $cc };
	if ($cc == 98)	 {$os1 = $hashval;}
	if ($cc eq 'NT') {$os2 = $hashval;}
	if ($cc eq 'XP') {$os3 = $hashval;}
	if ($cc eq 'VI') {$os4 = $hashval;}
	if ($cc eq 'UL') {$os5 = $hashval;}}
print "<tr><td>UNIX</td><td> $os5 &nbsp;</td></tr>";
print "<tr><td>WIN 98</td><td> $os1  &nbsp;</td></tr>";
print "<tr><td>NT</td><td> $os2 &nbsp;</td></tr>";
print "<tr><td>XP</td><td> $os3  &nbsp;</td></tr>";
print "<tr><td>Vista</td><td> $os4  &nbsp;</td></tr>";
print "</tbody></table></td>";

print "<td valign=top><table cellspacing=3 cellpadding=3 border=1><tbody>";
print "<tr><td colspan=2 align=center><b>Survey Results by Simulator Software</b></td></tr>";
foreach $cc (sort keys %sim_hash) {
	my $hashval = $sim_hash{ $cc };
	if ($cc eq 'M4') {$sim1 = $hashval;}
	if ($cc eq 'M2') {$sim2 = $hashval;}
	if ($cc eq 'M0') {$sim3 = $hashval;}
	if ($cc eq 'F4') {$sim4 = $hashval;}
	if ($cc eq 'FG') {$sim5 = $hashval;}
	if ($cc eq 'MF') {$sim6 = $hashval;}
	if ($cc eq 'XP') {$sim7 = $hashval;}
	if ($cc eq 'PM') {$sim8 = $hashval;}
	if ($cc eq 'NG') {$sim9 = $hashval;}
	if ($cc eq 'SL') {$sim10 = $hashval;}
	if ($cc eq 'L3') {$sim11 = $hashval;}
	if ($cc eq 'OT') {$sim12 = $hashval;}
	if ($cc eq 'ST') {$sim13 = $hashval;}
	if ($cc eq 'MX') {$sim14 = $hashval;}}
print "<tr><td>FS X</td><td> $sim14  &nbsp;</td></tr>";
print "<tr><td>FS 2004</td><td> $sim1 &nbsp;</td></tr>";
print "<tr><td>FS 2002</td><td> $sim2  &nbsp;</td></tr>";
print "<tr><td>FS 2000</td><td> $sim3  &nbsp;</td></tr>";
print "<tr><td>Falcon</td><td> $sim4  &nbsp;</td></tr>";
print "<tr><td>Flight Gear</td><td> $sim5  &nbsp;</td></tr>";
print "<tr><td>Micro Flight</td><td> $sim6  &nbsp;</td></tr>";
print "<tr><td>Orbiter</td><td> $sim13  &nbsp;</td></tr>";
print "<tr><td>X-Plane</td><td> $sim7  &nbsp;</td></tr>";
print "<tr><td>Project Magenta</td><td> $sim8  &nbsp;</td></tr>";
print "<tr><td>NexGen</td><td> $sim9  &nbsp;</td></tr>";
print "<tr><td>Singer Link</td><td> $sim10  &nbsp;</td></tr>";
print "<tr><td>L3</td><td> $sim11  &nbsp;</td></tr>";
print "<tr><td>OTHER</td><td> $sim12  &nbsp;</td></tr>";
print "</tbody></table></td></tr></tbody></table>";
print "<p><HR width=80%>";

# store cockpit results
foreach $ac ( keys %cp_hash) {
	my $hashval1 = $cp_hash{ $ac };
	if ( $ac eq "SFO") { $cpt1 = $hashval1; }
	if ( $ac eq "SHW") { $cpt2 = $hashval1; }
	if ( $ac eq "MFD") { $cpt3 = $hashval1; }
	if ( $ac eq "MCS") { $cpt4 = $hashval1; }
	if ( $ac eq "ACS") { $cpt5 = $hashval1; }}

# store axes results
foreach $ax ( keys %sx_hash){
	my $hashvalsx = $sx_hash{ $ax };
	if ($ax == 1) { $ax1 = $hashvalsx; }
	if ($ax == 2) { $ax2 = $hashvalsx; }
	if ($ax == 3) { $ax3 = $hashvalsx; }
	if ($ax == 4) { $ax4 = $hashvalsx; }}
print <<ENDHTML;
<p><center><table cellspacing=3 cellpadding=3 border=0><tbody>
<tr><td valign=top>
	<table cellspacing=3 cellpadding=3 border=1><tbody>
	<tr>
		<td align=center colspan=2><b>Survey Results for Cockpits</b></td></tr>
	<tr>
		<td align=center> Software ONLY w/ Joystick/Throtles <br><i>Off the shelf</i> </td><td align=center>$cpt1 &nbsp;</td></tr>
	<tr>
		<td align=center>Some Custom Hardware</td><td align=center>$cpt2 &nbsp;</td></tr>
	<tr>
		<td align=center>Cockpit Mockup <br><i>not a desk</i></td><td align=center>$cpt3 &nbsp;</td></tr>
	<tr>
		<td align=center>Cockpit Section <br><i>Mockup</i></td><td align=center>$cpt4 &nbsp;</td></tr>	
		
	<tr>
		<td align=center>Cockpit Section <br><i>Real Plane</i></td><td align=center>$cpt5</td></tr></tbody></table></td>
<td valign=top><table cellspacing=3 cellpadding=3 border=1><tbody>
<tr>
<td align=center colspan=2><b>Survey Results for Networks</b></td></tr>
<tr>
	<td align=center>FS closed </td><td align=center>$vt10 &nbsp;</td></tr>
<tr>
	<td align=center>Ethernet</td><td align=center>$vt11 &nbsp;</td></tr>
<tr>
	<td align=center>AFDX</td><td align=center>$vt12 &nbsp;</td></tr>
<tr>
	<td align=center>MIL 1553</td><td align=center>$vt13 &nbsp;</td></tr>
<tr>
	<td align=center>ARINC 429</td><td align=center>$vt14</td></tr></tbody></table></td>
<td valign=top><table cellspacing=3 cellpadding=3 border=1><tbody>
<tr>
<td align=center colspan=2><b>Survey Results for Motion Bases</b></td></tr>
<tr>
	<td align=center>Hydraulics </td><td align=center>$vt15 &nbsp;</td></tr>
<tr>
	<td align=center>Pneumatics</td><td align=center>$vt16 &nbsp;</td></tr>
<tr>
	<td align=center>Electric Motors</td><td align=center>$vt17 &nbsp;</td></tr></tbody></table></td>

<td valign=top><table cellspacing=3 cellpadding=3 border=1><tbody>
<tr>
<td align=center colspan=2><b>Survey Results for Motion Bases Axes</b></td></tr>
<tr><td align=center>One Axes - Pitch</td><td>$ax1 &nbsp;</td></tr>
<tr><td align=center>Two Axes - Pitch / Roll</td><td>$ax2 &nbsp;</td></tr>
<tr><td align=center>Three Axes - Pitch / Roll / Vert</td><td>$ax3 &nbsp;</td></tr>
<tr><td align=center>More Than 3 Axes</td><td>$ax4 &nbsp;</td></tr>
</tbody></table></td></tr></tbody></table>
<P><i>To take part in this survey you must <a href="register/index.shtml">register!</a></i></center>
<br>
<table width=90% align=center>
<tr>
<td align=left><font size=-1>Copyright &copy; 2004 - 2006 <a href="http://www.phoenixcomm.net">Phoenix Communications Services</a>.</font></td>
<td align=right><font size=-1>Please send all comments to the <a href="mailto:Webmaster\@phoenixcomm.net">Webmaster</a>.</td>
</tr>
<tr>
<td align=center colspan=2><!-- Site Meter -->
	<script type="text/javascript" src="http://s24.sitemeter.com/js/counter.js?site=s24nikon97">
	</script>
	<noscript>
	<a href="http://s24.sitemeter.com/stats.asp?site=s24nikon97" target="_top">
	<img src="http://s24.sitemeter.com/meter.asp?site=s24nikon97" alt="Site Meter" border="0"/></a>
	</noscript>
	<!-- Copyright (c)2006 Site Meter -->
</td></tr>
</table>

</body>
</HTML>
ENDHTML
