Файл: adultscript-2.0.3-pro/files/admin/modules/link/components/edit.php
Строк: 84
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_link_edit
{
private $db;
private $cache;
public function __construct()
{
$this->db = VF::factory('database');
$this->cache = VF::factory('cache');
}
public function render()
{
$errors = array();
$messages = array();
$link = array();
$id = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
$this->db->query("SELECT widget FROM #__link WHERE link_id = ".$id." LIMIT 1");
if ($this->db->affected_rows()) {
$o_widget = $this->db->fetch_field('widget');
if (isset($_POST['submit_edit_link'])) {
$filter = VF::factory('filter');
$title = $filter->get('title');
$desc = $filter->get('description');
$url = trim($_POST['url']);
$type = $filter->get('type');
$widget = $filter->get('widget');
$target = $filter->get('target');
$status = (int) trim($_POST['status']);
$name = $filter->get('name');
$email = $filter->get('email');
$linkback = $filter->get('linkback');
$hardlink = (int) trim($_POST['hardlink']);
if ($title == '') {
$errors[] = 'Please enter link title!';
} elseif (!VValid::length($title, 1, 255)) {
$errors[] = 'Link title can contain maximum 255 characters!';
}
if ($desc != '') {
if (!VValid::length($desc, 1, 255)) {
$errors[] = 'Link description can contain maximum 255 characters!';
}
}
if ($url == '') {
$errors[] = 'Please enter link url!';
} elseif (!VValid::url($url)) {
$errors[] = 'Link url is not a valid url address!';
} elseif (!VValid::length($url, 1, 255)) {
$errors[] = 'Link url can contain maximum 255 characters!';
}
if ($type == '') {
$errors[] = 'Please select link type!';
}
if ($widget == '') {
$errors[] = 'Please select a widget for this link!';
}
$link['name'] = $name;
$link['email'] = $email;
$link['linkback'] = $linkback;
$link['target'] = $target;
$link['status'] = $status;
if (!$errors) {
$this->db->query("UPDATE #__link
SET title = '".$this->db->escape($title)."',
description = '".$this->db->escape($desc)."',
url = '".$this->db->escape($url)."',
name = '".$this->db->escape($name)."',
email = '".$this->db->escape($email)."',
linkback = '".$this->db->escape($linkback)."',
type = '".$this->db->escape($type)."',
widget = '".$this->db->escape($widget)."',
target = '".$this->db->escape($target)."',
hardlink = '".$hardlink."',
status = '".$status."'
WHERE link_id = ".$id."
LIMIT 1");
if ($widget != $o_widget) {
$this->cache->remove('link_'.$o_widget);
}
$this->cache->remove('link_'.$widget);
$messages[] = 'Link updated!';
}
}
$link = $this->db->get_assoc("SELECT * FROM #__link WHERE link_id = ".$id." LIMIT 1");
}
$tpl = VF::factory('template');
$tpl->menu = 'link';
$tpl->submenu = 'link_manage';
$tpl->meta_title = 'Admin::Link::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->link = $link;
$tpl->load(array('header', 'link_edit', 'footer'));
$tpl->display();
}
}