Файл: adultscript-2.0.3-pro/files/admin/templates/default/extend/ajax/manage_player.plugin.php
Строк: 72
<?php
defined('_VALID') or die('Restricted Access!');
function ajax_plugin_manage_player()
{
$data = array('status' => 0, 'code' => '', 'msg' => '', 'debug' => '');
if (isset($_POST['video_id']) OR isset($_POST['options'])) {
$video_id = (isset($_POST['video_id'])) ? (int) trim($_POST['video_id']) : NULL;
if (isset($_POST['options'])) {
parse_str($_POST['options'], $options);
$video_id = (int) $options['video_id'];
}
$db = VF::factory('database');
$db->query("SELECT video_id FROM #__video WHERE video_id = ".$video_id." LIMIT 1");
if ($db->affected_rows()) {
if (isset($options)) {
$adv_text_id = (int) $options['adv_text'];
$adv_image_id = (int) $options['adv_image'];
$adv_video = (array) $options['adv_video'];
$db->query("DELETE FROM #__adv_player_video
WHERE video_id = ".$video_id);
$db->query("INSERT INTO #__adv_player_video
SET video_id = ".$video_id.",
type = 'text',
adv_id = ".$adv_text_id);
$db->query("INSERT INTO #__adv_player_video
SET video_id = ".$video_id.",
type = 'image',
adv_id = ".$adv_image_id);
foreach ($adv_video as $key => $value) {
$db->query("INSERT INTO #__adv_player_video
SET video_id = ".$video_id.",
type = 'video',
adv_id = ".(int) $value);
}
}
$db->query("SELECT adv_id, adv_name
FROM #__adv_player
WHERE type = 'text'
AND status = '1'");
$advs_text = $db->fetch_rows();
$db->query("SELECT adv_id, adv_name
FROM #__adv_player
WHERE type = 'image'
AND status = '1'");
$advs_image = $db->fetch_rows();
$db->query("SELECT adv_id, adv_name, position
FROM #__adv_player
WHERE type = 'video'
AND status = '1'");
$advs_video = $db->fetch_rows();
$db->query("SELECT adv_id, type
FROM #__adv_player_video
WHERE video_id = ".$video_id);
$advs = $db->fetch_rows();
$adv_text = NULL;
$adv_img = NULL;
$adv_video = array();
foreach ($advs as $adv) {
if ($adv['type'] == 'text') {
$adv_text = $adv['adv_id'];
}
if ($adv['type'] == 'image') {
$adv_img = $adv['adv_id'];
}
if ($adv['type'] == 'video') {
$adv_video[$adv['adv_id']] = 1;
}
}
$code = array();
$code[] = '<form id="manage-player-form" method="post" action="'.BASE_URL.'/?q=ajax&s=manage_player&d=backend">';
$code[] = '<input name="video_id" type="hidden" id="video_id" value="'.$video_id.'" />';
$code[] = '<fieldset>';
$code[] = '<legend>Text Advertising</legend>';
$code[] = '<select name="adv_text" id="adv_text">';
$code[] = '<option value="0">None</option>';
foreach ($advs_text as $adv) {
$selected = ($adv['adv_id'] == $adv_text) ? ' selected="selected"' : '';
$code[] = '<option value="'.$adv['adv_id'].'"'.$selected.'>'.e($adv['adv_name']).'</option>';
}
$code[] = '</select>';
$code[] = '</fieldset>';
$code[] = '<fieldset>';
$code[] = '<legend>Image Advertising</legend>';
$code[] = '<select name="adv_image" id="adv_image">';
$code[] = '<option value="0">None</option>';
foreach ($advs_image as $adv) {
$selected = ($adv['adv_id'] == $adv_img) ? ' selected="selected"' : '';
$code[] = '<option value="'.$adv['adv_id'].'"'.$selected.'>'.e($adv['adv_name']).'</option>';
}
$code[] = '</select>';
$code[] = '</fieldset>';
$code[] = '<fieldset>';
$code[] = '<legend>Video Advertising</legend>';
$code[] = '<select name="adv_video[]" id="adv_video" multiple size="10" style="min-height: 100px;">';
$code[] = '<option value="0">None</option>';
foreach ($advs_video as $adv) {
$selected = (isset($adv_video[$adv['adv_id']])) ? ' selected="selected"' : '';
$type = ($adv['position'] == '0') ? 'pre-roll' : 'mid-roll';
$type = ($adv['position'] == '-1') ? 'post-roll' : $type;
$code[] = '<option value="'.$adv['adv_id'].'"'.$selected.'>'.e($adv['adv_name']).' ('.$type.')</option>';
}
$code[] = '</select>';
$code[] = '</fieldset>';
$code[] = '</form>';
$data['status'] = 1;
$data['code'] = implode("n", $code);
} else {
$data['code'] = '<div class="none">Invalid video! What exactly did you click!?</div>';
}
} else {
$data['msg'] = 'Invalid ajax request!';
}
return json_encode($data);
}