Files
dnssash/adm/consultant_manage/tesst/test_schedule_generation.php
T
2026-06-11 18:47:38 +09:00

191 lines
5.8 KiB
PHP

<?php
/**
* 스케줄 생성 테스트 페이지
*/
include_once('./_common.php');
// 관리자 권한 확인
if (!$is_admin) {
alert('관리자만 접근할 수 있습니다.');
}
// 설치 확인
if (!is_consultant_installed()) {
alert('상담 예약 시스템이 설치되지 않았습니다.', 'install.php');
}
$g5['title'] = '스케줄 생성 테스트';
// 테스트 실행
if ($_POST['action'] == 'test_generation') {
$year = (int) ($_POST['year'] ?? date('Y'));
$month = (int) ($_POST['month'] ?? date('n'));
try {
require_once('classes/ScheduleGenerator.class.php');
$generator = new ScheduleGenerator();
echo "<h3>테스트 결과</h3>";
echo "<p><strong>대상:</strong> {$year}{$month}월</p>";
// 기존 스케줄 확인
$existing = sql_fetch("SELECT COUNT(*) as count FROM consultant_schedule WHERE YEAR(specific_date) = {$year} AND MONTH(specific_date) = {$month}");
echo "<p><strong>기존 스케줄:</strong> {$existing['count']}개</p>";
// 충돌 검사
// 💡 [수정] 최신 충돌 검사 로직으로 변경
$conflicts = $generator->findConflictsWithNewSettings($year, $month);
echo "<p><strong>충돌 검사:</strong> " . count($conflicts) . "건</p>";
if (!empty($conflicts)) {
echo "<ul>";
foreach ($conflicts as $conflict) {
echo "<li>{$conflict['date']} {$conflict['time']} - {$conflict['customer']} ({$conflict['reason']})</li>";
}
echo "</ul>";
}
// 스케줄 생성
$result = $generator->generateMonth($year, $month);
if ($result) {
$new_count = sql_fetch("SELECT COUNT(*) as count FROM consultant_schedule WHERE YEAR(specific_date) = {$year} AND MONTH(specific_date) = {$month}");
echo "<p style='color: green;'><strong>✅ 성공:</strong> {$new_count['count']}개 스케줄 생성 완료</p>";
// 생성된 스케줄 샘플 표시
$samples = sql_query("SELECT * FROM consultant_schedule WHERE YEAR(specific_date) = {$year} AND MONTH(specific_date) = {$month} ORDER BY specific_date, start_time LIMIT 10");
echo "<h4>생성된 스케줄 샘플 (최대 10개)</h4>";
echo "<table border='1' style='border-collapse: collapse; width: 100%;'>";
echo "<tr><th>날짜</th><th>시작시간</th><th>종료시간</th><th>최대인원</th><th>사용가능</th><th>타입</th></tr>";
while ($row = sql_fetch_array($samples)) {
$available = $row['is_available'] ? '가능' : '불가능';
$type = $row['temp_1'] ?? '일반';
echo "<tr>";
echo "<td>{$row['specific_date']}</td>";
echo "<td>{$row['start_time']}</td>";
echo "<td>{$row['end_time']}</td>";
echo "<td>{$row['max_persons']}</td>";
echo "<td>{$available}</td>";
echo "<td>{$type}</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<p style='color: red;'><strong>❌ 실패:</strong> 스케줄 생성에 실패했습니다.</p>";
}
} catch (Exception $e) {
echo "<p style='color: red;'><strong>오류:</strong> " . htmlspecialchars($e->getMessage()) . "</p>";
}
echo "<hr>";
}
include_once(G5_ADMIN_PATH . '/admin.head.php');
?>
<style>
.test-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
.test-form {
background: white;
border: 1px solid #ddd;
border-radius: 8px;
padding: 30px;
margin-bottom: 20px;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.form-group input,
.form-group select {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
width: 200px;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: 600;
}
.btn-primary {
background: #007bff;
color: white;
}
.btn-secondary {
background: #6c757d;
color: white;
}
table {
margin-top: 15px;
}
th,
td {
padding: 8px;
text-align: left;
border: 1px solid #ddd;
}
th {
background-color: #fff;
}
</style>
<div class="test-container">
<h2><?php echo $g5['title']; ?></h2>
<div class="test-form">
<h3>스케줄 생성 테스트</h3>
<p>선택한 년월의 스케줄을 생성하고 결과를 확인합니다.</p>
<form method="post">
<input type="hidden" name="action" value="test_generation">
<div class="form-group">
<label for="year">년도</label>
<input type="number" id="year" name="year" value="<?php echo date('Y'); ?>" min="2024" max="2030">
</div>
<div class="form-group">
<label for="month">월</label>
<select id="month" name="month">
<?php for ($i = 1; $i <= 12; $i++): ?>
<option value="<?php echo $i; ?>" <?php echo $i == date('n') ? 'selected' : ''; ?>>
<?php echo $i; ?>월
</option>
<?php endfor; ?>
</select>
</div>
<div style="margin-top: 20px;">
<button type="submit" class="btn btn-primary">스케줄 생성 테스트</button>
<a href="../settings.php" class="btn btn-secondary">설정으로 돌아가기</a>
</div>
</form>
</div>
</div>
<?php
include_once(G5_ADMIN_PATH . '/admin.tail.php');
?>