Viewing file: Chat.php (9.44 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Controllers;
class Chat extends BaseController
{
public function index()
{
if (!user() || user()['admin'] != '1') {
return redirect()->to('/login');
}
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
$data['page'] = createMeta('Kayıtlı Mesajları Görüntüle');
$data['messages'] = db('chat')
->where([
'chat_ust' => '0'
])
->get()
->getResultArray();
$data["ustSoru"] = db('chat')->get()->getResultArray();
return view(currentTheme() . '/Admin/chat', $data);
}
public function deleteChat($hash)
{
if (!user() || user()['admin'] != '1') {
return redirect()->to('/login');
}
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
db('chat')->delete([
'chat_hash' => $hash
]);
return redirect()->to('admin/chat-settings');
}
public function updateChat($hash)
{
if (!user() || user()['admin'] != '1') {
return redirect()->to('/login');
}
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
$soru = db('chat')->where(['chat_hash' => $hash])->get()->getResultArray();
$sorular = db('chat')->where(['chat_ust' => $hash])->get()->getResultArray();
if (empty($soru)) {
return redirect()->to('admin/chat-settings');
}
$soru = $soru[0];
$r = $this->request;
$soruBasligi = $r->getPost('soruBasligi');
$ustSoru = $soru["chat_hash"];
if ($r->getPost('ustSoru') != '0') {
$soruBasligi = db('chat')->where(array('chat_hash' => $r->getPost("ustSoru")))->get()->getResultArray()[0]["chat_cevap"];
$ustSoru = $r->getPost('ustSoru');
}
db('chat')->update([
'chat_soru' => $soruBasligi,
'chat_anaSoru' => $r->getPost('anaSoruMu'),
'chat_aciklama' => $r->getPost('aciklama'),
'chat_ustSoru' => $ustSoru
], ['chat_hash' => $hash]);
foreach ($r->getPost('cevap') as $key => $value) {
if ($value != null) {
$s = db('chat')->where(['chat_hash' => $key])->get()->getResultArray();
if (!isset($s[0]['chat_hash'])) {
db("chat")->insert([
"chat_hash" => md5(uniqid() . rand() . time() . microtime() . uniqid()),
"chat_ust" => $hash,
"chat_cevap" => $value,
"chat_ustSoru" => $ustSoru,
"chat_aciklama" => $r->getPost('aciklama')
]);
} else {
db('chat')->update([
"chat_ust" => $hash,
"chat_cevap" => $value,
"chat_ustSoru" => $ustSoru,
"chat_aciklama" => $r->getPost('aciklama')
], ['chat_hash' => $key]);
}
}
}
return redirect()->to('admin/chat-settings/edit/' . $hash);
}
public function editChat($hash)
{
if (!user() || user()['admin'] != '1') {
return redirect()->to('/login');
}
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
$data['page'] = createMeta('Mesaj Düzenle');
$data['messages'] = db('chat')
->where([
'chat_ust' => '0'
])
->get()
->getResultArray();
$data['soruDetay'] = db('chat')->where(['chat_hash' => $hash])->get()->getResultArray();
if (empty($data['soruDetay'])) {
return redirect()->to('admin/chat-settings');
}
$data['soruDetay'] = $data['soruDetay'][0];
$data['cevaplar'] = db('chat')->where([
'chat_ust' => $hash
])->get()->getResultArray();
$data["ustSoru"] = db('chat')->get()->getResultArray();
return view(currentTheme() . '/Admin/editChat', $data);
}
public function addChat()
{
if (!user() || user()['admin'] != '1') {
return redirect()->to('/login');
}
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
$req = $this->request;
$soruBasligi = $req->getPost('soruBasligi');
if ($req->getPost('ustSoru') !== '0') {
$soruBasligi = db('chat')->where(array('chat_hash' => $req->getPost("ustSoru")))->get()->getResultArray()[0]["chat_cevap"];
}
$hash = md5(uniqid() . rand() . time() . microtime() . uniqid());
$ustSoru = $hash;
if ($req->getPost("ustSoru") != "0") {
$ustSoru = $req->getPost("ustSoru");
}
db('chat')->insert(
[
"chat_hash" => $hash,
"chat_ust" => "0",
"chat_soru" => $soruBasligi,
"chat_cevap" => "0",
"chat_anaSoru" => $req->getPost("anaSoruMu"),
"chat_ustSoru" => $ustSoru,
"chat_aciklama" => $req->getPost("aciklama")
]
);
if (!empty($req->getPost("cevap"))) {
foreach ($req->getPost("cevap") as $key => $value) {
if ($value != null) {
db('chat')->insert([
"chat_hash" => md5(uniqid() . rand() . time() . microtime() . uniqid()),
"chat_ust" => $hash,
"chat_cevap" => $value,
"chat_ustSoru" => $ustSoru,
"chat_aciklama" => $req->getPost("aciklama")
]);
}
}
}
return redirect()->to('admin/chat-settings');
}
public function message()
{
if (settings('chat_active') == 'false') {
return redirect()->to('/admin');
}
$messageHash = $this->request->getPost('mesajHash');
if (!isset($messageHash)) {
die();
}
if ($messageHash == 'buton') {
$hash = md5(uniqid() . rand() . time() . microtime() . uniqid());
$sor = db('chat')->where([
'chat_anaSoru' => '1'
])->get()->getResultArray();
$sora = db('chat')->where([
'chat_hash' => $messageHash
])->get()->getResultArray();
?>
<li class="self">
<?php
foreach ($sor as $key => $anaSoru) {
echo preg_replace(
'!(http|ftp|scp)(s)?:\/\/(.*)+!',
"<a href=\"\\0\">\\0</a>",
$anaSoru["chat_soru"]
);
$alt = db('chat')->where(array('chat_ustSoru' => $anaSoru["chat_hash"], "chat_ust !=" => "0"))->get()->getResultArray();
foreach ($alt as $key => $value) {
?>
<button data-ust-hash="<?php echo $value["chat_hash"]; ?>" data-soru="<?php echo $value["chat_cevap"]; ?>" class="tpk-button mesaj-buton">
<?php echo preg_replace(
'!(http|ftp|scp)(s)?:\/\/(.*)+!',
"<a href=\"\\0\">\\0</a>",
$value["chat_cevap"]
); ?>
</button>
<?php
}
}
?>
</li>
<?php
} else {
$sor = db('chat')->where([
'chat_ustSoru' => $messageHash,
"chat_ust !=" => "0"
])->get()->getResultArray();
$sora = db('chat')->where([
'chat_ustSoru' => $messageHash,
])->get()->getResultArray();
?>
<li class="self">
<?php
echo preg_replace(
'!(http|ftp|scp)(s)?:\/\/(.*)+!',
"<a href=\"\\0\">\\0</a>",
$sora[0]["chat_aciklama"]
);
foreach ($sor as $key => $value) {
?>
<button data-ust-hash="<?php echo $value["chat_hash"]; ?>" data-soru="<?php echo $value["chat_cevap"]; ?>" class="tpk-button mesaj-buton"><?php echo preg_replace(
'!(http|ftp|scp)(s)?:\/\/(.*)+!',
"<a href=\"\\0\">\\0</a>",
$value["chat_cevap"]
); ?></button>
<?php
}
?>
</li>
<?php
}
}
}
|