Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/manage.php
Строк: 185
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_photo_manage extends VModule_Admin_photo
{
    private 
$filter;
    private 
$option;
    private 
$pcfg;
    public function 
__construct()
    {
          
parent::__construct();
          
          
$this->pcfg        VF::cfg('module.photo');
          
$this->filter    VF::factory('filter');
          
$this->option    = array(
              
'title' => '''description' => '''username' => '',
              
'category' => '''status' => '''flagged' => '',
              
'sort' => 'a.album_id''order' => 'DESC''display' => 10
          
);
    }
    
    public function 
render()
    {
          
$errors        = array();
          
$messages    = array();
          
$warnings    = array();
          
        if (isset(
$_POST['action']) && isset($_POST['album_id'])) {
              
$action         $this->filter->get('action');
            
$album_id       = (int) trim($_POST['album_id']);
            if (
$album_id) {
                  if (
$action == 'suspend' OR $action == 'activate') {
                      
$status = ($action == 'suspend') ? 1;
                    
$msg    = ($action == 'suspend') ? 'suspended' 'activated';
                    
$this->db->query("UPDATE #__photo_albums SET status = '".$status."' WHERE album_id = ".$album_id." LIMIT 1");
                    
$messages[] = 'Album '.$msg.'!';
                } elseif (
$action == 'delete') {
                    
$this->delete_album($album_id);
                    
$messages[] = 'Album deleted!';
                } elseif (
$action == 'unassign') {
                    
$this->db->query("UPDATE #__photo_albums SET adv = 0 WHERE album_id = ".$album_id." LIMIT 1");
                    
$messages[] = 'Banner unassigned!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                  
$errors[] = 'Invalid album id! Are you sure this album 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 #__photo_albums SET status = '".$status."' WHERE album_id IN (".implode(','$ids).")");
                    
$messages[] = 'Selected albums '.$msg.'!';
                } elseif (
$action == 'delete') {
                    foreach (
$ids as $id) {
                          
$this->delete_album($id);
                    }
                    
$messages[] = 'Selected albums deleted!';
                } elseif (
$action == 'unassign') {
                    
$this->db->query("UPDATE #__photo_albums SET adv = 0 WHERE album_id IN (".implode(','$ids).")");
                    
$messages[] = 'Removed advertising from selected albums!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'Please select at least one album!';
            }
        }

        
$reset            FALSE;
        
$page           = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
        
$categories     $this->get_photo_categories();

        if (isset(
$_GET['c']) && is_numeric($_GET['c'])) {
              
$this->option['category']     = (int) $_GET['c'];
              
$reset                        TRUE;
        }
                                    
        if (isset(
$_GET['f']) && is_numeric($_GET['f'])) {
              
$this->option['flagged']     = (string) intval($_GET['f']);
              
$reset                        TRUE;
            
$submenu                     'photo_flagged';
        }
                                                                                                                                            
        if (isset(
$_GET['s']) && is_numeric($_GET['s'])) {
              
$this->option['status']     = (string) intval($_GET['s']);
              
$reset                        TRUE;
            
$submenu                     'photo_approve';
        }
        
        if (isset(
$_GET['u'])) {
              
$reset                        TRUE;
              
$this->option['username']     = (string) trim($_GET['u']);
        }
        
        
$submenu    'photo_manage';
        if (!isset(
$_POST['submit_reset']) && !isset($_GET['r']) && !$reset) {
            if (isset(
$_SESSION['search_photo_option'])) {
                if (
array_diff_assoc($this->option$_SESSION['search_photo_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_photo_option'];
                }
            }
        }
                
        
$search            $this->search_photo_albums();
        
$albums_total   $this->db->get_field($search['sql_count'], 'total_albums');
        
$pagination     VPagination::get($page$albums_total$search['display']);
        
$albums         $this->db->get_rows($search['sql']." LIMIT ".$pagination['limit']);
                                                                                       
          
$tpl VF::factory('template');
          
$tpl->menu            'photo';
          
$tpl->submenu        'manage';
          
$tpl->meta_title    'Admin::Photo::Manage';
          
$tpl->errors        $errors;
          
$tpl->messages        $messages;
          
$tpl->warnings        $warnings;
          
$tpl->albums        $albums;
          
$tpl->pagination    $pagination;
          
$tpl->categories    $categories;
          
$tpl->load(array('header''photo_manage''footer'));
          
$tpl->display();
    }
    
    private function 
search_photo_albums()
    {
          
$sql        "SELECT a.album_id, a.title, a.total_photos, a.total_views, a.rating, a.rated_by, 
                                a.status, a.flagged, a.add_date, u.username,
                                  GROUP_CONCAT(pc.cat_id) AS category,
                                GROUP_CONCAT(c.name) AS name
                            FROM #__photo_albums AS a
                          LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
                            LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
                          LEFT JOIN #__photo_categories AS c ON (c.cat_id = pc.cat_id)"
;
          
$sql_count    "SELECT COUNT(*) AS total_albums
                           FROM #__photo_albums AS a, #__photo_category AS pc"
;
          
$sql_delim    " WHERE ";
          
          if (isset(
$_POST['submit_search'])) {
              
$this->option['title']            = $this->filter->get('title');
              
$this->option['description']    = $this->filter->get('description');
              
$this->option['username']        = $this->filter->get('username');
              
$this->option['category']        = $this->filter->get('category');
              
$this->option['status']            = $this->filter->get('status');
              
$this->option['flagged']        = $this->filter->get('flagged');
              
$this->option['sort']            = $this->filter->get('sort');
              
$this->option['order']            = $this->filter->get('order');
              
$this->option['display']        = (int) trim($_POST['display']);
          }
          
          if (
$this->option['title'] != '') {
              
$sql        .= $sql_delim." a.title LIKE '".$this->db->escape($this->option['title'])."%'";
              
$sql_count    .= $sql_delim." a.title LIKE '".$this->db->escape($this->option['title'])."%'";
              
$sql_delim     ' AND';
          }
          
          if (
$this->option['description'] != '') {
              
$sql        .= $sql_delim." a.title LIKE '".$this->db->escape($this->option['description'])."%'";
              
$sql_count    .= $sql_delim." a.title LIKE '".$this->db->escape($this->option['description'])."%'";
              
$sql_delim     ' 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 = (int) $this->db->fetch_field('user_id');
                  
$sql        .= $sql_delim." a.user_id = ".$user_id;
                  
$sql_count  .= $sql_delim." a.user_id = ".$user_id;
                  
$sql_delim   ' AND';
              }
          }
          
          if (
$this->option['category'] != '') {
              
$sql        .= $sql_delim." pc.cat_id = ".(int) $this->option['category'];
              
$sql_count    .= $sql_delim." pc.cat_id = ".(int) $this->option['category'];
              
$sql_delim     ' AND';
          }
          
          if (
$this->option['status'] != '') {
              
$sql        .= $sql_delim." a.status = '".(int) $this->option['status']."'";
              
$sql_count    .= $sql_delim." a.status = '".(int) $this->option['status']."'";
              
$sql_delim     ' AND';
          }

          if (
$this->option['flagged'] != '') {
              
$sql        .= $sql_delim." a.flagged = '".(int) $this->option['flagged']."'";
              
$sql_count    .= $sql_delim." a.flagged = '".(int) $this->option['flagged']."'";
              
$sql_delim     ' AND';
          }
          
          
$_SESSION['search_photo_option'] = $this->option;
          
          return array(
              
'sql'         => $sql.' GROUP BY a.album_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_album_') !== FALSE) {
                  
$ids[] = (int) str_replace('checkbox_album_'''$key);
            }
        }
                                                                                
        return 
$ids;
    }                                                                                            
}
?>
Онлайн: 0
Реклама