index.php
/**
 * Perform the undo action.
 *
 * @param $sql_conn \mysqli The mysqli connection
 */
Perform the undo action.
@param $sql_conn \mysqli The mysqli connection
Perform the undo action . @param $sql_conn \ mysqli The mysqli connection
function act_undo($sql_conn)
{
    $result = $sql_conn->query("SELECT `pid` FROM `problem` WHERE `trashed` = (SELECT MAX(`trashed`) FROM `problem`);");
    if (!$result) {
        die("undo failed: get last trashed");
    }
    $next_pid = $result->fetch_assoc()["pid"];
    $result = $sql_conn->query("UPDATE `problem` SET `follows` = $next_pid WHERE `follows` = 0;");
    if (!$result) {
        die("undo failed: reinstate order step 1");
    }
    $result = $sql_conn->query("UPDATE `problem` SET `follows` = 0 WHERE `pid` = $next_pid;");
    if (!$result) {
        die("undo failed: reinstate order step 2");
    }
    $result = $sql_conn->query("UPDATE `problem` SET `trashed` = NULL WHERE `pid` = $next_pid;");
    if (!$result) {
        die("undo failed: clear trashed timestamp");
    }
    return $next_pid;
}
function act_undo ( $ sql_conn ) { $ result = $ sql_conn -> query ( " SELECT `pid` FROM `problem` WHERE `trashed` = (SELECT MAX(`trashed`) FROM `problem`); " ) ; if ( ! $ result ) { die ( " undo failed: get last trashed " ) ; } $ next_pid = $ result -> fetch_assoc ( ) [ " pid " ] ; $ result = $ sql_conn -> query ( " UPDATE `problem` SET `follows` =  $ next_pid  WHERE `follows` = 0; " ) ; if ( ! $ result ) { die ( " undo failed: reinstate order step 1 " ) ; } $ result = $ sql_conn -> query ( " UPDATE `problem` SET `follows` = 0 WHERE `pid` =  $ next_pid ; " ) ; if ( ! $ result ) { die ( " undo failed: reinstate order step 2 " ) ; } $ result = $ sql_conn -> query ( " UPDATE `problem` SET `trashed` = NULL WHERE `pid` =  $ next_pid ; " ) ; if ( ! $ result ) { die ( " undo failed: clear trashed timestamp " ) ; } return $ next_pid ; }
Perform the undo action.
Perform the undo action .
// Get the ID of the last problem to be moved to the trash // This will be the next problem to be restored // Make former first problem follow the to-be-restored problem // Now make the to-be-restored problem first // Clear the now-restored problem's trashed timestamp