Файл: adultscript-2.0.3-pro/files/admin/modules/user/components/manage.php
Строк: 216
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_user_manage extends VModule_Admin_user
{
private $tpl;
private $filter;
private $option;
private $country;
public function __construct()
{
parent::__construct();
$this->tpl = VF::factory('template');
$this->filter = VF::factory('filter');
$this->countries = VCountry::get();
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
if (isset($_POST['action']) && isset($_POST['user_id'])) {
$action = trim($_POST['action']);
$user_id = (isset($_POST['user_id'])) ? (int) $_POST['user_id'] : NULL;
if ($user_id) {
switch ($action) {
case 'suspend':
case 'activate':
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$this->db->query("UPDATE #__user SET status = '".$status."' WHERE user_id = ".$user_id." LIMIT 1");
$messages[] = 'User '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__user WHERE user_id = ".$user_id." LIMIT 1");
$messages[] = 'User deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid user id! Are you sure this user exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$ids = $this->get_checkbox_ids();
$action = trim($_POST['action']);
if ($ids) {
if ($action == 'activate' OR
$action == 'suspend') {
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$this->db->query("UPDATE #__user SET status = ".$status." WHERE user_id IN (".implode(',', $ids).")");
$messages[] = 'Selected users '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__user WHERE user_id IN (".implode(',', $ids).")");
$messages[] = 'Selected users deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'You must select at least one user!';
}
}
$this->option = array(
'username' => '', 'email' => '', 'name' => '',
'gender' => '', 'country' => '', 'ip' => '',
'status' => '', 'verified' => '', 'group' => '',
'sort' => 'u.user_id', 'order' => 'DESC', 'display' => 10
);
if (!isset($_POST['submit_reset'])) {
if (isset($_SESSION['search_user_option'])) {
if (array_diff_assoc($this->option, $_SESSION['search_user_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_user_option'];
}
}
}
if (isset($GET['s'])) {
$this->option['status'] = $this->filter->get('s', 'STRING', 'GET');
}
if (isset($_GET['v'])) {
$this->option['verified'] = $this->filter->get('v', 'STRING', 'GET');
}
if (isset($_GET['g'])) {
$this->option['group'] = (int) trim($_GET['g']);
}
$page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
$groups = $this->get_groups();
$search = $this->search_users();
$users_total = $this->db->get_field($search['sql_count'], 'total_users');
$pagination = VPagination::get($page, $users_total, $search['display']);
$users = $this->db->get_rows($search['sql']." LIMIT ".$pagination['limit']);
$this->tpl->menu = 'user';
$this->tpl->submenu = 'user_manage';
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->warnings = $warnings;
$this->tpl->meta_title = 'Admin::User::Manage';
$this->tpl->groups = $groups;
$this->tpl->countries = $this->countries;
$this->tpl->users = $users;
$this->tpl->pagination = $pagination;
$this->tpl->option = $this->option;
$this->tpl->load(array('header', 'user_manage', 'footer'));
$this->tpl->display();
}
private function get_groups()
{
$this->db->query("SELECT group_id, name FROM #__user_groups ORDER BY group_id ASC");
if ($this->db->affected_rows()) {
return $this->db->fetch_rows();
}
die('Failed to load user groups table!');
}
private function search_users()
{
$sql = 'SELECT u.*, g.name AS group_name, ua.*, p.start_date, p.end_date, p.credit, p.status as pstatus
FROM #__user AS u
LEFT JOIN #__user_groups AS g ON (g.group_id = u.group_id)
LEFT JOIN #__user_premium AS p ON (p.user_id = u.user_id)
LEFT JOIN #__user_activity AS ua ON (ua.user_id = u.user_id)';
$sql_count = 'SELECT COUNT(*) AS total_users FROM #__user AS u';
$sql_add = '';
$sql_delim = ' WHERE';
if (isset($_POST['submit_search'])) {
$this->option['username'] = $this->filter->get('username');
$this->option['email'] = $this->filter->get('email');
$this->option['name'] = $this->filter->get('name');
$this->option['gender'] = $this->filter->get('gender');
$this->option['ip'] = $this->filter->get('ip');
$this->option['country'] = $this->filter->get('country');
$this->option['group'] = $this->filter->get('group');
$this->option['verified'] = $this->filter->get('verified');
$this->option['status'] = $this->filter->get('status');
$this->option['sort'] = $this->filter->get('sort');
$this->option['order'] = $this->filter->get('order');
$this->option['display'] = (int) trim($_POST['display']);
}
if ($this->option['username'] != '') {
$sql .= $sql_delim." u.username LIKE '".$this->db->escape($this->option['username'])."%'";
$sql_count .= $sql_delim." u.username LIKE '".$this->db->escape($this->option['username'])."%'";
$sql_delim = ' AND';
}
if ($this->option['email'] != '' && VValid::email($this->option['email'])) {
$sql .= $sql_delim." u.email = '".$this->db->escape($this->option['email'])."'";
$sql_count .= $sql_delim." u.email = '".$this->db->escape($this->option['email'])."'";
$sql_delim = ' AND';
}
if ($this->option['name'] != '') {
$sql .= $sql_delim." u.name LIKE '".$this->db->escape($this->option['name'])."%'";
$sql_count .= $sql_delim." u.name LIKE '".$this->db->escape($this->option['name'])."%'";
$sql_delim = ' AND';
}
if ($this->option['gender'] != '') {
$sql .= $sql_delim." u.gender = '".$this->db->escape($this->option['gender'])."'";
$sql_count .= $sql_delim." u.gender = '".$this->db->escape($this->option['gender'])."'";
$sql_delim = ' AND';
}
if ($this->option['ip'] != '' && VValid::ip($this->option['ip'])) {
$ip = ip2long($this->option['ip']);
$sql .= $sql_delim." u.login_ip = ".$ip;
$sql_count .= $sql_delim." u.login_ip = ".$ip;
$sql_delim = ' AND';
}
if ($this->option['country'] != '' && isset($this->countries[$this->option['country']])) {
$this->option['country'] = $this->countries[$this->option['country']];
$sql .= $sql_delim." u.country = '".$this->db->escape($this->option['country'])."'";
$sql_count .= $sql_delim." u.country = '".$this->db->escape($this->option['country'])."'";
$sql_delim = ' AND';
}
if ($this->option['group'] != '') {
$sql .= $sql_delim." u.group_id = ".(int) $this->option['group'];
$sql_count .= $sql_delim." u.group_id = ".(int) $this->option['group'];
$sql_delim = ' AND';
}
if ($this->option['verified'] != '') {
$sql .= $sql_delim." u.verified = '".(int) $this->option['verified']."'";
$sql_count .= $sql_delim." u.verified = '".(int) $this->option['verified']."'";
$sql_delim = ' AND';
}
if ($this->option['status'] != '') {
$sql .= $sql_delim." u.status = '".(int) $this->option['status']."'";
$sql_count .= $sql_delim." u.status = '".(int) $this->option['status']."'";
$sql_delim = ' AND';
}
$_SESSION['search_user_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_user_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_user_', '', $key);
}
}
return $ids;
}
private function update_user_status($user_id, $status)
{
$this->db->query("UPDATE #__user SET status = ".$status." WHERE user_id = ".$user_id." LIMIT 1");
}
// private function delete_user($user_id)
// {
// $this->db->query("DELETE FROM #__user WHERE user_id = ".$user_id." LIMIT 1");
// // need to implement some other stuff here...
// }
}
?>