Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/adv/components/player.php
Строк: 128
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_adv_player
{
    private 
$db;
    private 
$option;
    public function 
__construct()
    {
          
$this->db        VF::factory('database');
          
$this->option    = array(
              
'name' => '''type' => '''status' => '''expire' => '',
              
'sort' => 'adv_id''order' => 'DESC''display' => 20
          
);
    }
    
    public function 
render()
    {
        
$errors        = array();
        
$messages    = array();
        
        if (isset(
$_POST['action']) && isset($_POST['adv_id'])) {
            
$action trim($_POST['action']);
            
$adv_id = (int) trim($_POST['adv_id']);
            if (
$adv_id) {
                switch (
$action) {
                    case 
'activate':
                    case 
'suspend':
                        
$status = ($action == 'activate') ? 0;
                        
$msg    = ($action == 'activate') ? 'activated' 'suspended';
                        
$this->db->query("UPDATE #__adv_player SET status = '".$status."' WHERE adv_id = ".$adv_id." LIMIT 1");
                        
$messages[] = 'Banner '.$msg.'!';
                        break;
                    case 
'delete':
                        
$this->db->query("DELETE FROM #__adv_player WHERE adv_id = ".$adv_id." LIMIT 1");
                        
$messages[] = 'Banner deleted!';
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you click!?';
                        break;
                }
            } else {
                
$errors[] = 'Invalid advertising! Are you sure this banner exists!?';
            }
        }
        
        if (isset(
$_POST['submit_actions'])) {
            
$action trim($_POST['action']);
            
$ids    $this->get_checkbox_ids();
            if (
$ids) {
                switch (
$action) {
                    case 
'suspend':
                    case 
'activate':
                        
$status = ($action == 'activate') ? 0;
                        
$msg    = ($action == 'activate') ? 'activated' 'suspended';
                        
$this->db->query("UPDATE #__adv_player SET status = '".$status."' WHERE adv_id IN (".implode(','$ids).")");
                        
$messages[] = "Selected banners ".$msg."!";
                        break;
                    case 
'delete':
                        
$this->db->query("DELETE FROM #__adv_player WHERE adv_id IN (".implode(','$ids).")");
                        
$messages[] = "Selected banners deleted!";
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you select!?';
                        break;
                }
            } else {
                
$errors[] = 'Please select at least one banner!';
            }
        }        
        
        if (!isset(
$_POST['submit_reset'])) {
            if (isset(
$_SESSION['search_adv_player_option'])) {
                  if (
array_diff_assoc($this->option$_SESSION['search_adv_player_option'])) {
                    
$warnings[] = 'Results are selected based on your search criteria/options! If you want to see all results please reset the current search!';
                    
$this->option $_SESSION['search_adv_player_option'];
                }
            }
        }
        
        
$page            = (isset($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$query            $this->search_advs();
        
$total_advs        $this->db->get_field($query['sql_count'], 'total_advs');
        
$pagination        VPagination::get($page$total_advs$query['display']);
        
$advs            $this->db->get_rows($query['sql'].' LIMIT '.$pagination['limit']);
        
        
$tpl        VF::factory('template');
        
$tpl->menu            'adv';
        
$tpl->submenu        'player';
        
$tpl->extramenu        'player_manage';
        
$tpl->meta_title    'Advertising::Player::Manage';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->option        $this->option;
        
$tpl->advs            $advs;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''adv_player''footer'));
        
$tpl->display();
    }
    
    private function 
search_advs()
    {
        
$sql        "SELECT a.adv_id, a.adv_name, a.adv_desc, a.type,
                              a.clicks, a.views, a.expire, a.status
                       FROM #__adv_player AS a"
;
        
$sql_count    "SELECT COUNT(*) AS total_advs
                       FROM #__adv_player AS a"
;
        
$sql_delim    " WHERE";
        
        if (isset(
$_GET['e']) && $_GET['e'] == 'yes') {
            
$this->option['expire'] = 'yes';
        }
        
        if (isset(
$_POST['submit_search'])) {
            
$filter                        VF::factory('filter');
            
$this->option['name']        = $filter->get('name');
            
$this->option['type']        = $filter->get('type');
            
$this->option['status']        = $filter->get('status');
            
$this->option['sort']        = $filter->get('sort');
            
$this->option['order']        = $filter->get('order');
            
$this->option['display']    = (int) trim($_POST['display']);
        }
        
        if (
$this->option['name'] != '') {
            
$sql        .= $sql_delim." adv_name LIKE '%".$this->db->escape($this->option['name'])."%'";
            
$sql_count    .= $sql_delim." adv_name LIKE '%".$this->db->escape($this->option['name'])."%'";
            
$sql_delim     " AND";
        }
        
        if (
$this->option['type'] != '') {
            
$sql        .= $sql_delim." type = '".$this->db->escape($this->option['type'])."'";
            
$sql_count    .= $sql_delim." type = '".$this->db->escape($this->option['type'])."'";
            
$sql_delim     " AND";
        }
        
        if (
$this->option['status'] != '') {
            
$sql        .= $sql_delim." status = '".(int) $this->option['status']."'";
            
$sql_count    .= $sql_delim." status = '".(int) $this->option['status']."'";
            
$sql_delim     " AND";
        }
        
        if (
$this->option['expire'] == 'yes') {
            
$date         date('Y-m-d');
            
$sql        .= $sql_delim." expire > ".$date;
            
$sql_count    .= $sql_delim." expire > ".$date;
            
$sql_delim     " AND";            
        }
        
        
$_SESSION['search_adv_player_option'] = $this->option;
        
        return array(
            
'sql'        => $sql.' 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_adv_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_adv_'''$key);
            }
        }

        return 
$ids;
    }    
}
Онлайн: 1
Реклама