Файл: modules/news/index.php
Строк: 264
<?php
include '../../system/core.php';
include '../../system/header.php';
if(!$user['id']){
header('Location: /index.php/?m=guest'); exit;
}
if($user['menu'] == 1)
{
include '../../modules/menu/index.php';
}else{
}
switch($_GET['m']){
#Главная
default:
echo '<div class="tegi"><b>Новости ресурса</b></div></div>';
echo '</div>';
echo '<div class="start">';
include '../../system/nvg.php';
/////////////////////////////////////////////////
$rek = mysql_query("SELECT * FROM `ads` WHERE `mode` = '1'");
echo '<div class="rek"><div class="rekl"><img src="/images/r.png" alt="*"> <a href="/bl?bl=rek">Купить рекламу</a></br>';
while($rek2 = mysql_fetch_array($rek))
{
echo '<img src="/images/r.png" alt="*"> <a href="'.$rek2['link'].'">'.$rek2['name'].'</a></br>';
}
echo '</div>';
echo '</div>';
include 'system/nvg.php';
if($user['id']) {
echo ' <div class="start">';
echo '<div class="s" style="border-bottom:none;">';
echo '<table style="width:100%" cellspacing="0" cellpadding="0">';
echo '<tbody><tr><td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/cab" title="Кабинет"><img class="ico" align="middle" src="/images/vcard.png" alt="*"></a></center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/privat/" title="Почта"><img class="ico" align="middle" src="/images/mail2.png" alt="*"></a>';
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `privat` where `ho` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo ' <b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center><a href="/op/" title="Оповещения"><img class="ico" align="middle" src="/images/warning.png" alt="*"></a>';
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `op` where `who` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo '<b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '</tr></tbody></table>';
echo '</div>';
}
//////////////////////////////////////////////////////
if( $user['status'] >= 3){echo '<span><div class="post1"><a href="?m=add">Добавить новость</a></span>';}
echo '</div></div>';
$cop = $user['on_page'];
$ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `news`"),0);
$cp = ceil($ca/$cop);
if(isset($_GET['p']) && is_numeric($_GET['p'])){
$p = $_GET['p'];
if($_GET['p']>$cp) $p = $cp;
if($_GET['p']<1)$p = 1;
}else{
$p = 1;
}
$start = $p*$cop-$cop;
$news = mysql_query("SELECT * FROM `news` ORDER BY `time` DESC LIMIT $start,$cop");
while($news2 = mysql_fetch_assoc($news)){
echo '<div class="post1"><div class="newsds">Текст: '.smiles(bbcode($news2['text'])).'<br>
Добавил: '.ustatus($news2['author']).' <a href="/us'.$news2['author'].'">'.uname($news2['author']).'</a> '.uaccess($news2['author']).' ('.times($news2['time']).')';
if($user['status'] >= 2) echo ' [<a href="?m=del&id='.$news2['id'].'">уд</a>] [<a href="?m=edit&id='.$news2['id'].'">ред</a>]';
echo '<br><span><a href="/news/com'.$news2['id'].'">Комментарии</a> ('.mysql_result(mysql_query('select count(`id`) from `news_com` where `news` = "'.$news2['id'].'"'),0).')</span></div></div>';
}
echo '<div class="levo">Стр. ';
if($p-2>0) echo '<a href="/news?p=1"><<</a> ';
if($p-1>0) echo '<a href="/news?p='.($p-1).'"><</a> ';
if($p-3>0) echo '<a href="/news?p='.($p-3).'">'.($p-3).'</a> | ';
if($p-2>0) echo '<a href="/news?p='.($p-2).'">'.($p-2).'</a> | ';
if($p-1>0) echo '<a href="/news?p='.($p-1).'">'.($p-1).'</a> | ';
echo '<b>'.$p.'</b>';
if($p+1<=$cp) echo ' | <a href="/news?p='.($p+1).'">'.($p+1).'</a>';
if($p+2<=$cp) echo ' | <a href="/news?p='.($p+2).'">'.($p+2).'</a>';
if($p+3<=$cp) echo ' | <a href="/news?p='.($p+3).'">'.($p+3).'</a>';
if($p+1<=$cp) echo ' <a href="/news?p='.($p+1).'">></a>';
if($p+2<=$cp) echo ' <a href="/news?p='.ceil($ca/$cop).'">>></a>';
echo '</div></div>';
break;
case 'del':
if($user['status'] < 2){
header('Location: /news'); exit;
}
$id = TextGuard($_GET['id']);
$news = mysql_fetch_array(mysql_query('select * from `news` where `id` = "'.$id.'" limit 1'));
if(empty($id) or !is_numeric($id) or $news == 0){
header('Location: /news'); exit;
}
$news_com = mysql_query('select * from `news_com` where `news` = "'.$id.'"');
while($news_com2 = mysql_fetch_array($news_com)){
mysql_query("DELETE FROM `news_com` WHERE `id` = '".$news_com2['id']."'");
}
mysql_query("DELETE FROM `news` WHERE `id` = '$id'");
header('Location: /news'); exit;
break;
case 'add':
if($user['status'] < 2){
header('Location: /news'); exit;
}
echo '<div class="verh"><a href="/news"><b>Новости</a> | Добавить новость</b></div>';
/////////////////////////////////////////////////
$rek = mysql_query("SELECT * FROM `ads` WHERE `mode` = '1'");
echo '<div class="rek"><div class="rekl"><img src="/images/r.png" alt="*"> <a href="/bl?bl=rek">Купить рекламу</a></br>';
while($rek2 = mysql_fetch_array($rek))
{
echo '<img src="/images/r.png" alt="*"> <a href="'.$rek2['link'].'">'.$rek2['name'].'</a></br>';
}
echo '</div>';
echo '</div>';
include 'system/nvg.php';
if($user['id']) {
echo ' <div class="start">';
echo '<div class="s" style="border-bottom:none;">';
echo '<table style="width:100%" cellspacing="0" cellpadding="0">';
echo '<tbody><tr><td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/cab" title="Кабинет"><img class="ico" align="middle" src="/images/vcard.png" alt="*"></a></center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center>';
echo '<a href="/privat/" title="Почта"><img class="ico" align="middle" src="/images/mail2.png" alt="*"></a>';
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `privat` where `ho` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo ' <b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '<td style="vertical-align:top;width:10%;">';
echo '<center><a href="/op/" title="Оповещения"><img class="ico" align="middle" src="/images/warning.png" alt="*"></a>';
if($user['id']){
$c = mysql_result(mysql_query('select count(`id`) from `op` where `who` = "'.$user['id'].'" and `read` = "0"'),0);
if($c != 0) echo '<b> (+'.$c.')</b>';
}
echo '</center></td>';
echo '</tr></tbody></table>';
echo '</div>';
}
//////////////////////////////////////////////////////
include '../../system/nvg.php';
if(isset($_POST['submit'])){
$text = TextGuard($_POST['text']);
if(empty($text)) $err[] = 'Имя осталось пустым...';
$name = TextGuard($_POST['name']);
if(empty($name)) $err[] = 'Сообщение осталось пустым...';
if(!$err){
mysql_query("INSERT INTO `news`(
`author`,
`name`,
`text`,
`time`
)VALUES(
'".$user['id']."',
'".$name."',
'".$text."',
'".time()."'
)");
header('Location: /news'); exit;
}else{
echo '<div class="pet">';
foreach($err as $err_info){
echo $err_info.'<br>';
}
echo '</div>';
}
}
echo '<div class="news"><div class="newss">
<form action="/news?m=add" method="post">
Имя:<br><textarea style="width:98%" name="name" rows="3"></textarea><br>
Текст:<br><textarea style="width:98%" name="text" rows="3"></textarea><br>
<input type="submit" value="Добавить" name="submit"/>
</form></div></div>';
break;
case 'edit':
if($user['status'] < 2){
header('Location: /news'); exit;
}
$id = TextGuard($_GET['id']);
$news = mysql_fetch_array(mysql_query('select * from `news` where `id` = "'.$id.'" limit 1'));
if(empty($id) or !is_numeric($id) or $news == 0){
header('Location: /news'); exit;
}
echo '<div class="verh"><a href="/news"><b>Новости</a> | Редактировать новость</b></div>';
include '../../system/nvg.php';
if(isset($_POST['submit'])){
$text = TextGuard($_POST['text']);
if(empty($text)) $err[] = 'Сообщение осталось пустым...';
$name = TextGuard($_POST['name']);
if(empty($name)) $err[] = 'Сообщение осталось пустым...';
if(!$err){
mysql_query("UPDATE `news` SET `text`='".$text."' , `name`='".$name."' WHERE `id` = '".$id."' limit 1");
header('Location: /news'); exit;
}else{
echo '<div class="pet">';
foreach($err as $err_info){
echo $err_info.'<br>';
}
echo '</div>';
}
}
echo '<div class="mist">
<form action="/news?m=edit&id='.$id.'" method="post">
Имя:<br><textarea style="width:98%" name="name" rows="3">'.$news['name'].'</textarea><br>
Текст:<br><textarea style="width:98%" name="text" rows="3">'.$news['text'].'</textarea><br>
<input type="submit" value="Добавить" name="submit"/>
</form></div>';
break;
case 'com':
$id = TextGuard($_GET['id']);
$news = mysql_fetch_array(mysql_query('select * from `news` where `id` = "'.$id.'" limit 1'));
if(empty($id) or !is_numeric($id) or $news == 0){
header('Location: /news'); exit;
}
echo '<div class="podverh">';
echo '<div class="uv"><div class="sm"></div><div class="sm"></div><div class="co"><b>Просмотр новости</b></div></div>';
echo '</div>';
echo '<div class="start">';
include '../../system/nvg.php';
echo '<div class="s"><div class="ss"><span><a href="/cab">В кабинет</a><span></div></div>';
echo '<div class="news"><div class="newss">Текст: '.smiles(bbcode($news['text'])).'<br>
Добавил: '.ustatus($news['author']).' <a href="/us'.$news['author'].'">'.uname($news['author']).'</a> '.uaccess($news['author']).' ('.times($news['time']).')</div></div><div class="tegi"><font color="white">Комментарии:</font></div>
<div class="glav">
Сообщение:<br><form action="/news/com'.$id.'" method="post">
<textarea style="width:98%" name="text" rows="3"></textarea><br>
<input type="submit" value="Добавить" name="submit"/>
</form></div>';
if(isset($_POST['submit'])){
$text = TextGuard($_POST['text']);
if(empty($text)) $err[] = 'Сообщение осталось пустым...';
$ncm = mysql_query("SELECT * FROM `news_com` WHERE `author`='".$user['id']."' ORDER BY `time` desc");
while($ncm2 = mysql_fetch_assoc($ncm)){
$ncm_timeout = $ncm2['time'];
if((time()-$ncm_timeout) < 5) $err[] = 'Писать можно только раз в 5 секунд...';
}
if(mysql_result(mysql_query('select count(`id`) from `forum_m` where `author` = "'.$user['id'].'"'),0) < 10) $err[] = 'Наберите 10 постов на форуме,чтобы оставить свой коментарий';
$ncm_rep = mysql_fetch_array(mysql_query('select * from `news_com` where `author` = "'.$user['id'].'" and `text` = "'.$text.'"'));
if($ncm_rep != 0) $err[] = 'Вы уже писали подобное сообщение...';
if(!$err){
mysql_query("INSERT INTO `news_com`(
`news`,
`author`,
`text`,
`time`
)VALUES(
'".$id."',
'".$user['id']."',
'".$text."',
'".time()."'
)");
header('Location: /news/com'.$id.''); exit;
}else{
echo '<div class="err">';
foreach($err as $err_info){
echo $err_info.'<br>';
}
echo '</div>';
}
}
$cop = 10;
$ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `news_com` where `news` = '".$id."'"),0);
$cp = ceil($ca/$cop);
if(isset($_GET['p']) && is_numeric($_GET['p'])){
$p = $_GET['p'];
if($_GET['p']>$cp) $p = $cp;
if($_GET['p']<1)$p = 1;
}else{
$p = 1;
}
$start = $p*$cop-$cop;
if(isset($_GET['dp'])){
$pid = TextGuard($_GET['pid']);
if(empty($pid) or !is_numeric($pid)){
header('Location: ?'); exit;
}
$news_com = mysql_fetch_array(mysql_query('select * from `news_com` where `id` = "'.$pid.'"'));
if($news_com == 0){
header('Location: ?'); exit;
}
if($user['status'] < 1){
header('Location: /news/com'.$id.''); exit;
}
mysql_query("DELETE FROM `news_com` WHERE `id` = '$pid'");
}
$news_com = mysql_query("SELECT * FROM `news_com` where `news` = '".$id."' ORDER BY `time` DESC LIMIT $start,$cop");
while($news_com2 = mysql_fetch_assoc($news_com)){
echo '<div class="post1">'.ustatus($news_com2['author']).' <a href="/us'.$news_com2['author'].'">'.uname($news_com2['author']).'</a> '.uaccess($news_com2['author']).' ('.times($news_com2['time']).')';
if($user['status'] >= 2) echo ' [<a href="/news/com'.$id.'?dp&pid='.$news_com2['id'].'">уд</a>]</br>';
/////////////////////ВЫВОД ЗВЁЗД////////////////////////
////////////////////////////////////////////////////////
echo ''.smiles(bbcode($news_com2['text'])).'</div>';
}
echo '<div class="levo">Стр. ';
if($p-2>0) echo '<a href="/news?p=1"><<</a> ';
if($p-1>0) echo '<a href="/news?p='.($p-1).'"><</a> ';
if($p-3>0) echo '<a href="/news/com'.$id.'?p='.($p-3).'">'.($p-3).'</a> | ';
if($p-2>0) echo '<a href="/news/com'.$id.'?p='.($p-2).'">'.($p-2).'</a> | ';
if($p-1>0) echo '<a href="/news/com'.$id.'?p='.($p-1).'">'.($p-1).'</a> | ';
echo '<b>'.$p.'</b>';
if($p+1<=$cp) echo ' | <a href="/news/com'.$id.'?p='.($p+1).'">'.($p+1).'</a>';
if($p+2<=$cp) echo ' | <a href="/news/com'.$id.'?p='.($p+2).'">'.($p+2).'</a>';
if($p+3<=$cp) echo ' | <a href="/news/com'.$id.'?p='.($p+3).'">'.($p+3).'</a>';
if($p+1<=$cp) echo ' <a href="/news/com'.$id.'?p='.($p+1).'">></a>';
if($p+2<=$cp) echo ' <a href="/news/com'.$id.'?p='.ceil($ca/$cop).'">>></a>';
echo '</div>';
echo '</div>';
}
include '../../system/footer.php';
?>