Файл: adultscript-2.0.3-pro/files/admin/modules/player/components/manage.php
Строк: 74
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_player_manage
{
private $db;
private $cache;
private $filter;
public function __construct()
{
$this->db = VF::factory('database');
$this->cache = VF::factory('cache');
$this->filter = VF::factory('filter');
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
if (isset($_POST['action']) && isset($_POST['player_id'])) {
$action = $this->filter->get('action');
$id = $this->filter->get('player_id', 'INT');
$this->db->query("SELECT name FROM #__player WHERE player_id = ".$id." LIMIT 1");
if ($this->db->affected_rows()) {
$name = $this->db->fetch_field('name');
if ($action == 'suspend' OR $action == 'activate') {
$status = ($action == 'suspend') ? 0 : 1;
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$this->db->query("UPDATE #__player SET status = '".$status."' WHERE player_id = ".$id." LIMIT 1");
$this->cache->remove('player_'.$name);
$messages[] = 'Please profile '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__player WHERE player_id = ".$id." LIMIT 1");
$this->cache->remove('player_'.$name);
$messages[] = 'Please profile deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid player profile id! Are you sure this profile exists!?';
}
}
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';
foreach ($ids as $id) {
$this->db->query("SELECT name FROM #__player WHERE player_id = ".$id." LIMIT 1");
if ($this->db->affected_rows()) {
$this->cache->remove('player_'.$this->db->fetch_field('name'));
$this->db->query("UPDATE #__player SET status = ".$status." WHERE player_id = ".$id." LIMIT 1");
}
}
$messages[] = 'Selected profiles '.$msg.'!';
} elseif ($action == 'delete') {
foreach ($ids as $id) {
$this->db->query("SELECT name FROM #__player WHERE player_id = ".$id." LIMIT 1");
if ($this->db->affected_rows()) {
$this->cache->remove('player_'.$this->db->fetch_field('name'));
$this->db->query("DELETE FROM #__player WHERE player_id = ".$id." LIMIT 1");
}
}
$messages[] = 'Selected profiles deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
}
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
$profiles_total = $this->db->get_field("SELECT COUNT(*) AS total_profiles FROM #__player WHERE type = 0", 'total_profiles');
$pagination = VPagination::get($page, $profiles_total, 10);
$profiles = $this->db->get_rows("SELECT * FROM #__player WHERE type = 0 ORDER BY player_id ASC LIMIT ".$pagination['limit']);
$tpl = &VF::factory('template');
$tpl->menu = 'video';
$tpl->submenu = 'player_manage';
$tpl->meta_title = 'Admin::Video::Player::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->profiles = $profiles;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'player_manage', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_player_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_player_', '', $key);
}
}
return $ids;
}
}
?>