Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/sponsor.php
Строк: 153
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_sponsor
{
private $db;
private $option;
public function __construct()
{
$this->db = VF::factory('database');
$this->option = array(
'sponsor_name' => '',
'status' => '',
'sort' => 's.sponsor_id',
'order' => 'DESC',
'display' => 30
);
}
public function render()
{
$this->db = VF::factory('database');
$errors = array();
$messages = array();
if (isset($_POST['action']) && isset($_POST['sponsor_id'])) {
$action = trim($_POST['action']);
$sponsor_id = (int) trim($_POST['sponsor_id']);
if ($sponsor_id) {
if ($action == 'activate' OR $action == 'suspend') {
$status = ($action == 'activate') ? 1 : 0;
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$this->db->query("UPDATE #__video_sponsors SET status = '".$status."' WHERE sponsor_id = ".$sponsor_id." LIMIT 1");
$messages[] = 'Sponsor '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__video_sponsors WHERE sponsor_id = ".$sponsor_id." LIMIT 1");
$messages[] = 'Sponsor deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid sponsor id! Are you sure this sponsor exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$action = trim($_POST['action']);
$ids = $this->get_checkbox_ids();
if ($ids) {
if ($action == 'activate' OR $action == 'suspend') {
$status = ($action == 'activate') ? 1 : 0;
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$this->db->query("UPDATE #__video_sponsors SET status = '".$status."' WHERE sponsor_id IN (".implode(',', array_values($ids)).")");
$messages[] = 'Selected sponsors '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__video_sponsors WHERE sponsor_id IN (".implode(',', array_values($ids)).")");
$messages[] = 'Selected sponsors deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'Please check at least one sponsor!';
}
}
if (!isset($_POST['submit_reset'])) {
if (isset($_SESSION['search_sponsor_option'])) {
$this->option = $_SESSION['search_sponsor_option'];
}
}
$page = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$search = $this->search_sponsors();
$total_sponsors = $this->db->get_field($search['sql_count'], 'total_sponsors');
$pagination = VPagination::get($page, $total_sponsors, $search['display']);
$sponsors = $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'sponsor';
$tpl->extramenu = 'sponsor_manage';
$tpl->meta_title = 'Admin::Sponsor::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->option = $this->option;
$tpl->sponsors = $sponsors;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'adv_sponsor', 'footer'));
$tpl->display();
}
private function search_sponsors()
{
$sql = 'SELECT s.*, a.adv_id
FROM #__video_sponsors AS s
LEFT JOIN #__adv AS a ON (a.adv_id = s.adv_id)';
$sql_count = 'SELECT COUNT(*) AS total_sponsors FROM #__video_sponsors AS s';
$sql_delim = ' WHERE';
if (isset($_POST['submit_search'])) {
$filter = VF::factory('filter');
$this->option['sponsor_name'] = $filter->get('sponsor_name');
$this->option['status'] = trim($_POST['status']);
$this->option['order'] = $filter->get('order');
$this->option['sort'] = $filter->get('sort');
$this->option['display'] = (int) trim($_POST['display']);
}
if ($this->option['sponsor_name'] != '') {
$sql .= $sql_delim." s.sponsor_name LIKE '%".$this->db->escape($this->option['sponsor_name'])."%'";
$sql_count .= $sql_delim." s.sponsor_name LIKE '%".$this->db->escape($this->option['sponsor_name'])."%'";
$sql_delim = ' AND';
}
if ($this->option['status'] != '') {
$sql .= $sql_delim." s.status = '".(int) $this->option['status']."'";
$sql_count .= $sql_delim." s.status = '".(int) $this->option['status']."'";
}
$_SESSION['search_sponsor_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_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_sponsor_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_sponsor_', '', $key);
}
}
return $ids;
}
}