This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.php
216 lines (203 loc) · 8.43 KB
/
server.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!--Server with many channels and members-->
<?php
session_start();
include('actions/functions.php');
if((!isset($_SESSION['is_logged'])) || (!$_SESSION['is_logged'])) {
header('Location: index.php');
exit();
}
else {
$accountID=$_SESSION['account_accountID'];
}
require_once "connect.php";
mysqli_report(MYSQLI_REPORT_STRICT);
try {
$connect = @new mysqli($host, $user, $pass, $database);
if($connect->connect_errno!=0) {
throw new Exception($connect->mysqli_connect_errno());
}
//wybieranie servera jeśli podane jest id!!!
if((!isset($_GET['channel'])) || ($_GET['channel']=="")) {
if((!isset($_GET['server'])) || ($_GET['server']=="")) {
//nic nie jest podane
header('discerd.php');
$connect->close();
exit();
}
else {
//jest podane id servera ale nie ma id kanału
$serverid=$_GET['server'];
if($result=$connect->query(sprintf("SELECT MIN(`channel`.`channelID`) AS `channelID`, `channel`.`name`, `channel`.`type` FROM `channel`
JOIN `category` ON `category`.`categoryID` = `channel`.`categoryID`
JOIN `server` ON `server`.`serverID` = `category`.`serverID`
WHERE `server`.`serverID`='$serverid' AND `channel`.`type`='1'")))
{
$how_many=$result->num_rows;
if($how_many>0) {
$row=$result->fetch_assoc();
$channelid=$row['channelID'];
$serverid=$_GET['server'];
header('Location: server.php?server='.$serverid.'&channel='.$channelid.'');
$connect->close();
exit();
}
else {
header('Location: discerd.php');
$connect->close();
exit();
}
}
}
}
else {
if((!isset($_GET['server'])) || ($_GET['server']=="")) {
//jest podane id kanału ale nie servera
$channelid=$_GET['channel'];
try {
if($result=$connect->query(sprintf("..."))) {
/*SELECT `serverID` FROM `server`
JOIN `category` ON `category`.`categoryID` = `channel`.`categoryID`
JOIN `server` ON `server`.`serverID` = `category`.`serverID`
WHERE `channel`.`channelid`='$channelid'*/
$how_many=$result->num_rows;
if($how_many>0) {
$row=$result->fetch_assoc();
$serverid=$row['serverID'];
//$channelid=$row['channelID'];
header('Location: server.php?server='.$serverid.'&channel='.$channelid);
$connect->close();
exit();
}
else {
header('Location: discerd.php');
$connect->close();
exit();
}
}
else {
throw new Exception($connect->error);
}
}
catch(Exception $e) {
echo "<i>Error:</i>";
echo "<div class='error'><b>Dev info:</b> ".$e."</div>";
$connect->close();
}
}
else {
//podane jest id servera jak i kanału(wszystko)
$channelid=$_GET['channel'];
$serverid=$_GET['server'];
}
}
if($result=$connect->query(sprintf("SELECT `server`.`server_name`, `server`.`server_icon`, `server`.`is_public` FROM `server` WHERE `serverID`='$serverid'"))) {
$how_many=$result->num_rows;
if($how_many>0) {
$row=$result->fetch_assoc();
//$id
//channelid
//serverid
$name=$row['server_name'];
$icon=$row['server_icon'];
$is_public=$row['is_public'];
}
else {
//header('Location: index.php');
//$connect->close();
//exit();
}
}
else {
throw new Exception($connect->error);
}
}
catch(Exception $e) {
echo "<i>Error:</i>";
echo "<div class='error'><b>Dev info:</b> ".$e."</div>";
$connect->close();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Discer | Server - <?php if(isset($name)) echo $name?></title>
<link rel="stylesheet" href="styles/style.css">
<link rel="stylesheet" href="styles/chat.css">
<link rel="icon" href="imgs/icon.ico">
<script src="scripts/livechat.js"></script>
<script src="scripts/validation.js"></script>
</head>
<body onload="livechat();">
<div class="banner"><!--just header-->
<a href="discerd.php"><img src="imgs/banner.png"></a>
<ol>
<li><a href='createinvite.php'>Add member</a></li>
<?php
echo "<li><a href='server.php?server=$serverid'>".$name."</a></li>";
?>
</ol>
</div>
<div class="servers">
<?php //list of servers
servers($accountID, $connect);
?>
</div>
<div class="channels">
<?php
//list of categories and channels
try {
if($result=$connect->query(sprintf("SELECT * FROM `category` WHERE `category`.`serverID`='$serverid' ORDER BY `weight`"))) {
while($row=$result->fetch_assoc()) {
echo "<div class='category' style='background-color: #40444b;'>";
echo $row['name'];
$categoryid=$row['categoryID'];
if($result2=$connect->query(sprintf("SELECT * FROM `channel` WHERE `channel`.`categoryID`='$categoryid' ORDER BY `weight`"))) {
while($row2=$result2->fetch_assoc()) {
$thischannelid=$row2['channelID'];
if($row2['type']=="1") echo "<div style='margin: 2% 0 2% 0; text-align: center;'><a href='server.php?server=$serverid&channel=$thischannelid'>".$row2['name']."</a></div>";
else echo "<div style='margin: 2% 0 2% 0; text-align: center;'><a href=''>".$row2['name']."</a></div>";
//tutaj trochę na odwal się ale to trzeba by było już ogarnać czat głosowy
}
}
else {
throw new Exception($connect->error);
}
echo "</div>";
}
}
else {
throw new Exception($connect->error);
}
}
catch(Exception $e) {
echo "<i>Error:</i>";
echo "<div class='error'><b>Dev info:</b> ".$e."</div>";
$connect->close();
}
?>
<!--some code to voice chats:))-->
</div>
<div class="friends">
<?php //list of users
friends($accountID, $connect);
?>
</div>
<input type="hidden" id="type" value="server">
<input type="hidden" id="server" value="<?php echo$serverid;?>">
<input type="hidden" id="channel" value="<?php echo$channelid;?>">
<div class="content">Loading..</div>
<div class="inputBar">
<form name="message" action="actions/send.php" method="post" onsubmit="return messages();">
<input type="text" name="content" placeholder="Type here..." onfocus="this.placeholder=''" onblur="this.placeholder='Type here...'">
<input type="hidden" value="<?php echo $channelid; ?>" name="channel">
<input type="hidden" value="<?php echo $serverid; ?>" name="server">
<input type="submit" value="send" name="submit">
</form>
</div>
</body>
</html>
<?php
$connect->close();
?>