<?
include "lib.php";
include "func.php";

$id = $_POST[id];
$pw = $_POST[pw];

$pwTemp = substr($pw, 0, 32);

$connect = dbConn("sammo");

//회원 테이블에서 정보확인
$query = "select no,name,picture,grade from MEMBER where id='$id' and pw='$pwTemp'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$member = MYDB_fetch_array($result);

if(!$member) {
    MessageBox("잘못된 접근입니다!!!");
    echo "<script>history.go(-1);</script>";
    exit(1);
}

$connect = dbConn();
?>

<html>
<head>
<title>NPC선택</title>
<meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=utf-8'>
<link rel=stylesheet href=stylesheet.php type=text/css>
<? require('analytics.php'); ?>
</head>

<body onLoad='changeGen()' oncontextmenu='return false'>
    <table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13;word-break:break-all; id=bg0>
        <tr><td>장 수 선 택<br><? backButton(); ?></td></tr>
    </table>
    <table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13;word-break:break-all; id=bg0>
        <tr><td align=center><? info($connect, 0, 1); ?></td></tr>
    </table>
<?
$query = "select npcmode,maxgeneral,img from game where no='1'";
$result = MYDB_query($query, $connect) or Error("join ".MYDB_error($connect),"");
$admin = MYDB_fetch_array($result);

if($admin[npcmode] != 1) {
    echo "<script>alert('잘못된 접근입니다!');</script>";
    echo "<script>history.go(-1);</script>";
    exit();
}

$query = "select no from general where npc<2";
$result = MYDB_query($query, $connect) or Error("join ".MYDB_error($connect),"");
$gencount = MYDB_num_rows($result);

if($gencount >= $admin[maxgeneral]) {
    echo "<script>alert('더 이상 등록할 수 없습니다.');</script>";
    echo "<script>history.go(-1);</script>";
    exit();
}
?>

<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13;word-break:break-all; id=bg0>
<tr><td align=center colspan=2 id=bg1>임관 권유 메세지</td></tr>
<?
$query = "select name,scoutmsg,color from nation";
$nationresult = MYDB_query($query, $connect) or Error("join ".MYDB_error($connect),"");
$nationcount = MYDB_num_rows($nationresult);

for($i=0; $i < $nationcount; $i++) {
    $nation = MYDB_fetch_array($nationresult);
    if($nation[scoutmsg] == "") {
        echo "
    <tr><td align=center width=98 style=color:".newColor($nation[color]).";background-color:{$nation[color]}>$nation[name]</td><td width=898 style=color:{newColor($nation[color])};background-color:{$nation[color]}>-</td></tr>";
    } else {
        echo "
    <tr><td align=center width=98 style=color:".newColor($nation[color]).";background-color:{$nation[color]}>$nation[name]</td><td width=898 style=color:{newColor($nation[color])};background-color:{$nation[color]}>$nation[scoutmsg]</td></tr>";
    }
}
?>
</table>

<form name=form1 method=post action=select_npc_post.php>
<input type=hidden name=id value='<?=$id;?>'>
<input type=hidden name=pw value='<?=$pw;?>'>
    <table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13;word-break:break-all; id=bg0>
        <tr>
            <td colspan=2 align=center id=bg1>장수 선택</td>
        </tr>
<?
if($admin[img] >= 3) {
?>
        <tr>
            <td width=498 align=right rowspan=2 height=64 id=bg1>장수</td>
            <td width=498><img src=<?=$image;?>/1001.jpg border=0 name=picture width=64 height=64></td>
        </tr>
<?
}
?>
        <tr>
            <td align=left colspan=2>
                <select name=face size=1 style=color:white;background-color:black; value=1001 disabled>
<?
//$query  = "select npcid,name,leader,power,intel from general where npc=2 and level<5";
$query  = "select npcid,name,leader,power,intel from general where npc=2";
$result = MYDB_query($query,$connect);
$count = MYDB_num_rows($result);

for($i=0; $i < $count; $i++) {
    $npc = MYDB_fetch_array($result);
    $call = "{$npc[leader]} / {$npc[power]} / {$npc[intel]}";
    echo "
        <option value={$npc[npcid]}>{$npc[name]} 【{$call}】</option>";
}
?>

                </select>
            </td>
        </tr>
        <tr>
            <td align=center colspan=2>
                컴퓨터가 조작중이던 NPC장수를 조종하게 됩니다.<br>
                80시간동안 휴식을 취하면 다시 컴퓨터가 조종하게 되고 장수의 소유권을 잃습니다.
            </td>
        </tr>
        <tr>
            <td align=center colspan=2><input type=button name=sel value=다른장수 onclick='changeGen()'><input type=submit name=join value=장수선택 onclick='return selectGen()'></td>
        </tr>
    </table>
</form>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13;word-break:break-all; id=bg0>
    <tr><td><? backButton(); ?></td></tr>
    <tr><td><? banner(); ?> </td></tr>
</table>
</body>
<script type="text/javascript">
function changeGen() {
    sel = Math.floor(Math.random() * <?=$count;?>);
    document.form1.face.selectedIndex = sel;
    num = document.form1.face.value;
    document.form1.picture.src="<?=$image;?>" + "/"+ num +".jpg";
}

function selectGen() {
    document.form1.face.disabled = false;
    return true;
}
</script>
</html>
