<?php
ob_start();
include('../include/db_conx.php');
isset($_SESSION['admin_login']);
if (!isset($_SESSION['admin_login'])) {
    header("location: auth-login.php");
    exit();
} else {
    include('../include/admin_head.php');

    include('../include/admin_action/info.php');

    $DepositStatus = $_GET['DepositStatus'];
    if ($DepositStatus == 'true') {
        $msg = 'Deposit Successfully';
        $link = 'client_deposit.php?userID=' . $user_id;
        swal_success($msg, $link);
    }
?>



    <body>

        <!-- <body data-layout="horizontal"> -->

        <!-- Begin page -->
        <div id="layout-wrapper">

            <?php include('../include/admin_header.php'); ?>

            <!-- ========== Left Sidebar Start ========== -->

            <!-- Left Sidebar End -->
            <?php include('../include/admin_sidebar.php'); ?>



            <!-- ============================================================== -->
            <!-- Start right Content here -->
            <!-- ============================================================== -->
            <div class="main-content">

                <div class="page-content">
                    <div class="container-fluid">

                        <!-- start page title -->
                        <div class="row">
                            <div class="col-12">
                                <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                                    <h4 class="mb-sm-0 font-size-18">Deposit </h4>

                                    <div class="page-title-right">
                                        <ol class="breadcrumb m-0">
                                            <li class="breadcrumb-item"><a href="javascript: void(0);">Clients</a></li>
                                            <li class="breadcrumb-item active">Clients Deposit</li>
                                        </ol>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end page title -->



                        <div class="row">
                            <div class="col-lg-12">
                                <div class="card">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-sm order-2 order-sm-1">
                                                <div class="d-flex align-items-start mt-3 mt-sm-0">


                                                    <div class="flex-grow-1">
                                                        <div>
                                                            <h5 class="font-size-16 mb-1"><?php echo $first_name . ' ' . $last_name ?></h5>
                                                            <p class="text-muted font-size-13">Billing Name</p>


                                                            <div class="d-flex flex-wrap align-items-start gap-2 gap-lg-3 text-muted font-size-13">
                                                                <div> <i class="fas fa-envelope "></i> <?php echo $email ?></div>
                                                                <div><i class=" fas fa-key "></i> Password: <?php echo $password ?></div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-sm-auto order-1 order-sm-2">
                                                <div class="d-flex align-items-start justify-content-end gap-2">
                                                    <a href='client_dashboard.php?userID=<?php echo $user_id ?>'>
                                                        <button type="button" class="btn btn-primary"><i class="me-1"></i> <i class="fas fa-chevron-left "></i> Return to details </button>
                                                    </a>

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

                                        <ul class="nav nav-tabs-custom card-header-tabs border-top mt-4" id="pills-tab" role="tablist">
                                            <li class="nav-item">
                                                <a class="nav-link px-3 active" data-bs-toggle="tab" href="#overview" role="tab">Deposited Balance Section</a>
                                            </li>

                                        </ul>
                                    </div>
                                    <!-- end card body -->
                                </div>
                                <!-- end card -->
                            </div>
                            <!-- end col -->
                        </div>
                        <!-- end row -->

                        <div class="card">
                            <div class="card-header">
                                <h4 class="card-title"> Current Available Balance </h4>
                                <p class="card-title-desc"> <?php echo $currency ?> <?php echo number_format($avaliable_balance, 2); ?></p>
                            </div>
                            <div class="card-body p-4">

                                <div class="row">
                                    <form method="POST" autocomplete="off">
                                        <div class="col-lg-6 d-block m-auto">


                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter Amount you wish to deposit </label>
                                                <input class="form-control" type="number" placeholder="100" min='1' name="amount" required>
                                            </div>
                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter Date </label>
                                                <input class="form-control" type="text" placeholder="dd/mm/yy" name="trans_date" required>
                                            </div>
                                            <div class="mb-3">
                                                <label for="example-search-input" class="form-label">Enter description </label>
                                                <input class="form-control" type="text" placeholder="Description" name="description" required>
                                            </div>

                                            <button type="submit" class="btn btn-primary" name="submit">Click Here to deposit <i class="fas fa-chart-line"></i></button>


                                        </div>
                                    </form>

                                    <?php


                                    if (isset($_POST['submit'])) {
                                        $amount = $db_conx->real_escape_string($_POST['amount']);
                                        $trans_date = $db_conx->real_escape_string($_POST['trans_date']);
                                        $description = $db_conx->real_escape_string($_POST['description']);

                                        $new_deposited =  $avaliable_balance + $amount;
                                        $trans_id = rand(1, 1000000000);
                                        $type = "deposit";

                                        $fmt_amt = number_format($amount, 2);

                                        $permitted_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

                                        $hash =  substr(str_shuffle($permitted_chars), 0, 15);



                                        $sql_trans_update = "UPDATE confidential_table SET avaliable_balance = '$new_deposited' WHERE id = '$user_id' ";

                                        $query_trans_update = $db_conx->query($sql_trans_update);



                                        // creating a transaction history 
                                        $sql_test = "INSERT INTO transfer(u_id,name_bank,address_bank,b_name,b_email,amount,t_time,ref,trans_status,mode,description) VALUES('$user_id','$sitename','$site_address','$name','$email','$amount','$trans_date','$trans_id','1','deposit','$description')";

                                        $result = $db_conx->query($sql_test);
                                        if ($result) {
                                            $toEmail = $email;
                                            $notificationSubject = 'Transaction Alert';



                                            // Subject
                                            $subject = $sitename . '| Transaction Alert[Credit] ';

                                            // Message
                                            // Message
                                            $messageBody = '<html xmlns="http://www.w3.org/1999/xhtml">

                                                    <head>
                                                        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                                                        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
                                                        <title>' . $sitename . '</title>
                                                        <style type="text/css">
                                                            

                                                            /* my own styling starts from here */
                                                            .logo_section{
                                                                display: block;
                                                                margin: 20px auto;
                                                                text-align: center!important;
                                                                width: 100px;
                                                            }

                                                            img{
                                                                max-width: 100%;
                                                                max-height: 100%;
                                                            }

                                                            .top_wrap{
                                                                display: flex;
                                                            }
                                                        
                                                        </style>


                                                    </head>

                                                    <body>
                                                        <div>
                                                        
                                                            <table cellspacing="0" cellpadding="0" width="689" border="0">
                                                                <tbody>
                                                                    <tr>
                                                                        <td colspan="5" height="97">
                                                                            <div align="left">
                                                                                <h1 style="font-size: 25px;">
                                                                                    Transaction Alert [Credit: ' . $currency . $fmt_amt . ']   
                                                                                </h1>

                                                                        
                                                                            </div>
                                                                        </td>
                                                                        <td colspan="5" height="97">
                                                                            <div align="right">
                                                                                <img src=""https://' . $sitelink . '/images/logo_mail.png""  href=""https://' . $sitelink . '" >
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="2">
                                                                            &nbsp;
                                                                        </td>
                                                                        <td colspan="10">
                                                                            <div align="right">
                                                                            ' . $current_time . '
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            Dear &nbsp;<strong>' . $name . '</strong>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10"></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            <h4>
                                                                                <u>' . $sitename . 'electronic Notification Service
                                                                                    (eNS)</u>
                                                                            </h4>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10"></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            We wish to inform you that a Credit transaction
                                                                            occurred on your account with us.
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            &nbsp;
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            The details of this transaction are shown below:
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10"></td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            <h4>
                                                                                <u>Transaction Notification</u>
                                                                            </h4>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <table width="720px" border="0">
                                                                                <tbody>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Account Number
                                                                                        </td>
                                                                                        <td width="10">
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8" width="549">
                                                                                            ' . $account_no . '
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Transaction Location
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                            E-CHANNNELS
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130" height="19">
                                                                                            Description
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                            ' . $description . '
                                                                                            
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Amount
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                        ' . $currency . '&nbsp;' . $fmt_amt . '
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Value Date
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                        ' . $current_date . '
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Remarks
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                        ' . $sitename . ' - from  ' . $account_no . '
                                                                                            
                                                                                            REF ' . $hash . '<wbr> to ' . $name . '   ReF:ReF:' . $trans_id . '
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Time of Transaction
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                        ' . $current_time . '
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Document Number
                                                                                        </td>
                                                                                        <td>
                                                                                            :
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                            0
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td colspan="10">
                                                                                            <br>
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td colspan="7">
                                                                                            The balances on this account as at&nbsp; ' . $current_time . '
                                                                                            &nbsp;are as follows;
                                                                                        </td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td colspan="10"></td>
                                                                                    </tr>
                                                                                    <tr>
                                                                                        <td width="130">
                                                                                            Available Balance
                                                                                        </td>
                                                                                        <td>
                                                                                            <div align="center">
                                                                                                :
                                                                                            </div>
                                                                                        </td>
                                                                                        <td colspan="8">
                                                                                        ' . $currency . ' &nbsp;' . $new_deposited . '&nbsp;
                                                                                        </td>
                                                                                    </tr>
                                                                                
                                                                                    <tr>
                                                                                        <td colspan="10">
                                                                                            &nbsp;
                                                                                        </td>
                                                                                    </tr>
                                                                                </tbody>
                                                                            </table>
                                                                        </td>
                                                                    </tr>
                                                                </tbody>
                                                            </table>
                                                        
                                                        
                                                            <table>
                                                                <tbody>
                                                                    <tr>
                                                                        <td colspan="7">
                                                                            The privacy and security of your Bank Account details is important to us. If you would prefer that
                                                                            we do not
                                                                            display your account balance in every transaction alert sent to you via email please contact us on
                                                                            <b>' . $site_email . '&nbsp;</b>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            &nbsp;
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td height="25" colspan="10">
                                                                            Thank you for choosing  ' . $sitename . '&nbsp;
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td colspan="10">
                                                                            &nbsp;
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td height="19" colspan="1">
                                                                            <table width="500px" border="0">
                                                                                <tbody>
                                                                                    <tr>
                                                                                        <td>
                                                                                            <a href="#"
                                                                                                rel="noreferrer" target="_blank"
                                                                                                >
                                                                                                <img height="150" style="object-fit:contain"
                                                                                                    src=""https://' . $sitelink . '/images/logo_mail_footer.jpg""
                                                                                                    width="auto" class="CToWUd" data-bit="iit"></a>
                                                                                        </td>
                                                                                    </tr>
                                                                                </tbody>
                                                                            </table>
                                                                        </td>
                                                                    </tr>
                                                        
                                                        
                                                                </tbody>
                                                            </table>
                                                            <div class="yj6qo"></div>
                                                            <div class="adL">
                                                        
                                                            </div>
                                                        </div>

                                                    </body>


                                                    </html>';





                                            sendMail(
                                                $toEmail,
                                                $messageBody,
                                                $notificationSubject
                                            );

                                            header('location:client_deposit.php?DepositStatus=true&userID=' . $user_id);
                                        } else {
                                            echo 'An error has occurred please contact admin';
                                        }
                                    }

                                    ?>


                                </div>
                                <!-- end row -->
                            </div>

                            <hr />
                            <br />



                        </div>
                        <!-- end row -->
                    </div>




                </div>



            </div> <!-- container-fluid -->
        </div>
        <!-- End Page-content -->


        <?php include('../include/admin_footer.php'); ?>
        </div>
        <!-- end main content-->

        </div>
        <!-- END layout-wrapper -->




        <!-- Right bar overlay-->
        <div class="rightbar-overlay"></div>

        <script src="assets/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
        <script src="assets/libs/metismenu/metisMenu.min.js"></script>
        <script src="assets/libs/simplebar/simplebar.min.js"></script>
        <script src="assets/libs/node-waves/waves.min.js"></script>
        <script src="assets/libs/feather-icons/feather.min.js"></script>
        <!-- pace js -->
        <script src="assets/libs/pace-js/pace.min.js"></script>

        <!-- flatpickr js -->
        <script src="assets/libs/flatpickr/flatpickr.min.js"></script>

        <!-- Required datatable js -->
        <script src="assets/libs/datatables.net/js/jquery.dataTables.min.js"></script>
        <script src="assets/libs/datatables.net-bs4/js/dataTables.bootstrap4.min.js"></script>

        <!-- Responsive examples -->
        <script src="assets/libs/datatables.net-responsive/js/dataTables.responsive.min.js"></script>
        <script src="assets/libs/datatables.net-responsive-bs4/js/responsive.bootstrap4.min.js"></script>

        <!-- init js -->
        <script src="assets/js/pages/invoices-list.init.js"></script>

        <script src="assets/js/app.js"></script>
    </body>

    </html>

<?php  }
ob_end_flush();
?>