function updateAddon($curseAddonID)
{
    global $debug, $baseURL, $currentDateTime, $addonName, $ourAddonName, $zipURL, $addonURL, $currentVersion, $currentDownloadID;
    require 'config.php';
    $addonInfo = parseXML(fetchAddonXML($curseAddonID));
    $addonName = $addonInfo[0];
    $addonURL = $addonInfo[1];
    $currentDownloadID = $addonInfo[2];
    $currentVersion = $addonInfo[3];
    $zipURL = $addonInfo[4];
    $currentDateTime = getDateTime();
    $query = "SELECT lastDownloadID from amz_addonsList WHERE curseAddonID=" . $curseAddonID;
    $result = mysql_query($query);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $lastDownloadID = trim($row['lastDownloadID']);
    }
    $query = "UPDATE amz_addonsList SET addonName='{$addonName}', addonURL='{$addonURL}', version='{$currentVersion}', lastUpdateDateTime='{$currentDateTime['0']}', lastUpdateDateTimeHuman='{$currentDateTime['1']}' WHERE curseAddonID={$curseAddonID}";
    if ($debug) {
        echo $query . "<br />";
    }
    $updatesult = mysql_query($query);
    if ($debug && !$updateResult) {
        die('Invalid query: ' . mysql_error());
    }
    if ($currentDownloadID != $lastDownloadID) {
        $updatedNeeded = true;
    }
    if (!file_exists($baseURL . 'cachedZips/' . $addonName . '.zip')) {
        $updatedNeeded = true;
    }
    if (!file_exists($baseURL . 'cachedZips/' . $addonName . '.dir') && !$updatedNeeded) {
        fork('unzip -d "' . $baseURL . 'cachedZips/' . $addonName . '.dir" "' . $baseURL . 'cachedZips/' . $addonName . '.zip"');
    }
    if (!file_exists($baseURL . 'cachedZips/' . $addonName . '.dir/versions/' . $addonName . '.md5') && !$updatedNeeded) {
        md5Addon($addonName);
    }
    if (!$updatedNeeded) {
        return false;
    }
    $_SESSION['addonName'] = $addonName;
    $_SESSION['curseAddonID'] = $curseAddonID;
    $_SESSION['addonSize'] = getContentLength($zipURL);
    touch($baseURL . $curseAddonID . "InProgress");
    fork('wget -O "' . $baseURL . 'cachedZips/' . $addonName . '.zip" ' . $zipURL . ' && rm ' . $baseURL . $curseAddonID . 'InProgress && rm -rf "' . $baseURL . 'cachedZips/' . $addonName . '.dir"; unzip -d "' . $baseURL . 'cachedZips/' . $addonName . '.dir" "' . $baseURL . 'cachedZips/' . $addonName . '.zip" && md5 "' . $baseURL . 'cachedZips/' . $addonName . '.zip" -out "' . $baseURL . 'cachedZips/' . $addonName . '.dir/md5checksum.txt"');
    if (addonExists($curseAddonID)) {
        $query = "UPDATE amz_addonsList SET addonName='{$addonName}', version='{$currentVersion}', addonURL='{$addonURL}', lastDownloadID={$currentDownloadID}, lastDownloadDateTime='{$currentDateTime['0']}', lastDownloadDateTimeHuman='{$currentDateTime['1']}', lastUpdateDateTime='{$currentDateTime['0']}', lastUpdateDateTimeHuman='{$currentDateTime['1']}' WHERE curseAddonID={$curseAddonID}";
    } else {
        $query = "INSERT INTO amz_addonsList (curseAddonID, addonName, version, addonURL, lastDownloadID, lastDownloadDateTime, lastDownloadDateTimeHuman, lastUpdateDateTime, lastUpdateDateTimeHuman) VALUES ({$curseAddonID}, '{$addonName}', '{$currentVersion}', '{$addonURL}', {$currentDownloadID}, '{$currentDateTime['0']}', '{$currentDateTime['1']}', '{$currentDateTime['0']}', '{$currentDateTime['1']}')";
    }
    $result = mysql_query($query);
    if ($debug && !$result) {
        die('Invalid query: ' . mysql_error());
    }
    return true;
}
<?php

session_start();
$baseURL = "../";
require $baseURL . 'functions.php';
require $baseURL . 'config.php';
if (isset($_SESSION['addonName']) && isset($_SESSION['curseAddonID'])) {
    if (!checkForUpdateCompletion($_SESSION['curseAddonID'])) {
        $progressInBytes = checkDownloadProgress($_SESSION['addonName']);
        $progressInKilobytes = round($progressInBytes / 1024);
        $addonSize = $_SESSION['addonSize'];
        $addonSizeInKilobytes = round($addonSize / 1024);
        echo '<font color="blue">' . $_SESSION['addonName'] . ' is currently updating. ' . $progressInKilobytes . 'KB of ' . $addonSizeInKilobytes . 'KB downloaded so far.</font><br />';
        $downloadFinished = true;
    } else {
        if (!$downloadFinished) {
            echo '<font color="blue">' . $_SESSION['addonName'] . ' has completed downloading!<br />';
        } else {
            echo '<font color="blue">' . $_SESSION['addonName'] . ' has been updated!<br />';
        }
        md5Addon($_SESSION['addonName']);
        unset($_SESSION['addonName']);
        unset($_SESSION['curseAddonID']);
        unset($_SESSION['addonSize']);
    }
}
if (isset($_SESSION['message']) || isset($message)) {
    echo "<font color=\"blue\">" . $_SESSION['message'] . $message . "</font><br />&nbsp;<br />";
    unset($_SESSION['message']);
}