<?
session_cache_limiter('nocache');

session_start();

include_once('mapcfg.php');

if($usepost == 1){
$ShipClassName = $_POST["ItemName"];
$buyshipRace = $_POST["shipRace"];
$buyshipClass = $_POST["ClassShip"];
$BPV = $_POST["ItemInfo"];
$BidOwnerID = $_POST["BidOwnerID"];
$bid = $_POST["bid"];
}

if($usepost == 0){
$ShipClassName = $ItemName;
$buyshipRace = $shipRace;
$buyshipClass = $ClassShip;
$BPV = $ItemInfo;
}

echo ("<html>");
echo ("<head>");
echo ("<META HTTP-EQUIV='Refresh' CONTENT='10; URL=shipyard.php'>");
echo ("<meta http-equiv=Content-Style-Type content=text/css>");
echo ("<link rel=stylesheet href=$cssloc type=text/css>");
echo ("<title>$D2campname Bid Result</title>");
echo ("</head>");
echo ("<body>");
echo ("<table width=60% cellspacing=0 cellpadding=0 border=0 align=center>");
  	echo ("<tr>");
    	echo ("<td width=100% align=center class=windowbg2>");

				if(!$user_info['is_guest']) {

					$ChkOwner = array();
				
					$link = mysql_connect($D2dbhostname .":" .$D2dbport, $D2dbuser, $D2dbpass);
   					mysql_select_db($D2db);
    					$query = "SELECT Owner,ClassType FROM ship";
    					$result = mysql_query($query);
					$a=0;
					while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

							$ChkOwner[$a] = $line['Owner'];
							$ClassType[$a] = $line['ClassType'];
							$a=$a+1;
    					}
    					mysql_free_result($result);
				
					$shipsowned = 0;
					for ($i = 0; $i <= $a-1; $i++) {
						if ($ChkOwner[$i] == $BidOwnerID){
							if ($ClassType[$i] < 13 and $ClassType[$i] > 1) {
								$shipsowned = $shipsowned + 1;
							}
						}
					}


					$ChkBidOwnerID = array();

    					$query = "SELECT BidOwnerID FROM biditem";
    					$result = mysql_query($query);
					$b=0;
					while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {

							$ChkBidOwnerID[$b] = $line['BidOwnerID'];
							$b=$b+1;
    					}
    					mysql_free_result($result);
    					mysql_close($link);
				
					$shipsbidon = 0;
					for ($j = 0; $j <= $b-1; $j++) {
						if ($ChkBidOwnerID[$j] == $BidOwnerID){
							$shipsbidon = $shipsbidon + 1;
						}
					}

					$shipstotal = $shipsbidon + $shipsowned;



					if ($shipstotal < 3) {


						$link = mysql_connect($D2dbhostname .":" .$D2dbport, $D2dbuser, $D2dbpass);
   						mysql_select_db($D2db);
    						$query = "SELECT CharacterCurrentPrestige FROM servcharacter WHERE ID=";
						$query .= $BidOwnerID;
    						$result = mysql_query($query);
						//echo mysql_errno() . ": " . mysql_error() . "\n";
						//echo ("<br><br>");					
					
						$line = mysql_fetch_array($result, MYSQL_ASSOC);

						$CurrentPP = $line['CharacterCurrentPrestige'];

    						mysql_free_result($result);
    						mysql_close($link);



						if ($CurrentPP >= $bid) {

							$shiprace = array();
							$shiprace[0] = "Federation";
							$shiprace[1] = "Klingon";
							$shiprace[2] = "Romulan";
							$shiprace[3] = "Lyran";
							$shiprace[4] = "Hydran";
							$shiprace[5] = "Gorn";
							$shiprace[6] = "ISC";
							$shiprace[7] = "Mirak";
							$shiprace[8] = "OrionOrion";
							$shiprace[9] = "OrionKorgath";
							$shiprace[10] = "OrionPrime";
							$shiprace[11] = "OrionTigerHeart";
							$shiprace[12] = "OrionBeastRaiders";
							$shiprace[13] = "OrionSyndicate";
							$shiprace[14] = "OrionWyldeFire";
							$shiprace[15] = "OrionCamboro";
							$shiprace[16] = "Orion";
							$shiprace[23] = "Neutral";


	$shipdatarow = array();
	$shipcount = 0;
	$filename = "shiplist.txt";
	$fp=fopen("$filename","rt");
	while (($shipdata = fgetcsv($fp, 1569, chr(9))) !== FALSE) {
		if ($shipdata[0] == $shiprace[$buyshipRace] and $shipdata[2] == $ShipClassName){
			$shipdatarow[$shipcount] = $shipdata;
			$shipcount++;
		}
	}

	fclose($fp);
							
							for ($s = 0; $s <= $shipcount-1; $s++) {
								if ($shipdatarow[$s][0] == $shiprace[$buyshipRace] and $shipdatarow[$s][2] == $ShipClassName){

									$DamageBlob = "";

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][128]), 2, "0", STR_PAD_LEFT); //left warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][128]), 2, "0", STR_PAD_LEFT); //left warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][128]), 2, "0", STR_PAD_LEFT); //right warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][128]), 2, "0", STR_PAD_LEFT); //right warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][129]), 2, "0", STR_PAD_LEFT); //center warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][129]), 2, "0", STR_PAD_LEFT); //center warp
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][130]), 2, "0", STR_PAD_LEFT); //impulse
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][130]), 2, "0", STR_PAD_LEFT); //impulse

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][131]), 2, "0", STR_PAD_LEFT); //APR
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][131]), 2, "0", STR_PAD_LEFT); //APR
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][133]), 2, "0", STR_PAD_LEFT); //Bridge
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][133]), 2, "0", STR_PAD_LEFT); //Bridge
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][140]), 2, "0", STR_PAD_LEFT); //Sensors
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][140]), 2, "0", STR_PAD_LEFT); //Sensors
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][141]), 2, "0", STR_PAD_LEFT); //Scanners
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][141]), 2, "0", STR_PAD_LEFT); //Scanners

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Damage Control
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Damage Control
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][127]), 2, "0", STR_PAD_LEFT); //Repair
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][127]), 2, "0", STR_PAD_LEFT); //Repair
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][122]), 2, "0", STR_PAD_LEFT); //Forward Hull
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][122]), 2, "0", STR_PAD_LEFT); //Forward Hull
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][124]), 2, "0", STR_PAD_LEFT); //Aft Hull
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][124]), 2, "0", STR_PAD_LEFT); //Aft Hull

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][123]), 2, "0", STR_PAD_LEFT); //Center Hull
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][123]), 2, "0", STR_PAD_LEFT); //Center Hull
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][137]), 2, "0", STR_PAD_LEFT); //Tractors
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][137]), 2, "0", STR_PAD_LEFT); //Tractors
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][145]), 2, "0", STR_PAD_LEFT); //Extra Damage
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][145]), 2, "0", STR_PAD_LEFT); //Extra Damage
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][136]), 2, "0", STR_PAD_LEFT); //Transporters
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][136]), 2, "0", STR_PAD_LEFT); //Transporters

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][136]), 2, "0", STR_PAD_LEFT); //Transporters (again?)
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][136]), 2, "0", STR_PAD_LEFT); //Transporters (again?)
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][132]), 2, "0", STR_PAD_LEFT); //Battery
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][132]), 2, "0", STR_PAD_LEFT); //Battery
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][135]), 2, "0", STR_PAD_LEFT); //Lab
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][135]), 2, "0", STR_PAD_LEFT); //Lab
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][125]), 2, "0", STR_PAD_LEFT); //Cargo
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][125]), 2, "0", STR_PAD_LEFT); //Cargo

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][121]), 2, "0", STR_PAD_LEFT); //Armour
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][121]), 2, "0", STR_PAD_LEFT); //Armour
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][25]), 2, "0", STR_PAD_LEFT); //Cloak
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][25]), 2, "0", STR_PAD_LEFT); //Cloak
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Damage Control
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Damage Control
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][101]), 2, "0", STR_PAD_LEFT); //Probe
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][101]), 2, "0", STR_PAD_LEFT); //Probe

									$DamageBlob .= str_pad(dechex($shipdatarow[$s][126]), 2, "0", STR_PAD_LEFT); //Barracks
									$DamageBlob .= str_pad(dechex($shipdatarow[$s][126]), 2, "0", STR_PAD_LEFT); //Barracks
									for ($t = 26; $t <= 98; $t+=3) {
										$DamageBlob .= str_pad(dechex($shipdatarow[$s][$t]), 2, "0", STR_PAD_LEFT); //Weapon 1-25
										$DamageBlob .= str_pad(dechex($shipdatarow[$s][$t]), 2, "0", STR_PAD_LEFT); //Weapon 1-25
									}

									
									$StoresBlob = "";
									
									$StoresBlob .= "0101"; //same for all
									$StoresBlob .= "00"; //Type 1 drones / none
									$StoresBlob .= "00"; //slow drones / none
									$StoresBlob .= "01"; // Reloads of drones  (is one even for ships with no drones)
									$StoresBlob .= "00"; // spacer
									//to determine total number of racks and drone totals DroA DroB DroC DroF DroG DroM DroE
									$numracks = 0;
									$defdronetot = 0;
									for ($t = 27; $t <= 99; $t+=3) {
										if ($shipdatarow[$s][$t] == "DroA" or $shipdatarow[$s][$t] == "DroC" or $shipdatarow[$s][$t] == "DroF" or $shipdatarow[$s][$t] == "DroG" or $shipdatarow[$s][$t] == "DroM") {
											$numracks = $numracks + $shipdatarow[$s][$t-1];
											$defdronetot = $defdronetot + ($shipdatarow[$s][$t-1] * 4 * 2);
										}
										if ($shipdatarow[$s][$t] == "DroB" or $shipdatarow[$s][$t] == "DroE") {
											$numracks = $numracks + $shipdatarow[$s][$t-1];
											$defdronetot = $defdronetot + ($shipdatarow[$s][$t-1] * 6 * 2);
										}
									}
									$StoresBlob .= str_pad(dechex($numracks), 2, "0", STR_PAD_LEFT); // Number of drone racks
									$StoresBlob .= "00"; // spacer
									$StoresBlob .= str_pad(dechex($defdronetot), 2, "0", STR_PAD_LEFT); // Total remaining drones
									$StoresBlob .= "00"; // spacer
									$StoresBlob .= "00"; // spacer
									$StoresBlob .= "00"; // spacer
									$StoresBlob .= str_pad(dechex($defdronetot), 2, "0", STR_PAD_LEFT); // Total drones in storage
									for ($t = 27; $t <= 99; $t+=3) {
										if ($shipdatarow[$s][$t] == "DroA" or $shipdatarow[$s][$t] == "DroC" or $shipdatarow[$s][$t] == "DroF" or $shipdatarow[$s][$t] == "DroG" or $shipdatarow[$s][$t] == "DroB" or $shipdatarow[$s][$t] == "DroM" or $shipdatarow[$s][$t] == "DroE") {
											$StoresBlob .= "000000"; // spacer (covering drones in rack - unused at this point)
											if ($shipdatarow[$s][$t] == "DroA" or $shipdatarow[$s][$t] == "DroC" or $shipdatarow[$s][$t] == "DroF" or $shipdatarow[$s][$t] == "DroG" or $shipdatarow[$s][$t] == "DroM") {
												$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t-1] * 4 * 2), 2, "0", STR_PAD_LEFT); // drones in storage for that rack
											}
											if ($shipdatarow[$s][$t] == "DroB" or $shipdatarow[$s][$t] == "DroE") {
												$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t-1] * 6 * 2), 2, "0", STR_PAD_LEFT); // drones in storage for that rack
											}
											$StoresBlob .= "00"; // spacer
											$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t-1]), 2, "0", STR_PAD_LEFT); // number of racks on that mount
											$StoresBlob .= "00"; // spacer
											if ($shipdatarow[$s][$t] == "DroA" or $shipdatarow[$s][$t] == "DroC" or $shipdatarow[$s][$t] == "DroF" or $shipdatarow[$s][$t] == "DroG" or $shipdatarow[$s][$t] == "DroM") {
												$StoresBlob .= "04"; // drones per rack of that type
											}
											if ($shipdatarow[$s][$t] == "DroB" or $shipdatarow[$s][$t] == "DroE") {
												$StoresBlob .= "06"; // drones per rack of that type
											}
										} else {
											$StoresBlob .= "0000000000000000";
										}
									} // finished drones
									$StoresBlob .= "00"; //spacer
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][111]), 2, "0", STR_PAD_LEFT); //Base shuttles
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][112]), 2, "0", STR_PAD_LEFT); //Max shuttles
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][111]), 2, "0", STR_PAD_LEFT); //Current shuttles
									$StoresBlob .= "00000000000000000000000000"; // spacer
									$StoresBlob .= "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; // spacer?
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][16]), 2, "0", STR_PAD_LEFT); //Max boarding parties									
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][15]), 2, "0", STR_PAD_LEFT); //Base boarding parties
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][15]), 2, "0", STR_PAD_LEFT); //Current boarding parties
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][103]), 2, "0", STR_PAD_LEFT); //Max mines
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][102]), 2, "0", STR_PAD_LEFT); //Base mines
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][102]), 2, "0", STR_PAD_LEFT); //Current mines
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][144]*5), 2, "0", STR_PAD_LEFT); //Max Spares (5 x Damage Control)
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Base Spares (Damage Control)
									$StoresBlob .= str_pad(dechex($shipdatarow[$s][144]), 2, "0", STR_PAD_LEFT); //Current Spares (Damage Control)
									//fighters to go...
									//if ($shipdatarow[$s][113] == "" and $shipdatarow[$s][115] == "" and $shipdatarow[$s][117] == "" and $shipdatarow[$s][119] == ""){
									//$StoresBlob .= "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
									//}
									for ($t = 113; $t <= 119; $t+=2) {
										if ($shipdatarow[$s][$t] == ""){
											$StoresBlob .= "000000000000000000000000";
										} else {
											$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t]), 2, "0", STR_PAD_LEFT); // current fighters in bay
											$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t]), 2, "0", STR_PAD_LEFT); // base fighters for bay
											$StoresBlob .= str_pad(dechex($shipdatarow[$s][$t]), 2, "0", STR_PAD_LEFT); // max fighters for bay
											$StoresBlob .= "00"; //spacer
											$StoresBlob .= str_pad(dechex(strlen($shipdatarow[$s][$t+1])), 2, "0", STR_PAD_LEFT); // name length of fighter in bay
											$StoresBlob .= "000000"; //spacer
											$fightertypename = "";
											for ($u = 0; $u <= strlen($shipdatarow[$s][$t+1]) - 1; $u++) {
												$fightertypename .= str_pad(dechex(ord(substr($shipdatarow[$s][$t+1], $u, 1))), 2, "0", STR_PAD_LEFT); // fighter type name
											}
											$StoresBlob .= $fightertypename;
											$StoresBlob .= str_pad(dechex(strlen($shipdatarow[$s][$t+1])), 2, "0", STR_PAD_LEFT); // name length of base fighter
											$StoresBlob .= "000000"; //spacer
											$StoresBlob .= $fightertypename;
										}
									}

									$StoresSize = strlen($StoresBlob)/2;

								}
							}

							$link = mysql_connect($D2dbhostname .":" .$D2dbport, $D2dbuser, $D2dbpass);
   							mysql_select_db($D2db);
    							$query = "SELECT CurrentTime FROM campaigninfo";
    							$result = mysql_query($query);
					
							$line = mysql_fetch_array($result, MYSQL_ASSOC);

							$CurrentTime = $line['CurrentTime'];

    							mysql_free_result($result);

							$TurnNoHex = substr($CurrentTime, 0, 8);
							$TurnNoDec = hexdec(substr($TurnNoHex,0,2)) + hexdec(substr($TurnNoHex,2,2))*256 + hexdec(substr($TurnNoHex,4,2))*65536 + hexdec(substr($TurnNoHex,6,2))*16777216;					


    							$query = "SELECT NextID FROM databasedescription";
    							$result = mysql_query($query);
				
							$line = mysql_fetch_array($result, MYSQL_ASSOC);
							//$BidID = $line['NextID'] + mt_rand("50000000","60000000");
							$BidID = $line['NextID'];

    							mysql_free_result($result);

    							$query = "UPDATE databasedescription SET ID=1, LOCKED='1969-12-31 19:00:00', LOCKID=0, NextID=";
							$query .= $BidID + 2;
							$query .= ", NextLockID=1";
    							$result = mysql_query($query);

							//echo mysql_errno() . ": " . mysql_error() . "\n";
							//echo ("<br><br>");
    							//mysql_free_result($result);


    							$query = "INSERT INTO ship (ID, LOCKED, LOCKID, Owner, IsInAuction, Race, ClassType, BPV, EPV, ShipClassName, TurnCreated, Name, DamageSize, Damage, StoresSize, Stores, OfficersSize, Officers, Flags) ";
							$query .= "VALUES (";
							$query .= $BidID;
							$query .= ", ";
							$query .= "'1969-12-31 19:00:00'";
							$query .= ", ";
							$query .= "0";
							$query .= ", ";
							$query .= "0";
							$query .= ", ";
							$query .= "1";
							$query .= ", ";
							$query .= $buyshipRace;
							$query .= ", ";
							$query .= $buyshipClass;
							$query .= ", ";
							$query .= $BPV;
							$query .= ", ";
							$query .= $BPV;
							$query .= ", '";
							$query .= $ShipClassName;
							$query .= "', ";
							$query .= $TurnNoDec;
							$query .= ", ";
							$query .= "'HMCS Webmap'";
							$query .= ", ";
							$query .= "100";
							$query .= ", '";
							$query .= $DamageBlob;
							$query .= "', ";
							$query .= $StoresSize;
							$query .= ", '";
							$query .= $StoresBlob;
							$query .= "', ";
							$query .= "112";
							$query .= ", ";
							$query .= "'00000000010000000000000000000000000000000100000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000001000000000000000000000000000000010000000000000000000000'";
							$query .= ", ";
							$query .= "0";
							$query .= ")";
					
    							$result = mysql_query($query);
							//echo ("<br><br>*********SQL ERROR*************<br><br>");
							//echo mysql_errno() . ": " . mysql_error() . "\n";
							//echo ("<br><br>*********SQL ERROR*************<br><br>");
    							//mysql_free_result($result);

    							$query = "INSERT INTO biditem (ID, LOCKED, LOCKID, BiddingHasBegun, ItemName, ItemID, ItemInfo, AuctionValue, AuctionRate, TurnOpened, TurnToClose, CurrentBid, BidOwnerID, TurnBidMade, BidMaximum) ";
							$query .= "VALUES (";
							$query .= $BidID + 1;
							$query .= ", ";
							$query .= "'1969-12-31 19:00:00'";
							$query .= ", ";
							$query .= "0";
							$query .= ", ";
							$query .= "1";
							$query .= ", '";
							$query .= $ShipClassName;
							$query .= "', ";
							$query .= $BidID;
							$query .= ", ";
							$query .= $BPV;
							$query .= ", ";
							$query .= $BPV;
							$query .= ", ";
							$query .= "0";
							$query .= ", ";
							$query .= $TurnNoDec;
							$query .= ", ";
							$query .= $TurnNoDec + 1;
							$query .= ", ";
							$query .= $bid;
							$query .= ", ";
							$query .= $BidOwnerID;
							$query .= ", ";
							$query .= $TurnNoDec;
							$query .= ", ";
							$query .= $bid + 5;
							$query .= ")";
					
    							$result = mysql_query($query);
							//echo mysql_errno() . ": " . mysql_error() . "\n";
							//echo ("<br><br>");
    							//mysql_free_result($result);


    							//$query = "UPDATE ship SET IsInAuction=1 WHERE ID=";
							//$query .= $shipID;			
    							//$result = mysql_query($query);
							//echo mysql_errno() . ": " . mysql_error() . "\n";
							//echo ("<br><br>");
    							//mysql_free_result($result);



							$NewPP = $CurrentPP - $bid;

    							$query = "UPDATE servcharacter SET CharacterCurrentPrestige=";
							$query .= $NewPP;
							$query .= " WHERE ID=";
							$query .= $BidOwnerID;			
    							$result = mysql_query($query);
							//echo mysql_errno() . ": " . mysql_error() . "\n";
							//echo ("<br><br>");
    							//mysql_free_result($result);
    							mysql_close($link);

							echo ("<br><b>Your ship has been purchased... Please wait for the shipyard to reload...</b><br><br>");

						// $CurrentPP >= $bid endif
						}


						if ($CurrentPP < $bid) {
							echo ("<br>Sorry, you do not have enough Prestige Points<br><br>");
							echo ("<b>Ship not purchased...</b><br><br>");

						// $CurrentPP < $bid endif
						}


					// $shipstotal < 3 endif
					}


					if ($shipstotal >= 3) {
						echo ("You already own ");
						echo $shipsowned;
						echo (" ships, and have bid on ");
						echo $shipsbidon;
						echo (".<br><br>");
						echo ("<b>Ship not purchased...</b>");

					// shiptstotal >= endif
					}


				// login val true endif
				} else {
					echo ("<br>");
					echo ("<table width=25% cellspacing=0 cellpadding=0 border=0 align=center>");
  					echo ("<tr>");
    					echo ("<td width=100% align=center class=windowbg2>");
					echo ("<br>");
					echo ("<b>Please login with your forums ID:<b>");
					echo ("<br><br>");
					$loginurl = $webmaproot . "shipyard.php";
					ssi_login($loginurl);
					echo ("<br>");
					echo ("</td>");
					echo ("</tr>");
					echo ("</table>");
				}
				

	echo ("</td>");
	echo ("</tr>");
echo ("</table>");

echo ("</body>");

unset($shipdatarow);

echo ("</html>");

?>