<?php
require_once("../layouts/members/head.php");
?>

<?php if(in_array($user_data['usertype'], ['Admin','White Label'])){ ?>

<?php
if(isset($_POST['smsapiupdate']) && $user_data['user_id']>0){
$url = is_valid_url($_POST['url']);
if(!empty($url)){
$smsapi = json_encode(["url"=>$url]);
$insData = array();
$insData['smsapi'] = $smsapi;
if(db_update("sitedata", $insData, " user_id='".$user_data['user_id']."' ")){
awal_alert_msg("Api Updated Successfully!",'success','');  
}else{
awal_alert_msg("No Any Changes!",'info');
}

}else{
awal_alert_msg("Please Enter Valid URL!",'error');
}

}
?>


<?php
if(isset($_POST['smtpupdate']) && $user_data['user_id']>0){

$username = strip_tags($_POST['username']);
$password = strip_tags($_POST['password']);
$sender = strip_tags($_POST['sender']);
$host = strip_tags($_POST['host']);
$port = strip_tags($_POST['port']);
$protocol = strip_tags($_POST['protocol']);

if(!empty($username)
&& !empty($password) 
&& !empty($sender) 
&& !empty($host) 
&& !empty($port) 
&& !empty($protocol) 
){

$smtp = json_encode([
  "username"=>$username,
  "password"=>$password,
  "sender"=>$sender,
  "host"=>$host,
  "port"=>$port,
  "protocol"=>$protocol
]);

$insData = array();
$insData['smtp'] = $smtp;
if(db_update("sitedata", $insData, " user_id='".$user_data['user_id']."' ")){
awal_alert_msg("SMTP Updated Successfully!",'success','');  
}else{
awal_alert_msg("No Any Changes!",'info');
}

}else{
awal_alert_msg("Please Fill All Valid Details!",'error');
}

}
?>

<div class="row">
  <div class="col-md-12 mb-2">
    <div class="card text-danger">
      <div class="card-header bg-primary text-white py-2">
        <div class="d-flex align-items-center">
          <span class="mr-auto">SMS API</span>
        </div>
      </div>
      <div class="p-3">
      <form class="row text-dark" method="POST" action="">
        <div class="col-md-12 mb-3">
          <label>Dynamic SMS API - {NUMBER} | {MSG}</label>
          <input type="url" class="form-control" placeholder="https://sms.liveone.tech/send-message?api_key=123456&sender=9195*******&number=91{NUMBER}&message={MSG}" name="url" value="<?=smsapi("url")?>" required>
        </div> 
        <div class="col-md-4 mb-3">
          <button type="submit" class="btn btn-primary btn-block" name="smsapiupdate">Submit</button>
        </div>
      </form>
     </div>
    </div>
  </div>

  <div class="col-md-12 mb-2">
    <div class="card text-danger">
      <div class="card-header bg-primary text-white py-2">
        <div class="d-flex align-items-center">
          <span class="mr-auto">SMTP</span>
        </div>
      </div>
      <div class="p-3">
      <form class="row text-dark" method="POST" action="">
        <div class="col-md-4 mb-3">
          <label>Username</label>
          <input type="email" class="form-control" placeholder="Enter Username" name="username" value="<?=smtp("username")?>" required>
        </div> 
        <div class="col-md-4 mb-3">
          <label>Password</label>
          <input type="text" class="form-control" placeholder="Enter Password" name="password" value="<?=smtp("password")?>" required>
        </div>
        <div class="col-md-4 mb-3">
          <label>Sender</label>
          <input type="text" class="form-control" placeholder="Enter Sender" name="sender" value="<?=smtp("sender")?>" required>
        </div> 
        <div class="col-md-4 mb-3">
          <label>Host</label>
          <input type="text" class="form-control" placeholder="Enter Host" name="host" value="<?=smtp("host")?>" required>
        </div>
        <div class="col-md-4 mb-3">
          <label>Port</label>
          <input type="number" class="form-control" placeholder="Enter Port" name="port" value="<?=smtp("port")?>" required>
        </div>
        <div class="col-md-4 mb-3">
          <label>Protocol</label>
              <select name="protocol" class="form-control">
                <option <?=smtp("protocol")=="tls" ? 'selected':''?> value="tls">TLS</option>
                <option <?=smtp("protocol")=="ssl" ? 'selected':''?> value="ssl">SSL</option>
              </select>
        </div>
        <div class="col-md-4 mb-3">
          <button type="submit" class="btn btn-primary btn-block" name="smtpupdate">Submit</button>
        </div>
      </form>
     </div>
    </div>
  </div>

</div>
<?php 
}else{
require_once("404.php");
} 
?>

<?php
require_once("../layouts/members/foot.php");
summernote('#noticealert');
?>