Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/edit.php
Строк: 111
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_edit
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$errors = array();
$messages = array();
$id = (isset($_GET['id'])) ? (int) $_GET['id'] : 0;
$groups = array();
$adv = array();
$db->query("SELECT adv_group_id, image_ext
FROM #__adv
WHERE adv_id = ".$id."
LIMIT 1");
if ($db->affected_rows()) {
$o_group_id = (int) $db->fetch_field('adv_group_id');
$ext = $db->fetch_field('image_ext');
$groups = $db->get_rows("SELECT adv_group_id, adv_group_name
FROM #__adv_groups
ORDER BY adv_group_name ASC");
if (isset($_POST['submit_adv_edit'])) {
$filter = VF::factory('filter');
$group_id = (int) trim($_POST['adv_group_id']);
$name = $filter->get('adv_name');
$desc = $filter->get('adv_desc');
$status = (int) trim($_POST['status']);
$type = $filter->get('type');
$expire = $filter->get('expire');
$blank = (int) trim($_POST['blank']);
if ($name == '') {
$errors[] = 'Please enter the advertising banner name!';
}
if ($group_id === 0) {
$errors[] = 'Please select a advertising position!';
}
if ($type == 'text') {
$title = $filter->get('title');
$description = $filter->get('description');
$url = trim($_POST['url']);
if ($title == '') {
$errors[] = 'Please enter the advertising title (used for the a tag)!';
}
} elseif ($type == 'html') {
$code = trim($_POST['code']);
if ($code == '') {
$errors[] = 'Please enter the advertising html/javascript code!';
}
} elseif ($type == 'image') {
$url = trim($_POST['url']);
$image_type = $filter->get('image_type');
if ($image_type == 'url') {
$image_url = trim($_POST['image_url']);
if ($image_url == '') {
$errors[] = 'Image banner url cannot be left blank!';
} elseif (!VValid::url($image_url)) {
$errors[] = 'Image banner url is not a valid url address!';
}
} elseif ($image_type == 'file') {
if (isset($_FILES['image_file']['tmp_name']) && $_FILES['image_file']['tmp_name'] != '') {
if (is_uploaded_file($_FILES['image_file']['tmp_name'])) {
$file = $_FILES['image_file']['tmp_name'];
$filename = $_FILES['image_file']['name'];
$ext = VFile::ext($filename);
$valid = false;
if ($ext == 'gif') {
$valid = imagecreatefromgif($file);
} elseif ($ext == 'png') {
$valid = imagecreatefrompng($file);
} elseif ($ext == 'jpeg' OR $ext == 'jpg') {
$valid = imagecreatefromjpeg($file);
} else {
$errors[] = 'Invalid image banner file! Format not supported! Supported formats: jpg, png and gif!';
}
if (!$valid) {
$errors[] = 'Invalid image banner file! File is not a valid image (renders incorrectly)!';
}
} else {
$errors[] = 'Image banner file is not a valid uploaded file!';
}
}
} else {
$errors[] = 'Invalid image banner type selected! What exactly did you select!?';
}
} else {
$errors[] = 'Invalid banner type! What exactly did you select!?';
}
if (isset($url)) {
if ($url == '') {
$errors[] = 'Banner url cannot be left blank!';
} elseif (!VValid::url($url)) {
$errors[] = 'Banner url is not a valid url address!';
}
}
if ($expire != '0000-00-00') {
if (strlen($expire) !== 10) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} elseif (strtotime($expire) === FALSE) {
$errors[] = 'Advertising expire date invalid! Please use: yyyy-mm-dd!';
} else {
$current_timestamp = time();
$expire_timestamp = strtotime($expire);
if ($current_timestamp > $expire_timestamp) {
$errors[] = 'Advertising expire time is in the past!';
}
}
}
if (!$errors) {
$ext = (isset($ext) && $ext != '') ? $ext : '';
$title = (isset($title)) ? $title : '';
$description = (isset($description)) ? $description : '';
$url = (isset($url)) ? $url : '';
$code = (isset($code)) ? $code : '';
$image_type = (isset($image_type)) ? $image_type : 'url';
$image_url = (isset($image_url)) ? $image_url : '';
$db->query("UPDATE #__adv
SET adv_group_id = ".$group_id.",
adv_name = '".$db->escape($name)."',
adv_desc = '".$db->escape($desc)."',
type = '".$db->escape($type)."',
title = '".$db->escape($title)."',
description = '".$db->escape($description)."',
url = '".$db->escape($url)."',
code = '".$db->escape($code)."',
image_type = '".$db->escape($image_type)."',
image_url = '".$db->escape($image_url)."',
image_ext = '".$db->escape($ext)."',
expire = '".$db->escape($expire)."',
blank = '".$blank."',
status = '".$db->escape($status)."'
WHERE adv_id = ".$id."
LIMIT 1");
if ($o_group_id !== $group_id) {
$db->query("UPDATE #__adv_groups SET total_ads = total_ads+1 WHERE adv_group_id = ".$group_id." LIMIT 1");
$db->query("UPDATE #__adv_groups SET total_ads = total_ads-1 WHERE adv_group_id = ".$o_group_id." LIMIT 1");
}
if (isset($file)) {
if (!move_uploaded_file($file, MEDIA_DIR.'/banners/'.$id.'.'.$ext)) {
$errors[] = 'Failed to move uploaded file! Permissions problem!?';
}
}
if (!$errors) {
$messages[] = 'Advertising banner updated!';
}
}
}
$db->query("SELECT *
FROM #__adv
WHERE adv_id = ".$id."
LIMIT 1");
$adv = $db->fetch_assoc();
}
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'adv_manage';
$tpl->meta_title = 'Admin::Advertising::Edit';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->adv = $adv;
$tpl->groups = $groups;
$tpl->load(array('header', 'adv_edit', 'footer'));
$tpl->display();
}
}