Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/manage.php
Строк: 144
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_manage
{
private $db;
private $option;
public function __construct()
{
$this->db = VF::factory('database');
$this->option = array(
'adv_group_id' => 0, 'adv_name' => '', 'status' => '',
'expire' => '',
'sort' => 'a.adv_name', 'order' => 'DESC', 'display' => 20
);
}
public function render()
{
$approve = false;
$groups = $this->get_adv_groups();
$errors = array();
$messages = array();
$warnings = array();
if (isset($_POST['action']) && isset($_POST['adv_id'])) {
$action = trim($_POST['action']);
$adv_id = (int) trim($_POST['adv_id']);
if ($adv_id) {
switch ($action) {
case 'activate':
case 'suspend':
$status = ($action == 'activate') ? 1 : 0;
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$this->db->query("UPDATE #__adv SET status = '".$status."' WHERE adv_id = ".$adv_id." LIMIT 1");
$messages[] = 'Banner '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__adv WHERE adv_id = ".$adv_id." LIMIT 1");
$messages[] = 'Banner deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
break;
}
} else {
$errors[] = 'Invalid advertising! Are you sure this banner exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$action = trim($_POST['action']);
$ids = $this->get_checkbox_ids();
if ($ids) {
switch ($action) {
case 'suspend':
case 'activate':
$status = ($action == 'activate') ? 1 : 0;
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$this->db->query("UPDATE #__adv SET status = '".$status."' WHERE adv_id IN (".implode(',', $ids).")");
$messages[] = "Selected banners ".$msg."!";
break;
case 'delete':
$this->db->query("DELETE FROM #__adv WHERE adv_id IN (".implode(',', $ids).")");
$messages[] = "Selected banners deleted!";
break;
default:
$errors[] = 'Invalid action! What exactly did you select!?';
break;
}
} else {
$errors[] = 'Please select at least one banner!';
}
}
if (!isset($_POST['submit_reset'])) {
if (isset($_SESSION['search_adv_option'])) {
if (array_diff_assoc($this->option, $_SESSION['search_adv_option'])) {
$warnings[] = 'Results are selected based on your search criteria/options! If you want to see all results please reset the current search!';
$this->option = $_SESSION['search_adv_option'];
}
}
}
if (isset($_GET['u'])) {
foreach ($groups as $group) {
if ($group['adv_group_slug'] == 'user-player') {
$this->option['adv_group_id'] = $group['adv_group_id'];
$approve = true;
break;
}
}
}
$page = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$search = $this->search_adv($approve);
$total_advs = $this->db->get_field($search['sql_count'], 'total_advs');
$pagination = VPagination::get($page, $total_advs, $search['display']);
$advs = $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'adv_manage';
$tpl->meta_title = 'Admin::Advertising::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->option = $this->option;
$tpl->advs = $advs;
$tpl->pagination = $pagination;
$tpl->groups = $groups;
$tpl->approve = $approve;
$tpl->load(array('header', 'adv_manage', 'footer'));
$tpl->display();
}
private function search_adv($approve=FALSE)
{
$sql_count = 'SELECT COUNT(*) AS total_advs
FROM #__adv AS a';
$sql = 'SELECT a.*, g.adv_group_name, g.adv_group_slug, u.username
FROM #__adv AS a
LEFT JOIN #__adv_groups AS g ON (g.adv_group_id = a.adv_group_id)
LEFT JOIN #__user AS u ON (u.user_id = a.user_id)';
$sql_delim = ' WHERE';
if (isset($_GET['e'])) {
$expired = trim($_GET['e']);
if ($expired = 'yes') {
$this->option['expire'] = $expired;
}
}
if (isset($_POST['submit_search'])) {
$filter = VF::factory('filter');
$this->option['adv_name'] = $filter->get('adv_name');
$this->option['adv_group_id'] = (int) trim($_POST['adv_group_id']);
$this->option['status'] = trim($_POST['status']);
$this->option['sort'] = $filter->get('sort');
$this->option['order'] = $filter->get('order');
$this->option['display'] = $filter->get('display');
}
if ($this->option['adv_name'] != '') {
$sql .= $sql_delim." a.adv_name LIKE '%".$this->db->escape($this->option['adv_name'])."%'";
$sql_count .= $sql_delim." a.adv_name LIKE '%".$this->db->escape($this->option['adv_name'])."%'";
$sql_delim = ' AND';
}
if ($this->option['adv_group_id'] !== 0) {
$sql .= $sql_delim." a.adv_group_id = ".$this->option['adv_group_id'];
$sql_count .= $sql_delim." a.adv_group_id = ".$this->option['adv_group_id'];
$sql_delim = ' AND';
}
if ($this->option['status'] !== '') {
$sql .= $sql_delim." a.status = '".(int) $this->option['status']."'";
$sql_count .= $sql_delim." a.status = '".(int) $this->option['status']."'";
}
if ($this->option['expire'] == 'yes') {
$date = date('Y-m-d');
$sql .= $sql_delim." a.expire > ".$date;
$sql_count .= $sql_delim." a.expire > ".$date;
}
$_SESSION['search_adv_option'] = $this->option;
return array(
'sql' => $sql. ' ORDER BY '.$this->option['sort'].' '.$this->option['order'],
'sql_count' => $sql_count,
'display' => $this->option['display']
);
}
private function get_adv_groups()
{
return $this->db->get_rows('SELECT adv_group_id, adv_group_name, adv_group_slug
FROM #__adv_groups ORDER BY adv_group_name ASC');
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_adv_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_adv_', '', $key);
}
}
return $ids;
}
}