Файл: adultscript-2.0.3-pro/files/admin/modules/channel/components/network_manage.php
Строк: 150
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_channel_network_manage extends VModule_Admin_channel
{
private $tpl;
private $filter;
private $option;
public function __construct()
{
parent::__construct();
$this->tpl = VF::factory('template');
$this->filter = VF::factory('filter');
}
public function render()
{
$nmodel = VModel::load('network', 'channel', true);
$errors = array();
$messages = array();
$warnings = array();
if (isset($_POST['action']) && isset($_POST['network_id'])) {
$action = trim($_POST['action']);
$network_id = (isset($_POST['network_id'])) ? (int) $_POST['network_id'] : NULL;
if ($network_id) {
switch ($action) {
case 'delete':
$nmodel->delete($network_id);
$messages[] = 'Network deleted!';
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid network id! Are you sure this network exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$ids = (isset($_POST['checked'])) ? array_keys($_POST['checked']) : array();
$action = trim($_POST['action']);
if ($ids) {
if ($action == 'delete') {
$nmodel->delete($ids);
$messages[] = 'Selected networkds deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'You must select at least one network!';
}
}
$this->option = array(
'name' => '', 'network_id' => 0, 'username' => '',
'sort' => 'n.network_id', 'order' => 'DESC', 'display' => 10
);
if (!isset($_POST['submit_reset'])) {
if (isset($_SESSION['search_network_option'])) {
if (array_diff_assoc($this->option, $_SESSION['search_network_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_network_option'];
}
}
}
$page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
$params = $this->getParams();
$networks_total = $nmodel->count($params);
$pagination = VPagination::get($page, $networks_total, $params['display']);
$this->tpl->menu = 'channel';
$this->tpl->submenu = 'channel_network';
$this->tpl->errors = $errors;
$this->tpl->messages = $messages;
$this->tpl->warnings = $warnings;
$this->tpl->meta_title = 'Admin::Networks::Manage';
$this->tpl->option = $this->option;
$this->tpl->pagination = $pagination;
$this->tpl->networks = $nmodel->networks(array(), $params, $pagination['limit']);
$this->tpl->load(array('header', 'channel_network_manage', 'footer'));
$this->tpl->display();
}
private function getParams()
{
$params = array();
if (isset($_POST['submit_search'])) {
$this->option['name'] = $this->filter->get('name');
$this->option['network_id'] = (int) trim($_POST['network_id']);
$this->option['user_id'] = (int) trim($_POST['user_id']);
$this->option['sort'] = $this->filter->get('sort');
$this->option['order'] = $this->filter->get('order');
$this->option['display'] = (int) trim($_POST['display']);
}
if ($this->option['name'] != '') {
$params[] = "n.name LIKE '".$this->db->escape($this->option['name'])."%'";
}
if ($this->option['network_id'] > 0) {
$params[] = "n.network_id = ".$this->option['network_id'];
}
if ($this->option['username'] != '') {
if ($user_id = VModel::load('user', 'user', true)->exists('username', $this->option['username'])) {
$params[] = "n.user_id = ".$this->option['user_id'];
}
}
return array(
'where' => ($params) ? implode('AND ', $params) : '',
'sort' => $this->option['sort'],
'order' => $this->option['order'],
'display' => $this->option['display']
);
}
}
?>