diff --git a/public/userarea/employees.php b/public/userarea/employees.php new file mode 100644 index 0000000..93b0fd2 --- /dev/null +++ b/public/userarea/employees.php @@ -0,0 +1,752 @@ +getConnection(); + +/* ========================================== + AJAX HANDLERS (ADD / EDIT / DELETE) + ========================================== */ +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] == '1') { + header('Content-Type: application/json'); + + $action = $_POST['action'] ?? ''; + + try { + if ($action === 'add') { + $employee_code = trim($_POST['employee_code'] ?? ''); + $first_name = trim($_POST['first_name'] ?? ''); + $last_name = trim($_POST['last_name'] ?? ''); + $department = trim($_POST['department'] ?? ''); + $position = trim($_POST['position'] ?? ''); + $hire_date = trim($_POST['hire_date'] ?? ''); + $status = trim($_POST['status'] ?? 'active'); + $auth_user_id = $_POST['auth_user_id'] !== '' ? (int)$_POST['auth_user_id'] : null; + + if ($first_name === '' || $last_name === '') { + echo json_encode([ + 'success' => false, + 'message' => 'First name and Last name are required.' + ]); + exit; + } + + if (!in_array($status, ['active', 'inactive', 'suspended'], true)) { + $status = 'active'; + } + + $sql = "INSERT INTO employees + (auth_user_id, employee_code, first_name, last_name, department, position, hire_date, status, created_at, updated_at) + VALUES + (:auth_user_id, :employee_code, :first_name, :last_name, :department, :position, :hire_date, :status, NOW(), NOW())"; + $stmt = $pdo->prepare($sql); + $stmt->execute([ + 'auth_user_id' => $auth_user_id, + 'employee_code' => $employee_code !== '' ? $employee_code : null, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'department' => $department !== '' ? $department : null, + 'position' => $position !== '' ? $position : null, + 'hire_date' => $hire_date !== '' ? $hire_date : null, + 'status' => $status + ]); + + echo json_encode(['success' => true]); + exit; + } + + if ($action === 'edit') { + $id = (int)($_POST['id'] ?? 0); + $employee_code = trim($_POST['employee_code'] ?? ''); + $first_name = trim($_POST['first_name'] ?? ''); + $last_name = trim($_POST['last_name'] ?? ''); + $department = trim($_POST['department'] ?? ''); + $position = trim($_POST['position'] ?? ''); + $hire_date = trim($_POST['hire_date'] ?? ''); + $status = trim($_POST['status'] ?? 'active'); + $auth_user_id = $_POST['auth_user_id'] !== '' ? (int)$_POST['auth_user_id'] : null; + + if ($id <= 0) { + echo json_encode(['success' => false, 'message' => 'Invalid employee ID.']); + exit; + } + + if ($first_name === '' || $last_name === '') { + echo json_encode([ + 'success' => false, + 'message' => 'First name and Last name are required.' + ]); + exit; + } + + if (!in_array($status, ['active', 'inactive', 'suspended'], true)) { + $status = 'active'; + } + + $sql = "UPDATE employees + SET auth_user_id = :auth_user_id, + employee_code = :employee_code, + first_name = :first_name, + last_name = :last_name, + department = :department, + position = :position, + hire_date = :hire_date, + status = :status, + updated_at = NOW() + WHERE id = :id"; + $stmt = $pdo->prepare($sql); + $stmt->execute([ + 'auth_user_id' => $auth_user_id, + 'employee_code' => $employee_code !== '' ? $employee_code : null, + 'first_name' => $first_name, + 'last_name' => $last_name, + 'department' => $department !== '' ? $department : null, + 'position' => $position !== '' ? $position : null, + 'hire_date' => $hire_date !== '' ? $hire_date : null, + 'status' => $status, + 'id' => $id + ]); + + echo json_encode(['success' => true]); + exit; + } + + if ($action === 'delete') { + $id = (int)($_POST['id'] ?? 0); + + if ($id <= 0) { + echo json_encode(['success' => false, 'message' => 'Invalid employee ID.']); + exit; + } + + $stmt = $pdo->prepare("DELETE FROM employees WHERE id = :id"); + $stmt->execute(['id' => $id]); + + echo json_encode(['success' => true]); + exit; + } + + echo json_encode(['success' => false, 'message' => 'Unknown action.']); + exit; + } catch (Exception $e) { + echo json_encode([ + 'success' => false, + 'message' => $e->getMessage() + ]); + exit; + } +} + +/* ========================================== + PAGE DATA (LIST + USERS LIST) + ========================================== */ + +// Employees list +$sql = " + SELECT e.*, + au.email AS user_email, + CONCAT(COALESCE(au.first_name, ''), ' ', COALESCE(au.last_name, '')) AS user_fullname + FROM employees e + LEFT JOIN auth_users au ON e.auth_user_id = au.id + ORDER BY e.id DESC +"; +$stmtEmployees = $pdo->query($sql); +$employees = $stmtEmployees->fetchAll(PDO::FETCH_ASSOC); + +// Users list for select +$sqlUsers = " + SELECT id, + CONCAT( + COALESCE(first_name, ''), + ' ', + COALESCE(last_name, ''), + ' (', + email, + ')' + ) AS label + FROM auth_users + ORDER BY first_name, last_name, email +"; +$stmtUsers = $pdo->query($sqlUsers); +$users = $stmtUsers->fetchAll(PDO::FETCH_ASSOC); +?> + + + + + + + + + + Gestione Dipendenti - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
+
Gestione Dipendenti
+ +
+ +
+
+
Elenco Completo
+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDCodeNameDepartmentPositionHire DateStatusLinked UserActions
No employees found
+ + + + + + + +
+
+ +
+
+
+
+ + +
+ + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/userarea/production_dashboard.php b/public/userarea/production_dashboard.php index 4f0d951..d082a4f 100644 --- a/public/userarea/production_dashboard.php +++ b/public/userarea/production_dashboard.php @@ -110,7 +110,6 @@ background: linear-gradient(135deg, #9f7aea, #b794f4); } - .dash-btn { width: 100%; max-width: 280px; @@ -174,6 +173,38 @@ background: linear-gradient(135deg, #61ce5dff, #61ce5dff); } + .btn-problem { + background-color: #ef4444 !important; + color: #ffffff !important; + border-radius: 12px; + } + + .btn-problem:hover { + background-color: #dc2626 !important; + } + + .btn-tools { + background: linear-gradient(135deg, #9f7aea, #b794f4); + } + + /* 🔹 Nuovo bottone Employees */ + .btn-employees { + background: linear-gradient(135deg, #a5b4fc, #c7d2fe); + } + + /* --- Pulsanti grandi (default) --- */ + .dash-btn-large { + padding: 18px 10px; + font-size: 1.3rem; + } + + /* --- Pulsanti di servizio: più bassi --- */ + .dash-btn-small { + padding: 9px 10px !important; + font-size: 1.05rem !important; + min-height: 80px; + } + @media (max-width: 768px) { .stats-row { @@ -196,31 +227,6 @@ font-size: 2.6rem; } } - - .btn-problem { - background-color: #ef4444 !important; - /* rosso brillante */ - color: #ffffff !important; - border-radius: 12px; - } - - .btn-problem:hover { - background-color: #dc2626 !important; - /* rosso scuro hover */ - } - - /* --- Pulsanti grandi (default) --- */ - .dash-btn-large { - padding: 18px 10px; - font-size: 1.3rem; - } - - /* --- Pulsanti di servizio: più bassi --- */ - .dash-btn-small { - padding: 9px 10px !important; - font-size: 1.05rem !important; - min-height: 80px; - } @@ -281,7 +287,6 @@
Line View
- - @@ -319,7 +323,6 @@
-
+ +
+ +