<?php
header('Content-Type: text/html; charset=utf-8');
$cfg=require __DIR__.'/../config/config.php';$msg='';$ok=false;
if($_SERVER['REQUEST_METHOD']==='POST'){
  try{
    $pdo=new PDO("mysql:host={$cfg['db_host']};dbname={$cfg['db_name']};charset=utf8mb4",$cfg['db_user'],$cfg['db_pass'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,PDO::ATTR_DEFAULT_FETCH_MODE=>PDO::FETCH_ASSOC,PDO::ATTR_EMULATE_PREPARES=>false]);
    $sql=file_get_contents(__DIR__.'/../database/schema.sql');$pdo->exec($sql);
    require __DIR__.'/../src/auth_schema.php';ensure_auth_schema($pdo);
    $ok=true;$msg='Installation/upgrade completed. Login/Register, Admin User Control, District → Thana → Blood Group filters এবং LifeDrop demo donors ready. Default admin: admin@sadaka.local / admin123. কাজ শেষে install.php delete করুন।';
  }catch(Throwable $e){$msg='Database error: '.htmlspecialchars($e->getMessage(),ENT_QUOTES,'UTF-8');}
}
?><!doctype html><html lang="bn"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Sadaka Installer</title><style>body{font-family:system-ui;background:#f5f6fa;padding:30px;color:#1f2937}.card{max-width:720px;margin:auto;background:white;padding:28px;border-radius:24px;box-shadow:0 10px 35px #0001}.info{background:#f8fafc;padding:14px;border-radius:12px;margin:14px 0}.ok{color:#137333}.err{color:#b91c1c}button{background:#b71c1c;color:white;border:0;padding:14px 22px;border-radius:14px;font-weight:700;cursor:pointer}</style></head><body><div class="card"><h1>Sadaka Blood API Upgrade</h1><div class="info"><b>Database:</b> <?=htmlspecialchars($cfg['db_name'])?><br><b>User:</b> <?=htmlspecialchars($cfg['db_user'])?></div><p>ZIP extract করলেই API auth route প্রয়োজন হলে users table নিজে তৈরি করবে। চাইলে এখানে একবার <b>Install / Upgrade</b> চাপলে সব table এবং donor filter master data আগে থেকেই নিশ্চিত হবে।</p><?php if($msg):?><p class="<?=$ok?'ok':'err'?>"><b><?=$msg?></b></p><?php endif;?><form method="post"><button>Install / Upgrade Database</button></form></div></body></html>
