@@ -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 | |
6 | 6 | /** |
7 | 7 | * |
@@ -23,18 +23,18 @@ discard block |
||
23 | 23 | public function SelectUser($msg) |
24 | 24 | { |
25 | 25 | $msg = $msg->value; |
26 | - if(isset($_SESSION['start']) && isset($msg)) |
|
26 | + if (isset($_SESSION['start']) && isset($msg)) |
|
27 | 27 | { |
28 | 28 | $id = $_SESSION['start']; |
29 | 29 | $suggestion = trim($msg); |
30 | - if($suggestion != "" ) |
|
30 | + if ($suggestion != "") |
|
31 | 31 | { |
32 | 32 | $query = "SELECT * FROM login where login_id != '$id' and name like '$suggestion%' ORDER BY name DESC"; |
33 | - if($result = $this->connect->query($query)) |
|
33 | + if ($result = $this->connect->query($query)) |
|
34 | 34 | { |
35 | - if($result->num_rows > 0) |
|
35 | + if ($result->num_rows > 0) |
|
36 | 36 | { |
37 | - while($row = $result->fetch_assoc()) |
|
37 | + while ($row = $result->fetch_assoc()) |
|
38 | 38 | { |
39 | 39 | $this->array = array_merge($this->array, [$row]); |
40 | 40 | } |
@@ -40,18 +40,15 @@ |
||
40 | 40 | } |
41 | 41 | $this->array = array_merge([], ["Compose" => $this->array]); |
42 | 42 | return json_encode($this->array); |
43 | - } |
|
44 | - else |
|
43 | + } else |
|
45 | 44 | { |
46 | 45 | return json_encode(["Compose" => "Not Found"]); |
47 | 46 | } |
48 | - } |
|
49 | - else |
|
47 | + } else |
|
50 | 48 | { |
51 | 49 | return json_encode(["Compose" => "Query Failed"]); |
52 | 50 | } |
53 | - } |
|
54 | - else |
|
51 | + } else |
|
55 | 52 | { |
56 | 53 | return json_encode(["Compose" => "Not Found"]); |
57 | 54 | } |
@@ -16,14 +16,14 @@ |
||
16 | 16 | function TimeConversion($time) |
17 | 17 | { |
18 | 18 | |
19 | - if(substr($time,4,11) == date("d M Y", time() + 16200)) |
|
20 | - $time = substr($time,16,5); |
|
21 | - else if(substr($time,7,8) == date("M Y", time() + 16200) && substr($time, 4,2) - date("d") < 7) |
|
22 | - $time = substr($time,0,3); |
|
23 | - else if(substr($time,11,4) == date("Y", time() + 16200)) |
|
24 | - $time = substr($time,4,6); |
|
19 | + if (substr($time, 4, 11) == date("d M Y", time() + 16200)) |
|
20 | + $time = substr($time, 16, 5); |
|
21 | + else if (substr($time, 7, 8) == date("M Y", time() + 16200) && substr($time, 4, 2) - date("d") < 7) |
|
22 | + $time = substr($time, 0, 3); |
|
23 | + else if (substr($time, 11, 4) == date("Y", time() + 16200)) |
|
24 | + $time = substr($time, 4, 6); |
|
25 | 25 | else |
26 | - $time = substr($time,4,11); |
|
26 | + $time = substr($time, 4, 11); |
|
27 | 27 | |
28 | 28 | return $time; |
29 | 29 | } |
@@ -16,14 +16,15 @@ |
||
16 | 16 | function TimeConversion($time) |
17 | 17 | { |
18 | 18 | |
19 | - if(substr($time,4,11) == date("d M Y", time() + 16200)) |
|
20 | - $time = substr($time,16,5); |
|
21 | - else if(substr($time,7,8) == date("M Y", time() + 16200) && substr($time, 4,2) - date("d") < 7) |
|
22 | - $time = substr($time,0,3); |
|
23 | - else if(substr($time,11,4) == date("Y", time() + 16200)) |
|
24 | - $time = substr($time,4,6); |
|
25 | - else |
|
26 | - $time = substr($time,4,11); |
|
19 | + if(substr($time,4,11) == date("d M Y", time() + 16200)) { |
|
20 | + $time = substr($time,16,5); |
|
21 | + } else if(substr($time,7,8) == date("M Y", time() + 16200) && substr($time, 4,2) - date("d") < 7) { |
|
22 | + $time = substr($time,0,3); |
|
23 | + } else if(substr($time,11,4) == date("Y", time() + 16200)) { |
|
24 | + $time = substr($time,4,6); |
|
25 | + } else { |
|
26 | + $time = substr($time,4,11); |
|
27 | + } |
|
27 | 28 | |
28 | 29 | return $time; |
29 | 30 | } |
@@ -8,7 +8,7 @@ |
||
8 | 8 | |
9 | 9 | class Message extends Model |
10 | 10 | { |
11 | - protected $table='message'; |
|
11 | + protected $table = 'message'; |
|
12 | 12 | |
13 | 13 | protected $fillable = ['identifier_message_number', 'message', 'sent_by', 'time']; |
14 | 14 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | |
4 | 4 | namespace ChatApp; |
5 | -require_once (dirname(__DIR__) . '/database.php'); |
|
5 | +require_once (dirname(__DIR__).'/database.php'); |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * For retreiving User Information |
@@ -21,12 +21,12 @@ discard block |
||
21 | 21 | |
22 | 22 | function UserDetails($id, $para) |
23 | 23 | { |
24 | - if($para == True) |
|
24 | + if ($para == True) |
|
25 | 25 | $this->query = "SELECT * from login where login_id = '$id'"; |
26 | 26 | else |
27 | 27 | $this->query = "SELECT * from login where username = '$id'"; |
28 | 28 | $this->result = $this->connect->query($this->query); |
29 | - if($this->result->num_rows > 0) // if true |
|
29 | + if ($this->result->num_rows > 0) // if true |
|
30 | 30 | { |
31 | 31 | $this->details = $this->result->fetch_assoc(); |
32 | 32 | return $this->details; |
@@ -21,17 +21,19 @@ |
||
21 | 21 | |
22 | 22 | function UserDetails($id, $para) |
23 | 23 | { |
24 | - if($para == True) |
|
25 | - $this->query = "SELECT * from login where login_id = '$id'"; |
|
26 | - else |
|
27 | - $this->query = "SELECT * from login where username = '$id'"; |
|
24 | + if($para == True) { |
|
25 | + $this->query = "SELECT * from login where login_id = '$id'"; |
|
26 | + } else { |
|
27 | + $this->query = "SELECT * from login where username = '$id'"; |
|
28 | + } |
|
28 | 29 | $this->result = $this->connect->query($this->query); |
29 | - if($this->result->num_rows > 0) // if true |
|
30 | + if($this->result->num_rows > 0) { |
|
31 | + // if true |
|
30 | 32 | { |
31 | 33 | $this->details = $this->result->fetch_assoc(); |
32 | - return $this->details; |
|
33 | 34 | } |
34 | - else |
|
35 | + return $this->details; |
|
36 | + } else |
|
35 | 37 | { |
36 | 38 | return NULL; |
37 | 39 | } |
@@ -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 | use ChatApp\User; |
7 | 7 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | { |
31 | 31 | |
32 | 32 | $flag = 1; |
33 | - if(isset($_SESSION['start']) && isset($msg)) |
|
33 | + if (isset($_SESSION['start']) && isset($msg)) |
|
34 | 34 | { |
35 | 35 | $add_load = 0; |
36 | 36 | $id = $_SESSION['start']; |
@@ -40,25 +40,25 @@ discard block |
||
40 | 40 | |
41 | 41 | $fetch = $this->obUser->UserDetails($username, $para); |
42 | 42 | |
43 | - if($fetch != NULL) |
|
43 | + if ($fetch != NULL) |
|
44 | 44 | { |
45 | 45 | $login_id = (int)$fetch['login_id']; |
46 | 46 | |
47 | 47 | // Unique Identifier |
48 | - if($login_id > $id) |
|
48 | + if ($login_id > $id) |
|
49 | 49 | $identifier = $id.':'.$login_id; |
50 | 50 | else |
51 | 51 | $identifier = $login_id.':'.$id; |
52 | 52 | |
53 | 53 | $query = "SELECT total_messages from total_message where identifier = '$identifier'"; |
54 | - if($result = $this->connect->query($query)) |
|
54 | + if ($result = $this->connect->query($query)) |
|
55 | 55 | { |
56 | - if($result->num_rows > 0) |
|
56 | + if ($result->num_rows > 0) |
|
57 | 57 | { |
58 | 58 | $total = $result->fetch_assoc(); |
59 | 59 | $total = $total['total_messages']; |
60 | - if($total - $load > 0) |
|
61 | - if($total - $load > 10) |
|
60 | + if ($total - $load > 0) |
|
61 | + if ($total - $load > 10) |
|
62 | 62 | $add_load = $load + 10; |
63 | 63 | else |
64 | 64 | $add_load = $total; |
@@ -66,14 +66,14 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | $query = "SELECT message, time, sent_by FROM messages WHERE identifier_message_number = '$identifier' ORDER BY id DESC limit ".$load; |
69 | - if($result = $this->connect->query($query)) |
|
69 | + if ($result = $this->connect->query($query)) |
|
70 | 70 | { |
71 | - if($result->num_rows > 0) |
|
71 | + if ($result->num_rows > 0) |
|
72 | 72 | { |
73 | - while($row = $result->fetch_assoc()) |
|
73 | + while ($row = $result->fetch_assoc()) |
|
74 | 74 | { |
75 | 75 | $row['time'] = $this->obTime->TimeConversion($row['time']); |
76 | - $row = array_merge($row,['start' => $id]); |
|
76 | + $row = array_merge($row, ['start' => $id]); |
|
77 | 77 | $this->array = array_merge($this->array, [$row]); |
78 | 78 | } |
79 | 79 |
@@ -45,10 +45,11 @@ discard block |
||
45 | 45 | $login_id = (int)$fetch['login_id']; |
46 | 46 | |
47 | 47 | // Unique Identifier |
48 | - if($login_id > $id) |
|
49 | - $identifier = $id.':'.$login_id; |
|
50 | - else |
|
51 | - $identifier = $login_id.':'.$id; |
|
48 | + if($login_id > $id) { |
|
49 | + $identifier = $id.':'.$login_id; |
|
50 | + } else { |
|
51 | + $identifier = $login_id.':'.$id; |
|
52 | + } |
|
52 | 53 | |
53 | 54 | $query = "SELECT total_messages from total_message where identifier = '$identifier'"; |
54 | 55 | if($result = $this->connect->query($query)) |
@@ -57,11 +58,12 @@ discard block |
||
57 | 58 | { |
58 | 59 | $total = $result->fetch_assoc(); |
59 | 60 | $total = $total['total_messages']; |
60 | - if($total - $load > 0) |
|
61 | - if($total - $load > 10) |
|
61 | + if($total - $load > 0) { |
|
62 | + if($total - $load > 10) |
|
62 | 63 | $add_load = $load + 10; |
63 | - else |
|
64 | - $add_load = $total; |
|
64 | + } else { |
|
65 | + $add_load = $total; |
|
66 | + } |
|
65 | 67 | } |
66 | 68 | } |
67 | 69 | |
@@ -79,23 +81,19 @@ discard block |
||
79 | 81 | |
80 | 82 | $this->array = array_merge([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'load' => $add_load, 'type' => 1]], $this->array); |
81 | 83 | return json_encode($this->array); |
82 | - } |
|
83 | - else |
|
84 | + } else |
|
84 | 85 | { |
85 | 86 | return json_encode([['name' => $fetch['name'], 'username' => $fetch['username'], 'id' => $fetch['login_id'], 'type' => 0]]); |
86 | 87 | } |
87 | - } |
|
88 | - else |
|
88 | + } else |
|
89 | 89 | { |
90 | 90 | echo "Query Failed"; |
91 | 91 | } |
92 | - } |
|
93 | - else |
|
92 | + } else |
|
94 | 93 | { |
95 | 94 | echo "Query Failed"; |
96 | 95 | } |
97 | - } |
|
98 | - else |
|
96 | + } else |
|
99 | 97 | { |
100 | 98 | header('Location:../login.php'); |
101 | 99 | } |
@@ -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); |
@@ -61,16 +61,14 @@ |
||
61 | 61 | { |
62 | 62 | $this->array = array_merge([], ["Search" => $this->array]); |
63 | 63 | return json_encode($this->array); |
64 | + } else { |
|
65 | + return json_encode(["Search" => "Not Found"]); |
|
64 | 66 | } |
65 | - else |
|
66 | - return json_encode(["Search" => "Not Found"]); |
|
67 | - } |
|
68 | - else |
|
67 | + } else |
|
69 | 68 | { |
70 | 69 | return json_encode(["Search" => "Not Found"]); |
71 | 70 | } |
72 | - } |
|
73 | - else |
|
71 | + } else |
|
74 | 72 | { |
75 | 73 | return json_encode(["Search" => "Not Found"]); |
76 | 74 | } |
@@ -8,16 +8,16 @@ |
||
8 | 8 | use ChatApp\Chat; |
9 | 9 | |
10 | 10 | $server =IoServer::factory( |
11 | - new HttpServer( |
|
12 | - new WsServer( |
|
13 | - new Chat() |
|
14 | - ) |
|
15 | - ) |
|
16 | - , |
|
17 | - 8080 |
|
18 | - ); |
|
11 | + new HttpServer( |
|
12 | + new WsServer( |
|
13 | + new Chat() |
|
14 | + ) |
|
15 | + ) |
|
16 | + , |
|
17 | + 8080 |
|
18 | + ); |
|
19 | 19 | $server->run(); |
20 | 20 | |
21 | 21 | |
22 | 22 | |
23 | - ?> |
|
24 | 23 | \ No newline at end of file |
24 | + ?> |
|
25 | 25 | \ No newline at end of file |
@@ -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() |
@@ -131,6 +131,6 @@ |
||
131 | 131 | <?php |
132 | 132 | } |
133 | 133 | else{ |
134 | - header('Location:http://www.localhost/openchat/login.php'); |
|
134 | + header('Location:http://www.localhost/openchat/login.php'); |
|
135 | 135 | } |
136 | 136 | ?> |
@@ -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 | ?> |
@@ -129,8 +129,7 @@ |
||
129 | 129 | </html> |
130 | 130 | |
131 | 131 | <?php |
132 | -} |
|
133 | -else{ |
|
132 | +} else{ |
|
134 | 133 | header('Location:http://www.localhost/openchat/login.php'); |
135 | 134 | } |
136 | 135 | ?> |
@@ -3,17 +3,17 @@ |
||
3 | 3 | require_once '../source/class.register.php'; |
4 | 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; |
|
12 | - $ob = new register(); |
|
13 | - $result=$ob->_register($name,$email,$username,$password,$mob); |
|
14 | - if(isset($result)) |
|
15 | - echo $result; |
|
16 | - else |
|
17 | - echo json_encode([]); |
|
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 | + $ob = new register(); |
|
13 | + $result=$ob->_register($name,$email,$username,$password,$mob); |
|
14 | + if(isset($result)) |
|
15 | + echo $result; |
|
16 | + else |
|
17 | + echo json_encode([]); |
|
18 | 18 | } |
19 | 19 | ?> |
20 | 20 | \ No newline at end of file |
@@ -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([]); |
@@ -11,9 +11,10 @@ |
||
11 | 11 | $password=$register_field->password; |
12 | 12 | $ob = new register(); |
13 | 13 | $result=$ob->_register($name,$email,$username,$password,$mob); |
14 | - if(isset($result)) |
|
15 | - echo $result; |
|
16 | - else |
|
17 | - echo json_encode([]); |
|
18 | -} |
|
14 | + if(isset($result)) { |
|
15 | + echo $result; |
|
16 | + } else { |
|
17 | + echo json_encode([]); |
|
18 | + } |
|
19 | + } |
|
19 | 20 | ?> |
20 | 21 | \ No newline at end of file |