<?
include "lib.php";
include "func.php";
//로그인 검사
CheckLogin();
$connect = dbConn();
increaseRefresh($connect, "장수일람", 2);

$query = "select conlimit from game where no=1";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$admin = MYDB_fetch_array($result);

$query = "select con,userlevel,turntime from general where user_id='$_SESSION[p_id]'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$me = MYDB_fetch_array($result);

$con = checkLimit($me[userlevel], $me[con], $admin[conlimit]);
if($con >= 2) { printLimitMsg($me[turntime]); exit(); }

if($type == 0) {
    $type = 9;
}
$sel[$type] = "selected";

?>
<html>

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

<body 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><? closeButton(); ?></td></tr>
    <tr><td><form name=form1 method=post>정렬순서 :
        <select name=type size=1>
            <option <?=$sel[1];?> value=1>국가</option>
            <option <?=$sel[2];?> value=2>통솔</option>
            <option <?=$sel[3];?> value=3>무력</option>
            <option <?=$sel[4];?> value=4>지력</option>
            <option <?=$sel[5];?> value=5>명성</option>
            <option <?=$sel[6];?> value=6>계급</option>
            <option <?=$sel[7];?> value=7>관직</option>
            <option <?=$sel[8];?> value=8>삭턴</option>
            <option <?=$sel[9];?> value=9>벌점</option>
            <option <?=$sel[10];?> value=10>Lv</option>
            <option <?=$sel[11];?> value=11>성격</option>
            <option <?=$sel[12];?> value=12>내특</option>
            <option <?=$sel[13];?> value=13>전특</option>
            <option <?=$sel[14];?> value=14>연령</option>
            <option <?=$sel[15];?> value=15>NPC</option>
            <option <?=$sel[16];?> value=16>특별</option>
        </select>
        <input type=submit value='정렬하기'></form>
    </td></tr>
</table>
<?
$query = "select nation,name,level from nation";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$count = MYDB_num_rows($result);

$nationname[0] = "-";
for($i=0; $i < $count; $i++) {
    $nation = MYDB_fetch_array($result);
    $nationname[$nation[nation]] = $nation[name];
    $nationlevel[$nation[nation]] = $nation[level];
}

switch($type) {
    case  1: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by nation"; break;
    case  2: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by leader desc"; break;
    case  3: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by power desc"; break;
    case  4: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by intel desc"; break;
    case  5: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by experience desc"; break;
    case  6: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by dedication desc"; break;
    case  7: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by level desc"; break;
    case  8: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by killturn"; break;
    case  9: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by connect desc"; break;
    case 10: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by experience desc"; break;
    case 11: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by personal"; break;
    case 12: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by special desc"; break;
    case 13: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by special2 desc"; break;
    case 14: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by age desc"; break;
    case 15: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by npc desc"; break;
    case 16: $query = "select picture,imgsvr,npc,age,nation,special,special2,personal,name,injury,leader,power,intel,experience,dedication,level,killturn,connect from general order by userlevel desc"; break;
}
$genresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$gencount = MYDB_num_rows($genresult);

echo"
<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 width=64  align=center id=bg1>얼 굴</td>
        <td width=100 align=center id=bg1>이 름</td>
        <td width=50 align=center id=bg1>연령</td>
        <td width=50 align=center id=bg1>성격</td>
        <td width=90 align=center id=bg1>특기</td>
        <td width=50 align=center id=bg1>레 벨</td>
        <td width=100 align=center id=bg1>국 가</td>
        <td width=60 align=center id=bg1>명 성</td>
        <td width=60 align=center id=bg1>계 급</td>
        <td width=80 align=center id=bg1>관 직</td>
        <td width=45 align=center id=bg1>통솔</td>
        <td width=45 align=center id=bg1>무력</td>
        <td width=45 align=center id=bg1>지력</td>
        <td width=45 align=center id=bg1>삭턴</td>
        <td width=84 align=center id=bg1>벌점</td>
    </tr>";
for($j=0; $j < $gencount; $j++) {
    $general = MYDB_fetch_array($genresult);
    $nation = $nationname[$general[nation]];

    if($general[level] == 12) {
        $lbonus = $nationlevel[$general[nation]] * 2;
    } elseif($general[level] >= 5) {
        $lbonus = $nationlevel[$general[nation]];
    } else {
        $lbonus = 0;
    }
    if($lbonus > 0) {
        $lbonus = "<font color=cyan>+{$lbonus}</font>";
    } else {
        $lbonus = "";
    }

    if($general[injury] > 0) {
        $leader = floor($general[leader] * (100 - $general[injury])/100);
        $power = floor($general[power] * (100 - $general[injury])/100);
        $intel = floor($general[intel] * (100 - $general[injury])/100);
        $leader = "<font color=red>{$leader}</font>{$lbonus}";
        $power = "<font color=red>{$power}</font>";
        $intel = "<font color=red>{$intel}</font>";
    } else {
        $leader = "{$general[leader]}{$lbonus}";
        $power = "{$general[power]}";
        $intel = "{$general[intel]}";
    }

    if($general[npc] >= 2) { $name = "<font color=cyan>$general[name]</font>"; }
    elseif($general[npc] == 1) { $name = "<font color=skyblue>$general[name]</font>"; }
    else { $name =  "$general[name]"; }

    $general[connect] = round($general[connect] / 10, 0) * 10;

    $imageTemp = GetImageURL($general[imgsvr]);
    echo "
    <tr>
        <td align=center><img src={$imageTemp}/{$general[picture]}></img></td>
        <td align=center>$name</td>
        <td align=center>$general[age]세</td>
        <td align=center>".getGenChar($general[personal])."</td>
        <td align=center>".getGenSpecial($general[special])." / ".getGenSpecial($general[special2])."</td>
        <td align=center>Lv ".getExpLevel($general[experience])."</td>
        <td align=center>{$nation}</td>
        <td align=center>".getHonor($general[experience])."</td>
        <td align=center>".getDed($general[dedication])."</td>
        <td align=center>"; echo getLevel($general[level]); echo "</td>
        <td align=center>$leader</td>
        <td align=center>$power</td>
        <td align=center>$intel</td>
        <td align=center>$general[killturn]</td>
        <td align=center>$general[connect]"; echo "<br>【".getConnect($general[connect])."】</td>
    </tr>";
}
echo "
</table>
";

MYDB_close($connect);
?>

<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><? closeButton(); ?></td></tr>
    <tr><td><? banner(); ?></td></tr>
</table>
<? PrintElapsedTime(); ?>
</body>

</html>
