<?php
if (!defined('ROOT_FOLDER')) { require_once(dirname(__DIR__, 3) . '/init.php'); }
m_secure_session_start();
if (!m_admin_check()) { m_redirect(ADMIN_URL . '/login'); }
m_validate_session_security();


$db = new DB();
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0){ m_redirect(ADMIN_URL . '/admins/lists'); }

// Son süper admin silinemez
if (!has_other_super_admins($id)){
	m_set_session('formSuccess', false);
	m_set_session('error_message', lang('admins.cannot_demote_last_super', [], 'Son süper admin düşürülemez.'));
	m_redirect(ADMIN_URL . '/admins/lists');
}

$db->table('admins')->where('id','=',$id)->delete();
m_set_session('formSuccess', true);
m_set_session('success_message', lang('form_success_delete_message', [], 'Seçilen Kayıt Başarıyla Silindi!'));
m_redirect(ADMIN_URL . '/admins/lists');


