« Back to History
pissing_slot_editor.php
|
20260721_154033.php
Initial Bulk Import
Copy Code
<?php error_reporting(E_ALL); ini_set('display_errors',1); require dirname(__DIR__).'/modules/auth/auth.php'; require_login(); $u=auth_user(); $company_id=(int)$u['company_id']; $pdo=$GLOBALS['pdo']??null; if(!$pdo){ require dirname(__DIR__).'/core/db.php'; } function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); } function qall($pdo,$sql,$p=[]){ $st=$pdo->prepare($sql); $st->execute($p); return $st->fetchAll(PDO::FETCH_ASSOC); } $msg=null; if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['rows'])){ foreach($_POST['rows'] as $id=>$v){ $slot = $v['beam_type'] ?? ''; if(in_array($slot,['Primary','Secondary'],true)){ $pdo->prepare("UPDATE pissing_entry SET beam_type=:s WHERE id=:id AND company_id=:c") ->execute([':s'=>$slot, ':id'=>(int)$id, ':c'=>$company_id]); } } $msg="Saved."; } $machine = isset($_GET['machine']) && $_GET['machine']!=='' ? (int)$_GET['machine'] : null; $from = $_GET['from'] ?? date('Y-m-01'); $to = $_GET['to'] ?? date('Y-m-d'); $params = [':c'=>$company_id, ':f'=>$from, ':t'=>$to]; $sql = "SELECT id, entry_date, machine_no, beam_no, COALESCE(beam_type,'') AS beam_type FROM pissing_entry WHERE company_id=:c AND entry_date BETWEEN :f AND :t"; if($machine){ $sql.=" AND machine_no=:m"; $params[':m']=$machine; } $sql.=" ORDER BY entry_date DESC, id DESC"; $rows = qall($pdo,$sql,$params); $machines = qall($pdo,"SELECT DISTINCT machine_no FROM pissing_entry WHERE company_id=:c ORDER BY machine_no", [':c'=>$company_id]); ?> <!doctype html> <html><head><meta charset="utf-8"/> <title>Pissing Slot Editor</title> <style> body{font-family:system-ui,Segoe UI,Roboto,Arial,sans-serif;background:#f6f8f9;margin:0;color:#111} .wrap{max-width:1000px;margin:22px auto;padding:0 16px} .card{background:#fff;border:1px solid #e5e7eb;border-radius:14px;padding:18px 16px;margin-bottom:16px} table{width:100%;border-collapse:separate;border-spacing:0 8px} th,td{padding:10px 12px} tr{background:#fff;border:1px solid #eef2f5} select{border:1px solid #e5e7eb;border-radius:8px;padding:6px;background:#fff} .btn{border:1px solid #e5e7eb;border-radius:10px;padding:8px 12px;background:#fff;font-weight:600;cursor:pointer} </style> </head> <body> <div class="wrap"> <div class="card"> <h2>Pissing Slot Editor</h2> <?php if($msg): ?><p><b><?=h($msg)?></b></p><?php endif; ?> <form method="get" style="display:flex;gap:8px;flex-wrap:wrap"> <select name="machine"> <option value="">All Machines</option> <?php foreach($machines as $m): $v=(int)$m['machine_no']; ?> <option value="<?=$v?>" <?=($machine===$v?'selected':'')?>>Machine <?=$v?></option> <?php endforeach; ?> </select> <input type="date" name="from" value="<?=h($from)?>"/> <input type="date" name="to" value="<?=h($to)?>"/> <button class="btn" type="submit">Filter</button> <a class="btn" href="pissing_slot_editor.php">Reset</a> </form> </div> <form method="post" class="card"> <h3>Edit beam_type (Primary/Secondary)</h3> <table> <thead><tr><th>ID</th><th>Date</th><th>Machine</th><th>Beam</th><th>Beam Type</th></tr></thead> <tbody> <?php foreach($rows as $r): ?> <tr> <td><?=h($r['id'])?></td> <td><?=h($r['entry_date'])?></td> <td><?=h($r['machine_no'])?></td> <td><b><?=h($r['beam_no'])?></b></td> <td> <select name="rows[<?=h($r['id'])?>][beam_type]"> <option value="">—</option> <option value="Primary" <?=$r['beam_type']==='Primary'?'selected':''?>>Primary</option> <option value="Secondary" <?=$r['beam_type']==='Secondary'?'selected':''?>>Secondary</option> </select> </td> </tr> <?php endforeach; if(empty($rows)): ?> <tr><td colspan="5">No rows.</td></tr> <?php endif; ?> </tbody> </table> <div style="margin-top:10px"> <button class="btn" type="submit">Save Changes</button> <a class="btn" href="../beam_card_report.php">Back to Report</a> </div> </form> </div> </body> </html>