Файл: adultscript-2.0.3-pro/files/admin/modules/menu/components/link_manage.php
Строк: 134
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_menu_link_manage
{
private $db;
private $filter;
public function __construct()
{
$this->db = &VF::factory('database');
$this->filter = &VF::factory('filter');
}
public function render()
{
$errors = array();
$messages = array();
$menu_id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : NULL;
if (isset($_POST['slug']) && isset($_POST['direction']) && isset($_POST['position'])) {
$slug = trim($_POST['slug']);
$direction = trim($_POST['direction']);
$position = (int) trim($_POST['position']);
$current = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'link_') !== FALSE) {
$current[$value-1] = $key;
}
}
$links = VArray::move($current, $position-1, $direction);
foreach ($links as $pos => $link_id) {
$this->db->query("UPDATE #__menu_links SET pos = ".($pos+1)." WHERE link_id = ".(int) substr($link_id, 5)." LIMIT 1");
}
VF::factory('cache')->remove($slug.'_links');
$messages[] = 'Position changed!';
}
if (isset($_POST['action']) && isset($_POST['link_id'])) {
$action = $this->filter->get('action');
$link_id = (int) $_POST['link_id'];
switch ($action) {
case 'suspend':
case 'activate':
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$status = ($action == 'suspend') ? 0 : 1;
$this->db->query("UPDATE #__menu_links SET status = '".$status."' WHERE link_id = ".$link_id." LIMIT 1");
$messages[] = 'Link '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__menu_links WHERE link_id = ".$link_id." LIMIT 1");
break;
default:
$errors[] = 'Invalid action! What exactly did you click!?';
}
}
if (isset($_POST['submit_actions'])) {
$action = $this->filter->get('action');
$ids = $this->get_checkbox_ids();
if ($ids) {
if ($action == 'suspend' OR $action == 'activate') {
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$status = ($action == 'suspend') ? 0 : 1;
$this->db->query("UPDATE #__menu_links SET status = '".$status."' WHERE link_id IN (".implode(', ', $ids).")");
$messages[] = 'Selected menu links '.$msg.'!';
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__menu_links WHERE link_id IN (".implode(', ', $ids).")");
$messages[] = 'Selected menu links deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'Please select at least one menu link!';
}
}
$this->db->query("SELECT ml.*, m.title AS menu, m.name as slug
FROM #__menu_links AS ml, #__menu AS m
WHERE ml.menu_id = ".$menu_id."
AND m.menu_id = ml.menu_id
ORDER BY ml.pos ASC");
if ($this->db->affected_rows()) {
$links = $this->db->fetch_rows();
$slug = $links['0']['slug'];
} else {
$links = array();
$slug = '';
}
$tpl = &VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'menu';
$tpl->meta_title = 'Admin::Menu::Link::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->menu_id = $menu_id;
$tpl->links = $this->fix_pos($links);
$tpl->slug = $slug;
$tpl->load(array('header', 'menu_link_manage', 'footer'));
$tpl->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 fix_pos($links)
{
$pos = 1;
$arr = array();
foreach ($links as $link) {
$link['pos'] = $pos;
$arr[] = $link;
++$pos;
}
return $arr;
}
}
?>