<?php
include('../Config/config.php');

session_start();
$months = array();
$currentMonth = (int) date('m');
$checkQueryAdmin = mysqli_query(get_db(), "SELECT * FROM admin WHERE admin_id = 1");
//echo "SELECT * FROM admin WHERE username = '".$_POST['username']."'  AND password = '".$_POST['Password']."' ".mysqli_error();

$fetchAdmin = mysqli_fetch_array($checkQueryAdmin);

for ($x = $currentMonth; $x < $currentMonth + 10; $x++) {
    $months[] = date('m-Y', mktime(0, 0, 0, $x, 1));
}

$userEmailExist = mysqli_query(get_db(), "SELECT * FROM member_details ORDER BY member_id DESC ");

$fetchhh = mysqli_fetch_array($userEmailExist);



//print_r($months);
if (isset($_POST['addUser'])) {
    $userEmailExist2342342 = mysqli_query(get_db(), "SELECT * FROM member_details WHERE memberID = '" . $_POST['sponser_id'] . "' AND completeProfile = 1 ");


    $userEmailExist565 = mysqli_query(get_db(), "SELECT * FROM member_details WHERE memberID = '" . $_POST['sponser_id'] . "'");
    if (mysqli_num_rows($userEmailExist565) == 0) {
        echo '<script>alert("Sorry.. Sponser ID is not yet exist.");</script>';
        echo "<script>window.location='';</script>";
        exit;


    }









    /* $userEmailExist = mysqli_query(get_db(), "SELECT * FROM member_details WHERE memberID = '".$_POST['sponser_id']."' AND completeProfile = 1 ");
       if(mysqli_num_rows($userEmailExist) == 0)
       {
                 echo'<script>alert("Sorry.. Sponser ID is not yet activated.");</script>';	
               echo "<script>window.location='add-member.php';</script>";
              exit;

       }
       */

    if (empty($_POST['sponser_id'])) {
        $_POST['sponser_id'] = 'FDX00001';
    }
    $memberID = generateRandomIDD();

    $memberphone = $_POST['phone'];

    $getLastRefrenceID = getLastRefrenceID();
    //echo 'getLastRefrenceID'.$getLastRefrenceID;
//exit;
    $password = $_POST['password'];
    $insert = array(
        'memberID' => $memberID,
        'password' => $password,

        'name' => $_POST['name'],
        'email' => $_POST['email'],
        'countryname' => $_POST['countryCode'],
        'phone' => $_POST['phone'],
        'sponser_id' => $_POST['sponser_id'],
        'placementID' => $getLastRefrenceID,
        'city' => $_POST['city'],
        'joining_date' => date('d/m/Y'),
        'tron' => $_POST['tron'],
        
        'status' => 0,
        'completeProfile' => 0,
        'updatedProfile' => 0,
        
        'registration_date_time' => date("Y-m-d h:i:s A"),
        'last_updated_by' => 'Registered From Website'

    );

    $update_status = insert_data('member_details', $insert);

    $email_to = $_POST['email'];

   $url = 'https://coinearn.in.net/emails/examples/mail1.php?email=' . $email_to;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response_json = curl_exec($ch);
    curl_close($ch);

    // distributing income accordigly 
header('location: sucess-member.php?id=' . $email_to);
exit;
//exit;

    ?>

    <script>alert("Congratulation ! Registration is Done.");</script>

    <?php
    header('Location: sucess-member.php?id=' . $email_to);

    //$updatingPath = mysqli_query(get_db(), "UPDATE admin SET password = '".$new_password."' WHERE username = '".$_SESSION['username']."' ");
    ?>
    <script>window.location = 'sucess-member.php?id='<?php echo $email_to; ?>';</script>

    <?php

}
?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->

<head>
    <meta charset="UTF-8">
    <title><?php echo $fetchAdmin['website_title']; ?> || Register</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- bootstrap 4  -->
    <link href="LoginCss/bootstrap.min.css" rel="stylesheet" />
    <link href="LoginCss/all.min.css" rel="stylesheet" />
    <link href="LoginCss/line-awesome.min.css" rel="stylesheet" />
    <link href="LoginCss/animate.min.css" rel="stylesheet" />
    <link href="LoginCss/slick.css" rel="stylesheet" />
    <link href="LoginCss/dots.css" rel="stylesheet" />
    <link href="LoginCss/main.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <div class="preloader">
        <div class="preloader-container">
            <span class="animated-preloader"></span>
        </div>
    </div>

    <!-- scroll-to-top start -->
    <div class="scroll-to-top">
        <span class="scroll-icon">
            <i class="fa fa-rocket" aria-hidden="true"></i>
        </span>
    </div>
    <!-- scroll-to-top end -->

    <div class="full-wh">
        <!-- STAR ANIMATION -->
        <div class="bg-animation">
            <div id='stars'></div>
            <div id='stars2'></div>
            <div id='stars3'></div>
            <div id='stars4'></div>
        </div><!-- / STAR ANIMATION -->
    </div>
    <div class="page-wrapper">

        <!-- account section start -->
        <div class="account-section bg_img" data-background="LoginCss/Images/bg-5.jpg">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-xl-5 col-lg-7">
                        <div class="account-card">
                            <div class="account-card__header bg_img overlay--one"
                                data-background="LoginCss/Images/bg-6.jpg" style="text-align: center;">
                                <a href="Home.html">
                                    <img src="<?php echo $fetchAdmin['web_logo']; ?>"
                                        style="display: block; margin-left: auto; margin-right: auto; width: 250px; height: auto;" />
                                </a>
                                <h2 style="font-size: 36px;" class="section-title">Welcome to <span
                                        class="base--color"><?php echo $fetchAdmin['website_title']; ?></span></h2>
                            </div>
                            <div class="account-card__body">
                                <h3 class="text-center">Create an Account</h3>
                                <form method="post" action="" id="ctl00" class="mt-4">
                                    <div class="aspNetHidden">
                                        <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
                                        <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
                                        <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
                                        <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
                                            value=" " />
                                    </div>

                                    <script type="text/javascript">
                                        //<![CDATA[
                                        var theForm = document.forms['ctl00'];
                                        if (!theForm) {
                                            theForm = document.ctl00;
                                        }
                                        function __doPostBack(eventTarget, eventArgument) {
                                            if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
                                                theForm.__EVENTTARGET.value = eventTarget;
                                                theForm.__EVENTARGUMENT.value = eventArgument;
                                                theForm.submit();
                                            }
                                        }
                                        //]]>
                                    </script>


                                    <script
                                        src="WebResource4ab7.js?d=pynGkmcFUV13He1Qd6_TZCEpnGD75JyZ7HhMDB8saLlQC_hdGWdJuS21ZJXRK6X0yqSKRPgsBEmhXnNnVKv-EA2&amp;t=638627956040000000"
                                        type="text/javascript"></script>

                                    <div class="aspNetHidden">

                                        <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR"
                                            value="F375BEB0" />
                                    </div>
                                    <div class="form-group">
                                        <label>Referral Code</label>
                                        <input name="sponser_id" type="text" maxlength="12"
                                           onKeyUp="showHint(this.value)" required
                                            id="sponser_id" class="form-control" placeholder="Referral Code (optional)" />
                                        <div class="form-floating form-floating-custom mb-4">
                                            <span id="txtspname"
                                                style="color:Red;margin: 0 auto; display: table;"></span>
                                        </div>
                                    </div>
                                  
                                    <div class="form-group">
                                        <label>Full Name</label>
                                        <input name="name" type="text" maxlength="50" id="name"
                                            class="form-control" placeholder="User Name" />
                                    </div>
                                    <div class="form-group">
                                        <label>Contact No.</label>
                                        <input name="phone" type="text" maxlength="10" id="phone" tabindex="5"
                                            class="form-control" required="required" placeholder="Contact Number" />
                                    </div>
                                    <div class="form-group">
                                        <label>Email Address</label>
                                        <input name="email" type="text" maxlength="70" id="email" tabindex="6"
                                            class="form-control" required="required" placeholder="Email Address" />
                                    </div>

                                    <div class="form-group">
                                        <label for="input-password">Select Country</label>
                                        <select name="ddlcountry" id="ddlcountry" tabindex="4" class="form-control">
                                            <option value="0">-Select Country-</option>
                                            <option value="1">Afghanistan(+93)</option>
                                            <option value="2">Albania(+355)</option>
                                            <option value="3">Algeria(+213)</option>
                                            <option value="4">American Samoa(+1)</option>
                                            <option value="5">Andorra(+376)</option>
                                            <option value="6">Angola(+244)</option>
                                            <option value="7">Anguilla(+1)</option>
                                            <option value="8">Antigua and Barbuda(+1)</option>
                                            <option value="9">Argentina(+54)</option>
                                            <option value="223">Armenia(+374)</option>
                                            <option value="224">Aruba(+297)</option>
                                            <option value="225">Australia(+61)</option>
                                            <option value="226">Austria(+43)</option>
                                            <option value="227">Azerbaijan(+994)</option>
                                            <option value="228">Bahamas(+1)</option>
                                            <option value="229">Bahrain(+973)</option>
                                            <option value="230">Bangladesh(+880)</option>
                                            <option value="10">Barbados(+1)</option>
                                            <option value="11">Belarus(+375)</option>
                                            <option value="12">Belgium(+32)</option>
                                            <option value="13">Belize(+501)</option>
                                            <option value="14">Benin(+229)</option>
                                            <option value="15">Bermuda(+1)</option>
                                            <option value="16">Bhutan(+975)</option>
                                            <option value="17">Bolivia(+591)</option>
                                            <option value="18">Bosnia and Herzegovina(+387)</option>
                                            <option value="19">Botswana(+267)</option>
                                            <option value="20">Brazil(+55)</option>
                                            <option value="21">British Indian Ocean Territory()</option>
                                            <option value="22">British Virgin Islands(+1)</option>
                                            <option value="23">Brunei(+673)</option>
                                            <option value="24">Bulgaria(+226)</option>
                                            <option value="25">Burkina Faso()</option>
                                            <option value="26">Burma()</option>
                                            <option value="27">Burundi(+226)</option>
                                            <option value="28">Cambodia(+855)</option>
                                            <option value="29">Cameroon(+237)</option>
                                            <option value="30">Canada(+1)</option>
                                            <option value="31">Cape Verde(+238)</option>
                                            <option value="32">Cayman Islands(+1-345)</option>
                                            <option value="33">Central African Republic(+236)</option>
                                            <option value="34">Chad(+235)</option>
                                            <option value="35">Chile(+56)</option>
                                            <option value="36">China(+86)</option>
                                            <option value="37">Colombia(+57)</option>
                                            <option value="38">Comoros(+269)</option>
                                            <option value="39">Congo Democratic Republic(+243)</option>
                                            <option value="40">Congo Republic()</option>
                                            <option value="41">Cook Islands(+682)</option>
                                            <option value="42">Costa Rica(+506)</option>
                                            <option value="43">Cote Divoire()</option>
                                            <option value="44">Croatia(+385)</option>
                                            <option value="45">Cuba(+53)</option>
                                            <option value="46">Cyprus(+357)</option>
                                            <option value="47">Czech Republic(+420)</option>
                                            <option value="48">Denmark(+45)</option>
                                            <option value="50">Dominica(+1-767)</option>
                                            <option value="51">Dominican Republic(+1-809)</option>
                                            <option value="52">East Timor(+670)</option>
                                            <option value="53">Egypt(+20)</option>
                                            <option value="54">El Salvador(+503)</option>
                                            <option value="55">England()</option>
                                            <option value="56">Equador(+20)</option>
                                            <option value="57">Equatorial Guinea(+240)</option>
                                            <option value="58">Eritrea(+291)</option>
                                            <option value="59">Estonia(+372)</option>
                                            <option value="60">Ethiopia(+251)</option>
                                            <option value="61">Falkland Islands(+500)</option>
                                            <option value="62">Faroe Islands(+298)</option>
                                            <option value="63">Fiji(+679)</option>
                                            <option value="64">Finland(+358)</option>
                                            <option value="65">France(+33)</option>
                                            <option value="66">French Polynesia(+689)</option>
                                            <option value="67">Gabon(+241)</option>
                                            <option value="68">Gambia(+220)</option>
                                            <option value="69">Georgia(+995)</option>
                                            <option value="70">Germany(+49)</option>
                                            <option value="71">Ghana(+233)</option>
                                            <option value="72">Gibraltar(+350)</option>
                                            <option value="73">Great Britain()</option>
                                            <option value="74">Greece(+30)</option>
                                            <option value="75">Greenland(+299)</option>
                                            <option value="76">Grenada(+1-473)</option>
                                            <option value="77">Guam(+1-671)</option>
                                            <option value="78">Guatemala(+502)</option>
                                            <option value="79">Guernsey(+44-1481)</option>
                                            <option value="81">Guinea Bissau(+245)</option>
                                            <option value="80">Guinea(+224)</option>
                                            <option value="82">Guyana(+592)</option>
                                            <option value="83">Haiti(+509)</option>
                                            <option value="84">Honduras(+504)</option>
                                            <option value="85">Hong Kong(+852)</option>
                                            <option value="86">Hungary(+36)</option>
                                            <option value="87">Iceland(+354)</option>
                                            <option selected="selected" value="88">India(+91)</option>
                                            <option value="89">Indonesia(+62)</option>
                                            <option value="90">Iran(+98)</option>
                                            <option value="91">Iraq(+964)</option>
                                            <option value="92">Ireland(+353)</option>
                                            <option value="93">Isle of Man(+44-1624)</option>
                                            <option value="94">Israel(+972)</option>
                                            <option value="95">Italy(+39)</option>
                                            <option value="96">Jamaica(+1-876)</option>
                                            <option value="97">Japan(+81)</option>
                                            <option value="98">Jersey(+44-1534)</option>
                                            <option value="99">Jordan(+962)</option>
                                            <option value="100">Kazakhstan(+7)</option>
                                            <option value="101">Kenya(+254)</option>
                                            <option value="102">Kiribati(+686)</option>
                                            <option value="103">Kuwait(+965)</option>
                                            <option value="104">Kyrgyzstan(+996)</option>
                                            <option value="105">Laos(+856)</option>
                                            <option value="106">Latvia(+371)</option>
                                            <option value="107">Lebanon(+961)</option>
                                            <option value="108">Lesotho(+266)</option>
                                            <option value="109">Liberia(+231)</option>
                                            <option value="110">Libya(+218)</option>
                                            <option value="111">Liechtenstein(+423)</option>
                                            <option value="112">Lithuania(+370)</option>
                                            <option value="113">Luxembourg(+352)</option>
                                            <option value="114">Macau(+853)</option>
                                            <option value="115">Macedonia(+389)</option>
                                            <option value="116">Madagascar(+261)</option>
                                            <option value="117">Malawi(+265)</option>
                                            <option value="118">Malaysia(+60)</option>
                                            <option value="119">Maledives(+960)</option>
                                            <option value="120">Mali(+223)</option>
                                            <option value="121">Malta(+356)</option>
                                            <option value="122">Marshall Islands(+692)</option>
                                            <option value="123">Martinique()</option>
                                            <option value="124">Mauretania(+222)</option>
                                            <option value="125">Mauritius(+230)</option>
                                            <option value="126">Mexico(+52)</option>
                                            <option value="127">Micronesia(+691)</option>
                                            <option value="128">Moldova(+373)</option>
                                            <option value="129">Monaco(+377)</option>
                                            <option value="130">Mongolia(+976)</option>
                                            <option value="131">Montserrat(+1-664)</option>
                                            <option value="132">Morocco(+212)</option>
                                            <option value="133">Mozambique(+258)</option>
                                            <option value="134">Namibia(+264)</option>
                                            <option value="135">Nauru(+674)</option>
                                            <option value="136">Nepal(+977)</option>
                                            <option value="138">Netherlands Antilles(+599)</option>
                                            <option value="137">Netherlands(+31)</option>
                                            <option value="139">New Zealand(+64)</option>
                                            <option value="140">Nicaragua(+505)</option>
                                            <option value="141">Niger(+227)</option>
                                            <option value="142">Nigeria(+234)</option>
                                            <option value="143">Niue(+683)</option>
                                            <option value="144">Norfolk Island()</option>
                                            <option value="145">North Korea(+850)</option>
                                            <option value="146">Northern Mariana Islands(+1-670)</option>
                                            <option value="147">Norway(+47)</option>
                                            <option value="148">Oman(+968)</option>
                                            <option value="232">Others()</option>
                                            <option value="149">Pakistan(+92)</option>
                                            <option value="150">Palau(+680)</option>
                                            <option value="151">Panama(+507)</option>
                                            <option value="152">Papua New Guinea(+675)</option>
                                            <option value="153">Paraquay(+595)</option>
                                            <option value="154">Peru(+51)</option>
                                            <option value="155">Philippines(+63)</option>
                                            <option value="156">Pitcairn Islands(+64)</option>
                                            <option value="157">Poland(+48)</option>
                                            <option value="158">Portugal(+351)</option>
                                            <option value="159">Puerto Rico(+1-787)</option>
                                            <option value="160">Qatar(+974)</option>
                                            <option value="161">Romania(+40)</option>
                                            <option value="162">Russia(+7)</option>
                                            <option value="163">Rwanda(+250)</option>
                                            <option value="164">Saint Helena(+590)</option>
                                            <option value="165">Saint Kitts and Nevis(+1-869)</option>
                                            <option value="166">Saint Lucia(+1-758)</option>
                                            <option value="167">Saint Pierre and Miquelon(+508)</option>
                                            <option value="168">Saint Vincent and the Grenadines(+1-784)</option>
                                            <option value="169">Samoa(+685)</option>
                                            <option value="170">San Marino(+378)</option>
                                            <option value="171">Sao Tome and Principe(+239)</option>
                                            <option value="172">Saudi Arabia(+966)</option>
                                            <option value="173">Scotland()</option>
                                            <option value="174">Senegal(+221)</option>
                                            <option value="175">Serbia Montenegro(+381)</option>
                                            <option value="176">Seychelles(+248)</option>
                                            <option value="177">Sierra Leone(+232)</option>
                                            <option value="178">Singapore(+65)</option>
                                            <option value="179">Slovakia(+421)</option>
                                            <option value="180">Slovenia(+386)</option>
                                            <option value="181">Solomon Islands(+677)</option>
                                            <option value="182">Somalia(+252)</option>
                                            <option value="183">South Africa(+27)</option>
                                            <option value="184">South Georgia()</option>
                                            <option value="185">South Korea(+82)</option>
                                            <option value="186">Spain(+34)</option>
                                            <option value="187">Sri Lanka(+94)</option>
                                            <option value="188">Sudan(+249)</option>
                                            <option value="189">Suriname(+597)</option>
                                            <option value="190">Swaziland(+268)</option>
                                            <option value="191">Sweden(+46)</option>
                                            <option value="192">Switzerland(+41)</option>
                                            <option value="193">Syria(+963)</option>
                                            <option value="194">Taiwan(+886)</option>
                                            <option value="195">Tajikistan(+992)</option>
                                            <option value="196">Tanzania(+255)</option>
                                            <option value="197">Thailand(+66)</option>
                                            <option value="198">Tibet()</option>
                                            <option value="199">Togo(+228)</option>
                                            <option value="200">Tonga(+676)</option>
                                            <option value="201">Trinidad and Tobago(+1-868)</option>
                                            <option value="202">Tunisia(+216)</option>
                                            <option value="203">Turkey(+90)</option>
                                            <option value="204">Turkmenistan(+993)</option>
                                            <option value="205">Turks and Caicos Islands(+1-649)</option>
                                            <option value="206">Tuvalu(+688)</option>
                                            <option value="207">Uganda(+256)</option>
                                            <option value="231">UK(+44)</option>
                                            <option value="208">Ukraine(+380)</option>
                                            <option value="209">United Arab Emirates(+971)</option>
                                            <option value="210">Uruquay(+598)</option>
                                            <option value="211">USA(+1)</option>
                                            <option value="212">Uzbekistan(+263)</option>
                                            <option value="213">Vanuatu(+678)</option>
                                            <option value="214">Vatican City(+379)</option>
                                            <option value="215">Venezuela(+58)</option>
                                            <option value="216">Vietnam(+84)</option>
                                            <option value="217">Virgin Islands()</option>
                                            <option value="218">Wales()</option>
                                            <option value="219">Wallis and Futuna(+681)</option>
                                            <option value="220">Yemen(+967)</option>
                                            <option value="221">Zambia(+260)</option>
                                            <option value="222">Zimbabwe()</option>

                                        </select>


                                    </div>
                                    <div class="form-group">
                                        <label>Password</label>
                                        <input name="password" type="text" maxlength="50" id="password" class="form-control"
                                            placeholder="Password" />
                                    </div>
                                    <div class="form-row">
                                        <div class="col-sm-6">
                                            <div class="form-group form-check">
                                                <span class="form-check-input"><input id="chkRememberMe" type="checkbox"
                                                        name="chkRememberMe" /></span>
                                                <label class="form-check-label" for="exampleCheck1">Remember me</label>
                                            </div>
                                        </div>
                                        <div class="col-sm-6 text-sm-right">
                                            <p class="f-size-14">Have an account? <a href="login.php"
                                                    class="base--color">Login</a></p>
                                        </div>
                                    </div>
                                    <div class="mt-3">
                                        <input type="submit" name="addUser" value="Register" id="btnRegister"
                                            tabindex="11" class="cmn-btn" />
                                        <span id="lblmsg" style="color:Red;font-size: large; text-align: left"></span>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- account section end -->

    </div> <!-- page-wrapper end -->
    <!-- jQuery library -->
    <script src="LoginCss/Js/jquery-3.5.1.min.js"></script>
    <script src="LoginCss/Js/bootstrap.bundle.min.js"></script>
    <script src="LoginCss/Js/slick.min.js"></script>
    <script src="LoginCss/Js/wow.min.js"></script>
    <script src="LoginCss/Js/contact.js"></script>
    <script src="LoginCss/Js/app.js"></script>
     <script type="text/javascript">
function showHint(str) {
//alert("bvcbcvb");
  if (str.length == 0) {
    document.getElementById("txtHint").innerHTML = "";
    return;	
  } else {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
        document.getElementById("txtspname").innerHTML = this.responseText;
      }
    }
    xmlhttp.open("GET", "validateID.php?userID="+str, true);
    xmlhttp.send();
  }
}

</script>
</body>



</html>