Files
firstgarden-web-gnu/theme/rb.basic/skin/shop/basic/reservation.skin.php
2025-07-02 14:13:16 +09:00

688 lines
31 KiB
PHP

<style>
#rb_reservation .ui-datepicker {box-shadow: none; width: 100% !important; margin-top: 0px; border-radius: 10px;}
#rb_reservation .ui-state-highlight, .ui-widget-content .ui-state-highlight, .ui-widget-header .ui-state-highlight {padding: 0px; background-color: transparent;}
#rb_reservation .rb_reservation_l {float:left; width: 55%;}
#rb_reservation .rb_reservation_r {float:right; width: 45%; padding-left: 50px;}
#rb_reservation .ui-datepicker-calendar>tbody>tr>td {height:50px;}
#rb_reservation .ui-datepicker td.ui-datepicker-today {background: #F0F3F9 !important; border-radius: 10px;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-start {background: #BAC1D1 !important; color:#fff !important; border-radius: 10px; border-bottom-right-radius: 0px; border-top-right-radius: 0px;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-start a {color:#fff !important;}
#rb_reservation .ui-datepicker td.ui-state-highlight {background: #BAC1D1 !important; border-radius: 0px; color:#fff !important;}
#rb_reservation .ui-datepicker td.ui-state-highlight a {color:#fff !important;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-end {background: #BAC1D1 !important; color:#fff !important; border-radius: 10px; border-bottom-left-radius: 0px; border-top-left-radius: 0px;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-end a {color:#fff !important;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-d {background: #BAC1D1 !important; color:#fff !important; border-radius: 10px;}
#rb_reservation .ui-datepicker td.ui-datepicker-current-day-d a {color:#fff !important;}
#rb_reservation .ct_date {border:0px !important; padding: 0px; font-size: 20px; width:120px; height:30px;}
#rb_reservation .ct_date:focus {border:0px;}
#rb_reservation .ct_date::placeholder {color:#bbb; font-family: "font-R";}
#rb_reservation .d_flex {display: flex; align-items: center; flex-direction: row; flex-wrap: wrap; gap:0 5px;}
#rb_reservation .d_flex dd {font-size: 20px;}
#rb_reservation .d_flex dd#mg_span {margin-left: -5px;}
#rb_reservation .it_date_t_wrap {background-color: #F0F3F9; border-radius: 10px; height: 150px; overflow-y: auto; margin-top: 15px;}
#rb_reservation .it_date_t_wrap dd {border-top:1px solid rgba(0,0,0,0.1); padding-top: 10px; padding-bottom: 10px; padding-left: 20px; padding-right: 20px;}
#rb_reservation .it_date_t_wrap dd:hover {background-color: #E3E6ED;}
#rb_reservation .it_date_t_wrap h6 {display: block; color:rgba(0,0,0,0.4); padding: 20px;}
#rb_reservation input[type="radio"][disabled] + label {opacity: .5;}
#rb_reservation #ct_date_d {text-align: right;}
#rb_reservation .number-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100%, 1fr)); /* 개수에 따라 자동 조절 */
gap: 10px; /* 요소 간격 */
}
#rb_reservation .number-box {
display: flex;
align-items: center;
border: 1px solid rgba(0,0,0,0.1);
border-radius: 10px;
overflow: hidden;
position: relative;
}
#rb_reservation .number-box button {width: 45px;height: 45px;border: none;background: #fff;cursor: pointer;font-size: 18px; opacity: 0.5; border-left: 1px solid rgba(0,0,0,0.1);}
#rb_reservation .number-box button:hover {opacity: 1;}
#rb_reservation .number-box button.decrease {}
#rb_reservation .number-box input {border:0px !important; border-radius: 0px; width: 45px;height: 45px;text-align: center;border: none;font-size: 16px;outline: none;flex: 1; padding-left: 15px; padding-right: 15px; font-size: 13px; background-color: #fff; text-align: left; text-align: right;}
#rb_reservation .number-box label {font-size: 13px; width: 50%; padding-left: 20px;}
#rb_reservation .number-box label.cnt_wd {width: auto;}
#rb_reservation #ct_res_pri {margin-top: 15px;}
#rb_reservation #ct_res_pri {font-size:1.167em;line-height:45px;text-align:right}
#rb_reservation #ct_res_pri:after {display:block;visibility:hidden;clear:both;content:""}
#rb_reservation #ct_res_pri span {float:left}
#rb_reservation #ct_res_pri strong {font-size:1.5em;margin-left:15px}
.sit_rels {margin-top: 0px; padding-top: 0px; border-top: 1px solid #e3e3e3;}
@media all and (max-width:768px) {
#rb_reservation .rb_reservation_l {float:none; width: 100%; margin-top: 25px;}
#rb_reservation .rb_reservation_r {float:none; width: 100%; margin-top: 25px; padding-left: 0px;}
#rb_reservation .number-box input {height:50px;}
}
</style>
<?php
$todayd = date('Y-m-d');
$one_year_later = date('Y-m-d', strtotime('+1 year -1 day'));
?>
<div class="sit_rels">
<section id="sit_rel">
<br>
<h2>사용 기간</h2>
<div id="rb_reservation">
<ul class="rb_reservation_l">
<div id="datepicker"></div>
</ul>
<ul class="rb_reservation_r">
<li class="d_flex">
<dd>
<input type="text" id="ct_date_s" class="ct_date font-B main_color" value="<?php echo $todayd ?>" name="ct_date_s" readonly placeholder="0000-00-00">
<input type="hidden" id="ct_types" name="ct_types" readonly value="<?php echo isset($it['it_types']) ? $it['it_types'] : ''; ?>"> <!-- 상품타입 -->
</dd>
<dd class="font-B" id="mg_span">~</dd>
<dd><input type="text" id="ct_date_e" class="ct_date font-B main_color" value="<?php echo $one_year_later ?>" name="ct_date_e" readonly placeholder="0000-00-00">
</dd>
<dd>
<input type="hidden" id="ct_date_d" class="ct_date font-B" name="ct_date_d" readonly value="" style="width:50px;" placeholder="0">
</dd>
</li>
<?php if(isset($it['it_date_g']) && $it['it_date_g'] == 1) { ?>
<li class="help_txt color-999">
<?php if(isset($it['it_date_min']) && $it['it_date_min'] < 1 && isset($it['it_date_max']) && $it['it_date_max'] < 1) { ?>
예약 가능한 일수 제한 없음
<?php } else { ?>
최소 <?php echo $it['it_date_min'] ?>일 ~ 최대 <?php echo $it['it_date_max']; ?>일 까지 예약이 가능합니다.
<?php } ?>
</li>
<?php } ?>
<?php if(isset($it['it_date_g']) && $it['it_date_g'] != 1 && isset($it['it_date_t']) && $it['it_date_t']) { ?>
<li class="it_date_t_wrap">
<h6>옵션을 선택하세요.</h6>
<?php
$it_date_t = trim($it['it_date_t']); // 앞뒤 공백 제거
$time_slots = explode("\n", $it_date_t); // 줄바꿈 기준으로 분리
if (!empty($time_slots)) {
$index = 1; // id 부여용 숫자
foreach ($time_slots as $slot) {
$slot = trim($slot); // 각 줄의 앞뒤 공백 제거
if (!empty($slot)) { // 빈 줄 방지
$input_id = "ct_date_t_" . $index; // 고유 id 생성
echo '<dd>
<input type="radio" id="' . $input_id . '" name="ct_date_t" value="' . htmlspecialchars($slot) . '">
<label for="' . $input_id . '">' . $slot . '</label>
</dd>';
$index++;
}
}
}
?>
</li>
<?php } ?>
<li class="mt-15">
<div class="number-container">
<?php if(isset($it['it_user_use1']) && $it['it_user_use1'] == 1) { ?>
<div class="number-box">
<label><span class="cut"><?php echo isset($it['it_user_txt1']) ? $it['it_user_txt1'] : ''; ?></span></label>
<label class="cnt_wd">수량</label>
<input type="text" class="num-input font-B main_color" name="adult" value="0" min="0" readonly>
<button type="button" class="decrease font-B">-</button>
<button type="button" class="increase font-B">+</button>
</div>
<?php } ?>
<?php if(isset($it['it_user_use2']) && $it['it_user_use2'] == 1) { ?>
<div class="number-box">
<label><?php echo isset($it['it_user_txt2']) ? $it['it_user_txt2'] : ''; ?></label>
<label class="cnt_wd">수량</label>
<input type="text" class="num-input font-B main_color" name="child" value="0" min="0" readonly>
<button type="button" class="decrease font-B">-</button>
<button type="button" class="increase font-B">+</button>
</div>
<?php } ?>
<?php if(isset($it['it_user_use3']) && $it['it_user_use3'] == 1) { ?>
<div class="number-box">
<label><?php echo isset($it['it_user_txt3']) ? $it['it_user_txt3'] : ''; ?></label>
<label class="cnt_wd">수량</label>
<input type="text" class="num-input font-B main_color" name="infant" value="0" min="0" readonly>
<button type="button" class="decrease font-B">-</button>
<button type="button" class="increase font-B">+</button>
</div>
<?php } ?>
</div>
</li>
<li id="ct_res_pri" class="font-R"></li>
</ul>
<ul class="cb"></ul>
</div>
</section>
</div>
<script>
$(document).ready(function () {
var target = document.querySelector("#sit_tot_price");
if (target) {
var observer = new MutationObserver(function (mutationsList) {
$("#ct_res_pri").text($("#sit_tot_price").text()); // 값 반영
$("#ct_res_pri").html($("#sit_tot_price").html());
});
observer.observe(target, { childList: true, subtree: true });
}
//인원선택
var adultPrice = parseInt("<?php echo $it['it_user_pri1']; ?>") || 0;
var childPrice = parseInt("<?php echo $it['it_user_pri2']; ?>") || 0;
var infantPrice = parseInt("<?php echo $it['it_user_pri3']; ?>") || 0;
function updatePeoplePrice() {
var adultCount = parseInt($(".num-input[name='adult']").val()) || 0;
var childCount = parseInt($(".num-input[name='child']").val()) || 0;
var infantCount = parseInt($(".num-input[name='infant']").val()) || 0;
var totalPeoplePrice = (adultCount * adultPrice) + (childCount * childPrice) + (infantCount * infantPrice);
// 기존 people_price 값 제거 후 새로운 값 추가
$("input[name='people_price']").remove();
$("<input>", {
type: "hidden",
name: "people_price",
value: totalPeoplePrice
}).appendTo("#sit_sel_option");
// price_calculate 호출하여 총 금액 업데이트
setTimeout(function() {
price_calculate();
}, 150);
}
// 인원 변경 이벤트 통합 (중복 이벤트 제거)
$(document).on("click", ".increase, .decrease", function() {
let input = $(this).siblings('.num-input');
let currentValue = parseInt(input.val(), 10) || 0;
let maxLimit = 0;
let minLimit = 0;
let labelText = ""; // 제목 변수
if (input.attr("name") === "adult") {
labelText = "<?php echo isset($it['it_user_txt1']) ? $it['it_user_txt1'] : '첫번째 항목'; ?>";
maxLimit = <?php echo isset($it['it_user_max1']) ? $it['it_user_max1'] : 0; ?>;
minLimit = <?php echo isset($it['it_user_min1']) ? $it['it_user_min1'] : 0; ?>;
} else if (input.attr("name") === "child") {
labelText = "<?php echo isset($it['it_user_txt2']) ? $it['it_user_txt2'] : '두번째 항목'; ?>";
maxLimit = <?php echo isset($it['it_user_max2']) ? $it['it_user_max2'] : 0; ?>;
minLimit = <?php echo isset($it['it_user_min2']) ? $it['it_user_min2'] : 0; ?>;
} else if (input.attr("name") === "infant") {
labelText = "<?php echo isset($it['it_user_txt3']) ? $it['it_user_txt3'] : '세번째 항목'; ?>";
maxLimit = <?php echo isset($it['it_user_max3']) ? $it['it_user_max3'] : 0; ?>;
minLimit = <?php echo isset($it['it_user_min3']) ? $it['it_user_min3'] : 0; ?>;
}
// 증가 시 최대값 초과 방지
if ($(this).hasClass("increase")) {
if (maxLimit > 0 && currentValue >= maxLimit) {
alert(labelText + "의 최대 선택 가능한 수량은 " + maxLimit + " 입니다.");
return;
}
input.val(currentValue + 1);
}
// 감소 시 최소값 이하로 내려가지 않도록 방지 (단, `minLimit > 0`일 때만 검사)
else if ($(this).hasClass("decrease")) {
if (minLimit > 0 && currentValue <= minLimit) {
alert(labelText + "은 최소 " + minLimit + "개 이상 선택해주셔야 합니다.");
input.val(minLimit);
return;
}
if (currentValue > 0) {
input.val(currentValue - 1);
}
}
updatePeoplePrice(); // 인원 변경 시 가격 업데이트
});
function checkMinimumValues(input) {
let currentValue = parseInt(input.val(), 10) || 0;
let minLimit = 0;
let labelText = "";
if (input.attr("name") === "adult") {
labelText = "<?php echo isset($it['it_user_txt1']) ? $it['it_user_txt1'] : '첫번째 항목'; ?>";
minLimit = <?php echo isset($it['it_user_min1']) ? $it['it_user_min1'] : 0; ?>;
} else if (input.attr("name") === "child") {
labelText = "<?php echo isset($it['it_user_txt2']) ? $it['it_user_txt2'] : '두번째 항목'; ?>";
minLimit = <?php echo isset($it['it_user_min2']) ? $it['it_user_min2'] : 0; ?>;
} else if (input.attr("name") === "infant") {
labelText = "<?php echo isset($it['it_user_txt3']) ? $it['it_user_txt3'] : '세번째 항목'; ?>";
minLimit = <?php echo isset($it['it_user_min3']) ? $it['it_user_min3'] : 0; ?>;
}
// 최소값 미달 시 alert 띄우고 최소값으로 변경
if (minLimit > 0 && currentValue < minLimit) {
alert(labelText + "은 최소 " + minLimit + "개 이상 선택해주셔야 합니다.");
//input.val(minLimit).focus();
}
}
$(document).on("input", ".num-input", function() {
let value = parseInt($(this).val(), 10);
if (isNaN(value) || value < 0) {
$(this).val(0);
}
updatePeoplePrice(); // 직접 입력 시 가격 업데이트
});
$("#datepicker").on("change", function() {
updatePeoplePrice();
});
//날짜선택
var startDate = null;
var endDate = null;
var availableStartDate = new Date("<?php echo $it['it_date_s']; ?>");
var availableEndDate = new Date("<?php echo $it['it_date_e']; ?>");
var disabledDates = <?php echo json_encode(array_map('trim', explode(',', $it['it_date_n']))); ?>;
var allowRangeSelection = <?php echo ($it['it_date_g'] == 1) ? 'true' : 'false'; ?>;
var basePrice = parseInt("<?php echo $it['it_price']; ?>") || 0;
// 오늘 날짜 가져오기 (시간 초기화)
var today = new Date();
today.setHours(0, 0, 0, 0);
// 최소 선택 가능 날짜 설정 (오늘과 availableStartDate 중 더 늦은 날짜 선택)
var minSelectableDate = availableStartDate > today ? availableStartDate : today;
$("#datepicker").datepicker({
dateFormat: "yy-mm-dd",
numberOfMonths: 1,
minDate: minSelectableDate,
maxDate: availableEndDate,
beforeShowDay: function (date) {
return [false, "", "날짜 선택 불가"];
var className = "";
var dateString = $.datepicker.formatDate("yy-mm-dd", date);
// 오늘 이전 날짜 선택 방지
if (date <= today) {
return [false, "", "오늘 이전 날짜 선택 불가"];
}
if (disabledDates.indexOf(dateString) !== -1) {
return [false, "", "예약 불가능한 날짜"];
}
if (startDate && endDate && date >= startDate && date <= endDate && allowRangeSelection) {
className = "ui-state-highlight";
}
return [true, className];
},
onSelect: function (dateText, inst) {
var selectedDate = new Date(dateText);
if (disabledDates.indexOf(dateText) !== -1) {
alert("예약 불가능한 날짜가 있습니다");
resetDateSelection();
return;
}
if (!allowRangeSelection) {
if (startDate && startDate.getTime() === selectedDate.getTime()) {
resetDateSelection();
return;
}
startDate = selectedDate;
endDate = null;
$("#ct_date_s").val(dateText);
$("#ct_date_e").val("");
} else {
if (!startDate || (startDate && endDate)) {
startDate = selectedDate;
endDate = null;
$("#ct_date_s").val(dateText);
$("#ct_date_e").val("");
} else {
endDate = selectedDate;
if (startDate > endDate) {
var temp = startDate;
startDate = endDate;
endDate = temp;
}
var currentDate = new Date(startDate.getTime());
while (currentDate <= endDate) {
var checkDate = $.datepicker.formatDate("yy-mm-dd", currentDate);
if (disabledDates.indexOf(checkDate) !== -1) {
alert("예약 불가능한 날짜가 있습니다");
resetDateSelection();
return;
}
currentDate.setDate(currentDate.getDate() + 1);
}
$("#ct_date_s").val($.datepicker.formatDate("yy-mm-dd", startDate));
$("#ct_date_e").val($.datepicker.formatDate("yy-mm-dd", endDate));
}
}
updateStayPrice(); // 날짜 변경 시 옵션만 업데이트 (중복 추가 방지)
setTimeout(addCurrentDayClass, 10);
$("#datepicker").datepicker("refresh");
//$("#mg_span").toggle($("#ct_date_e").val() !== "");
},
onChangeMonthYear: function (year, month, inst) {
setTimeout(function () {
addCurrentDayClass(year, month);
}, 10);
}
});
updateStayPrice();
function addCurrentDayClass(year, month) {
$(".ui-datepicker-calendar td").each(function () {
var dateText = $(this).text();
if (!dateText) return;
var currentYear = year || $("#datepicker").datepicker("getDate").getFullYear();
var currentMonth = month || $("#datepicker").datepicker("getDate").getMonth() + 1;
var formattedDate = currentYear + "-" +
(currentMonth < 10 ? "0" + currentMonth : currentMonth) + "-" +
(dateText < 10 ? "0" + dateText : dateText);
// 기존 ui-datepicker-current-day 관련 클래스 제거
$(this).removeClass("ui-datepicker-current-day ui-datepicker-current-day-start ui-datepicker-current-day-end ui-datepicker-current-day-d");
if ($("#ct_date_s").val() === formattedDate) {
if (allowRangeSelection) {
$(this).addClass("ui-datepicker-current-day-start"); // 시작 날짜에 적용
} else {
$(this).addClass("ui-datepicker-current-day-d"); // 단일 날짜에 적용
}
}
if ($("#ct_date_e").val() === formattedDate && allowRangeSelection) {
$(this).addClass("ui-datepicker-current-day-end"); // 종료 날짜에 적용
}
});
}
function updateStayPrice() {
var start = $("#ct_date_s").val();
var end = $("#ct_date_e").val();
if (!start) return;
var startDateObj = new Date(start);
var endDateObj = end ? new Date(end) : startDateObj;
var days = end ? Math.ceil((endDateObj - startDateObj) / (1000 * 60 * 60 * 24)) + 1 : 1;
if (days < 1) {
alert("기간을 올바르게 선택해주세요.");
return;
}
// 첫 번째 날짜 선택 시 "1일" 입력
if (!end) {
$("#ct_date_d").val("1");
} else {
$("#ct_date_d").val(days);
}
<?php if(isset($it['it_date_g']) && $it['it_date_g'] == 1) { ?>
// 최소 및 최대 일수 제한
var minDays = <?php echo isset($it['it_date_min']) ? $it['it_date_min'] : 0; ?>;
var maxDays = <?php echo isset($it['it_date_max']) ? $it['it_date_max'] : 0; ?>;
// 두 번째 날짜가 선택된 경우에만 검사
if (end) {
if (minDays > 0 && days < minDays) {
alert("최소 예약 가능 일수는 " + minDays + "일 입니다.");
resetDateSelection();
return;
}
if (maxDays > 0 && days > maxDays) {
alert("최대 예약 가능 일수는 " + maxDays + "일 입니다.");
resetDateSelection();
return;
}
}
<?php } ?>
// 옵션이 선택되지 않은 상태에서 날짜를 먼저 선택하면 경고 후 초기화
if ($(".sit_opt_list").length < 1) {
alert("상품의 선택옵션을 선택해 주십시오.");
resetDateSelection();
return false;
}
// ✅ 무조건 1일 금액만 적용
var datePrice = 0;
// 첫 번째 날짜 선택 시 가격 반영 없이 기존 옵션만 유지
//var datePrice = (!end) ? 0 : basePrice * (days - 1);
// 가격을 `price_calculate()`에서 처리하도록 히든 필드 업데이트
$("input[name='date_price']").remove(); // 기존 값 제거
$("<input>", {
type: "hidden",
name: "date_price",
value: datePrice
}).appendTo("#sit_sel_option");
// 기존 옵션들과 함께 총 금액 업데이트 (가격 계산 로직 활용)
setTimeout(function () {
price_calculate();
}, 150);
}
// 날짜 선택 초기화 함수 (잘못 선택한 경우)
function resetDateSelection() {
$("#ct_date_s, #ct_date_e").val("");
startDate = null;
endDate = null;
$("#datepicker").datepicker("refresh");
}
// `price_calculate()`에서 날짜 가격을 반영하도록 수정
if (typeof price_calculate === "function") {
price_calculate = (function() {
var cached_function = price_calculate;
return function() {
if ($(".2017_renewal_itemform").length) {
var it_price = parseInt($("input#it_price").val());
if (isNaN(it_price))
return;
var $el_prc = $("input.io_price");
var $el_qty = $("input[name^=ct_qty]");
var $el_type = $("input[name^=io_type]");
var date_price = parseInt($("input[name='date_price']").val()) || 0;
var people_price = parseInt($("input[name='people_price']").val()) || 0;
var price, type, qty, total = 0;
$el_prc.each(function(index) {
price = parseInt($(this).val());
qty = parseInt($el_qty.eq(index).val());
type = $el_type.eq(index).val();
if (type == "0") { // 선택옵션
total += (it_price + price) * qty;
} else { // 추가옵션
total += price * qty;
}
});
// 날짜 가격 추가
if (date_price > 0) {
total += date_price;
}
// 인원 가격 추가
if (people_price > 0) {
total += people_price;
}
$("#sit_tot_price").empty().html("<span>총 금액 : </span><strong>" + number_format(String(total)) + "</strong> 원");
$("#sit_tot_price").trigger("price_calculate", [total]);
} else {
cached_function.apply(this, arguments);
}
};
}());
}
});
//기존 submit 함수 처리
window.onload = function () {
// 기존 fitem_submit()이 있는지 확인 후 백업
if (typeof fitem_submit === "function") {
var original_fitem_submit = fitem_submit;
}
// 새로운 fitem_submit() 정의 (기존 함수 유지)
fitem_submit = function (f) {
// 예약 날짜 검증 로직 추가
<?php if(isset($it['it_date_g']) && $it['it_date_g'] == 1) { ?>
if (!$("#ct_date_s").val() || $("#ct_date_s").val().trim() === "") {
alert("사용 시작일 선택해주세요.");
return false;
}
if (!$("#ct_date_e").val() || $("#ct_date_e").val().trim() === "") {
alert("두번째 날짜를 선택해주세요.");
return false;
}
var startDate = new Date($("#ct_date_s").val());
var endDate = new Date($("#ct_date_e").val());
var days = Math.ceil((endDate - startDate) / (1000 * 60 * 60 * 24)) + 1;
var minDays = <?php echo isset($it['it_date_min']) ? $it['it_date_min'] : 0; ?>;
var maxDays = <?php echo isset($it['it_date_max']) ? $it['it_date_max'] : 0; ?>;
if (minDays > 0 && days < minDays) {
alert("최소 예약 가능 일수는 " + minDays + "일 입니다.");
return false;
}
if (maxDays > 0 && days > maxDays) {
alert("최대 예약 가능 일수는 " + maxDays + "일 입니다.");
return false;
}
<?php } else { ?>
if (!$("#ct_date_s").val() || $("#ct_date_s").val().trim() === "") {
alert("예약날짜를 선택해주세요.");
return false;
}
<?php } ?>
<?php if(isset($it['it_date_g']) && $it['it_date_g'] != 1 && isset($it['it_date_t']) && $it['it_date_t']) { ?>
// 예약 옵션 (`ct_date_t`)이 하나도 선택되지 않은 경우
if ($("input[name='ct_date_t']:checked").length === 0) {
alert("옵션을 선택해 주세요.");
return false;
}
<?php } ?>
let valid = true;
$(".num-input").each(function() {
let input = $(this);
let currentValue = parseInt(input.val(), 10) || 0;
let minLimit = 0;
let labelText = "";
if (input.attr("name") === "adult") {
labelText = "<?php echo isset($it['it_user_txt1']) ? $it['it_user_txt1'] : '첫번째항목'; ?>";
minLimit = <?php echo isset($it['it_user_min1']) ? $it['it_user_min1'] : 0; ?>;
} else if (input.attr("name") === "child") {
labelText = "<?php echo isset($it['it_user_txt2']) ? $it['it_user_txt2'] : '두번째항목'; ?>";
minLimit = <?php echo isset($it['it_user_min2']) ? $it['it_user_min2'] : 0; ?>;
} else if (input.attr("name") === "infant") {
labelText = "<?php echo isset($it['it_user_txt3']) ? $it['it_user_txt3'] : '세번째항목'; ?>";
minLimit = <?php echo isset($it['it_user_min3']) ? $it['it_user_min3'] : 0; ?>;
}
// 최소값 미달 시 alert 띄우고 포커스 이동, 폼 전송 방지
if (minLimit > 0 && currentValue < minLimit) {
alert("[" + labelText + "] 옵션은 최소 " + minLimit + " 이상 선택해주셔야 합니다.");
//input.val(minLimit).focus();
valid = false;
return false; // `each` 루프 종료
}
});
if (!valid) return false; // 최소값 미달 항목이 있으면 폼 전송 중단
var data = {
"ct_types": $("input[name='ct_types']").val(),
"ct_date_s": $("input[name='ct_date_s']").val(),
"ct_date_e": $("input[name='ct_date_e']").val(),
"ct_date_d": $("input[name='ct_date_d']").val(),
"ct_date_t": $("input[name='ct_date_t']:checked").val() || "", // 라디오 버튼
"ct_user_txt1": "<?php echo isset($it['it_user_txt1']) ? $it['it_user_txt1'] : ''; ?>",
"ct_user_txt2": "<?php echo isset($it['it_user_txt2']) ? $it['it_user_txt2'] : ''; ?>",
"ct_user_txt3": "<?php echo isset($it['it_user_txt3']) ? $it['it_user_txt3'] : ''; ?>",
"ct_user_qty1": $("input[name='adult']").val(),
"ct_user_qty2": $("input[name='child']").val(),
"ct_user_qty3": $("input[name='infant']").val(),
"ct_user_pri1": "<?php echo isset($it['it_user_pri1']) ? $it['it_user_pri1'] : ''; ?>",
"ct_user_pri2": "<?php echo isset($it['it_user_pri2']) ? $it['it_user_pri2'] : ''; ?>",
"ct_user_pri3": "<?php echo isset($it['it_user_pri3']) ? $it['it_user_pri3'] : ''; ?>"
};
$.each(data, function (key, value) {
$("<input>").attr({
type: "hidden",
class: "hidden-data",
name: key,
value: value
}).appendTo(f);
});
// 기존 `fitem_submit()`이 있다면 실행하고, `false` 반환 시 중단
if (typeof original_fitem_submit === "function") {
var result = original_fitem_submit(f);
if (result === false) return false;
}
// ✅ 폼 전송 전 ct_date_d 무조건 0로 덮어쓰기
$("input[name='ct_date_d']").val("1");
return true;
};
};
</script>