@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace ChatApp; |
4 | -require_once (dirname(__DIR__) . '/database.php'); |
|
4 | +require_once (dirname(__DIR__).'/database.php'); |
|
5 | 5 | use ChatApp\Time; |
6 | 6 | |
7 | 7 | /** |
@@ -28,24 +28,24 @@ discard block |
||
28 | 28 | { |
29 | 29 | $suggestion = $suggestion->value; |
30 | 30 | $flag = 0; |
31 | - if(isset($_SESSION['start']) && isset($suggestion)) |
|
31 | + if (isset($_SESSION['start']) && isset($suggestion)) |
|
32 | 32 | { |
33 | 33 | $id = $_SESSION['start']; |
34 | 34 | $suggestion = trim($suggestion); |
35 | - if($suggestion != "") |
|
35 | + if ($suggestion != "") |
|
36 | 36 | { |
37 | 37 | $query = "SELECT * FROM login where login_id != '$id' and name like '$suggestion%' ORDER BY name ASC"; |
38 | - if($result = $this->connect->query($query)) |
|
38 | + if ($result = $this->connect->query($query)) |
|
39 | 39 | { |
40 | - if($result->num_rows > 0) |
|
40 | + if ($result->num_rows > 0) |
|
41 | 41 | { |
42 | - while($row = $result->fetch_assoc()) |
|
42 | + while ($row = $result->fetch_assoc()) |
|
43 | 43 | { |
44 | 44 | $check_id = $row["login_id"]; |
45 | 45 | $query = "SELECT * from total_message where (user1 = '$check_id' and user2 = '$id') or (user2 = '$check_id' and user1 = '$id')"; |
46 | - if($result1 = $this->connect->query($query)) |
|
46 | + if ($result1 = $this->connect->query($query)) |
|
47 | 47 | { |
48 | - if($result1->num_rows > 0) |
|
48 | + if ($result1->num_rows > 0) |
|
49 | 49 | { |
50 | 50 | $fetch = $result1->fetch_assoc(); |
51 | 51 | $fetch['time'] = $this->obTime->TimeConversion($fetch['time']); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
60 | - if($flag != 0) |
|
60 | + if ($flag != 0) |
|
61 | 61 | { |
62 | 62 | $this->array = array_merge([], ["Search" => $this->array]); |
63 | 63 | return json_encode($this->array); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace ChatApp; |
4 | -require_once (dirname(__DIR__) . '/database.php'); |
|
4 | +require_once (dirname(__DIR__).'/database.php'); |
|
5 | 5 | use ChatApp\Time; |
6 | 6 | |
7 | 7 | /** |
@@ -23,26 +23,26 @@ discard block |
||
23 | 23 | |
24 | 24 | function LoadSideBar($userId) |
25 | 25 | { |
26 | - if(isset($userId)) |
|
26 | + if (isset($userId)) |
|
27 | 27 | { |
28 | 28 | $query = "SELECT * FROM total_message WHERE user1='$userId' or user2='$userId' ORDER BY id DESC"; |
29 | - if($result = $this->connect->query($query)) |
|
29 | + if ($result = $this->connect->query($query)) |
|
30 | 30 | { |
31 | 31 | if ($result->num_rows > 0) |
32 | 32 | { |
33 | 33 | $length = strlen($userId); |
34 | - while($row = $result->fetch_assoc()) |
|
34 | + while ($row = $result->fetch_assoc()) |
|
35 | 35 | { |
36 | 36 | $identifier = $row['identifier']; |
37 | 37 | $substring = substr($identifier, 0, $length); |
38 | - if($substring != $userId) |
|
38 | + if ($substring != $userId) |
|
39 | 39 | { |
40 | 40 | $this->Data($substring, $row); |
41 | 41 | } |
42 | 42 | |
43 | 43 | else |
44 | 44 | { |
45 | - $substring = substr($identifier, $length+1); |
|
45 | + $substring = substr($identifier, $length + 1); |
|
46 | 46 | $this->Data($substring, $row); |
47 | 47 | } |
48 | 48 | } |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | function Data($id, $row) |
69 | 69 | { |
70 | 70 | $query = "SELECT username,name,login_status,login_id from login where login_id = '$id'"; |
71 | - if($result = $this->connect->query($query)) |
|
71 | + if ($result = $this->connect->query($query)) |
|
72 | 72 | { |
73 | - if($result->num_rows > 0) |
|
73 | + if ($result->num_rows > 0) |
|
74 | 74 | { |
75 | 75 | $fetch = $result->fetch_assoc(); |
76 | 76 | $row['time'] = $this->obTime->TimeConversion($row['time']); |
@@ -7,7 +7,7 @@ |
||
7 | 7 | use Ratchet\WebSocket\WsServer; |
8 | 8 | use ChatApp\Chat; |
9 | 9 | |
10 | -$server =IoServer::factory( |
|
10 | +$server = IoServer::factory( |
|
11 | 11 | new HttpServer( |
12 | 12 | new WsServer( |
13 | 13 | new Chat() |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | session_start(); |
3 | -if(isset($_SESSION['start']) and empty($_GET['user'])) |
|
3 | +if (isset($_SESSION['start']) and empty($_GET['user'])) |
|
4 | 4 | { |
5 | 5 | ?> |
6 | 6 | <!DOCTYPE html> |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | |
131 | 131 | <?php |
132 | 132 | } |
133 | -else{ |
|
133 | +else { |
|
134 | 134 | header('Location:http://www.localhost/openchat/login.php'); |
135 | 135 | } |
136 | 136 | ?> |
@@ -1,17 +1,17 @@ |
||
1 | 1 | <?php |
2 | 2 | session_start(); |
3 | 3 | require_once '../source/class.register.php'; |
4 | -if(isset($_POST['q'])) |
|
4 | +if (isset($_POST['q'])) |
|
5 | 5 | { |
6 | - $register_field=json_decode($_POST['q']); |
|
7 | - $name=$register_field->name; |
|
8 | - $email=$register_field->email; |
|
9 | - $username=$register_field->username; |
|
10 | - $mob=$register_field->mob; |
|
11 | - $password=$register_field->password; |
|
6 | + $register_field = json_decode($_POST['q']); |
|
7 | + $name = $register_field->name; |
|
8 | + $email = $register_field->email; |
|
9 | + $username = $register_field->username; |
|
10 | + $mob = $register_field->mob; |
|
11 | + $password = $register_field->password; |
|
12 | 12 | $ob = new register(); |
13 | - $result=$ob->_register($name,$email,$username,$password,$mob); |
|
14 | - if(isset($result)) |
|
13 | + $result = $ob->_register($name, $email, $username, $password, $mob); |
|
14 | + if (isset($result)) |
|
15 | 15 | echo $result; |
16 | 16 | else |
17 | 17 | echo json_encode([]); |
@@ -1,14 +1,14 @@ |
||
1 | 1 | <?php |
2 | 2 | session_start(); |
3 | 3 | require_once '../source/class.login.php'; |
4 | -if(isset($_POST['q'])) |
|
4 | +if (isset($_POST['q'])) |
|
5 | 5 | { |
6 | - $login_field=json_decode($_POST['q']); |
|
7 | - $login=$login_field->login; |
|
8 | - $password=$login_field->password; |
|
6 | + $login_field = json_decode($_POST['q']); |
|
7 | + $login = $login_field->login; |
|
8 | + $password = $login_field->password; |
|
9 | 9 | $ob = new login(); |
10 | - $result=$ob->_login($login,$password); |
|
11 | - if(isset($result)) |
|
10 | + $result = $ob->_login($login, $password); |
|
11 | + if (isset($result)) |
|
12 | 12 | echo $result; |
13 | 13 | else |
14 | 14 | echo json_encode([]); |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | |
18 | 18 | function __construct() |
19 | 19 | { |
20 | - $this->array_error=array(); |
|
21 | - $this->key=0; |
|
20 | + $this->array_error = array(); |
|
21 | + $this->key = 0; |
|
22 | 22 | $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
23 | - $this->ob=new validate(); |
|
23 | + $this->ob = new validate(); |
|
24 | 24 | |
25 | 25 | |
26 | - $query="CREATE TABLE IF NOT EXISTS register ( |
|
26 | + $query = "CREATE TABLE IF NOT EXISTS register ( |
|
27 | 27 | id int primary key auto_increment unique not null, |
28 | 28 | email varchar(255) unique not null, |
29 | 29 | username varchar(255) unique not null, |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | echo "Table is not created || Query failed"; |
35 | 35 | } |
36 | 36 | |
37 | - $query="CREATE TABLE IF NOT EXISTS login ( |
|
37 | + $query = "CREATE TABLE IF NOT EXISTS login ( |
|
38 | 38 | login_id int primary key not null, |
39 | 39 | name varchar(255) not null, |
40 | 40 | email varchar(255) unique not null, |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | echo "Table is not created || Query failed"; |
49 | 49 | } |
50 | 50 | |
51 | - $query="CREATE TABLE IF NOT EXISTS profile ( |
|
51 | + $query = "CREATE TABLE IF NOT EXISTS profile ( |
|
52 | 52 | login_id int primary key not null unique, |
53 | 53 | status text, |
54 | 54 | education text, |
@@ -61,98 +61,98 @@ discard block |
||
61 | 61 | |
62 | 62 | } |
63 | 63 | |
64 | - function _register($name,$email,$username,$password,$mob) |
|
64 | + function _register($name, $email, $username, $password, $mob) |
|
65 | 65 | { |
66 | - $this->name=trim($name); |
|
67 | - $this->email=trim($email); |
|
68 | - $this->username=trim($username); |
|
69 | - $this->password=trim($password); |
|
70 | - $this->mob=trim($mob); |
|
66 | + $this->name = trim($name); |
|
67 | + $this->email = trim($email); |
|
68 | + $this->username = trim($username); |
|
69 | + $this->password = trim($password); |
|
70 | + $this->mob = trim($mob); |
|
71 | 71 | if (empty($this->name)) { |
72 | - $this->key=1; |
|
73 | - $this->array_error=array_merge($this->array_error,["name"=>"Enter the name"]); |
|
72 | + $this->key = 1; |
|
73 | + $this->array_error = array_merge($this->array_error, ["name"=>"Enter the name"]); |
|
74 | 74 | } |
75 | 75 | |
76 | - if(empty($this->email)) { |
|
77 | - $this->key=1; |
|
78 | - $this->array_error=array_merge($this->array_error,["email"=>"Enter the email address"]); |
|
76 | + if (empty($this->email)) { |
|
77 | + $this->key = 1; |
|
78 | + $this->array_error = array_merge($this->array_error, ["email"=>"Enter the email address"]); |
|
79 | 79 | } |
80 | - elseif(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false) { |
|
81 | - $this->key=1; |
|
82 | - $this->array_error=array_merge($this->array_error,["email"=>"Enter correct Email address"]); |
|
80 | + elseif (filter_var($this->email, FILTER_VALIDATE_EMAIL) == false) { |
|
81 | + $this->key = 1; |
|
82 | + $this->array_error = array_merge($this->array_error, ["email"=>"Enter correct Email address"]); |
|
83 | 83 | } |
84 | 84 | else |
85 | 85 | { |
86 | - if($this->ob->validate_email_in_db($this->email)) |
|
86 | + if ($this->ob->validate_email_in_db($this->email)) |
|
87 | 87 | { |
88 | - $this->key=1; |
|
89 | - $this->array_error=array_merge($this->array_error,["email"=>"Email is already registered"]); |
|
88 | + $this->key = 1; |
|
89 | + $this->array_error = array_merge($this->array_error, ["email"=>"Email is already registered"]); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - if(empty($this->username)) { |
|
94 | - $this->key=1; |
|
95 | - $this->array_error=array_merge($this->array_error,["username"=>"Enter the username"]); |
|
93 | + if (empty($this->username)) { |
|
94 | + $this->key = 1; |
|
95 | + $this->array_error = array_merge($this->array_error, ["username"=>"Enter the username"]); |
|
96 | 96 | } |
97 | 97 | else |
98 | 98 | { |
99 | - if($this->ob->validate_username_in_db($this->username)) |
|
99 | + if ($this->ob->validate_username_in_db($this->username)) |
|
100 | 100 | { |
101 | - $this->key=1; |
|
102 | - $this->array_error=array_merge($this->array_error,["username"=>"Username is already registered"]); |
|
101 | + $this->key = 1; |
|
102 | + $this->array_error = array_merge($this->array_error, ["username"=>"Username is already registered"]); |
|
103 | 103 | } |
104 | 104 | } |
105 | 105 | |
106 | - if(empty($this->password)) { |
|
107 | - $this->key=1; |
|
108 | - $this->array_error=array_merge($this->array_error,["password"=>"Enter the password"]); |
|
106 | + if (empty($this->password)) { |
|
107 | + $this->key = 1; |
|
108 | + $this->array_error = array_merge($this->array_error, ["password"=>"Enter the password"]); |
|
109 | 109 | } |
110 | 110 | |
111 | - if(empty($this->mob)) { |
|
112 | - $this->key=1; |
|
113 | - $this->array_error=array_merge($this->array_error,["mob"=>"Enter the Mobile Number"]); |
|
111 | + if (empty($this->mob)) { |
|
112 | + $this->key = 1; |
|
113 | + $this->array_error = array_merge($this->array_error, ["mob"=>"Enter the Mobile Number"]); |
|
114 | 114 | } |
115 | - elseif (!preg_match("/^[0-9]{10}$/",$this->mob)) { |
|
116 | - $this->key=1; |
|
117 | - $this->array_error=array_merge($this->array_error,["mob"=>"Enter correct Mobile Number"]); |
|
115 | + elseif (!preg_match("/^[0-9]{10}$/", $this->mob)) { |
|
116 | + $this->key = 1; |
|
117 | + $this->array_error = array_merge($this->array_error, ["mob"=>"Enter correct Mobile Number"]); |
|
118 | 118 | } |
119 | 119 | |
120 | - if($this->key==1) |
|
120 | + if ($this->key == 1) |
|
121 | 121 | { |
122 | 122 | return json_encode($this->array_error); |
123 | 123 | } |
124 | 124 | else |
125 | 125 | { |
126 | - $this->key=0; |
|
127 | - $pass=md5($this->password); |
|
128 | - $query="INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')"; |
|
129 | - if(!$this->connect->query($query)) { |
|
130 | - $this->key=1; |
|
126 | + $this->key = 0; |
|
127 | + $pass = md5($this->password); |
|
128 | + $query = "INSERT INTO register VALUES(null,'$this->email','$this->username','$pass')"; |
|
129 | + if (!$this->connect->query($query)) { |
|
130 | + $this->key = 1; |
|
131 | 131 | echo "You are not registered || Error in registration2"; |
132 | 132 | } |
133 | 133 | else |
134 | 134 | { |
135 | - $query="SELECT id FROM register WHERE email='$this->email'"; |
|
136 | - if($result=$this->connect->query($query)) { |
|
137 | - $row=$result->fetch_assoc(); |
|
138 | - $id=$row['id']; |
|
139 | - |
|
140 | - $query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')"; |
|
141 | - if(!$this->connect->query($query)) { |
|
142 | - $this->key=1; |
|
135 | + $query = "SELECT id FROM register WHERE email='$this->email'"; |
|
136 | + if ($result = $this->connect->query($query)) { |
|
137 | + $row = $result->fetch_assoc(); |
|
138 | + $id = $row['id']; |
|
139 | + |
|
140 | + $query = "INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')"; |
|
141 | + if (!$this->connect->query($query)) { |
|
142 | + $this->key = 1; |
|
143 | 143 | echo "You are not registered || Error in registration1"; |
144 | 144 | } |
145 | - $join="Joined OpenChat"; |
|
146 | - $query="INSERT INTO profile VALUES('$id','$join','$join','')"; |
|
147 | - if(!$this->connect->query($query)) { |
|
148 | - $this->key=1; |
|
145 | + $join = "Joined OpenChat"; |
|
146 | + $query = "INSERT INTO profile VALUES('$id','$join','$join','')"; |
|
147 | + if (!$this->connect->query($query)) { |
|
148 | + $this->key = 1; |
|
149 | 149 | echo "You are not updated || Error in profile"; |
150 | 150 | } |
151 | 151 | } |
152 | 152 | } |
153 | 153 | } |
154 | - if ($this->key==0) { |
|
155 | - $_SESSION['start']=$id; |
|
154 | + if ($this->key == 0) { |
|
155 | + $_SESSION['start'] = $id; |
|
156 | 156 | return json_encode(["location"=>"http://localhost/openchat/account.php"]); |
157 | 157 | } |
158 | 158 | else |
@@ -2,11 +2,11 @@ |
||
2 | 2 | require_once 'database.php'; |
3 | 3 | session_start(); |
4 | 4 | $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
5 | -if(isset($_SESSION['start'])) |
|
5 | +if (isset($_SESSION['start'])) |
|
6 | 6 | { |
7 | 7 | $id = $_SESSION['start']; |
8 | 8 | $query = "Update login set login_status = '' where login_id = '$id'"; |
9 | - if($result = $connect->query($query)) |
|
9 | + if ($result = $connect->query($query)) |
|
10 | 10 | { |
11 | 11 | unset($_SESSION['start']); |
12 | 12 | header('Location: ../../index.php'); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | { |
9 | 9 | $this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
10 | 10 | |
11 | - $query="CREATE TABLE IF NOT EXISTS register ( |
|
11 | + $query = "CREATE TABLE IF NOT EXISTS register ( |
|
12 | 12 | id int primary key auto_increment unique not null, |
13 | 13 | email varchar(255) unique not null, |
14 | 14 | username varchar(255) unique not null, |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | echo "Table is not created || Query failed"; |
20 | 20 | } |
21 | 21 | |
22 | - $query="CREATE TABLE IF NOT EXISTS login ( |
|
22 | + $query = "CREATE TABLE IF NOT EXISTS login ( |
|
23 | 23 | login_id int primary key not null, |
24 | 24 | name varchar(255) not null, |
25 | 25 | email varchar(255) unique not null, |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | |
36 | 36 | function validate_email_in_db($email) |
37 | 37 | { |
38 | - $query="SELECT login_id FROM login WHERE email='$email'"; |
|
39 | - if ($result=$this->connect->query($query)) |
|
38 | + $query = "SELECT login_id FROM login WHERE email='$email'"; |
|
39 | + if ($result = $this->connect->query($query)) |
|
40 | 40 | { |
41 | - if ($result->num_rows>0) { |
|
41 | + if ($result->num_rows > 0) { |
|
42 | 42 | return 1; |
43 | 43 | } |
44 | 44 | else |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | function validate_username_in_db($username) |
50 | 50 | { |
51 | - $query="SELECT login_id FROM login WHERE username='$username'"; |
|
52 | - if ($result=$this->connect->query($query)) { |
|
53 | - if ($result->num_rows>0) { |
|
51 | + $query = "SELECT login_id FROM login WHERE username='$username'"; |
|
52 | + if ($result = $this->connect->query($query)) { |
|
53 | + if ($result->num_rows > 0) { |
|
54 | 54 | return 1; |
55 | 55 | } |
56 | 56 | else |