<?php
include_once 'header.php';
?>
<div class="page-wrapper">
        <!-- ============================================================== -->
        <!-- Bread crumb and right sidebar toggle -->
        <!-- ============================================================== -->
        <div class="page-breadcrumb">
          <div class="row">
            <div class="col-12 d-flex no-block align-items-center">
              <h4 class="page-title">New Registration</h4>
              <div class="ms-auto text-end">
                <nav aria-label="breadcrumb">
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="#">Dashboard</a></li>
                    <li class="breadcrumb-item active" aria-current="page">
                     Student
                    </li>
                  </ol>
                </nav>
              </div>
            </div>
          </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->
   
 <!-- Container fluid  -->
        <!-- ============================================================== -->
        <div class="container-fluid">
          <!-- ============================================================== -->
          <!-- Start Page Content -->
          <!-- ============================================================== -->
          <div class="row">
            <div class="col-md-12">
              <div class="card">
                <form class="form-horizontal" id="form">
                  <div class="card-body">
                    <h4 class="card-title">Personal Info</h4>
                    <div class="form-group row">
                      <label for="name" class="col-sm-3 text-end control-label col-form-label">
                        Student Name *</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="name" placeholder="Student Name Here"/>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="fname" class="col-sm-3 text-end control-label col-form-label">
                        Father Name *</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="fname" placeholder="Father Name Here"/>
                      </div>
                    </div>
                    <div class="form-group row">
                    <label class="col-sm-3 text-end control-label col-form-label">Gender *</label>
                    <div class="col-md-9" id="gender">
                      <div class="form-check">
                        <input type="radio" class="form-check-input" id="g1"
                          name="radio-stacked" value="Male" required/>
                        <label class="form-check-label mb-0" for="g1"
                          >Male</label
                        >
                      </div>
                      <div class="form-check">
                        <input type="radio" class="form-check-input" id="g2"
                          name="radio-stacked" value="Female" required/>
                        <label class="form-check-label mb-0" for="g2"
                          >Female</label>
                      </div>                
                    </div>
                  </div>
                  
                  <div class="form-group row">
                      <label for="dob" class="col-sm-3 text-end control-label col-form-label">
                        Date of Birth *</label>
                      <div class="col-sm-9">
                      <input type="date" class="form-control date-inputmask" id="dob"
                      placeholder="Enter Date of Birth"/>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="mobile"
                        class="col-sm-3 text-end control-label col-form-label">Mobile No *</label>
                      <div class="col-sm-9">
                        <input
                          type="text" class="form-control" id="mobile"
                          placeholder="Student Contact No"
                        />
                      </div>
                    </div>
                    <div class="form-group row">
                      <label
                        for="o_mobile"
                        class="col-sm-3 text-end control-label col-form-label">Parents Mob No</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="o_mobile"
                          placeholder="Parents Mob No Here"/>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="email" class="col-sm-3 text-end control-label col-form-label"
                        >Email *</label>
                      <div class="col-sm-9">
                        <input type="email" class="form-control"
                          id="email" placeholder="Email Here"/>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label
                        for="address"
                        class="col-sm-3 text-end control-label col-form-label"
                        >Address *</label>
                      <div class="col-sm-9">
                        <textarea class="form-control" id="address"></textarea>
                      </div>
                    </div>
                  </div>
                  <div class="border-top">
                    <div class="card-body">
                      <button type="button" id="insert_data" class="btn btn-primary">
                        Save Student
                      </button>
                    </div>
                  </div>
                </form>
              </div>
</div>

<script>
              $('#insert_data').click(function(){
                    var name = $("#name").val();
                    var fname = $("#fname").val();
                    var dob = $("#dob").val();
                    if (document.getElementById('g1').checked) 
                    {
                        var gender = document.getElementById('g1').value;
                    }else
                    {
                        gender=document.getElementById('g2').value;
                    }                    
                    var mobile= $("#mobile").val();
                    var o_mobile = $("#o_mobile").val();
                    var email = $("#email").val();
                    var address = $("#address").val();
                    if((name.length===0)||(fname.length===0)||(mobile.length===0)||(email.length===0)||(address.length===0))
                    {
                     
                      showAlert('some field is empty!','warning');
                      return 0;
                    }  
                    $.ajax({
                        url:"core/registration.php",
                        method:"post",
                        data: {
                            name:name,
                            fname:fname,
                            mobile:mobile,
                            dob:dob,
                            gender:gender,
                            o_mobile:o_mobile,
                            email:email,
                            address:address,                          
                        },
                        success: function(data){
                         
                           if(data==1)
                           {
                            showAlert('Student Record Successfully Submited','success');
                            setTimeout(function(){window.location='./students.php';}, 2000); 
                           }
                        }
                    });
                });

</script>
<?php
include_once 'footer.php';
?>