<?
include "lib.php";
include "func.php";
//로그인 검사
CheckLogin();
$connect = dbConn();

$admin = getAdmin($connect);

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

if($me[userlevel] < 4) {
    echo "<script>location.replace('_admin3.php');</script>";
}

switch($btn) {
    case "메세지 전달":
        $date = date('Y-m-d H:i:s');
        for($i=0; $i < sizeof($genlist); $i++) {
            $query = "select msgindex from general where no='$genlist[$i]'";
            $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
            $you = MYDB_fetch_array($result);
            // 상대에게 발송
            $you[msgindex]++;
            if($you[msgindex] >= 10) { $you[msgindex] = 0; }
            $query = "update general set msgindex='$you[msgindex]',msg{$you[msgindex]}_type=10,msg{$you[msgindex]}='$msg',msg{$you[msgindex]}_who={$me['no']}*10000+$genlist[$i],msg{$you[msgindex]}_when='$date',newmsg=1 where no='$genlist[$i]'";
            MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
        }
        break;
}

echo "<script>location.replace('_admin3.php');</script>";
?>

