<?php include("../common.php");
//사용할 계시판 테이블명을 적으세요.
$board = 'score';   
//게임 한번 할 때마다 점수 차감
$minus = -50;
//최고 점수를 기록할 경우 보상. 보상이 없을 경우는 0으로 기록
$plus = 100;
//게임 한 후에 가져올 정보 - 수정하지 마세요!!!!
$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)   $point = $member['mb_point'] + $plus + $minus;
else $point = $member['mb_point'] + $minus;
$addWr = $wr + 1;
$wr_num = -($addWr + 1);

$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}'");

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

  echo   $point;
    $sql = " insert into g5_point
                set mb_id = '{$member['mb_id']}',
                    po_datetime = '".G5_TIME_YMDHIS."',
                    po_content = '$getMemebr',
                    po_point = '$minus',
                    po_use_point = '$minus',
                    po_mb_point = ' $point',
                    po_expired = '0',
                    po_expire_date = '9999-12-31',
                    po_rel_table = '$board',
                    po_rel_id = '$addWr',
                    po_rel_action = '$rel_action' ";
    sql_query($sql);
    $sql = " update {$g5['member_table']} set mb_point = '$point' where mb_id = '{$member['mb_id']}' ";
    sql_query($sql);


?>