<?php
session_start();
require '../config.php';
if(isset($_POST['tombol'])){
    $send_to = opt_get('ZW1haWwtYWRtaW4=');
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $desc = $_POST['desc'];
    $nama = $_POST['name'];
    $tipe = $_POST['type'];
    if(!$tipe || !$email || !$phone || !$nama){
        $_SESSION['alert'] = ['danger','Failed!','Masih Ada Form Yang Kosong'];
        exit(header('location: /page/contact_us'));
    }else{
        require '../lynchstore/lib/PHPMailer/PHPMailerAutoload.php';
        $mail = new PHPMailer;
        $mail->Host = opt_get('c210cF9ob3N0');
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Username = opt_get('c210cF91c2VybmFtZQ==');
        $mail->Password = opt_get('c210cF9wYXNzd29yZA==');
        $mail->SMTPSecure = 'ssl';
        $mail->Port = opt_get('c210cF9wb3J0');
        $mail->setFrom(opt_get('c210cF91c2VybmFtZQ=='), opt_get('c210cF9uYW1l'));
        $mail->addAddress($send_to);
        $mail->Subject = $tipe;
        $mail->isHTML(true);
        $email_img = base_url().opt_get('aWNvbi13ZWI=');
        $email_font = "'Poppins'";
        $mailContent = '<body style="margin: 0;padding: 0;background: #f8fafa;">
            <style>
                @import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;1,100;1,200;1,300;1,400;1,500;1,600&display=swap");
            </style>
            <div style="font-family: '.$email_font.', sans-serif;margin: 50px auto;background: #fff;max-width: 550px;padding: 20px;border: 1px solid #f1f1f1;border-radius: 4px;font-size: 14px;color: #606060;">
                <div style="text-align: center;margin-bottom: 20px;margin-top: 20px;">
                    <img src="'.$email_img.'" width="90" style="border-radius:50%;">
                </div>
                <h2 style="font-weight: 500;">'.$tipe.'</h2>
                <table style="width: 100%;">
                    <tr>
                        <th style="font-weight: 400;text-align: left;padding-right: 25px;">Name :</th>
                        <td style="font-weight: 600;">'.$nama.'</td>
                    </tr>
                    <tr>
                        <th style="font-weight: 400;text-align: left;padding-right: 25px;">Phone :</th>
                        <td style="font-weight: 600;"><a href="https://wa.me/'.$phone.'">'.$phone.'</td>
                    </tr>
                    <tr>
                        <th style="font-weight: 400;text-align: left;padding-right: 25px;">Email :</th>
                        <td style="font-weight: 600;">'.$email.'</td>
                    </tr>
                </table>
                <hr>
                <div clas="mb-2>
                    <p style="margin: 0;">Description: '.$desc.'</p>
                </div>
                <hr>
                <div style="text-align: center;padding: 15px;background: #bf3931;">
                    <p style="margin: 0;color: #fff;">Ini adalah email otomatis, mohon untuk tidak membalas email ini. Jika kamu tidak ingin menerima email ini dari '.config('web','title_web').'.</p>
                </div>
            </div>
        </body>';
                        
        $mail->Body = $mailContent;
        if(!$mail->send()){
            $_SESSION['alert'] = ['danger','Failed', 'Mailer Error: '.$mail->ErrorInfo];
            exit(header('location: /page/contact_us'));
        }else{
            $_SESSION['alert'] = ['success','Success', 'Laporan Berhasil Dikirim'];
            exit(header('location: /page/contact_us'));
        }
    }
}
require '../layouts/header.php';
?>
        <div class="row">
            <div class="col-lg-6 mx-auto mt-5 mb-5">
                <div class="card bg-dark shadow">
                    <div class="card-header">
                        <h4 class="card-title">CV. <?= config('web','title');?></h4>
                    </div>
                    <div class="card-body">
                        <form action="" id="frmContact" method="POST">
                            <table>
                                <tbody>
                                    <tr>
                                        <td valign="top">Alamat</td>
                                        <td valign="top">: </td>
                                        <td style="padding-left:5px"><?= opt_get('YWxhbWF0LWFkbWlu');?></td>
                                    </tr>
                                    <tr>
                                        <td>Nomor Whatsapp</td>
                                        <td valign="top">: </td>
                                        <td style="padding-left:5px"><?= opt_get('d2EtYWRtaW4=');?></td>
                                    </tr>
                                    <tr>
                                        <td>Email </td>
                                        <td valign="top">: </td>
                                        <td style="padding-left:5px"><?= opt_get('ZW1haWwtYWRtaW4=');?></td>
                                    </tr>
                                </tbody>
                            </table>
                            <br>
                        <div class="row mb-2">
                            <div class="col-md-6">
                                <label for="type">Tipe</label>
                                <select name="type" id="type" class="form-select">
                                    <option value="Masalah Order">Masalah Order</option>
                                    <option value="Order via Api">Order via API</option>
                                    <option value="Keluhan Pelanggan">Keluhan Pelanggan</option>
                                    <option value="Ingin buat web seperti ini?">Ingin buat web seperti ini?</option>
                                </select>
                            </div>
                            <div class="col-md-6">
                                <label for="username">Nama :</label>
                                <input type="text" name="name" placeholder="Nama/Username" id="name" class="form-control" autocomplete="off">
                            </div>
                        </div>
                        <div class="row mb-2">
                            <div class="col-md-6">
                                <label for="email">Email :</label>
                                <input type="text" name="email" placeholder="cs@zurcypedia.com" id="email" class="form-control" autocomplete="off">
                            </div>
                            <div class="col-md-6">
                                <label for="phone">No WhatsApp :</label>
                                <input type="number" name="phone" placeholder="6285xxxx" id="phone" class="form-control" required>
                            </div>
                        </div>
                        <div class="row mb-2">
                            <div class="col">
                                <label for="description">Deskripsi</label>
                                <textarea name="desc" id="desc" cols="30" rows="5" class="form-control" autocomplete="off" placeholder="Silahkan tulis pesan Anda secara detail"></textarea>
                            </div>
                        </div>
                        <div class="row mt-3">
                            <div class="col-lg-12 clearfix">
                                <div class="row">
                                    <div class="col">
                                        <button class="btn btn-primary w-100 btn-lg" name="tombol">Kirim Pesan <i class="fas fa-paper-plane"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
<?php require '../layouts/footer.php';?>
<script type="text/javascript">
    $(document).ready(function(){
        $('#phone').on('input', function() {
                if (this.value.startsWith('08')) {
                    this.value = "628";
                }
                this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');
            });
    });
    </script>