Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/comment.php
Строк: 111
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_video_comment 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();
        
$video_id     = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
        
$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']);
            
$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':
                        
$this->db->query("DELETE FROM #__video_comments
                                          WHERE comment_id IN ("
.implode(',', array_values($ids)).")");
                        
$this->db->query("UPDATE #__video
                                          SET total_comments = total_comments-"
.count($ids)."
                                          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 WHERE video_id = ".$video_id;
        
$total_comments    = $this->db->get_field($sql_count, 'total_comments');
        
$pagination        = VPagination::get($page, $total_comments, 10);
        
$sql            = "SELECT c.*, u.username
                           FROM #__video_comments AS c
                           LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
                           WHERE c.video_id = "
.$video_id."
                           ORDER BY c.comment_id DESC
                           LIMIT "
.$pagination['limit'];
        
$comments        = $this->db->get_rows($sql);
    
        
$tpl->menu                = 'video';
        
$tpl->submenu            = 'video_comment';
        
$tpl->meta_title        = 'Admin::Video::View::Comments';
        
$tpl->vcfg                = VF::cfg('module.video');
        
$tpl->errors            = $errors;
        
$tpl->messages            = $messages;
        
$tpl->video_id            = $video_id;
        
$tpl->comments            = $comments;
        
$tpl->pagination        = $pagination;
        
$tpl->load(array('header', 'video_comment', '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
Реклама