Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/category.php
Строк: 107
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_photo_category extends VModule_Admin_photo
{
private $option;
private $filter;
public function __construct()
{
parent::__construct();
$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 #__photo_categories SET status = '".$status."' WHERE cat_id = ".$cat_id." LIMIT 1");
$messages[] = 'Category '.$msg.'!';
$cache->remove('categories');
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__photo_categories WHERE cat_id = ".$cat_id." LIMIT 1");
$messages[] = 'Category deleted!';
$cache->remove('categories');
} elseif ($action == 'unassign') {
$this->db->query("UPDATE #__photo_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['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 #__photo_categories SET status = ".$status." WHERE cat_id IN (".implode(',', $ids).")");
$messages[] = 'Select categories '.$msg.'!';
$cache->remove('categories');
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__photo_categories WHERE cat_id IN (".implode(',', $ids).")");
$messages[] = 'Selected categories deleted!';
$cache->remove('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' => 10
);
$search = $this->search_photo_categories();
$categories_total = $this->db->get_field($search['sql_count'], 'total_categories');
$pagination = VPagination::get($page, $categories_total, $search['display']);
$categories = $this->db->get_rows($search['sql']." LIMIT ".$pagination['limit']);
$advs = $this->db->get_rows("SELECT a.adv_id, adv_name
FROM #__adv AS a, #__adv_groups AS g
WHERE g.adv_group_slug = 'video-player'
AND a.adv_group_id = g.adv_group_id
AND a.status = '1'
ORDER BY a.adv_name ASC");
$tpl = VF::factory('template');
$tpl->menu = 'photo';
$tpl->submenu = 'photo_category';
$tpl->meta_title = 'Admin::Photo::Category::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->option = $this->option;
$tpl->categories = $categories;
$tpl->pagination = $pagination;
$tpl->advs = $advs;
$tpl->load(array('header', 'photo_category', 'footer'));
$tpl->display();
}
private function search_photo_categories()
{
$sql = "SELECT * FROM #__photo_categories";
$sql_count = "SELECT COUNT(*) AS total_categories FROM #__photo_categories";
if (isset($_POST['submit_search'])) {
$this->option['name'] = $this->filter->get('name');
$this->option['sort'] = $this->filter->get('sort');
$this->option['order'] = ($_POST['order'] == 'DESC') ? 'DESC' : 'ASC';
$this->option['display'] = (int) $_POST['display'];
}
if ($this->option['name'] != '') {
$sql .= " WHERE name LIKE '%".$this->db->escape($this->option['name'])."%'";
$sql_count .= " WHERE name LIKE '%".$this->db->escape($this->option['name'])."%'";
}
return array(
'sql' => $sql.' ORDER BY '.$this->option['sort'].' '.$this->option['order'],
'sql_count' => $sql_count,
'display' => $this->option['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 delete_video_category($cat_id)
{
}
}
?>