Файл: adultscript-2.0.3-pro/files/admin/modules/email/components/add.php
Строк: 55
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_email_add
{
public function __construct()
{
}
public function render()
{
$db = VF::factory('database');
$cfg = VF::cfg('core.config');
$email = array(
'name' => '', 'description' => '', 'subject' => '', 'message' => '', 'status' => '1'
);
$errors = array();
$messages = array();
if (isset($_POST['submit_add_email'])) {
$filter = &VF::factory('filter');
$name = $filter->get('name');
$description = $filter->get('description');
$subject = trim($_POST['subject']);
$message = str_replace(array("rn", "r"), "n", trim($_POST['message']));
$status = $filter->get('status', 'INTEGER');
if ($name == '') {
$errors[] = 'Please enter the email name!';
} elseif (!preg_match('/^[a-zA-Z0-9_-]*$/', $name)) {
$errors[] = 'Email name can contain only letters, dashes and underscores!';
} elseif (!VValid::length($name, 1, 100)) {
$errors[] = 'Email name can contain maximum 100 characters!';
} else {
$db->query("SELECT email_id
FROM #__email
WHERE name = '".$db->escape($name)."'
LIMIT 1");
if ($db->affected_rows()) {
$errors[] = 'Email name is already used for another email!';
} else {
$email['name'] = $name;
}
}
if ($subject == '') {
$errors[] = 'Please enter email subject!';
} else {
$email['subject'] = $subject;
}
if ($message == '') {
$errors[] = 'Please enter email message!';
} else {
$email['message'] = $message;
}
$email['description'] = $description;
if (!$errors) {
$db->query("INSERT INTO #__email
SET name = '".$db->escape($name)."',
description = '".$db->escape($description)."',
subject = '".$db->escape($subject)."',
message = '".$db->escape($message)."',
status = '".$status."'");
if ($db->affected_rows()) {
VF::factory('cache')->remove('emails');
$messages[] = 'Email added!';
} else {
$errors[] = 'Failed to add email!';
}
}
}
$tpl = VF::factory('template');
$tpl->menu = 'main';
$tpl->submenu = 'email_add';
$tpl->meta_title = 'Admin::Email::Add';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->email = $email;
$tpl->load(array('header', 'email_add', 'footer'));
$tpl->display();
}
}
?>