<?php
/**
 * Поиск MP3 (ВКонтакте)
 *
 * Автор: byvlad
 * Версия: 2.12
 * Стоимость: 400 WMR
 */

require_once ('system/core.php');		// Ядро скрипта
require_once ('system/functions.php');	// Функции скрипта

/**
* Конвертирование
*/

$query = $mysqli -> query("SELECT * FROM `songs` WHERE `id` = " . $_GET['id']) -> fetch_assoc();
$arr_files = array('mp3_320', 'mp3_256', 'mp3_192', 'mp3_160', 'mp3_128', 'mp3_64', 'mp3_32');
$extdir = dirname($_SERVER['REQUEST_URI'])=='/' ? dirname($_SERVER['REQUEST_URI']) : dirname($_SERVER['REQUEST_URI']).'/';

if(!in_array($_POST['bitrate'], $arr_files) or $query['original'] != 'yes')
    die('Fatal error!');

if($query[$_POST['bitrate']] != 'no') {
	header('Location: http://' . $_SERVER['SERVER_NAME'] . $extdir . 'view_' . $query['id'] . '.html?repeat');
	exit;
}

if($config['captcha'] and $_SESSION['code2'] != $_POST['code']) {
	header('Location: http://' . $_SERVER['SERVER_NAME'] . $extdir . 'view_' . $query['id'] . '.html?captcha_error');
	exit;
}

$mysqli -> query("UPDATE `songs` SET `".$_POST['bitrate']."` = 'started' WHERE `id` = " . $query['id']);
runExternal("php -f ".dirname(__FILE__)."/run.php ".$_POST['bitrate']." ".$query['id']."  >/dev/null 2>/dev/null &");

header('Location: http://' . $_SERVER['SERVER_NAME'] . $extdir . 'view_' . $query['id'] . '.html?' . rand(0, 100));
exit;
?>