no message

This commit is contained in:
a-kizaki
2026-10-22 08:48:13 +09:00
commit f81638a7b3
13 changed files with 934 additions and 0 deletions

127
public/controller.php Normal file
View File

@@ -0,0 +1,127 @@
<?php
require_once __DIR__ . '/../database/employees/EmployeeAccess.php';
// エラーメッセージを格納する変数
$errorMessage = '';
try {
// EmployeeData.csv のパスを指定(プロジェクトルートにあるファイル)
$employeeAccess = new EmployeeAccess(__DIR__ . '/../EmployeeData.csv');
$action = isset($_GET['action']) ? $_GET['action'] : '';
if ($action == 'list') {
try {
// 部分検索機能を追加:検索キーワードがあれば、社員名にキーワードが含まれるかチェック
$keyword = isset($_GET['keyword']) ? $_GET['keyword'] : "";
$allEmployees = $employeeAccess->getAll();
$employees = array();
if ($keyword != "") {
foreach ($allEmployees as $emp) {
if (strpos($emp['name'], $keyword) !== false) {
$employees[] = $emp;
}
}
} else {
$employees = $allEmployees;
}
include 'employee_list.php';
} catch (Exception $e) {
$errorMessage = "社員一覧の取得に失敗しました: " . $e->getMessage();
include 'employee_list.php';
}
} elseif ($action == 'register') {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
if ($name != '' && $email != '') {
$employeeAccess->add(array('name' => $name, 'email' => $email));
header("Location: controller.php?action=list");
exit;
} else {
$errorMessage = "名前とメールアドレスは必須です";
}
} catch (InvalidArgumentException $e) {
$errorMessage = $e->getMessage();
} catch (Exception $e) {
$errorMessage = "登録に失敗しました: " . $e->getMessage();
}
}
include 'employee_register.php';
} elseif ($action == 'update') {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
try {
$id = isset($_POST['id']) ? $_POST['id'] : '';
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
if ($id != '' && $name != '' && $email != '') {
$employeeAccess->update($id, array('name' => $name, 'email' => $email));
header("Location: controller.php?action=list");
exit;
} else {
$errorMessage = "ID、名前、メールアドレスは必須です";
}
} catch (InvalidArgumentException $e) {
$errorMessage = $e->getMessage();
} catch (RuntimeException $e) {
$errorMessage = $e->getMessage();
} catch (Exception $e) {
$errorMessage = "更新に失敗しました: " . $e->getMessage();
}
include 'employee_update.php';
} else {
try {
$id = isset($_GET['id']) ? $_GET['id'] : '';
if (empty($id)) {
$errorMessage = "IDが指定されていません";
include 'employee_update.php';
} else {
$employees = $employeeAccess->getAll();
$employee = null;
foreach ($employees as $emp) {
if ($emp['id'] == $id) {
$employee = $emp;
break;
}
}
if ($employee === null) {
$errorMessage = "指定された社員が見つかりません";
}
include 'employee_update.php';
}
} catch (Exception $e) {
$errorMessage = "社員情報の取得に失敗しました: " . $e->getMessage();
include 'employee_update.php';
}
}
} elseif ($action == 'delete' && isset($_GET['id'])) {
try {
$id = $_GET['id'];
if (empty($id)) {
throw new InvalidArgumentException("IDが指定されていません");
}
$employeeAccess->delete($id);
header("Location: controller.php?action=list");
exit;
} catch (InvalidArgumentException $e) {
$errorMessage = $e->getMessage();
include 'employee_list.php';
} catch (RuntimeException $e) {
$errorMessage = $e->getMessage();
header("Location: controller.php?action=list&error=" . urlencode($errorMessage));
exit;
} catch (Exception $e) {
$errorMessage = "削除に失敗しました: " . $e->getMessage();
header("Location: controller.php?action=list&error=" . urlencode($errorMessage));
exit;
}
} else {
include 'index.php';
}
} catch (Exception $e) {
// 初期化エラーなど、致命的なエラーの場合
die("システムエラーが発生しました: " . htmlspecialchars($e->getMessage()));
}

72
public/employee_list.php Normal file
View File

@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>社員一覧 - 社員メンテナンスシステム</title>
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- ナビバー -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php">社員メンテナンスシステム</a>
</div>
</nav>
<div class="container mt-4">
<h1 class="mb-4">社員一覧</h1>
<!-- エラーメッセージ表示 -->
<?php if (!empty($errorMessage)): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php endif; ?>
<?php if (isset($_GET['error'])): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($_GET['error']); ?>
</div>
<?php endif; ?>
<!-- 部分検索用のフォーム -->
<form method="get" action="controller.php" class="mb-3">
<input type="hidden" name="action" value="list">
<div class="input-group">
<input type="text" name="keyword" class="form-control" placeholder="検索キーワード" value="<?php echo isset($_GET['keyword']) ? htmlspecialchars($_GET['keyword']) : ''; ?>">
<button class="btn btn-primary" type="submit">検索</button>
</div>
</form>
<!-- 社員一覧テーブル -->
<table class="table table-bordered table-striped">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>名前</th>
<th>Email</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach ($employees as $emp): ?>
<tr>
<td><?php echo htmlspecialchars($emp['id']); ?></td>
<td><?php echo htmlspecialchars($emp['name']); ?></td>
<td><?php echo htmlspecialchars($emp['email']); ?></td>
<td>
<a href="controller.php?action=update&id=<?php echo $emp['id']; ?>" class="btn btn-sm btn-warning">更新</a>
<a href="controller.php?action=delete&id=<?php echo $emp['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('本当に削除しますか?');">削除</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<a href="controller.php?action=register" class="btn btn-success">新規登録</a>
<a href="index.php" class="btn btn-secondary">ホームに戻る</a>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>社員登録 - 社員メンテナンスシステム</title>
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- ナビバー -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php">社員メンテナンスシステム</a>
</div>
</nav>
<div class="container mt-4">
<h1 class="mb-4">社員登録</h1>
<!-- エラーメッセージ表示 -->
<?php if (!empty($errorMessage)): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php endif; ?>
<form action="controller.php?action=register" method="post">
<div class="mb-3">
<label for="name" class="form-label">名前</label>
<input type="text" id="name" name="name" class="form-control" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" id="email" name="email" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">登録</button>
<a href="index.php" class="btn btn-secondary">ホームに戻る</a>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>社員更新 - 社員メンテナンスシステム</title>
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- ナビバー -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php">社員メンテナンスシステム</a>
</div>
</nav>
<div class="container mt-4">
<h1 class="mb-4">社員更新</h1>
<!-- エラーメッセージ表示 -->
<?php if (!empty($errorMessage)): ?>
<div class="alert alert-danger" role="alert">
<?php echo htmlspecialchars($errorMessage); ?>
</div>
<?php endif; ?>
<?php if (isset($employee) && $employee): ?>
<form action="controller.php?action=update" method="post">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($employee['id']); ?>">
<div class="mb-3">
<label for="name" class="form-label">名前</label>
<input type="text" id="name" name="name" class="form-control" value="<?php echo htmlspecialchars($employee['name']); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" id="email" name="email" class="form-control" value="<?php echo htmlspecialchars($employee['email']); ?>" required>
</div>
<button type="submit" class="btn btn-primary">更新</button>
<a href="controller.php?action=list" class="btn btn-secondary">社員一覧に戻る</a>
</form>
<?php else: ?>
<div class="alert alert-warning" role="alert">
指定された社員が見つかりません。
</div>
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

30
public/index.php Normal file
View File

@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ホーム - 社員メンテナンスシステム</title>
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- ナビバー -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="index.php">社員メンテナンスシステム</a>
</div>
</nav>
<div class="container mt-4">
<h1 class="mb-4">ホーム</h1>
<div class="list-group">
<a href="controller.php?action=list" class="list-group-item list-group-item-action">社員一覧</a>
<a href="controller.php?action=register" class="list-group-item list-group-item-action">社員登録</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>