<?php
require __DIR__ . '/../app/bootstrap.php';
auth_require();
require __DIR__ . '/../app/pages/_common.php';
require_perm('manage_permissions');

if ($_SERVER['REQUEST_METHOD']==='POST') {
  csrf_check();

  // Ensure assets.serial_number exists (legacy safety)
  $col = db_one("SELECT COLUMN_NAME FROM information_schema.COLUMNS
                 WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME='assets' AND COLUMN_NAME='serial_number'");
  if (!$col) {
    db_exec("ALTER TABLE assets ADD COLUMN serial_number VARCHAR(120) NULL AFTER tag");
  }

  flash_set('ok','تمت ترقية v0.3.1.1 بنجاح.');
  redirect(url('/index.php?page=dashboard'));
}

$title = 'ترقية v0.3.1.1';
$view = __DIR__ . '/../app/pages/_upgrade_view.php';
require __DIR__ . '/../app/views/layout.php';
