-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddtwits.php
99 lines (84 loc) · 3.29 KB
/
addtwits.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
<?php
session_start();
include_once 'include.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$userid = $_SESSION['user']['id'];
$newTextTwit = $_POST['texttwit'];
if (isset($_SESSION['user']) && isset($_POST['twit']) && strlen($_POST['texttwit']) <=140 && strlen($_POST['texttwit']) >=1 ) {
$twitObject = new Tweet();
$twitObject->setTwitText($newTextTwit);
$twitObject->setUserId($userid);
if ($twitObject->addTwit()) {
$message = "Your Twit successfully added!";
}
} else {
$message = "Check if you added text to the textarea below";
}
}
//set SESSION's value
if (!isset($_SESSION['user'])) {
header('Location:login.php');
} else {
echo "SESSION 'user' has started";
$name = $_SESSION['user']['name'];
}
?>
<html lang="en-EN">
<head>
<title>Add twits</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">Home</a></li>
<li role="presentation"><a href="profile.php">Profile</a></li>
<li role="presentation" class="active"><a href="alltwits.php">Tweets</a></li>
<li role="presentation"><a href="logout.php">Log out</a></li>
</ul>
</nav>
<h3 class="text-muted">Welcome <?php echo $name ?>!</h3>
</div>
<div id="content">
<h3>Add new twits</h3>
<?php
//show message if error in $message above
if (isset($message)) {
echo "<div class=\"alert alert-warning\" role=\"alert\">";
echo $message;
echo '</div>';
}
?>
<form action="#" method="POST" class="form-signin" id="twitform">
<div class="form-group">
<label for="twitform">Add text below (140 chars maximum)</label>
<textarea rows="4" cols="40" name="texttwit" id="twitform" form="twitform" maxlength="140">Enter your twit here...</textarea>
<button type="submit" name="twit" class="btn btn-default">Send twit</button>
</div>
</form>
</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>