<div class="container-fluid">
    <div>
        <h3>E-mail & SMS Setup</h3>
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="#">Home</a>
                </li>
                <li class="breadcrumb-item">
                    <a href="#">Settings</a>
                </li>
                <li class="breadcrumb-item active" aria-current="page">E-mail & SMS Setup</li>
            </ol>
        </nav>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">E-mail Configuration</h6>
                    <form class="email-settings" method="POST">
                        <label for="smtp_or_mail" class="main-label">E-mail Server</label>
                        <select class="form-control show-tick" id="smtp_or_mail" name="smtp_or_mail">
                          <option value="smtp" <?php if($wo['config']['smtp_or_mail'] == 'smtp'){echo 'selected';};?> >SMTP Server</option>
                          <option value="mail" <?php if($wo['config']['smtp_or_mail'] == 'mail'){echo 'selected';};?> >Server Mail (Default)</option>
                        </select>
                        <small class="admin-info">Select which E-mail server you want to use, Server Mail function is not recommended.</small>
                        <div class="clearfix"></div>
                        <hr>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Website Default E-mail</label>
                                <input type="text" id="siteEmail" name="siteEmail" class="form-control" value="<?php echo $wo['config']['siteEmail']; ?>">
                                <small class="admin-info">This is your default website E-mail, this will be used to send E-mails to users.</small>
                            </div>
                        </div>
                        <hr>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">SMTP Host</label>
                                <input type="text" id="smtp_host" name="smtp_host" class="form-control" value="<?php echo $wo['config']['smtp_host'];?>">
                                <small class="admin-info">Your SMTP account host name, can be IP, domain or subdomain.</small>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">SMTP Username</label>
                                <input type="text" id="smtp_username" name="smtp_username" class="form-control" value="<?php echo $wo['config']['smtp_username'];?>">
                                <small class="admin-info">Your SMTP account username.</small>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">SMTP Password</label>
                                <input type="password" id="smtp_password" name="smtp_password" class="form-control" value="<?php echo openssl_decrypt($wo['config']['smtp_password'], "AES-128-ECB", 'mysecretkey1234');?>">
                                <small class="admin-info">Your SMTP account password.</small>
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">SMTP Port</label>
                                <input type="text" id="smtp_port" name="smtp_port" class="form-control" value="<?php echo $wo['config']['smtp_port'];?>">
                                <small class="admin-info">Which port does your SMTP server use? most used 587 for TLS, and 465 for SSL encryption. </small>
                            </div>
                        </div>
                        <label for="smtp_encryption">SMTP Encryption</label>
                        <select class="form-control show-tick" id="smtp_encryption" name="smtp_encryption">
                          <option value="tls" <?php if((strtolower($wo['config']['smtp_encryption']) == 'tls')){echo 'selected';};?> >TLS (Default, Not secured)</option>
                          <option value="ssl" <?php if((strtolower($wo['config']['smtp_encryption']) == 'ssl')){echo 'selected';};?> >SSL (Secure)</option>
                        </select>
                        <small class="admin-info">Which encryption method does your SMTP server use?</small>
                        <div class="clearfix"></div><br>
                        <div class="alert alert-info">
                            After clicking "Test E-mail Server", a test message will be sent to your account's email address.
                        </div>
                        <div class="email-settings-alert"></div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <!-- <button type="submit" class="btn btn-primary m-t-15 waves-effect">Save</button> -->
                        <button type="button" class="btn btn-success m-t-15 waves-effect" onclick="Wo_TestMessage();">Test E-mail Server</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="col-lg-6 col-md-6">
            <div class="card">
                <div class="card-body">
                    <h6 class="card-title">SMS Settings</h6>
                    
                    <form class="sms-settings" method="POST">
                        <div class="alert alert-info">To start sending SMS, you have to create an account and buy credits in <a href="http://www.twilio.com">Twilio</a> <span class="red">OR</span> <a href="http://www.bulksms.com/">BulkSMS</a> <span class="red">OR</span> <a href="https://www.infobip.com/">Infobip</a>.</div><br>

                        <label for="sms_provider" class="main-label">Default SMS Provider</label>
                        <select class="form-control show-tick" id="sms_provider" name="sms_provider">
                          <option value="twilio" <?php if($wo['config']['sms_provider'] == 'twilio'){echo 'selected';};?> >Twilio</option>
                          <option value="bulksms" <?php if($wo['config']['sms_provider'] == 'bulksms'){echo 'selected';};?> >BulkSMS</option>
                          <option value="infobip" <?php if($wo['config']['sms_provider'] == 'infobip'){echo 'selected';};?> >Infobip</option>
                          <option value="msg91" <?php if($wo['config']['sms_provider'] == 'msg91'){echo 'selected';};?> >Msg91</option>
                        </select>
                        <small class="admin-info">Select which SMS provider you want to use, you can use only one at the same time.</small>
                        <div class="clearfix"></div>
                        <hr>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Your Phone Number</label>
                                <input type="text" id="sms_phone_number" name="sms_phone_number" class="form-control" value="<?php echo $wo['config']['sms_phone_number'];?>">
                                <small class="admin-info">Set your website default number, this will be used to send SMS to users, e.g (+9053..)</small>
                            </div>
                        </div>
                        <hr>
                        <label  class="main-label">BulkSMS Configuration</label><br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">BulkSMS Eapi_URL</label>
                                <input type="text" id="eapi" name="eapi" class="form-control" value="<?php echo $wo['config']['eapi'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">BulkSMS Username</label>
                                <input type="text" id="sms_username" name="sms_username" class="form-control" value="<?php echo $wo['config']['sms_username'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">BulkSMS Password</label>
                                <input type="password" id="sms_password" name="sms_password" class="form-control" value="<?php echo $wo['config']['sms_password'];?>">
                            </div>
                        </div>
                       <hr>
                       <label  class="main-label">Twilio Configuration</label><br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Twilio account_sid</label>
                                <input type="text" id="sms_twilio_username" name="sms_twilio_username" class="form-control" value="<?php echo $wo['config']['sms_twilio_username'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Twilio auth_token</label>
                                <input type="text" id="sms_twilio_password" name="sms_twilio_password" class="form-control" value="<?php echo $wo['config']['sms_twilio_password'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Twilio Phone number</label>
                                <input type="text" id="sms_t_phone_number" name="sms_t_phone_number" class="form-control" value="<?php echo $wo['config']['sms_t_phone_number'];?>">
                            </div>
                        </div>
                        <hr>
                        <label  class="main-label">Infobip Configuration</label><br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Infobip Username</label>
                                <input type="text" id="infobip_username" name="infobip_username" class="form-control" value="<?php echo $wo['config']['infobip_username'];?>">
                            </div>
                        </div>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Infobip Password</label>
                                <input type="text" id="infobip_password" name="infobip_password" class="form-control" value="<?php echo $wo['config']['infobip_password'];?>">
                            </div>
                        </div>
                        <hr>
                        <label  class="main-label">Msg91 Configuration</label><br><br>
                        <div class="form-group form-float">
                            <div class="form-line">
                                <label class="form-label">Msg91 AuthKey</label>
                                <input type="text" id="msg91_authKey" name="msg91_authKey" class="form-control" value="<?php echo $wo['config']['msg91_authKey'];?>">
                            </div>
                        </div>
                        
                      
                        <div class="alert alert-info">After clicking "Test SMS Server", a test message will be sent to your phone</div>
                        <input type="hidden" name="hash_id" value="<?php echo Wo_CreateSession();?>">
                        <div class="sms-settings-alert"></div>
                        <!-- <button type="submit" class="btn btn-primary m-t-15 waves-effect">Save</button> -->
                        <button type="button" class="btn btn-success m-t-15 waves-effect" onclick="Wo_TestSMSMessage();">Test SMS Server</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
function Wo_TestMessage() {
    $('form.email-settings').find('.btn-success').text('Please wait..');
    $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s: 'test_message'}, function (data) {
        if (data.status == 200) {
            $('.email-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Message sent!</div>');
            setTimeout(function () {
                $('.email-settings-alert').empty();
            }, 2000);
        } else {
            $('.email-settings-alert').html('<div class="alert alert-danger">Message failed to sent, error: ' + data.error+'</div>');
            setTimeout(function () {
                $('.email-settings-alert').empty();
            }, 2000);
        }
        $('form.email-settings').find('.btn-success').text('Test E-mail Server');
    });
}
function Wo_TestSMSMessage() {
    $('form.sms-settings').find('.btn-success').text('Please wait..');
    $.get(Wo_Ajax_Requests_File(), {f:'admin_setting', s: 'test_sms_message'}, function (data) {
        if (data.status == 200) {
            $('.sms-settings-alert').html('<div class="alert alert-success"><i class="fa fa-check"></i> Message sent!</div>');
            setTimeout(function () {
                $('.sms-settings-alert').empty();
            }, 2000);
        } else {
            $('.sms-settings-alert').html('<div class="alert alert-danger">Message failed to sent, error: ' + data.error+'</div>');
            setTimeout(function () {
                $('.sms-settings-alert').empty();
            }, 2000);
        }
        $('form.sms-settings').find('.btn-success').text('Test SMS Server');
    });
}
$(function() {
    $('.switcher input[type=checkbox]').click(function () {
        setToTrue = 0;
        if ($(this).is(":checked") === true) {
            setToTrue = 1;
        }
        var configName = $(this).attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        objData[configName] = setToTrue;
        objData['hash_id'] = hash_id;
        $.post( Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData);
    });

    var setTimeOutColor = setTimeout(function (){});
    $('select').on('change', function() {
         clearTimeout(setTimeOutColor);
        var thisElement = $(this);
        var configName = thisElement.attr('name');
        var hash_id = $('input[name=hash_id]').val();
        var objData = {};
        objData[configName] = this.value;
        objData['hash_id'] = hash_id;
        thisElement.addClass('warning');
        $.post( Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData, function (data) {
            if (data.status == 200) {
                thisElement.removeClass('warning');
                thisElement.addClass('success');
            } else {
                thisElement.addClass('error');
            }
            var setTimeOutColor = setTimeout(function () {
                thisElement.removeClass('success');
                thisElement.removeClass('warning');
                thisElement.removeClass('error');
            }, 2000);
        });
    });
    $('input[type=text], input[type=number], input[type=password]').on('keyup', delay(function() {
            clearTimeout(setTimeOutColor);
            var thisElement = $(this);
            var configName = thisElement.attr('name');
            var hash_id = $('input[name=hash_id]').val();
            var objData = {};
            objData[configName] = this.value;
            objData['hash_id'] = hash_id;
            thisElement.addClass('warning');
            $.post( Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_general_setting', objData, function (data) {
                if (data.status == 200) {
                    thisElement.removeClass('warning');
                    thisElement.addClass('success');
                } else {
                    thisElement.addClass('error');
                }
                var setTimeOutColor = setTimeout(function () {
                    thisElement.removeClass('success');
                    thisElement.removeClass('warning');
                    thisElement.removeClass('error');
                }, 2000);
                //thisElement.focus();
            });
    }, 500));
});
</script>