<?php
// STEP 2D-2 PRAYER DYNAMIC
 require_once __DIR__ . '/auth.php';

if (!function_exists('app_setting')) {
    function app_setting(PDO $pdo, string $key, string $default = ''): string {
        try {
            $stmt = $pdo->prepare("SELECT setting_value FROM app_settings WHERE setting_key = ? LIMIT 1");
            $stmt->execute([$key]);
            $value = $stmt->fetchColumn();
            return ($value !== false && $value !== null && $value !== '') ? (string)$value : $default;
        } catch (Throwable $e) {
            return $default;
        }
    }
}

$prayerTitle = app_setting($pdo, 'menu_prayer', 'Prayer Guide');
 $pageTitle = $prayerTitle; require_once __DIR__ . '/includes/header.php'; $items=$pdo->query("SELECT * FROM prayer_guides WHERE COALESCE(active,1)=1 ORDER BY sort_order ASC,id DESC")->fetchAll(); ?>
<main><section class="section"><div class="container"><div class="panel"><h1><?php echo h($prayerTitle); ?></h1><div class="grid-2"><?php foreach($items as $item): ?><article class="card"><h2><?php echo h($item['title']); ?></h2><?php if(!empty($item['image_url'])): ?><img class="media-img" src="<?php echo h($item['image_url']); ?>"><?php endif; ?><p class="muted"><?php echo nl2br(h($item['description']??$item['content']??'')); ?></p></article><?php endforeach; ?></div></div></div></section></main><?php require_once __DIR__ . '/includes/footer.php'; ?>
