-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitdetails.php
151 lines (119 loc) · 5.17 KB
/
twitdetails.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
<?php
session_start();
include_once 'include.php';
//set SESSION's value
if (!isset($_SESSION['user'])) {
header('Location:login.php');
} else {
$name = $_SESSION['user']['name'];
}
//possibility to add comment to the twit
if($_SERVER['REQUEST_METHOD'] == "POST") {
$userIdComment = $_SESSION['user']['id'];
$twitId = $_GET['twitId'];
$textComment = $_POST['textcomment'];
$currentTime = date("Y-m-d h:i:s");
$newComment = new Comment();
$newComment->setUserId($userIdComment);
$newComment->setTwitId($twitId);
$newComment->setCommentText($textComment);
$newComment->setCreatedTimeComment($currentTime);
$newComment->saveToDB($conn);
}
//Showing all twits of a user
if (isset($_GET['twitId'])) {
$twitId = $_GET['twitId'];
$resultTwitDetailsQuery = Tweet::getTwitDetails($twitId);
$showComments = Comment::GetAllCommentsForTwit($conn, $twitId);
$numberOfComments = count($showComments);
}
//presenting all comments to the twit
?>
<html lang="en-EN">
<head>
<title>Details of the Twit</title>
<meta charset="utf-8">
<!-- Latest compiled and minified CSS -->
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Custom styles for this template -->
<link href="css/signin.css" rel="stylesheet">
<link href="css/jumbotron-narrow.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation"><a href="index.php">My Twits</a></li>
<li role="presentation"><a href="profile.php">My Profile</a></li>
<li role="presentation"><a href="mymessages.php">My Messages</a></li>
<li role="presentation"><a href="twits.php">All Twits</a></li>
<li role="presentation"><a href="logout.php">Log out</a></li>
</ul>
</nav>
<h3 class="text-muted">Welcom <?php echo $name ?>!</h3>
</div>
<div id="content">
<h3>Details of the twit</h3>
<?php
foreach($resultTwitDetailsQuery as $twit){
echo "<div class='panel panel-default'>";
echo "<div class='panel-body'>{$twit->getTwitText()}</div>";
echo "<div class='panel-footer'>Created time: {$twit->getCreatedTime()}</div>";
$twitUserId = $twit->getUserId();
$twitUserDetails = User::getUserProfile($twitUserId);
foreach($twitUserDetails as $key => $user) {
echo "<div class='panel-footer'>"."Created by: {$user->getName()}, "."<a href='userdetails.php?userId={$user->getId()}'>Check user's profile</a></div>";
}
echo "<div class='panel-footer'>Nr of comments: {$numberOfComments}</div>";
echo "</div>";
}
?>
<br />
<h3>Add comment to the twit</h3>
<form action="#" method="POST" class="form-signin" id="textcomment">
<div class="form-group">
<textarea rows="4" cols="30" name="textcomment" id="textcomment" form="textcomment" maxlength="60" placeholder="Add comment below (60 chars maximum)"></textarea><br/>
</div>
<button type="submit" name="comment" class="btn btn-primary btn-lg">Send comment</button>
</form>
<br />
<h3>List of all comments</h3>
<?php
if(count($showComments) > 0) {
foreach ($showComments as $key => $comment) {
echo "<div class='panel panel-default'>";
echo "<div class='panel-body'>{$comment->getCommentText()}</div>";
$commentUserId = $comment->getUserId();
$commentUserDetails = User::getUserProfile($commentUserId);
echo "<div class='panel-footer'>Created time: {$comment->getCreatedTimeComment()}</div>";
echo "<div class='panel-footer'>Created by: {$commentUserDetails[0]->getName()},
<a href='userdetails.php?userId={$commentUserDetails[0]->getId()}'>Check user's profile</a></div>";
echo "</div>";
}
}else {
echo "<div class=\"alert alert-warning\" role=\"alert\">";
echo "The twit hasn't received any comments yet";
echo '</div>';
}
?>
<br />
</div>
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation"><a href="login.php">Login</a></li>
<li role="presentation"><a href="registration.php">Registration</a></li>
</ul>
</nav>
<footer class="footer">
<p>© Jakub Pawelczak</p>
</footer>
</div> <!-- /container -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS"
crossorigin="anonymous"></script>
</body>
</html>