<?php
session_start();

// Database Configuration
define('DB_HOST', getenv('DB_HOST') ?: '127.0.0.1');
define('DB_USER', getenv('DB_USER') ?: 'root');
define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : '');
define('DB_NAME', getenv('DB_NAME') ?: 'attendance_system');

// System Configuration
define('SITE_NAME', 'QR Attendance System');
define('SITE_URL', 'http://localhost/attendance_system/');
define('TIMEZONE', 'Asia/Manila');

// QR Code Configuration
define('QR_VALIDITY_MINUTES', 30); // QR code validity period

// Set timezone
date_default_timezone_set(TIMEZONE);

// Error reporting (disable in production)
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Create database connection
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Check connection
if (!$conn) {
    die("Database connection failed: " . mysqli_connect_error());
}

// Set charset
mysqli_set_charset($conn, "utf8mb4");

// Function to escape input
function escape($conn, $value) {
    return mysqli_real_escape_string($conn, $value);
}

// Function to execute query
function query($conn, $sql) {
    return mysqli_query($conn, $sql);
}

// Function to get last insert ID
function getInsertId($conn) {
    return mysqli_insert_id($conn);
}
?>