@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/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__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Store Message in the Database |
@@ -21,37 +21,37 @@ discard block |
||
| 21 | 21 | public function replyTo($msg) |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - if(isset($_SESSION['start']) && isset($msg)) //checks for session login and the value send |
|
| 24 | + if (isset($_SESSION['start']) && isset($msg)) //checks for session login and the value send |
|
| 25 | 25 | { |
| 26 | 26 | $id = $_SESSION['start']; |
| 27 | - $msg = json_decode($msg); //decode json value |
|
| 27 | + $msg = json_decode($msg); //decode json value |
|
| 28 | 28 | $identifier = $msg->name; |
| 29 | 29 | |
| 30 | - $receiverID = $identifier; //stores id of the person whom message is to be sent |
|
| 30 | + $receiverID = $identifier; //stores id of the person whom message is to be sent |
|
| 31 | 31 | |
| 32 | - if($identifier > $id) // geneate specific unique code to store messages |
|
| 32 | + if ($identifier > $id) // geneate specific unique code to store messages |
|
| 33 | 33 | $identifier = $id.":".$identifier; |
| 34 | 34 | else |
| 35 | 35 | $identifier = $identifier.":".$id; |
| 36 | 36 | |
| 37 | 37 | $reply = addslashes(trim($msg->reply[0])); // stores the message sent by the user. |
| 38 | 38 | |
| 39 | - $time = date("D d M Y H:i:s", time() + 16200); // current time |
|
| 39 | + $time = date("D d M Y H:i:s", time() + 16200); // current time |
|
| 40 | 40 | $time_id = date("YmdHis", time() + 16200); //to sort the array on the basis of time |
| 41 | 41 | |
| 42 | 42 | //the sender id must not be equal to current session id |
| 43 | - if($reply != "" && $receiverID != $id) |
|
| 43 | + if ($reply != "" && $receiverID != $id) |
|
| 44 | 44 | { |
| 45 | 45 | // check whether the receiver is authorized or registered |
| 46 | 46 | $query = "SELECT * from login where login_id = '$receiverID'"; |
| 47 | 47 | |
| 48 | 48 | $result = $this->connect->query($query); |
| 49 | - if($result->num_rows > 0) // if true |
|
| 49 | + if ($result->num_rows > 0) // if true |
|
| 50 | 50 | { |
| 51 | 51 | //check whether he is sending message for thr first time or he has sent messages before |
| 52 | 52 | $query = "SELECT * from total_message where identifier = '$identifier'"; |
| 53 | 53 | $result = $this->connect->query($query); |
| 54 | - if($result->num_rows>0) // if he has sent messages before |
|
| 54 | + if ($result->num_rows > 0) // if he has sent messages before |
|
| 55 | 55 | { |
| 56 | 56 | // Update Total_Message Table |
| 57 | 57 | $query = "UPDATE total_message SET total_messages = total_messages+1, time = '$time', unread = 1, id = '$time_id' WHERE identifier = '$identifier'"; |
@@ -61,15 +61,15 @@ discard block |
||
| 61 | 61 | else // if he sends message for the first time |
| 62 | 62 | { |
| 63 | 63 | $length = strlen($id); |
| 64 | - if(substr($identifier, 0, $length) == $id) // generate specific unique code |
|
| 64 | + if (substr($identifier, 0, $length) == $id) // generate specific unique code |
|
| 65 | 65 | { |
| 66 | - $user2 = substr($identifier, $length+1); |
|
| 66 | + $user2 = substr($identifier, $length + 1); |
|
| 67 | 67 | $user1 = $id; |
| 68 | 68 | } |
| 69 | 69 | else |
| 70 | 70 | { |
| 71 | 71 | $user2 = $id; |
| 72 | - $length = strlen($identifier) - $length-1; |
|
| 72 | + $length = strlen($identifier) - $length - 1; |
|
| 73 | 73 | $user1 = substr($identifier, 0, $length); |
| 74 | 74 | } |
| 75 | 75 | // insert Details in Total_Message Table |
@@ -92,13 +92,13 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | public function UpdateMessages($query, $identifier, $reply, $id, $time) |
| 94 | 94 | { |
| 95 | - if($result = $this->connect->query($query)) |
|
| 95 | + if ($result = $this->connect->query($query)) |
|
| 96 | 96 | { |
| 97 | 97 | //insert message in db |
| 98 | 98 | $query = "INSERT into messages values('$identifier', '$reply', '$id', '$time', null)"; |
| 99 | - if($result = $this->connect->query($query)) |
|
| 99 | + if ($result = $this->connect->query($query)) |
|
| 100 | 100 | { |
| 101 | - echo "Messages is sent \n"; // if query is executed return true |
|
| 101 | + echo "Messages is sent \n"; // if query is executed return true |
|
| 102 | 102 | } |
| 103 | 103 | else |
| 104 | 104 | { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/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 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | namespace ChatApp; |
| 4 | 4 | use ChatApp\Validate; |
| 5 | 5 | use ChatApp\Session; |
| 6 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 6 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 7 | 7 | |
| 8 | 8 | class Register |
| 9 | 9 | { |
@@ -36,45 +36,45 @@ discard block |
||
| 36 | 36 | $this->onError(["name" => " *Enter the name"]); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if(empty($email)) { |
|
| 39 | + if (empty($email)) { |
|
| 40 | 40 | $this->onError(["email" => " *Enter the email address"]); |
| 41 | 41 | } |
| 42 | - elseif(filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
| 42 | + elseif (filter_var($email, FILTER_VALIDATE_EMAIL) == false) { |
|
| 43 | 43 | $this->onError(["email" => " *Enter correct Email address"]); |
| 44 | 44 | } |
| 45 | 45 | else |
| 46 | 46 | { |
| 47 | - if($this->obValidate->validateEmailInDb($email) === 1) |
|
| 47 | + if ($this->obValidate->validateEmailInDb($email) === 1) |
|
| 48 | 48 | { |
| 49 | 49 | |
| 50 | 50 | $this->onError(["email" => " *Email is already registered"]); |
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if(empty($username)) { |
|
| 54 | + if (empty($username)) { |
|
| 55 | 55 | $this->onError(["username" => " *Enter the username"]); |
| 56 | 56 | } |
| 57 | 57 | else |
| 58 | 58 | { |
| 59 | - if($this->obValidate->validateUsernameInDb($username) === 1) |
|
| 59 | + if ($this->obValidate->validateUsernameInDb($username) === 1) |
|
| 60 | 60 | { |
| 61 | 61 | |
| 62 | 62 | $this->onError(["username" => " *Username is already registered"]); |
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if(empty($password)) { |
|
| 66 | + if (empty($password)) { |
|
| 67 | 67 | $this->onError(["password" => " *Enter the password"]); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if(empty($mob)) { |
|
| 70 | + if (empty($mob)) { |
|
| 71 | 71 | $this->onError(["mob" => " *Enter the Mobile Number"]); |
| 72 | 72 | } |
| 73 | 73 | elseif (!preg_match("/^[0-9]{10}$/", $mob)) { |
| 74 | 74 | $this->onError(["mob" => " *Enter correct Mobile Number"]); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if($this->key == 1) |
|
| 77 | + if ($this->key == 1) |
|
| 78 | 78 | { |
| 79 | 79 | return json_encode($this->error); |
| 80 | 80 | } |
@@ -83,19 +83,19 @@ discard block |
||
| 83 | 83 | $this->key = 0; |
| 84 | 84 | $pass = md5($password); |
| 85 | 85 | $query = "INSERT INTO register VALUES(null, '$email', '$username', '$pass')"; |
| 86 | - if(!$this->connect->query($query)) { |
|
| 86 | + if (!$this->connect->query($query)) { |
|
| 87 | 87 | $this->key = 1; |
| 88 | 88 | echo "You are not registered || Error in registration2"; |
| 89 | 89 | } |
| 90 | 90 | else |
| 91 | 91 | { |
| 92 | 92 | $query = "SELECT id FROM register WHERE email = '$email'"; |
| 93 | - if($result = $this->connect->query($query)) { |
|
| 93 | + if ($result = $this->connect->query($query)) { |
|
| 94 | 94 | $row = $result->fetch_assoc(); |
| 95 | 95 | $userId = $row['id']; |
| 96 | 96 | |
| 97 | 97 | $query = "INSERT INTO login VALUES('$userId', '$name', '$email', '$username', '$mob', 0)"; |
| 98 | - if(!$this->connect->query($query)) { |
|
| 98 | + if (!$this->connect->query($query)) { |
|
| 99 | 99 | $this->key = 1; |
| 100 | 100 | echo "You are not registered || Error in registration1"; |
| 101 | 101 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace ChatApp; |
| 3 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 3 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 4 | 4 | |
| 5 | 5 | class Validate |
| 6 | 6 | { |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 5 | 5 | use ChatApp\Time; |
| 6 | 6 | |
| 7 | 7 | /** |
@@ -23,26 +23,26 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | public 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 | public 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']); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * For checking online status |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
| 15 | 15 | $query = "Update login set login_status = 1 where login_id = '$userId'"; |
| 16 | - if(!$connect->query($query)); |
|
| 16 | + if (!$connect->query($query)); |
|
| 17 | 17 | echo $connect->error; |
| 18 | 18 | $connect->close(); |
| 19 | 19 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | { |
| 23 | 23 | $connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); |
| 24 | 24 | $query = "Update login set login_status = 0 where login_id = '$userId'"; |
| 25 | - if(!$connect->query($query)); |
|
| 25 | + if (!$connect->query($query)); |
|
| 26 | 26 | echo $connect->error; |
| 27 | 27 | $connect->close(); |
| 28 | 28 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/database.php'); |
|
| 5 | 5 | use ChatApp\User; |
| 6 | 6 | use ChatApp\Time; |
| 7 | 7 | use ChatApp\Conversation; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | $name = $this->messages['name']; |
| 32 | 32 | $this->messages = json_decode($this->conversation->ConversationLoad($msg, True)); |
| 33 | 33 | $id = json_decode($msg)->username; |
| 34 | - for ($i=1 ; $i < count($this->messages); $i++) { |
|
| 34 | + for ($i = 1; $i < count($this->messages); $i++) { |
|
| 35 | 35 | $this->messages[$i]->start = $id; |
| 36 | 36 | } |
| 37 | 37 | $this->messages[0]->username = $username; |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ChatApp; |
| 4 | -require_once (dirname(__DIR__) . '/config/database.php'); |
|
| 4 | +require_once (dirname(__DIR__).'/config/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 | } |