public function testViewGuestBookWithNoEntries() { $GuestBook = new GuestBook(); $GuestBook->deleteAll(); $entries = $GuestBook->viewAll(); $this->assertEmpty($entries); }
public function countUserComments() { $userComments = GuestBook::getUserComments($this); if (is_array($userComments)) { $this->totalComments = count($userComments); } else { $this->totalComments = 0; } }
/** * Load the component GuestBook. * * @param \Cx\Core\ContentManager\Model\Entity\Page $page The resolved page */ public function load(\Cx\Core\ContentManager\Model\Entity\Page $page) { global $objTemplate, $_CORELANG, $subMenuTitle; switch ($this->cx->getMode()) { case \Cx\Core\Core\Controller\Cx::MODE_FRONTEND: $objGuestbook = new GuestBook(\Env::get('cx')->getPage()->getContent()); \Env::get('cx')->getPage()->setContent($objGuestbook->getPage()); break; case \Cx\Core\Core\Controller\Cx::MODE_BACKEND: $this->cx->getTemplate()->addBlockfile('CONTENT_OUTPUT', 'content_master', 'LegacyContentMaster.html'); $objTemplate = $this->cx->getTemplate(); \Permission::checkAccess(9, 'static'); $subMenuTitle = $_CORELANG['TXT_GUESTBOOK']; $objGuestbook = new GuestBookManager(); $objGuestbook->getPage(); break; default: break; } }
/** * Will return one of the following: * * 2-D array of all comments from all users contained the 'Comments' table * OR * A string advising there are no comments in the 'Comments' table * * @return array|string */ public static function getComments() { // Get DB Connection self::$DB = DBConnection::getConnection(); // Query for Read-Only. Order by comment date posted $result = self::$DB->query("SELECT Comments.comm_Title, Comments.comm_Body, Comments.comm_Date_Posted, Users.user_Username FROM Comments INNER JOIN Users ON Comments.user_ID = Users.user_ID ORDER BY comm_Date_Posted DESC"); // Array to return to view if ($result->rowCount() === 0) { $comments = "No comments at this time"; } else { $comments = []; // Store the comments to return to the web view while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Title, Message, Logged-In Username and Date-Time stamp $comments[] = $row; } } // Nullify the DB object $DB = null; return $comments; }
// 88 88 88ooooo 88 88ooooo 88 88ooooo 8P 88 88 88 88 88 88 88 88 88ooooo 88V8o 88 88 // 88 88 88~~~~~ 88 88~~~~~ 88 88~~~~~ 8b 88 88 88 88 88 88 88 88 88~~~~~ 88 V8o88 88 // 88 .8D 88. 88booo. 88. 88 88. Y8b d8 `8b d8' 88 88 88 88 88 88 88. 88 V888 88 // Y8888D' Y88888P Y88888P Y88888P YP Y88888P `Y88P' `Y88P' YP YP YP YP YP YP Y88888P VP V8P YP } else { if (isset($_POST['delete'])) { require_once MODEL_GUEST_BOOK; require_once MODEL_USER; session_start(); // Get the user object $user = $_SESSION['user']; // Store the comment ID $comm_ID = $_POST['userComment']; // Get the comment and store it in a variable ( Will be an associative array ) $comment = GuestBook::getComment($comm_ID); GuestBook::deleteComment($comment); // Count user comments for view and store it back into the session $user->countUserComments(); $_SESSION['user'] = $user; // Provide the user a message $_SESSION['userMessage'] = "Your comment has been deleted!"; header('HTTP/1.1 302 Redirect'); header('Location: ' . INDEX_REDIRECT); } elseif (isset($_POST['cancel'])) { session_start(); // Unset the session to change the view if (isset($_SESSION['editComment'])) { unset($_SESSION['editComment']); } // User cancelled an action so refresh the page header('HTTP/1.1 302 Redirect');
</form> <?php } } else { include SK_DIR . "/guestbook_admin.php"; } } elseif ($_MODULE) { if ($_NOTBAR) { if (!file_exists(SK_DIR . "/guestbook.php")) { if (isset($a) && $a == "admin") { $MDL->LoadAdminPage("{$p}"); return; } include "config.php"; global $side; $guest = new GuestBook($DIRS["guestbook_files"], $DIRS["guestbook_predir"], $GV["guestbook_premoderation"]); $guest->answ_item_sep = $GV["sep3"]; $guest->answ_separator = $GV["sep1"]; $guest->item_separator = $GV["sep2"]; if (!isset($p_idx)) { $p_idx = 1; } $guest->set_curr_page($p_idx); if (isset($add) && $add == 1 && (!isset($side) || $side == 0)) { $add = 0; $time = norm_date(time()); $name1 = $FLTR->DirectProcessString($name); $email = $FLTR->DirectProcessString($email); $url = $FLTR->DirectProcessString($url); $text = $FLTR->DirectProcessText($text); if (check_auth()) {
/** * Used to display all comments in the database. This function is only to tidy up * the source code. * */ function showAllComments() { // Show comments if there is any present. '$comments' will be 2-D [int][assoc] $comments = GuestBook::getComments(); if (is_array($comments)) { for ($i = 0; $i < count($comments); ++$i) { ?> <div class="commentBox"> <p class="commentTitle text-center"><?php echo $comments[$i]['comm_Title']; ?> </p> <p><?php echo $comments[$i]['comm_Body']; ?> </p> <p>User Posted: <?php echo $comments[$i]['user_Username']; ?> </p> <p class="text-center">Date Posted: <?php echo date("F j, Y, g:i a", $comments[$i]['comm_Date_Posted']); ?> </p> </div> <?php } } else { ?> <div> <p class="text-center commentBox"><?php echo $comments; ?> </p> </div> <?php } }
<!-- Edit Modal --> <div id="edit" class="modal fade" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="text-center modal-title">Edit Comment in GuestBook</h4> </div> <div class="modal-body"> <form method="POST" class="form-horizontal" role="form" action="controller/redirect.php"> <div class="form-group"> <?php $userComments = GuestBook::getUserComments($user); if (is_array($userComments)) { // The value of 'userComment' will be the comment ID echo '<select id="editSelect" class="form-control" name="userComment" onchange="verifySelection(this)">'; echo '<option value="">--- SELECT A COMMENT ---</option>'; for ($i = 0; $i < count($userComments); ++$i) { // If ADMIN is logged in, store the username for their listing of comments $username = isset($_SESSION['adminLoggedIn']) ? $userComments[$i]['user_Username'] . ' | ' : ''; echo '<option value="' . $userComments[$i]['comm_ID'] . '">' . $userComments[$i]['comm_Title'] . ' | ' . $username . date("F j, Y, g:i a", $userComments[$i]['comm_Date_Posted']) . '</option>'; } echo '</select>'; ?> <!-- Show the button to allow edit functionality --> <br/> <div class="text-center form-group"> <button type="submit" class="btn btn-primary" name="edit" id="editButton" disabled>Edit Comment</button>
<?php include "header.inc.php"; include "guestBook.php"; // Was the form submitted? if (isset($_POST['submit'])) { extract($_POST); // Get the form data /* Use the AddressBook Class */ $entry = new GuestBook(); // Instantiate the class $entry->setName($your_name); // Assign the properties $entry->setAddress($your_address); $entry->setPhone($your_phone); $entry->setBirthday($your_bd); $entry->setFile($your_file); $entry->showGuest(); // Call the class methods $entry->saveGuest(); } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="POST"> <div align="center"> <font face="arial" size=+1> <table cellspacing="1" cellpadding="1" border="0"> <tr><td>Enter your name:</td>
public function deleteAll() { self::$entries = []; return true; }