Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/tools/components/cron_add.php
Строк: 80
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_tools_cron_add
{
    private 
$db;
    public function 
__construct()
    {
        
$this->db    VF::factory('database');
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$script        = array(
            
'module'    => '',
            
'name'        => '',
            
'slug'        => '',
            
'period'    => 0,
            
'status'    => 1
        
);
    
        if (isset(
$_POST['submit-add'])) {
            
$filter            VF::factory('filter');
            
$module            $filter->get('module');
            
$name            $filter->get('name');
            
$slug            $filter->get('slug');
            
$period            = (int) trim($_POST['period']);
            
$status            = (int) trim($_POST['status']);
            
            if (
$name == '') {
                
$errors[]    = 'Script name cannot be left blank!';
            } elseif (!
VValid::length($name3100)) {
                
$errors[]    = 'Script name must contain minimum 3 and no more than 100 characters!';
            } else {
                
$script['name']    = $name;
            }

            if (
$slug == '') {
                
$errors[]    = 'Script SLUG cannot be left blank!';
            } elseif (!
VValid::alunderscore($slug)) {
                
$errors[]    = 'Script SLUG can contain only alpha numeric characters and dashes!';
            } elseif (!
VValid::length($slug3100)) {
                
$errors[]    = 'Script SLUG must contain minimum 3 and no more than 100 characters!';
            } else {
                
$this->db->query("SELECT cron_id
                                  FROM #__cron
                                  WHERE slug = '"
.$this->db->escape($slug)."'
                                  LIMIT 1"
);
                if (
$this->db->affected_rows()) {
                    
$errors[]        = 'SLUG is already used by another cron script entry!';
                } else {
                    
$script['slug']    = $slug;
                }
            }
            
            if (
$module == '') {
                
$errors[]    = 'Please select a module for your script!';
            } else {
                
$script['module']    = $module;
            }
            
            if (
$period === 0) {
                
$errors[]    = 'Script period cannot be left blank!';
            } elseif (
$period 1) {
                
$errors[]    = 'Script period cannot be lower than 1 minute!';
            } else {
                
$script['period']    = $period;
            }
            
            
$script['status']     = $status;
            
            if (!
$errors) {
                
$this->db->query("INSERT INTO #__cron
                                  SET module = '"
.$this->db->escape($module)."',
                                      name = '"
.$this->db->escape($name)."',
                                      slug = '"
.$this->db->escape($slug)."',
                                      period = "
.$period.",
                                      status = "
.$status);
                if (
$this->db->affected_rows()) {
                    
$messages[]    = 'Cron script added!';
                } else {
                    
$errors[]    = 'Failed to create database entry! Aborting...';
                }
            }
        }
    
        
$tpl    VF::factory('template');
        
$tpl->menu            'tools';
        
$tpl->submenu        'tools_cron';
        
$tpl->meta_title    'Admin::Tools::Cron::Add';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->script        $script;
        
$tpl->modules        $this->get_modules();
        
$tpl->load(array('header''tools_cron_add''footer'));
        
$tpl->display();
    }
    
    private function 
get_modules()
    {
        
$this->db->query("SELECT name, description
                          FROM #__module
                          ORDER BY description ASC"
);
        return 
$this->db->fetch_rows();
    }
}
Онлайн: 1
Реклама