View file blog/moder.php

File size: 4.18Kb
<?php 
// by mides, wmclub.mobi

$title = 'Блоги - Модерация';
require('../config.php');
require('../includes/sys.php');
require('../includes/start.php');
require('../includes/header.php');

if($u['user_access'] > 1){
switch($_GET['act']){

###############################################################################
##                           Главная страница                                ##
###############################################################################
default:

tp('Модерация');

$all_articles = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `blog_articles` WHERE `ok` = 0"), 0);
if($all_articles > 0){
	$pages = ceil($all_articles/$config['onpage']);
	if(intval($_REQUEST['page'])){
		$page = intval($_REQUEST['page']);
	}else{
		$page = 1;
	}
	$from = ($page-1)*$config['onpage'];
	
	$r_articles = mysql_query("SELECT `id`, `title`, `time` FROM `blog_articles` WHERE `ok` = 0 ORDER BY `time` LIMIT $from, $config[onpage]");
	while($article = mysql_fetch_assoc($r_articles)){
		echo '<a href="?act=edit&amp;id='.$article['id'].'">'.$article['title'].'</a> ('.date('d.m.y, H:i', $article['time']).')<br />';
	}
}else{
	echo 'Статей пока нет :(';
}
	
echo '<hr />';

navig($page, '?', $pages);
echo '<a href="./">Назад</a><br />';
echo '</div>';

break;

###############################################################################
##                       Форма редактирования статьи                         ##
###############################################################################
case 'edit':

$id = intval($_REQUEST['id']);
$article = mysql_fetch_assoc(mysql_query("SELECT * FROM `blog_articles` WHERE `id` = '$id'"));
if($article['id']){
	tp('Редактировать');
	echo '<form action="?act=edit_do&amp;id='.$id.'" method="post" name="form">
		 Раздел:<br />
		 <select name="cat">';
		 // articles' cat
		 $ar_cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `blog_cats` WHERE `id` = '$article[id_cat]'"));
		 echo '<option value="'.$ar_cat['id'].'">'.$ar_cat['name'].'</option>';
		  // new cat
		 $cats = mysql_query("SELECT * FROM `blog_cats` WHERE `id` != '$article[id_cat]'");
		 while($cat = mysql_fetch_assoc($cats)){
		 	echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';
		}
	echo '</select><br />
		 Заголовок(max50):<br /><input name="title" type="text" maxlength="50" value="'.$article['title'].'" /><br />
		 Текст:<br /><textarea name="text" cols="" rows="5">'.$article['text'].'</textarea><br />
		 Метки(max50):<br /><input name="tags" type="text" maxlength="50" value="'.$article['tags'].'" /><br />
		 Действие:<br />
		 <select name="action">
		 	<option value="1">Промодерировать</option>
		 	<option value="2">Удалить</option>
		 </select><br />
		 <input name="submit" type="submit" value="Ok" />
		 </form>';
}else{
	error('Выбранная статья не существует!');
}
nav('?');

break;

###############################################################################
##                          Редактирование статьи                            ##
###############################################################################
case 'edit_do':

$id = intval($_REQUEST['id']);
$action = intval($_POST['action']);
if($action == 1){
	if(!empty($_POST['title']) and !empty($_POST['text']) and !empty($_POST['tags'])){
		$cat = intval($_POST['cat']);
		$title = check($_POST['title']);
		$text = check($_POST['text']);
		$tags = check($_POST['tags']);
		mysql_query("UPDATE `blog_articles` SET `id_cat` = '$cat', `title` = '$title', `text` = '$text', `tags` = '$tags', `ok` = 1 WHERE `id` = '$id'");
		info('Статья успешно промодерирована!');
	}else{
		error('Вы не заполнили поля!');
	}
}elseif($action == 2){
	mysql_query("DELETE FROM `blog_articles` WHERE `id` = '$id'");
	info('Статья успешно удалена!');
}
nav('./');

break;

}
}else{
	error('Доступ запрещен!');
	nav_main();
}

require('../includes/tail.php');
?>