Файл: adultscript-2.0.3-pro/files/admin/modules/menu/components/link_edit.php
Строк: 144
<?php
defined('_VALID') or die('Restricted Acces!');
class VComponent_Admin_menu_link_edit
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$menus = $db->get_rows("SELECT menu_id, title FROM #__menu ORDER BY menu_id ASC");
$item = array('link_id' => 0, 'menu_id' => '', 'name' => '', 'title' => '', 'link' => '',
'type' => 'internal', 'target' => 'none', 'status' => '1', 'current' => '');
$id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
$db->query("SELECT link_id FROM #__menu_links WHERE link_id = ".$id." LIMIT 1");
if ($db->affected_rows()) {
if (isset($_POST['submit_edit_menu'])) {
$filter = VF::factory('filter');
$menu_id = $filter->get('menu_id', 'INTEGER');
$name = $filter->get('name');
$title = $filter->get('title');
$link = trim($_POST['link']);
$type = $filter->get('type');
$target = $filter->get('target');
$lang = $filter->get('lang');
$current = $filter->get('current');
$status = $filter->get('status', 'INTEGER');
if ($menu_id === 0) {
$errors[] = 'Please select a menu for this link!';
}
if ($name == '') {
$errors[] = 'Menu link name field cannot be left blank!';
} elseif (!VValid::length($name, 1, 99)) {
$errors[] = 'Menu link name can contain maximum 99 characters!';
}
if ($title != '') {
if (!VValid::length($title, 1, 255)) {
$errors[] = 'Menu title can contain maximum 255 characters!';
}
}
if ($link == '') {
$errors[] = 'Menu link url cannot be left blank!';
} elseif (!VValid::length($link, 1, 255)) {
$errors[] = 'Menu link url can contain maximum 255 characters!';
} else {
if ($type != 'int') {
if (!VValid::url($link)) {
$errors[] = 'Menu link is not a valid url address!';
}
}
}
$item['type'] = ($type == 'int') ? 'int' : 'ext';
if (!in_array($target, array('none', 'self', 'blank'))) {
$errors[] = 'Menu link target invalid! Allowed targets: none, self and blank!';
} else {
$item['target'] = $target;
}
if ($current != '') {
if (!VValid::length($current, 0, 99)) {
$errors[] = 'Menu link current identifier can contain maximum 99 characters!';
} else {
$item['current'] = $current;
}
}
if (!$errors) {
$db->query("UPDATE #__menu_links
SET menu_id = ".$menu_id.",
name = '".$db->escape($name)."',
title = '".$db->escape($title)."',
link = '".$db->escape($link)."',
type = '".$db->escape($item['type'])."',
target = '".$db->escape($target)."',
lang = '".$db->escape($lang)."',
current = '".$db->escape($current)."',
status = '".$status."'
WHERE link_id = ".$id."
LIMIT 1");
$db->query("SELECT name FROM #__menu WHERE menu_id = ".$menu_id." LIMIT 1");
VF::factory('cache')->remove($db->fetch_field('name').'_links');
$messages[] = 'Menu link updated!';
}
}
$db->query("SELECT * FROM #__menu_links WHERE link_id = ".$id." LIMIT 1");
$item = $db->fetch_assoc();
}
$tpl = &VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'menu';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->meta_title = 'Admin::Menu::Link::Edit';
$tpl->menus = $menus;
$tpl->item = $item;
$tpl->load(array('header', 'menu_link_edit', 'footer'));
$tpl->display();
}
}