Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/category.php
Строк: 112
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_video_category
{
private $db;
private $option;
private $filter;
public function __construct()
{
$this->db = &VF::factory('database');
$this->filter = &VF::factory('filter');
}
public function render()
{
$errors = array();
$messages = array();
$cache = VF::factory('cache');
if (isset($_POST['action']) && isset($_POST['cat_id'])) {
$action = $this->filter->get('action');
$cat_id = (int) trim($_POST['cat_id']);
if ($cat_id) {
if ($action == 'suspend' OR $action == 'activate') {
$status = ($action == 'suspend') ? 0 : 1;
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$this->db->query("UPDATE #__video_categories SET status = '".$status."' WHERE cat_id = ".$cat_id." LIMIT 1");
$messages[] = 'Category '.$msg.'!';
$cache->remove('categories');
} elseif ($action == 'delete') {
if ($this->delete_video_category($cat_id)) {
$messages[] = 'Category deleted!';
$cache->remove('categories');
} else {
$errors[] = 'You cannot delete this category! It contains subcategories!';
}
} elseif ($action == 'unassign') {
$this->db->query("UPDATE #__video_categories SET adv = 0 WHERE cat_id = ".$cat_id." LIMIT 1");
$messages[] = 'Advertising banner removed!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid category id! What exactly did you click!?';
}
}
if (isset($_POST['sub_action'])) {
$action = $this->filter->get('sub_action');
$ids = str_replace('&', '&', $this->filter->get('sub_ids'));
if (!empty($ids)) {
parse_str($ids, $categs);
if ($action == 'assign') {
$adv_id = (int) ($_POST['sub_id']);
if (!empty($adv_id)) {
$this->db->query("UPDATE #__video_categories
SET adv = ".$adv_id."
WHERE cat_id IN (".implode(',', array_keys($categs)).")");
$messages[] = 'Advertising assigned to selected categories!';
} else {
$errors[] = 'Please select a advertising banner!';
}
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Please select at least one category!';
}
}
if (isset($_POST['submit_actions'])) {
$action = $this->filter->get('action');
$ids = $this->get_checkbox_ids();
if ($action == 'suspend' OR $action == 'activate') {
$status = ($action == 'suspend') ? 0 : 1;
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$this->db->query("UPDATE #__video_categories SET status = ".$status." WHERE cat_id IN (".implode(',', $ids).")");
$messages[] = 'Select categories '.$msg.'!';
$cache->remove('categories');
} elseif ($action == 'delete') {
$success = TRUE;
foreach ($ids as $cat_id) {
$cat_id = (int) $cat_id;
if (!$this->delete_video_category($cat_id)) {
$success = FALSE;
}
}
if ($success === TRUE) {
$messages[] = 'Selected categories deleted!';
} else {
$errors[] = 'Failed to delete one or more categories because they contain subcategories!';
}
} elseif ($action == 'unassign') {
$this->db->query("UPDATE #__video_categories
SET adv = 0
WHERE cat_id IN (".implode(',', array_keys($ids)).")");
$messages[] = 'Advertising banners removed from selected categories!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
}
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
$this->option = array(
'name' => '',
'sort' => 'name', 'order' => 'ASC', 'display' => 30
);
$sql = "SELECT cat_id, parent_id, name, slug, total_videos, status
FROM #__video_categories
ORDER BY slug, parent_id ASC";
$categories = $this->db->get_rows($sql);
if (VF::cfg_item('module.video.subcategories')) {
}
$this->db->query("SELECT cat_id, name
FROM #__video_categories
WHERE parent_id = 0
ORDER BY slug ASC");
$rows = $this->db->fetch_rows();
$parents = array();
foreach ($rows as $categ) {
$parents[intval($categ['cat_id'])] = $categ['name'];
}
$tpl = VF::factory('template');
$tpl->menu = 'video';
$tpl->submenu = 'video_category';
$tpl->meta_title = 'Admin::Video::Category::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->option = $this->option;
$tpl->categories = $categories;
$tpl->parents = $parents;
$tpl->advs = $this->get_video_advs();
$tpl->load(array('header', 'video_category', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_category_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_category_', '', $key);
}
}
return $ids;
}
private function get_video_advs()
{
$this->db->query("SELECT a.adv_id, a.adv_name
FROM #__adv_groups AS g
INNER JOIN #__adv AS a ON (a.adv_group_id = g.adv_group_id AND a.status = '1')
WHERE g.adv_group_slug = 'video-player'
ORDER BY a.adv_name ASC");
return $this->db->fetch_rows();
}
private function delete_video_category($cat_id)
{
$this->db->query("SELECT cat_id
FROM #__video_categories
WHERE parent_id = ".$cat_id."
LIMIT 1");
if ($this->db->affected_rows()) {
return FALSE;
}
$this->db->query("DELETE FROM #__video_categories WHERE cat_id = ".$cat_id." LIMIT 1");
return TRUE;
}
}
?>