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

164 lines
5.3 KiB
PHP

<?php
include_once '_common.php';
if(!isset($_SESSION['user_id']) && !isset($_POST['app_id'])) exit; // 관리자가 업력하거나 온라인 주문이 아닌 경우 exit
if(isset($_POST['app_id'])) $user_name = $user_id = "온라인 자동입력"; // 온라인 주문인 경우 log에 온라인 자동입력임을 넣어줌
/*
파일 업로드를 하므로 uploadDir 경로의 권한이 777이어야 함
*/
// 변수 선언
$ca_id = trim($_POST['ca_id']); // 회원구분
$app_id = trim($_POST['app_id']); // 접수자, 온라인 주문의 경우 온라인으로 처리
$mem_no = isset($_POST['mem_no']) ? trim($_POST['mem_no']) : ""; // 회원번호
$mem_name = trim($_POST['name']); // 성명
$mem_gender = trim($_POST['gender']); // 성별
$mem_tel = addTelHyphen(trim($_POST['tel'])); // 연락처
$mem_birth = trim($_POST['birth']); // 생일
$mem_email = trim($_POST['email']); // 이메일
$mem_addr = trim($_POST['addr']); // 주소
$mem_memo = trim($_POST['memo']); // 메모
$mem_sdate = trim($_POST['sdate']); // 시작일
$mem_edate = getAnnualEdate($mem_sdate); // 종료일 만들어주기
$last_editdate = $datetime = date("Y-m-d H:i:s"); // 현재시간
if( isset($_POST['od_id']) ) { // 온라인 주문인 경우 자동으로 넣어줄 값
// 온라인 주문이므로 관리자가 한번 더 확인해야 함
$status = "검토대기";
// 주문정보
$od_qty = trim($_POST['od_qty']);
$od_id = trim($_POST['od_id']);
// 주문자 이름이 대표자명이 됨
$rep_name = trim($_POST['rep_name']);
} else {
// 관리자가 입력하는 경우
$status = "정상";
// 온라인 정보 없음
$od_qty = $od_id = $rep_name = "";
}
// 파일 업로드
if (isset($_FILES)) {
// 업로드 디렉토리를 설정
$dir = "/data/annual_member_photo/"; // 업로드 디렉토리
$uploadDir = FG_MANAGER_PATH.$dir; // 업로드 디렉토리 절대경로
$maxFileSize = 10 * 1024 * 1024; // 10MB
// 업로드된 파일의 정보 가져오기
$fileName = $_FILES["photofile"]["name"];
$fileTmpName = $_FILES["photofile"]["tmp_name"];
$fileSize = $_FILES["photofile"]["size"];
// 파일 확장자를 체크하고 허용되는 확장자를 지정
$allowedExtensions = ["jpg", "jpeg", "png", "gif"];
$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
if (in_array($fileExtension, $allowedExtensions)) {
// 파일 크기를 체크하고 원하는 크기로 제한
if ($fileSize <= $maxFileSize) {
// 새로운 파일 이름을 생성
$newFileName = uniqid() . "." . $fileExtension;
$uploadPath = $uploadDir . $newFileName;
// 임시 파일의 경로를 UTF-8로 변환
$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 {
alert("파일 크기가 너무 큽니다. 최대 파일 크기는 " . ($maxFileSize / (1024 * 1024)) . "MB입니다.");
}
} else if ($_SESSION['user_id'] != 'abc'){ // 최고관리자의 경우 체크 안함
alert("지원하지 않는 파일 형식입니다. jpg, jpeg, png, gif 파일만 허용됩니다.");
}
} else if ($_SESSION['user_id'] != 'abc') { // 최고관리자의 경우 체크 안함
alert("파일이 존재하지 않습니다");
}
// 파일 업로드 끝
// DB에 입력
// 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,
od_qty,
rep_name
)";
// 값 지정
$query .= "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}',
'{$od_qty}',
'{$rep_name}'
) ";
// 쿼리실행
$result = sql_query($query);
/*
// 전체 재고 DB에 업데이트
$memo = $mem_no.' 불출, 처리자 : '.$_SESSION['user_name'];
$update_query = "INSERT INTO {$fg['card_stock_table']} (status, output, date, memo) VALUES('출고', '1','{$time}','{$memo}')";
$update = sql_query($update_query);
*/
if ( $result ) { // DB 업데이트가 완료되면 로그를 기록한다.
// log 기록
$work = "연간회원등록";
$work_detail = "번호 : ".$mem_no." 처리자 : ".$user_name;
$logquery = "INSERT INTO {$fg['log_table']} (work, work_detail, id, date) VALUES ('카드불출', '{$work_detail}', '{$user_id}', '{$datetime}')";
$logResult = log_update($work, $work_detail, $user_id, $datetime);
if ( $logResult ) {
if( $status == "검토대기" ) { // 온라인 주문의 경우 마이페이지로 넘겨줌
alert("저장 완료", "/firstgarden/shop/mypage.php");
}
alert("저장 완료", false);
} else {
alert("로그 저장 실패");
}
} else {
alert("저장 실패");
}