Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/kb/components/category_edit.php
Строк: 56
<?php
defined
('_VALID') or die('Restricted Access!');

define('IMG_WIDTH', 175);
define('IMG_HEIGHT', 215);

class 
VComponent_Admin_video_category_edit
{
    public function 
__construct()
    {
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
$db            = &VF::factory('database');
        
$cat        = array('cat_id' => 0, 'name' => '', 'description' => '', 'status' => '1');
        
$cat_id        = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
        
$db->query("SELECT cat_id FROM #__video_categories WHERE cat_id = ".$cat_id." LIMIT 1");
        if (
$db->affected_rows()) {
            if (isset(
$_POST['submit_edit_category'])) {
                
$filter            = VF::factory('filter');
                
$name            = $filter->get('name');
                
$slug            = $filter->get('slug');
                
$description    = $filter->get('description');
                
$status            = $filter->get('status', 'INT');
        
                if (
$name == '') {
                    
$errors[]    = 'Category name field cannot be left blank!';
                } elseif (!
VValid::length($name, 1, 100)) {
                    
$errors[]    = 'Category name can contain maximum 100 characters!';
                } else {
                    
$db->query("SELECT cat_id FROM #__video_categories WHERE name = '".$db->escape($name)."' AND cat_id != ".$cat_id." LIMIT 1");
                    if (
$db->affected_rows()) {
                        
$errors[] = 'Category name is already used for another category!';
                    }
                }
                
                if (
$slug == '') {
                    
$errors[]    = 'Category slug cannot be left blank!';
                } elseif (!
preg_match('/[a-z0-9-]/', $slug)) {
                    
$errors[]    = 'Category slug can contain only lower alphanumeric characters!';
                } else {
                    
$db->query("SELECT cat_id FROM #__video_categories WHERE slug = '".$db->escape($slug)."' AND cat_id != ".$cat_id." LIMIT 1");
                    if (
$db->affected_rows()) {
                        
$errors[] = 'Category slug is already used for another category!';
                    }
                }

                 if (isset(
$_FILES['image']['tmp_name']) &&
                    
$_FILES['image']['tmp_name'] != '') {
                      if (!
$file = VUpload::process('image', 2, array('jpg', 'jpeg', 'png', 'gif'))) {
                          
$errors = array_merge($errors, VUpload::error());
                      }
                  }
        
                if (!
$errors) {
                    
$db->query("UPDATE #__video_categories
                                SET name = '"
.$db->escape($name)."',
                                    slug = '"
.$db->escape($slug)."',
                                    description = '"
.$db->escape($description)."',
                                    status = '"
.$status."'
                                WHERE cat_id = "
.$cat_id."
                                LIMIT 1"
);
                    
$messages[] = 'Category updated!';
                    
VF::factory('cache')->remove('categories');
                }
            }
            
            
$db->query("SELECT * FROM #__video_categories WHERE cat_id = ".$cat_id." LIMIT 1");
            
$cat = $db->fetch_assoc();
        } else {
            
$errors[] = 'Invalid category id! Are you sure this category exists!';
        }
        
        
$tpl    = &VF::factory('template');
        
$tpl->menu            = 'video_category';
        
$tpl->submenu        = 'video_category';
        
$tpl->meta_title    = 'Admin::Video::Category::Edit';
        
$tpl->errors        = $errors;
        
$tpl->messages        = $messages;
        
$tpl->cat            = $cat;
        
$tpl->load(array('header', 'video_category_edit', 'footer'));
        
$tpl->display();
    }
}
?>
Онлайн: 3
Реклама