<?php
  include_once 'header.php';
  $obj=new Database();
  $obj->select('email_config','*',null,'id=1',null,null);
  $result=$obj->getResult();                              
  foreach($result as list("host_name"=>$h_name,"email_id"=>$email,"password"=>$pass,"port_no"=>$port_no,"header"=>$header))
  {

?>

<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">Email Setup</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">
                     Configuration
                    </li>
                  </ol>
                </nav>
              </div>
            </div>
          </div>
        </div>
        <!-- ============================================================== -->
        <!-- End Bread crumb and right sidebar toggle -->
        <!-- Container fluid  -->
        <!-- ============================================================== -->

          <div class="container-fluid row">
            <div class="col-md-12">
              <div class="card">
                <form class="form-horizontal" id="form">
                  <div class="card-body">
                    <h4 class="card-title"></h4>
                    <div class="form-group row">
                      <label for="h_name" class="col-sm-3 text-end control-label col-form-label">
                        Host Name</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" value="<?php if(isset($h_name)){echo $h_name;}?>" id="h_name"/>
                      </div>
                    </div>
           
                    <div class="form-group row">
                      <label for="email"
                        class="col-sm-3 text-end control-label col-form-label">Email Id</label>
                      <div class="col-sm-9">
                        <input
                          type="text" class="form-control" id="email"
                          value="<?php if(isset($email)){echo $email;}?>"
                        />
                      </div>
                    </div>
                    <div class="form-group row">
                      <label
                        for="password"
                        class="col-sm-3 text-end control-label col-form-label">Password</label>
                      <div class="col-sm-9">
                        <input type="password" class="form-control" id="password"
                        value="<?php if(isset($pass)){echo $pass;}?>"/>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="port_no" class="col-sm-3 text-end control-label col-form-label"
                        >Port No</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control"
                          id="port_no" value="<?php if(isset($port_no)){echo $port_no;}?>"/>
                      </div>
                    </div>
               
                    <div class="form-group row">
                      <label for="header" class="col-sm-3 text-end control-label col-form-label">
                        Header Name</label>
                      <div class="col-sm-9">
                        <input type="text" class="form-control" id="header" value="<?php if(isset($header)){echo $header;}?>"/>
                      </div>
                    </div>
                  <div class="border-top">
                    <div class="card-body">
                      <button type="button" id="insert_data" class="btn btn-primary">
                        Save Configuration
                      </button>
                    </div>
                  </div>
                </form>
              </div>

</div>

<?php
}
?>
</div></div>
       <footer class="footer text-center">
          All Rights Reserved by ECI. Designed and Developed by
          <a href="https://www.ntlogix.in">NTLogix</a>.
        </footer>
   <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="../assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="../assets/libs/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="../assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="../assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="../dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="../dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="../dist/js/custom.min.js"></script>
    <!-- this page js -->
    <script src="../assets/extra-libs/multicheck/datatable-checkbox-init.js"></script>
    <script src="../assets/extra-libs/multicheck/jquery.multicheck.js"></script>
    <script src="../assets/extra-libs/DataTables/datatables.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script>
        var msg;
        var icon;
        function showAlert(msg,icon) {
            Swal.fire({
                title: msg,
                icon: icon,
                confirmButtonText: 'Close'
            });
        }
        $(document).ready(function(){
              $('#insert_data').click(function(){
                    var h_name = $("#h_name").val();
                    var email = $("#email").val();             
                    var password= $("#password").val();
                    var port_no = $("#port_no").val();
                    var header = $("#header").val();
                    if((h_name.length===0)||(email===0)||(password.length===0)||(port_no.length===0)||(header.length===0))
                    {
                      showAlert('some field is empty!','warning');
                      return 0;
                    } 
                    $.ajax({
                        url:"core/configure.php",
                        method:"post",
                        data: {
                            state:'mail',
                            h_name:h_name,
                            email:email,
                            password:password,
                            port_no:port_no,
                            header:header,                     
                        },
                        success: function(data){                         
                           if(data==1)
                           {
                                showAlert('Email Setup Updated!','success');                       
                           }
                        }
                    });
                });
          });

</script>
       

   
  </body>
</html>