Beispiel #1
0
print "<div class='asg4'>\n";
if (empty($_POST) || $_POST['cancel']) {
    showAddAndClear();
    showBlog();
} elseif ($_POST['submitAdd']) {
    addEntryForm();
} elseif ($_POST['addEntry']) {
    processAddEntry();
    showAddAndClear();
    showBlog();
} elseif ($_POST['submitClear']) {
    askConfirm();
} elseif ($_POST['submitClearConfirmed']) {
    clearBlog();
    showAddAndClear();
    showBlog();
}
print "</div>\n";
//end of opening div
printDocFooter();
//shows any entries that might
//have been saved to the blog
function showBlog()
{
    $blogText = "";
    $fh = fopen("../../../asdf3434/myBlog.txt", "r");
    if (!$fh) {
        print "<h2> no blog entries </h2>" . "\n";
    } else {
        flock($fh, LOCK_SH);
        while (!feof($fh)) {
Beispiel #2
0
                    $insert = "insert into likes(entry_id, liking_user) values(?,?)";
                    $rows = prepared_statement($dbh, $insert, array($entry_id, $liking_user));
                }
            }
            header("Location: toBlog.php?user={$posting_user}");
        } else {
            if (isset($_POST['blogComment'])) {
                $insert = "insert into comments(entry_id, commenting_user, comment_text) values(?, ?, ?)";
                // the current user should remain on the blog page of the user who created the post, which must be determined
                $rows = prepared_statement($dbh, $insert, array($_POST['entryId'], $loggedInUser, $_POST['blogComment']));
                $preparedquery = "SELECT user FROM blog_entry where entry_id = ?";
                $resultset = prepared_query($dbh, $preparedquery, $_POST['entryId']);
                $row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC);
                $posting_user = $row['user'];
                header("Location: toBlog.php?user={$posting_user}");
            } else {
                $user = $_GET['user'];
                $result = $user == $loggedInUser;
                if ($result == 1) {
                    printBlog($dbh, $user);
                } else {
                    showBlog($dbh, $user, $loggedInUser);
                }
            }
        }
    }
}
?>

</body>
</html>