. */ // This file is run by http://www.cleanmpg.com/index.php?page=garage // Set header type to streaming Excel format header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=cleanmpg_mileage.xls"); header("Pragma: no-cache"); header("Expires: 0"); // make sure to include electricity into the mpg equation !!!!!!!!!!!!// define(DIR, '/home/cleanmpg/public_html/garage'); require_once('../forums/global.php'); require(DIR . '/includes/functions_user.php'); define('NO_REGISTER_GLOBALS', 1); define('THIS_SCRIPT', 'Mileage Logs'); $colorgas="#663333"; $colorelectric="#009900"; $colorhybrid="#0066CC"; $colordiesel="#660099"; $colorother="#000000"; $colormotorcycle="#CC6600"; $colorqrtryr="#990033"; $displayunits=$_GET["displayunits"]; // Set display units to what ever was passed. $currencyconversion=(float)$vbulletin->userinfo['field7']; $displayoptions=$vbulletin->userinfo[field9]; if ($displayoption == "") { $vbulletin->userinfo[field9]="15903"; } if ($displayoptions & 1) { // print "Owner's Name"; } if ($displayoptions & 2) { // print "Vehicle Name"; } if ($displayoptions & 4) { // print "Year/Make/Model/Trans"; } if ($displayoptions & 8) { // print "Emissions"; } if ($displayoptions & 16) { // print "Starting Distance Driven"; } if ($displayoptions & 32) { // print "Zip Code"; } if ($displayoptions & 64) { // print "Propulsion"; } if ($displayoptions & 128) { //print "Highway Fuel Economy"; } if ($displayoptions & 256) { //print "City Fuel Economy"; } if ($displayoptions & 512) { //print "Owner Economy"; } if ($displayoptions & 1024) { //print "Total Distance Driven"; } if ($displayoptions & 2048) { //print "Fuel Used"; } if ($displayoptions & 4096) { //print "Electricity Used"; } if ($displayoptions & 8192) { //print "Total Fuel Economy"; } $userid = $vbulletin->userinfo['userid']; $viewcar=$_GET["viewcar"]; $viewuser=$_GET["viewuser"]; $viewuserorig=$viewuser; $viewuser=str_replace(";quote;","'",$viewuser); $viewuser=str_replace(";amp;","&",$viewuser); $viewsort=$_GET["sort"]; $sortdir=$_GET["sortdir"]; $summary=$_GET["summary"]; $maxnum=$_GET["maxnum"]; $prop=$_GET["prop"]; $username='mileage'; $password='7rack$ter'; $database='test'; if (!$maxnum) // if no limit per propulsion category has been set, use a default { if ($summary) { $maxnum="10"; } else { $maxnum="50"; } } if (!$displayunits) // if display units hasn't been forced then take the users default { $displayunits=$vbulletin->userinfo['field6']; } if ($displayunits=='') // if for some reason the user doesn't have a default set then make it MPG(US) { $displayunits="MPG(US)"; } switch ($displayunits) { case 'MPG(US)': $distanceconversion=1; $fuelconversion=1; $fuelunits="US Gallons"; $distanceunits="Miles"; $mpgunits="US MPG"; $selectus="selected"; break; case 'MPG(UK)': $distanceconversion=1; $fuelconversion=0.83267384; $fuelunits="UK Gallons"; $distanceunits="Miles"; $mpgunits="UK MPG"; $selectuk="selected"; break; case 'L/100Km': $distanceconversion=1.609344; $fuelconversion=3.78541178; $fuelunits="Liters"; $distanceunits="km"; $mpgunits="L/100km"; $selectl="selected"; break; } switch ($maxnum) { case '10': $select10="selected"; break; case '20': $select20="selected"; break; case '50': $select50="selected"; break; case '100': $select100="selected"; break; case 'All': $selectAll="selected"; break; } switch ($prop) { case '': $selectpropAll="selected"; break; case 'gas': $selectgas="selected"; break; case 'hybrid': $selecthybrid="selected"; break; case 'diesel': $selectdiesel="selected"; break; case '10motorcycle': $selectmotorcycle="selected"; break; case '00electric': $selectelectric="selected"; break; case 'quarter-year fe challenge': $selectqrtryr="selected"; break; } mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); //onChange="reload_withyear(this.value)" if ($viewcar) { $carstring="&viewcar=".$viewcar; } if ($viewuser) { $userstring="&viewuser=".$viewuserorig; } if ($displayunits) { $displayunitsstring="&displayunits=".$displayunits; } if ($sortdir) { $sortdirstring="&sortdir=".$sortdir; } if ($viewsort) { $sortstring="&sort=".$viewsort; $urlsortstring=$sortstring; } if ($maxnum) { $maxnumstring="&maxnum=".$maxnum; } if ($prop) { $urlprop=preg_replace("/\s/","%20",$prop); $propstring="&prop=".$urlprop; } if ($summary) { $summarystring="&summary=1"; } $distance_dropdown="
"; $limit_dropdown=""; $propulsion_dropdown=""; if ($summary!='') { //$query="SELECT * FROM autobarn ORDER BY propulsion,mpg desc"; //$query="SELECT * FROM autobarn ORDER BY mpg desc"; if (($maxnum!="All") and ($prop=='')) { $query="SELECT * FROM autobarn WHERE propulsion!=".'"00electric" ORDER BY mpg desc'; } elseif ($prop!='') { $query='SELECT * FROM autobarn WHERE propulsion="'.$prop.'" ORDER BY mpg desc'; } else { $query="SELECT * FROM autobarn ORDER BY mpg desc"; } $result = mysql_query($query); $num=mysql_numrows($result); if (($num>$maxnum) and ($maxnum!="All")) { $num=$maxnum; } $i=0; $maxlength=81; $scalefactor=(($maxlength)-1)/(mysql_result($result,0,"mpg")); echo ""; //echo ""; echo ""; echo ""; $m=0; while ($m<$maxlength) { echo ""; $m++; } echo ""; while ($i<$num) { $car_name=mysql_result($result,$i,"car_name"); $car_name_text=str_replace(";39;","'",$car_name); $car_year=mysql_result($result,$i,"year"); $make=mysql_result($result,$i,"make"); $model=mysql_result($result,$i,"model"); $trans=mysql_result($result,$i,"trans"); //$emissions=mysql_result($result,$i,"emissions"); //$starting_miles=mysql_result($result,$i,"starting_miles"); //$url=mysql_result($result,$i,"url"); //$zipcode=str_pad(mysql_result($result,$i,"zipcode"),5,STR_PAD_LEFT); //$propulsion=mysql_result($result,$i,"propulsion"); //$city_mileage=mysql_result($result,$i,"city_mileage"); //$hwy_mileage=mysql_result($result,$i,"hwy_mileage"); //$notes=mysql_result($result,$i,"notes"); //$notes_str=str_replace(";39;","'",$notes); $poe=mysql_result($result,$i,"percent_of_epa"); $distance=mysql_result($result,$i,"distance"); $fuelused=mysql_result($result,$i,"fuelused"); //$elecused=mysql_result($result,$i,"elecused"); $mpg=mysql_result($result,$i,"mpg"); //$owner=mysql_result($result,$i,"ownerid"); $usersname=mysql_result($result,$i,"username"); $value=(int)($mpg*$scalefactor); if ($distance!=0) { if ($value==0) { $value=1; } if ($mpg=='') { $mpg=0; } if ($mpgunits=="L/100km") { $mpg=round(235.2209/$mpg,3); } else { if ($fuelused!=0) { $mpg=round(($distance*$distanceconversion)/($fuelused*$fuelconversion),3); } else { $mpg=0; } } echo ""; echo ""; echo ""; $i++; } else { $i=$num; } } echo "
  
Top 10 Most Efficient Drivers and Vehicles
  

".$limit_dropdown." Efficient Drivers and Vehicles

  
".$propulsion_dropdown." ".$distance_dropdown." 
 
$usersname
$car_year $make $model $trans
   $mpg $displayunits
"; mysql_close(); } ################## #### view all cars ################## elseif ($viewcar=='' and $viewuser=='') { $username = $vbulletin->userinfo['username']; $sortstring="mpg"; switch ($viewsort) { case "owner": $sortstring="username"; break; case "cname": $sortstring="car_name"; break; case "model": if ($sortdir=='') { $sortdir='desc'; } $sortstring="year ".$sortdir.",make,model,trans"; break; case "emissions": $sortstring="emissions"; break; case "poe": $sortstring="percent_of_epa"; break; case "fuel": if ($sortdir=='desc') { $elecuseds=''; } else { $elecuseds='asc'; } $sortstring="fuelused ".$sortdir.",elecused ".$elecuseds; break; case "distance": $sortstring="distance"; break; case "mpg": $sortstring='mpg'; break; } if (((($sortstring=='mpg') or ($viewsort=='distance')) or ($sortstring=='percent_of_epa')) and $sortdir=='') { $sortdir='desc'; } if ($prop=='') { $query="SELECT * FROM autobarn ORDER BY propulsion desc,".$sortstring." ".$sortdir; } else { $query='SELECT * FROM autobarn WHERE propulsion="'.$prop.'" ORDER BY '.$sortstring." ".$sortdir; } $totresult = mysql_query($query); $totnum=mysql_numrows($totresult); echo "

CleanMPG.com Universal Vehicular Fuel and Energy Consumption Logs


*Still in development please let us know if you find any bugs or have any comments on how to improve it.*
"; echo ""; $site="Vehicles: ".$totnum; if ($prop!='') { echo "
"; echo $site.$urlsortstring.$sortdirstring.$displayunitsstring.$userstring.$carstring.$maxnumstring; echo "'>Click to return to overview"; } echo ""; echo $limit_dropdown." "; echo $distance_dropdown." "; echo "
"; echo ""; if ($userid>0) { $addvehicle="Add Vehicle"; } echo ""; echo "
".$addvehicle."Model Summaries
"; ################## ##### headings bar ################## echo ""; if (($userid>0) and ($prop=='')) { $query="SELECT * FROM autobarn WHERE ownerid=".$userid." ORDER BY ".$sortstring." ".$sortdir; $result = mysql_query($query); $num=mysql_numrows($result); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if ($num==0) { //echo "No vehicles"; } else { $i=0; $alt1="'.$alt1.'
Add
Tanks
'.$alt1.'
Edit or Delete
Vehicle
'; $usersname_text=str_replace("&",";amp;",$usersname); $usersname_text=str_replace("'",";quote;",$usersname_text); $q=$q.$alt1."".$usersname."".$alt1."".$car_name_text.""; $q=$q.$alt1.$car_year.' '.$make.' '.$model.' '.$trans.''.$alt1.$poe.''.$alt1; $q=$q.round(($fuelused*$fuelconversion),3).''.$alt1.$elecused.'Wh'.$alt1.round($distance*$distanceconversion,2).' '.$alt1.$mpg.''.$alt1.' '; // $car_year $make $model $trans $poe $starting_miles

$url $zipcode $propulsion $city_mileage $hwy_mileage

$notes"; echo $q; $i++; if ($alt1=="
Manage
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=owner'>Owner ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=owner'>Reverse Sort Order".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=cname'>Vehicle Name ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=cname'>Reverse Sort Order".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=model'>
Year/Make/Model
Transmission ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=model'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=poe'>% of EPA ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=poe'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=fuel'>Fueled By
".$fuelunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=fuel'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=distance'>
Distance
".$distanceunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=distance'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=mpg'>".$mpgunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=MPG'>Reverse Sort Order 
"; while ($i<$num){ $carid=mysql_result($result,$i,"id"); $car_name=mysql_result($result,$i,"car_name"); $car_name_text=str_replace(";39;","'",$car_name); $car_name_text=str_replace(";amp;","&",$car_name_text); $car_name_text=str_replace(";quote;","'",$car_name_text); $car_year=mysql_result($result,$i,"year"); $make=mysql_result($result,$i,"make"); $model=mysql_result($result,$i,"model"); $trans=mysql_result($result,$i,"trans"); $emissions=mysql_result($result,$i,"emissions"); $poe=mysql_result($result,$i,"percent_of_epa"); $starting_miles=mysql_result($result,$i,"starting_miles"); $url=mysql_result($result,$i,"url"); $zipcode=str_pad(mysql_result($result,$i,"zipcode"),5,STR_PAD_LEFT); $propulsion=mysql_result($result,$i,"propulsion"); $city_mileage=mysql_result($result,$i,"city_mileage"); $hwy_mileage=mysql_result($result,$i,"hwy_mileage"); $notes=mysql_result($result,$i,"notes"); $notes_str=str_replace(";39;","'",$notes); $distance=mysql_result($result,$i,"distance"); $fuelused=mysql_result($result,$i,"fuelused"); $elecused=mysql_result($result,$i,"elecused"); $usersname=mysql_result($result,$i,"username"); $mpg=mysql_result($result,$i,"mpg"); if ($fuelused=='') { $fuelused='0'; } if ($elecused=='') { $elecused='0'; } if ($distance!=0) { if ($mpgunits=="L/100km") { if ($mpg==0) { $mpg=0; } else { $mpg=round(235.2209/$mpg,3); } } else { if (($fuelused==0) or ($fuelconversion==0)) { $mpg=0; } else { $mpg=round(($distance*$distanceconversion)/($fuelused*$fuelconversion),3); } } } else { $mpg=0; } $q='
") { $alt1=""; } else { $alt1=""; } } } } $oldpropulsion="new"; if ($maxnum=='All') { $maxnum=$totnum; } if ($totnum==0) { //echo "No vehicles"; } else { $i=0; $limitlist=1; $alt1=""; while ($i<$totnum) { $car_name=mysql_result($totresult,$i,"car_name"); $car_name_text=str_replace(";39;","'",$car_name); $car_year=mysql_result($totresult,$i,"year"); $make=mysql_result($totresult,$i,"make"); $model=mysql_result($totresult,$i,"model"); $trans=mysql_result($totresult,$i,"trans"); $emissions=mysql_result($totresult,$i,"emissions"); $poe=mysql_result($totresult,$i,"percent_of_epa"); $starting_miles=mysql_result($totresult,$i,"starting_miles"); $url=mysql_result($totresult,$i,"url"); $zipcode=str_pad(mysql_result($totresult,$i,"zipcode"),5,STR_PAD_LEFT); $propulsion=mysql_result($totresult,$i,"propulsion"); $city_mileage=mysql_result($totresult,$i,"city_mileage"); $hwy_mileage=mysql_result($totresult,$i,"hwy_mileage"); $notes=mysql_result($totresult,$i,"notes"); $notes_str=str_replace(";39;","'",$notes); $ownerid=mysql_result($totresult,$i,"ownerid"); $distance=mysql_result($totresult,$i,"distance"); $fuelused=mysql_result($totresult,$i,"fuelused"); $elecused=mysql_result($totresult,$i,"elecused"); $mpg=mysql_result($totresult,$i,"mpg"); $usersname=mysql_result($totresult,$i,"username"); $carid=mysql_result($totresult,$i,"id"); if ($fuelused=='') { $fuelused="0"; } if ($elecused=='') { $elecused='0'; } if ($distance!=0) { if ($mpgunits=="L/100km") { $imagetype="L"; $mpg=round(235.2209/$mpg,3); } else { if ($fuelused==0) { $mpg=0; } else { $mpg=round(($distance*$distanceconversion)/($fuelused*$fuelconversion),3); } } } else { $mpg=0; } ### ### Status (hypermiler, expert, elite) ### ###if ($car_year>2007) if (($car_year>2007) and ($propulsion!="10motorcycle")) { $fix2007=1.2; } else { $fix2007=1;} $testmileage = (($city_mileage+$hwy_mileage)*$fix2007)/2; $mpgstats=" "; if ($mpg>0) { if ($distance>5000) { if ($mpg>$testmileage) { $mpgstats=$mpg." ".$testmileage; $mpgstats="Skilled"; } if ($mpg>($testmileage*1.25)) { $mpgstats="Expert"; } if ($mpg>($testmileage*1.5)) { $mpgstats="Elite"; } } } //$colorgas="#663333"; //$colorelectric="#009900"; //$colorhybrid="#0066CC"; //$colordiesel="#660099"; //$colorother="#000000"; //$colormotorcycle="#CC6600"; //$colorqrtryr="#990033"; if ($propulsion=="other") $carcolor=$colorother; if ($propulsion=="hybrid") $carcolor=$colorhybrid; if ($propulsion=="gas") $carcolor=$colorgas; if ($propulsion=="00electric") $carcolor=$colorelectric; if ($propulsion=="diesel") $carcolor=$colordiesel; if ($propulsion=="10motorcycle") $carcolor=$colormotorcycle; if ($propulsion=="quarter-year fe challenge") $carcolor=$colorqrtryr; $usersname_text=str_replace("&",";amp;",$usersname); $usersname_text=str_replace("'",";quote;",$usersname_text); if (($propulsion != $oldpropulsion) and ($oldpropulsion !="")) { $limitlist=1; echo "

"; $propulsion1=preg_replace("/^\d+/","",$propulsion); $urlprop=preg_replace("/\s/","%20",$propulsion); echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; ### $oldpropulsion=$propulsion; } //if ($distance!=0) //if (((($distance==0) and ($userid!=678)) and ($propulsion!="Qrtr-Yr FE")) or (($limitlist>$maxnum) and ($propulsion!="Qrtr-Yr FE"))) if ((($distance==0) and (($userid!=678) and ($userid!=3))) or ($limitlist>$maxnum)) { } else //if (($distance!=0) and ($distance>5000)) { echo ""; echo ""; echo $alt1."".$usersname.""; echo $alt1; if (($userid==678) or ($userid==3) or ($userid==486)) { echo " '; } echo "".$car_name_text."".$alt1.' '.$car_year.' '.$make.' '.$model.' '.$trans."".$alt1.$poe."".$alt1.round($fuelused*$fuelconversion,3)."".$alt1.$elecused."Wh".$alt1.round($distance*$distanceconversion,2)."".$alt1.$mpg.""; if ($alt1=="
".$site.$urlsortstring.$sortdirstring.$displayunitsstring.$userstring.$carstring.$maxnumstring; echo "&prop=".$urlprop."'>".strtoupper($propulsion1)."
Status
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=owner'>Owner ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=owner'>Reverse Sort Order".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=cname'>Vehicle Name ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=cname'>Reverse Sort Order".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=model'>
Year/Make/Model
Transmission ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=model'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=poe'>% of EPA ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=poe'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=fuel'>Fueled By
".$fuelunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=desc&sort=fuel'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=distance'>
Distance
".$distanceunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=distance'>Reverse Sort Order
".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sort=mpg'>".$mpgunits." ".$site."&displayunits=".$displayunits.$propstring.$maxnumstring."&sortdir=asc&sort=mpg'>Reverse Sort Order
".$mpgstats."
") { $alt1=""; } else { $alt1=""; } } $i++; $limitlist++; } } echo "
"; mysql_close(); } ############################ #### View a specific vehicle ############################ else // View a specific vehicle { $username='mileage'; $password='7rack$ster'; $database='test'; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $userid = $vbulletin->userinfo['userid']; $username = $vbulletin->userinfo['username']; $sortstring="&sortstr="; if ($viewsort!='') { $sortstring="ORDER BY profile,".$viewsort; if ($sortdir) { $sortstring=$sortstring." ".$sortdir; } } else { $sortstring="order by date_of_tank DESC"; } if ($viewcar!='') { $query='SELECT * FROM autobarn WHERE id="'.$viewcar.'"'; $viewcarstr="&viewcar=".$viewcar; } else { $viewcarstr=""; } if ($viewuser!='') { $query='SELECT * FROM autobarn WHERE username="'.$viewuser.'"'; $viewuserstr="&viewuser=".$viewuser; } else { $viewuserstr=""; } $result = mysql_query($query); if ($result!='') { $num=mysql_numrows($result); } $site=""; // grab car if ($num<1) { echo "You have no cars"; } if ($displayunits=="L/100Km") { $imagetype="L"; } elseif ($displayunits=="MPG(UK)") { $imagetype="UK"; } else { $imagetype=""; } if ($num>0) { $i=0; while ($i<$num){ // loop through cars $car_name=mysql_result($result,$i,"car_name"); $car_name_text=str_replace(";39;","'",$car_name); $id=mysql_result($result,$i,"id"); $car_owner=mysql_result($result,$i,"ownerid"); echo "\n"; $viewcarstr="&viewcar=".$viewcar; echo "\n"; echo ""; // date_of_tank echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; //$query2 = 'select * from autobarn_profiles where car_name="'.$car_name.'"'; $query2 = 'select * from autobarn_profiles where car_name="'.$car_name.'" and ownerid="'.$car_owner.'"'; $result2=mysql_query($query2); $num2=mysql_numrows($result2); $car_year=mysql_result($result,$i,"year"); $make=mysql_result($result,$i,"make"); $model=mysql_result($result,$i,"model"); $trans=mysql_result($result,$i,"trans"); $emissions=mysql_result($result,$i,"emissions"); $poe=mysql_result($result,$i,"percent_of_epa"); $starting_miles=mysql_result($result,$i,"starting_miles"); $url=mysql_result($result,$i,"url"); $zipcode=str_pad(mysql_result($result,$i,"zipcode"),5,STR_PAD_LEFT); $propulsion=mysql_result($result,$i,"propulsion"); $city_mileage=mysql_result($result,$i,"city_mileage"); $hwy_mileage=mysql_result($result,$i,"hwy_mileage"); $notes=mysql_result($result,$i,"notes"); $notes_str=str_replace(";39;","'",$notes); $ownerid=mysql_result($result,$i,"ownerid"); $distance=mysql_result($result,$i,"distance"); $fuelused=mysql_result($result,$i,"fuelused"); $elecused=mysql_result($result,$i,"elecused"); $mpg=mysql_result($result,$i,"mpg"); $usersname=mysql_result($result,$i,"username"); $carid=mysql_result($result,$i,"id"); if ($elecused=='') { $elecused='0'; } if ($fuelused=='') { $fuelused='0'; } $q=0; if ($num2==0) { echo "\n"; } $costpermile=0; $adjustedmpg=0; while ($q<$num2){ // loop through profiles $profile_name=mysql_result($result2,$q,"profile_name"); $profile_description=mysql_result($result2,$q,"description"); //$query1 = 'select * from autobarn_miles where profile="'.$profile_name.'" and car_name="'.$car_name.'" '.$sortstring; $query1 = 'select * from autobarn_miles where profile="'.$profile_name.'" and car_name="'.$car_name.'" and ownerid="'.$ownerid.'" '.$sortstring; $result1=mysql_query($query1); $num1=mysql_numrows($result1); echo "\n"; $z=0; if ($num1==0) { echo "\n"; } $toggle='1'; while ($z<$num1) // loop through tanks { $id=mysql_result($result1,$z,"id"); $date_of_tank=mysql_result($result1,$z,"date_of_tank"); $distance=mysql_result($result1,$z,"distance"); $fuelused=mysql_result($result1,$z,"fuelused"); $distancec=$distance*$distanceconversion; $fuelusedc=$fuelused*$fuelconversion; $speed=mysql_result($result1,$z,"speed"); $elecused=mysql_result($result1,$z,"elecused"); $costfuel=mysql_result($result1,$z,"costfuel"); $costfuel=$costfuel*$currencyconversion; if ($costfuel>0) { if ($fuelused>0) { $costpermile=$costpermile+($distancec/($fuelusedc*$costfuel)); } } $costelectric=mysql_result($result1,$z,"costelectric"); $costelectric=$costelectric*$currencyconversion; $maxspeed=mysql_result($result1,$z,"maxspeed"); $temp=mysql_result($result1,$z,"temp"); if ($temp != 0) { if ($temp<40) { if ($temp<0) { $adjustedmpg=($adjustedmpg+(($distancec/$fuelusedc)+((40-$temp)/10)))/2; } else { $adjustedmpg=($adjustedmpg+(($distancec/$fuelusedc)+((($temp-40)*-1)/10)))/2; } } if ($temp>80) { $adjustedmpg=($adjustedmpg+($distancec/$fuelusedc)+(($temp-80)/10))/2; } } else { ##print "distande:".$distance." fuel:".$fuelused; // $adjustedmpg=$adjustedmpg+($distancec/$fuelusedc); } $fueltype=mysql_result($result1,$z,"fueltype"); $wind=mysql_result($result1,$z,"wind"); $avtrip=mysql_result($result1,$z,"avtrip"); $tripnotes=mysql_result($result1,$z,"tripnotes"); $tripnotes_str=str_replace(";39;","'",$tripnotes); $thistechs=mysql_result($result1,$z,"techs"); $date_of_entry=mysql_result($result1,$z,"date_entered"); $citypct=mysql_result($result1,$z,"citypercent"); $ownerid=mysql_result($result1,$z,"ownerid"); $techs=''; list($tyear,$tmonth,$tday) = split('[/.-]', $date_of_tank); $date_of_tank=$tmonth."/".$tday."/".$tyear; if ($thistechs>16383) { #$techs="O"; $techso="C"; $cnoc="checked=checked"; $thistechs=$thistechs-16384; } else { #$techs="-"; $techso="-"; } if ($thistechs>8191) { #$techs="N".$techs; $thistechs=$thistechs-8192; } else { #$techs="-".$techs; } if ($thistechs>4095) { #$techs="M".$techs; $thistechs=$thistechs-4096; } else { #$techs="-".$techs; } if ($thistechs>2047) { #$techs="L".$techs; $thistechs=$thistechs-2048; } else { #$techs="-".$techs; } if ($thistechs>1023) { #$techs="K".$techs; $thistechs=$thistechs-1024; } else { #$techs="-".$techs; } if ($thistechs>511) { #$techs="J".$techs; $techs="J"; $thistechs=$thistechs-512; } else { #$techs="-".$techs; $techs="-"; } if ($thistechs>255) { $techs="I".$techs; $thistechs=$thistechs-256; } else { $techs="-".$techs; } if ($thistechs>127) { $techs="H".$techs; $thistechs=$thistechs-128; } else { $techs="-".$techs; } if ($thistechs>63) { $techs="G".$techs; $thistechs=$thistechs-64; } else { $techs="-".$techs; } if ($thistechs>31) { $techs="F".$techs; $thistechs=$thistechs-32; } else { $techs="-".$techs; } if ($thistechs>15) { $techs="E".$techs; $thistechs=$thistechs-16; } else { $techs="-".$techs; } if ($thistechs>7) { $techs="D".$techs; $thistechs=$thistechs-8; } else { $techs="-".$techs; } if ($thistechs>3) { #$techs="C".$techs; $thistechs=$thistechs-4; } else { #$techs="-".$techs; } $techs=$techso.$techs; if ($thistechs>1) { $techs="B".$techs; $thistechs=$thistechs-2; } else { $techs="-".$techs; } if ($thistechs>0) { $techs="A".$techs; $thistechs=$thistechs-1; } else { $techs="-".$techs; } if ($thistechs!=0) { print "error decoding techniques"; } if ($mpg=='') { $mpg=0; } if ($mpgunits=="L/100km") { $imagetype="L"; if ($fuelused==0) { $mpg=0; } else { $mpg=$distance/$fuelused; $mpg=round(235.2209/$mpg,3); } } else { if ($fuelused!=0) { $mpg=round(($distance*$distanceconversion)/($fuelused*$fuelconversion),3); } else { $mpg=0; } } echo "\n"; echo ""; //echo ""; echo ""; if ($toggle=='1') { $toggle='2'; } else { $toggle='1'; } echo ""; $totalmiles=$totalmiles+$distance; $totalfuel=$totalfuel+$fuelused; $z++; } $q++; } echo "\n"; $i++; if ($userid == 2) { if ($costpermile>0) { echo ""; echo "
".$car_name."
MPG
Date Of Tank
Distance
".$distanceunits."
Fueled By
".$fuelunits."
Speed
Elect.
Used
Fuel
Cost
Elect.
Cost
% of Max
Speed
Temp
Fuel
Type
Ave.
Trip
Length
Notes
Techniques
Date
Of
Entry
% of
City
Driving
This car has no Tanks

"; echo $profile_name; if ($profile_description) { echo " - ".$profile_description; } else { echo " - Default Profile"; } echo "
This Profile has no Tanks

$mpg ".$mpgunits.""; echo $date_of_tank." ".round($distance*$distanceconversion,2); echo " ".round($fuelused*$fuelconversion,3)." ".$speed." ".$elecused." ".$costfuel." ".$costelectric; echo " ".$maxspeed." ".$temp." ".$fueltype." ".$avtrip." \"".$tripnotes."\"/ ".$techs." ".$date_of_entry; echo " ".$citypct."%
+Cost per 100 miles
$".number_format($costpermile/100,2)."
++Adjusted
MPGus:

".number_format($adjustedmpg,2)."
"; echo "
"; echo "
".round($totalmiles*$distanceconversion,4)."".round($totalfuel*$fuelconversion,4)."
"; $totalfuel=0; $totalmiles=0; } } } } echo ""; mysql_close(); } // I need to first grab car. Then search for number of profiles then cycle through each profile. Then go to next car etc. ?>