Файл: adultscript-2.0.3-pro/files/admin/modules/menu/components/manage.php
Строк: 87
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_menu_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();
$categories = array();
if (isset($_POST['action']) && isset($_POST['menu_id'])) {
$menu_id = (int) $_POST['menu_id'];
$action = trim($_POST['action']);
switch ($action) {
case 'activate':
case 'suspend':
$msg = ($action == 'suspend') ? 'suspended' : 'activate';
$status = ($action == 'suspend') ? 0 : 1;
$this->db->query("UPDATE #__menu SET status = '".$status."' WHERE menu_id = ".$menu_id." LIMIT 1");
$messages[] = 'Menu '.$msg;
break;
case 'delete':
$this->db->query("DELETE FROM #__menu WHERE menu_id = ".$menu_id." LIMIT 1");
$this->db->query("DELETE FROM #__menu_links WHERE menu_id = ".$menu_id);
$messages[] = 'Menu deleted!';
break;
default:
$errors[] = 'Invalid action! Allowed actions: activate, suspend and delete!';
}
}
if (isset($_POST['submit_actions'])) {
$action = $this->filter->get('action');
$ids = $this->get_checkbox_ids();
if ($action == 'suspend' OR $action == 'activate') {
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$status = ($action == 'suspend') ? 0 : 1;
$this->db->query("UPDATE #__menu SET status = '".$status."' WHERE menu_id IN (".implode(', ', $ids).")");
$messages[] = 'Selected menus '.$msg;
} elseif ($action == 'delete') {
$this->db->query("DELETE FROM #__menu WHERE menu_id IN (".implode(', ', $ids).")");
$this->db->query("DELETE FROM #__menu_links WHERE menu_id IN (".implode(', ', $ids).")");
$messages[] = 'Selected menus deleted!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
}
$this->db->query("SELECT * FROM #__menu ORDER BY title ASC");
if ($this->db->affected_rows()) {
$menus = $this->db->fetch_rows();
} else {
$menus = array();
}
$tpl = &VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'menu';
$tpl->meta_title = 'Admin::Menu::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->menus = $menus;
$tpl->load(array('header', 'menu_manage', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_menu_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_menu_', '', $key);
}
}
return $ids;
}
}
?>