<section class="input"> <?php include_once $path->getViewPath() . 'partials/note.form.inc.php'; ?> </section> <div class="clear"></div> <section class="notes"> <div class="flexParent"> <?php /** @var $notes Note[] */ ?> <?php $notes = $dbHandler->getNotesForUser($authHandler->getUserId()); ?> <?php foreach ($notes as $note) { ?> <div id="note-<?php echo $note->getId(); ?> " class="note flexChild"> <i class="delete fa fa-trash fa-lg"></i> <div class="title"><?php echo $note->getTitle(); ?> </div> <div class="content"><?php echo $note->getContent();
<?php session_start(); use views\helpers\PathHelper; require_once dirname(dirname(dirname(__FILE__))) . '/views/helpers/PathHelper.php'; $path = new PathHelper(); require_once $path->getModelPath() . 'DBHandler.php'; require_once $path->getModelPath() . 'AuthHandler.php'; require_once $path->getConfigPath() . 'connectionInfo.private.php'; $dbHandler = new DBHandler($host, $user, $password, $db); $authHandler = new AuthHandler($dbHandler); if (isset($_POST['title']) && isset($_POST['content'])) { if ($id = $dbHandler->insertNote($_POST['title'], $_POST['content'], $authHandler->getUserId())) { $result = array("id" => $id, "title" => $_POST['title'], "content" => $_POST['content']); } else { header("HTTP/1.1 501 Could not modify object"); $result = array("error" => "An error occurred saving your note."); } } else { // title and content were not set header("HTTP/1.1 502 Empty parameter set"); $result = array("error" => "Please provide a title and content for your note."); } header("Content-Type: application/json; charset=UTF-8"); echo json_encode($result);
// try to log in. if ($authHandler->loginUser($_POST['username'], $_POST['password'])) { echo "<div class='notification success'>Hi " . $authHandler->getUserName() . ", you are now logged in!</div>"; } else { echo "<div class='notification error'>We're sorry, but the log in failed. Is the password correct?</div>"; } } // LOGOUT if (isset($_POST['logout'])) { $authHandler->logoutUser(); } // ADD NOTE // check if the user has submitted a new note: if (isset($_POST['submitNote'])) { if (isset($_POST['title']) && isset($_POST['content'])) { if ($dbHandler->insertNote($_POST['title'], $_POST['content'], $authHandler->getUserId())) { echo "<div class='notification success'>Successfully added note!</div>"; } else { echo "<div class='notification error'>Oops! There was an error while saving your note.</div>"; } } } // DELETE NOTES if (isset($_POST['submitDelete']) && isset($_POST['delete'])) { $notesToDelete = array(); foreach ($_POST['delete'] as $noteId) { $notesToDelete[] = $noteId; } if ($dbHandler->deleteNotes($notesToDelete)) { echo "<div class='notification success'>Successfully deleted notes.</div>"; } else {