37497-vm/create_request.php
Flatlogic Bot 65bff23a0b 1
2026-01-16 09:31:10 +00:00

185 lines
8.8 KiB
PHP

<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$pdo = db();
// Basic validation
$required_fields = ['company', 'hq_name', 'department_name', 'requester_name', 'issued_date', 'request_title', 'background_purpose', 'implementation_details', 'category', 'impact_range'];
foreach ($required_fields as $field) {
if (empty($_POST[$field])) {
throw new Exception('Please fill in all required fields.');
}
}
// Generate Request Number
$department = $_POST['department_name'];
$yearMonth = date('Ym');
// Find the last running number for this department and month
$stmt = $pdo->prepare('SELECT request_number FROM ChangeRequests WHERE request_number LIKE ? ORDER BY request_number DESC LIMIT 1');
$stmt->execute(["RSS/$department/$yearMonth/%"]);
$lastRequest = $stmt->fetch();
$runningNumber = 1;
if ($lastRequest) {
$parts = explode('/', $lastRequest['request_number']);
$lastRunningNumber = (int)end($parts);
$runningNumber = $lastRunningNumber + 1;
}
$requestNumber = sprintf('RSS/%s/%s/%03d', $department, $yearMonth, $runningNumber);
$stmt = $pdo->prepare(
'INSERT INTO ChangeRequests (request_number, company, hq_name, department_name, requester_name, extension, issued_date, desired_date, request_title, background_purpose, implementation_details, quantitative_effect, basis_of_calculation, qualitative_effect, category, impact_range, status, approval_level_pending) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
);
$stmt->execute([
$requestNumber,
$_POST['company'],
$_POST['hq_name'],
$_POST['department_name'],
$_POST['requester_name'],
$_POST['extension'] ?? null,
$_POST['issued_date'],
$_POST['desired_date'] ?? null,
$_POST['request_title'],
$_POST['background_purpose'],
$_POST['implementation_details'],
$_POST['quantitative_effect'] ?? null,
$_POST['basis_of_calculation'] ?? null,
$_POST['qualitative_effect'] ?? null,
$_POST['category'],
$_POST['impact_range'],
'Pending Approval', // Initial status
'Dept Manager/GM' // Initial approval level
]);
$success_message = 'Request submitted successfully!';
} catch (Exception $e) {
$error_message = 'Error: ' . $e->getMessage();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Program Change Request</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<div style="text-align: right; margin-bottom: 20px;">
Logged in as <strong><?php echo htmlspecialchars($_SESSION['username']); ?></strong> | <a href="logout.php">Logout</a>
</div>
<h1>Create Program Change Request</h1>
<?php if ($success_message): ?>
<div class="alert alert-success"><?php echo $success_message; ?></div>
<?php endif; ?>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form action="create_request.php" method="POST">
<div class="row">
<div class="col-md-6 mb-3">
<label for="company" class="form-label">Company / 会社名 *</label>
<input type="text" class="form-control" id="company" name="company" required>
</div>
<div class="col-md-6 mb-3">
<label for="hq_name" class="form-label">Headquarters / 本部名 *</label>
<input type="text" class="form-control" id="hq_name" name="hq_name" required>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="department_name" class="form-label">Department / 部署名 *</label>
<select class="form-select" id="department_name" name="department_name" required>
<option value="">Select a department</option>
<option value="Sales">Sales</option>
<option value="Marketing">Marketing</option>
<option value="Engineering">Engineering</option>
<option value="HR">HR</option>
<option value="Other">Other</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="requester_name" class="form-label">Requester Name / 依頼者名 *</label>
<input type="text" class="form-control" id="requester_name" name="requester_name" value="<?php echo htmlspecialchars($_SESSION['username']); ?>" required>
</div>
</div>
<div class="row">
<div class="col-md-4 mb-3">
<label for="extension" class="form-label">Extension / 内線</label>
<input type="text" class="form-control" id="extension" name="extension">
</div>
<div class="col-md-4 mb-3">
<label for="issued_date" class="form-label">Issued Date / 発行日 *</label>
<input type="date" class="form-control" id="issued_date" name="issued_date" required>
</div>
<div class="col-md-4 mb-3">
<label for="desired_date" class="form-label">Desired Date / 希望納期</label>
<input type="date" class="form-control" id="desired_date" name="desired_date">
</div>
</div>
<div class="mb-3">
<label for="request_title" class="form-label">Request Title / 依頼件名 *</label>
<input type="text" class="form-control" id="request_title" name="request_title" required>
</div>
<div class="mb-3">
<label for="background_purpose" class="form-label">Background & Purpose / 背景・目的 *</label>
<textarea class="form-control" id="background_purpose" name="background_purpose" rows="3" required></textarea>
</div>
<div class="mb-3">
<label for="implementation_details" class="form-label">Implementation Details / 内容 *</label>
<textarea class="form-control" id="implementation_details" name="implementation_details" rows="5" required></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="category" class="form-label">Category / カテゴリー *</label>
<select class="form-select" id="category" name="category" required>
<option value="">Select a category</option>
<option value="Legal">Legal / 法改正</option>
<option value="Business Challenge">Business Challenge / 経営課題</option>
<option value="Cust. Complaint">Cust. Complaint / 顧客クレーム</option>
<option value="Cust. Request">Cust. Request / 顧客要望</option>
<option value="Settings/Conversions">Settings/Conversions / 設定変更・変換</option>
<option value="Improvement">Improvement / 改善</option>
<option value="Other">Other / その他</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="impact_range" class="form-label">Impact Range / 影響範囲 *</label>
<select class="form-select" id="impact_range" name="impact_range" required>
<option value="">Select impact range</option>
<option value="All ROHM">All ROHM / 全社</option>
<option value="Within Headquarters">Within Headquarters / 本部内</option>
<option value="Within Dept/Div">Within Dept/Div / 部門内</option>
<option value="Other">Other / その他</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit Request</button>
<a href="index.php" class="btn btn-secondary">Back to Home</a>
</form>
</div>
</body>
</html>