Вход Регистрация
Файл: adultscript-2.0.3-pro/files/admin/modules/photo/components/photo_comments.php
Строк: 110
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VComponent_Admin_photo_photo_comments extends VModule_Admin_photo
{
    public function 
__construct()
    {
        
parent::__construct();
    }
    
    public function 
render()
    {
        
$photo_id    = (isset($_GET['id'])) ? (int) trim($_GET['id']) : 0;
        
$page        = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
        
$comments    = array();
        
$pagination    = array();
        
$errors        = array();
        
$messages    = array();

        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') ? 1;
                        
$msg    = ($action == 'suspend') ? 'suspended' 'activated';
                        
$this->db->query("UPDATE #__photo_comments SET status = '".$status."' WHERE comment_id = ".$comment_id." LIMIT 1");
                        
$messages[] = 'Comment '.$msg.'!';
                        break;
                    case 
'delete':
                          
$this->db->query("DELETE FROM #__photo_comments WHERE comment_id = ".$comment_id." LIMIT 1");
                        
$this->db->query("UPDATE #__photo SET total_comments = total_comments-1 WHERE photo_id = ".$photo_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') ? 1;
                        
$msg    = ($action == 'suspend') ? 'suspended' 'activate';
                        
$this->db->query("UPDATE #__photo_comments SET status = '".$status."' WHERE comment_id IN (".implode(','array_values($ids)).")");
                        
$messages[] = 'Selected comments '.$msg.'!';
                        break;
                    case 
'delete':
                          
$this->db->query("DELETE FROM #__photo_comments WHERE comment_id IN (".implode(','array_values($ids)).")");
                        
$this->db->query("UPDATE #__photo SET total_comments = total_comments-".count($ids)." WHERE photo_id = ".$photo_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 #__photo_comments WHERE photo_id = ".$photo_id;
        
$total_comments    $this->db->get_field($sql_count'total_comments');
        
$pagination        VPagination::get($page$total_comments10);
        
$sql            "SELECT c.*, u.username
                           FROM #__photo_comments AS c
                           LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
                           WHERE c.photo_id = "
.$photo_id."
                           ORDER BY c.comment_id DESC
                           LIMIT "
.$pagination['limit'];
        
$comments        $this->db->get_rows($sql);
        
        
$tpl VF::factory('template');
        
$tpl->menu            'photo';
        
$tpl->submenu        'photo_manage';
        
$tpl->amenu            'photo_comments';
        
$tpl->meta_title    'Admin::Photo::Comments';
        
$tpl->errors        $errors;
        
$tpl->messages        $messages;
        
$tpl->photo_id        $photo_id;
        
$tpl->comments        $comments;
        
$tpl->pagination    $pagination;
        
$tpl->load(array('header''photo_comments''footer'));
        
$tpl->display();
    }

    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
Реклама