Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/sponsor_add.php
Строк: 147
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_adv_sponsor_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$db->query("SELECT adv_group_id
FROM #__adv_groups
WHERE adv_group_slug = 'video-player'
LIMIT 1");
$errors = array();
$messages = array();
$group = (int) $db->fetch_field('adv_group_id');
$sponsor = array('sponsor_name' => '', 'adv_type' => 'assign', 'adv_id' => 0);
$adv = array(
'adv_name' => '', 'adv_desc' => '', 'type' => 'image',
'title' => '', 'description' => '', 'url' => '', 'code' => '',
'image_type' => 'url', 'image_url' => '', 'image_ext' => '',
'status' => 1
);
$advs = $db->get_rows("SELECT adv_id, adv_name
FROM #__adv
WHERE adv_group_id = ".$group);
if (isset($_POST['submit_sponsor_add'])) {
$filter = VF::factory('filter');
$sponsor_name = $filter->get('sponsor_name');
$adv_type = $filter->get('adv_type');
if ($sponsor_name == '') {
$errors[] = 'Sponsor name field cannot be left blank!';
} else {
$sponsor['sponsor_name'] = $sponsor_name;
}
if ($adv_type == 'assign') {
$adv_id = (int) trim($_POST['adv_id']);
if ($adv_id === 0) {
$errors[] = 'Please select a advertising banner for this sponsor!';
} else {
$sponsor['adv_id'] = $adv_id;
}
} elseif ($adv_type == 'create') {
$name = $filter->get('adv_name');
$desc = $filter->get('adv_desc');
$status = (int) trim($_POST['status']);
$type = $filter->get('type');
if ($name == '') {
$errors[] = 'Please enter the advertising banner name!';
} else {
$adv['adv_name'] = $name;
}
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)!';
} else {
$adv['title'] = $title;
}
if ($description != '') {
$adv['description'] = $description;
}
} elseif ($type == 'html') {
$code = trim($_POST['code']);
if ($code == '') {
$errors[] = 'Please enter the advertising html/javascript code!';
} else {
$adv['code'] = $code;
}
} elseif ($type == 'image') {
$url = trim($_POST['url']);
$image_type = $filter->get('image_type');
if ($image_type == 'url') {
$image_url = $filter->get('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!';
} else {
$adv['image_url'] = $image_url;
}
} elseif ($image_type == 'file') {
if ($_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[] = 'Please upload a image banner 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!';
} else {
$adv['url'] = $url;
}
}
$adv['status'] = $status;
$adv['type'] = $type;
$adv['image_type'] = (isset($image_type)) ? $image_type : 'url';
} else {
$errors[] = 'Invalid sponsor advertising method selected! What exactly did you select!?';
}
$sponsor['adv_type'] = $adv_type;
if (!$errors) {
if ($adv_type == 'create') {
$ext = (isset($ext)) ? $ext : '';
$db->query("INSERT INTO #__adv
SET adv_group_id = ".$group.",
adv_name = '".$db->escape($name)."',
adv_desc = '".$db->escape($desc)."',
type = '".$db->escape($type)."',
title = '".$db->escape($adv['title'])."',
description = '".$db->escape($adv['description'])."',
url = '".$db->escape($adv['url'])."',
code = '".$db->escape($adv['code'])."',
image_type = '".$db->escape($adv['image_type'])."',
image_url = '".$db->escape($adv['image_url'])."',
image_ext = '".$db->escape($ext)."',
status = '".$db->escape($status)."'");
if ($db->affected_rows()) {
$adv_id = $db->get_last_insert_id('#__adv');
$db->query("UPDATE #__adv_groups SET total_ads = total_ads+1 WHERE adv_group_id = ".$group." LIMIT 1");
if (isset($file)) {
if (!move_uploaded_file($file, MEDIA_DIR.'/banners/'.$adv_id.'.'.$ext)) {
$errors[] = 'Failed to move uploaded file! Permissions problem!?';
}
}
} else {
$errors[] = 'Failed to add avertising banner! Application error!?';
}
}
if (!$errors) {
$db->query("INSERT INTO #__video_sponsors
SET sponsor_name = '".$db->escape($sponsor_name)."',
adv_id = ".$adv_id);
if ($db->affected_rows()) {
$messages[] = 'Sponsor added (banner assigned)!';
} else {
$errors[] = 'Failed to add sponsor! Application error!?';
}
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'adv';
$tpl->submenu = 'sponsor_add';
$tpl->meta_title = 'Admin::Advertising::Sponsor::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->group = $group;
$tpl->adv = $adv;
$tpl->advs = $advs;
$tpl->sponsor = $sponsor;
$tpl->load(array('header', 'adv_sponsor_add', 'footer'));
$tpl->display();
}
}