![]() 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/private_html/api/ |
<?php
session_start();
header('Content-Type: application/json');
require_once '../config/database.php';
if (!isset($_SESSION['user_id'])) {
echo json_encode(['success' => false, 'error' => 'Not authenticated']);
exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo json_encode(['success' => false, 'error' => 'Invalid request method']);
exit;
}
$input = json_decode(file_get_contents('php://input'), true);
$crate_id = isset($input['crate_id']) ? (int)$input['crate_id'] : null;
$track_order = isset($input['track_order']) ? $input['track_order'] : [];
if (!$crate_id || !is_array($track_order)) {
echo json_encode(['success' => false, 'error' => 'Crate ID and track order are required']);
exit;
}
try {
$pdo = getDBConnection();
// Verify crate belongs to user
$stmt = $pdo->prepare("SELECT id FROM artist_playlists WHERE id = ? AND user_id = ?");
$stmt->execute([$crate_id, $_SESSION['user_id']]);
if (!$stmt->fetch()) {
echo json_encode(['success' => false, 'error' => 'Crate not found or access denied']);
exit;
}
// Update track positions
$pdo->beginTransaction();
foreach ($track_order as $position => $track_id) {
$stmt = $pdo->prepare("UPDATE playlist_tracks SET position = ? WHERE playlist_id = ? AND track_id = ?");
$stmt->execute([$position + 1, $crate_id, $track_id]);
}
// Update crate updated_at
$stmt = $pdo->prepare("UPDATE artist_playlists SET updated_at = NOW() WHERE id = ?");
$stmt->execute([$crate_id]);
$pdo->commit();
echo json_encode([
'success' => true,
'message' => 'Crate track order updated successfully'
]);
} catch (Exception $e) {
$pdo->rollBack();
error_log("Error updating crate track order: " . $e->getMessage());
echo json_encode(['success' => false, 'error' => 'Failed to update track order: ' . $e->getMessage()]);
}