2003-03-21 04:38:55 +00:00
|
|
|
<?php
|
2004-02-02 23:34:39 +00:00
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/host.inc");
|
2003-03-21 04:38:55 +00:00
|
|
|
|
2003-12-01 06:08:22 +00:00
|
|
|
function fail($msg) {
|
2004-01-08 00:09:26 +00:00
|
|
|
echo "Error: $msg";
|
2003-12-01 06:08:22 +00:00
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2004-01-08 00:09:26 +00:00
|
|
|
function get_host($hostid, $user) {
|
|
|
|
$host = lookup_host($hostid);
|
|
|
|
if (!$host || $host->userid != $user->id) {
|
2004-05-30 21:47:11 +00:00
|
|
|
fail("We have no record of that computer");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
2004-01-08 00:09:26 +00:00
|
|
|
return $host;
|
|
|
|
}
|
2003-12-01 06:08:22 +00:00
|
|
|
|
2004-01-08 00:09:26 +00:00
|
|
|
function merge_hosts($old_host, $new_host) {
|
2004-03-26 22:56:45 +00:00
|
|
|
if ($old_host->id == $new_host->id) {
|
|
|
|
fail("same host");
|
|
|
|
}
|
|
|
|
if (!hosts_compatible($old_host, $new_host)) {
|
|
|
|
fail("Can't merge hosts - they're incompatible");
|
|
|
|
}
|
2003-03-21 04:38:55 +00:00
|
|
|
|
2004-03-26 22:56:45 +00:00
|
|
|
echo "<br>Merging $old_host->id into $new_host->id\n";
|
2004-01-08 00:09:26 +00:00
|
|
|
|
2004-03-26 22:56:45 +00:00
|
|
|
// update the database:
|
|
|
|
// - add credit from old to new host
|
|
|
|
// - change results to refer to new host
|
|
|
|
// - delete old host
|
2004-05-30 21:47:11 +00:00
|
|
|
//
|
2004-03-26 22:56:45 +00:00
|
|
|
$total_credit = $old_host->total_credit + $new_host->total_credit;
|
|
|
|
$recent_credit = $old_host->expavg_credit + $new_host->expavg_credit;
|
2004-03-28 20:22:03 +00:00
|
|
|
$result = mysql_query("update host set total_credit=$total_credit, expavg_credit=$recent_credit where id=$new_host->id");
|
2004-04-20 05:05:52 +00:00
|
|
|
if (!$result) {
|
2004-03-26 22:56:45 +00:00
|
|
|
fail("Couldn't update credit of new host");
|
|
|
|
}
|
|
|
|
$result = mysql_query("update result set hostid=$new_host->id where hostid=$old_host->id");
|
|
|
|
if (!$result) {
|
|
|
|
fail("Couldn't update results");
|
|
|
|
}
|
|
|
|
$result = mysql_query("delete from host where id=$old_host->id");
|
|
|
|
if (!$result) {
|
2004-05-30 21:47:11 +00:00
|
|
|
fail("Couldn't delete record of computer");
|
2004-03-26 22:56:45 +00:00
|
|
|
}
|
2004-01-08 00:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
db_init();
|
|
|
|
$user = get_logged_in_user();
|
|
|
|
|
2004-05-30 21:47:11 +00:00
|
|
|
page_head("Merge computer records");
|
2004-01-08 00:09:26 +00:00
|
|
|
|
|
|
|
$nhosts = $_GET["nhosts"];
|
|
|
|
$hostid = $_GET["id_0"];
|
|
|
|
$latest_host = get_host($hostid, $user);
|
|
|
|
for ($i=1; $i<$nhosts; $i++) {
|
|
|
|
$var = "id_$i";
|
|
|
|
$hostid = $_GET[$var];
|
|
|
|
if (!$hostid) continue;
|
|
|
|
$host = get_host($hostid, $user);
|
|
|
|
if ($host->create_time > $latest_host->create_time) {
|
|
|
|
merge_hosts($latest_host, $host);
|
|
|
|
$latest_host = $host;
|
|
|
|
} else {
|
|
|
|
merge_hosts($host, $latest_host);
|
|
|
|
}
|
2004-06-01 18:55:59 +00:00
|
|
|
// reread latest_host from database since we just
|
|
|
|
// updated its credits
|
|
|
|
//
|
|
|
|
$latest_host = lookup_host($latest_host->id);
|
2004-01-08 00:09:26 +00:00
|
|
|
}
|
|
|
|
echo "
|
|
|
|
<p><a href=hosts_user.php>Return to list of your computers</a>
|
|
|
|
";
|
|
|
|
page_tail();
|
|
|
|
|
|
|
|
//Header("Location: show_host_detail.php?hostid=$latest_host->id");
|
2003-03-21 04:38:55 +00:00
|
|
|
|
|
|
|
?>
|