Файл: adultscript-2.0.3-pro/files/admin/modules/link/components/manage.php
Строк: 161
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_link_manage
{
private $db;
private $cache;
private $option;
public function __construct()
{
$this->db = VF::factory('database');
$this->cache = VF::factory('cache');
}
public function render()
{
$errors = array();
$messages = array();
if (isset($_POST['action']) && isset($_POST['link_id'])) {
$action = trim($_POST['action']);
$link_id = (int) trim($_POST['link_id']);
if ($link_id) {
switch ($action) {
case 'activate':
case 'suspend':
$msg = ($action == 'activate') ? 'activated' : 'suspended';
$status = ($action == 'activate') ? 1 : 0;
$this->db->query("UPDATE #__link SET status = '".$status."' WHERE link_id = ".$link_id." LIMIT 1");
$this->cache->remove('link_'.$this->get_link_widget($link_id));
$messages[] = 'Link '.$msg;
break;
case 'delete':
$this->cache->remove('link_'.$this->get_link_widget($link_id));
$this->db->query("DELETE FROM #__link WHERE link_id = ".$link_id." LIMIT 1");
$messages[] = 'Link deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid link id! Are you sure this link 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 #__link SET status = '".$status."' WHERE link_id IN (".implode(',', $ids).")");
$this->cache->cache->remove('link_left');
$this->cache->cache->remove('link_right');
$this->cache->cache->remove('link_footer');
$messages[] = 'Selected links '.$msg;
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__link WHERE link_id IN (".implode(',', $ids).")");
$this->cache->cache->remove('link_left');
$this->cache->cache->remove('link_right');
$this->cache->cache->remove('link_footer');
$messages[] = 'Selected links deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'You must select at least one link!';
}
}
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$this->option = array(
'title' => '', 'type' => '', 'status' => '',
'sort' => 'link_id', 'order' => 'DESC', 'display' => 20
);
if (isset($_SESSION['search_link_option'])) {
$this->option = $_SESSION['search_link_option'];
}
if (isset($_GET['s']) && $_GET['s'] == '0') {
$this->option['status'] = '0';
}
$search = $this->search_links();
$total_links = $this->db->get_field($search['sql_count'], 'total_links');
$pagination = VPagination::get($page, $total_links, $search['display']);
$links = $this->db->get_rows($search['sql']." LIMIT ".$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'link';
$tpl->submenu = 'link_manage';
$tpl->meta_title = 'Admin::Link::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->links = $links;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'link_manage', 'footer'));
$tpl->display();
}
private function search_links()
{
$sql = 'SELECT * FROM #__link';
$sql_count = 'SELECT COUNT(*) AS total_links FROM #__link';
$sql_add = ' WHERE';
if (isset($_POST['submit_search'])) {
$filter = VF::factory('filter');
$this->option['title'] = $filter->get('title');
$this->option['type'] = $filter->get('type');
$this->option['status'] = $filter->get('status');
$this->option['sort'] = $filter->get('sort');
$this->option['order'] = ($_POST['order'] == 'DESC') ? 'DESC' : 'ASC';
$this->option['display'] = (int) trim($_POST['display']);
$_SESSION['search_link_option'] = $this->option;
}
if ($this->option['title'] != '') {
$sql .= $sql_add.' title LIKE '%'.$this->db->escape($this->option['title']).'%'';
$sql_count .= $sql_add.' title LIKE '%'.$this->db->escape($this->option['title']).'%'';
$sql_add = ' AND';
}
if ($this->option['type'] != '') {
$sql .= $sql_add.' type = ''.$this->db->escape($this->option['type']).''';
$sql_count .= $sql_add.' type = ''.$this->db->escape($this->option['type']).''';
$sql_add = ' AND';
}
if ($this->option['status'] != '') {
$sql .= $sql_add.' status = ''.(int) $this->option['status'].''';
$sql_count .= $sql_add.' status = ''.(int) $this->option['status'].''';
$sql_add = ' AND';
}
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_link_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_link_', '', $key);
}
}
return $ids;
}
private function get_link_widget($link_id)
{
return $this->db->get_field("SELECT widget FROM #__link WHERE link_id = ".$link_id." LIMIT 1", 'widget');
}
}