<?php
declare(strict_types=1);require __DIR__.'/_bootstrap.php';
if(request_is_post()){verify_csrf();$id=(int)($_POST['id']??0);db()->prepare("UPDATE pages SET status=IF(status='published','draft','published'),published_at=IF(status='published',published_at,NOW()),updated_at=NOW() WHERE id=?")->execute([$id]);flash('success','Sayfa durumu değiştirildi.');redirect('/admin/pages.php');}
$items=db()->query('SELECT * FROM pages ORDER BY menu_group,sort_order,id')->fetchAll();admin_header('Kurumsal Sayfalar');?>
<div class="panel"><div class="panel-head"><h2>Kurumsal ve yasal içerikler</h2><a class="button" href="<?=url('/admin/content-edit.php?type=page')?>">Yeni Sayfa</a></div><div class="table-wrap"><table><thead><tr><th>Sayfa</th><th>Menü</th><th>Sıra</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">/kurumsal/<?=e($p['slug'])?></span></td><td><?=e($p['menu_group'])?></td><td><?=$p['sort_order']?></td><td><?=admin_status($p['status'])?></td><td><div class="actions"><a class="button small secondary" href="<?=url('/admin/content-edit.php?type=page&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();?>
