Commit inicial con archivos existentes

This commit is contained in:
2026-01-17 16:14:00 -06:00
parent 48671dc88e
commit 4c48c279de
2539 changed files with 2412708 additions and 0 deletions

35
includes/activity_logger.php Executable file
View File

@@ -0,0 +1,35 @@
<?php
require_once __DIR__ . '/db.php';
function log_activity(int $userId, string $action, ?string $details = null): void
{
global $pdo;
// Debugging: Check if $pdo is a valid PDO object
if (!($pdo instanceof PDO)) {
error_log("Error logging activity: $pdo is not a valid PDO object. Type: " . gettype($pdo));
return;
}
try {
// Fetch username from session or database if not available
$username = $_SESSION['username'] ?? 'Unknown';
if ($username === 'Unknown' && $userId > 0) {
$stmt = $pdo->prepare("SELECT username FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user) {
$username = $user['username'];
}
}
$stmt = $pdo->prepare(
"INSERT INTO activity_log (user_id, username, action, details, timestamp)
VALUES (?, ?, ?, ?, NOW())"
);
$stmt->execute([$userId, $username, $action, $details]);
} catch (PDOException $e) {
error_log("Error logging activity: " . $e->getMessage());
}
}
?>