Файл: adultscript-2.0.3-pro/files/admin/modules/pornstar/components/comments.php
Строк: 108
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_pornstar_comments
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$tpl = VF::factory('template');
$errors = array();
$messages = array();
$comments = array();
$model_id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) $_GET['id'] : 0;
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 0;
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 #__model_comments
SET status = '".$status."'
WHERE comment_id = ".$comment_id."
LIMIT 1");
$messages[] = 'Comment '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__model_comments
WHERE comment_id = ".$comment_id."
LIMIT 1");
$this->db->query("UPDATE #__model
SET total_comments = total_comments-1
WHERE model_id = ".$model_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 #__model_comments
SET status = '".$status."'
WHERE comment_id IN (".implode(',', array_values($ids)).")");
$messages[] = 'Selected comments '.$msg.'!';
break;
case 'delete':
$this->db->query("DELETE FROM #__model_comments
WHERE comment_id IN (".implode(',', array_values($ids)).")");
$this->db->query("UPDATE #__model
SET total_comments = total_comments-".count($ids)."
WHERE model_id = ".$model_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 #__model_comments WHERE model_id = ".$model_id;
$total_comments = $this->db->get_field($sql_count, 'total_comments');
$pagination = VPagination::get($page, $total_comments, 10);
$sql = "SELECT c.*, u.username
FROM #__model_comments AS c
LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
WHERE c.model_id = ".$model_id."
ORDER BY c.comment_id DESC
LIMIT ".$pagination['limit'];
$comments = $this->db->get_rows($sql);
$tpl->menu = 'pornstar';
$tpl->submenu = 'pornstar_comments';
$tpl->meta_title = 'Admin::Model::View::Comments';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->model_id = $model_id;
$tpl->comments = $comments;
$tpl->pagination = $pagination;
$tpl->load(array('header', 'pornstar_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;
}
}
?>