Files
sam-kd/geoattendance/api/setup_db.php

44 lines
1.2 KiB
PHP
Raw Normal View History

<?php
/**
* Geo Attendance Database Setup
*
* One-time script to create the geo_attendance table if it doesn't exist.
* Run this via browser or command line before using the system.
*/
require_once($_SERVER['DOCUMENT_ROOT'] . '/lib/mydb.php');
header('Content-Type: application/json; charset=utf-8');
try {
$pdo = db_connect();
// Create geo_attendance table
$sql = "CREATE TABLE IF NOT EXISTS geo_attendance (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id VARCHAR(50) NOT NULL,
type ENUM('CLOCK_IN', 'CLOCK_OUT') NOT NULL,
lat DECIMAL(10, 8) NOT NULL,
lng DECIMAL(11, 8) NOT NULL,
distance DECIMAL(10, 2) NOT NULL,
is_verified TINYINT(1) DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_user_id (user_id),
INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$pdo->exec($sql);
echo json_encode([
'status' => 'success',
'message' => 'geo_attendance table created successfully.'
]);
} catch (PDOException $e) {
echo json_encode([
'status' => 'error',
'message' => 'Database error: ' . $e->getMessage()
]);
}
?>