Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/group.php
Строк: 65
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_group
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
$errors = array();
$messages = array();
if (isset($_POST['action']) && isset($_POST['adv_group_id'])) {
$action = trim($_POST['action']);
$adv_group_id = (int) trim($_POST['adv_group_id']);
if ($adv_group_id) {
switch ($action) {
case 'activate':
case 'suspend':
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$db->query("UPDATE #__adv_groups SET status = '".$status."' WHERE adv_group_id = ".$adv_group_id." LIMIT 1");
$messages[] = 'Advertising group '.$msg.'!';
break;
case 'delete':
$db->query("DELETE FROM #__adv_groups WHERE adv_group_id = ".$adv_group_id." LIMIT 1");
$messages[] = 'Advertising group deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid advertising group id! Are you sure this advertising group 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;
$db->query("UPDATE #__adv_groups SET status = '".$status."' WHERE adv_group_id IN (".implode(',', $ids).")");
$messages[] = 'Selected advertising groups '.$msg;
} elseif ($action == 'delete') {
$db->query("DELETE FROM #__adv_groups WHERE adv_group_id IN (".implode(',', $ids).")");
$messages[] = 'Selected advertising groups deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'You must select at least one advertising group!';
}
}
$sql_count = 'SELECT COUNT(*) AS total_groups FROM #__adv_groups';
$total_groups = $db->get_field($sql_count, 'total_groups');
$sql = 'SELECT * FROM #__adv_groups ORDER BY adv_group_slug ASC';
$pagination = VPagination::get($page, $total_groups, 20);
$groups = $db->get_rows($sql.' LIMIT '.$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'adv_group';
$tpl->meta_title = 'Admin::Advertising::Group::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->groups = $groups;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'adv_group', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_group_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_group_', '', $key);
}
}
return $ids;
}
}
?>