Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/kb/components/category.php
Строк: 65
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_kb_category
{
    private 
$db;
    private 
$filter;
    public function 
__construct()
    {
        
$this->db        = &VF::factory('database');
        
$this->filter    = &VF::factory('filter');
    }
    
    public function 
render()
    {
        
$errors     = array();
        
$messages   = array();
        
$cache        VF::factory('cache');
        if (isset(
$_POST['action']) && isset($_POST['cat_id'])) {
            
$action $this->filter->get('action');
            
$cat_id    = (int) trim($_POST['cat_id']);
            if (
$cat_id) {
                if (
$action == 'suspend' OR $action == 'activate') {
                    
$status = ($action == 'suspend') ? 1;
                    
$msg    = ($action == 'suspend') ? 'suspended' 'activated';
                    
$this->db->query("UPDATE #__kb_categories SET status = '".$status."' WHERE cat_id = ".$cat_id." LIMIT 1");
                    
$messages[] = 'Category '.$msg.'!';
                    
$cache->remove('kb_categories');
                } elseif (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__kb_categories WHERE cat_id = ".$cat_id." LIMIT 1");
                    
$messages[] = 'Category deleted!';
                    
$cache->remove('kb_categories');
                } else {
                    
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[] = 'Invalid category id! What exactly did you click!?';
            }
        }
        
        if (isset(
$_POST['submit_actions'])) {
            
$action $this->filter->get('action');
            
$ids    $this->get_checkbox_ids();
            if (
$action == 'suspend' OR $action == 'activate') {
                
$status     = ($action == 'suspend') ? 1;
                
$msg        = ($action == 'suspend') ? 'suspended' 'activated';
                
$this->db->query("UPDATE #__kb_categories SET status = ".$status." WHERE cat_id IN (".implode(','$ids).")");
                
$messages[] = 'Select categories '.$msg.'!';
                
$cache->remove('kb_categories');
            } elseif (
$action == 'delete') {
                
$this->db->query("DELETE FROM #__kb_categories WHERE cat_id IN (".implode(','$ids).")");
                
$messages[]    = 'Selected categories deleted!';
                
$cache->remove('kb_categories');
            } else {
                
$errors[] = 'Invalid action! What exactly did you select!?';
            }
        }

        
$page                = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$this->db->query("SELECT COUNT(*) AS total_categories FROM #__kb_categories ORDER BY pos ASC");
        
$categories_total    $this->db->fetch_field('total_categories');
        
$pagination            VPagination::get($page$categories_total12);
        
$this->db->query("SELECT * FROM #__kb_categories ORDER BY pos ASC LIMIT ".$pagination['limit']);
        
$categories            $this->db->fetch_rows();
    
        
$tpl    VF::factory('template');
        
$tpl->menu            'kb';
        
$tpl->submenu        'kb_category';
        
$tpl->meta_title    'Admin::Knowledge Base::Category::Manage';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->categories    $categories;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''kb_category''footer'));
        
$tpl->display();
    }
    
    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key'checkbox_category_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_category_'''$key);
            }
        }

        return 
$ids;
    }
    
    private function 
delete_kb_category($cat_id)
    {
        
// code to delete knowledge base category here...
    
}
}
?>
Онлайн: 2
Реклама