« Back to History
dev_shop_setup.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php declare(strict_types=1); require_once __DIR__ . '/config.php'; /** * DEVELOPER ONLY * ------------------------- * - Create new shop * - Reset password for existing shop * ------------------------- * DELETE or PROTECT after use */ $message = ''; $error = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $action = $_POST['action'] ?? ''; $shop_name = trim($_POST['shop_name'] ?? ''); $mobile = trim($_POST['mobile'] ?? ''); $password = $_POST['password'] ?? ''; $profit_enabled = isset($_POST['profit_tracking']) ? 1 : 0; $khata_enabled = isset($_POST['khata']) ? 1 : 0; if ($mobile === '' || $password === '') { $error = 'Mobile number and password are required.'; } else { try { /* ========================= CREATE NEW SHOP ========================= */ if ($action === 'create') { if ($shop_name === '') { throw new Exception('Shop name is required.'); } $chk = $pdo->prepare( "SELECT shop_id FROM shop WHERE owner_mobile = ?" ); $chk->execute([$mobile]); if ($chk->fetch()) { throw new Exception('Shop already exists for this mobile.'); } $pdo->beginTransaction(); $hash = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare(" INSERT INTO shop (shop_name, owner_mobile, password_hash, is_active) VALUES (?, ?, ?, 1) "); $stmt->execute([$shop_name, $mobile, $hash]); $shop_id = (int)$pdo->lastInsertId(); $cfg = $pdo->prepare(" INSERT INTO system_config (shop_id, profit_tracking_enabled, khata_enabled) VALUES (?, ?, ?) "); $cfg->execute([$shop_id, $profit_enabled, $khata_enabled]); $pdo->commit(); $message = "Shop created successfully. Shop ID: {$shop_id}"; } /* ========================= RESET PASSWORD ========================= */ if ($action === 'reset') { $stmt = $pdo->prepare( "SELECT shop_id FROM shop WHERE owner_mobile = ?" ); $stmt->execute([$mobile]); $shop = $stmt->fetch(); if (!$shop) { throw new Exception('No shop found for this mobile.'); } $hash = password_hash($password, PASSWORD_DEFAULT); $upd = $pdo->prepare( "UPDATE shop SET password_hash = ? WHERE shop_id = ?" ); $upd->execute([$hash, $shop['shop_id']]); $message = 'Password reset successful. You can login now.'; } } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } $error = $e->getMessage(); } } } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Developer | Shop Setup</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/main.css"> </head> <body class="font-md"> <div class="header"> <h2>Developer – Shop Setup</h2> </div> <div class="container"> <div class="card"> <?php if ($error): ?> <div class="alert alert-danger"><?php echo h($error); ?></div> <?php endif; ?> <?php if ($message): ?> <div class="alert alert-success"><?php echo h($message); ?></div> <?php endif; ?> <form method="post"> <div class="form-group"> <label>Shop Name (only for CREATE)</label> <input type="text" name="shop_name" placeholder="My Mobile Shop"> </div> <div class="form-group"> <label>Owner Mobile</label> <input type="text" name="mobile" inputmode="numeric" required> </div> <div class="form-group"> <label>New Password</label> <input type="password" name="password" required> </div> <div class="form-group"> <label> <input type="checkbox" name="profit_tracking"> Enable Profit Tracking (create only) </label> </div> <div class="form-group"> <label> <input type="checkbox" name="khata"> Enable Khata (create only) </label> </div> <div class="form-group"> <label> <input type="radio" name="action" value="create" checked> Create New Shop </label> <br> <label> <input type="radio" name="action" value="reset"> Reset Password Only </label> </div> <button class="btn btn-primary">Submit</button> </form> </div> </div> </body> </html>