<!DOCTYPE html>
<html>
<head>
<!--    header content-->
 <?php 
   include "dbconfig.php";
   include('header.php');
    include ("head.php");
   include ("user_sidebar.php");
   include "footer.php";
?>
   
  


<!-- End   header content-->

</head>
<body>
   
      <section id="main-content">
        <section class="wrapper">
           
        <!-- page start-->

       <div class="container-fluid">
                         <!-- Content Section -->
                     <div class="container">
                        <div class="row">
                              <!-- Content Section -->
                                  <div class="container">
                                  <div class="row">
                                  <div class="col-md-12">
                                  <h2>List of Doctors:</h2>
                                  <div class="pull-right">
                                  <button class="btn btn-success" data-toggle="modal" data-target="#add_new_record_modal">Add New Record</button>
                                  </div>
                                  </div>
                                  </div>
                                  <div class="row">
                                  <div class="col-md-12">
                                  <h4>Records:</h4>
                                  <div class="records_content"></div>
                                  </div>
                                  </div>
                                  </div>

                           
                        </div>
                     </div>
                     <!-- To Add New Record -->
                    
                              <div class="modal fade" id="add_new_record_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                              <div class="modal-dialog" role="document">
                              <div class="modal-content">
                              <div class="modal-header">
                              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                              <h4 class="modal-title" id="myModalLabel">Add New Doctor</h4>
                              </div>
                              <div class="modal-body">
                               
                              <div class="form-group">
                              <label for="first_name">First Name</label>
                              <input type="text" id="first_name" placeholder="First Name" class="form-control" />
                              </div>
                               
                              <div class="form-group">
                              <label for="last_name">Last Name</label>
                              <input type="text" id="last_name" placeholder="Last Name" class="form-control" />
                              </div>
                               
                              <div class="form-group">
                              <label for="email">Place</label>
                              <input type="text" id="email" placeholder="Place Address" class="form-control" />
                              </div>
                               
                              </div>
                              <div class="modal-footer">
                              <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                              <button type="button" class="btn btn-primary" onclick="addRecord()">Add Record</button>
                              </div>
                              </div>
                              </div>
                              </div>
                     
                     <!-- Modal - Update User details -->
                                    <div class="modal fade" id="update_user_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                        <div class="modal-dialog" role="document">
                                                    <div class="modal-content">
                                                <div class="modal-header">
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                                    <h4 class="modal-title" id="myModalLabel">Update</h4>
                                                </div>
                                                <div class="modal-body">
                                     
                                                    <div class="form-group">
                                                        <label for="update_first_name">First Name</label>
                                                        <input type="text" id="update_first_name" placeholder="First Name" class="form-control"/>
                                                    </div>
                                     
                                                    <div class="form-group">
                                                        <label for="update_last_name">Last Name</label>
                                                        <input type="text" id="update_last_name" placeholder="Last Name" class="form-control"/>
                                                    </div>
                                     
                                                    <div class="form-group">
                                                        <label for="update_email">Place</label>
                                                        <input type="text" id="update_email" placeholder="Place Address" class="form-control"/>
                                                    </div>
                                     
                                                </div>
                                                <div class="modal-footer">
                                                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                                                    <button type="button" class="btn btn-primary" onclick="UpdateUserDetails()" >Save Changes</button>
                                                    <input type="hidden" id="hidden_user_id">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

           </div>
      </section>
   </section>
   <script type="text/javascript">
      $(document).ready(function() {
         //alert();
         // READ recods on page load
         readRecords(); // calling function
      });

      function addRecord() {
    // get values
    var first_name = $("#first_name").val();
    var last_name = $("#last_name").val();
    var email = $("#email").val();
 
    // Add record
    $.post("doc_CRUD/addRecord.php", {
        first_name: first_name,
        last_name: last_name,
        email: email
    }, function (data, status) {
        // close the popup
        $("#add_new_record_modal").modal("hide");
 
        // read records again
        readRecords();
 
        // clear fields from the popup
        $("#first_name").val("");
        $("#last_name").val("");
        $("#email").val("");
    });
}
 
// READ records
function readRecords() {
    $.get("doc_CRUD/readRecord.php", {}, function (data, status) {
        $(".records_content").html(data);
    });
}
   // functon to get the details of selected record

      function GetUserDetails(id) {
    // Add User ID to the hidden field for furture usage
    $("#hidden_user_id").val(id);
    $.post("doc_CRUD/readUserDetails.php", {
            id: id
        },
        function (data, status) {
            // PARSE json data
            var user = JSON.parse(data);
            // Assing existing values to the modal popup fields
            $("#update_first_name").val(user.first_name);
            $("#update_last_name").val(user.last_name);
            $("#update_email").val(user.email);
        }
    );
    // Open modal popup
    $("#update_user_modal").modal("show");
}
   //Now Update this address

  
function UpdateUserDetails() {
    // get values
    var first_name = $("#update_first_name").val();
    var last_name = $("#update_last_name").val();
    var email = $("#update_email").val();
 
    // get hidden field value
    var id = $("#hidden_user_id").val();
 
    // Update the details by requesting to the server using ajax
    $.post("doc_CRUD/updateUserDetails.php", {
            id: id,
            first_name: first_name,
            last_name: last_name,
            email: email
        },
        function (data, status) {
            // hide modal popup
            $("#update_user_modal").modal("hide");
            // reload Users by using readRecords();
            readRecords();
        }
    );
}

   //Delete the record

     function DeleteUser(id) {
    var conf = confirm("Are you sure, do you really want to delete User?");
    if (conf == true) {
        $.post("doc_CRUD/deleteRecord.php", {
                id: id
            },
            function (data, status) {
                // reload Users by using readRecords();
                readRecords();
            }
        );
    }
}




   </script>
   
   
   
   
</body>
</html>

