![]() 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/ |
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: auth/login_new.php');
exit;
}
// Check if form was submitted
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: index.php#create');
exit;
}
// SECURITY: CSRF Protection
require_once 'includes/security.php';
$csrf_token = $_POST['csrf_token'] ?? '';
if (!validateCSRFToken($csrf_token)) {
error_log("SECURITY: CSRF token validation failed in create_lyrics.php from IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown'));
$_SESSION['error'] = 'Security validation failed. Please refresh the page and try again.';
header('Location: index.php#create');
exit;
}
require_once 'config/database.php';
require_once 'api_functions.php';
require_once 'includes/translations.php';
$pdo = getDBConnection();
$api = new APIBoxFunctions('63edba40620216c5aa2c04240ac41dbd');
// Get form data
$prompt = $_POST['prompt'] ?? '';
$title = $_POST['title'] ?? 'Untitled Lyrics';
$theme = $_POST['theme'] ?? '';
$style = $_POST['style'] ?? '';
$language = $_POST['language'] ?? 'English';
$rhymeScheme = $_POST['rhymeScheme'] ?? '';
$hookFrequency = $_POST['hookFrequency'] ?? '';
$verseChorusRatio = $_POST['verseChorusRatio'] ?? '';
$bridge = $_POST['bridge'] ?? '';
$outroStyle = $_POST['outroStyle'] ?? '';
$buildUps = $_POST['buildUps'] ?? '';
$transitions = $_POST['transitions'] ?? '';
$quality = $_POST['quality'] ?? '';
$mood = $_POST['mood'] ?? '';
$energy = $_POST['energy'] ?? '';
$excitement = $_POST['excitement'] ?? '';
$danceability = $_POST['danceability'] ?? '';
$tags = $_POST['tags'] ?? '';
// Validate input
if (empty($prompt)) {
$_SESSION['error'] = 'Please provide a lyrics description.';
header('Location: index.php#create');
exit;
}
// Calculate credit cost
$creditCost = 1; // Simple lyrics generation
// Check user credits
$stmt = $pdo->prepare("SELECT credits FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch();
if (!$user || $user['credits'] < $creditCost) {
// Check if user has enough credits
if (!$user || $user['credits'] < $creditCost) {
error_log("Insufficient credits for user {$_SESSION['user_id']}: has {$user['credits']}, needs $creditCost");
$_SESSION['error'] = "Insufficient credits. You need $creditCost credits to generate lyrics. Please purchase credits to continue.";
header('Location: index.php#create');
exit;
}
$user['credits'] = $_SESSION['credits'];
}
// Create track record
$temp_task_id = 'lyrics_' . time() . '_' . $_SESSION['user_id'] . '_' . uniqid();
$metadata = json_encode([
'theme' => $theme,
'style' => $style,
'language' => $language,
'rhymeScheme' => $rhymeScheme,
'hookFrequency' => $hookFrequency,
'verseChorusRatio' => $verseChorusRatio,
'bridge' => $bridge,
'outroStyle' => $outroStyle,
'buildUps' => $buildUps,
'transitions' => $transitions,
'quality' => $quality,
'mood' => $mood,
'energy' => $energy,
'excitement' => $excitement,
'danceability' => $danceability,
'tags' => $tags
]);
$track_id = $api->createTrackRecord($_SESSION['user_id'], $temp_task_id, $title, $prompt, 'lyrics', json_decode($metadata, true));
// Deduct credits
$newCredits = $user['credits'] - $creditCost;
$stmt = $pdo->prepare("UPDATE users SET credits = ? WHERE id = ?");
$stmt->execute([$newCredits, $_SESSION['user_id']]);
// Record credit transaction
$stmt = $pdo->prepare("
INSERT INTO credit_transactions (user_id, amount, type, description, created_at)
VALUES (?, ?, 'usage', 'Lyrics generation: $title', NOW())
");
$stmt->execute([$_SESSION['user_id'], -$creditCost]);
$_SESSION['credits'] = $newCredits;
// Call the lyrics generation API
$api_data = [
'prompt' => $prompt,
'title' => $title,
'callBackUrl' => 'https://soundstudiopro.com/callback.php'
];
// Add additional parameters if provided
if ($theme) $api_data['theme'] = $theme;
if ($style) $api_data['style'] = $style;
if ($language) $api_data['language'] = $language;
if ($rhymeScheme) $api_data['rhymeScheme'] = $rhymeScheme;
if ($hookFrequency) $api_data['hookFrequency'] = $hookFrequency;
if ($verseChorusRatio) $api_data['verseChorusRatio'] = $verseChorusRatio;
if ($bridge) $api_data['bridge'] = $bridge;
if ($outroStyle) $api_data['outroStyle'] = $outroStyle;
if ($buildUps) $api_data['buildUps'] = $buildUps;
if ($transitions) $api_data['transitions'] = $transitions;
if ($quality) $api_data['quality'] = $quality;
if ($mood) $api_data['mood'] = $mood;
if ($energy) $api_data['energy'] = $energy;
if ($excitement) $api_data['excitement'] = $excitement;
if ($danceability) $api_data['danceability'] = $danceability;
if ($tags) $api_data['tags'] = $tags;
$result = $api->generateLyrics($api_data);
if (isset($result['error'])) {
error_log("Lyrics generation error: " . json_encode($result));
$_SESSION['success'] = t('success.lyrics_generation.started');
} else {
// Extract task ID from response
$real_task_id = $result['taskId'] ?? $result['id'] ?? $result['data']['taskId'] ?? $temp_task_id;
// Update track with real task ID
$stmt = $pdo->prepare("UPDATE music_tracks SET task_id = ? WHERE id = ?");
$stmt->execute([$real_task_id, $track_id]);
$_SESSION['success'] = t('success.lyrics_generation.started');
}
// Redirect back to the create page with success message
header('Location: index.php#create');
exit;
?>