<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가 

include_once(AMINA_PATH.'/lib/write.lib.php');

if(AMINA == "g4s") {
	$point_log = '댓글';
} else {
	$point_log = '코멘트';
}

$lucky_str = '';

//자신의 글과 특정일 이후에 등록된 코멘트에 대한 포인트 등록 불가 설정
if($w == "c" && $board['bo_comment_point'] && $member['mb_id']) {
	$chk_comment = ($amina['limit_date'] > 0) ? date("Y-m-d H:i:s", G4_SERVER_TIME - ( $amina['limit_date'] * 24 * 3600 )) : '';

	if(($wr['mb_id'] == $member['mb_id'] && $amina['limit_cmt']) || ($chk_comment && $wr['wr_datetime'] < $chk_comment)) { 
		if (!delete_point($member['mb_id'], $bo_table, $comment_id, $point_log)) 
		    insert_point($member['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write[wr_parent]}-{$comment_id} {$point_log}삭제");
	} else { 
		if($wr['mb_id'] != $member['mb_id'] && $amina['lucky_rate'] > 0 && $amina['lucky_point'] > 0) {
			//당첨여부 확인
			$lucky = sql_fetch(" select count(*) as cnt from {$g4['point_table']} where mb_id = '{$member['mb_id']}' and po_rel_table = '$bo_table' and po_rel_id = '$wr_id' and po_rel_action = '@lucky' ");

			if(!$lucky['cnt']) { //미당첨자일 경우에만 돌림
				$lucky1 = rand(1,$amina['lucky_rate']);
				$lucky2 = rand(1,$amina['lucky_rate']);
				if($lucky1 == $lucky2) {
					$lucky_point = $board['bo_comment_point'] * rand(1,$amina['lucky_point']);

					//포인트 등록
					insert_point($member['mb_id'], (int)$lucky_point, "{$board['bo_subject']} {$wr_id} 럭키포인트!", $bo_table, $wr_id, '@lucky');
	
					//글정보 업데이트
					$lucky_str = "wr_10 = '$lucky_point', ";
				}
			}
		}
	}
}

//Mobile
$post_mobile = G4_IS_MOBILE ? '1' : '';

//익명댓글
$cmt_no_str = '';
if($amina['nameless_cmt'] && $wr_nameless) {
	$wr_rename = $amina['nameless_head'].amina_nameless_tail($amina['nameless_tail']);
	$cmt_no_str = "wr_name = '$wr_rename', mb_id = '', wr_email = '', wr_homepage = '', ";
}

//아이콘($wr_5) 값 정리하기..
if ($w == "cu") {
	$icon = amina_array_icon($wr_cmt['wr_5']);
	$wr_5 = $icon['level'].'|'.$post_mobile.'|'.$post_icon.'|'.$icon['choice'].'|'.$icon['choice_point'].'|'.$icon['choice_mb'].'|'.$post_cool.'|'.$post_icon_mb;
	$wr_9 = $wr_cmt['wr_9'];
} else {
	$mb_xp_level = $cmt_no_str ? '' : xp_level($member['mb_id']); //익명일 때 레벨을 날림
	$wr_5 = $mb_xp_level.'|'.$post_mobile.'|'.$post_icon.'|'.$icon['choice'].'|'.$icon['choice_point'].'|'.$icon['choice_mb'].'|'.$post_cool.'|'.$post_icon_mb;
	$wr_9 = 0;
}

sql_query(" update $write_table set $cmt_no_str $lucky_str wr_9 = '$wr_9', wr_5 = '$wr_5' where wr_id = '$comment_id' ");

if(file_exists($cmt_skin_path.'/write_comment_update.tail.skin.php')) include_once ($cmt_skin_path.'/write_comment_update.tail.skin.php');

// xp 정보 업데이트
if($w != "cu" && $member['mb_id']) check_xp($member['mb_id']);

//이동 별도 지정시
if($go_url) goto_url($go_url.'&go_url='.urlencode($go_url));

?>
