<?php
declare(strict_types=1);require __DIR__.'/_bootstrap.php';
if(request_is_post()){verify_csrf();$id=(int)($_POST['id']??0);db()->prepare("UPDATE posts SET status=IF(status='published','draft','published'),published_at=IF(status='published',published_at,NOW()),updated_at=NOW() WHERE id=?")->execute([$id]);flash('success','Makale durumu değiştirildi.');redirect('/admin/posts.php');}
$items=db()->query('SELECT * FROM posts ORDER BY created_at DESC,id DESC')->fetchAll();admin_header('Makaleler');?>
<div class="panel"><div class="panel-head"><h2>Wellness rehberi içerikleri</h2><a class="button" href="<?=url('/admin/content-edit.php?type=post')?>">Yeni Makale</a></div><div class="table-wrap"><table><thead><tr><th>Başlık</th><th>Yayın</th><th>Rezervasyon Alanı</th><th>Durum</th><th></th></tr></thead><tbody><?php foreach($items as $p):?><tr><td><b><?=e($p['title'])?></b><br><span class="muted">/makale/<?=e($p['slug'])?></span></td><td><?=e($p['published_at']?date('d.m.Y H:i',strtotime($p['published_at'])):'—')?></td><td><?=$p['show_booking']?'Açık':'Kapalı'?></td><td><?=admin_status($p['status'])?></td><td><div class="actions"><?php if($p['status']==='published'):?><a class="button small secondary" href="<?=url('/makale/'.$p['slug'])?>" target="_blank" rel="noopener">Makaleyi Gör</a><?php endif;?><a class="button small secondary" href="<?=url('/admin/content-edit.php?type=post&id='.$p['id'])?>">Düzenle</a><form method="post"><?=csrf_field()?><button class="button small" name="id" value="<?=$p['id']?>"><?=$p['status']==='published'?'Taslağa Al':'Yayınla'?></button></form></div></td></tr><?php endforeach;?></tbody></table></div></div>
<?php admin_footer();?>
