<?php
require('../db.php');
require("../function/function.php");


// 変数の初期化
$datetime = array();
$user_name = null;
$message = array();
$message_data = null;
$error_message = array();
$pdo = null;
$stmt = null;
$res = null;
$option = null;

session_name('uwuzu_s_id');
session_set_cookie_params([
    'lifetime' => 0,
    'path' => '/',
    'domain' => '',
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Lax'
]);
session_start();
session_regenerate_id(true);

// データベースに接続
try {

    $option = array(
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::MYSQL_ATTR_MULTI_STATEMENTS => false
    );
    $pdo = new PDO('mysql:charset=utf8mb4;dbname='.DB_NAME.';host='.DB_HOST , DB_USER, DB_PASS, $option);

} catch(PDOException $e) {

    // 接続エラーのときエラー内容を取得する
    $error_message[] = $e->getMessage();
}

//ログイン認証---------------------------------------------------
blockedIP($_SERVER['REMOTE_ADDR']);
$is_login = uwuzuUserLogin($_SESSION, $_COOKIE, $_SERVER['REMOTE_ADDR'], "user");
if($is_login === false){
	header("Location: ../index.php");
	exit;
}else{
	$userid = safetext($is_login['userid']);
	$username = safetext($is_login['username']);
	$loginid = safetext($is_login["loginid"]);
	$role = safetext($is_login["role"]);
	$sacinfo = safetext($is_login["sacinfo"]);
	$myblocklist = safetext($is_login["blocklist"]);
	$myfollowlist = safetext($is_login["follow"]);
	$is_Admin = safetext($is_login["admin"]);
}

require('../logout/logout.php');
?>
<!DOCTYPE HTML>
<html>
  <head>
    <title>uwuzu API Docs - <?php echo safetext($serversettings["serverinfo"]["server_name"]);?></title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=360,initial-scale=1">
    <link rel="icon" href="./uwuzu.png" />
    <link rel="stylesheet" href="../css/color.css" />
    <script src="../js/unsupported.js"></script>
    <script src="../js/console_notice.js"></script>
  </head>
  <body>
    <!-- Loading -->
    <div id="loading">
      <!-- Iconify -->
      <script src="https://code.iconify.design/iconify-icon/3.0.0/iconify-icon.min.js"></script>
      <script>import "iconify-icon";</script>
      
      <link rel="stylesheet" href="./loading.css">
      <iconify-icon
        icon="svg-spinners:6-dots-scale"
        width="60"
      />
    </div>
    
    <!-- Scalar -->
    <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.35.5"></script>
    <div id="app" />
    <script>
      Scalar.createApiReference("#app", {
        url: "./openapi",
        onLoaded: () => {
          // Delete Loading Content
          document.getElementById("loading").remove();
        },
        hideDarkModeToggle: true,
      });
    </script>
  </body>
</html>
