<?php

$cekID = new cekID();
$cekID->cek('mailer', 'id', $id_page);


$clsCrud = new crudData();
$view = $clsCrud->editData('mailer', 'id', $id_page);
$data = $view->fetch(PDO::FETCH_OBJ);


?>
<style>
    .fontInput {
        font-size: 11px;
        font-family: arial;
    }

    .judul {
        font-size: 15px;
        font-family: arial;
    }
</style>

<div class="content-wrapper">

    <?php require('./layout/headerpage.php'); ?>

    <div class="container col-12 mb-4 pb-5">
        <div class="row  mx-3 pr-3">
            <div class="col-12">
                <div class="col-12 ">
                    <div class="card  mx-3">
                        <div class="timeline-header bg-primary py-2 pl-2">
                            <b class="text-light judul"><span class="bi bi-envelope"></span> Pengaturan Email Notifikasi </b>
                        </div>

                        <div class="row col-md-12">
                            <div class="col-md-8">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-6 col-md-12">
                                            <div class="info-box mb-3">


                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-4">
                                                        <input name="judul" value="PENGATURAN EMAIL" style="background-color: gainsboro;" class="form-control-sm col-sm-3 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">

                                                        <form action="" method="post">

                                                            <?php $csrf->token(); ?>
                                                            <input type="text" class="form-control form-control-sm" value="<?php echo $data->id; ?>" name="id" hidden />



                                                            <div class="row">
                                                                <label class="col-sm-12 col-form-label text-primary mt-3">Pengaturan Email Pengirim <i class="small"></i> </label>

                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">Alamat Email</label>
                                                                <div class="col-md-9">
                                                                    <input type="text" class="form-control form-control-sm" style="font-family:arial;font-size:12px" value="<?php echo $data->email; ?>" placeholder="Alamat Email" name="email">
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">Password Email</label>
                                                                <div class="col-md-9">
                                                                    <input type="password" class="form-control form-control-sm" style="font-family:arial;font-size:12px" value="<?php echo $data->password; ?>" placeholder="Password Email" name="passwordemail">
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">SMTP Server</label>
                                                                <div class="col-md-9">
                                                                    <input type="text" class="form-control form-control-sm" style="font-family:arial;font-size:12px" value="<?php echo $data->server; ?>" placeholder="SMTP Server" name="serversmtp">
                                                                </div>
                                                            </div>
                                                            <div class="row">
                                                                <label class="col-sm-3 col-form-label">Port</label>
                                                                <div class="col-md-9">
                                                                    <input type="text" class="form-control form-control-sm" style="font-family:arial;font-size:12px" value="<?php echo $data->port; ?>" placeholder="Port SMTP Server" name="port">
                                                                </div>
                                                            </div>


                                                            <div class='row '>
                                                                <div class="col-12 my-3">
                                                                    <div class="row float-left">
                                                                        <div class="col-auto">
                                                                            <div class="custom-control custom-switch custom-switch-off-danger custom-switch-on-success">
                                                                                <input type="checkbox" class="custom-control-input" name="aktif" id="customSwitch3" value="1" <?php if ($data->aktif == 1) {
                                                                                                                                                                                    echo "checked";
                                                                                                                                                                                } else {
                                                                                                                                                                                    echo "";
                                                                                                                                                                                }; ?> />
                                                                                <label class="custom-control-label" for="customSwitch3"><?php if ($data->aktif == 1) {
                                                                                                                                            echo "<span class='text-success'>Email Notifikasi Aktif</span>";
                                                                                                                                        } else {
                                                                                                                                            echo "<span class='text-danger'>Email Notifikasi Tidak Aktif</span>";
                                                                                                                                        }; ?></label>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                </div>

                                                                <div class="col-12 py-0 mb-4">
                                                                    <div class="row float-left">
                                                                        <div class="col-auto">
                                                                            <button type="submit" class="btn btn-primary btn-xs mx-1 px-2 mt-1" name="submit"><i class="bi-save"></i> SIMPAN </button>
                                                                        </div>

                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </form>


                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="card-body mt-4 px-1 mx-2">

                                    <div class="row">
                                        <div class="col-12 col-sm-6 col-md-12">
                                            <div class="info-box mb-3">


                                                <div class="info-box-content">
                                                    <div class="relative mb-0 pb-3">
                                                        <input name="judul" value="INFO SETING GMAIL" style="background-color: gainsboro;" class="form-control-sm col-sm-6 fontInput small bg-default mt-3 text-center" disabled>
                                                    </div>

                                                    <div class="col-sm-12 invoice-col pt-0">

                                                        <p>Untuk mengaktifkan Fitur Email, perlu memiliki email (gmail) dan melakukan pengaturan untuk diatur di pengaturan Email :</p>

                                                        <ul>
                                                            <li>Aktifkan Verifikasi 2 Langkah</li>
                                                            <li>Buat Sandi Aplikasi (16 Digit).</li>

                                                        </ul>



                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>



                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php

$clsMailer = new mailer();
if (isset($_POST['submit'])) {
    $csrf = $csrf->cekToken();
    $clsMailer->saveShort();
} else {
    echo '';
}
