293 lines
8.4 KiB
PHP
293 lines
8.4 KiB
PHP
<?php
|
|
/**
|
|
* 상담 일정 설정
|
|
*/
|
|
$sub_menu = '850300';
|
|
include_once('./_common.php');
|
|
|
|
// 관리자 권한 확인
|
|
if (!$is_admin) {
|
|
alert('관리자만 접근할 수 있습니다.');
|
|
}
|
|
|
|
// 설치 확인
|
|
if (!is_consultant_installed()) {
|
|
alert('상담 예약 시스템이 설치되지 않았습니다.', 'install.php');
|
|
}
|
|
|
|
$g5['title'] = '상담 일정 설정';
|
|
|
|
// 월별 스케줄 생성 처리
|
|
if ($_POST['action'] == 'generate_monthly_schedule') {
|
|
try {
|
|
require_once('classes/ScheduleGenerator.class.php');
|
|
$generator = new ScheduleGenerator();
|
|
|
|
$year = (int)($_POST['year'] ?? date('Y'));
|
|
$month = (int)($_POST['month'] ?? date('n'));
|
|
|
|
// 충돌 검사
|
|
$conflicts = $generator->checkScheduleConflicts($year, $month);
|
|
if (!empty($conflicts)) {
|
|
$conflictMsg = "다음 예약과 충돌이 발생합니다:\\n";
|
|
foreach ($conflicts as $conflict) {
|
|
$conflictMsg .= "- {$conflict['date']} {$conflict['time']} {$conflict['customer']} ({$conflict['phone']})\\n";
|
|
}
|
|
$conflictMsg .= "\\n계속 진행하시겠습니까?";
|
|
|
|
if (!isset($_POST['force_generate'])) {
|
|
echo "<script>
|
|
if (confirm('{$conflictMsg}')) {
|
|
var form = document.createElement('form');
|
|
form.method = 'POST';
|
|
form.innerHTML = '<input type=\"hidden\" name=\"action\" value=\"generate_monthly_schedule\">' +
|
|
'<input type=\"hidden\" name=\"year\" value=\"{$year}\">' +
|
|
'<input type=\"hidden\" name=\"month\" value=\"{$month}\">' +
|
|
'<input type=\"hidden\" name=\"force_generate\" value=\"1\">';
|
|
document.body.appendChild(form);
|
|
form.submit();
|
|
}
|
|
</script>";
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 스케줄 생성
|
|
if ($generator->generateMonth($year, $month)) {
|
|
alert("{$year}년 {$month}월 스케줄이 생성되었습니다.", $_SERVER['PHP_SELF']);
|
|
} else {
|
|
alert("스케줄 생성에 실패했습니다.");
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
alert("오류가 발생했습니다: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 폼 처리 (기존 코드 유지)
|
|
if ($_POST['action'] == 'save_schedule') {
|
|
// 기존 스케줄 삭제
|
|
sql_query("DELETE FROM consultant_schedule WHERE day_of_week IS NOT NULL");
|
|
|
|
// 새 스케줄 저장
|
|
for ($day = 1; $day <= 7; $day++) {
|
|
$enabled = $_POST["day_{$day}_enabled"] ?? 0;
|
|
$start_time = $_POST["day_{$day}_start"] ?? '09:00';
|
|
$end_time = $_POST["day_{$day}_end"] ?? '18:00';
|
|
|
|
if ($enabled) {
|
|
$sql = "INSERT INTO consultant_schedule
|
|
(day_of_week, start_time, end_time, time_slot, max_persons, is_available)
|
|
VALUES ({$day}, '{$start_time}', '{$end_time}', 60, 2, 1)";
|
|
sql_query($sql);
|
|
}
|
|
}
|
|
|
|
alert('일정이 저장되었습니다.', $_SERVER['PHP_SELF']);
|
|
}
|
|
|
|
// 현재 스케줄 조회
|
|
$schedules = [];
|
|
$sql = "SELECT * FROM consultant_schedule WHERE day_of_week IS NOT NULL ORDER BY day_of_week";
|
|
$result = sql_query($sql);
|
|
while ($row = sql_fetch_array($result)) {
|
|
$schedules[$row['day_of_week']] = $row;
|
|
}
|
|
|
|
$days = ['', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일', '일요일'];
|
|
|
|
include_once(G5_ADMIN_PATH . '/admin.head.php');
|
|
?>
|
|
|
|
<style>
|
|
.schedule-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 30px;
|
|
padding: 20px;
|
|
background: #fff;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.schedule-tabs {
|
|
display: flex;
|
|
border-bottom: 2px solid #ddd;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.tab-button {
|
|
padding: 16px 28px;
|
|
border: none;
|
|
background: none;
|
|
cursor: pointer;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: #666;
|
|
text-decoration: none;
|
|
border-bottom: 3px solid transparent;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.tab-button.active {
|
|
color: #007bff;
|
|
border-bottom-color: #007bff;
|
|
}
|
|
|
|
.tab-content {
|
|
display: none;
|
|
}
|
|
|
|
.tab-content.active {
|
|
display: block;
|
|
}
|
|
|
|
.monthly-generator {
|
|
background: white;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
padding: 30px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.generator-form {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.alert {
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.alert-info {
|
|
color: #0c5460;
|
|
background-color: #d1ecf1;
|
|
border-color: #bee5eb;
|
|
}
|
|
|
|
.alert-warning {
|
|
color: #856404;
|
|
background-color: #fff3cd;
|
|
border-color: #ffeaa7;
|
|
}
|
|
.schedule-container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
.schedule-form {
|
|
background: white;
|
|
border: 1px solid #ddd;
|
|
border-radius: 8px;
|
|
padding: 30px;
|
|
}
|
|
.day-schedule {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 15px 0;
|
|
border-bottom: 1px solid #eee;
|
|
}
|
|
.day-schedule:last-child {
|
|
border-bottom: none;
|
|
}
|
|
.day-name {
|
|
width: 100px;
|
|
font-weight: bold;
|
|
}
|
|
.day-controls {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 15px;
|
|
flex: 1;
|
|
}
|
|
.time-input {
|
|
padding: 8px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
width: 100px;
|
|
}
|
|
.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;
|
|
}
|
|
.alert {
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
border: 1px solid transparent;
|
|
border-radius: 4px;
|
|
}
|
|
.alert-info {
|
|
color: #0c5460;
|
|
background-color: #d1ecf1;
|
|
border-color: #bee5eb;
|
|
}
|
|
</style>
|
|
|
|
<div class="schedule-container">
|
|
<h2><?php echo $g5['title']; ?></h2>
|
|
|
|
<div class="alert alert-info">
|
|
<strong>안내:</strong> 상담 가능한 요일과 시간을 설정하세요. 체크된 요일만 예약이 가능합니다.
|
|
</div>
|
|
|
|
<form method="post" class="schedule-form">
|
|
<input type="hidden" name="action" value="save_schedule">
|
|
|
|
<?php for ($day = 1; $day <= 7; $day++): ?>
|
|
<?php
|
|
$schedule = $schedules[$day] ?? null;
|
|
$enabled = $schedule ? 1 : 0;
|
|
$start_time = $schedule['start_time'] ?? '09:00';
|
|
$end_time = $schedule['end_time'] ?? '18:00';
|
|
?>
|
|
|
|
<div class="day-schedule">
|
|
<div class="day-name"><?php echo $days[$day]; ?></div>
|
|
<div class="day-controls">
|
|
<label>
|
|
<input type="checkbox" name="day_<?php echo $day; ?>_enabled" value="1"
|
|
<?php echo $enabled ? 'checked' : ''; ?>>
|
|
운영
|
|
</label>
|
|
|
|
<label>
|
|
시작:
|
|
<input type="time" name="day_<?php echo $day; ?>_start"
|
|
value="<?php echo $start_time; ?>" class="time-input">
|
|
</label>
|
|
|
|
<label>
|
|
종료:
|
|
<input type="time" name="day_<?php echo $day; ?>_end"
|
|
value="<?php echo $end_time; ?>" class="time-input">
|
|
</label>
|
|
</div>
|
|
</div>
|
|
<?php endfor; ?>
|
|
|
|
<div style="text-align: center; margin-top: 30px;">
|
|
<button type="submit" class="btn btn-primary">저장</button>
|
|
<a href="dashboard.php" class="btn btn-secondary">대시보드로</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<?php
|
|
include_once(G5_ADMIN_PATH . '/admin.tail.php');
|
|
?>
|