Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/
Upload File :
Current File : /home/copmadinaarea/.trash/test_delete.php.1

<?php
require_once 'config/config.php';
require_login();

$database = new Database();
$conn = $database->getConnection();

echo "<h2>Delete Functionality Test</h2>";

// Test if we can access delete.php directly
echo "<h3>Testing Delete Page Access</h3>";

// Get a news article to test with
try {
    $stmt = $conn->query("SELECT * FROM news LIMIT 1");
    $article = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if ($article) {
        echo "<p>✓ Found test article: " . htmlspecialchars($article['title']) . " (ID: " . $article['id'] . ")</p>";
        echo "<p><a href='news/delete.php?id=" . $article['id'] . "' target='_blank'>Test Delete Page</a></p>";
        
        // Test permissions
        echo "<h3>Permission Check</h3>";
        echo "<p>Current user ID: " . ($_SESSION['user_id'] ?? 'not set') . "</p>";
        echo "<p>Article user ID: " . ($article['user_id'] ?? 'not set') . "</p>";
        echo "<p>Account type: " . ($_SESSION['account_type'] ?? 'not set') . "</p>";
        
        $canDelete = (($article['user_id'] ?? 0) == ($_SESSION['user_id'] ?? 0)) || 
                     (($_SESSION['account_type'] ?? 'user') !== 'user');
        
        if ($canDelete) {
            echo "<p style='color: green;'>✓ User has permission to delete this article</p>";
        } else {
            echo "<p style='color: red;'>❌ User does not have permission to delete this article</p>";
        }
        
    } else {
        echo "<p style='color: red;'>❌ No news articles found to test with</p>";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>❌ Database error: " . $e->getMessage() . "</p>";
}

// Test News delete method
echo "<h3>Testing News Delete Method</h3>";
try {
    require_once 'classes/News.php';
    $news = new News($conn);
    echo "<p>✓ News class loaded successfully</p>";
    
    // Check if delete method exists
    if (method_exists($news, 'delete')) {
        echo "<p>✓ Delete method exists in News class</p>";
    } else {
        echo "<p style='color: red;'>❌ Delete method missing from News class</p>";
    }
} catch (Exception $e) {
    echo "<p style='color: red;'>❌ News class error: " . $e->getMessage() . "</p>";
}

?>

<!DOCTYPE html>
<html>
<head>
    <title>Test Delete Functionality</title>
    <link rel="stylesheet" href="assets/css/style.css">
</head>
<body>
    <div class="container" style="margin-top: 2rem;">
        <p><a href="news/index.php">← Back to News</a></p>
    </div>
</body>
</html>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists