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 pathcreaterequest.php
154 lines (139 loc) · 4.88 KB
/
createrequest.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
<?php
session_start();
include('actions/functions.php');
if((!isset($_SESSION['is_logged'])) || ($_SESSION['is_logged']==false)) {
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());
}
}
catch(Exception $e) {
echo "<i>Error:</i>";
echo "<div class='error'><b>Dev info:</b> ".$e."</div>";
$connect->close();
}
if(isset($_POST['submit'])) {
$is_good=true;
unset($_POST['submit']);
if((!isset($_POST['text'])) || ($_POST['text']=="")) {
$is_good=false;
$rq_nick_error="Fill nick and tag";
}
else {
$text = $_POST['text'];
$data = explode("#", $text);
if((!isset($data[0])) || ($data[0]=="")) {
$is_good=false;
$rq_nick_error="Invalid nick";
}
else {
$nick = $data[0];
}
if((!isset($data[1])) || ($data[1]=="")) {
$is_good=false;
$rq_nick_error="Invalid tag";
}
else {
$tag = $data[1];
}
$senderID=$_SESSION['account_accountID'];
$reciverID=$tag;
if($senderID==$reciverID) {
$is_good=false;
$rq_nick_error="This is your account";
}
}
if($is_good) {
try {
if(!$result = $connect->query("SELECT * FROM account WHERE nickname='$nick' AND accountID='$tag'")) {
throw new Exception($connect->error);
}
$how_many=$result->num_rows;
if($how_many<=0) {
$rq_nick_error="That user doesn't exist";
}
else {
if(!$result = $connect->query("SELECT * FROM friendship WHERE (senderID='$senderID' AND reciverID='$reciverID') OR (senderID='$reciverID' AND reciverID='$senderID')")) {
throw new Exception($connect->error);
}
$how_many=$result->num_rows;
if($how_many>0) {
$rq_nick_error="You've already sent an request";
}
else {
if($result=$connect->query("INSERT INTO friendship(`senderID`,`reciverID`,`status`) VALUES ('$senderID','$reciverID','0')")) {
$info = "Request was sent";
}
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();
}
$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 | Send friend request</title>
<link rel="stylesheet" href="styles/style.css">
<link rel="stylesheet" href="styles/discerd.css">
<link rel="stylesheet" href="styles/login.css">
<link rel="icon" href="imgs/icon.ico">
</head>
<body>
<div class="banner">
<a href="discerd.php"><img src="imgs/banner.png"></a>
</div>
<div class="servers">
<?php //list of servers
servers($accountID, $connect);
?>
</div>
<div class="friends">
<?php //list of users
friends($accountID, $connect);
?>
</div>
<div class="content">
<div class="form">
<?php
if(isset($info)) {
echo "<div class='info'>".$info."</div>";
unset($text);
unset($info);
echo "<a href='discerd.php' style='float: left;'>Back</a>";
exit();
}
?>
<form action="" method="post">
<input type="text" name="text" value="<?php if(isset($text)) echo$text; ?>" placeholder="Nick#1" onfocus="this.placeholder=''" onblur="this.placeholder='Nick#1'">
<?php
if(isset($rq_nick_error)) {
echo "<div class='error'>".$rq_nick_error."</div>";
unset($rq_nick_error);
}?>
<input type="submit" name="submit" value="Send request">
</form>
</div>
</div>
</body>
</html>