Файл: adultscript-2.0.3-pro/files/admin/modules/pornstar/components/photos.php
Строк: 97
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_pornstar_photos
{
private $filter;
private $pcfg;
private $db;
private $model_id;
public function __construct()
{
$this->db = VF::factory('database');
$this->filter = VF::factory('filter');
$this->pcfg = VF::cfg('module.photo');
}
public function render()
{
$errors = array();
$messages = array();
$warnings = array();
if (isset($_POST['action']) && isset($_POST['album_id'])) {
$action = $this->filter->get('action');
$album_id = (int) trim($_POST['album_id']);
if ($album_id) {
if ($action == 'suspend' OR $action == 'activate') {
$status = ($action == 'suspend') ? 0 : 1;
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$this->db->query("UPDATE #__photo_albums SET status = '".$status."' WHERE album_id = ".$album_id." LIMIT 1");
$messages[] = 'Album '.$msg.'!';
} elseif ($action == 'delete') {
$this->delete_album($album_id);
$messages[] = 'Album deleted!';
} elseif ($action == 'unassign') {
$this->db->query("UPDATE #__photo_albums SET adv = 0 WHERE album_id = ".$album_id." LIMIT 1");
$messages[] = 'Banner unassigned!';
} else {
$errors[] = 'Invalid action! What exactly did you click!?';
}
} else {
$errors[] = 'Invalid album id! Are you sure this album exists!?';
}
}
if (isset($_POST['submit_actions'])) {
$action = $this->filter->get('action');
$ids = $this->get_checkbox_ids();
if ($ids) {
if ($action == 'suspend' OR $action == 'activate') {
$status = ($action == 'suspend') ? 0 : 1;
$msg = ($action == 'suspend') ? 'suspended' : 'activated';
$this->db->query("UPDATE #__photo_albums SET status = '".$status."' WHERE album_id IN (".implode(',', $ids).")");
$messages[] = 'Selected albums '.$msg.'!';
} elseif ($action == 'delete') {
foreach ($ids as $id) {
$this->delete_album($id);
}
$messages[] = 'Selected albums deleted!';
} elseif ($action == 'unassign') {
$this->db->query("UPDATE #__photo_albums SET adv = 0 WHERE album_id IN (".implode(',', $ids).")");
$messages[] = 'Removed advertising from selected albums!';
} else {
$errors[] = 'Invalid action! What exactly did you select!?';
}
} else {
$errors[] = 'Please select at least one album!';
}
}
$model_id = (isset($_GET['id']) && is_numeric($_GET['id'])) ? (int) trim($_GET['id']) : 0;
$page = (isset($_GET['page']) && is_numeric($_GET['page'])) ? (int) $_GET['page'] : 1;
$sql_count = "SELECT COUNT(*) AS total_albums
FROM #__model_albums AS m
WHERE m.model_id = ".$model_id;
$albums_total = $this->db->get_field($sql_count, 'total_albums');
$pagination = VPagination::get($page, $albums_total, 20);
$sql = "SELECT a.album_id, a.title, a.total_photos, a.total_views, a.rating, a.rated_by,
a.status, a.flagged, a.add_date, u.username,
GROUP_CONCAT(pc.cat_id) AS category,
GROUP_CONCAT(c.name) AS name
FROM #__model_albums AS m
INNER JOIN #__photo_albums AS a ON (a.album_id = m.album_id)
LEFT JOIN #__photo_category AS pc ON (pc.album_id = a.album_id)
LEFT JOIN #__user AS u ON (u.user_id = a.user_id)
LEFT JOIN #__photo_categories AS c ON (c.cat_id = pc.cat_id)
WHERE m.model_id = ".$model_id;
$albums = $this->db->get_rows($sql." LIMIT ".$pagination['limit']);
$tpl = VF::factory('template');
$tpl->menu = 'pornstar';
$tpl->submenu = 'pornstar_photos';
$tpl->meta_title = 'Admin::Pornstar::Albums';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->warnings = $warnings;
$tpl->albums = $albums;
$tpl->pagination = $pagination;
$tpl->categories = $this->get_photo_categories();
$tpl->load(array('header', 'pornstar_photos', 'footer'));
$tpl->display();
}
private function get_checkbox_ids()
{
$ids = array();
foreach ($_POST as $key => $value) {
if (strpos($key, 'checkbox_album_') !== FALSE) {
$ids[] = (int) str_replace('checkbox_album_', '', $key);
}
}
return $ids;
}
private function get_photo_categories()
{
$this->db->query("SELECT cat_id, name, description, total_albums
FROM #__photo_categories
ORDER BY name ASC");
return $this->db->fetch_rows();
}
}
?>