Файл: adultscript-2.0.3-pro/files/admin/modules/video/components/mass_update.php
Строк: 217
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_Admin_video_mass_update extends VModule_Admin_video
{
private $db;
public function __construct()
{
$this->db = VF::factory('database');
}
public function render()
{
$errors = array();
$messages = array();
$ids = array();
if (isset($_POST['videos']) && is_array($_POST['videos'])) {
$ids = $_POST['videos'];
}
$ids_in = implode(',', array_values($ids));
if (empty($ids)) {
$errors[] = 'Please selected at least one video to edit!';
}
$mass = array(
'username' => '',
'channel_id' => 'none',
'advertising' => 'none',
'categories' => array(),
'category_method' => 'none',
'allow_rating' => 'none',
'allow_comment' => 'none',
'allow_download' => 'none',
'total_views' => '',
'total_downloads' => '',
'total_favorites' => '',
'total_comments' => '',
'rating' => '',
'rated_by' => '',
'type' => 'none',
'mobile' => 'none',
'premium' => 'none',
'price' => '',
'add_date' => '',
'view_date' => '',
'shedule_date' => '',
'status' => 'none',
);
if (isset($_POST['submit-edit'])) {
$filter = VF::factory('filter');
$username = $filter->get('username');
$channel_id = $filter->get('channel_id');
$advertising = $filter->get('advertising');
$categories = (isset($_POST['category'])) ? (array) $_POST['category'] : array();
$type = $filter->get('type');
$allow_rating = $filter->get('allow_rating');
$allow_comment = $filter->get('allow_comment');
$allow_download = $filter->get('allow_download');
$total_views = $filter->get('total_views');
$total_comments = $filter->get('total_comments');
$total_downloads = $filter->get('total_downloads');
$total_favorites = $filter->get('total_favorites');
$rating = $filter->get('rating');
$rated_by = $filter->get('rated_by');
$premium = $filter->get('premium');
$price = $filter->get('price');
$add_date = $filter->get('add_date');
$view_date = $filter->get('view_date');
$shedule_date = $filter->get('shedule_date');
$status = $filter->get('status');
$mobile = $filter->get('mobile');
$sql = array();
if ($username != '') {
$this->db->query("SELECT user_id
FROM #__user
WHERE username = '".$this->db->escape($username)."'
AND status = '1'
LIMIT 1");
if ($this->db->affected_rows()) {
$user_id = (int) $this->db->fetch_field('user_id');
$sql[] = "user_id = ".$user_id;
}
}
if ($channel_id != 'none') {
$sql[] = "channel_id = ".(int) $channel_id;
}
if ($advertising != 'none') {
$sql[] = "adv = ".(int) $advertising;
}
if ($type != 'none') {
$sql[] = "type = '".$this->db->escape($type)."'";
}
if ($allow_rating != 'none') {
$sql[] = "allow_rating = '".(int) $allow_rating."'";
}
if ($allow_comment != 'none') {
$sql[] = "allow_rating = '".(int) $allow_comment."'";
}
if ($allow_download != 'none') {
$sql[] = "allow_rating = '".(int) $allow_download."'";
}
if ($total_views != '') {
$sql[] = "total_views = ".(int) $total_views;
}
if ($total_downloads != '') {
$sql[] = "total_downloads = ".(int) $total_downloads;
}
if ($total_comments != '') {
$sql[] = "total_comments = ".(int) $total_comments;
}
if ($total_favorites != '') {
$sql[] = "total_favorites = ".(int) $total_favorites;
}
if ($rating != '') {
$sql[] = "rating = ".(float) $rating;
}
if ($rated_by != '') {
$sql[] = "rated_by = ".(int) $rated_by;
}
if ($premium != 'none') {
$sql[] = "premium = '".(int) $premium."'";
}
if ($price != '') {
$sql[] = "price = ".(float) $price;
}
if ($add_date != '') {
if ($add_time = strtotime($add_date) !== FALSE) {
$sql[] = "add_date = '".$this->db->escape($add_date.' 00:00:00')."'";
$sql[] = "add_time = ".$add_time;
} else {
$errors[] = 'Invalid add date supplied! Use format: yy mm dd!';
}
}
if ($view_date != '') {
if ($view_time = strtotime($view_date) !== FALSE) {
$sql[] = "view_date = '".$this->db->escape($view_date.' 00:00:00')."'";
$sql[] = "view_time = ".$view_time;
} else {
$errors[] = 'Invalid view date supplied! Use format: yy mm dd!';
}
}
if ($status != 'none') {
$sql[] = "status = ".$status;
}
if ($mobile != 'none') {
$sql[] = "mobile = '".$mobile."'";
}
if ($channel_id != 'none') {
$channel_id = (int) $channel_id;
foreach ($ids as $video_id) {
$this->db->query("
SELECT channel_id
FROM #__video
WHERE video_id = ".$video_id."
AND channel_id != ".$channel_id."
LIMIT 1
");
if ($this->db->affected_rows()) {
$o_channel_id = (int) $this->db->fetch_field('channel_id');
if ($o_channel_id === 0) {
$this->db->query("UPDATE #__channel
SET total_videos = total_videos+1,
last_add_time = ".time()."
WHERE channel_id = ".$channel_id."
LIMIT 1");
} elseif ($channel_id === 0) {
$this->db->query("UPDATE #__channel
SET total_videos = total_videos-1
WHERE channel_id = ".$o_channel_id."
LIMIT 1");
} else {
$this->db->query("UPDATE #__channel
SET total_videos = total_videos+1,
last_add_time = ".time()."
WHERE channel_id = ".$channel_id."
LIMIT 1");
$this->db->debug();
$this->db->query("UPDATE #__channel
SET total_videos = total_videos-1
WHERE channel_id = ".$o_channel_id."
LIMIT 1");
}
}
}
}
if (!empty($sql)) {
$this->db->query("UPDATE #__video
SET ".implode(',', $sql)."
WHERE video_id IN (".$ids_in.")");
$messages[] = "You have updated ".$this->db->affected_rows()." videos!";
}
if (!empty($categories)) {
foreach ($ids as $video_id) {
$this->db->query("SELECT cat_id
FROM #__video_category
WHERE video_id = ".$video_id);
if ($this->db->affected_rows()) {
$categs = $this->db->fetch_rows();
foreach ($categs as $categ) {
$this->db->query("UPDATE #__video_categories
SET total_videos = total_videos-1
WHERE cat_id = ".(int) $categ['cat_id']."
LIMIT 1");
}
}
}
$this->db->query("DELETE FROM #__video_category
WHERE video_id IN (".$ids_in.")");
foreach ($categories as $category) {
$cat_id = (int) $category;
foreach ($ids as $video_id) {
$this->db->query("INSERT INTO #__video_category
SET video_id = ".$video_id.",
cat_id = ".$cat_id);
$this->db->query("UPDATE #__video_categories
SET total_videos = total_videos+1
WHERE cat_id = ".$cat_id."
LIMIT 1");
}
}
$messages[] = 'Categories updated for selected videos!';
if ($shedule_date != '') {
foreach ($ids as $video_id) {
$this->db->query("INSERT INTO #__video_shedule
SET video_id = ".$video_id.",
shedule_date = '".$this->db->escape($shedule_date)."'");
}
$messages[] = 'You have sheduled '.count($ids).' videos to go live on '.$shedule_date.'!';
}
}
if (empty($messages)) {
$messages[] = 'No changes!';
}
}
$tpl = VF::factory('template');
$tpl->menu = 'video';
$tpl->submenu = 'video_manage';
$tpl->meta_title = 'Admin::Video::Manage';
$tpl->errors = $errors;
$tpl->messages = $messages;
$tpl->ids = $ids;
$tpl->mass = $mass;
$tpl->categories = $this->get_video_categories();
$tpl->channels = VModel::load('channel', 'channel', true)->channels(array('c.channel_id', 'c.name'));
$tpl->advertising = $this->get_video_advertising();
$tpl->statuses = array(
'0' => 'Suspended',
'1' => 'Published',
'2' => 'Waiting Approval',
'3' => 'Uploading',
'4' => 'Converting',
'5' => 'Grabbing',
'6' => 'Queued',
'7' => 'Error'
);
$tpl->load(array('header', 'video_mass_update', 'footer'));
$tpl->display();
}
private function get_video_categories()
{
$this->db->query("SELECT cat_id, parent_id, name
FROM #__video_categories
ORDER BY slug ASC");
return $this->db->fetch_rows();
}
private function get_video_advertising()
{
$this->db->query("SELECT adv_group_id
FROM #__adv_groups
WHERE adv_group_slug = 'video-player'
LIMIT 1");
if ($this->db->affected_rows()) {
$adv_group_id = (int) $this->db->fetch_field('adv_group_id');
$this->db->query("SELECT adv_id, adv_name
FROM #__adv
WHERE adv_group_id = ".$adv_group_id);
return $this->db->fetch_rows();
}
return array();
}
}