Пример #1
0
</head>
<?php 
require "php/topbar.php";
?>
<body>
	<div class="maindiv">

<?php 
session_start();
require_once "php/database.php";
require_once "php/storedprocedures.php";
require_once "php/error.php";
if (isset($_GET['confirm']) && $_GET['confirm'] == 'Delete') {
    $db = connectToDatabase();
    if ($db) {
        $info = multigetPostDetails($db, $_SESSION['id'], array($_GET['postid']))[$_GET['postid']];
        $results = deletePost($db, $_SESSION['id'], $_GET['postid'], $_SESSION['token']);
        switch ($results[SP::ERROR]) {
            case ERR::OK:
                echo "<p>Post deleted successfully. Back to <a href='threadview.php?threadid=" . $info[POST::THREAD_ID] . "'thread</p>";
                break;
            case ERR::PERMIS_FAIL:
                echo "<p>You are not permitted to do this.</p>";
                break;
            case ERR::TOKEN_EXPIRED:
            case ERR::TOKEN_FAIL:
            case ERR::USER_NO_TOKEN:
                header("Location: logout.php?error=" . $results[SP::ERROR]);
                break;
            default:
                echo "<p>Error: " . $ERRORS[$results[SP::ERROR]] . "</p>";
Пример #2
0
             break;
         case ERR::TOKEN_FAIL:
         case ERR::TOKEN_EXPIRED:
         case ERR::USER_NO_TOKEN:
             echo "Your session has expired; please <a href='login.php'>log in</a> again.";
             break;
         case ERR::UNKNOWN:
         default:
             echo "An unknown error occurred. Please try again later. Error Code: " . $result[SP::ERROR];
             break;
     }
 } elseif (isset($_POST['editid'])) {
     $result = editPost($db, $_SESSION['id'], $_POST['editid'], $_POST['content'], $_SESSION['token']);
     switch ($result[SP::ERROR]) {
         case ERR::OK:
             $info = multigetPostDetails($db, $_SESSION['id'], array($_POST['editid']))[$_POST['editid']];
             echo "Post made successfully! <a href='threadview.php?threadid=" . $info[POST::THREAD_ID] . "&postid=" . $_POST['editid'] . "'>Back to thread</a>.";
             break;
         case ERR::THREAD_LOCKED:
             echo "The specified thread is locked.";
             break;
         case ERR::PERMIS_FAIL:
             echo "You do not have sufficient permissions to do this.";
             break;
         case ERR::TOKEN_FAIL:
         case ERR::TOKEN_EXPIRED:
         case ERR::USER_NO_TOKEN:
             echo "Your session has expired; please <a href='login.php'>log in</a> again.";
             break;
         case ERR::UNKNOWN:
         default:
Пример #3
0
        case ERR::UNKNOWN:
            echo "There was an issue obtaining post data. Please try again later.";
            break;
    }
}
$max = $page * $postsPerPage + $postsPerPage;
if ($max > $numPosts) {
    $max = $numPosts;
}
$postsToGet = array();
//Intentional; we do stop 1 before $max, otherwise we'd return $postsPerPage + 1 posts.
for ($i = $page * $postsPerPage; $i != $max; ++$i) {
    $postsToGet[] = $postIDs[$i][POST::ID];
}
try {
    $posts = multigetPostDetails($db, $_SESSION['id'], $postsToGet);
} catch (RuntimeException $e) {
    echo $e->getMessage();
}
$userDetails = array();
if ($posts) {
    echo "<ol>";
    foreach ($posts as $ID => $details) {
        switch ($details[SP::ERROR]) {
            case ERR::OK:
                $userID = $details[POST::USER_ID];
                if (!isset($userDetails[$userID])) {
                    // If it doesn't work this time it probably won't work the next time. We can change this to not output it if the error is unknown later, maybe
                    $userDetails[$userID] = getPublicUserDetails($db, $userID);
                }
                echo <<<EOT