Файл: adultscript-2.0.3-pro/files/admin/modules/email/components/edit.php
Строк: 58
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_email_edit
{
    public function __construct()
    {
    }
    
    public function render()
    {
        $db  = VF::factory('database');
        $cfg = VF::cfg('core.config');
        
        $email_id    = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : NULL;
        $db->query("SELECT email_id FROM #__email WHERE email_id = ".$email_id." LIMIT 1");
        if (!$db->affected_rows()) {
            $email_id = NULL;
            $errors[] = 'Invalid email id! Are you sure this email exists!?';
        }
        
        $email         = array(
            'name' => '', 'description' => '',
            'subject' => '', 'message' => '', 'status' => '1', 'email_id' => 0
        );
        
        $errors     = array();
        $messages    = array();
        if (isset($_POST['submit_edit_email']) && $email_id) {
            $filter            = &VF::factory('filter');
            $name            = $filter->get('name');
            $description    = $filter->get('description');
            $subject        = htmlspecialchars_decode(trim($_POST['subject']), ENT_QUOTES);
            $message        = htmlspecialchars_decode(trim($_POST['message']), ENT_QUOTES);
            $status            = $filter->get('status', 'INTEGER');
            
            if ($name == '') {
                $errors[] = 'Email name field cannot be left blank!';
            } elseif (!preg_match('/^[a-zA-Z0-9_-]*$/', $name)) {
                $errors[] = 'Email name field (identifier) can only contain letters, underscores and dashes!';
            } elseif (!VValid::length($name, 3, 99)) {
                $errors[] = 'Email name must be at least 3 and no more than 9 characters!';
            } else {
                $db->query("SELECT email_id
                            FROM #__email
                            WHERE email_id != ".$email_id."
                            AND name = '".$db->escape($name)."'
                            LIMIT 1");
                if ($db->affected_rows()) {
                    $errors[] = 'Email name is already used by another email!';
                }
            }
            
            if ($subject == '') {
                $errors[] = $language['email_add.subject_empty'];
            }
            
            if ($message == '') {
                $errors[] = $language['email_add.message_empty'];
            }
            
            $email['description'] = $description;
            
            if (!$errors) {
                $db->query("UPDATE #__email
                            SET name = '".$db->escape($name)."',
                                description = '".$db->escape($description)."',
                                subject = '".$db->escape($subject)."',
                                message = '".$db->escape($message)."',
                                status = '".$status."'
                            WHERE email_id = ".$email_id."
                            LIMIT 1");
                $cache = &VF::factory('cache');
                $cache->remove('emails');
                $messages[] = 'Email updated!';
            }
        }
        
        if ($email_id) {
            $db->query("SELECT * FROM #__email WHERE email_id = ".$email_id." LIMIT 1");
            $email = $db->fetch_assoc();
        }
        
        $tpl = &VF::factory('template');
        $tpl->menu            = 'main';
        $tpl->submenu        = 'email_manage';
        $tpl->meta_title    = 'Admin::Email::Edit';
        $tpl->errors        = $errors;
        $tpl->messages        = $messages;
        $tpl->email            = $email;
        $tpl->load(array('header', 'email_edit', 'footer'));
        $tpl->display();                    
    }
}
?>