Skip to content

Commit

Permalink
Show user online
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitjain28may committed Sep 24, 2016
1 parent 934c748 commit a67188d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 31 deletions.
16 changes: 8 additions & 8 deletions ajax/change.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
$id=$_SESSION['start'];
$query="SELECT * FROM total_message WHERE user1='$id' or user2='$id' ORDER BY id DESC";
// $query="SELECT * FROM total_message WHERE identifier like '%:$id' or '$id:%'";
if($result=$connect->query($query))
if($result=$connect->query($query))
{
if ($result->num_rows > 0)
if ($result->num_rows > 0)
{
$array = array();
$ln=strlen($id);
while($row = $result->fetch_assoc())
while($row = $result->fetch_assoc())
{
if($row['id']==$last_time && $flag!=0)
{
Expand All @@ -32,8 +32,8 @@
$st=substr($value, 0,$ln);
if($st!=$id)
{
$query="SELECT username,name from login where login_id='$st'";
if($result1=$connect->query($query))
$query="SELECT username,name,login_status from login where login_id='$st'";
if($result1=$connect->query($query))
{
if($result1->num_rows>0)
{
Expand All @@ -51,12 +51,12 @@
}
}
}

else
{
$st=substr($value,$ln+1);
$query="SELECT username,name from login where login_id='$st'";
if($result1=$connect->query($query))
$query="SELECT username,name,login_status from login where login_id='$st'";
if($result1=$connect->query($query))
{
if($result1->num_rows>0)
{
Expand Down
5 changes: 3 additions & 2 deletions ajax/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


// $query="SELECT * FROM total_message WHERE user1='$id' or user2='$id'";
$query="SELECT login_id,name FROM login WHERE username='$username'";
$query="SELECT login_id,name,login_status FROM login WHERE username='$username'";
$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if($result=$connect->query($query))
{
Expand Down Expand Up @@ -71,6 +71,7 @@
$row['time']=substr($row['time'],4,11);
$row['identifier_message_number']=$login_id;
$row=array_merge($row,['name'=>$fetch['name']]);
$row=array_merge($row,['login_status'=>$fetch['login_status']]);
$row=array_merge($row,['start'=>$id]);
$row=array_merge($row,['username'=>$username]);
$array=array_merge($array,[$row]);
Expand All @@ -82,7 +83,7 @@
}
else
{
echo json_encode(['identifier_message_number'=>$login_id,'name'=>$fetch['name'],'new'=>0]);
echo json_encode(['identifier_message_number'=>$login_id,'name'=>$fetch['name'],'login_status'=>$fetch['login_status'],'new'=>0]);
}
}
else
Expand Down
10 changes: 9 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ a {
border: 1px solid #e9ebee;

}
.online {
display: inline-block;
margin-left: 5px;
width: 6px;
height: 6px;
border-radius: 50%;
background-color:#42b72a;
margin-top:10px;
}
#message {
overflow-y: scroll;
}
Expand Down Expand Up @@ -211,7 +220,6 @@ a {

}


.sender {
float: right;
color: #fff;
Expand Down
30 changes: 30 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ function init(index)
bre.appendChild(inp);
bre.setAttribute('class','message_time');
para.appendChild(bre);

if(arr[i]['login_status']=='1')
{
var online = document.createElement("div");
online.setAttribute('class','online');
para.appendChild(online);
}


}

// Load messgage for the first conversation
Expand Down Expand Up @@ -147,6 +156,15 @@ function chat(element,num)
var txt=$("<a></a>").text(arr[0].name);
$("#chat_heading").append(txt);
$("#chat_heading a").attr({"href":"http://localhost/openchat/account.php/"+arr[0].username});
// Online
if(arr[0]['login_status']=='1')
{
var online = document.createElement("p");
online.setAttribute('class','online');
$("#chat_heading a").append(online);
$("#chat_heading a p").css({"float":'right'});
}

if(width())
$(".text_icon #text_reply").attr({'name':arr[0]['identifier_message_number']});
else
Expand All @@ -159,14 +177,26 @@ function chat(element,num)
{
ele.innerHTML="";
$("#chat_heading a").remove('a');

var txt=$("<a></a>").text(arr.name);
$("#chat_heading").append(txt);
$("#chat_heading a").attr({"href":"http://localhost/openchat/account.php/"+arr.username});

if(arr['login_status']=='1')
{
var online = document.createElement("p");
online.setAttribute('class','online');
$("#chat_heading a").append(online);
$("#chat_heading a p").css({"float":'right'});
}

if(width())
$(".text_icon #text_reply").attr({'name':arr['identifier_message_number']});
else
$("#text_reply").attr({'name':arr['identifier_message_number']});
}


}
}
};
Expand Down
28 changes: 18 additions & 10 deletions registration-module/source/class.login.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ function _login($login,$password)
$this->login=trim($login);
$this->password=trim($password);

if(empty($this->login))
if(empty($this->login))
{
$this->key=1;
$this->array_error=array_merge($this->array_error,["login"=>"Enter the login field"]);
}
elseif (preg_match("/^[@]{1}$/",$this->login))
{
if(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false)
{
if(filter_var($this->email,FILTER_VALIDATE_EMAIL)== false)
{
$this->key=1;
$this->array_error=array_merge($this->array_error,["login"=>"Enter correct Email address"]);
}
}
}
if(empty($this->password)) {
$this->key=1;
$this->array_error=array_merge($this->array_error,["password"=>"Enter the password"]);
Expand All @@ -49,9 +49,9 @@ function _login($login,$password)
if($this->key==0)
{
$query="SELECT * FROM login WHERE email='$this->login' or username='$this->login'";
if ($result=$connect->query($query))
if ($result=$connect->query($query))
{
if ($result->num_rows>0)
if ($result->num_rows>0)
{
$row=$result->fetch_assoc();
$login_id=$row['login_id'];
Expand All @@ -60,8 +60,16 @@ function _login($login,$password)
{
if ($result->num_rows>0)
{
$_SESSION['start']=$login_id;
return json_encode(["location"=>"http://localhost/openchat/account.php"]);
$query = "Update login set login_status = '1' where login_id = '$login_id'";
if($result = $connect->query($query))
{
$time=date("D d M Y H:i:s", time()+12600); // current time
$time_id=date("YmdHis",time()+12600);
// $query = "Update "
$_SESSION['start']=$login_id;
return json_encode(["location"=>"http://localhost/openchat/account.php"]);
}

}
else
{
Expand All @@ -75,8 +83,8 @@ function _login($login,$password)
$this->array_error=array_merge($this->array_error,["login"=>"Invalid username or email"]);
return json_encode($this->array_error);
}
}
}

}
else
{
Expand Down
12 changes: 10 additions & 2 deletions registration-module/source/class.logout.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<?php
require_once 'database.php';
session_start();
$connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(isset($_SESSION['start']))
{
unset($_SESSION['start']);
header('Location: ../../index.php');
$id = $_SESSION['start'];
$query = "Update login set login_status = '' where login_id = '$id'";
if($result = $connect->query($query))
{
unset($_SESSION['start']);
header('Location: ../../index.php');
}

}
else
{
Expand Down
17 changes: 9 additions & 8 deletions registration-module/source/class.register.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function __construct()
$this->key=0;
$this->connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$this->ob=new validate();


$query="CREATE TABLE IF NOT EXISTS register (
id int primary key auto_increment unique not null,
Expand All @@ -40,9 +40,10 @@ function __construct()
email varchar(255) unique not null,
username varchar(255) unique not null,
mobile varchar(255) not null,
login_status varchar(255),
FOREIGN KEY (login_id) REFERENCES register(id)
) ENGINE=INNODB;";

if (!$this->connect->query($query)) {
echo "Table is not created || Query failed";
}
Expand All @@ -53,11 +54,11 @@ function __construct()
education text,
gender varchar(10)
) ENGINE=INNODB;";

if (!$this->connect->query($query)) {
echo "Table is not created || Query failed";
}

}

function _register($name,$email,$username,$password,$mob)
Expand Down Expand Up @@ -135,8 +136,8 @@ function _register($name,$email,$username,$password,$mob)
if($result=$this->connect->query($query)) {
$row=$result->fetch_assoc();
$id=$row['id'];
$query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob')";

$query="INSERT INTO login VALUES('$id','$this->name','$this->email','$this->username','$this->mob','1')";
if(!$this->connect->query($query)) {
$this->key=1;
echo "You are not registered || Error in registration1";
Expand All @@ -148,7 +149,7 @@ function _register($name,$email,$username,$password,$mob)
echo "You are not updated || Error in profile";
}
}
}
}
}
if ($this->key==0) {
$_SESSION['start']=$id;
Expand All @@ -158,6 +159,6 @@ function _register($name,$email,$username,$password,$mob)
{
return json_encode($this->array_error);
}
}
}
}
?>

0 comments on commit a67188d

Please sign in to comment.