0) { $st = $pdo->prepare('SELECT * FROM archives WHERE id=:id'); $st->execute([':id' => $id]); $editing = $st->fetch(); if (!$editing) { flash('error', '档案不存在'); header('Location: index.php'); exit; } } $dirs = fetchDirectories($pdo); $loanInstitutions = loadLoanInstitutions(); $dirId = (int)($_GET['dir_id'] ?? ($editing['directory_id'] ?? 0)); $dirPath = dirPathMap($dirs); $planAll = loadRepaymentPlans(); $planCfg = $editing ? getArchiveRepaymentPlan($planAll, (int)$editing['id']) : ['enabled' => false, 'plans' => []]; $financeAll = loadFinanceConfigs(); $financeCfg = $editing ? getArchiveFinanceConfig($financeAll, (int)$editing['id']) : [ 'interest_mode' => '', 'settlement_rule' => 'monthly_day', 'settlement_day' => 21, 'overdue_float_pct' => 50, 'manual_overdue' => false, 'manual_early_settled' => false, 'remark' => '', 'manual_principal_repaid' => 0.0, 'manual_interest_paid' => 0.0, ]; $planRows = $planCfg['plans'] ?? []; if (empty($planRows)) { for ($i = 0; $i < 6; $i++) { $planRows[] = ['id' => '', 'due_date' => '', 'amount' => '']; } } $editArchiveId = (int)($editing['id'] ?? 0); $editFiles = []; if ($editArchiveId > 0) { $fs = $pdo->prepare('SELECT * FROM files WHERE archive_id=:a ORDER BY id DESC'); $fs->execute([':a' => $editArchiveId]); $editFiles = $fs->fetchAll(); } pageHeader($me); ?>