-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
118 lines (82 loc) · 3.36 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
session_start(); // Start the session
$userLoggedIn = '';
require './classes/dbConnect.php'; // DbConnect
require './classes/post.queryDb.php'; // PostDbConnector
require './classes/post.validator.php'; // PostValidator
require './classes/category.validator.php'; // CategoryValidator
require './classes/userSession.validator.php'; // UserSession
require './classes/user.dbQuery.php'; // UserDbQuery
if (isset($_POST['insertPostData']))
{
$validatePostData = new PostValidator();
$validatePostData->setTitle($_POST['title']);
$validatePostData->setCategory($_POST['category']);
$validatePostData->setDescription($_POST['description']);
$validatePostData->setFileName($_FILES['photo']['name']);
$validatePostData->setFileSize($_FILES['photo']['size']);
$validatePostData->setFileError($_FILES['photo']['error']);
$errors = $validatePostData->validatePostData();
if (!$errors)
{
$insertPostData = new PostQueryDb();
$insertPostData->setTitle($_POST['title']);
$insertPostData->setCategory($_POST['category']);
$insertPostData->setDescription($_POST['description']);
$insertPostData->insertPost();
$_POST = [];
}
}
if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true)
{
$userLoggedIn = true;
if (isset($_POST['logOutUser']))
{
$userStatus = new UserSessionValidator();
$logOutUser = $userStatus->logOutUser();
}
}
else
{
$userLoggedIn = false; // User is not logged in
}
?>
<body>
<div class="mainContainer"><!-- contains all the page contents -->
<?php include $userLoggedIn ? './headers/indexHeader.php' : './headers/notLoggedInIndexHeader.php'; ?>
<section class="blogContents">
<section class="d-flex justify-content-between">
<section class="mainContentContainer">
<?php
$postResults = new PostQueryDb();
$posts = $postResults->fetchAllPosts();
foreach ($posts as $post): ?>
<?php include './cards/postCard.php' ?>
<?php endforeach ?>
</section>
<section class="rightSideContentContainer border-start"> <!-- Right side section -->
</section>
</section>
<?php include './footers/dropUsAMessage.php' ?>
</section>
<?php include './footers/globalFooter.php' ?> <!-- Footer -->
<!-- Create Post Modal button -->
<button type="button" onclick="openPostModal()" class="postBtn border-0">
<img src="assets/svg/feather.svg" alt="Click to post">
</button>
<div id="createPostTooltip" class="createPostTooltip">
<p>Click to post</p>
</div>
<?php include './modals/forms/createPostForm.php'?>
</div>
<!-- Black background behind Post Modal -->
<div id="postModalBackground" onclick="closePostModal()" class="postModalBackground"> </div>
</body>
</html>
<?php if (!empty($errors)): ?> <!-- Keeps Create Post Modal open when there is error after form submission -->
<script defer>
$(document).ready(function(){
openPostModal();
});
</script>
<?php endif ?>