-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitter_sendmessage.php
79 lines (63 loc) · 1.97 KB
/
twitter_sendmessage.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
<?php
/**
* File of miniTwitter
*
* @author Daniel Plewinski
* @author email: [email protected]
* @link https://github.com/daniel-plewinski/miniTwitter
*/
session_start();
ob_start();
include 'config.php';
include 'src/User.php';
include 'src/Comment.php';
include 'src/Tweet.php';
include 'src/Message.php';
include 'template/header.php';
if(!isset($_SESSION["userID"])){
header("location: twitter_wall.php");
die();
}
if (isset($_GET['id']) && is_numeric(($_GET['id']))) {
$toId = $_GET['id'];
}
if ($toId == $_SESSION['userID']) {
header("location: twitter_wall.php");
$_SESSION['selfError'] = true;
}
?>
<div class="container">
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<form action="" method="post" role="form">
<legend>Wysyłanie wiadomości</legend>
<div class="form-group">
<label for="content">Treść:</label>
<textarea class="form-control" rows="5" name="content" id="content"></textarea>
</div>
<button type="submit" class="btn btn-primary">Dodaj</button>
</form>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
<?php
if ($_SERVER['REQUEST_METHOD'] === "POST") {
if (!empty($_POST['content'])) {
$content = $_POST['content'];
$message = new Message;
$message->setFromId($_SESSION['userID']);
$message->setToId($toId);
$message->setContent($content);
$message->sendMessage($conn);
echo "Wiadomość została przesłana";
} else {
echo "Wiadomość nie może być pusta";
}
}
?>
</div>
</div>
</div>
</body>
</html>