Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/content/components/manage.php
Строк: 96
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_content_manage
{
    private 
$db;
    private 
$option;
    public function 
__construct()
    {
        
$this->db    = VF::factory('database');
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        if (isset(
$_POST['action']) && isset($_POST['page_id'])) {
            
$action = trim($_POST['action']);
            
$page_id  = (int) trim($_POST['page_id']);
            if (
$page_id) {
                switch (
$action) {
                    case 
'activate':
                    case 
'suspend':
                        
$msg    = ($action == 'activate') ? 'activated' : 'suspended';
                        
$status = ($action == 'activate') ? 1 : 0;
                        
$this->db->query("UPDATE #__static SET status = '".$status."' WHERE static_id = ".$page_id." LIMIT 1");
                        
$messages[] = 'Static page '.$msg.'!';
                        break;
                    case 
'delete':
                        
$this->db->query("DELETE FROM #__static WHERE static_id = ".$page_id." LIMIT 1");
                        
$messages[] = 'Banner deleted!';
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[]   = 'Invalid static page id! Are you sure this static page exists!?';
            }
        }

        if (isset(
$_POST['submit_actions'])) {
            
$ids    = $this->get_checkbox_ids();
            
$action = trim($_POST['action']);
            if (
$ids) {
                if (
$action == 'activate' OR
                    
$action == 'suspend') {
                    
$msg    = ($action == 'activate') ? 'activated' : 'suspended';
                    
$status = ($action == 'activate') ? 1 : 0;
                    
$this->db->query("UPDATE #__static SET status = '".$status."' WHERE static_id IN (".implode(',', $ids).")");
                    
$messages[] = 'Selected static pages '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__static WHERE static_id IN (".implode(',', $ids).")");
                    
$messages[] = 'Selected static pages deleted!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'You must select at least one static page!';
            }
        }

        
$page            = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$this->option    = array(
            
'name' => '', 'status' => '', 'sort' => 'c.static_id', 'order' => 'DESC', 'display' => 10
        
);
        
        if (isset(
$_SESSION['search_content_option'])) {
            
$this->option = $_SESSION['search_content_option'];
        }
        
        
$search         = $this->search_content();
        
$pages_total       = $this->db->get_field($search['sql_count'], 'total_pages');
        
$pagination     = VPagination::get($page, $pages_total, $search['display']);
        
$pages          = $this->db->get_rows($search['sql'].' LIMIT '.$pagination['limit']);
        
        
$tpl    = VF::factory('template');
        
$tpl->menu                = 'main';
        
$tpl->submenu            = 'content_manage';
        
$tpl->meta_title        = 'Admin::Content::Manage';
        
$tpl->errors            = $errors;
        
$tpl->messages            = $messages;
        
$tpl->pages                = $pages;
        
$tpl->pagination        = $pagination;
        
$tpl->load(array('header', 'content_manage', 'footer'));
        
$tpl->display();
    }
    
    private function 
search_content()
    {
        
$sql        = "SELECT c.* FROM #__static AS c";
        
$sql_count  = "SELECT COUNT(*) AS total_pages FROM #__static AS c";

        return array(
            
'sql'       => $sql,
            
'sql_count' => $sql_count,
            
'display'     => $this->option['display']
        );
    }
    
    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key, 'checkbox_content_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_content_', '', $key);
            }
        }

        return 
$ids;
    }    
}
?>
Онлайн: 2
Реклама