summaryrefslogtreecommitdiff
path: root/html/import/import_bt.php
blob: fe6a480139e53f3f58840198e78031a3d0fe1439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// get the caps, captimes and store them in the events database
	$sql_capbt = "SELECT col0, col1, col2, col3, col4 FROM uts_temp_$uid WHERE (col1 = 'cap' OR col1 = 'btcap') AND col2 = $playerid";
	$q_capbt = mysql_query($sql_capbt);

	$cap_speed = 0;
        $cap_time = 0;
	$cap_gametime = 0;
	$flag_capture = 0;

	while ($r_capbt = mysql_fetch_array($q_capbt)) {
	      if ($cap_speed == 0 || $r_capbt['col3'] > $cap_speed) {
		    $cap_speed = $r_capbt['col3'];
		    $col0 = $r_capbt['col0']; // time
		    $col1 = $r_capbt['col1']; // cap
		    $col2 = $r_capbt['col2']; // playerid
		    $col3 = $r_capbt['col3']; // speed in 2000 - seconds (old system) or 600000 - hundreds of seconds (new system)
		    $col4 = $r_capbt['col4']; // date in seconds since epoch
	      }
	      $flag_capture++;
        }

	if ($cap_speed != 0) {
		# use col2 to store the rank, col3 to store the captime in seconds and col4 to store the date of the record 
		$col2 = small_count("SELECT DISTINCT col2 FROM uts_temp_$uid WHERE col1 = 'cap' AND col3 > $col3") + 1;
		if ($col1 == "btcap") {
			$col3 = ceil(600000 - $col3) / 100;
		}
		else if ($col1 == "cap") {
			$col3 = ceil((2000 - $col3-1)*100/1.1) / 100;
			$col1 = "btcap";
		}
		$col3 = sprintf("%01.2f", $col3);
		$sql_eventsbt = "INSERT INTO uts_events 
		      (matchid, playerid, col0, col1, col2, col3, col4) VALUES
		      ($matchid, $playerid, '$col0', '$col1', '$col2', '$col3', '$col4')";
		mysql_query($sql_eventsbt) or die (mysql_error());
	}

	if ($flag_capture > 0) {
	$sql_playerflags = "	UPDATE 	uts_player
								SET 	flag_capture = $flag_capture
								WHERE 	id = $playerecordid";
	mysql_query($sql_playerflags) or die(mysql_error());
	}
?>