Exemple #1
0
function changeStatus($uid, $pid, $status)
{
    //make permission exception if we're killing -- for kill puzzle button
    if (!(canViewPuzzle($uid, $pid) && (canChangeStatus($uid) || $status == getDeadStatusId()))) {
        utilsError("You do not have permission to modify the status of this puzzle.");
    }
    $sql = sprintf("SELECT pstatus.inTesting FROM puzzle_idea LEFT JOIN pstatus ON puzzle_idea.pstatus =\n        pstatus.id WHERE puzzle_idea.id='%s'", mysql_real_escape_string($pid));
    query_db($sql);
    $inTesting_before = get_element($sql);
    //      echo "<br>inTesting_before is $inTesting_before<br>";
    mysql_query('START TRANSACTION');
    $old = getStatusForPuzzle($pid);
    if ($old == $status) {
        mysql_query('COMMIT');
        return;
    }
    $sql = sprintf("UPDATE puzzle_idea SET pstatus='%s' WHERE id='%s'", mysql_real_escape_string($status), mysql_real_escape_string($pid));
    query_db($sql);
    $oldName = getPuzzleStatusName($old);
    $newName = getPuzzleStatusName($status);
    $comment = "Puzzle status changed from {$oldName} to {$newName}. <br />";
    addComment($uid, $pid, $comment, TRUE);
    if (isStatusInTesting($old)) {
        emailTesters($pid, $status);
    }
    mysql_query('COMMIT');
    $sql = sprintf("SELECT pstatus.inTesting FROM puzzle_idea LEFT JOIN pstatus ON puzzle_idea.pstatus =\n        pstatus.id WHERE puzzle_idea.id='%s'", mysql_real_escape_string($pid));
    query_db($sql);
    $inTesting_after = get_element($sql);
    //      echo "<br>inTesting_after is $inTesting_after<br>";
    if ($inTesting_before == "1" && $inTesting_after == "0") {
        //              echo "<br>inTesting changed from yes to no<br>";
        // For every user that was testing this puzzle, mark the puzzle as doneTesting
        $sql = sprintf("SELECT uid FROM test_queue WHERE pid = '%s'", mysql_real_escape_string($pid));
        query_db($sql);
        $users = get_elements($sql);
        foreach ($users as $user) {
            // echo "<br>Setting puzzle $pid done for user $user<br>";
            doneTestingPuzzle($user, $pid);
        }
        // Now, reset the number-of-testers count for the puzzle.
        resetPuzzleTesterCount($pid);
    }
    if ($inTesting_before == "0" && $inTesting_after == "1") {
        // Status changed into testing; file an automatic testsolve
        // request.
        if (getTestsolveRequestsForPuzzle($pid) == 0) {
            requestTestsolve($uid, $pid, "Automatic testsolve request.");
        }
        if (getWikiPage($pid) == "" || getWikiPage($pid) == NULL) {
            $newpage = defaultWikiPageForPuzzle($pid);
            updateWikiPage($uid, $pid, "", $newpage);
        }
    }
    $fcs = getFactcheckersForPuzzle($pid);
    if (isStatusInFactchecking($status) && !empty($fcs)) {
        // Let existing factcheckers know that we've gone back into
        // factchecking.
        emailFactcheckers($pid);
    }
    // reset approval status on puzz status change
    flushPuzzApprovals($pid);
    if ($status == getDeadStatusId()) {
        //return answer words to pool if we're killing a puzzle
        foreach (getAnswersForPuzzle($pid) as $akey => $answer) {
            //echo "removing answer id $akey<br>";
            removeAnswerKill($uid, $pid, $akey);
        }
        //remove editors from puzzle if we're killing it
        foreach (getEditorsForPuzzle($pid) as $ekey => $editor) {
            //echo "removing editor id $ekey<br>";
            removeEditorKill($uid, $pid, $ekey);
        }
        //utilsError("Debug Breakpoint");
    }
}
    $file = $_FILES['fileupload'];
    uploadFiles($uid, $pid, $type, $file);
    header("Location: " . URL . "/puzzle.php?pid=" . $pid);
    exit(0);
}
if (isset($_POST['addcomment'])) {
    $pid = $_POST['pid'];
    $comment = $_POST['comment'];
    addComment($uid, $pid, $comment, FALSE, FALSE, TRUE);
    header("Location: " . URL . "/puzzle.php?pid=" . $pid);
    exit(0);
}
if (isset($_POST['requestTestsolve'])) {
    $pid = $_POST['pid'];
    $notes = $_POST['notes'];
    requestTestsolve($uid, $pid, $notes);
    header("Location: " . URL . "/puzzle.php?pid=" . $pid);
    exit(0);
}
if (isset($_POST['clearTestsolveRequests'])) {
    $pid = $_POST['pid'];
    clearTestsolveRequests($pid);
    header("Location: " . URL . "/puzzle.php?pid=" . $pid);
    exit(0);
}
if (isset($_POST['clearOneTestsolveRequest'])) {
    $pid = $_POST['pid'];
    clearOneTestsolveRequest($pid);
    header("Location: " . URL . "/puzzle.php?pid=" . $pid);
    exit(0);
}