-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_room.php
106 lines (101 loc) · 3.93 KB
/
add_room.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
<?php
session_start();
$my_email = openssl_decrypt($_SESSION['token'], "AES-128-CTR", "11112000", 0, "1234567890123456");
$pdo = new PDO('mysql:host=localhost;dbname=users', 'root', 'pwd');
if (!empty($_POST['user'])) {
$room_name = $_POST['room_name'];
$q = $pdo->prepare('insert into rooms(room_name) values (?)');
$q->bindValue(1, $room_name);
$q->execute();
$q = $pdo->prepare('select * from rooms');
$q->execute();
$n = 0;
while ($result = $q->fetch(PDO::FETCH_ASSOC)) {
if ($n < $result['id']) $n = $result['id'];
}
$q4 = $pdo->prepare("select * from chatters where email=?");
$q4->bindValue(1, $my_email);
$q4->execute();
$r = $q4->fetch(PDO::FETCH_ASSOC);
$qs = $pdo->prepare('insert into rooms_members (id_room, first_name, last_name, email) values (?,?,?,?)');
$qs->bindValue(1, $n);
$qs->bindValue(2, $r['first_name']);
$qs->bindValue(3, $r['last_name']);
$qs->bindValue(4, $r['email']);
$qs->execute();
foreach ($_POST['user'] as $value) {
$query = $pdo->prepare("select * from chatters where email=?");
$query->bindValue(1, $value);
$query->execute();
$result = $query->fetch(PDO::FETCH_ASSOC);
$q2 = $pdo->prepare('insert into rooms_members (id_room, first_name, last_name, email) values (?,?,?,?)');
$q2->bindValue(1, $n);
$q2->bindValue(2, $result['first_name']);
$q2->bindValue(3, $result['last_name']);
$q2->bindValue(4, $result['email']);
$q2->execute();
}
header("Location: dashbord.php?show=rooms");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat App</title>
<link rel="stylesheet" href="add_room.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@300&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<div class="wrapper">
<section class="users">
<form action="add_room.php" method="POST">
<header>
<div class="content">
<img src="https://www.shareicon.net/data/512x512/2016/06/30/788858_group_512x512.png" style="object-fit: contain;" alt="">
<div class="details">
<div class="input-data">
<input name="room_name" required type="text" placeholder="Room name">
</div>
</div>
</header>
<div class="users-list">
<?php
$my_email = openssl_decrypt($_SESSION['token'], "AES-128-CTR", "11112000", 0, "1234567890123456");
$pdo = new PDO('mysql:host=localhost;dbname=users', 'root', 'sonicmario1');
$q = $pdo->prepare("select * from chatters where not email=?");
$q->bindValue(1, $my_email);
$q->execute();
while ($result = $q->fetch()) {
$nom = $result['first_name'] . " " . $result['last_name'];
echo "<a>
<div class='content'>
<img src='https://w7.pngwing.com/pngs/613/636/png-transparent-computer-icons-user-profile-male-avatar-avatar-heroes-logo-black-thumbnail.png' alt=''>
<div class='details'>
<div class='pretty p-default p-round'>
<input type='checkbox' id='" . $nom . "' name='user[]' value='" . $result['email'] . "' />
<div class='state p-success-o'>
<label for='" . $nom . "'>"
. $nom .
"</label>
</div>
</div>
</div>
</div>
</a>";
}
?>
</div>
<footer>
<input type="submit" value="Create room" href="" class="create" />
</footer>
</form>
</section>
</div>
</body>
</html>