header("location: index.php");
        exit;
    }
    if (getRequestVar("pagerefresh") == "true") {
        $_SESSION["prefresh"] = true;
        header("location: index.php");
        exit;
    }
}
// Check to see if QManager is running if not Start it.
if (checkQManager() == 0) {
    if ($cfg["AllowQueing"]) {
        if (is_dir($cfg["path"]) && is_writable($cfg["path"])) {
            AuditAction($cfg["constants"]["QManager"], "QManager Not Running");
            sleep(2);
            startQManager($cfg["maxServerThreads"], $cfg["maxUserThreads"], $cfg["sleepInterval"]);
            sleep(2);
        } else {
            AuditAction($cfg["constants"]["error"], "Error starting Queue Manager -- TorrentFlux settings are not correct (path is not valid)");
            if (IsAdmin()) {
                header("location: admin.php?op=configSettings");
                exit;
            } else {
                $messages .= "<b>Error</b> TorrentFlux settings are not correct (path is not valid) -- please contact an admin.<br>";
            }
        }
    }
}
$torrent = getRequestVar('torrent');
$arDoneList = array();
if (isset($_POST['runAll'])) {
function updateConfigSettings()
{
    global $cfg;
    $tmpPath = getRequestVar("path");
    if (!empty($tmpPath) && substr($tmpPath, -1) != "/") {
        // path requires a / on the end
        $_POST["path"] = $_POST["path"] . "/";
    }
    if (array_key_exists("AllowQueing", $_POST) && $_POST["AllowQueing"] != $cfg["AllowQueing"] || array_key_exists("maxServerThreads", $_POST) && $_POST["maxServerThreads"] != $cfg["maxServerThreads"] || array_key_exists("maxUserThreads", $_POST) && $_POST["maxUserThreads"] != $cfg["maxUserThreads"] || array_key_exists("sleepInterval", $_POST) && $_POST["sleepInterval"] != $cfg["sleepInterval"] || array_key_exists("debugTorrents", $_POST) && $_POST["debugTorrents"] != $cfg["debugTorrents"] || array_key_exists("tfQManager", $_POST) && $_POST["tfQManager"] != $cfg["tfQManager"] || array_key_exists("btphpbin", $_POST) && $_POST["btphpbin"] != $cfg["btphpbin"]) {
        // kill QManager process;
        if (getQManagerPID() != "") {
            stopQManager();
        }
        $settings = $_POST;
        saveSettings($settings);
        AuditAction($cfg["constants"]["admin"], " Updating TorrentFlux Settings");
        // if enabling Start QManager
        if ($cfg["AllowQueing"]) {
            sleep(2);
            startQManager($cfg["maxServerThreads"], $cfg["maxUserThreads"], $cfg["sleepInterval"]);
            sleep(1);
        }
    } else {
        $settings = $_POST;
        saveSettings($settings);
        AuditAction($cfg["constants"]["admin"], " Updating TorrentFlux Settings");
    }
    $continue = getRequestVar('continue');
    header("Location: admin.php?op=" . $continue);
}