-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
239 lines (103 loc) · 4.03 KB
/
user.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?php
include('functions.php');
include('core/json.json');
if (!isLoggedIn()) {
$_SESSION['msg'] = "You must log in first";
header('location: login.php');
}
?>
<?php include("core/json.php"); ?>
<html>
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<title><?php echo $name; ?> - User control panel</title>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="js/bootstrap.min.js"></script>
<?php include("core/menu.php"); ?>
</head>
<body>
<center>
<div class="jumbotron">
<h1>User control panel</h1>
<br/>
<?php if (isset($_SESSION['user'])) : ?>
<strong><?php echo $_SESSION['user']['username']; ?></strong>
<small>
<i style="color: #888;">(<?php echo $usertype; ?>)</i>
<br>
<a href="core/logout.php" style="color: red;">logout</a>
</small>
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" id="profile-tab" data-toggle="tab" href="#posts" role="tab" aria-controls="profile" aria-selected="false">Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" id="contact-tab" data-toggle="tab" href="#settings" role="tab" aria-controls="contact" aria-selected="false">Settings</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab"><p>111</p></div>
<div class="tab-pane fade" id="posts" role="tabpanel" aria-labelledby="profile-tab"><p><div class="row">
<div class="col-lg-6">
<?php
$conn = mysqli_connect($dbhost, $usernamedb, $password, $db);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT id, author, posttimestamp FROM posts";
$result = mysqli_query($conn, $sql);
$value = 0;
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
if($row["author"] == $_SESSION['user']['username']){
echo '<div class="card">
<a href="view.php?id='. $row["id"] .'"><img class="" width="10%" src="posts/'. $row["id"] .'/'. $row["id"].'.png" alt="'. $row["title"] .'"></a>
<div class="card-body">
<h5 class="card-title">'. $row["title"] .'</h5>
<p class="card-text">'. $row["description"] .'</p>
<p class="card-text"><small class="text-muted">posted on: '. date("F j, Y, g:i a", $row["posttimestamp"]) .'</small>
<form method="post" action="" >
<input hidden value="'. $row["id"] .'" name="id" />
<input hidden value="'. $row["author"] .'" name="author" />
<input type="submit" class="btn btn-danger" name="deletepost_btn" value="Delete." />
</form>
</p>
</div>
</div>';
$value += 1;
}
}
} else {
if($value == 0){
echo '
<div class="alert alert-dark" role="alert">
sorry but you havent posted anything post something by clicking <a href="upload.php">here</a>
</div>';
}
}
?></p>
<p class="margin: auto;">total of posts <?php echo $value; ?></p></div></div>
</div>
<div class="tab-pane fade" id="settings" role="tabpanel" aria-labelledby="contact-tab"><p>
<form>
<p>profile picture</p>
<input type="file" name="file" class="btn btn-success" />
<input type="submit" class="btn btn-success" name="setpfp" value="Set as new profile picture" />
</form>
</p></div>
</div>
<?php endif ?>
</center>
</div>
</body>
<footer>
<center>© <?php print($copyright); ?></center>
</footer>
</html>