Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/photo_flags.php
Строк: 62
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_photo_photo_flags extends VModule_Admin_photo
{
    protected 
$db;
    public function 
__construct()
    {
        
$this->db        = VF::factory('database');
    }
    
    public function 
render()
    {
        
$tpl        = VF::factory('template');
        
$photo_id    = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
        
$errors        = array();
        
$messages    = array();
        
        
$reasons    = array(
            
1 => 'Inappropriate',
            
2 => 'Underage',
            
3 => 'Copyrighted Material',
            
4 => 'Not Playing',
            
5 => 'Other'        
        
);
        
        
$errors     = array();
        
$messages   = array();
        if (isset(
$_POST['action']) && isset($_POST['flag_id'])) {
            
$action = trim($_POST['action']);
            
$flag_id  = (int) trim($_POST['flag_id']);
            if (
$flag_id) {
                if (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__photo_flags WHERE photo_id = ".$photo_id." AND flag_id = ".$flag_id." LIMIT 1");
                    
$messages[] = 'Flag removed!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[]   = 'Invalid static page id! Are you sure this report exists!?';
            }
        }

        if (isset(
$_POST['submit_actions'])) {
            
$ids    = (isset($_POST['checked'])) ? (array) $_POST['checked'] : array();
            
$action = trim($_POST['action']);
            if (
$ids) {
                if (
$action == 'delete') {
                    
$this->db->query("DELETE FROM #__photo_flags WHERE photo_id = ".$photo_id." AND flag_id IN (".implode(',', array_keys($ids)).")");
                    
$messages[] = 'Selected flags removed!';
                } else {
                    
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'You must select at least one report!';
            }
        }
        
        if (isset(
$_GET['a'])) {
              
$action = trim($_GET['a']);
              switch (
$action) {
                  case 
'unflag':
                      
$this->db->query("UPDATE #__photo SET flagged = '0' WHERE photo_id = ".$photo_id." LIMIT 1");
                      
$this->db->query("DELETE FROM #__photo_flags WHERE photo_id = ".$photo_id);
                      
$messages[] = 'Photo unflagged!';
                      break;
                  case 
'delete':
                      
$this->delete_photo($photo_id);
                      
$messages[] = 'Photo deleted!';
                      break;
                  case 
'suspend':
                  case 
'publish':
                      
$status     = ($action == 'publish') ? 1 : 0;
                      
$msg        = ($action == 'publish') ? 'published' : 'suspended';
                      
$this->db->query("UPDATE #__photo
                                        SET status = '"
.$status."'
                                        WHERE photo_id = "
.$photo_id."
                                        LIMIT 1"
);
                      
$messages[] = 'Photo '.$msg.'!';
                      break;
                  default:
                      
$errors[] = 'Invalid action! What exactly did you click!?';
              }
        }

        if (
$photo_id) {
            
$this->db->query("SELECT status, flagged
                              FROM #__photo
                              WHERE photo_id = "
.$photo_id."
                              LIMIT 1"
);
            if (
$this->db->affected_rows()) {
                  
$tpl->photo            = $this->db->fetch_assoc();
                
$page                = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
                
$sql_count            = "SELECT COUNT(*) AS total_flags
                                         FROM #__photo_flags
                                         WHERE photo_id = "
.$photo_id;
                  
$total_flags           = $this->db->get_field($sql_count, 'total_flags');
                  
$tpl->pagination    = VPagination::get($page, $total_flags, 10);
                  
$sql                = "SELECT vf.*, u.username
                                         FROM #__photo_flags AS vf
                                           LEFT JOIN #__user AS u ON (u.user_id = vf.user_id)
                                           WHERE vf.photo_id = "
.$photo_id."
                                         ORDER BY vf.flag_id DESC
                                         LIMIT "
.$tpl->pagination['limit'];
                  
$tpl->flags         = $this->db->get_rows($sql);
              }
        }
    
        
$tpl->menu                = 'photo';
        
$tpl->submenu            = 'photo_flags';
        
$tpl->meta_title        = 'Admin::Photo::View::Flags';
        
$tpl->errors            = $errors;
        
$tpl->messages            = $messages;
        
$tpl->photo_id            = $photo_id;
        
$tpl->reasons            = $reasons;
        
$tpl->load(array('header', 'photo_flags', 'footer'));
        
$tpl->display();
    }
    
    private function 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key, 'checkbox_flag_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_flag_', '', $key);
            }
        }

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