2003-03-21 04:38:55 +00:00
|
|
|
<?php
|
2003-08-22 05:36:25 +00:00
|
|
|
require_once("db.inc");
|
2003-03-21 04:38:55 +00:00
|
|
|
require_once("util.inc");
|
|
|
|
require_once("host.inc");
|
|
|
|
|
2003-12-01 06:08:22 +00:00
|
|
|
function fail($msg) {
|
|
|
|
page_head("Host merge failed");
|
|
|
|
echo $msg;
|
|
|
|
page_tail();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
db_init();
|
|
|
|
$user = get_logged_in_user();
|
|
|
|
|
|
|
|
$hostid = $_GET["hostid"];
|
|
|
|
$targetid = $_GET["targetid"];
|
|
|
|
|
2003-12-01 06:08:22 +00:00
|
|
|
if ($hostid == $targetid) {
|
|
|
|
fail("same host");
|
|
|
|
}
|
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
$result = mysql_query("select * from host where id=$hostid");
|
|
|
|
$old_host = mysql_fetch_object($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
if (!$old_host || $old_host->userid != $user->id) {
|
2003-12-01 06:08:22 +00:00
|
|
|
fail("Host not found");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
2003-12-01 06:08:22 +00:00
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
$result = mysql_query("select * from host where id=$targetid");
|
|
|
|
$new_host = mysql_fetch_object($result);
|
|
|
|
mysql_free_result($result);
|
|
|
|
if (!$new_host || $new_host->userid != $user->id) {
|
2003-12-01 06:08:22 +00:00
|
|
|
fail("Host not found");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
2003-08-08 22:30:24 +00:00
|
|
|
|
2003-03-21 04:38:55 +00:00
|
|
|
if (!hosts_compatible($old_host, $new_host)) {
|
2003-12-01 06:08:22 +00:00
|
|
|
fail("Can't merge hosts - they're incompatible");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
|
|
|
|
2003-03-21 21:45:34 +00:00
|
|
|
// update the database:
|
|
|
|
// - add credit from old to new host
|
|
|
|
// - change results to refer to new host
|
|
|
|
// - delete old host
|
|
|
|
|
|
|
|
$t = $old_host->total_credit + $new_host->total_credit;
|
|
|
|
$a = $old_host->expavg_credit + $new_host->expavg_credit;
|
|
|
|
$result = mysql_query("update host set total_credit=$t, expavg_credit=$a where id=$new_host->id");
|
2003-12-01 06:08:22 +00:00
|
|
|
if (!result) {
|
|
|
|
fail("Couldn't update credit of new host");
|
|
|
|
}
|
|
|
|
$result = mysql_query("update result set hostid=$targetid where hostid=$hostid");
|
|
|
|
if (!$result) {
|
|
|
|
fail("Couldn't update results");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
2003-12-01 06:08:22 +00:00
|
|
|
$result = mysql_query("delete from host where id=$hostid");
|
|
|
|
if (!$result) {
|
|
|
|
fail("Couldn't delete host");
|
2003-03-21 04:38:55 +00:00
|
|
|
}
|
2004-01-06 22:09:19 +00:00
|
|
|
Header("Location: show_host_detail.php?hostid=$targetid");
|
2003-03-21 04:38:55 +00:00
|
|
|
|
|
|
|
?>
|