<?php include("../common.php");
//위의 링크를 정확하게 하셔야 합니다. 현재는 game 폴더 아래 있는 것을 기준으로 합니다.
//설정하세요///////////////////////
$board = 'score';   //사용할 계시판 테이블명을 적으세요.
$minus = -50; //게임 한번 할 때마다 점수 차감
$plus = 0; //최고 점수를 기록할 경우 보상. 보상이 없을 경우는 0으로 기록
$minscore = 0; //최고 점수를 기록할 경우 보상. 최저 보상 점수. 처음	부터 주면 안되기에
////////////////////////////////////////
//게임 한 후에 가져올 정보 - 수정하지 마세요!!!!
$gameName = strip_tags($_GET['game']);
$score = strip_tags($_GET['score']);
if($member['mb_nick'] == "") $nick = "비회원";
else $nick = $member['mb_nick'];
$getMemebr = $gameName." ".$nick." ".$score."점";
$query = "select max(wr_id) as maxWr from g5_write_$board";
$result = sql_query($query); 
while($row  = sql_fetch_array($result)) {	
	$wr = $row['maxWr'];
}

$query = "select max(wr_content) as maxScore from g5_write_$board where wr_link1 = '$gameName'";
$result = sql_query($query); 
while($row  = sql_fetch_array($result)) {	
	$maxScore = $row['maxScore'];
}

if($score > $maxScore && $plus != 0  && $maxScore > $minscore)   $point = $plus + $minus;
else $point =  $minus;
//$po_point = $plus + $minus;
$addWr = $wr + 1;
$wr_num = -($addWr + 1);



$query = "select po_datetime from g5_point where mb_id = '{$member['mb_id']}' order by po_datetime desc limit 1";
$result = sql_query($query); 
while($row  = sql_fetch_array($result)) {	
	$date = $row['po_datetime'];
}

$someTime=strtotime(G5_TIME_YMDHIS) - strtotime($date);
$checktime = date('s', $someTime);

if($checktime >= 5) {

	$sql = " insert into g5_write_$board
                set wr_num = '$wr_num',
                     wr_reply = '$wr_reply',
                     wr_comment = 0,
                     ca_name = '$ca_name',
                     wr_option = '$html,$secret,$mail',
                     wr_subject = '$getMemebr',
                     wr_content = '$score',
                     wr_link1 = '$gameName',
                     wr_link2 = '$wr_link2',
                     wr_link1_hit = 0,
                     wr_link2_hit = 0,
                     wr_hit = 0,
                     wr_good = '$score',
                     wr_nogood = 0,
                     mb_id = '{$member['mb_id']}',
                     wr_password = '$wr_password',
                     wr_name = '$nick',
                     wr_email = '$wr_email',
                     wr_homepage = '$wr_homepage',
                     wr_datetime = '".G5_TIME_YMDHIS."',
                     wr_last = '".G5_TIME_YMDHIS."',
                     wr_ip = '{$_SERVER['REMOTE_ADDR']}',
                     wr_1 = '$wr_1',
                     wr_2 = '$wr_2',
                     wr_3 = '$wr_3',
                     wr_4 = '$wr_4',
                     wr_5 = '$wr_5',
                     wr_6 = '$wr_6',
                     wr_7 = '$wr_7',
                     wr_8 = '$wr_8',
                     wr_9 = '$wr_9',
                     wr_10 = '$wr_10' ";
    sql_query($sql);

    
	// 부모 아이디에 UPDATE
    sql_query(" update g5_write_$board set wr_parent = '$addWr' where wr_id = '$addWr' ");

    // 새글 INSERT
    sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$addWr}', '{$addWr}', '".G5_TIME_YMDHIS."', '{$member['mb_id']}' ) ");

    // 게시글 1 증가
    sql_query("update {$g5['board_table']} set bo_count_write = bo_count_write + 1 where bo_table = '{$bo_table}'");

//포인트를 감소시킵니다.


	$mb_id = $member['mb_id'];
	insert_point($mb_id, $point, $gameName, '@login', $mb_id, G5_TIME_YMDHIS); 

}


?>