View Single Post
  #2  
Old 11-01-2013, 09:09 PM
Akkadius's Avatar
Akkadius
Administrator
 
Join Date: Feb 2009
Location: MN
Posts: 2,072
Default

Doing this is duplication of work unecessarily that already works 100%.

All you had to do is reply to the original post that was made when you first made the claim.

My Firefox works just fine, I test on Chrome and Firefox (IE Can go die in a fire) - if yours doesn't work than you either need to update or stop blocking javascript because EoC uses it for performance and simplicity of the interface. Posted pictures below to prove I had tested this for you.

If you wanted to make one yourself just for the sake of doing it then that is your call. I've already gone through the pain of making sure that the schematic imports go smoothly given certain scenarios exist that you may not have been anticipating originally.

I may come off like a dick - probably because I am and I'm tired as shit from moving, but either way here is the details:

EOC Does the following:
  • Cloning Doors
  • Cloning Objects
  • Cloning NPC's into new or existing NPC types data
  • Cloning new or existing grids
  • Importing from a completely different database
  • All of these from one version to another
  • Does full zone copies within seconds
  • Full deletion of versions





Here's the database calls that copy all of the schemas: (AJAX)

The below code does not consider injection because there is no database to inject but your own.

Code:
	if($_GET['ZoneID'] && $_GET['ImportSelector'] == 1){
	
		/* 2nd DB Connection Stuff */
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db2);
		while($row = mysql_fetch_array($QueryResult)){
			echo '<br><br><h1><FONT COLOR="YELLOW">' . $row['long_name'] . '</FONT></h1>';
			$ZoneSN = $row['short_name'];
		}
		echo '<br>';
		$Query = "SELECT version, COUNT(*) AS total FROM `spawn2` WHERE `zone` = '". $ZoneSN . "' GROUP by `version`";
		$QueryResult = mysql_query($Query, $db2);
		while($row = mysql_fetch_array($QueryResult)){
			echo '<h4> Version: ' . $row['version'] . ' Spawn Count: ' . $row['total'] . '</h4>';
		}
		echo '<br><h2>Import Options</h2>';
		$Query = "SELECT version, COUNT(*) AS total FROM `spawn2` WHERE `zone`  = '". $ZoneSN . "' GROUP by `version`";
		$QueryResult = mysql_query($Query, $db2);
		echo '<table>';
		echo '<tr><td>Source Version (2nd DB)</td><td><select id="VersionSourceR">'; 
		while($row = mysql_fetch_array($QueryResult)){
			echo '<option value="'. $row['version'] . '">Version '. $row['version'] . ' (' . $row['total'] . ')</option>';
		}
		echo '</select></td><td><a href="javascript:;" onclick="ListZoneRemote('. $_GET['ZoneID'] .', document.getElementById(\'VersionSourceR\').value)">List this zone</a></td></tr>';
		
		
		/* 1st DB Connection Stuff */
		$Query = "SELECT version, COUNT(*) AS total FROM `spawn2` WHERE `zone`  = '". $ZoneSN . "' GROUP by `version`";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){
			echo '<option value="'. $row['version'] . '">Version '. $row['version'] . ' (' . $row['total'] . ')</option>';
			$VersionData[$row['version']] = $row['total'];
		}
		echo '<tr><td>Destination Version (Primary DB)</td><td><select id="VersionDestD">';
		for($i = 0; $i <= 100; $i++){
			if($VersionData[$i]){ $VVersion = $VersionData[$i]; } else { $VVersion = 0; }
			echo '<option value="' . $i . '">Version '. $i . ' (' . $VVersion . ')</option>';
		}
		echo '</select></td><td><a href="javascript:;" onclick="ListZoneLocal('. $_GET['ZoneID'] .', document.getElementById(\'VersionDestD\').value)">List this zone</a></td>';
		echo '<tr><td>Import Doors? </td><td><select id="importdoors"><option value="0">No</option><option value="1">Yes</option></select></td></tr>';
		echo '<tr><td>Import Objects? </td><td><select id="importobjects"><option value="0">No</option><option value="1">Yes</option></select></td></tr>';
		echo '</tr></table>';
		echo '<br><input type="button" value="Import!" class="btnIconLeft mr10" onclick="CopyZoneVersionExtToLoc('. $_GET['ZoneID'] . ', document.getElementById(\'VersionSourceR\').value, document.getElementById(\'VersionDestD\').value, document.getElementById(\'importdoors\').value, document.getElementById(\'importobjects\').value)">';
		echo '<div id="CopyZoneVersionExtToLoc"></div>';
	}
	if($_GET['ZoneID'] && isset($_GET['Version']) && $_GET['ListZone']){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db2);
		if($_GET['Version']){ $Version = $_GET['Version']; } else{ $Version = 0; }
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
		$Query = "SELECT
			npc_types.id,
			npc_types.name,
			npc_types.lastname,
			npc_types.level,
			npc_types.race,
			spawnentry.chance,
			spawn2.zone,
			spawn2.`version`,
			spawn2.pathgrid
			FROM
			npc_types
			Inner Join spawnentry ON npc_types.id = spawnentry.npcID
			Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
			WHERE spawn2.zone = '". $ZoneSN . "' AND spawn2.version = ". $Version . "
			ORDER BY npc_types.id";
			#echo $Query;
		echo '<div class="widget">
				<div class="head opened" id="opened"><h5>\'' . $ZoneSN . '\' 2nd DB (Remote)</h5></div>
				<div class="body">';
			AutoDataTableZone($Query, $db2);
	}
	if($_GET['ZoneID'] && isset($_GET['Version']) && $_GET['ListZoneLocal']){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
		$Query = "SELECT
			npc_types.id,
			npc_types.name,
			npc_types.lastname,
			npc_types.level,
			npc_types.race,
			spawnentry.chance,
			spawn2.zone,
			spawn2.`version`,
			spawn2.pathgrid
			FROM
			npc_types
			Inner Join spawnentry ON npc_types.id = spawnentry.npcID
			Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
			WHERE spawn2.zone = '". $ZoneSN . "' AND spawn2.version = ". $_GET['Version'] . "
			ORDER BY npc_types.id";
		echo '<div class="widget">
				<div class="head opened" id="opened2"><h5>\'' . $ZoneSN . '\' 1st DB (Primary)</h5></div>
				<div class="body">';
			AutoDataTableZone($Query, $db);
	}
	if($_GET['ZoneID'] && $_GET['CopyTool'] == "importzone"){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
			echo '<br><h4>Zone Importer</h4><br>
			<!-- Login form area -->
				<div class="loginWrapper">
					<center><img src="../images/eqemu.png" alt="" /><br><img src="images/eoc-fd.png" alt=""/></center>
					<div class="loginPanel">
						<div class="head"><h5 class="iUser">Connect to a 2nd Database...</h5></div>
						<form action="zonetools.php?ImportMode=1" id="valid" class="mainForm" method="post">
							<fieldset>
								<div class="loginRow">
									<label for="req1">IP:Port</label>
									<div class="loginInput"><input type="text" id="dbservipport2" name="dbservipport2" value="'. $_COOKIE['dbip2'] . '" class="validate[required]" /></div>
									<div class="fix"></div>
								</div>
								
								<div class="loginRow">
									<label for="req2">DB Name</label>
									<div class="loginInput"><input type="text" id="dbname2" name="dbname2" value="'. $_COOKIE['dbname2'] . '" class="validate[required]" /></div>
									<div class="fix"></div>
								</div>
								
								<div class="loginRow">
									<label for="req2">DB User</label>
									<div class="loginInput"><input type="text" id="dbuser2" name="dbuser2" value="'. $_COOKIE['dbuser2'] . '" class="validate[required]"  /></div>
									<div class="fix"></div>
								</div>
								
								<div class="loginRow">
									<label for="req2">DB Pass</label>
									<div class="loginInput"><input type="password" id="dbpass2" name="dbpass2" value="'. $_COOKIE['dbpass2'] . '" class="validate[required]" /></div>
									<div class="fix"></div>
								</div>
								<input type="button" value="Check Connection" class="basicBtn submitForm" onclick="TestDBAuth(document.getElementById(\'dbservipport2\').value, document.getElementById(\'dbname2\').value, document.getElementById(\'dbuser2\').value, document.getElementById(\'dbpass2\').value)" />
								<div id="DBAUTH"></div>
							</fieldset>
						</form>
					</div>
				</div>';
	}	
	if($_GET['ZoneID'] && $_GET['CopyTool'] == "copyzone"){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
	
		echo '<br><h4>Copy Zone Version</h4><br>';
		$Query = "SELECT version, COUNT(*) AS total FROM `spawn2` WHERE `zone`  = '". $ZoneSN . "' GROUP by `version`";
		$QueryResult = mysql_query($Query, $db);
		echo '<table>';
		echo '<tr><td>Source Version</td><td><select id="VersionSource">'; 
		while($row = mysql_fetch_array($QueryResult)){
			echo '<option value="'. $row['version'] . '">Version '. $row['version'] . ' (' . $row['total'] . ')</option>';
			$VersionData[$row['version']] = $row['total'];
		}
		echo '</select></td></tr>';
		
		echo '<tr><td>Destination Version</td><td><select id="VersionDest">';
		for($i = 0; $i <= 100; $i++){
			if($VersionData[$i]){ $VVersion = $VersionData[$i]; } else { $VVersion = 0; }
			echo '<option value="' . $i . '">Version '. $i . ' (' . $VVersion . ')</option>';
		}
		echo '</select></td></tr></table>';
		echo '<br><h4>Options</h4>';
		echo 'NPC Data: <select id="NPCDATA" onchange="ToggleOtherOptions(this.value)"><option value="existing">Use Existing Data</option><option value="copy">Copy NPC\'s into New Data</option></select><br>'; 
		echo '<div id="NPCGRIDS"></div>';
		echo '<br><input type="button" value="Copy!" class="btnIconLeft mr10" onclick="CopyZoneVersion('. $_GET['ZoneID'] . ', document.getElementById(\'VersionSource\').value, document.getElementById(\'VersionDest\').value, document.getElementById(\'NPCDATA\').value, document.getElementById(\'NPCGRIDS\').value)">';
		echo '<br><div id="ZoneToolCopyZoneSelectOP2"></div>';
	}
	if($_GET['NPCGRIDSSHOW'] == "copy"){
		echo 'NPC Grids: <select id="NPCGRIDS"><option value="existing">Use Existing Data</option><option value="copy">Copy Grids into New ID\'s</option></select><br>'; 
	}
	if($_GET['ZoneID'] && $_GET['ImportTool'] && isset($_GET['Source']) && isset($_GET['Dest'])){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db2);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
		#echo $db1 . ' ' . $db2  . '<br>'; 	
		/* Cache the Data for after reference */
		#echo var_dump($_GET);
		#return;
		
		if($_GET['Doors'] == 1){
			echo 'Doors is getting dumped yo<br>';
			/* Doors */
			$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `doors`', $db);
			$row = mysql_fetch_assoc($result);
			$ID = $row['id'];
			$result = mysql_query('SELECT MAX(doorid) + 1 AS id FROM `doors` WHERE `zone` = "' . $ZoneSN .'" AND (version = ' . $_GET['Source'] . ' or version = -1);', $db);
			$row = mysql_fetch_assoc($result);
			$DoorID = $row['doorid'];
			
			$Query = "SELECT * FROM `doors` WHERE `zone` = '" . $ZoneSN . "' AND (version = " . $_GET['Source'] . " OR version = -1)";
			$QueryResult = mysql_query($Query, $db2);
			while ($row = mysql_fetch_array($QueryResult)) { 
				// Do Stuff here
				$InsertQuery = "INSERT INTO `doors` (";
				$InsertQuery2 = "";
				$n = 0; $f = 0;
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$type  = mysql_field_type($QueryResult, $f);
						$name  = mysql_field_name($QueryResult, $f);
						#if($type == "int" && $v == ""){ echo 'FOUND INTEGER WITH NO VALUE (' . $f . ': ' . $name . ' - ' . $k .') k ' . $k . ' v '. $v . '<br>'; }
						if($type == "int" && $v == ""){ $v = 0; }
						$InsertQuery .= $k . ", ";
						if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else if($k == "version"){ $InsertQuery2 .= "'" . $_GET['Dest'] . "', "; }
						else if($k == "doorid"){ $InsertQuery2 .= "'" . $DoorID . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
						$f++;
					}
					$n++;
				}
				#$NewReferenceList[$row['id']] = $ID;
				$ID++;
				$DoorID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				mysql_query($Query, $db);
				#echo $Query . '<br>';
			}
		}
		
		if($_GET['Objects'] == 1){
			echo 'Objects is getting dumped yo<br>';
			/* Objects */
			$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `object`', $db);
			$row = mysql_fetch_assoc($result);
			$ID = $row['id'];
			$Query = "SELECT * FROM `object` WHERE `zoneid` = " . $_GET['ZoneID'] . " AND (version = " . $_GET['Source'] . " OR version = -1)";
			$QueryResult = mysql_query($Query, $db2);
			while ($row = mysql_fetch_array($QueryResult)) { 
				// Do Stuff here
				$InsertQuery = "INSERT INTO `object` (";
				$InsertQuery2 = "";
				$n = 0; $f = 0;
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$type  = mysql_field_type($QueryResult, $f);
						$name  = mysql_field_name($QueryResult, $f);
						#if($type == "int" && $v == ""){ echo 'FOUND INTEGER WITH NO VALUE (' . $f . ': ' . $name . ' - ' . $k .') k ' . $k . ' v '. $v . '<br>'; }
						if($type == "int" && $v == ""){ $v = 0; }
						$InsertQuery .= $k . ", ";
						if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else if($k == "version"){ $InsertQuery2 .= "'" . $_GET['Dest'] . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
						$f++;
					}
					$n++;
				}
				$ID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				mysql_query($Query, $db);
				#echo $Query . '<br>';
			}
		}
		
		/* Grids */ 
		$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `grid` WHERE `zoneid` = "'. $_GET['ZoneID'] . '"', $db);
		$row = mysql_fetch_assoc($result);
		$ID = $row['id'];

		$Query = "SELECT * FROM `grid` WHERE `zoneid` = '". $_GET['ZoneID'] . "'";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) { 
			$n = 0;
			$InsertQuery = "INSERT INTO `grid` (";
			$InsertQuery2 = "";
			foreach ($row as $k=>$v){
				if($n > 0 && !is_numeric($k)){
					$InsertQuery .= $k . ", ";
					if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
					else{ $InsertQuery2 .= "'" . $v . "', "; }
				}
				$n++;
			}
			$GridList[$row['id']] = $ID;
			$ID++;
			$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
			mysql_query($Query, $db);
			#echo $Query . '<br>';
		}
		
		$Query = "SELECT * FROM `grid_entries` WHERE `zoneid` = '". $_GET['ZoneID'] . "'";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) { 
			$n = 0;
			$InsertQuery = "INSERT INTO `grid_entries` (";
			$InsertQuery2 = "";
			foreach ($row as $k=>$v){
				if($n > 0 && !is_numeric($k)){
					$InsertQuery .= $k . ", ";
					if($k == "gridid"){ $InsertQuery2 .= "'" . $GridList[$row['gridid']] . "', "; }
					else{ $InsertQuery2 .= "'" . $v . "', "; }
				}
				$n++;
			}
			$GridList[$row['id']] = $ID;
			$ID++;
			$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
			mysql_query($Query, $db);
			#echo $Query . '<br>';
		}
		
		/* npc_types */
		$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `npc_types`', $db);
		$row = mysql_fetch_assoc($result);
		$ID = $row['id'];
		$Query = "SELECT
			npc_types.*
			FROM
			spawnentry
			Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
			Inner Join npc_types ON npc_types.id = spawnentry.npcID WHERE `zone` = '" . $ZoneSN . "'  AND spawn2.version = " . $_GET['Source'] . " GROUP by npc_types.id";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) { 
			// Do Stuff here
			$InsertQuery = "INSERT INTO `npc_types` (";
			$InsertQuery2 = "";
			$n = 0; $f = 0;
			#$fields = mysql_num_fields($QueryResult);
			#for ($i=0; $i < $fields; $i++) {
			#	$type  = mysql_field_type($QueryResult, $i);
			#	$name  = mysql_field_name($QueryResult, $i);
			#	echo $i . ' ' . $name . ' <br>';
			#}
			foreach ($row as $k=>$v){
				if($n > 0 && !is_numeric($k)){
					$type  = mysql_field_type($QueryResult, $f);
					$name  = mysql_field_name($QueryResult, $f);
					#if($type == "int" && $v == ""){ echo 'FOUND INTEGER WITH NO VALUE (' . $f . ': ' . $name . ' - ' . $k .') k ' . $k . ' v '. $v . '<br>'; }
					if($type == "int" && $v == ""){ $v = 0; }
					$InsertQuery .= $k . ", ";
					if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
					else{ $InsertQuery2 .= "'" . $v . "', "; }
					$f++;
				}
				$n++;
			}
			$NewReferenceList[$row['id']] = $ID;
			$ID++;
			$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
			mysql_query($Query, $db);
			#echo $Query . '<br>';
		}
		
		/* spawngroup */
		$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `spawngroup`', $db);
		$row = mysql_fetch_assoc($result);
		$ID = $row['id'];
		$Query = "SELECT
			spawngroup.*
			FROM
			spawn2
			Inner Join spawngroup ON spawngroup.id = spawn2.spawngroupID
			WHERE spawn2.zone = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . "";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) {
			$n = 0;
			$InsertQuery = "INSERT INTO `spawngroup` (";
			$InsertQuery2 = "";
			foreach ($row as $k=>$v){
				if($n > 0 && !is_numeric($k)){
					$InsertQuery .= $k . ", ";
					if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
					else if($k == "name"){ $InsertQuery2 .= "'" . $ZoneSN . '_' . $ID . "', "; }
					else{ $InsertQuery2 .= "'" . $v . "', "; }
				}
				$n++;
			}
			$SpawnGroup[$row['id']] = $ID;
			$ID++;
			$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
			##echo $Query . '<br>';
			mysql_query($Query, $db);
			#echo $Query . '<br>';
		}
		
		/* spawnentry */	
		$Query = "SELECT
			spawnentry.spawngroupID,
			spawnentry.npcID,
			spawnentry.chance
			FROM
			spawnentry
			Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
			WHERE spawn2.zone = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . "";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) { 
			$n = 0;
			$InsertQuery = "INSERT INTO `spawnentry` (";
			$InsertQuery2 = "";
			$NValid = 0;
			foreach ($row as $k=>$v){
				if($n > 0 && !is_numeric($k)){
					if($row['npcID'] != 0){
						$InsertQuery .= $k . ", ";
						if($k == "spawngroupID"){ $InsertQuery2 .= "'" . $SpawnGroup[$row['spawngroupID']] . "', "; }
						else if($k == "npcID"){ $InsertQuery2 .= "'" . $NewReferenceList[$row['npcID']] . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
					} else{ $NValid = 1; }
				}
				$n++;
			}
			$NewSpawnGroupReferenceList[$row['spawngroupID']] = $ID;
			$ID++;
			if($NValid != 1){
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				mysql_query($Query, $db);
				#echo $NewSpawnGroupReferenceList[$row['spawngroupID']] . ' ' . $row['spawngroupID'] . '<br>';
				#echo $Query . '<br>';
			}
		}
		
		/* spawn2 */
		$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `spawn2`', $db);
		$row = mysql_fetch_assoc($result);
		$ID = $row['id'];
		
		$Query = "SELECT * FROM `spawn2` WHERE `zone` = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . "";
		$QueryResult = mysql_query($Query, $db2);
		while ($row = mysql_fetch_array($QueryResult)) {
			if($NewSpawnGroupReferenceList[$row['spawngroupID']]){
				$n = 0;
				$InsertQuery = "INSERT INTO `spawn2` (";
				$InsertQuery2 = "";
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$InsertQuery .= $k . ", ";
						if($GridList[$row['pathgrid']]){ $GRID = $GridList[$row['pathgrid']]; } else{ $GRID = 0; } 
						if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else if($k == "spawngroupID"){ $InsertQuery2 .= "'" . $SpawnGroup[$row['spawngroupID']] . "', "; }
						else if($k == "version"){ $InsertQuery2 .= "'" . $_GET['Dest'] . "', "; }
						else if($k == "pathgrid" && $_GET['NPCGRIDS']){ $InsertQuery2 .= "'" . $GRID . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
					}
					$n++;
				}
				$NewReferenceList[$row['id']] = $ID;
				$ID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				##echo $Query . '<br>';
				mysql_query($Query, $db);
				#echo $Query . '<br>';
			}
		}
		echo '<br>Copy should be successful! Refresh your zone selection<br>';
	}
	if($_GET['ZoneID'] && $_GET['CopyToolSubmit']){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
		
		$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `spawn2`', $db);
		$row = mysql_fetch_assoc($result);
		$ID = $row['id'];
		
		if($_GET['NPCDATA'] == "existing"){
			$Query = "SELECT * FROM `spawn2` WHERE `zone` = '". $ZoneSN . "' AND `version` = " . $_GET['Source'] . "";
			$QueryResult = mysql_query($Query, $db);
			while ($row = mysql_fetch_array($QueryResult)) {
				$n = 0;
				$InsertQuery = "INSERT INTO `spawn2` (";
				$InsertQuery2 = "";
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$InsertQuery .= $k . ", ";
						if($k == "version"){ $InsertQuery2 .= "'" . $_GET['Dest'] . "', "; }
						else if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
					}
					$n++;
				}
				$ID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				mysql_query($Query, $db);
			}
			echo '<br><h4>Newly Created Zone Data</h4><br>';
			AutoDataTableZone("SELECT * FROM `spawn2` WHERE `zone` = '". $ZoneSN . "' AND `version` = " . $_GET['Dest'] . "");
		}
		else if($_GET['NPCDATA'] == "copy"){
			/* Cache the Data for after reference */

			if($_GET['NPCGRIDS']){
				/* Grids */
				$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `grid` WHERE `zoneid` = "'. $_GET['ZoneID'] . '"', $db);
				$row = mysql_fetch_assoc($result);
				$ID = $row['id'];
				
				$Query = "SELECT * FROM `grid` WHERE `zoneid` = '". $_GET['ZoneID'] . "'";
				$QueryResult = mysql_query($Query, $db);
				##echo $Query . '<br>';
				while ($row = mysql_fetch_array($QueryResult)) { 
					$n = 0;
					$InsertQuery = "INSERT INTO `grid` (";
					$InsertQuery2 = "";
					foreach ($row as $k=>$v){
						if($n > 0 && !is_numeric($k)){
							$InsertQuery .= $k . ", ";
							if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
							else{ $InsertQuery2 .= "'" . $v . "', "; }
						}
						$n++;
					}
					$GridList[$row['id']] = $ID;
					$ID++;
					$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
					mysql_query($Query, $db);
					##echo $Query . '<br>';
				}
				
				$Query = "SELECT * FROM `grid_entries` WHERE `zoneid` = '". $_GET['ZoneID'] . "'";
				$QueryResult = mysql_query($Query, $db);
				##echo $Query . '<br>';
				while ($row = mysql_fetch_array($QueryResult)) { 
					$n = 0;
					$InsertQuery = "INSERT INTO `grid_entries` (";
					$InsertQuery2 = "";
					foreach ($row as $k=>$v){
						if($n > 0 && !is_numeric($k)){
							$InsertQuery .= $k . ", ";
							if($k == "gridid"){ $InsertQuery2 .= "'" . $GridList[$row['gridid']] . "', "; }
							else{ $InsertQuery2 .= "'" . $v . "', "; }
						}
						$n++;
					}
					$GridList[$row['id']] = $ID;
					$ID++;
					$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
					mysql_query($Query, $db);
					##echo $Query . '<br>';
				}
				
				
			}	
			
			/* npc_types */
			$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `npc_types`', $db);
			$row = mysql_fetch_assoc($result);
			$ID = $row['id'];
			$Query = "SELECT
				npc_types.*
				FROM
				spawnentry
				Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
				Inner Join npc_types ON npc_types.id = spawnentry.npcID WHERE `zone` = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . " GROUP by npc_types.id";
			$QueryResult = mysql_query($Query, $db);
			##echo $Query . '<br>';
			while ($row = mysql_fetch_array($QueryResult)) { 
				// Do Stuff here
				$n = 0;
				$InsertQuery = "INSERT INTO `npc_types` (";
				$InsertQuery2 = "";
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$InsertQuery .= $k . ", ";
						if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
					}
					$n++;
				}
				$NewReferenceList[$row['id']] = $ID;
				$ID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				mysql_query($Query, $db);
				##echo $Query . '<br>';
			}
			
			/* spawngroup */
			$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `spawngroup`', $db);
			$row = mysql_fetch_assoc($result);
			$ID = $row['id'];
			$Query = "SELECT
				spawngroup.*
				FROM
				spawn2
				Inner Join spawngroup ON spawngroup.id = spawn2.spawngroupID
				WHERE spawn2.zone = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . "";
			$QueryResult = mysql_query($Query, $db);
			##echo $Query . '<br>';
			while ($row = mysql_fetch_array($QueryResult)) {
				$n = 0;
				$InsertQuery = "INSERT INTO `spawngroup` (";
				$InsertQuery2 = "";
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						$InsertQuery .= $k . ", ";
						if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
						else if($k == "name"){ $InsertQuery2 .= "'" . $ZoneSN . '_' . $ID . "', "; }
						else{ $InsertQuery2 .= "'" . $v . "', "; }
					}
					$n++;
				}
				$SpawnGroup[$row['id']] = $ID;
				$ID++;
				$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
				##echo $Query . '<br>';
				mysql_query($Query, $db);
			}
			
			/* spawnentry */	
			$Query = "SELECT
				spawnentry.spawngroupID,
				spawnentry.npcID,
				spawnentry.chance
				FROM
				spawnentry
				Inner Join spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
				WHERE spawn2.zone = '" . $ZoneSN . "' AND spawn2.version = " . $_GET['Source'] . "";
			$QueryResult = mysql_query($Query, $db);
			##echo $Query . '<br>';
			while ($row = mysql_fetch_array($QueryResult)) { 
				$n = 0;
				$InsertQuery = "INSERT INTO `spawnentry` (";
				$InsertQuery2 = "";
				$NValid = 0;
				foreach ($row as $k=>$v){
					if($n > 0 && !is_numeric($k)){
						if($row['npcID'] != 0){
							$InsertQuery .= $k . ", ";
							if($k == "spawngroupID"){ $InsertQuery2 .= "'" . $SpawnGroup[$row['spawngroupID']] . "', "; }
							else if($k == "npcID"){ $InsertQuery2 .= "'" . $NewReferenceList[$row['npcID']] . "', "; }
							else{ $InsertQuery2 .= "'" . $v . "', "; }
						} else{ $NValid = 1; }
					}
					$n++;
				}
				$NewSpawnGroupReferenceList[$row['spawngroupID']] = $ID;
				$ID++;
				if($NValid != 1){
					$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
					mysql_query($Query, $db);
					#echo $NewSpawnGroupReferenceList[$row['spawngroupID']] . ' ' . $row['spawngroupID'] . '<br>';
					##echo $Query . '<br>';
				}
			}
			
			/* spawn2 */
			$result = mysql_query('SELECT MAX(id) + 1 AS id FROM `spawn2`', $db);
			$row = mysql_fetch_assoc($result);
			$ID = $row['id'];
			
			$Query = "SELECT * FROM `spawn2` WHERE `zone` = '" . $ZoneSN . "' and version = " . $_GET['Source'] . "";
			$QueryResult = mysql_query($Query, $db);
			##echo $Query . '<br>';
			while ($row = mysql_fetch_array($QueryResult)) {
				if($NewSpawnGroupReferenceList[$row['spawngroupID']]){
					#echo $row['spawngroupID'] . ' ' . $NewSpawnGroupReferenceList[$row['spawngroupID']] . '<br>';
				
					$n = 0;
					$InsertQuery = "INSERT INTO `spawn2` (";
					$InsertQuery2 = "";
					foreach ($row as $k=>$v){
						if($n > 0 && !is_numeric($k)){
							$InsertQuery .= $k . ", ";
							if($GridList[$row['pathgrid']]){ $GRID = $GridList[$row['pathgrid']]; } else{ $GRID = 0; } 
							if($k == "id"){ $InsertQuery2 .= "'" . $ID . "', "; }
							else if($k == "spawngroupID"){ $InsertQuery2 .= "'" . $SpawnGroup[$row['spawngroupID']] . "', "; }
							else if($k == "version"){ $InsertQuery2 .= "'" . $_GET['Dest'] . "', "; }
							else if($k == "pathgrid" && $_GET['NPCGRIDS']){ $InsertQuery2 .= "'" . $GRID . "', "; }
							else{ $InsertQuery2 .= "'" . $v . "', "; }
						}
						$n++;
					}
					$NewReferenceList[$row['id']] = $ID;
					$ID++;
					$Query = substr($InsertQuery, 0, -2) . ') VALUES ('. substr($InsertQuery2, 0, -2) . ');';
					##echo $Query . '<br>';
					mysql_query($Query, $db);
				}
			}
			echo '<br>Copy should be successful! Refresh your zone selection<br>';
		}
	}
	
	
	if($_GET['ZoneID'] && $_GET['CopyTool'] == "deletezone"){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
	
		echo '<br><h4>Delete Zone Version</h4>';
		$Query = "SELECT version, COUNT(*) AS total FROM `spawn2` WHERE `zone`  = '". $ZoneSN . "' GROUP by `version`";
		$QueryResult = mysql_query($Query, $db);
		echo '<table>';
		echo '<tr><td>Version</td><td><select id="VersionToDelete" onchange="DeleteZoneVersion('. $_GET['ZoneID'] . ', this.value)">'; 
		echo '<option value="">Select...</option>';
		while($row = mysql_fetch_array($QueryResult)){
			echo '<option value="'. $row['version'] . '">Version '. $row['version'] . ' (' . $row['total'] . ')</option>';
			$VersionData[$row['version']] = $row['total'];
		}
		echo '</select></td></tr></table>';
		echo '<br><h4>Options</h4>';
		echo '<table>';
		echo '<tr><td>NPC Data: </td><td><select id="DeleteOption"><option value="partial">Partial: (This zone only had spawn entries from the original)</option><option value="full">Full: Use this when you made a full unique copy from one version to another</option></select></td></tr>'; 
		echo '<tr><td>Delete Objects?</td><td> <input type="checkbox" value="1" id="objdelete"></td></tr>';
		echo '<tr><td>Delete Doors? </td><td><input type="checkbox" value="1" id="doordelete"></td></tr>';
		echo '</tr></table>';
		echo '<br><div id="ZoneToolDeleteData"></div>';
	}
	if($_GET['ZoneID'] && isset($_GET['VersionToDelete']) && !$_GET['Submit']){
		$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
		$QueryResult = mysql_query($Query, $db);
		while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; }
		echo '<input type="button" value="DELETE!" class="btnIconLeft mr10" onclick="DeleteZoneVersionSubmit('. $_GET['ZoneID'] . ', document.getElementById(\'VersionToDelete\').value, document.getElementById(\'DeleteOption\').value, document.getElementById(\'objdelete\').value, document.getElementById(\'doordelete\').value)">';
		echo '<br><br><h4>Spawn2 Data that will be purged:</h4>';
		AutoDataTableZone("SELECT * FROM `spawn2` WHERE `zone` = '". $ZoneSN . "' AND `version` = " . $_GET['VersionToDelete'], $db);
	}
	if($_GET['ZoneID'] && isset($_GET['VersionToDelete']) && $_GET['Submit'] == 1){
		if($_GET['DeleteType'] == "partial"){
			$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
			$QueryResult = mysql_query($Query, $db);
			while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; $ZoneLN = $row['long_name']; }
			mysql_query("DELETE FROM `spawn2` WHERE `zone` = '". $ZoneSN . "' AND `version` = '". $_GET['VersionToDelete'] . "';", $db);
			echo '<h4>' . $ZoneLN . ' with Version ' . $_GET['VersionToDelete'] . ' has been deleted!</h4>';
		}
		if($_GET['DeleteType'] == "full"){
			$Query = "SELECT * FROM `zone` WHERE `zoneidnumber` = ". $_GET['ZoneID'] . " LIMIT 1";
			$QueryResult = mysql_query($Query, $db);
			while($row = mysql_fetch_array($QueryResult)){ $ZoneSN = $row['short_name']; $ZoneLN = $row['long_name']; }

			$Query = "SELECT
				spawn2.pathgrid 
				FROM
				(npc_types) 
				INNER JOIN spawnentry ON npc_types.id = spawnentry.npcID
				INNER JOIN spawn2 ON spawnentry.spawngroupID = spawn2.spawngroupID
				WHERE spawn2.zone = '". $ZoneSN . "' AND spawn2.version = '". $_GET['VersionToDelete'] . "'";
			#echo $Query;
			$QueryAdd1 = ""; $QueryAdd2 = "";
			$QueryResult = mysql_query($Query, $db);
			while($row = mysql_fetch_array($QueryResult)){
				if($row['pathgrid'] > 0){
					$QueryAdd1 .= " OR id='". $row['pathgrid'] . "'";
					$QueryAdd2 .= " OR gridid='". $row['pathgrid'] . "'";
				}
			}
			mysql_query("DELETE FROM grid WHERE id='999999999999' ". $QueryAdd1 . ";", $db);
			mysql_query("DELETE FROM grid_entries WHERE gridid='999999999999' ". $QueryAdd2 . ";", $db);
			
			$Query = "SELECT DISTINCT spawnentry.npcID,spawn2.spawngroupID FROM spawnentry, npc_types, spawngroup, spawn2 WHERE (spawnentry.npcID=npc_types.id) AND (spawnentry.spawngroupID=spawngroup.id) AND (spawn2.spawngroupID = spawnentry.spawngroupID) AND (spawn2.zone='" . $ZoneSN . "') AND (spawn2.version='" . $_GET['VersionToDelete'] . "') ORDER BY npc_types.id";
			$QueryResult = mysql_query($Query, $db);
			while($row = mysql_fetch_array($QueryResult)){
				mysql_query("DELETE FROM spawnentry WHERE spawngroupID='" . $row['spawngroupID'] . "';", $db);
				mysql_query("DELETE FROM spawngroup WHERE id='" . $row['spawngroupID'] . "';", $db);
				mysql_query("DELETE FROM npc_types WHERE id='" . $row['npcID'] . "' AND id > 999;", $db);
			}
			mysql_query("DELETE FROM spawn2 WHERE zone='" . $ZoneSN . "' AND  spawn2.version='" . $_GET['VersionToDelete'] . "'", $db);
		}
		if($_GET['ObjectsDelete'] == 1){ mysql_query("DELETE FROM object WHERE zoneid = " . $_GET['ZoneID'] . " AND version = ". $_GET['VersionToDelete'] . ";", $db); }
		if($_GET['DoorsDelete'] == 1){ mysql_query("DELETE FROM doors WHERE zone = " . $ZoneSN . " AND version = " . $GET['VersionToDelete'] . ";", $db); }
		#echo var_dump($_GET);
		echo 'Zone Version has been deleted successfully!<br>';
	}
Reply With Quote