Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/comments.php
Строк: 115
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_video_comments extends VModule_Admin_video
{
    protected 
$db;
    public function 
__construct()
    {
        
$this->db    = VF::factory('database');
    }
    
    public function 
render()
    {
        
$tpl        = VF::factory('template');
        
        
$errors        = array();
        
$messages    = array();
        
$comments    = array();
        
$page        = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 0;
        
$categories = $this->get_video_categories();
        
        if (isset(
$_POST['action']) && isset($_POST['comment_id'])) {
            
$action     = trim($_POST['action']);
            
$video_id    = (int) trim($_POST['video_id']);
            
$comment_id    = (int) trim($_POST['comment_id']);
            if (
$comment_id) {
                switch (
$action) {
                    case 
'suspend':
                    case 
'activate':
                        
$status = ($action == 'suspend') ? 0 : 1;
                        
$msg    = ($action == 'suspend') ? 'suspended' : 'activated';
                        
$this->db->query("UPDATE #__video_comments
                                          SET status = '"
.$status."'
                                          WHERE comment_id = "
.$comment_id."
                                          LIMIT 1"
);
                        
$messages[] = 'Comment '.$msg.'!';
                        break;
                    case 
'delete':
                        
$this->db->query("DELETE FROM #__video_comments
                                          WHERE comment_id = "
.$comment_id."
                                          LIMIT 1"
);
                        
$this->db->query("UPDATE #__video
                                          SET total_comments = total_comments-1
                                          WHERE video_id = "
.$video_id."
                                          LIMIT 1"
);
                        
$messages[] = 'Comment deleted!';
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you click!?';
                }
            } else {
                
$errors[] = 'Invalid comment! What exactly did you click!?';
            }
        }
        
        if (isset(
$_POST['submit_actions'])) {
            if (
$ids = $this->get_checkbox_ids()) {
                
$action = trim($_POST['action']);
                switch (
$action) {
                    case 
'activate':
                    case 
'suspend':
                        
$status = ($action == 'suspend') ? 0 : 1;
                        
$msg    = ($action == 'suspend') ? 'suspended' : 'activate';
                        
$this->db->query("UPDATE #__video_comments
                                          SET status = '"
.$status."'
                                          WHERE comment_id IN ("
.implode(',', array_values($ids)).")");
                        
$messages[] = 'Selected comments '.$msg.'!';
                        break;
                    case 
'delete':
                        foreach (
$ids as $comment_id) {
                            
$this->db->query("SELECT video_id
                                              FROM #__video_comments
                                              WHERE comment_id = "
.$comment_id."
                                              LIMIT 1"
);
                            if (
$this->db->affected_rows()) {
                                
$video_id    = (int) $this->db->fetch_field('video_id');
                                
$this->db->query("DELETE FROM #__video_comments
                                                  WHERE comment_id = "
.$comment_id."
                                                  LIMIT 1"
);
                                
$this->db->query("UPDATE #__video
                                                  SET total_comments = total_comments-1
                                                  WHERE video_id = "
.$video_id."
                                                  LIMIT 1"
);
                            }
                        }
                    
                        
$messages[] = 'Selected comments deleted!';
                        break;
                    default:
                        
$errors[] = 'Invalid action! What exactly did you select!?';
                }
            } else {
                
$errors[] = 'Please select at least one comment!';
            }
        }
        
        
$sql_count        = "SELECT COUNT(*) AS total_comments FROM #__video_comments";
        
$total_comments    = $this->db->get_field($sql_count, 'total_comments');
        
$pagination        = VPagination::get($page, $total_comments, 10);
        
$sql            = "SELECT c.*, u.username, v.title, v.slug
                           FROM #__video_comments AS c
                           LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
                           LEFT JOIN #__video AS v ON (v.video_id = c.video_id)
                           ORDER BY c.comment_id DESC
                           LIMIT "
.$pagination['limit'];
        
$comments        = $this->db->get_rows($sql);
    
        
$tpl->menu                = 'video';
        
$tpl->submenu            = 'video_comments';
        
$tpl->meta_title        = 'Admin::Video::Comments';
        
$tpl->vcfg                = VF::cfg('module.video');
        
$tpl->errors            = $errors;
        
$tpl->messages            = $messages;
        
$tpl->comments            = $comments;
        
$tpl->pagination        = $pagination;
        
$tpl->load(array('header', 'video_comments', '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 
get_checkbox_ids()
    {
        
$ids = array();
        foreach (
$_POST as $key => $value) {
            if (
strpos($key, 'checkbox_comment_') !== FALSE) {
                
$ids[] = (int) str_replace('checkbox_comment_', '', $key);
            }
        }

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