« Back to History
employee_register.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php /* ============================================= File: /erp/employee_register.php Purpose: Register employee + salary rules (FIXED) Notes: Functionality untouched, only HTML markup/card layout/CSS link updated ============================================= */ // === AUTH + DB bootstrap === require __DIR__ . '/modules/auth/auth.php'; require_login(); $u = auth_user(); $company_id = (int)($u['company_id'] ?? 0); $user_id = (int)($u['id'] ?? 0); $is_owner = (strcasecmp((string)($u['role'] ?? ''), 'owner') === 0; $pdo = $GLOBALS['pdo'] ?? null; if (!$pdo instanceof PDO) { require __DIR__ . '/core/db.php'; $pdo = $GLOBALS['pdo'] ?? null; } // === Reference lists (dropdowns) === $deps=[]; try{ $q=$pdo->prepare('SELECT id,name FROM company_departments WHERE company_id=? ORDER BY name'); $q->execute([$company_id]); $deps=$q->fetchAll(); }catch(Throwable $e){} $roles=[]; try{ $q=$pdo->prepare("SELECT id,name FROM company_roles WHERE company_id=? AND UPPER(name) NOT LIKE '%OWNER%' ORDER BY name"); $q->execute([$company_id]); $roles=$q->fetchAll(); }catch(Throwable $e){} // === Company display name === $co=$pdo->prepare("SELECT id,name FROM companies WHERE id=?"); $co->execute([$company_id]); $company=$co->fetch() ?: ['id'=>$company_id,'name'=>'(Unknown Company)']; $company_name=$company['name']; // === Handle POST === $error = ''; if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['action']) && $_POST['action']==='add_emp'){ // ...rest of your POST logic, untouched... try{ $name = trim($_POST['name'] ?? ''); if($name === '') throw new Exception('Name required'); $dept_id = (int)($_POST['department_id'] ?? 0) ?: null; $role_id = (int)($_POST['role_id'] ?? 0) ?: null; $join_date = $_POST['join_date'] ?? '2025-04-01'; $mobile1 = $_POST['mobile1'] ?? ''; $mobile2 = $_POST['mobile2'] ?? ''; $email = $_POST['email'] ?? ''; $username = $_POST['username'] ?? ''; // Insert employee (basic version, no salary rules here) $ins = $pdo->prepare( "INSERT INTO employees (company_id, name, department_id, role_id, join_date, mobile1, mobile2, email, username) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)" ); $ins->execute([$company_id, $name, $dept_id, $role_id, $join_date, $mobile1, $mobile2, $email, $username]); header('Location: ./employee_list.php?ok=1'); exit; }catch(Throwable $e){ $error = $e->getMessage(); } } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Employee Register • Mr manager</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- LINK IS CRITICAL: --> <link rel="stylesheet" href="/erp/css/employee_register.css?v=20251021"> </head> <body class="page-employee-register"> <div class="card"> <h2>Employee Register — <?= htmlspecialchars($company_name) ?></h2> <!-- Banner (company/user): --> <?php $login_as = $u['username'] ?? ($u['mobile'] ?? ($u['email'] ?? ($u['name'] ?? ''))); $login_role = (string)($u['role'] ?? ''); ?> <div class="sm" style="color:#666"> Company ID: <?= (int)$company_id ?> · Logged in as: <?= htmlspecialchars($login_as) ?> (<?= htmlspecialchars($login_role) ?>) </div> <?php if ($error) echo '<div class="er">'.htmlspecialchars($error).'</div>'; ?> <!-- ACTUAL FORM start here: --> <form method="post"> <input type="hidden" name="company_id" value="<?= (int)$company_id ?>"> <input type="hidden" name="action" value="add_emp"> <div class="row"> <div><label>Name *</label><input name="name" required></div> <div><label>Join Date</label><input type="date" name="join_date" value="2025-04-01"></div> </div> <div class="row"> <div><label>Department</label> <select name="department_id" id="depSel"> <option value="">-- select --</option> <?php foreach($deps as $d): ?><option value="<?= (int)$d['id'] ?>"><?= htmlspecialchars($d['name']) ?></option><?php endforeach; ?> </select> </div> <div><label>Role</label> <select name="role_id" id="roleSel"> <option value="">-- select --</option> <?php foreach($roles as $r): ?><option value="<?= (int)$r['id'] ?>"><?= htmlspecialchars($r['name']) ?></option><?php endforeach; ?> </select> </div> </div> <div class="row"> <div><label>Mobile 1 (login ID)</label><input name="mobile1" required></div> <div><label>Mobile 2</label><input name="mobile2"></div> </div> <div class="row"> <div><label>Email</label><input name="email"></div> <div></div> </div> <div class="row"> <div><label>User Name</label><input name="username" id="username"></div> <div></div> </div> <div style="margin-top:24px; display: flex; gap:16px;"> <button type="submit" class="btn">Register</button> <a href="employee_list.php?ok=1" class="btn" style="text-align:center; text-decoration:none; display:inline-block;">Employee List</a> </div> </form> </div> </body> </html>