Вход Регистрация
Файл: New_top/AdmPanel/news.php
Строк: 166
<?php
$title 
'Панель управления сайтом - Управление новостями';
require_once(
'../Sys/head.php');
reg();
level(2);
switch(
$act)
    {
            default:
            echo 
'<div class="block">Управление новостями</div>';
            
$count $mysqli->query("SELECT `id` FROM `".$prefix."news`")->num_rows;
            if(
$count 0)
                {
                    
$total intval(($count-1)/$pageNews)+1;
                    
$page = (isset($_GET['page'])) ? abs(intval($_GET['page'])) : '';
                    if(empty(
$page) OR $page 0)
                        {
                            
$page 1;
                        }
                    if(
$page $total)
                        {
                            
$page $total;
                        }
                    
$past intval($count/$pageNews);
                    
$start $page*$pageNews-$pageNews;
                    
$news $mysqli->query("SELECT * FROM `".$prefix."news` ORDER BY `time` DESC LIMIT ".$start.",".$pageNews."");
                    while(
$row $news->fetch_assoc())
                        {
                            
$start++;
                            echo 
'<div class="l1"><span class="o">'.$start.'</span> <strong>'.$row['name'].'</strong> ['.data($row['time']).']</div>';
                            echo 
'<div class="li">';
                            echo 
bbCodes(nl2br($row['text']));
                            echo 
'<hr>';
                            echo 
'<div id="left2">Добавил: '.$row['author'].'</div>';
                            echo 
'<div id="right2"><a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/comments/'.$row['id'].'">Коментарии</a> ['.$row['comments'].']</div>';
                            echo 
'</div>';
                            echo 
'<div class="l1"><a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/deleteNews/'.$row['id'].'">Удалить новость</a> :: <a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/editNews/'.$row['id'].'">Изменить новость</a></div>';
                            
                        }
                    if(
$count $pageNews)
                        {
                            
navigation($total,$page,'http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/');
                        }
                }
            else
                {
                    echo 
'<div class="l1">';
                    echo 
'Новостей нет.<br/>';
                    echo 
'</div>';
                }
        echo 
'<div class="li"><a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/add">Добавить новость</a><br/></div>';
        break;
        case 
'add':
        if(!isset(
$_POST['ok']))
            {
                echo 
'
                <div class="l1">
                <form action="" method="post">
                Название новости (max. 100):<br/>
                <input type="text" class="form" name="name" class="input" maxlength="30" /><br />
                Текст новости (max. 4000):<br/>
                <textarea class="form" name="text" cols="38" rows="8"></textarea><br/>
                <input name="ok" type="submit" class="button" value="Добавить" />
                </form>
                </div>
                '
;
            }
        else
            {
                
$name filter($_POST['name']);
                
$text filter($_POST['text']);
                
$error '';
                if(empty(
$name) OR empty($text))
                    {
                        
$error .= 'Не заполнены поля.<br/>';
                    }
                if(
mb_strlen($name) > 100)
                    {
                        
$error .= 'Поле "Название новости" больше 100 символов.<br/>';
                    }
                if(
mb_strlen($text) > 4000)
                    {
                        
$error .= 'Поле "Текст новости" больше 4000 символов.<br/>';
                    }
                if(!empty(
$error))
                    {
                        echo 
'<div class="l1">';
                        echo 
'В результате заполнения полей , выявились ошибки:<br/>';
                        echo 
$error;
                        echo 
'<a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/add">Назад</a><br/>';
                        echo 
'</div>';
                    }
                else
                    {
                        
$mysqli->query("INSERT INTO `".$prefix."news` VALUES ('', '".$name."', '".$text."', '".$time."', '".$user_data['login']."', '0')");
                        echo 
'<div class="l1">';
                        echo 
'Новость успешно добавлена! <br/>';
                        echo 
'</div>';
                        }
                    
//////////////////////////////////////////////
                 
$headers '';
                 
$headers .= "From: ".$set['mail']." n";
                 
$headers .= "Content-Type: text/plain; charset=utf-8n";
                 
$mails $mysqli->query("SELECT DISTINCT `mail` FROM `".$prefix."users` WHERE `mail` <> ''");
                 if(
$mails->num_rows 0)
                    {
                        while(
$row $mails->fetch_assoc())
                            {
                                
mail($row['mail'], $name$text$headers);
                            }
                        echo 
'<div class="l1">';
                        echo 
'Ваше сообщение отправлено '.$mails->num_rows.' участнику(ам).<br/>';
                        echo 
'</div>';
                    }
                    else
                    {
                        echo 
'<div class="l1">';
                        echo 
'E-MAIL`ов не найдено.<br/>';
                        echo 
'</div>';
                    }
            }
        break;
        case 
'deleteNews':
        if(
$id)
            {
                
$mysqli->query("DELETE FROM `".$prefix."news_comments` WHERE `nid` = '".$id."'");
                
$mysqli->query("DELETE FROM `".$prefix."news` WHERE `id` = '".$id."'");
                echo 
'<div class="l1">';
                echo 
'Новость успешно удалена.<br/>';
                echo 
'</div>';
            }
        else
            {
                echo 
'<div class="l1">';
                echo 
'Не выбрана новость.<br/>';
                echo 
'</div>';
            }
        break;
        case 
'editNews':
        if(
$id)
            {
                
$isset $mysqli->query("SELECT `id`,`name`,`text` FROM `".$prefix."news` WHERE `id` = '".$id."'");
                if(
$isset->num_rows 0)
                    {
                        
$news $isset->fetch_assoc();
                        echo 
'<div class="block">Изменение новости</div>';
                        if(!isset(
$_POST['ok']))
                            {
                                echo 
'
                                <div class="l1">
                                <form action="" method="post">
                                Название новости(max.100):<br/>
                                <input type="text" class="form" name="name" maxlength="30" value="'
.$news['name'].'"/><br/>
                                Текст новости(max.4000):<br/>
                                <textarea class="form" name="text" cols="38" rows="8">'
.$news['text'].'</textarea><br/>
                                <input type="submit" class="button" name="ok" value="Изменить"/>
                                </form></div>'
;
                            }
                        else
                            {
                                
$name filter($_POST['name']);
                                
$text filter($_POST['text']);
                                
$error '';
                                if(empty(
$name) OR empty($text))
                                    {
                                        
$error .= 'Ошибка!Не заполнены поля!<br/>';
                                    }
                                if(
mb_strlen($name) > 100)
                                    {
                                        
$error .= 'Поле "Название новости" больше 100 символов.<br/>';
                                    }
                                if(
mb_strlen($text) > 4000)
                                    {
                                        
$error .= 'Поле "Текст новости" больше 4000 символов.<br/>';
                                    }
                                if(!empty(
$error))
                                    {
                                        echo 
'<div class="l1">';
                                        echo 
'В результате заполнения полей , выявились ошибки:<br/>';
                                        echo 
$error;
                                        echo 
'<a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/editNews/'.$id.'">Назад</a><br/>';
                                        echo 
'</div>';
                                    }
                                else
                                    {
                                        
$mysqli->query("UPDATE `".$prefix."news` SET `name` = '".$name."', `text` = '".$text."' WHERE `id` = '".$id."'");
                                        echo 
'<div class="l1">';
                                        echo 
'Новость успешно изменена<br/>';
                                        echo 
'</div>';
                                    }
                            }
                    }
                else
                    {
                        echo 
'<div class="l1">';
                        echo 
'Данной новости нет.<br/>';
                        echo 
'</div>';
                    }
            }
        else
            {
                echo 
'<div class="l1">';
                echo 
'Не выбрана новость.<br/>';
                echo 
'</div>';
            }
        break;
        case 
'comments':
        echo 
'<div class="block">Управление комментариями</div>';
        
$issetNews $mysqli->query("SELECT `id` FROM `".$prefix."news` WHERE `id` = '".$id."'")->num_rows;
        if(
$issetNews 0)
            {
                
$count $mysqli->query("SELECT `id` FROM `".$prefix."news_comments` WHERE `nid` = '".$id."'")->num_rows;
                if(
$count 0)
                    {
                        
$total intval(($count-1)/$pageNc)+1;
                        
$page = (isset($_GET['page'])) ? abs(intval($_GET['page'])) : '';
                        if(empty(
$page) OR $page 0)
                            {
                                
$page 1;
                            }
                        if(
$page $total)
                            {
                                
$page $total;
                            }
                        
$past intval($count/$pageNc);
                        
$start $page*$pageNc-$pageNc;
                        
$comments $mysqli->query("SELECT * FROM `".$prefix."news_comments` WHERE `nid` = '".$id."' ORDER BY `time` DESC LIMIT ".$start.",".$pageNc."");
                        while(
$row $comments->fetch_assoc())
                            {
                                
$start++;
                                echo 
'<div class="l1"><span class="o">'.$start.'</span> <strong>'.$row['name'].'</strong> ['.data($row['time']).']</div>';
                                echo 
'<div class="li">';
                                echo 
$row['text'].'<br/>';
                                echo 
'<hr/>';
                                echo 
'<a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/deleteComment/'.$row['id'].'">Удалить</a><br/>';
                                echo 
'</div>';
                            }
                        echo 
'<div class="l1">';
                        echo 
'<center><a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/deleteComments/'.$id.'">Удалить все комментарии</a></center>';
                        echo 
'</div>';
                        if(
$count $pageNc)
                            {
                                
navigation($total,$page,'http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news/comments/'.$id.'/');
                            }
                    }
                else
                    {
                        echo 
'<div class="l1">';
                        echo 
'Комментариев к данной новости нет.<br/>';
                        echo 
'</div>';
                    }
            }
        else
            {
                echo 
'<div class="l1">';
                echo 
'Нет такой новости.</br>';
                echo 
'</div>';
            }
        break;
        case 
'deleteComment':
        echo 
'<div class="block">Управление комментариями</div>';
        
$newsId $mysqli->query("SELECT `nid` FROM `".$prefix."news_comments` WHERE `id` = '".$id."'")->fetch_assoc();
        
$mysqli->query("DELETE FROM `".$prefix."news_comments` WHERE `id` = '".$id."'");
        
$mysqli->query("UPDATE `".$prefix."news` SET `comments` = (`comments` - 1) WHERE `id` = '".$newsId['nid']."'");
        echo 
'<div class="l1">';
        echo 
'Комментарий успешно удален.<br/>';
        echo 
'</div>';
        break;
        case 
'deleteComments':
        echo 
'<div class="block">Управление комментариями</div>';
        
$mysqli->query("DELETE FROM `".$prefix."news_comments` WHERE `nid` = '".$id."'");
        
$mysqli->query("UPDATE `".$prefix."news` SET `comments` = '0' WHERE `id` = '".$id."'");
        echo 
'<div class="l1">';
        echo 
'Все комментарии успешно удалены.<br/>';
        echo 
'</div>';
        break;
    }

echo 
'<div class="li">';
echo 
'<a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel/news">К управлению новостями</a><br/>';
echo 
'<a href="http://'.$_SERVER['HTTP_HOST'].'/controlPanel">В Админку</a><br/>';
echo 
'</div>';
?>
Онлайн: 3
Реклама