<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create OAuth Providers Table - System Maintenance</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding: 20px;
background-color: #f8f9fa;
}
.container {
max-width: 1000px;
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.1);
}
h1 {
color: #333;
border-bottom: 2px solid #e9ecef;
padding-bottom: 10px;
margin-bottom: 20px;
}
.success {
color: #28a745;
padding: 10px;
background-color: #d4edda;
border-radius: 5px;
margin-bottom: 15px;
}
.error {
color: #dc3545;
padding: 10px;
background-color: #f8d7da;
border-radius: 5px;
margin-bottom: 15px;
}
.info {
color: #17a2b8;
padding: 10px;
background-color: #d1ecf1;
border-radius: 5px;
margin-bottom: 15px;
}
.warning {
color: #ffc107;
padding: 10px;
background-color: #fff3cd;
border-radius: 5px;
margin-bottom: 15px;
}
.nav-links {
margin-top: 30px;
display: flex;
gap: 10px;
}
.nav-links a {
padding: 8px 16px;
text-decoration: none;
background-color: #f8f9fa;
border-radius: 5px;
color: #333;
transition: all 0.3s;
}
.nav-links a:hover {
background-color: #e9ecef;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
table, th, td {
border: 1px solid #dee2e6;
}
th, td {
padding: 12px 15px;
text-align: left;
}
th {
background-color: #f8f9fa;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<div class="container">
<h1>Create OAuth Providers Table - System Maintenance</h1>
<?php
// Include database configuration
require_once '../../admin/database/db_config.php';
// Success and error messages
$messages = [];
// Function to add messages
function addMessage($type, $message) {
global $messages;
$messages[] = ['type' => $type, 'message' => $message];
}
// Check if the table already exists
$tableExists = $conn->query("SHOW TABLES LIKE 'oauth_providers'");
$tableExists = $tableExists->num_rows > 0;
if ($tableExists) {
addMessage('info', 'The oauth_providers table already exists.');
} else {
// SQL to create the oauth_providers table
$sql = "CREATE TABLE oauth_providers (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
provider VARCHAR(50) NOT NULL,
provider_user_id VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
display_name VARCHAR(255),
photo_url VARCHAR(255),
access_token TEXT,
refresh_token TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
UNIQUE KEY provider_user_id_unique (provider, provider_user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4";
if ($conn->query($sql) === TRUE) {
addMessage('success', 'OAuth providers table created successfully.');
} else {
addMessage('error', 'Error creating oauth_providers table: ' . $conn->error);
}
}
// Display messages
if (!empty($messages)) {
echo '<table>';
echo '<tr><th>Type</th><th>Message</th></tr>';
foreach ($messages as $msg) {
echo '<tr class="' . $msg['type'] . '">';
echo '<td>' . ucfirst($msg['type']) . '</td>';
echo '<td>' . $msg['message'] . '</td>';
echo '</tr>';
}
echo '</table>';
}
// Display success or full completion
if ($tableExists || (isset($sql) && $conn->query($sql) === TRUE)) {
echo '<div class="success">OAuth providers table setup completed successfully.</div>';
} else {
echo '<div class="error">There were errors in setting up the OAuth providers table. Please check the messages above.</div>';
}
?>
<div class="nav-links">
<a href="/">Home</a>
<a href="/admin">Admin Dashboard</a>
<a href="/admin/system_utilities.php">System Utilities</a>
<a href="/debug">Debug Tools</a>
</div>
</div>
</body>
</html>