![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/studio/ |
<?php
session_start();
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../api_functions.php';
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php');
exit;
}
// Get user data
$pdo = getDBConnection();
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if (!$user) {
$_SESSION['error'] = 'User not found';
header('Location: /studio.php');
exit;
}
// Check credits (2 credits for Boost Style)
$creditCost = 2;
if ($user['credits'] < $creditCost) {
$_SESSION['error'] = "Insufficient credits. You need $creditCost credits to boost style.";
header('Location: /studio.php');
exit;
}
// Get form data
$title = trim($_POST['title'] ?? '');
$trackId = $_POST['track_id'] ?? null;
$audioUrl = trim($_POST['audioUrl'] ?? '');
$audioFile = $_FILES['audioFile'] ?? null;
$content = trim($_POST['content'] ?? ''); // Style description
if (empty($title) || empty($content)) {
$_SESSION['error'] = 'Track title and style description are required';
header('Location: /studio.php');
exit;
}
// Determine audio source
$finalAudioUrl = null;
if ($trackId) {
$stmt = $pdo->prepare("SELECT audio_url FROM music_tracks WHERE id = ? AND user_id = ?");
$stmt->execute([$trackId, $_SESSION['user_id']]);
$track = $stmt->fetch();
if ($track && $track['audio_url']) {
$finalAudioUrl = $track['audio_url'];
}
}
if (!$finalAudioUrl && $audioUrl) {
$finalAudioUrl = $audioUrl;
}
if (!$finalAudioUrl && $audioFile && $audioFile['error'] === UPLOAD_ERR_OK) {
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
$fileName = time() . '_' . $_SESSION['user_id'] . '_' . basename($audioFile['name']);
$uploadPath = $uploadDir . $fileName;
if (move_uploaded_file($audioFile['tmp_name'], $uploadPath)) {
$finalAudioUrl = 'https://soundstudiopro.com/' . $uploadPath;
} else {
$_SESSION['error'] = 'Failed to upload audio file.';
header('Location: /studio.php');
exit;
}
}
if (!$finalAudioUrl) {
$_SESSION['error'] = 'Please provide an audio track';
header('Location: /studio.php');
exit;
}
// Deduct credits
$newCredits = $user['credits'] - $creditCost;
$stmt = $pdo->prepare("UPDATE users SET credits = ? WHERE id = ?");
$stmt->execute([$newCredits, $_SESSION['user_id']]);
$stmt = $pdo->prepare("
INSERT INTO credit_transactions (user_id, amount, type, description, created_at)
VALUES (?, ?, 'usage', 'Boost Style: $title', NOW())
");
$stmt->execute([$_SESSION['user_id'], -$creditCost]);
$_SESSION['credits'] = $newCredits;
// Initialize API
$api_key = '63edba40620216c5aa2c04240ac41dbd';
$api = new APIBoxFunctions($api_key);
// Create track record
$temp_task_id = 'boost_style_' . time() . '_' . $_SESSION['user_id'] . '_' . uniqid();
$metadata = [
'original_audio_url' => $finalAudioUrl,
'style_description' => $content
];
$track_id = $api->createTrackRecord($_SESSION['user_id'], $temp_task_id, $title, $content, 'boost_style', $metadata);
// Prepare API request - Based on API.box boost-style endpoint
$api_params = [
'content' => $content, // Style description
'callBackUrl' => 'https://soundstudiopro.com/callback.php'
];
// Note: The boost-style API might need audioUrl in a different format
// Check API.box docs for exact parameter structure
if ($finalAudioUrl) {
$api_params['audioUrl'] = $finalAudioUrl;
}
// Call Boost Style API
$result = $api->boostMusicStyle($api_params);
if (isset($result['error'])) {
error_log("Boost Style API error: " . json_encode($result));
$_SESSION['error'] = 'Failed to boost style. Please try again.';
header('Location: /studio.php');
exit;
}
$_SESSION['success'] = "Style is being boosted. You'll be notified when it's ready!";
header('Location: /studio.php');
exit;
?>