-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.php
121 lines (121 loc) · 5.32 KB
/
chat.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
<?php
require_once("dbConnect.php");
$tip = $_POST["tip"];
$sonuc ["hata"]= "mesaj gönderilemedi";
if($tip=="kaydet"){
$kadi = $_SESSION["kadi"];
($_SESSION["rutbe"] == "" || !isset($_SESSION["rutbe"])) ? $rutbe = 1 :$rutbe = $_SESSION["rutbe"];
$saat=date("H:i");
$tarih=date("d.m.Y");
$resim = $_SESSION["resim"];
$mesaj = $_POST["mesaj"];
$dosya = fopen("chat.txt","a+");
$yazi = $saat."\t".$tarih."\t".$kadi."\t".$rutbe."\t".$mesaj."\t".$resim."\n";
$write = fwrite($dosya,$yazi);
if($write){
$sonuc["onay"]= "mesaj gönderildi";
}else{
$sonuc ["hata"]= "mesaj gönderilemediiiiii";
}
}elseif($tip=="getir"){
$dosyass = file("chat.txt");
$veriler ="";
foreach($dosyass as $icerik){
$ayir = explode("\t",$icerik);
$isim= $ayir[2];
$mesaj = $ayir[4];
$rt = $ayir[3];
$saat = $ayir[0];
$tarih = $ayir[1];
$resim = $ayir[5];
$tasa = $tarih." ".$saat;
if($rt == 1){
if($_SESSION["kadi"] == $isim) {
$icerikler = "<div class='direct-chat-msg right'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-right' style='color: darkblue'>$isim</span>
<span class='direct-chat-timestamp pull-left'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>" ;
}else{
$icerikler =
"<div class='direct-chat-msg'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-left' style='color: darkblue'>$isim</span>
<span class='direct-chat-timestamp pull-right'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>";
}
}
if($rt == 2){
if($_SESSION["kadi"] == $isim) {
$icerikler = "<div class='direct-chat-msg right'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-right' style='color: lightgreen; background-color: darkblue'>$isim</span>
<span class='direct-chat-timestamp pull-left'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>" ;
}else{
$icerikler =
"<div class='direct-chat-msg'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-left' style='color: lightgreen; background-color: darkblue'>$isim</span>
<span class='direct-chat-timestamp pull-right'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>";
}
}
if($rt == 3){
if($_SESSION["kadi"] == $isim) {
$icerikler = "<div class='direct-chat-msg right'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-right' style='color: yellowgreen; background-color: darkred'>$isim</span>
<span class='direct-chat-timestamp pull-left'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>" ;
}else{
$icerikler =
"<div class='direct-chat-msg'>
<div class='direct-chat-info clearfix'>
<span class='direct-chat-name pull-left' style='color: yellowgreen; background-color: darkred'>$isim</span>
<span class='direct-chat-timestamp pull-right'>$tasa</span>
</div>
<img class='direct-chat-img' src='$resim' alt='message user image' />
<div class='direct-chat-text'>
$mesaj
</div>
</div>";
}
}
$veriler = $veriler."<br/>".$icerikler."<br/>";
if(empty($veriler) || !$dosyass){
$sonuc["bos"] = "<p class=\"message\">
<center><span style=\"color: red; font-size: large\">MESAJ YOK</span></center>
</p>";
}else{
$sonuc["dolu"]=$veriler;
}
}
}
echo json_encode($sonuc);
?>