Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/pornstar/components/videos.php
Строк: 175
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_pornstar_videos
{
    protected 
$db;
    private 
$cfg;
    private 
$filter;
    private 
$option;
    public function 
__construct()
    {
        
$this->cfg        VF::cfg('core.config');
        
$this->db        VF::factory('database');
        
$this->filter    VF::factory('filter');
        
$this->option    = array(
            
'title' => '''description' => '''username' => '',
            
'category' => '''status' => '''flagged' => '',
            
'sort' => 'v.video_id''order' => 'DESC''display' => 10
        
);
    }
    
    public function 
render()
    {
        
$model_id    = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
        
$errors        = array();
        
$messages    = array();
        
        if (isset(
$_POST['action']) && isset($_POST['video_id'])) {
            
$action        $this->filter->get('action');
            
$video_id    $this->filter->get('video_id''INTEGER');
            if (
$video_id) {
                if (
$action == 'suspend' OR $action == 'activate') {
                    
$status = ($action == 'suspend') ? 1;
                    
$msg    = ($action == 'suspend') ? 'suspended' 'activated';
                    
$this->db->query("UPDATE #__video SET status = ".$status." WHERE video_id = ".$video_id." LIMIT 1");
                    
$messages[] = 'Video '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->delete_video($video_id);
                    
$messages[] = 'Video deleted!';
                } elseif (
$action == 'unassign') {
                    
$this->db->query("UPDATE #__video SET adv = 0 WHERE video_id = ".$video_id." LIMIT 1");
                    
$messages[] = 'Banner unassigned!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[] = 'Invalid video id! Are you sure this video exists!?';
            } 
        }
        
        if (isset(
$_POST['submit_actions'])) {
            
$action    $this->filter->get('action');
            
$ids    $this->get_checkbox_ids();
            if (
$ids) {
                if (
$action == 'suspend' OR $action == 'activate') {
                    
$status     = ($action == 'suspend') ? 1;
                    
$msg        = ($action == 'suspend') ? 'suspended' 'activated';
                    
$this->db->query("UPDATE #__video SET status = ".$status." WHERE video_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selected videos '.$msg.'!';
                } elseif (
$action == 'delete') {
                    foreach (
$ids as $id) {
                        
$this->delete_video($id);
                    }
                    
$messages[] = 'Selected videos deleted!';
                } elseif (
$action == 'unassign') {
                    
$this->db->query("UPDATE #__video SET adv = 0 WHERE video_id IN (".implode(','$ids).")");
                    
$messages[] = 'Removed advertising from selected videos!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'Please select at least one video!';
            }
        }
        
        
$page            = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$categories        $this->get_video_categories();
        
        
$submenu    'video_manage';
        if (!isset(
$_POST['submit_reset']) && !isset($_GET['r'])) {
            if (isset(
$_SESSION['search_video_option'])) {
                
$this->option $_SESSION['search_video_option'];
            }
        }
        
        if (isset(
$_GET['c']) && is_numeric($_GET['c'])) {
            
$this->option['category'] = (int) $_GET['c'];
        }
        
        if (isset(
$_GET['f']) && is_numeric($_GET['f'])) {
            
$this->option['flagged'] = (string) intval($_GET['f']);
            
$submenu 'video_flagged';
        }

        if (isset(
$_GET['s']) && is_numeric($_GET['s'])) {
            
$this->option['status'] = (string) intval($_GET['s']);
            
$submenu 'video_approve';
        }
        
        if (isset(
$_GET['u'])) {
            
$this->option['username'] = (string) trim($_GET['u']);
        }
        
        
$search         $this->search_videos($model_id);
        
$videos_total   $this->db->get_field($search['sql_count'], 'total_videos');
        
$pagination     VPagination::get($page$videos_total$search['display']);
        
$videos         $this->db->get_rows($search['sql']." LIMIT ".$pagination['limit']);
        
        
$advs            $this->db->get_rows("SELECT a.adv_id, adv_name
                                               FROM #__adv AS a, #__adv_groups AS g
                                               WHERE g.adv_group_slug = 'video-player'
                                               AND a.adv_group_id = g.adv_group_id
                                               AND a.status = '1'
                                               ORDER BY a.adv_name ASC"
);
        
        
$tpl VF::factory('template');
        
$tpl->menu            'pornstar';
        
$tpl->submenu        'pornstar_videos';
        
$tpl->meta_title    'Admin::Model::View::Videos';
        
$tpl->option        $this->option;
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->categories    $categories;
        
$tpl->videos        $videos;
        
$tpl->pagination    $pagination;
        
$tpl->advs            $advs;
        
$tpl->model_id        $model_id;
        
$tpl->load(array('header''pornstar_videos''footer'));
        
$tpl->display();
    }
    
    private function 
get_video_categories()
    {
        return 
$this->db->get_rows("SELECT cat_id, name FROM #__video_categories ORDER BY name ASC");
    }
    
    private function 
search_videos($model_id)
    {
        
$sql        "SELECT v.*, u.username, GROUP_CONCAT(DISTINCT vc.cat_id) AS category,
                              GROUP_CONCAT(DISTINCT c.name) AS name
                       FROM #__model_videos AS m, #__video_category AS vc, #__video AS v, #__video_categories AS c, #__user AS u
                       WHERE m.model_id = "
.$model_id."
                       AND vc.video_id = m.video_id
                       AND v.video_id = m.video_id
                       AND c.cat_id = vc.cat_id
                       AND u.user_id = v.user_id"
;
        
$sql_count    "SELECT COUNT(*) AS total_videos
                       FROM #__model_videos AS m, #__video AS v, #__video_category AS vc
                       WHERE m.model_id = "
.$model_id."
                       AND v.video_id = m.video_id
                       AND vc.video_id = v.video_id"
;

        
$sql_add    ' AND';
        if (isset(
$_POST['submit_search'])) {
            
$this->option['title']        = $this->filter->get('title');
            
$this->option['tags']        = $this->filter->get('tags');
            
$this->option['username']    = $this->filter->get('username');
            
$this->option['category']    = $this->filter->get('category');
            
$this->option['flagged']    = $this->filter->get('flagged');
            
$this->option['status']        = $this->filter->get('status');
            
$this->option['sort']        = $this->filter->get('sort');
            
$this->option['order']        = $this->filter->get('order');
            
$this->option['display']    = (int) $_POST['display'];
        }

        if (
$this->option['title'] != '') {
            
$sql        .= " AND v.title LIKE '%".$this->db->escape($this->option['title'])."%'";
            
$sql_count    .= $sql_add." v.title LIKE '%".$this->db->escape($this->option['title'])."%'";
            
$sql_add     ' AND';
        }
        
        if (
$this->option['description'] != '') {
            
$sql        .= " AND v.description LIKE '%".$this->db->escape($this->option['description'])."%'";
            
$sql_count    .= $sql_add." v.description LIKE '%".$this->db->escape($this->option['description'])."%'";
            
$sql_add     ' AND';
        }
        
        if (
$this->option['username'] != '') {
            
$this->db->query("SELECT user_id FROM #__user WHERE username = '".$this->db->escape($this->option['username'])."' LIMIT 1");
            if (
$this->db->affected_rows()) {
                
$user_id $this->db->fetch_field('user_id');
                
$sql        .= " AND v.user_id = ".$user_id;
                
$sql_count    .= $sql_add." v.user_id = ".$user_id;
                
$sql_add     ' AND';
            }
        }
        
        if (
$this->option['category'] != '') {
            
$sql        .= " AND vc.cat_id = ".(int) $this->option['category'];
            
$sql_count    .= $sql_add." vc.cat_id = ".(int) $this->option['category'];
            
$sql_add     ' AND';
        }
        
        if (
$this->option['flagged'] != '') {
            
$sql        .= " AND v.flagged = '".(int) $this->option['flagged']."'";
            
$sql_count    .= $sql_add." v.flagged = '".(int) $this->option['flagged']."'";
            
$sql_add     ' AND';
        }
        
        if (
$this->option['status'] != '') {
            
$sql        .= " AND v.status = ".(int) $this->option['status'];
            
$sql_count    .= $sql_add." v.status = ".(int) $this->option['status'];
            
$sql_add     ' AND';
        }
        
        
$_SESSION['search_video_option'] = $this->option;
        
        return array(
            
'sql' => $sql" GROUP BY vc.video_id ORDER BY ".$this->option['sort']." ".$this->option['order'],
            
'sql_count' => $sql_count,
            
'display' => $this->option['display']
        );
    }

    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key'checkbox_video_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_video_'''$key);
            }
        }
            
        return 
$ids;
    }
}
?>
Онлайн: 0
Реклама