Файл: adultscript-2.0.3-pro/files/admin/modules/news/components/manage.php
Строк: 115
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_news_manage
{
private $db;
private $option;
public function __construct()
{
$this->db = VF::factory('database');
$this->option = array(
'username' => '',
'title' => '',
'status' => '',
'sort' => 'n.news_id',
'order' => 'DESC',
'display' => 10
);
}
public function render()
{
$errors = array();
$messages = array();
if (isset($_POST['action']) && isset($_POST['news_id'])) {
$action = trim($_POST['action']);
$news_id = (int) trim($_POST['news_id']);
if ($news_id) {
switch ($action) {
case 'activate':
case 'suspend':
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$this->db->query("UPDATE #__news SET status = '".$status."' WHERE news_id = ".$news_id." LIMIT 1");
$messages[] = 'Article '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__news WHERE news_id = ".$news_id." LIMIT 1");
$messages[] = 'Article deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid news article id! Are you sure this article exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$ids = $this->get_checkbox_ids();
$action = trim($_POST['action']);
if ($ids) {
if ($action == 'activate' OR
$action == 'suspend') {
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$this->db->query("UPDATE #__news SET status = '".$status."' WHERE news_id IN (".implode(',', $ids).")");
$messages[] = 'Selected articles '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__news WHERE news_id IN (".implode(',', $ids).")");
$messages[] = 'Selected articles deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'You must select at least one article!';
}
}
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
if (isset($_SESSION['search_news_option'])) {
$this->option = $_SESSION['search_news_option'];
}
$search = $this->search_news();
$articles_total = $this->db->get_field($search['sql_count'], 'total_pages');
$pagination = VPagination::get($page, $articles_total, $search['display']);
$articles = $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'news';
$tpl->extramenu = 'news_manage';
$tpl->meta_title = 'Admin::News::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->articles = $articles;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'news_manage', 'footer'));
$tpl->display();
}
private function search_news()
{
$sql = "SELECT n.news_id, n.title, n.total_views, n.add_date, n.status,
n.user_id, u.username
FROM #__news AS n
LEFT JOIN #__user AS u ON (u.user_id = n.user_id)";
$sql_count = "SELECT COUNT(*) AS total_articles FROM #__news AS n";
return array(
'sql' => $sql,
'sql_count' => $sql_count,
'display' => $this->option['display']
);
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_news_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_news_', '', $key);
}
}
return $ids;
}
}
?>