Вход Регистрация
Файл: adm_panel/news.php
Строк: 198
<?php
define
('NTOP'1);
$title 'Админка - Управление новостями';
require_once(
'../system/connect.php');
require_once(
'../system/core.php');
require_once(
'../system/function.php');
require_once(
'../m/head.php');
reg();
level(2);
switch(
$act)
    {
            default:
            echo 
'<div class="title2">Администрирование новостей</div>';
            
            
$count mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."news`"));
            if(
$count 0)
                {
                    
$total=intval(($count-1)/$page_news)+1
                    
$page=abs(intval($_GET['page'])); 
                    if(empty(
$page) OR $page 0)
                        {
                            
$page 1
                        }
                    if(
$page $total)
                        {
                            
$page $total
                        }
                    
$past=intval($count/$page_news);  
                    
$start=$page*$page_news-$page_news
                    
$news mysql_query("SELECT * FROM `".$prefix."news` ORDER BY `time` DESC LIMIT ".$start.",".$page_news."");
                    while(
$row mysql_fetch_array($news)) 
                        {
                            
$start++;
                            
$count_comment mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."news_comments` WHERE `id_news` = '".$row['id']."'"));
                            echo 
'<div class="topni"><span class="o">'.$start.'</span> <b>'.$row['name'].'</b> ['.data($row['time']).']</div>';
                            echo 
'<div class="main">';
                            echo 
$row['text'].'<br/>';
                            echo 
'<hr>';
                            echo 
'Добавил: '.$row['author'].'';
                            echo 
'<span class = "gray" style="float:right"><a style="margin-right: 9px"><a href="http://'.$set['home'].'/adm_panel/news.php?act=comments&id='.$row['id'].'">Комм: </a>['.$count_comment.']</span></div>';
                            echo 
'<div class="topni">';
                            echo 
'<a href="http://'.$set['home'].'/adm_panel/news.php?act=del_news&id='.$row['id'].'">Удалить Новость</a> :: <a href="http://'.$set['home'].'/adm_panel/news.php?act=edit_news&id='.$row['id'].'">Изменить Новость</a><br/>';
                            echo 
'</div>';
                        }
                    
navigation($count,$page_news,$page,'http://'.$set['home'].'/adm_panel/news/',$total);
                }
            else
                {
                    echo 
'<div class="main">';
                    echo 
'Новостей нет!<br/>';
                    echo 
'</div>';
                }
        break;
        case 
'add':
        if(!isset(
$_POST['ok']))
            {
                echo 
'
                <div class="main">
                <form action="news.php?act=add" method="post">
                Название новости(max. 30):<br/>
                <input type="text" name="name" class="input" maxlength="30" /><br />
                Текст новости(max. 200):<br/>
                <textarea name="text" cols="38" rows="8"></textarea><br/>
                <input name="ok" type="submit" value="Добавить" />
                </form>
                </div>
                '
;
            }
        else
            {
                
$name htmlspecialchars(trim($_POST['name']));
                
$text htmlspecialchars(trim($_POST['text']));
                
$error '';
                if(empty(
$name) OR empty($text))
                    {
                        
$error .= 'Ошибка! Не заполнены поля! <br/>';
                    }
                if(
mb_strlen($name) > 30)
                    {
                        
$error .= 'Ошибка! Поле "Название новости" больше 30 символов! <br/>';
                    }
                if(
mb_strlen($text) > 1000)
                    {
                        
$error .= 'Ошибка! Поле "Текст новости" больше 1000 символов! <br/>';
                    }
                if(!empty(
$error))
                    {
                        echo 
'<div class="topni">';
                        echo 
$error;
                        echo 
'</div>';
                    }
                else
                    {
                        
$insert mysql_query("INSERT INTO `".$prefix."news` SET 
                `name` = '" 
mysql_real_escape_string($name) . "',
                `text` = '" 
mysql_real_escape_string($text) . "', 
                `time` = '" 
time() . "',
                `author` = '" 
mysql_real_escape_string($user_data['login']) . "'");
                        if(
$insert)
                            {
                                echo 
'<div class="main">';
                                echo 
'Новость успешно добавлена! <br/>';
                                echo 
'</div>';
                            }
                        else
                            {
                                echo 
'<div class="topni">';
                                echo 
'Новость не добавлена! <br/>';
                                echo 
'</div>';
                            }
                    }            
            }
        break;
        case 
'del_news':
        if(
$id)
            {
                
$del_comm mysql_query("DELETE FROM `".$prefix."news_comments` WHERE `id_news` = '".$id."'");
                
$del_news mysql_query("DELETE FROM `".$prefix."news` WHERE `id` = '".$id."'");
                if(
$del_news AND $del_comm)
                    {
                        echo 
'<div class="main">';
                        echo 
'Новость успешно удалена! <br/>';
                        echo 
'</div>';
                    }
                else
                    {
                        echo 
'<div class="topni">';
                        echo 
'Новость не удалена! <br/>';
                        echo 
'</div>';
                    }
            }
        else
            {
                echo 
'<div class="topni">';
                echo 
'Не выбрана новость! <br/>';
                echo 
'</div>';
            }
        break;
        case 
'edit_news':
        if(
$id)
            {
                
$isset mysql_query("SELECT * FROM `".$prefix."news` WHERE `id` = '".$id."'");
                if(
mysql_num_rows($isset) > 0)
                    {
                        
$news mysql_fetch_array($isset);
                        echo 
'<div class="title">Изменение новости</div>';
                        if(!isset(
$_POST['ok']))
                            {
                                echo 
'
                                <div class="main">
                                <form action="news.php?act=edit_news&id='
.$id.'" method="post">
                                Название новости(max.30):<br/>
                                <input type="text" name="name" maxlength="30" value="'
.$news['name'].'"/><br/>
                                Текст новости(max.200):<br/>
                                <textarea name="text" cols="38" rows="8">'
.$news['text'].'</textarea><br/>
                                <input type="submit" name="ok" value="Изменить"/>
                                </form></div>'
;
                            }
                        else
                            {
                                
$name htmlspecialchars(trim($_POST['name']));
                                
$text htmlspecialchars(trim($_POST['text']));
                                
$error '';
                                if(empty(
$name) OR empty($text))
                                    {
                                        
$error .= 'Ошибка!Не заполнены поля!<br/>';
                                    }
                                if(
mb_strlen($name) > 30)
                                    {
                                        
$error .= 'Ошибка!Поле "Название новости" больше 30 символов<br/>';
                                    }
                                if(
mb_strlen($text) > 1000)
                                    {
                                        
$error .= 'Ошибка!Поле "Текст новости" больше 1000 символов<br/>';
                                    }
                                if(!empty(
$error))
                                    {
                                        echo 
'<div class="error">';
                                        echo 
$error;
                                        echo 
'</div>';
                                    }
                                else
                                    {
                                        
$up mysql_query("UPDATE `".$prefix."news` SET
               `name` = '" 
mysql_real_escape_string($name) . "',
               `text` = '" 
mysql_real_escape_string($text) . "' 
                WHERE `id` = '" 
.$id"'");
                                        if(
$up)
                                            {
                                                echo 
'<div class="main">';
                                                echo 
'Новость успешно изменена<br/>';
                                                echo 
'</div>';
                                            }
                                        else
                                            {
                                                echo 
'<div class="topni">';
                                                echo 
'Новость не изменена<br/>';
                                                echo 
'</div>';
                                            }
                                    }
                            }
                    }
                else
                    {
                        echo 
'<div class="topni">';
                        echo 
'Данной новости нет!<br/>';
                        echo 
'</div>';
                    }
            }
        else
            {            
                echo 
'<div class="topni">';
                echo 
'Не выбрана новость!<br/>';
                echo 
'</div>';
            }
        break;
        case 
'comments':
        echo 
'<div class="title2">Управление комментариями</div>';
        
$isset_news mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."news` WHERE `id` = '".$id."'"));
        if(
$isset_news != 0)
            {
                
$count mysql_num_rows(mysql_query("SELECT * FROM `".$prefix."news_comments` WHERE `id_news` = '".$id."'"));
                if(
$count 0)
                    {
                        
$total=intval(($count-1)/$page_nc)+1
                        
$page=abs(intval($_GET['page'])); 
                        if(empty(
$page) OR $page 0)
                            {
                                
$page 1
                            }
                        if(
$page $total)
                            {
                                
$page $total
                            }
                        
$past=intval($count/$page_nc);  
                        
$start=$page*$page_nc-$page_nc
                        
$comments mysql_query("SELECT * FROM `".$prefix."news_comments` WHERE `id_news` = '".$id."' ORDER BY `time` DESC LIMIT ".$start.",".$page_nc."");
                        while(
$row mysql_fetch_array($comments)) 
                            {
                                
$start++;
                                echo 
'<div class="topni"><span class="o">'.$start.'</span> <b>'.$row['name'].'</b> ['.data($row['time']).']</div>';
                                echo 
'<div class="main">';
                                echo 
$row['text'].'</div>';
                                echo 
'<div class="topni"><a href="http://'.$set['home'].'/adm_panel/news.php?act=del_comment&id='.$row['id'].'">Удалить</a>';
                                echo 
'</div>';
                            }
                        
                        echo 
'<div class="main">- <a href="http://'.$set['home'].'/adm_panel/news.php?act=del_comments&id='.$id.'">Удалить Все Комм</a></div>';
                        
                        
navigation($count,$page_nc,$page,'http://'.$set['home'].'/adm_panel/news/com/'.$id.'/',$total);
                    }
                else
                    {
                        echo 
'<div class="main">';
                        echo 
'Комментариев к данной новости нет!<br/>';
                        echo 
'</div>';
                    }
                
            }
        else
            {
                echo 
'<div class="topni">';
                echo 
'Нет такой новости!</br>';
                echo 
'</div>';
            }
        break;
        case 
'del_comment':
        echo 
'<div class="title2">Управление комментариями</div>';
        
$del mysql_query("DELETE FROM `".$prefix."news_comments` WHERE `id` = '".$id."'");
            if(
$del)
                {
                    echo 
'<div class="main">';
                    echo 
'Комментарий успешно удален<br/>';
                    echo 
'</div>';
                }
            else
                {
                    echo 
'<div class="topni">';
                    echo 
'Комментарий не удален<br/>';
                    echo 
'</div>';
                }
        break;
        case 
'del_comments':
        echo 
'<div class="title2">Управление комментариями</div>';
        
$del mysql_query("DELETE FROM `".$prefix."news_comments` WHERE `id_news` = '".$id."'");
        if(
$del)
            {
                echo 
'<div class="main">';
                echo 
'Комментарии успешно удалены<br/>';
                echo 
'</div>';
            }
        else
            {
                echo 
'<div class="topni">';
                echo 
'Комментарии не удалены<br/>';
                echo 
'</div>';
            }
        break;
    }

echo 
'<div class="main">';
echo 
'<a href="http://'.$set['home'].'/adm_panel/news.php?act=add">Добавить Новость</a><br/>';
echo 
'<a href="http://'.$set['home'].'/adm_panel/news.php">К управлению новостями</a><br/>';
echo 
'<a href="http://'.$set['home'].'/adm_panel/index.php">В Админку</a><br/>';
echo 
'</div>';

require_once(
'../m/foot.php');
?>
Онлайн: 1
Реклама