Sindbad~EG File Manager
<?php
require_once 'config/config.php';
require_login();
$database = new Database();
$conn = $database->getConnection();
echo "<h2>Debug Information</h2>";
// Check if locations table exists and has data
try {
$stmt = $conn->query("SELECT COUNT(*) as count FROM locations");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo "<p>✓ Locations table exists with " . $result['count'] . " records</p>";
$stmt = $conn->query("SELECT * FROM locations LIMIT 5");
$locations = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<p>Sample locations:</p><ul>";
foreach ($locations as $loc) {
echo "<li>" . htmlspecialchars($loc['name']) . " (" . $loc['type'] . ")</li>";
}
echo "</ul>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Locations table error: " . $e->getMessage() . "</p>";
}
// Check if users table has location_id column
try {
$stmt = $conn->query("SHOW COLUMNS FROM users LIKE 'location_id'");
if ($stmt->rowCount() > 0) {
echo "<p>✓ Users table has location_id column</p>";
} else {
echo "<p style='color: red;'>❌ Users table missing location_id column</p>";
}
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Users table error: " . $e->getMessage() . "</p>";
}
// Check TinyMCE API key
try {
$api_key = get_setting('tinymce_api_key', 'not-found');
echo "<p>TinyMCE API Key: " . substr($api_key, 0, 10) . "...</p>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Settings error: " . $e->getMessage() . "</p>";
}
// Check news table structure
try {
$stmt = $conn->query("DESCRIBE news");
$columns = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<p>✓ News table exists with columns:</p><ul>";
foreach ($columns as $col) {
echo "<li>" . $col['Field'] . " (" . $col['Type'] . ")</li>";
}
echo "</ul>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ News table error: " . $e->getMessage() . "</p>";
}
// Test News class
try {
require_once 'classes/News.php';
$news = new News($conn);
echo "<p>✓ News class loaded successfully</p>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ News class error: " . $e->getMessage() . "</p>";
}
// Test actual news creation
if ($_POST && !empty($_POST['test_news'])) {
echo "<h3>Testing News Creation:</h3>";
try {
require_once 'classes/News.php';
require_once 'classes/Location.php';
$news = new News($conn);
$location = new Location($conn);
// Get first location for test
$locations = $location->getAll();
$first_location = $locations[0] ?? null;
if ($first_location) {
$test_data = [
'title' => 'Test Article',
'location_id' => $first_location['id'],
'description' => 'Test description',
'content' => 'Test content for news article',
'written_by' => 'Test Author',
'category_id' => null,
'user_id' => $_SESSION['user_id'],
'status' => 'draft'
];
echo "<p>Attempting to create news with data:</p>";
echo "<pre>" . print_r($test_data, true) . "</pre>";
$news_id = $news->create($test_data);
if ($news_id) {
echo "<p style='color: green;'>✓ News created successfully with ID: " . $news_id . "</p>";
// Clean up test article
$conn->prepare("DELETE FROM news WHERE id = ?")->execute([$news_id]);
echo "<p>Test article cleaned up</p>";
} else {
echo "<p style='color: red;'>❌ News creation failed</p>";
}
} else {
echo "<p style='color: red;'>❌ No locations found for test</p>";
}
} catch (Exception $e) {
echo "<p style='color: red;'>❌ News creation error: " . $e->getMessage() . "</p>";
}
}
// Simple form test
if ($_POST && empty($_POST['test_news'])) {
echo "<h3>Form Data Received:</h3>";
echo "<pre>" . print_r($_POST, true) . "</pre>";
if (!empty($_POST['title']) && !empty($_POST['content'])) {
echo "<p style='color: green;'>✓ Form submission working - required fields present</p>";
} else {
echo "<p style='color: red;'>❌ Missing required fields</p>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Test Create Article</title>
<link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
<div class="container" style="margin-top: 2rem;">
<h1>Test Article Creation</h1>
<form method="POST" action="">
<div class="form-group">
<label>Title:</label>
<input type="text" name="title" class="form-control" required>
</div>
<div class="form-group">
<label>Content:</label>
<textarea name="content" class="form-control" rows="5" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Test Submit</button>
<button type="submit" name="test_news" value="1" class="btn btn-success">Test News Creation</button>
</form>
<p><a href="news/create.php">← Back to Create News</a></p>
</div>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists