<?php

$pageName  = "Settings";
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/header.php");

// Ofofonobs Developer WhatsAPP +2348114313795


// Bank Script Developer - Use For Educational Purpose Only

// Other scripts Available
// include($_SERVER['DOCUMENT_ROOT']."/admin/include/adminFunction.php");
//require_once("./include/adminloginFunction.php");


if (isset($_POST['upload_picture'])) {
    if (isset($_FILES['image'])) {
        $file = $_FILES['image'];
        $name = $file['name'];

        $path = pathinfo($name, PATHINFO_EXTENSION);

        $allowed = array('jpg', 'png', 'jpeg', 'svg');

        $folder = "assets/images/logo/";
        $n = $name;

        $destination = $folder . $n;
    }
    if (move_uploaded_file($file['tmp_name'], $destination)) {
        $sql = "UPDATE settings SET image=:image WHERE id ='1'";
        $stmt = $conn->prepare($sql);

        $stmt->execute([
            'image' => $n,
        ]);

        if (true) {
            toast_alert("success", "Your Image Uploaded Successfully", "Thanks!");
        } else {
            echo "invalid";
        }
    }
}

if (isset($_POST['save_settings'])) {
    $url_name = $_POST['url_name'];
    $url_tel = $_POST['url_tel'];
    $url_email = $_POST['url_email'];
    $url_address = $_POST['url_address'];
    $padiwise_sms = $_POST['padiwise_sms'];
    $currency = $_POST['currency'];
    $id = "1";

    $sql = "UPDATE settings SET url_name=:url_name,url_tel=:url_tel,url_email=:url_email,url_address=:url_address,padiwise_sms=:padiwise_sms,currency=:currency WHERE id=:id";
    $stmt = $conn->prepare($sql);
    $stmt->execute([
        'url_name' => $url_name,
        'url_tel' => $url_tel,
        'url_email' => $url_email,
        'url_address' => $url_address,
        'padiwise_sms' => $padiwise_sms,
        'currency' => $currency,
        'id' => $id
    ]);

    if (true) {

        $msg1 = "
       <div class='alert alert-warning'>
       
       <script type='text/javascript'>
            
               function Redirect() {
               window.location='./dashboard.php';
               }
               document.write ('');
               setTimeout('Redirect()', 4000);
            
               </script>
               
       <center><img src='../assets/images/loading.gif' width='180px'  /></center>
       
       
       <center>	<strong style='color:black;'>Updated successfully, Please Wait while we redirect you...
              </strong></center>
         </div>
       ";


        //  toast_alert('success','Settings updated successfully','Approved');
    } else {
        toast_alert('error', 'Sorry something went wrong');
    }
}


function PadiwiseCode($page)
{
    if ($page['padiwise_sms'] == '1') {
        return 'Activated';
    }

    if ($page['padiwise_sms'] == '0') {
        return 'Disactivated';
    }
}

$PadiwiseCode = PadiwiseCode($page);



?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            System Settings
        </h1>
        <ol class="breadcrumb">
            <li><a href="./dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        </ol>
    </section>



    <!-- Main content -->
    <section class="content">

        <!-- SELECT2 EXAMPLE -->
        <div class="box box-default">
            <form method="POST" enctype="multipart/form-data">
                <div class="box-header with-border">
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">

                        <?php if (isset($msg1)) echo $msg1; ?>

                        <div class="col-md-6">
                            <div class="form-group">
                                <label>Company Name</label>
                                <input type="text" class="form-control" name="url_name" value="<?= $page['url_name'] ?>" placeholder="Company Name">
                            </div>
                            <!-- /.form-group -->
                            <div class="form-group">
                                <label>Company Address</label>
                                <input type="text" class="form-control" name="cardfee" value="<?= $page['url_address'] ?>" placeholder="Company Address">
                            </div>
                            
                            
                            <div class="form-group">
                                <label>Padiwise Config Option:  <span style="color: red;"><?= $PadiwiseCode ?></span> </label>
                                <select class="form-control select2" name="padiwise_sms" style="width: 100%;">
                                    <option >Select Option</option>
                                    <option value="1">On</option>
                                    <option value="0">Off</option>
                                </select>
                            </div>

                            

                            <!-- /.form-group -->
                        </div>
                        <!-- /.col -->
                        <div class="col-md-6">
                            <div class="form-group">
                                <label>System Email</label>
                                <input type="email" class="form-control" name="url_email" value="<?= $page['url_email'] ?>" placeholder="<?= $page['url_email'] ?> ">
                            </div>
                            <div class="form-group">
                                <label>System Phone</label>
                                <input type="text" class="form-control" name="url_tel" value="<?= $page['url_tel'] ?>" placeholder="<?= $page['url_tel'] ?>">
                            </div>

                            <div class="form-group">
                                <label>System Currency</label>
                                <input type="text" class="form-control" name="currency" value="<?= $page['currency'] ?>" placeholder="System Currency">
                            </div>

                           

                            


                        </div>
                        <!-- /.col -->
                    </div>
                    <!-- /.row -->
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="submit" name="save_settings" class="btn btn-primary">Save Settings</button>
                </div>
            </form>
        </div>


        <!-- /.box -->

        <div>
            Logo Image
        </div>
        <form method="POST" id="general-info" enctype="multipart/form-data">
            <div class="form-group">
                <input type="file" id="input-file-max-fs" class="form-control" name="image" data-max-file-size="2M" />
            </div>
            <div class="box-footer">
                <button type="submit" name="upload_picture" class="btn btn-primary">Change Image</button>
            </div>
        </form>
        <br><br>
        <!-- /.box -->



    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->



<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/footer.php");

?>