<?php
require_once("header.php");
require_once("menu.php");
$_SESSION['error_msg'] ='';

if(isset($_REQUEST['edit']))
{
    $e_id = base64_decode($_REQUEST['edit']);
    $ex = $obj->get_email_setting_id($e_id);
    $row = mysqli_fetch_array($ex);
}


if(isset($_POST['submit']))
{
$row['e_name'] = $_POST['e_name'];
$row['e_email'] = $_POST['e_email'];
$row['e_password'] = $_POST['e_password'];
$row['e_income_host'] = $_POST['e_income_host'];
$row['e_income_port'] = $_POST['e_income_port'];
$row['e_income_protocol'] = $_POST['e_income_protocol'];
$row['e_smtp_host'] = $_POST['e_smtp_host'];
$row['e_smtp_port'] = $_POST['e_smtp_port'];
$row['e_smtp'] = $_POST['e_smtp'];
$row['e_remark'] = $_POST['e_remark'];
  $ex = $obj->email_configuration($row);
  if($ex == 1)
    {
    echo '<script>window.location="email_setting.php"</script>';
  }
   else
    {
     $_SESSION['error_msg'] = "EMAIL SENDING FAILED PLEASE CHECK CONFIGURATION DETAILS....";  
    }
}

?>

<div id="layoutSidenav_content">
<main class="mt-4">
    <div class="container-fluid">
        
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-check-square mr-1"></i>Email Configuration
                <a href="email_setting.php" class="btn btn-primary btn-sm float-right">Back</a>
            </div>
            <div class="card-body">
              <p class="text-danger"><?php echo $_SESSION['error_msg'];?></p>
                <form method="post" name="frm" id="frm" enctype="multipart/form-data">
                   <div class="row row-xs">
                
                  <input type="hidden" name="e_id" value="<?php echo $row['e_id'];?>">
                  
                  

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Name</label>
                    <input type="text" class="form-control" name="e_name"  value="<?php echo $row['e_name'];?>">
                  </div>

                 
                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Email Id</label>
                    <input type="email" class="form-control" name="e_email" required="" value="<?php echo $row['e_email'];?>">
                  </div>

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Password</label>
                    <input type="text" class="form-control" name="e_password" required="" value="<?php echo $row['e_password'];?>">
                  </div>

                  <div class="col-sm-12"><hr/></div>
                   <div class="form-group col-lg-4 col-sm-12">
                    <label>Incoming Host Name</label>
                    <input type="text" class="form-control" name="e_income_host" required="" value="<?php echo $row['e_income_host'];?>">
                  </div>

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Incoming Port</label>
                    <input type="text" class="form-control" name="e_income_port"  value="<?php echo $row['e_income_port'];?>">
                  </div>

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>IMAP/POP3</label>
                    
                    <select class="form-control" name="e_income_protocol">
                      <option value="">Select</option>
                      <option value="imap" <?php echo $row['e_income_protocol']=='imap'?'selected':'';?>>IMAP</option>
                      <option value="pop3" <?php echo $row['e_income_protocol']=='pop3'?'selected':'';?>>POP3</option>
                    </select>
                  </div>
                  
                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Outgoing Host Name</label>
                    <input type="text" class="form-control" name="e_smtp_host" required  value="<?php echo $row['e_smtp_host'];?>">
                  </div>
                  
                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Outgoing Port</label>
                    <input type="text" class="form-control" name="e_smtp_port" required  value="<?php echo $row['e_smtp_port'];?>">
                  </div>

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>SSL/TLS</label>
                    
                    <select class="form-control" name="e_smtp" required>
                      <option value=''>Select</option>
                      <option value="SSL" <?php echo $row['e_smtp']=='SSL'?'selected':'';?>>SSL</option>
                      <option value="TLS" <?php echo $row['e_smtp']=='TLS'?'selected':'';?>>TLS</option>
                    </select>

                  </div>

                  <div class="form-group col-lg-4 col-sm-12">
                    <label>Remark</label>
                    <input type="text" class="form-control" name="e_remark"  value="<?php echo $row['e_remark'];?>">
                  </div>

                  
                  
                
                <div class="col-sm-12"><br/></div>
                <div class="col-md mg-t-10 mg-md-t-0">
                  
                    <?php if(isset($_REQUEST['edit']))
                    { ?> 
                        <button type="submit" class="btn btn-primary" name="submit">Update</button>
                    <?php } 
                    else
                    { ?>
                        <button type="submit" class="btn btn-primary" name="submit">Submit</button>
                    <?php } ?>
                 
                </div><!-- col -->
            </div><!-- row -->
          
          
                  
                </form> 
            </div>
        </div>
    </div>
</main>

<script>
    var url = "email_setting.php";
</script>

<?php require_once("footer.php");?>

