-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprivate.php
196 lines (160 loc) · 8.81 KB
/
private.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php require_once "libs/functions.php"; ?>
<?php require_once "libs/auth.php"; ?>
<?php require_once "libs/contacts.php"; ?>
<?php
$new_message = array();
$dir_flag = 0; //0 = left & 1 = right
$user1 = "";
$user2 = "";
$history = array();
if(isset($_GET['user1']) && isset($_GET['user2'])) {
$user1 = $_GET['user1'];
$user2 = $_GET['user2'];
}
if($user1 != $current_user)
$person = $user1;
else
$person = $user2;
if(!empty($user1) && !empty($user2)) {
if (!file_exists("private-chats/$user1&$user2.txt")) {
$fp = fopen("private-chats/$user1&$user2.txt", 'a');
fwrite($fp, "");
fclose($fp);
}
if ($new_message = prepareMessageData()) {
// echo "<pre>";
// var_dump($new_message);
// echo "</pre>";
saveToFile($new_message, "private-chats/$user1&$user2.txt");
}
$history = convertFileContentToArray("private-chats/$user1&$user2.txt");
}
if($history == null)
$history = [];
?>
<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" type="text/css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<br>
<h3>Welcome "<?php echo $_SESSION['username'] ?>". You are In: <a href="index.php">Home</a> » <a href="#"><?php echo $person; ?>'s PV</a></h3> <br>
<div class="messaging">
<div class="inbox_msg">
<div class="inbox_people">
<div class="headind_srch">
<div class="recent_heading">
<h4>Contacts:</h4>
</div>
<div class="srch_bar">
<div class="stylish-input-group">
<input type="text" class="search-bar" placeholder="Search">
<span class="input-group-addon">
<button type="button"> <i class="fa fa-search" aria-hidden="true"></i> </button>
</span>
</div>
</div>
</div>
<div class="inbox_chat">
<?php for($i=0;$i<count($records);$i++) { ?>
<div class="chat_list active_chat">
<div class="chat_people">
<div class="chat_img">
<img src="img/user-profile.png" alt="sunil">
</div>
<div class="chat_ib">
<h5>
<a href="<?php echo makePrivateLink($current_user, $records[$i]['username']); ?>">
<?php echo $records[$i]['name']; ?>
</a>
</h5>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<div class="mesgs">
<div class="msg_history">
<?php if ($history_chats = showHistoryChat($history, 100)) :
for ($i = 0; $i < count($history_chats); $i++) {
if($history_chats[$i]['sender'] == $current_user) {
$dir_flag = 0;
}
else
$dir_flag = 1;
// if (($i != 0) &&
// ($history_chats[$i]['sender'] != $history_chats[$i - 1]['sender'])
// ) {
// if($dir_flag == 1)
// $dir_flag = 0;
// else
// $dir_flag = 1;
// }
if ($dir_flag == 1) : ?>
<div class="incoming_msg">
<div class="incoming_msg_img"> <img src="img/user-profile.png" alt="sunil"> </div>
<div class="received_msg">
<div class="received_withd_msg">
<p>
<?php
if(isset($history_chats[$i]['message']))
echo $history_chats[$i]['message'];
elseif(isset($history_chats[$i]['file'])) { ?>
<img src="<?php echo $history_chats[$i]['file']['tmp_name']; ?>" alt="">
<?php }
?>
</p>
<span class="time_date">
<?php echo 'from <strong>' . $history_chats[$i]['sender'] . '</strong> |'; ?>
<?php echo $history_chats[$i]['date']; ?>
</span>
</div>
</div>
</div>
<?php else : ?>
<div class="outgoing_msg">
<div class="sent_msg">
<p>
<?php
if(isset($history_chats[$i]['message']))
echo $history_chats[$i]['message'];
elseif(isset($history_chats[$i]['file'])) { ?>
<img src="<?php echo $history_chats[$i]['file']['tmp_name']; ?>" alt="">
<?php }
?>
</p>
<span class="time_date">
<?php echo 'from <strong>' . $history_chats[$i]['sender'] . '</strong> |'; ?>
<?php echo $history_chats[$i]['date']; ?>
</span>
</div>
</div>
<?php endif; ?>
<?php } ?>
<?php else :
echo "There is'nt any Chat.";
endif; ?>
</div>
<div class="type_msg">
<form action="" method="post" enctype="multipart/form-data">
<div class="input_msg_write">
<input type="text" class="write_msg" name="message" id="message" placeholder="Type a message" />
<button class="msg_send_btn" type="submit" value="submit"><i class="fa fa-paper-plane-o" aria-hidden="true"></i></button>
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-paperclip" aria-hidden="true"></i>
</label>
<input id="file-upload" name="file" type="file" style="margin-right: 41px;"/>
</div>
</form>
</div>
</div>
</div>
<p class="text-center top_spac"> Developed by <a target="_blank" href="https://www.linkedin.com/in/sunil-rajput-nattho-singh/">Sajjad Shahrabi</a></p>
</div>
</div>
</body>
</html>