2022-09-17 20:50:50 +09:00
< ? php
2024-09-23 11:07:19 +09:00
include_once " ./_common.php " ;
2022-09-17 20:50:50 +09:00
/*==========================
$w == a : 답변
$w == r : 추가질문
$w == u : 수정
==========================*/
2024-09-19 20:57:39 +09:00
if ( $is_guest )
alert ( '회원이시라면 로그인 후 이용해 보십시오.' , './login.php?url=' . urlencode ( G5_BBS_URL . '/qalist.php' ));
2022-09-17 20:50:50 +09:00
2024-09-23 09:37:13 +09:00
$msg = [];
2022-09-17 20:50:50 +09:00
// 1:1문의 설정값
$qaconfig = get_qa_config ();
2024-09-19 20:57:39 +09:00
if ( trim ( $qaconfig [ 'qa_category' ])) {
if ( $w != 'a' ) {
$category = explode ( '|' , $qaconfig [ 'qa_category' ]);
if ( ! in_array ( $qa_category , $category ))
alert ( '분류를 올바르게 지정해 주십시오.' );
}
2022-09-17 20:50:50 +09:00
} else {
2024-09-19 20:57:39 +09:00
alert ( '1:1문의 설정에서 분류를 설정해 주십시오' );
2022-09-17 20:50:50 +09:00
}
// e-mail 체크
$qa_email = '' ;
2024-09-19 20:57:39 +09:00
if ( isset ( $_POST [ 'qa_email' ]) && $_POST [ 'qa_email' ])
$qa_email = get_email_address ( trim ( $_POST [ 'qa_email' ]));
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w != 'a' && $qaconfig [ 'qa_req_email' ] && ! $qa_email )
$msg [] = '이메일을 입력하세요.' ;
2022-09-17 20:50:50 +09:00
$qa_subject = '' ;
if ( isset ( $_POST [ 'qa_subject' ])) {
2024-09-19 20:57:39 +09:00
$qa_subject = substr ( trim ( $_POST [ 'qa_subject' ]), 0 , 255 );
$qa_subject = preg_replace ( " #[ \\ \ ]+ $ # " , " " , $qa_subject );
2022-09-17 20:50:50 +09:00
}
if ( $qa_subject == '' ) {
2024-09-19 20:57:39 +09:00
$msg [] = '<strong>제목</strong>을 입력하세요.' ;
2022-09-17 20:50:50 +09:00
}
$qa_content = '' ;
if ( isset ( $_POST [ 'qa_content' ])) {
2024-09-19 20:57:39 +09:00
$qa_content = substr ( trim ( $_POST [ 'qa_content' ]), 0 , 65536 );
$qa_content = preg_replace ( " #[ \\ \ ]+ $ # " , " " , $qa_content );
2022-09-17 20:50:50 +09:00
}
if ( $qa_content == '' ) {
2024-09-19 20:57:39 +09:00
$msg [] = '<strong>내용</strong>을 입력하세요.' ;
2022-09-17 20:50:50 +09:00
}
if ( ! empty ( $msg )) {
2024-09-19 20:57:39 +09:00
$msg = implode ( '<br>' , $msg );
alert ( $msg );
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
if ( $qa_hp )
$qa_hp = preg_replace ( '/[^0-9\-]/' , '' , strip_tags ( $qa_hp ));
2022-09-17 20:50:50 +09:00
// 090710
if ( substr_count ( $qa_content , '&#' ) > 50 ) {
2024-09-19 20:57:39 +09:00
alert ( '내용에 올바르지 않은 코드가 다수 포함되어 있습니다.' );
exit ;
2022-09-17 20:50:50 +09:00
}
$upload_max_filesize = ini_get ( 'upload_max_filesize' );
if ( empty ( $_POST )) {
2024-09-19 20:57:39 +09:00
alert ( " 파일 또는 글내용의 크기가 서버에서 설정한 값을 넘어 오류가 발생하였습니다. \\ npost_max_size= " . ini_get ( 'post_max_size' ) . " , upload_max_filesize= " . $upload_max_filesize . " \\ n게시판관리자 또는 서버관리자에게 문의 바랍니다. " );
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
for ( $i = 1 ; $i <= 5 ; $i ++ ) {
$var = " qa_ $i " ;
$$var = " " ;
if ( isset ( $_POST [ 'qa_' . $i ]) && $_POST [ 'qa_' . $i ]) {
$$var = trim ( $_POST [ 'qa_' . $i ]);
}
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
if ( $w == 'u' || $w == 'a' || $w == 'r' ) {
if ( $w == 'a' && ! $is_admin )
alert ( '답변은 관리자만 등록할 수 있습니다.' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$sql = " select * from { $g5 [ 'qa_content_table' ] } where qa_id = ' $qa_id ' " ;
if ( ! $is_admin ) {
$sql .= " and mb_id = ' { $member [ 'mb_id' ] } ' " ;
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$write = sql_fetch ( $sql );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w == 'u' ) {
if ( ! $write [ 'qa_id' ])
alert ( '게시글이 존재하지 않습니다.\\n삭제되었거나 자신의 글이 아닌 경우입니다.' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( ! $is_admin ) {
if ( $write [ 'qa_type' ] == 0 && $write [ 'qa_status' ] == 1 )
alert ( '답변이 등록된 문의글은 수정할 수 없습니다.' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $write [ 'mb_id' ] != $member [ 'mb_id' ])
alert ( '게시글을 수정할 권한이 없습니다.\\n\\n올바른 방법으로 이용해 주십시오.' , G5_URL );
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w == 'a' ) {
if ( ! $write [ 'qa_id' ])
alert ( '문의글이 존재하지 않아 답변글을 등록할 수 없습니다.' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $write [ 'qa_type' ] == 1 )
alert ( '답변글에는 다시 답변을 등록할 수 없습니다.' );
}
2022-09-17 20:50:50 +09:00
}
// 파일개수 체크
2024-09-19 20:57:39 +09:00
$file_count = 0 ;
2022-09-17 20:50:50 +09:00
$upload_count = count ( $_FILES [ 'bf_file' ][ 'name' ]);
2024-09-19 20:57:39 +09:00
for ( $i = 1 ; $i <= $upload_count ; $i ++ ) {
if ( $_FILES [ 'bf_file' ][ 'name' ][ $i ] && is_uploaded_file ( $_FILES [ 'bf_file' ][ 'tmp_name' ][ $i ]))
$file_count ++ ;
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
if ( $file_count > 2 )
alert ( '첨부파일을 2개 이하로 업로드 해주십시오.' );
2022-09-17 20:50:50 +09:00
// 디렉토리가 없다면 생성합니다. (퍼미션도 변경하구요.)
2024-09-19 20:57:39 +09:00
@ mkdir ( G5_DATA_PATH . '/qa' , G5_DIR_PERMISSION );
@ chmod ( G5_DATA_PATH . '/qa' , G5_DIR_PERMISSION );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$chars_array = array_merge ( range ( 0 , 9 ), range ( 'a' , 'z' ), range ( 'A' , 'Z' ));
2022-09-17 20:50:50 +09:00
// 가변 파일 업로드
$file_upload_msg = '' ;
2024-09-23 09:37:13 +09:00
$upload = [];
2024-09-19 20:57:39 +09:00
for ( $i = 1 ; $i <= count ( $_FILES [ 'bf_file' ][ 'name' ]); $i ++ ) {
$upload [ $i ][ 'file' ] = '' ;
$upload [ $i ][ 'source' ] = '' ;
$upload [ $i ][ 'del_check' ] = false ;
// 삭제에 체크가 되어있다면 파일을 삭제합니다.
if ( isset ( $_POST [ 'bf_file_del' ][ $i ]) && $_POST [ 'bf_file_del' ][ $i ]) {
$upload [ $i ][ 'del_check' ] = true ;
@ unlink ( G5_DATA_PATH . '/qa/' . $write [ 'qa_file' . $i ]);
// 썸네일삭제
if ( preg_match ( " / \ .( { $config [ 'cf_image_extension' ] } ) $ /i " , $write [ 'qa_file' . $i ])) {
delete_qa_thumbnail ( $write [ 'qa_file' . $i ]);
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
}
$tmp_file = $_FILES [ 'bf_file' ][ 'tmp_name' ][ $i ];
$filesize = $_FILES [ 'bf_file' ][ 'size' ][ $i ];
$filename = $_FILES [ 'bf_file' ][ 'name' ][ $i ];
$filename = get_safe_filename ( $filename );
// 서버에 설정된 값보다 큰파일을 업로드 한다면
if ( $filename ) {
if ( $_FILES [ 'bf_file' ][ 'error' ][ $i ] == 1 ) {
$file_upload_msg .= '\"' . $filename . '\" 파일의 용량이 서버에 설정(' . $upload_max_filesize . ')된 값보다 크므로 업로드 할 수 없습니다.\\n' ;
continue ;
} else if ( $_FILES [ 'bf_file' ][ 'error' ][ $i ] != 0 ) {
$file_upload_msg .= '\"' . $filename . '\" 파일이 정상적으로 업로드 되지 않았습니다.\\n' ;
continue ;
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( is_uploaded_file ( $tmp_file )) {
// 관리자가 아니면서 설정한 업로드 사이즈보다 크다면 건너뜀
if ( ! $is_admin && $filesize > $qaconfig [ 'qa_upload_size' ]) {
$file_upload_msg .= '\"' . $filename . '\" 파일의 용량(' . number_format ( $filesize ) . ' 바이트)이 게시판에 설정(' . number_format ( $qaconfig [ 'qa_upload_size' ]) . ' 바이트)된 값보다 크므로 업로드 하지 않습니다.\\n' ;
continue ;
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
//=================================================================\
// 090714
// 이미지나 플래시 파일에 악성코드를 심어 업로드 하는 경우를 방지
// 에러메세지는 출력하지 않는다.
//-----------------------------------------------------------------
$timg = @ getimagesize ( $tmp_file );
// image type
if (
preg_match ( " / \ .( { $config [ 'cf_image_extension' ] } ) $ /i " , $filename ) ||
preg_match ( " / \ .( { $config [ 'cf_flash_extension' ] } ) $ /i " , $filename )
) {
if ( $timg [ '2' ] < 1 || $timg [ '2' ] > 16 )
continue ;
}
//=================================================================
if ( $w == 'u' ) {
// 존재하는 파일이 있다면 삭제합니다.
@ unlink ( G5_DATA_PATH . '/qa/' . $write [ 'qa_file' . $i ]);
// 이미지파일이면 썸네일삭제
if ( preg_match ( " / \ .( { $config [ 'cf_image_extension' ] } ) $ /i " , $write [ 'qa_file' . $i ])) {
delete_qa_thumbnail ( $row [ 'qa_file' . $i ]);
}
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
// 프로그램 원래 파일명
$upload [ $i ][ 'source' ] = $filename ;
$upload [ $i ][ 'filesize' ] = $filesize ;
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
// 아래의 문자열이 들어간 파일은 -x 를 붙여서 웹경로를 알더라도 실행을 하지 못하도록 함
2024-09-22 09:27:53 +09:00
$filename = preg_replace ( " / \ .(php|phtm|htm|cgi|pl|exe|jsp|asp|inc|phar)/i " , " $ 0-x " , $filename );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
shuffle ( $chars_array );
$shuffle = implode ( '' , $chars_array );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
// 첨부파일 첨부시 첨부파일명에 공백이 포함되어 있으면 일부 PC에서 보이지 않거나 다운로드 되지 않는 현상이 있습니다. (길상여의 님 090925)
$upload [ $i ][ 'file' ] = abs ( ip2long ( $_SERVER [ 'REMOTE_ADDR' ])) . '_' . substr ( $shuffle , 0 , 8 ) . '_' . replace_filename ( $filename );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$dest_file = G5_DATA_PATH . '/qa/' . $upload [ $i ][ 'file' ];
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
// 업로드가 안된다면 에러메세지 출력하고 죽어버립니다.
$error_code = move_uploaded_file ( $tmp_file , $dest_file ) or die ( $_FILES [ 'bf_file' ][ 'error' ][ $i ]);
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
// 올라간 파일의 퍼미션을 변경합니다.
chmod ( $dest_file , G5_FILE_PERMISSION );
}
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
if ( $w == '' || $w == 'a' || $w == 'r' ) {
if ( $w == '' || $w == 'r' ) {
$row = sql_fetch ( " select MIN(qa_num) as min_qa_num from { $g5 [ 'qa_content_table' ] } " );
$qa_num = $row [ 'min_qa_num' ] - 1 ;
}
if ( $w == 'a' ) {
$qa_num = $write [ 'qa_num' ];
$qa_parent = $write [ 'qa_id' ];
$qa_related = $write [ 'qa_related' ];
$qa_category = $write [ 'qa_category' ];
$qa_type = 1 ;
$qa_status = 1 ;
}
$sql = " insert into { $g5 [ 'qa_content_table' ] }
2022-09-17 20:50:50 +09:00
set qa_num = '$qa_num' ,
mb_id = '{$member[' mb_id ']}' ,
2024-09-19 20:57:39 +09:00
qa_name = '" . addslashes($member[' mb_nick ']) . "' ,
2022-09-17 20:50:50 +09:00
qa_email = '$qa_email' ,
qa_hp = '$qa_hp' ,
qa_type = '$qa_type' ,
qa_parent = '$qa_parent' ,
qa_related = '$qa_related' ,
qa_category = '$qa_category' ,
qa_email_recv = '$qa_email_recv' ,
qa_sms_recv = '$qa_sms_recv' ,
qa_html = '$qa_html' ,
qa_subject = '$qa_subject' ,
qa_content = '$qa_content' ,
qa_status = '$qa_status' ,
qa_file1 = '{$upload[1][' file ']}' ,
qa_source1 = '{$upload[1][' source ']}' ,
qa_file2 = '{$upload[2][' file ']}' ,
qa_source2 = '{$upload[2][' source ']}' ,
qa_ip = '{$_SERVER[' REMOTE_ADDR ']}' ,
2024-09-19 20:57:39 +09:00
qa_datetime = '" . G5_TIME_YMDHIS . "' ,
2022-09-17 20:50:50 +09:00
qa_1 = '$qa_1' ,
qa_2 = '$qa_2' ,
qa_3 = '$qa_3' ,
qa_4 = '$qa_4' ,
qa_5 = '$qa_5' " ;
2024-09-19 20:57:39 +09:00
sql_query ( $sql );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w == '' || $w == 'r' ) {
$qa_id = sql_insert_id ();
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w == 'r' && $write [ 'qa_related' ]) {
$qa_related = $write [ 'qa_related' ];
} else {
$qa_related = $qa_id ;
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$sql = " update { $g5 [ 'qa_content_table' ] }
2022-09-17 20:50:50 +09:00
set qa_parent = '$qa_id' ,
qa_related = '$qa_related'
where qa_id = '$qa_id' " ;
2024-09-19 20:57:39 +09:00
sql_query ( $sql );
}
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
if ( $w == 'a' ) {
$sql = " update { $g5 [ 'qa_content_table' ] }
2022-09-17 20:50:50 +09:00
set qa_status = '1'
where qa_id = '{$write[' qa_parent ']}' " ;
2024-09-19 20:57:39 +09:00
sql_query ( $sql );
}
} else if ( $w == 'u' ) {
if ( ! $upload [ 1 ][ 'file' ] && ! $upload [ 1 ][ 'del_check' ]) {
$upload [ 1 ][ 'file' ] = $write [ 'qa_file1' ];
$upload [ 1 ][ 'source' ] = $write [ 'qa_source1' ];
}
if ( ! $upload [ 2 ][ 'file' ] && ! $upload [ 2 ][ 'del_check' ]) {
$upload [ 2 ][ 'file' ] = $write [ 'qa_file2' ];
$upload [ 2 ][ 'source' ] = $write [ 'qa_source2' ];
}
$sql = " update { $g5 [ 'qa_content_table' ] }
2022-09-17 20:50:50 +09:00
set qa_email = '$qa_email' ,
qa_hp = '$qa_hp' ,
qa_category = '$qa_category' ,
qa_html = '$qa_html' ,
qa_subject = '$qa_subject' ,
qa_content = '$qa_content' ,
qa_file1 = '{$upload[1][' file ']}' ,
qa_source1 = '{$upload[1][' source ']}' ,
qa_file2 = '{$upload[2][' file ']}' ,
qa_source2 = '{$upload[2][' source ']}' ,
qa_1 = '$qa_1' ,
qa_2 = '$qa_2' ,
qa_3 = '$qa_3' ,
qa_4 = '$qa_4' ,
qa_5 = '$qa_5' " ;
2024-09-19 20:57:39 +09:00
if ( $qa_sms_recv )
$sql .= " , qa_sms_recv = ' $qa_sms_recv ' " ;
$sql .= " where qa_id = ' $qa_id ' " ;
sql_query ( $sql );
2022-09-17 20:50:50 +09:00
}
// SMS 알림
2024-09-19 20:57:39 +09:00
if ( $config [ 'cf_sms_use' ] == 'icode' && $qaconfig [ 'qa_use_sms' ]) {
if ( $config [ 'cf_sms_type' ] == 'LMS' ) {
} else {
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
}
2022-09-17 20:50:50 +09:00
}
// 답변 이메일전송
2024-09-19 20:57:39 +09:00
if ( $w == 'a' && $write [ 'qa_email_recv' ] && trim ( $write [ 'qa_email' ])) {
include_once ( G5_LIB_PATH . '/mailer.lib.php' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$subject = $config [ 'cf_title' ] . ' ' . $qaconfig [ 'qa_title' ] . ' 답변 알림 메일' ;
$content = nl2br ( conv_unescape_nl ( stripslashes ( $qa_content )));
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
mailer ( $config [ 'cf_admin_email_name' ], $config [ 'cf_admin_email' ], $write [ 'qa_email' ], $subject , $content , 1 );
2022-09-17 20:50:50 +09:00
}
// 문의글등록 이메일전송
2024-09-19 20:57:39 +09:00
if (( $w == '' || $w == 'r' ) && trim ( $qaconfig [ 'qa_admin_email' ])) {
include_once ( G5_LIB_PATH . '/mailer.lib.php' );
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
$subject = $config [ 'cf_title' ] . ' ' . $qaconfig [ 'qa_title' ] . ' 질문 알림 메일' ;
$content = nl2br ( conv_unescape_nl ( stripslashes ( $qa_content )));
2022-09-17 20:50:50 +09:00
2024-09-19 20:57:39 +09:00
mailer ( $config [ 'cf_admin_email_name' ], $qa_email , $qaconfig [ 'qa_admin_email' ], $subject , $content , 1 );
2022-09-17 20:50:50 +09:00
}
2024-09-19 20:57:39 +09:00
if ( $w == 'a' )
$result_url = G5_BBS_URL . '/qaview.php?qa_id=' . $qa_id . $qstr ;
else if ( $w == 'u' && $write [ 'qa_type' ])
$result_url = G5_BBS_URL . '/qaview.php?qa_id=' . $write [ 'qa_parent' ] . $qstr ;
2022-09-17 20:50:50 +09:00
else
2024-09-19 20:57:39 +09:00
$result_url = G5_BBS_URL . '/qalist.php' . preg_replace ( '/^&/' , '?' , $qstr );
2022-09-17 20:50:50 +09:00
if ( $file_upload_msg )
2024-09-19 20:57:39 +09:00
alert ( $file_upload_msg , $result_url );
2022-09-17 20:50:50 +09:00
else
2024-09-19 20:57:39 +09:00
goto_url ( $result_url );