<?php
//DB연결
$server_root_path = $_SERVER['DOCUMENT_ROOT'];
require_once $server_root_path . "/database/mysqli_connection.php";


$query = "SELECT * FROM vpnid WHERE server_name='$HTTP_HOST' AND ( is_admin IS NULL OR is_admin='' ) ORDER BY no DESC";
$result = $db->query($query);
$total = mysqli_num_rows($result);

$output_data = "";

$output_data .= "<div style='width:98%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:column;'>";
$output_data .= "	<div style='width:100%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:row; border:0;'>";
$output_data .= "		<div style='width:50%; height:auto; padding:0px 0px 10px; text-align:center; text-align:left;'><span style=' color:#000000; cursor:pointer; font-size:13px; padding:5px 10px 5px; border-radius:3px; margin-bottom:5px; background:#35d4c7;' onclick='list_id_popup_new();'>아이디 추가</span></div>";
$output_data .= "		<div style='width:50%; height:auto; padding:0px 0px 10px; text-align:center; text-align:right;'><span style=' color:#ffffff; cursor:pointer; font-size:13px; padding:5px 10px 5px; border-radius:3px; margin-bottom:5px; background:orangered;' onclick='$(\"#list_id_popup\").slideUp();'>CLOSE</span></div>";
$output_data .= "	</div>";
$output_data .= "</div>";


$output_data .= "<div style='width:98%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:column; font-size:10px; '>";
$output_data .= "	<div style='width:100%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:row; border:1px solid #333333;'>";
$output_data .= "		<div style='width:25%; height:auto; padding:10px 0px 10px; text-align:center; border-right:1px solid #333333; background:#2a2a2a;'>등록/만료일</div>";
$output_data .= "		<div style='width:50%; height:auto; padding:10px 0px 10px; text-align:center; border-right:1px solid #333333; background:#2a2a2a; color:#35d4c7;'>아이디<span style='color:#a7a7a7;'>/</span><span style='color:#ffffff;'>메모</span></div>";
$output_data .= "		<div style='width:25%; height:auto; padding:10px 0px 10px; text-align:center; background:#2a2a2a;'>기능</div>";
$output_data .= "	</div>";
$output_data .= "</div>";


if ($total > 0) {
	while( $row = mysqli_fetch_array($result) ) {
		$member_id_data = $row['vpn_user_id'];
		$member_memo_data = $row['member_memo'];
		$member_id_expire_data = $row['member_id_expire'];
		$member_id_expire_data_short = substr($row['member_id_expire'],0,10);
		if ($member_id_expire_data == "") {
			$member_id_expire_data = "0000-00-00 00:00:00";
			$member_id_expire_data_short = "0000-00-00";
		}

		if (strtotime($member_id_expire_data_short . " 23:59:59") < strtotime(date("Y-m-d H:i:s"))) {
			$member_id_expire_data_display = "<span style='color:orangered;'>" . $member_id_expire_data_short . "</span>";
		} else if (strtotime($member_id_expire_data_short . " 23:59:59" . "-1 days") < strtotime(date("Y-m-d H:i:s"))) {
			$member_id_expire_data_display = "<span style='background:orangered; color:#ffffff;'>" . $member_id_expire_data_short . "</span>";
		} else {
			$member_id_expire_data_display = "<span style='color:#ffffff;'>" . $member_id_expire_data_short . "</span>";
		}


		$output_data .= "<div style='width:98%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:column;  font-size:10px; '>";
		$output_data .= "	<div style='width:100%; height:auto; display:flex; justify-content:center; align-items:center;; flex-direction:row; border:1px solid #333333;'>";
		$output_data .= "		<div style='width:25%; height:auto; padding:10px 0px 10px; text-align:center; border-right:1px solid #333333;'>" . substr($row['datetime'],0,10) . "<br>". $member_id_expire_data_display . "</div>";
		$output_data .= "		<div style='width:50%; height:auto; padding:10px 0px 10px; text-align:center; border:0; border-right:1px solid #333333; color:#35d4c7;'>" . $row['vpn_user_id'] . "<br><span style='color:#ffffff;'>" . $row['member_memo'] . "</span></div>";
		$output_data .= "		<div style='width:25%; height:auto; padding:10px 0px 10px; text-align:center; border:0;'><span style='background:#dddddd; color:#333333; padding:3px; cursor:pointer;' onclick='list_id_popup_edit(\"$member_id_data\",\"$member_id_expire_data_short\",\"$member_memo_data\"); return false;'>변경</span> <span  style='background:#333333; color:#ffffff; padding:3px; cursor:pointer; margin-left:5px;' onclick='list_id_popup_del(\"$member_id_data\",\"$member_id_expire_data_short\",\"$member_memo_data\"); return false;'>삭제</span></div>";
		$output_data .= "	</div>";
		$output_data .= "</div>";
	}
}

echo $output_data;
?>