<?php
ob_start();
//error_reporting(0);
session_start();
require_once('../include/dbconnect.php');

$report = "";

$date_ = date("Y-m-d");

$countries = array(
  "AF" => "Afghanistan",
  "AX" => "Åland Islands",
  "AL" => "Albania",
  "DZ" => "Algeria",
  "AS" => "American Samoa",
  "AD" => "Andorra",
  "AO" => "Angola",
  "AI" => "Anguilla",
  "AQ" => "Antarctica",
  "AG" => "Antigua and Barbuda",
  "AR" => "Argentina",
  "AM" => "Armenia",
  "AW" => "Aruba",
  "AU" => "Australia",
  "AT" => "Austria",
  "AZ" => "Azerbaijan",
  "BS" => "Bahamas",
  "BH" => "Bahrain",
  "BD" => "Bangladesh",
  "BB" => "Barbados",
  "BY" => "Belarus",
  "BE" => "Belgium",
  "BZ" => "Belize",
  "BJ" => "Benin",
  "BM" => "Bermuda",
  "BT" => "Bhutan",
  "BO" => "Bolivia",
  "BA" => "Bosnia and Herzegovina",
  "BW" => "Botswana",
  "BV" => "Bouvet Island",
  "BR" => "Brazil",
  "IO" => "British Indian Ocean Territory",
  "BN" => "Brunei Darussalam",
  "BG" => "Bulgaria",
  "BF" => "Burkina Faso",
  "BI" => "Burundi",
  "KH" => "Cambodia",
  "CM" => "Cameroon",
  "CA" => "Canada",
  "CV" => "Cape Verde",
  "KY" => "Cayman Islands",
  "CF" => "Central African Republic",
  "TD" => "Chad",
  "CL" => "Chile",
  "CN" => "China",
  "CX" => "Christmas Island",
  "CC" => "Cocos (Keeling) Islands",
  "CO" => "Colombia",
  "KM" => "Comoros",
  "CG" => "Congo",
  "CD" => "Congo, The Democratic Republic of The",
  "CK" => "Cook Islands",
  "CR" => "Costa Rica",
  "CI" => "Cote D'ivoire",
  "HR" => "Croatia",
  "CU" => "Cuba",
  "CY" => "Cyprus",
  "CZ" => "Czech Republic",
  "DK" => "Denmark",
  "DJ" => "Djibouti",
  "DM" => "Dominica",
  "DO" => "Dominican Republic",
  "EC" => "Ecuador",
  "EG" => "Egypt",
  "SV" => "El Salvador",
  "GQ" => "Equatorial Guinea",
  "ER" => "Eritrea",
  "EE" => "Estonia",
  "ET" => "Ethiopia",
  "FK" => "Falkland Islands (Malvinas)",
  "FO" => "Faroe Islands",
  "FJ" => "Fiji",
  "FI" => "Finland",
  "FR" => "France",
  "GF" => "French Guiana",
  "PF" => "French Polynesia",
  "TF" => "French Southern Territories",
  "GA" => "Gabon",
  "GM" => "Gambia",
  "GE" => "Georgia",
  "DE" => "Germany",
  "GH" => "Ghana",
  "GI" => "Gibraltar",
  "GR" => "Greece",
  "GL" => "#ff6666land",
  "GD" => "Grenada",
  "GP" => "Guadeloupe",
  "GU" => "Guam",
  "GT" => "Guatemala",
  "GG" => "Guernsey",
  "GN" => "Guinea",
  "GW" => "Guinea-bissau",
  "GY" => "Guyana",
  "HT" => "Haiti",
  "HM" => "Heard Island and Mcdonald Islands",
  "VA" => "Holy See (Vatican City State)",
  "HN" => "Honduras",
  "HK" => "Hong Kong",
  "HU" => "Hungary",
  "IS" => "Iceland",
  "IN" => "India",
  "ID" => "Indonesia",
  "IR" => "Iran, Islamic Republic of",
  "IQ" => "Iraq",
  "IE" => "Ireland",
  "IM" => "Isle of Man",
  "IL" => "Israel",
  "IT" => "Italy",
  "JM" => "Jamaica",
  "JP" => "Japan",
  "JE" => "Jersey",
  "JO" => "Jordan",
  "KZ" => "Kazakhstan",
  "KE" => "Kenya",
  "KI" => "Kiribati",
  "KP" => "Korea, Democratic People's Republic of",
  "KR" => "Korea, Republic of",
  "KW" => "Kuwait",
  "KG" => "Kyrgyzstan",
  "LA" => "Lao People's Democratic Republic",
  "LV" => "Latvia",
  "LB" => "Lebanon",
  "LS" => "Lesotho",
  "LR" => "Liberia",
  "LY" => "Libyan Arab Jamahiriya",
  "LI" => "Liechtenstein",
  "LT" => "Lithuania",
  "LU" => "Luxembourg",
  "MO" => "Macao",
  "MK" => "Macedonia, The Former Yugoslav Republic of",
  "MG" => "Madagascar",
  "MW" => "Malawi",
  "MY" => "Malaysia",
  "MV" => "Maldives",
  "ML" => "Mali",
  "MT" => "Malta",
  "MH" => "Marshall Islands",
  "MQ" => "Martinique",
  "MR" => "Mauritania",
  "MU" => "Mauritius",
  "YT" => "Mayotte",
  "MX" => "Mexico",
  "FM" => "Micronesia, Federated States of",
  "MD" => "Moldova, Republic of",
  "MC" => "Monaco",
  "MN" => "Mongolia",
  "ME" => "Montenegro",
  "MS" => "Montserrat",
  "MA" => "Morocco",
  "MZ" => "Mozambique",
  "MM" => "Myanmar",
  "NA" => "Namibia",
  "NR" => "Nauru",
  "NP" => "Nepal",
  "NL" => "Netherlands",
  "AN" => "Netherlands Antilles",
  "NC" => "New Caledonia",
  "NZ" => "New Zealand",
  "NI" => "Nicaragua",
  "NE" => "Niger",
  "NG" => "Nigeria",
  "NU" => "Niue",
  "NF" => "Norfolk Island",
  "MP" => "Northern Mariana Islands",
  "NO" => "Norway",
  "OM" => "Oman",
  "PK" => "Pakistan",
  "PW" => "Palau",
  "PS" => "Palestinian Territory, Occupied",
  "PA" => "Panama",
  "PG" => "Papua New Guinea",
  "PY" => "Paraguay",
  "PE" => "Peru",
  "PH" => "Philippines",
  "PN" => "Pitcairn",
  "PL" => "Poland",
  "PT" => "Portugal",
  "PR" => "Puerto Rico",
  "QA" => "Qatar",
  "RE" => "Reunion",
  "RO" => "Romania",
  "RU" => "Russian Federation",
  "RW" => "Rwanda",
  "SH" => "Saint Helena",
  "KN" => "Saint Kitts and Nevis",
  "LC" => "Saint Lucia",
  "PM" => "Saint Pierre and Miquelon",
  "VC" => "Saint Vincent and The Grenadines",
  "WS" => "Samoa",
  "SM" => "San Marino",
  "ST" => "Sao Tome and Principe",
  "SA" => "Saudi Arabia",
  "SN" => "Senegal",
  "RS" => "Serbia",
  "SC" => "Seychelles",
  "SL" => "Sierra Leone",
  "SG" => "Singapore",
  "SK" => "Slovakia",
  "SI" => "Slovenia",
  "SB" => "Solomon Islands",
  "SO" => "Somalia",
  "ZA" => "South Africa",
  "GS" => "South Georgia and The South Sandwich Islands",
  "ES" => "Spain",
  "LK" => "Sri Lanka",
  "SD" => "Sudan",
  "SR" => "Suriname",
  "SJ" => "Svalbard and Jan Mayen",
  "SZ" => "Swaziland",
  "SE" => "Sweden",
  "CH" => "Switzerland",
  "SY" => "Syrian Arab Republic",
  "TW" => "Taiwan, Province of China",
  "TJ" => "Tajikistan",
  "TZ" => "Tanzania, United Republic of",
  "TH" => "Thailand",
  "TL" => "Timor-leste",
  "TG" => "Togo",
  "TK" => "Tokelau",
  "TO" => "Tonga",
  "TT" => "Trinidad and Tobago",
  "TN" => "Tunisia",
  "TR" => "Turkey",
  "TM" => "Turkmenistan",
  "TC" => "Turks and Caicos Islands",
  "TV" => "Tuvalu",
  "UG" => "Uganda",
  "UA" => "Ukraine",
  "AE" => "United Arab Emirates",
  "GB" => "United Kingdom",
  "US" => "United States",
  "UM" => "United States Minor Outlying Islands",
  "UY" => "Uruguay",
  "UZ" => "Uzbekistan",
  "VU" => "Vanuatu",
  "VE" => "Venezuela",
  "VN" => "Viet Nam",
  "VG" => "Virgin Islands, British",
  "VI" => "Virgin Islands, U.S.",
  "WF" => "Wallis and Futuna",
  "EH" => "Western Sahara",
  "YE" => "Yemen",
  "ZM" => "Zambia",
  "ZW" => "Zimbabwe"
);	

if(isset($_POST['cAcc'])){
		
    $fn = $_POST['fn'];
    $ln = $_POST['ln'];
    $cn = $_POST['country'];
    $em = $_POST['email'];
    $pword = $_POST['pword'];
    $login_id = rand(11111111,99999999);
    $token = chr(rand(97,122))."".rand(1,9)."".chr(rand(97,122))."".rand(1,9)."".rand(11,99);
    $_SESSION['token'] = $token;
                                    
    $dt = date("Y-m-d h:i:s");
            
    $sl="SELECT * FROM users WHERE email ='$em'";
    $rs=mysqli_query($conn,$sl);
    $row=mysqli_fetch_array($rs);
    $cnt = mysqli_num_rows($rs); // if uname/pass correct it returns must be 1 row
                                
    if($cnt > 0) 
    {
      $report="<script>alert('Error! An account with the specified email address exists already!')</script>";
    }else{
        $sst="INSERT INTO settings(memID, sA1, sA2, sA3, eP, eB, eT, e3D, eEa, eSa, b2, b3, b4, b5)values('".$login_id."', 'yes', 'yes', 'yes', 'yes', 'yes','yes','yes','yes','yes','yes','yes','yes','yes')";
        $rss=mysqli_query($conn,$sst);
            
        $sql="INSERT INTO users(fn, ln, country, email, memID, pass, status)values('".mysqli_real_escape_string($conn, $fn)."', '".mysqli_real_escape_string($conn, $ln)."', '".mysqli_real_escape_string($conn, $cn)."', '".mysqli_real_escape_string($conn, $em)."', '".mysqli_real_escape_string($conn, $login_id)."', '".mysqli_real_escape_string($conn, $pword)."', '1')";
        $result=mysqli_query($conn,$sql);
                            
        if ($result) {
            $last_id = mysqli_insert_id($conn);

            $_SESSION['uid'] = $last_id;
            $dt = date("Y-m-d h:i:s");		
            
            $sl="update users set LLogin='".$dt."' where uID=".$last_id."";
            $result=mysqli_query($conn,$sl);
                  
            echo "<meta http-equiv='refresh' content='3; url=processing.php?request=signin' >";
            $report = "<p style='color: limegreen;'>Account created successfully! Redirecting...</p>";	
        } else {
            $report = "<p style='color: indianred;'>Something went wrong, try again later...</p>";	
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, shrink-to-fit=no">
<link href="images/favicon.png" rel="icon" />
<title>User Dashboard - Newage Union Bank</title>

<meta name="author" content="">

<!-- Web Fonts
============================================= -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap">

<!-- Stylesheet
============================================= -->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="vendor/font-awesome/css/all.min.css" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css" />
<!-- Colors Css -->
<link id="color-switcher" type="text/css" rel="stylesheet" href="#" />



</head>
<body>

<!-- Preloader
<div id="preloader">
  <div data-loader="dual-ring"></div>
</div>
Preloader End -->
<div id="google_translate_element"></div>

<script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL}, 'google_translate_element');
}
</script>

<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<div id="main-wrapper">
  <div class="container-fluid px-0">
    <div class="row g-0 min-vh-100">
      <div class="col-md-6"> 
        <!-- Get Verified! Text
        ============================================= -->
         <div class="col-md-6">
        <div class="hero-wrap d-flex align-items-center h-100">
          <div style="background:#0000;" class="hero-mask opacity-8 "></div>
          <div class="hero-bg hero-bg-scroll" style="background-image:url('images/bg/image-3.jpg');"></div>
          <div class="hero-content mx-auto w-100 h-100 d-flex flex-column">
            <div class="row g-0">
              <div class="col-10 col-lg-9 mx-auto">
                <div class="logo mt-5 mb-5 mb-md-0"> <a class="d-flex" href="../" title=""><img src="images/newage.png" style="width: 200px;" alt=""></a> </div>
              </div>
            </div>
            <div class="row g-0 my-auto">
              <div class="col-10 col-lg-9 mx-auto">
                <h1 class="text-11 text-white mb-4">Welcome back!</h1>
                <p class="text-4 text-white lh-base mb-5">We are glad to see you again! Sign In to access your Online Banking portal.</p>
              </div>
            </div>
          </div>
        </div>
      </div>
        <!-- Get Verified! Text End --> 
      </div>
      <div class="col-md-6 d-flex align-items-center"> 
        <!-- SignUp Form
        ============================================= -->
        <div class="container my-4">
          <div class="row g-0">
            <div class="col-11 col-lg-9 col-xl-8 mx-auto" style="margin-top: 50px;">
              <h3 class="fw-400 mb-4">Sign Up</h3>
              <p><?php echo $report; ?></p>
              <!-- MULTI-STEP REGISTRATION FORM -->
<form id="regForm" method="post">

  <!-- Step 1: Personal Info -->
  <div class="tab">
    <h4 class="mb-3">Personal Information</h4>
    <div class="mb-3">
      <label>First Name</label>
      <input type="text" class="form-control" name="fn" required>
    </div>
    <div class="mb-3">
      <label>Last Name</label>
      <input type="text" class="form-control" name="ln" required>
    </div>
    <div class="mb-3">
      <label>Date of Birth</label>
      <input type="date" class="form-control" name="dob" required>
    </div>
    <div class="mb-3">
      <label>Gender</label>
      <select name="gender" class="form-control" required>
        <option value="" disabled selected>Select Gender</option>
        <option>Male</option>
        <option>Female</option>
        <option>Other</option>
      </select>
    </div>
  </div>

  <!-- Step 2: Contact & Security -->
  <div class="tab">
    <h4 class="mb-3">Contact & Security</h4>
    <div class="mb-3">
      <label>Email</label>
      <input type="email" class="form-control" name="email" required>
    </div>
    <div class="mb-3">
      <label>Phone Number</label>
      <input type="text" class="form-control" name="phone" required>
    </div>
    <div class="mb-3">
      <label>Country</label>
      <select class="form-control" name="country" required>
        <option value="" disabled selected>Select Country</option>
        <?php foreach ($countries as $code => $name) { echo "<option value='$name'>$name</option>"; } ?>
      </select>
    </div>
    <div class="mb-3">
      <label>Password</label>
      <input type="password" class="form-control" name="pword" required>
    </div>
  </div>

  <!-- Step 3: Account Setup -->
  <div class="tab">
    <h4 class="mb-3">Account Preferences</h4>
    <div class="mb-3">
      <label>Account Type</label>
      <select name="account_type" class="form-control" required>
        <option value="" disabled selected>Select Account Type</option>
        <option>Savings</option>
        <option>Current</option>
        <option>Business</option>
        <option>Fixed Deposit</option>
      </select>
    </div>
    <div class="mb-3">
      <label>Initial Deposit (USD)</label>
      <input type="number" name="deposit" class="form-control" required>
    </div>
    <div class="form-check mb-3">
      <input type="checkbox" class="form-check-input" required>
      <label class="form-check-label">I agree to the <a href="#">Terms & Conditions</a></label>
    </div>
    <div class="d-grid">
      <button class="btn btn-dark" type="submit" name="cAcc">Create Account</button>
    </div>
  </div>

  <!-- Navigation Buttons -->
  <!--<div style="overflow:auto;" class="mt-3">-->
  <!--  <div style="float:right;">-->
  <!--    <button type="button" class="btn btn-secondary" id="prevBtn" onclick="nextPrev(-1)">Previous</button>-->
  <!--    <button type="button" class="btn btn-primary" id="nextBtn" onclick="nextPrev(1)">Next</button>-->
  <!--  </div>-->
  <!--</div>-->

</form>
<!-- END MULTI-STEP FORM -->

              <p class="text-3 text-center text-muted">Already have an account? <a class="btn-link" href="login.php">Log In</a></p>
            </div>
          </div>
        </div>
        <!-- SignUp Form End --> 
      </div>
    </div>
  </div>
</div>

<!-- Back to Top
============================================= --> 
<a id="back-to-top" data-bs-toggle="tooltip" title="Back to Top" href="javascript:void(0)"><i class="fa fa-chevron-up"></i></a> 

<!-- Styles Switcher -->

<!-- Styles Switcher End --> 
<script>
let currentTab = 0;
showTab(currentTab);

function showTab(n) {
  let x = document.getElementsByClassName("tab");
  x[n].style.display = "block";
  document.getElementById("prevBtn").style.display = n === 0 ? "none" : "inline";
  document.getElementById("nextBtn").innerHTML = n === (x.length - 1) ? "Submit" : "Next";
}

function nextPrev(n) {
  let x = document.getElementsByClassName("tab");
  if (n === 1 && !validateForm()) return false;
  x[currentTab].style.display = "none";
  currentTab += n;
  if (currentTab >= x.length) {
    document.getElementById("regForm").submit();
    return false;
  }
  showTab(currentTab);
}

function validateForm() {
  let x, y, i, valid = true;
  x = document.getElementsByClassName("tab");
  y = x[currentTab].querySelectorAll("input, select");
  for (i = 0; i < y.length; i++) {
    if (!y[i].checkValidity()) {
      y[i].classList.add("is-invalid");
      valid = false;
    } else {
      y[i].classList.remove("is-invalid");
    }
  }
  return valid;
}
</script>

<!-- Script --> 
<!-- Smartsupp Live Chat script -->
<!-- Smartsupp Live Chat script -->
<script type="text/javascript">
var _smartsupp = _smartsupp || {};
_smartsupp.key = '28bf529905701ee28207d99d49cd6e736a87a742';
window.smartsupp||(function(d) {
  var s,c,o=smartsupp=function(){ o._.push(arguments)};o._=[];
  s=d.getElementsByTagName('script')[0];c=d.createElement('script');
  c.type='text/javascript';c.charset='utf-8';c.async=true;
  c.src='https://www.smartsuppchat.com/loader.js?';s.parentNode.insertBefore(c,s);
})(document);
</script><!-- Smartsupp Live Chat script -->

<!-- Style Switcher --> 

<script src="js/switcher.min.js"></script> 
<script src="js/theme.js"></script>
</body>
</html>