Файл: panel/news.php
Строк: 212
<?php
/**
* @package Prime Social
* @link http://primesocial.ru
* @copyright Copyright (C) 2016 Prime Social
* @author BoB | http://primesocial.ru/about
*/
require_once('../core/start.php');
check_auth();
head('Sayt yangiliklari');
if (privilegy('news') == FALSE) {
header("Location: ".HOME."/panel");
exit();
}
if (privilegy('news')) {
switch ($select) {
default:
if ($_GET['del']) {
$del = num($_GET['del']);
DB::$dbs->query("DELETE FROM ".NEWS." WHERE `id` = ?",array($del));
DB::$dbs->query("DELETE FROM ".NEWS_COMM." WHERE `new_id` = ?",array($del));
echo DIV_MSG . 'Yangilik o`chirildi' . CLOSE_DIV;
}
if (!empty($_POST['sett'])) {
$news = num($_POST['news']);
$comm = num($_POST['comm']);
if (empty($news) || empty($comm)) {
echo DIV_ERROR . 'Bo`sh tarkib' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".CONFIG." SET `write_news` = ?, `write_news_comm` = ? ", array($news, $comm));
header("Location: ".HOME."/panel/news/");
}
}
if ($_POST['add']) {
$title = html($_POST['title']);
$afisha = html($_POST['afisha']);
$new = html($_POST['new']);
if (strlen($title) < 10) {
$err .= 'Yangilik nomi juda qisqa. kamida 10 belgi bo`lishi kerak<br />';
}
if (strlen($new) < 20) {
$err .= 'Juda qisqa yangilik matni. kamida 20 belgi bo`lishi kerak<br />';
}
if (empty($afisha)) {
$err .= 'Bosh sahifaga ko`rinadigan yangilik matni to`ldirilmadi<br />';
}
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".NEWS." (`title`, `afisha`, `new`, `time`, `user_id`) VALUES (?, ?, ?, ?, ?)", array($title, $afisha, $new, time(), $user['user_id']));
echo DIV_MSG . 'Yangilik qo`shildi' . CLOSE_DIV;
}
}
echo '<div class="line">';
echo '<form action="#" method="POST">';
echo 'Nomi: [max. 100]<br /><input type="text" name="title" /><br /><br />';
echo 'Bosh sahifa uchun:<br /><textarea name="afisha" cols="30" rows="6"></textarea><br />';
echo 'Yangilik:<br /><textarea name="new" cols="30" rows="6"></textarea><br />';
echo '<input type="submit" name="add" value="Kiritish" /></form>';
echo CLOSE_DIV;
echo '<div class="line">';
echo '<b>Sahifadagi yangiliklar soni:</b><br />';
echo '<form action="#" method="POST">';
echo '<select name="news">';
echo '<option '.(1 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="1">1</option>';
echo '<option '.(3 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="3">3</option>';
echo '<option '.(5 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="5">5</option>';
echo '<option '.(10 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="10">10</option>';
echo '<option '.(20 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="20">20</option>';
echo '<option '.(30 == $config['write']['news'] ? 'selected="selected"' : NULL).' value="30">30</option>';
echo '</select><br />';
echo '<b>Sahifadagi sharhlar:</b><br />';
echo '<select name="comm">';
echo '<option '.(5 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="5">5</option>';
echo '<option '.(10 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="10">10</option>';
echo '<option '.(15 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="15">15</option>';
echo '<option '.(20 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="20">20</option>';
echo '<option '.(30 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="30">30</option>';
echo '<option '.(40 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="40">40</option>';
echo '<option '.(50 == $config['write']['news_comm'] ? 'selected="selected"' : NULL).' value="50">50</option>';
echo '</select><br />';
echo '<input type="submit" name="sett" value="Saqlash" /></form>';
echo CLOSE_DIV;
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS."");
if ($all == 0) {
echo DIV_AUT . 'Yangiliklar yo`q' . CLOSE_DIV;
} else {
$n = new Navigator($all,$config['write']['news'],'');
$sql = DB::$dbs->query("SELECT * FROM ".NEWS." ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['news']."");
while($new = $sql -> fetch()) {
echo DIV_AUT;
echo '<b>Sarlavha:</b> ' . $new['title'] . '<br /><br />';
echo '<b>Bosh sahifaga:</b> ' . text($new['afisha']) . '<br /><br />';
echo '<b>Yangilik:</b> ' . text($new['new']) . '<br /><br />';
echo CLOSE_DIV;
echo DIV_LI;
$comm = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS_COMM." WHERE `new_id` = ?", array($new['id']));
echo '<a href="'.HOME.'/panel/news/comm/'.$new['id'].'/">Sharhlar: <b>'.$comm.'</b></a>';
echo CLOSE_DIV;
echo DIV_LI;
echo '<a href="'.HOME.'/panel/news/?del='.$new['id'].'">[O`chirish]</a> <a href="'.HOME.'/panel/news/edit/'.$new['id'].'/">[Tahrirlash]</a>';
echo CLOSE_DIV;
}
echo $n->navi();
}
break;
case 'edit':
$id = num($_GET['id']);
if ($_POST) {
$title = html($_POST['title']);
$afisha = html($_POST['afisha']);
$new = html($_POST['new']);
if (strlen($title) < 10) {
$err .= 'Sarlavha nomi juda qisqa. Kamida 10 belgi<br />';
}
if (strlen($new) < 20) {
$err .= 'Yangilik matni juda qisqa. Kamida 20 belgi<br />';
}
if (empty($afisha)) {
$err .= 'Bosh sahifaga maydonchasi to`ldirilmadi<br />';
}
if ($err) {
echo DIV_ERROR . $err . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".NEWS." SET `title` = ?, `afisha` = ?, `new` = ? WHERE `id` = ?", array($title, $afisha, $new, $id));
echo DIV_MSG . 'Yangilik o`zgartirildi' . CLOSE_DIV;
}
}
$new = DB::$dbs->queryFetch("SELECT `title`, `afisha`, `new` FROM ".NEWS." WHERE `id` = ?",array($id));
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Sarlavha: [max. 100]<br /><input type="text" value="'.$new['title'].'" name="title" /><br /><br />';
echo 'Bosh sahifaga:<br /><textarea name="afisha" cols="30" rows="6">'.$new['afisha'].'</textarea><br />';
echo 'Yangilik:<br /><textarea name="new" cols="30" rows="6">'.$new['new'].'</textarea><br />';
echo '<input type="submit" value="O`zgartirish" /></form>';
echo CLOSE_DIV;
break;
case 'comm':
$id = num($_GET['id']);
$new = DB::$dbs->queryFetch("SELECT * FROM ".NEWS." WHERE `id` = ? ",array($id));
$comm = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".NEWS_COMM." WHERE `new_id` = ?", array($new['id']));
echo DIV_LI . '<b>Yangilikga sharh:</b>' . CLOSE_DIV;
if (!empty($_GET['del_comm'])) {
DB::$dbs->query("DELETE FROM ".NEWS_COMM." WHERE `id` = ? ", array(num($_GET['del_comm'])));
header("Location: ".HOME."/panel/news.php?select=comm&id=".$id."&p=".(int)$_GET['p']);
}
if (!empty($_GET['edit_comm'])) {
$comm2 = DB::$dbs->queryFetch("SELECT * FROM ".NEWS_COMM." WHERE `id` = ?",array(num($_GET['edit_comm'])));
if ($_POST) {
$msg = html($_POST['comm']);
DB::$dbs->query("UPDATE ".NEWS_COMM." SET `comm` = ? WHERE `id` = ?", array($msg, num($_GET['edit_comm'])));
header("Location: ".HOME."/panel/news.php?select=comm&id=".$id."&p=".(int)$_GET['p']);
}
echo DIV_AUT;
echo '<form action="news.php?select=comm&id='.$new['id'].'&edit_comm='.$comm2['id'].'&p='.(int)$_GET['p'].'" method="POST">';
echo 'Sharhni o`zgartirish:<br /><textarea name="comm">'.$comm2['comm'].'</textarea><br />';
echo '<input type="submit" value="O`zgartirish" /></form>';
echo CLOSE_DIV;
}
if (empty($comm)) {
echo DIV_BLOCK . 'Sharhlar yo`q' . CLOSE_DIV;
} else {
$n = new Navigator($comm,$config['write']['news_comm'],'select=comm&id='.$id);
$sql = DB::$dbs->query("SELECT * FROM ".NEWS_COMM." WHERE `new_id` = ? ORDER BY `id` DESC LIMIT {$n->start()}, ".$config['write']['news_comm']."", array($id));
while($comm = $sql -> fetch()) {
echo DIV_LI . userLink($comm['user_id']) . ' [' . vrem($comm['time']) . ']' . (privilegy('news_comm_delete') ? ' <a href="news.php?select=comm&id='.$new['id'].'&del_comm='.$comm['id'].'&p='.(int)$_GET['p'].'">[Удал.]</a> <a href="news.php?select=comm&id='.$new['id'].'&edit_comm='.$comm['id'].'&p='.(int)$_GET['p'].'">[Изм.]</a>' : NULL) . CLOSE_DIV;
echo DIV_BLOCK . text($comm['comm']) . CLOSE_DIV;
}
echo $n->navi();
}
break;
}
} else {
echo DIV_BLOCK . 'Kirishda xatolik' . CLOSE_DIV;
}
echo DIV_GO . '<a href="'.HOME.'/">Bosh sahifa</a> / <a href="'.HOME.'/panel">Boshqaruv panel</a> / <b>Sayt yangiliklari</b>' . CLOSE_DIV;
require_once('../core/stop.php');
?>