Files
firstgarden-web-gnu/manager/annual_member/annual_member_insert.update.php

169 lines
5.9 KiB
PHP

<?php
include_once '_common.php';
if(!isset($_SESSION['user_id']) && !isset($_POST['app_id'])) exit; // 관리자가 입력하거나 온라인 주문이 아닌 경우 exit
if(isset($_POST['app_id'])) {
$app_id = trim($_POST['app_id']); // 접수자, 온라인 주문의 경우 온라인으로 처리
} else {
$user_name = $user_id = "온라인 자동입력"; // 온라인 주문인 경우 log에 온라인 자동입력임을 넣어줌
$app_id = "온라인";
}
$isDebug = false;
if ($isDebug) {
var_dump($_REQUEST);
echo "<br>";
}
/*
파일 업로드를 하므로 uploadDir 경로의 권한이 777이어야 함
*/
// 기본 변수 선언
$last_editdate = $datetime = date("Y-m-d H:i:s"); // 현재시간
if(isset($_POST['od_id'])) { // 온라인 주문인 경우 자동으로 넣어줄 값
$status = "검토대기";
$od_id = trim($_POST['od_id']); // 주문 ID
$rep_name = trim($_POST['rep_name']); // 대표자 이름
} else {
$status = "정상";
$od_id = $rep_name = "";
}
// 파일 업로드 설정
$dir = "/data/annual_member_photo/"; // 업로드 디렉토리
$uploadDir = FG_MANAGER_PATH . $dir; // 업로드 디렉토리 절대경로
$maxFileSize = 10 * 1024 * 1024; // 10MB
$allowedExtensions = ["jpg", "jpeg", "png", "gif"]; // 허용되는 파일 확장자
// 주문 수량만큼 처리
$od_qty = trim($_POST['it_id_cnt']);
if ($isDebug) echo "주문건수 : " . $od_qty . "<br>";
for ($i = 0; $i < $od_qty; $i++) {
$ct_qty = $_POST['ct_qty_' . $i . '0'];
if ($isDebug) {
echo '$i : ' . $i . "<br>";
echo "주문수량 : " . $ct_qty . "<br>";
}
for ($j = 0; $j < $ct_qty; $j++) {
// 개별 변수 선언
$ca_id = trim($_POST['ca_id_' . $i . $j]);
$mem_no = isset($_POST['mem_no_' . $i . $j]) ? trim($_POST['mem_no_' . $i . $j]) : ""; // 회원번호
$mem_name = trim($_POST['name_' . $i . $j]); // 성명
$mem_gender = trim($_POST['gender_' . $i . $j]); // 성별
$mem_tel = addTelHyphen(trim($_POST['tel_' . $i . $j])); // 연락처
$mem_birth = trim($_POST['birth_' . $i . $j]); // 생일
$mem_email = trim($_POST['email_' . $i . $j]); // 이메일
$mem_addr = trim($_POST['addr_' . $i . $j]); // 주소
$mem_memo = isset($_POST['memo_' . $i . $j]) ? trim($_POST['memo_' . $i . $j]) : ""; // 메모
$mem_sdate = trim($_POST['sdate_' . $i . $j]); // 시작일
$mem_edate = getAnnualEdate($mem_sdate); // 종료일 만들어주기
// 파일 업로드 처리
$fileName = $_FILES["photofile_" . $i . $j]["name"];
$fileTmpName = $_FILES["photofile_" . $i . $j]["tmp_name"];
$fileSize = $_FILES["photofile_" . $i . $j]["size"];
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (in_array($fileExtension, $allowedExtensions) && $fileSize <= $maxFileSize) {
$newFileName = uniqid() . "." . $fileExtension;
$uploadPath = $uploadDir . $newFileName;
$utf8TmpFileName = mb_convert_encoding($fileTmpName, 'UTF-8', 'auto');
if (move_uploaded_file($utf8TmpFileName, $uploadPath)) {
$photo_url = FG_MANAGER_URL . $dir . $newFileName;
$photo_name = $fileName;
} else {
alert("파일 업로드 실패.");
}
} else if (!$isDebug) {
alert("지원하지 않는 파일 형식이거나 파일 크기가 너무 큽니다. jpg, jpeg, png, gif 파일만 허용되며 최대 파일 크기는 " . ($maxFileSize / (1024 * 1024)) . "MB입니다.");
}
if ($isDebug) $photo_url = $photo_name = '';
// DB에 입력
$query = "INSERT INTO {$fg['annual_member_table']} (
mem_no,
status,
ca_id,
app_id,
name,
memo,
birth,
email,
addr,
tel,
gender,
sdate,
edate,
photo_url,
photo_name,
join_datetime,
last_edit_date,
last_edit_id,
last_ent_date,
ent_count,
od_id,
rep_name
) VALUES (
'{$mem_no}',
'{$status}',
'{$ca_id}',
'{$app_id}',
'{$mem_name}',
'{$mem_memo}',
'{$mem_birth}',
'{$mem_email}',
'{$mem_addr}',
'{$mem_tel}',
'{$mem_gender}',
'{$mem_sdate}',
'{$mem_edate}',
'{$photo_url}',
'{$photo_name}',
'{$last_editdate}',
'{$last_editdate}',
'{$user_id}',
'0000-00-00 00:00:00',
0,
'{$od_id}',
'{$rep_name}'
)";
if ($isDebug) {
print_r($query); // 디버깅인 경우 출력
echo "<br>";
$result = false;
} else {
$result = sql_query($query);
}
if ($result) {
// log 기록
$work = "연간회원등록";
$work_detail = "번호 : " . $mem_no . " 처리자 : " . $user_name;
log_update($work, $work_detail, $user_id, $datetime);
} else if (!$isDebug) {
alert("저장 실패");
}
}
}
if (isset($result) && $result) { // 저장이 성공했다면
// 상태를 완료처리
$update_query = "UPDATE {$g5['g5_shop_cart_table']} SET od_status = '완료' WHERE od_id = '{$od_id}'";
$result = sql_query($update_query); // 업데이트
alert("저장 완료", false);
}