« Back to History
cut_beam_stock_add.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* File: /erp/cut_beam_stock_add.php Drop-in corrected + debug version for diagnosing blank page issue. Set $DEBUG = true to output debug markers (remember to set false after). */ require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('cut_beam_stock_add'); $user = $ctx['user'] ?? null; $company_id = (int)($ctx['company_id'] ?? 0); $pdo = $ctx['pdo'] ?? null; if (!$pdo) { require_once __DIR__ . '/core/db.php'; } require_once __DIR__ . '/helpers/activity_helper.php'; /* ---------- TEMP DEBUG FLAG (set false in production) ---------- */ $DEBUG = false; // <-- set to true to show diagnostic output /* ----------------------------- CSRF SETUP ------------------------------ */ if (empty($_SESSION['csrf_token'])) { $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); } /* ----------------------------- FORM SUBMIT ----------------------------- */ $errors = []; $success = false; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!isset($_POST['csrf_token']) || $_POST['csrf_token'] !== $_SESSION['csrf_token']) { $errors[] = "Invalid CSRF token."; } $beam_no = trim($_POST['beam_no'] ?? ''); $cut_date = trim($_POST['cut_date'] ?? ''); $cut_from_mc_no = trim($_POST['cut_from_mc_no'] ?? ''); $install_date = trim($_POST['install_date'] ?? ''); $install_mc_no = trim($_POST['install_mc_no'] ?? ''); if ($beam_no === '') $errors[] = "Beam No required."; if ($cut_date === '') $errors[] = "Cut Date required."; if ($cut_from_mc_no === '') $errors[] = "Cut From Machine No required."; if (!$errors) { $stmt = $pdo->prepare(" INSERT INTO cut_beam_stock (company_id, beam_no, cut_date, cut_from_mc_no, install_date, install_mc_no) VALUES (:cid, :beam_no, :cut_date, :cut_from_mc_no, :install_date, :install_mc_no) "); $stmt->execute([ ':cid' => $company_id, ':beam_no' => $beam_no, ':cut_date' => $cut_date, ':cut_from_mc_no' => $cut_from_mc_no, ':install_date' => $install_date ?: null, ':install_mc_no' => $install_mc_no ?: null, ]); activity_create('cutting', 'cut_beam_stock_create', (int)$pdo->lastInsertId(), 'Added cut beam stock'); // After insert: redirect with success flag (preserves original behaviour) header("Location: " . basename(__FILE__) . "?success=1"); exit; } } /* ---------- If DEBUG, expose minimal server state ---------- */ if ($DEBUG) { ini_set('display_errors', 1); error_reporting(E_ALL); echo "<pre style='background:#fff; color:#000; padding:10px; border:1px solid #ccc; z-index:99999; position:relative;'>"; echo "DEBUG: reached cut_beam_stock_add.php\n"; echo "company_id: " . htmlspecialchars($company_id) . "\n"; echo "user id: " . ($user['id'] ?? 'null') . "\n"; echo "pdo present: " . ($pdo ? 'yes' : 'no') . "\n"; echo "csrf_token present: " . (isset($_SESSION['csrf_token']) ? 'yes' : 'no') . "\n"; echo "</pre>"; } /* ---------- Render page (header include path corrected) ---------- */ require_once __DIR__ . '/partials/header.php'; ?> <div class="card" style="max-width: 700px; margin: 0 auto;"> <h2>Cut Beam Stock – Add New</h2> <?php if (!empty($_GET['success'])): ?> <div class="notice success">Record added successfully.</div> <?php endif; ?> <?php if ($errors): ?> <div class="notice error"> <?php foreach ($errors as $e): ?> <div><?php echo h($e); ?></div> <?php endforeach; ?> </div> <?php endif; ?> <!-- The form always prints. If you don't see inputs in the browser, inspect element to confirm CSS hiding or overlap. --> <form method="post" id="cut-beam-form"> <input type="hidden" name="csrf_token" value="<?php echo h($_SESSION['csrf_token']); ?>"> <div class="form-grid"> <div class="form-group"> <label>Beam No</label> <input type="text" name="beam_no" required> </div> <div class="form-group"> <label>Cut Date</label> <input type="date" name="cut_date" required> </div> <div class="form-group"> <label>Cut From Machine No</label> <input type="text" name="cut_from_mc_no" required> </div> <div class="form-group"> <label>Install Date (optional)</label> <input type="date" name="install_date"> </div> <div class="form-group"> <label>Install Machine No (optional)</label> <input type="text" name="install_mc_no"> </div> </div> <button class="btn primary" type="submit">Save</button> </form> </div> <?php require_once __DIR__ . '/partials/footer.php'; ?>