-
Notifications
You must be signed in to change notification settings - Fork 1
/
subscribe.php
53 lines (45 loc) · 1.69 KB
/
subscribe.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
<?php
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
require_once 'helpers.php';
require_once 'functions.php';
require_once 'data.php';
require_once 'session.php';
$follow_id = filter_input(INPUT_GET, 'id');
$sql = 'SELECT id
FROM users
WHERE id = ?;';
$stmt = db_get_prepare_stmt($connection, $sql, [$follow_id]);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
if (!$result) {
header('Location: error.php?code=404');
exit;
}
$follower_id = $user['user_id'];
$sql = 'SELECT *' .
' FROM subscribes' .
' WHERE follow_id = ? AND follower_id = ?;';
$stmt = db_get_prepare_stmt($connection, $sql, [$follow_id, $follower_id]);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$result = mysqli_fetch_assoc($result);
if (!$result) {
$sql = 'INSERT INTO subscribes (follow_id, follower_id)' .
' VALUES (?, ?)';
$stmt = mysqli_prepare($connection, $sql);
mysqli_stmt_bind_param($stmt, 'ii', $follow_id, $follower_id);
mysqli_stmt_execute($stmt);
$this_user = get_user($connection, $follow_id);
$email = new Email();
$email->from($email_configuration['from']);
$email->to($this_user['email']);
$email->subject('У вас новый подписчик');
$email->text(
'Здравствуйте, ' . $this_user['login'] . '. На вас подписался новый пользователь ' . $user['user'] . '. Вот ссылка на его профиль:' . $email_configuration['host_info'] . '/users_profile.php?id=' . $user['user_id']
);
$mailer = new Mailer($transport);
$mailer->send($email);
header('Location: users_profile.php?id=' . $follow_id);
exit;
}