<?php

    session_start();

    ob_start();

    include "../db.php";

?>

<!DOCTYPE html>

<html lang="en">

<head>

 <?php include "include/meta.php"; ?>    		 

    <?php include "include/css.php"; ?>    





<style>

* {box-sizing: border-box}



/* Set height of body and the document to 100% */

body, html {

  height: 100%;

  margin: 0;

  font-family: Arial;

}



/* Style tab links */

.tablink {

  background-color: #555;

  color: white;

  float: left;

  border: none;

  outline: none;

  cursor: pointer;

  padding: 14px 16px;

  font-size: 17px;

  width: 50%;

}



.tablink:hover {

  background-color: #777;

}



/* Style the tab content (and add height:100% for full page content) */

.tabcontent {

  color: white;

  display: none;

  padding: 100px 20px;

  height: 100%;

}



#Home {background-color: #D1D0C0;}

#News {background-color: #D1D0C0;}



</style>

    <style>

    /* sign in FORM */

    #logreg-forms {

        width: 412px;

        margin: 10vh auto;

        background-color: #f3f3f3;

        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);

        transition: all 0.3s cubic-bezier(.25, .8, .25, 1);

    }



    #logreg-forms form {

        width: 100%;

        max-width: 410px;

        padding: 15px;

        margin: auto;

    }



    #logreg-forms .form-control {

        position: relative;

        box-sizing: border-box;

        height: auto;

        padding: 10px;

        font-size: 16px;

    }



    #logreg-forms .form-control:focus {

        z-index: 2;

    }



    #logreg-forms .form-signin input[type="email"] {

        margin-bottom: -1px;

        border-bottom-right-radius: 0;

        border-bottom-left-radius: 0;

    }



    #logreg-forms .form-signin input[type="password"] {

        border-top-left-radius: 0;

        border-top-right-radius: 0;

    }



    #logreg-forms .social-login {

        width: 390px;

        margin: 0 auto;

        margin-bottom: 14px;

    }



    #logreg-forms .social-btn {

        font-weight: 100;

        color: white;

        width: 190px;

        font-size: 0.9rem;

    }



    #logreg-forms a {

        display: block;

        padding-top: 10px;

        color: lightseagreen;

    }



    #logreg-form .lines {

        width: 200px;

        border: 1px solid red;

    }





    #logreg-forms button[type="submit"] {

        margin-top: 10px;

    }



    #logreg-forms .facebook-btn {

        background-color: #3C589C;

    }



    #logreg-forms .google-btn {

        background-color: #DF4B3B;

    }



    #logreg-forms .form-reset,

    #logreg-forms .form-signup {

        display: none;

    }



    #logreg-forms .form-signup .social-btn {

        width: 210px;

    }



    #logreg-forms .form-signup input {

        margin-bottom: 2px;

    }



    .form-signup .social-login {

        width: 210px !important;

        margin: 0 auto;

    }



    /* Mobile */



    @media screen and (max-width:500px) {

        #logreg-forms {

            width: 300px;

        }



        #logreg-forms .social-login {

            width: 200px;

            margin: 0 auto;

            margin-bottom: 10px;

        }



        #logreg-forms .social-btn {

            font-size: 1.3rem;

            font-weight: 100;

            color: white;

            width: 200px;

            height: 56px;



        }



        #logreg-forms .social-btn:nth-child(1) {

            margin-bottom: 5px;

        }



        #logreg-forms .social-btn span {

            display: none;

        }



        #logreg-forms .facebook-btn:after {

            content: 'Facebook';

        }



        #logreg-forms .google-btn:after {

            content: 'Google+';

        }

    }

    </style>

	

	

	    <style>

        .content {

            position: absolute;

            top: 300px;

            left: 50%;

            transform: translate(-50%, -50%);

            background: rgba(0, 0, 0, 0.5);

            color: #f1f1f1;

            padding: 20px;

            border-radius: 5px;

            width: 300px;

            height:400px;

        }

        @media(max-width:500px){

            .content {

                left: 50%;

                width: 100%;

            }

        }

        .content3{

            background: #000;

            color:#fff;

            padding:20px;

        }

        .testing{

            text-align: right;

        }

        @media(max-width:768px){

            .testing{

                text-align: left;

            }

        }

    </style>

</head>



<body>

   <?php include "include/header2.php"; ?>



   <div style="padding-top:30px;"></div>	 

   

  





<div id="logreg-forms">

	

	



    <button class="tablink" style="width: 100%;" onclick="openPage('Home', this, 'green')"  id="defaultOpen">Request Form</button>



    <div id="Home" class="tabcontent">

        <form method="post">

                <div class="form-group">

                    <input type="text" name="signup_username" id="signup_username" class="form-control" style="margin:10px 0;" placeholder="Enter Name *" required>



                    <input type="tel" name="signup_mobileno" id="signup_mobileno" class="form-control" style="margin:10px 0;" placeholder="Enter Mobile No. *" required>



                    <input type="email" name="signup_email" id="signup_email" class="form-control" style="margin:10px 0;" placeholder="Enter Email Id">



                    <input type="text" name="signup_address" id="signup_address" class="form-control" style="margin:10px 0;" placeholder="Enter City,Street Name *" required>



                    <input type="text" name="signup_dist" id="signup_dist" class="form-control" style="margin:10px 0;" placeholder="Enter District *" required>



                    <input type="text" name="signup_pin" id="signup_pin" class="form-control" style="margin:10px 0;" placeholder="Enter Pin *" required>

                    

                    <input list="signup_category" name="signup_category" placeholder=" Select Category *"  class="form-control" style="margin:10px 0;" required>

                              <datalist id="signup_category">

                                    <option value="Member">

                                    <option value="Institute">

                                    <option value="School">

                                    <option value="Coaching Center">

                                    <option value="Teacher">

                              </datalist>



                    <textarea name="signup_about" id="signup_about" class="form-control" style="margin:10px 0;" placeholder="About *"></textarea>

                    

                    <input type="text" name="signup_upload_ref" id="signup_upload_ref" class="form-control" style="margin:10px 0;" placeholder="Referance Code" value="<?php if(isset($_GET['r']) && !empty($_GET['r'])){ echo $_GET['r'];} ?>">



                    <button type="submit" class="btn btn-success" name="signup_button"> <i class="fa fa-sign-in"></i> Sign-Up</button>

                    <br>

                    <br>

                    <br>

                    <p  style="color:black;"><strong style="color:red;">Note: </strong>We Will Contact You As Soon As Possible.</p>

                </div>

        </form>

    </div>



</div>



</body>

</html>



<script>

    function toggleResetPswd(e) {

        e.preventDefault();

        $('#logreg-forms .form-signin').toggle()

        $('#logreg-forms .form-reset').toggle()

    }function toggleSignUp(e) {

        e.preventDefault();

        $('#logreg-forms .form-signin').toggle();

        $('#logreg-forms .form-signup').toggle();

    }function validate(evt) {

        var theEvent = evt || window.event;

        if (theEvent.type === 'paste') {

            key = event.clipboardData.getData('text/plain');

        } else {

            var key = theEvent.keyCode || theEvent.which;

            key = String.fromCharCode(key);

        }

        var regex = /[0-9]|\./;

        if (!regex.test(key)) {

            theEvent.returnValue = false;

            if (theEvent.preventDefault) theEvent.preventDefault();

        }

    }$(() => {

        $('#logreg-forms #forgot_pswd').click(toggleResetPswd);

        $('#logreg-forms #cancel_reset').click(toggleResetPswd);

        $('#logreg-forms #btn-signup').click(toggleSignUp);

        $('#logreg-forms #cancel_signup').click(toggleSignUp);

    })

</script>



<script>

function openPage(pageName,elmnt,color) {

  var i, tabcontent, tablinks;

  tabcontent = document.getElementsByClassName("tabcontent");

  for (i = 0; i < tabcontent.length; i++) {

    tabcontent[i].style.display = "none";

  }

  tablinks = document.getElementsByClassName("tablink");

  for (i = 0; i < tablinks.length; i++) {

    tablinks[i].style.backgroundColor = "";

  }

  document.getElementById(pageName).style.display = "block";

  elmnt.style.backgroundColor = color;

}



// Get the element with id="defaultOpen" and click on it

document.getElementById("defaultOpen").click();

</script>





<?php

    if ( isset($_POST['signup_button']) ) {

        $signup_username = mysqli_real_escape_string($con, strip_tags($_POST['signup_username']));

        $signup_address = mysqli_real_escape_string($con, strip_tags($_POST['signup_address']));

        $signup_dist = mysqli_real_escape_string($con, strip_tags($_POST['signup_dist']));

        $signup_pin = mysqli_real_escape_string($con, strip_tags($_POST['signup_pin']));

        $signup_about = mysqli_real_escape_string($con, strip_tags($_POST['signup_about']));

        $signup_category = mysqli_real_escape_string($con, strip_tags($_POST['signup_category']));

        $signup_mobileno = mysqli_real_escape_string($con, strip_tags($_POST['signup_mobileno']));

        $signup_email = mysqli_real_escape_string($con, strip_tags($_POST['signup_email']));

        $signup_upload_ref = mysqli_real_escape_string($con, strip_tags($_POST['signup_upload_ref']));

        $ucreated = date("j F, Y, g:i a");



        $slicedName = substr($signup_username, 0, 2);

        $slicedCategory = substr($signup_mobileno, 0, 2);

        $slicedRandom = substr(mt_rand(), 0, 2);

        // created password

        //$password = $slicedCategory.$slicedRandom;

        

        // created user reference code

        $customTime = date("s");

        $upperUserStr = strtoupper($signup_username);

        $firstTwoCharactersOfUser = substr($upperUserStr, 0, 2);

        $r_ref = $firstTwoCharactersOfUser.$customTime.$slicedRandom;



        $u_sql = "SELECT ucontact FROM users WHERE ucontact = '$signup_mobileno'";

        $u_run = mysqli_query($con, $u_sql);

        $rowCount = $u_run->num_rows;



        // echo $rowCount;exit();



        if ( $rowCount > 0 ) {

            ?>

            <script>

                alert("User Exists Already !");

                window.location = "index.php";

            </script>

            <?php

        } else {

            $ins_sql = "INSERT INTO users (uname, uref_code, ucontact, uemail,  saddress, dist, pin,  uremark, uqualification, upload_ref_code, reg_approved,  ucreated) VALUES ('$signup_username','$r_ref','$signup_mobileno', '$signup_email','$signup_address','$signup_dist','$signup_pin','$signup_about', '$signup_category', '$signup_upload_ref', '0' , '$ucreated')";





          

            if( mysqli_query($con, $ins_sql) ){

                ?>

                <script>

                    alert("Signed Up Successfully");

                    window.location = "index.php";

                </script>

                <?php

            }

            else{

                ?>

                <script>

                    alert("Something's Wrong");

                    window.location = "index.php";

                </script>

                <?php

            }

        }



    }







ob_end_flush();



?>



  <!--Footer-->

    <?php include "include/ft.php"; ?>

  

  <!-- JavaScript Libraries -->

  <?php include "include/js.php"; ?>