diff --git a/api/log_session.php b/api/log_session.php new file mode 100644 index 0000000..4080a3b --- /dev/null +++ b/api/log_session.php @@ -0,0 +1,45 @@ + false, 'message' => '', 'error' => '']; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $input = file_get_contents('php://input'); + $data = json_decode($input, true); + + $patternName = $data['pattern_name'] ?? null; + $intensity = $data['intensity'] ?? null; + $durationSeconds = $data['duration_seconds'] ?? null; + + if ($patternName === null || $intensity === null || $durationSeconds === null) { + $response['error'] = 'Missing required parameters.'; + } else { + try { + $pdo = db(); + $stmt = $pdo->prepare( + 'INSERT INTO massage_sessions (pattern_name, intensity, duration_seconds) VALUES (:pattern_name, :intensity, :duration_seconds)' + ); + $stmt->bindParam(':pattern_name', $patternName); + $stmt->bindParam(':intensity', $intensity, PDO::PARAM_STR); // Use PARAM_STR for float to avoid precision issues + $stmt->bindParam(':duration_seconds', $durationSeconds, PDO::PARAM_INT); + $stmt->execute(); + + $response['success'] = true; + $response['message'] = 'Session logged successfully.'; + } catch (PDOException $e) { + $response['error'] = 'Database error: ' . $e->getMessage(); + } catch (Exception $e) { + $response['error'] = 'Server error: ' . $e->getMessage(); + } + } +} else { + $response['error'] = 'Invalid request method.'; +} + +echo json_encode($response); diff --git a/db/config.php b/db/config.php index 03d0ae9..b9378d0 100644 --- a/db/config.php +++ b/db/config.php @@ -1,17 +1,13 @@ PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - ]); - } - return $pdo; -} +// Database configuration sourced from environment variables, managed by the platform. +// DO NOT CHANGE THESE KEYS OR HARDCODE VALUES. +return [ + 'DB_HOST' => $_SERVER['DB_HOST'] ?? '127.0.0.1', + 'DB_PORT' => $_SERVER['DB_PORT'] ?? '3306', + 'DB_NAME' => $_SERVER['DB_NAME'] ?? 'app_38497', + 'DB_USER' => $_SERVER['DB_USER'] ?? 'app_38497', + 'DB_PASS' => $_SERVER['DB_PASS'] ?? 'f136384b-ba47-4035-beb4-5038b71f0857', +]; diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..26d59d6 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,27 @@ +exec($sql); + echo "Migration 001_create_sessions.sql applied successfully.\n"; + +} catch (PDOException $e) { + echo "Database migration failed: " . $e->getMessage() . "\n"; +} catch (Exception $e) { + echo "Error: " . $e->getMessage() . "\n"; +} + +echo "Database migration finished.\n"; diff --git a/db/migrations/001_create_sessions.sql b/db/migrations/001_create_sessions.sql new file mode 100644 index 0000000..c2f02c3 --- /dev/null +++ b/db/migrations/001_create_sessions.sql @@ -0,0 +1,8 @@ +-- Migration: Create massage_sessions table +CREATE TABLE IF NOT EXISTS massage_sessions ( + id INT AUTO_INCREMENT PRIMARY KEY, + pattern_name VARCHAR(50) NOT NULL, + intensity FLOAT NOT NULL, + duration_seconds INT NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); diff --git a/includes/db.php b/includes/db.php new file mode 100644 index 0000000..5863893 --- /dev/null +++ b/includes/db.php @@ -0,0 +1,28 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, // Disable emulation for security + ]); + } + + return $pdo; +} diff --git a/index.php b/index.php index 7205f3d..52da689 100644 --- a/index.php +++ b/index.php @@ -4,6 +4,8 @@ declare(strict_types=1); @error_reporting(E_ALL); @date_default_timezone_set('UTC'); +require_once __DIR__ . '/includes/db.php'; // Include the database helper + $phpVersion = PHP_VERSION; $now = date('Y-m-d H:i:s'); ?> @@ -12,7 +14,7 @@ $now = date('Y-m-d H:i:s'); - New Style + Gamepad Haptic Simulator -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

+
+
+

Gamepad Haptic Simulator

-
+ +
+

Connection Status

+

Gamepad: Disconnected

+

+
+ +
+

Massage Configurator

+ + + +
+
+ + + 0.5 +
+
+ + + 1x +
+
+
+ +
+

Active Session Controller

+ + +

Time Remaining: 00:00

+ + +
+ + + +