Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/view.php
Строк: 105
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_photo_view extends VModule_Admin_photo
{
    private 
$option;
    public function 
__construct()
    {
        
parent::__construct();
        
$this->option    = array(
            
'sort' => 'photo_id''order' => 'DESC''display' => 10
        
);
    }
    
    public function 
render()
    {
        
$tpl VF::factory('template');
    
        
$album        = array();
        
$photos        = array();
        
$pagination    = array();
        
$album_id    = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
        
$categories    $this->get_photo_categories();
        
$statuses    = array(
            
'0' => 'Suspended',
            
'1' => 'Active',
            
'2' => 'Approve Required',
            
'3' => 'Processing'
        
);
        
        
$errors         = array();
        
$messages    = array();
        
$warnings    = array();
        
        
$this->db->query("SELECT a.*, u.username,
                                 GROUP_CONCAT(DISTINCT c.cat_id) AS cats,
                                 GROUP_CONCAT(DISTINCT c.name) AS name,
                                 GROUP_CONCAT(DISTINCT t.name) AS tags
                          FROM #__photo_albums AS a
                          LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
                          LEFT JOIN #__photo_categories AS c ON (pc.cat_id = c.cat_id)
                          LEFT JOIN #__photo_tags AS t ON (t.album_id = a.album_id)
                          LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
                          WHERE a.album_id = "
.$album_id."
                          GROUP BY a.album_id
                          LIMIT 1"
);
        if (
$this->db->affected_rows()) {
            
$album             $this->db->fetch_assoc();
            if (isset(
$_POST['aaction']) && isset($_POST['album_id'])) {
                
$action        trim($_POST['aaction']);
                
$album_id    = (int) trim($_POST['album_id']);
                if (
$action == 'activate' OR $action == 'suspend') {
                    
$status    = ($action == 'activate') ? 0;
                    
$msg    = ($action == 'activate') ? 'published' 'suspended';
                    
$this->db->query("UPDATE #__photo_albums SET status = '".$status."' WHERE album_id = ".$album_id." LIMIT 1");
                    
$album['status'] = $status;
                    
$messages[] = 'Album '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->delete_album($album_id);
                    
$album = array();
                    
$messages[] = 'Album deleted!';
                } else {
                    
$errors[] = 'Invalid album action! What exactly did you click!?';
                }
            }
            
            if (isset(
$_POST['action']) && isset($_POST['photo_id'])) {
                
$action        trim($_POST['action']);
                
$photo_id    = (int) trim($_POST['photo_id']);
                if (
$action == 'activate' OR $action == 'suspend') {
                    
$status    = ($action == 'activate') ? 0;
                    
$msg    = ($action == 'activate') ? 'published' 'suspended';
                    
$this->db->query("UPDATE #__photo SET status = '".$status."' WHERE photo_id = ".$photo_id." LIMIT 1");
                    
$album['status'] = $status;
                    
$messages[] = 'Photo '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->delete_photo($photo_id$album_id);
                    
$messages[]    = 'Photo deleted!';
                } else {
                    
$errors[] = 'Invalid photo action! What exactly did you click!?';
                }
            }
            
            if (isset(
$_POST['submit_actions'])) {
                
$action    trim($_POST['action']);
                
$ids    $this->get_checkbox_ids();
                if (
$action == 'suspend' OR $action == 'activate') {
                    
$status    = ($action == 'activate') ? 0;
                    
$msg    = ($action == 'activate') ? 'published' 'suspended';
                    
$this->db->query("UPDATE #__photo SET status = '".$status."' WHERE photo_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selected photos '.$msg.'!';
                } elseif (
$action == 'delete') {
                    foreach (
$ids as $photo_id) {
                        
$this->delete_photo((int) $photo_id);
                    }
                    
$messages[] = 'Selected photos deleted!';
                } else {
                }
            }
            
            
$page            = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
            
$query            $this->search_photos($album_id);
            
$total_photos    $this->db->get_field($query['sql_count'], 'total_photos');
            
$pagination        VPagination::get($page$total_photos$query['display']);
            
$photos            $this->db->get_rows($query['sql'].' LIMIT '.$pagination['limit']);
        }                                                                                                                                                                             
        
        
$tpl VF::factory('template');
        
$tpl->menu            'photo';
        
$tpl->submenu        'photo_view';
        
$tpl->meta_title    'Admin::Album::View';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->warnings        $warnings;
        
$tpl->categories    $categories;
        
$tpl->statuses        $statuses;
        
$tpl->album            $album;
        
$tpl->album_id        $album_id;
        
$tpl->photos        $photos;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''photo_album_view''footer'));
        
$tpl->display();
    }
    
    private function 
search_photos($album_id)
    {
        
$sql_count            "SELECT COUNT(*) AS total_photos
                               FROM #__photo
                               WHERE album_id = "
.$album_id;
        
$sql                "SELECT photo_id, caption, ext, total_views, total_comments, total_favorites,
                                      rating, rated_by, add_date, flagged, status
                               FROM #__photo
                               WHERE album_id = "
.$album_id;
        
        if (isset(
$_POST['submit_search'])) {
            
$filter                        VF::factory('filter');
            
$this->option['sort']        = $filter->get('sort');
            
$this->option['order']        = $filter->get('order');
            
$this->option['display']    = (int) trim($_POST['display']);
        }
        
        return array(
            
'sql_count'    => $sql_count,
            
'sql'        => $sql.' ORDER BY '.$this->option['sort'].' '.$this->option['order'],
            
'display'    => $this->option['display']
        );
    }

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