<?php
// *************************************************************************
// *                                                                       *
// * DEPRIXA BASIC -  Freight Forwarding & Shipping Software Solutions     *
// * Copyright (c) JAOMWEB. All Rights Reserved                            *
// *                                                                       *
// *************************************************************************
// *                                                                       *
// * Email: support@jaom.info                                              *
// * Website: https://deprixa.link/documentation/                          *
// *                                                                       *
// *************************************************************************
// *                                                                       *
// * This software is furnished under a license and may be used and copied *
// * only  in  accordance  with  the  terms  of such  license and with the *
// * inclusion of the above copyright notice.                              *
// * If you Purchased from Codecanyon, Please read the full License from   *
// * here- http://codecanyon.net/licenses/standard                         *
// *                                                                       *
// *************************************************************************



if (!$user->cdp_is_Admin())
    cdp_redirect_to("login.php");

$userData = $user->cdp_getUserData();

require_once('helpers/querys.php');

if (isset($_GET['user'])) {
    $data = cdp_getUserEdit($_GET['user']);
}

if (!isset($_GET['user']) or $data['rowCount'] != 1) {
    cdp_redirect_to("users_list.php");
}

$row = $data['data'];


$db->cdp_query("SELECT * FROM cdb_users_multiple_addresses WHERE user_id='" . $_GET['user'] . "'");
$user_addreses = $db->cdp_registros();

?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="Courier DEPRIXA-Integral Web System" />
    <meta name="author" content="Jaomweb">

    <title><?php echo $lang['filter4'] ?> | <?php echo $core->site_name ?></title>
    <link rel="stylesheet" href="dist/css/input-css/intlTelInput.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <link href="assets/libs/sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">

    <?php include 'views/inc/head_scripts.php'; ?>

</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->


    <?php include 'views/inc/preloader.php'; ?>
    <!-- ============================================================== -->
    <!-- Main wrapper - style you can find in pages.scss -->
    <!-- ============================================================== -->
    <div id="main-wrapper">
        <!-- ============================================================== -->
        <!-- Topbar header - style you can find in pages.scss -->
        <!-- ============================================================== -->

        <!-- ============================================================== -->
        <!-- Preloader - style you can find in spinners.css -->
        <!-- ============================================================== -->

        <?php include 'views/inc/topbar.php'; ?>

        <!-- End Topbar header -->


        <!-- Left Sidebar - style you can find in sidebar.scss  -->

        <?php include 'views/inc/left_sidebar.php'; ?>


        <!-- End Left Sidebar - style you can find in sidebar.scss  -->

        <!-- Page wrapper  -->
        <!-- ============================================================== -->
        <div class="page-wrapper">

            <div class="page-breadcrumb ">
                <div class="row">
                    <div class="col-5 align-self-center">
                        <h4 class="page-title">
                            <?php echo $lang['filter4']; ?></h4>

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

            <div class="container-fluid">

                <div class="row">
                    <!-- Column -->
                    <div class="col-lg-4 col-xlg-3 col-md-5">
                        <div class="card">
                            <div class="card-body">
                                <center class="m-t-30"> <img src="assets/<?php echo ($row->avatar) ? $row->avatar : "/uploads/blank.png"; ?>" class="rounded-circle" width="150" />
                                    <div><br></div>
                                    <h4 class="card-title m-t-10"><?php echo $row->fname; ?> <?php echo $row->lname; ?></h4>
                                    <h6 class="card-subtitle m-t-10"><?php echo $lang['user_manage2'] ?> <i class="icon-double-angle-right"></i>
                                        <span class="badge bg-secondary"><?php echo $row->username; ?></span>
                                    </h6>
                                    <h6 class="card-subtitle m-t-10">Virtual Locker <i class="icon-double-angle-right"></i>
                                        <span class="badge bg-secondary"><?php echo $row->locker; ?></span>
                                    </h6>
                                </center>
                            </div>
                            <div>
                                <hr>
                            </div>
                            <div class="card-body"> <small class="text-muted">E-mail </small>
                                <h6><?php echo $row->email; ?></h6> <small class="text-muted p-t-30 db">Phone</small>
                                <h6> <?php echo $row->phone; ?></h6>
                            </div>
                            <div class="card-body row text-center">
                                <div class="col-6 border-right">
                                    <h6><?php echo $row->created; ?></h6>
                                    <span><?php echo $lang['user-account18'] ?></span>
                                </div>
                                <div class="col-6">
                                    <h6><?php echo $row->lastlogin; ?></h6>
                                    <span><?php echo $lang['user-account19'] ?></span>
                                </div>
                            </div>


                        </div>
                    </div>
                    <!-- Column -->


                    <!-- Column -->
                    <div class="col-lg-8 col-xlg-9 col-md-7">
                        <div class="card">
                            <div class="card-header badge-light">
                                <ul class="nav nav-pills custom-pills" id="pills-tab" role="tablist">
                                    <li class="nav-item">
                                        <a class="nav-link active" id="pills-setting-tab" data-toggle="pill" href="#previous-month" role="tab" aria-controls="pills-setting" aria-selected="false"><?php echo $lang['edit-clien1'] ?><span><?php echo $lang['edit-clien2'] ?> <i class="icon-double-angle-right"></i> <?php echo $row->username; ?></span></a>
                                    </li>
                                </ul>
                            </div>

                            <div class="tab-content" id="pills-tabContent">
                                <div class="tab-pane fade show active" id="previous-month" role="tabpanel" aria-labelledby="pills-setting-tab">
                                    <div class="card-body">
                                        <!-- <div id="loader" style="display:none"></div> -->
                                        <div id="resultados_ajax"></div>

                                        <form class="form-horizontal form-material" id="edit_user" name="edit_user" method="post">
                                            <section>
                                                <div class="row">
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="firstName1"><?php echo $lang['user_manage3'] ?></label>
                                                            <input type="text" class="form-control" disabled="disabled" name="username" readonly="readonly" value="<?php echo $row->username; ?>" placeholder="<?php echo $lang['user_manage3'] ?>">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="lastName1"><?php echo $lang['user_manage4'] ?></label>
                                                            <input type="text" class="form-control" id="password" name="password" placeholder="<?php echo $lang['user_manage32'] ?>">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="row">
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1">Document type</label>
                                                            <select class="form-select " id="document_type" name="document_type" value="<?php echo $row->document_type; ?>">


                                                                <option value="DNI" <?php if ($row->document_type == 'DNI') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder165'] ?></option>

                                                                <option value="RIC" <?php if ($row->document_type == 'RIC') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder166'] ?></option>

                                                                <option value="CI" <?php if ($row->document_type == 'CI') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder167'] ?></option>

                                                                <option value="CIE" <?php if ($row->document_type == 'CIE') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder168'] ?></option>

                                                                <option value="CIN" <?php if ($row->document_type == 'CIN') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder169'] ?></option>

                                                                <option value="CIE" <?php if ($row->document_type == 'CIE') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder170'] ?></option>

                                                                <option value="CC" <?php if ($row->document_type == 'CC') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder171'] ?></option>

                                                                <option value="TI" <?php if ($row->document_type == 'TI') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder172'] ?></option>

                                                                <option value="PSP" <?php if ($row->document_type == 'PSP') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder174'] ?></option>


                                                                <option value="NIT" <?php if ($row->document_type == 'NIT') {
                                                                                        echo 'selected';
                                                                                    } ?>><?php echo $lang['leftorder1745'] ?></option>
                                                            </select>
                                                        </div>
                                                    </div>


                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1">Document number</label>
                                                            <input type="text" class="form-control" id="document_number" name="document_number" value="<?php echo $row->document_number; ?>" placeholder="Document number">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="row">
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="emailAddress1"><?php echo $lang['user_manage6'] ?></label>
                                                            <input type="text" class="form-control" name="fname" id="fname" value="<?php echo $row->fname; ?>" placeholder="<?php echo $lang['user_manage6'] ?>">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1"><?php echo $lang['user_manage7'] ?></label>
                                                            <input type="text" class="form-control" name="lname" id="lname" value="<?php echo $row->lname; ?>" placeholder="<?php echo $lang['user_manage7'] ?>">
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="row">
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="emailAddress1"><?php echo $lang['user_manage5'] ?></label>
                                                            <input type="text" class="form-control" id="email" name="email" value="<?php echo $row->email; ?>" placeholder="<?php echo $lang['user_manage5'] ?>">
                                                        </div>

                                                    </div>

                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1"><?php echo $lang['user_manage9'] ?></label>
                                                            <input type="text" class="form-control" id="phone_custom" name="phone_custom" value="<?php echo $row->phone; ?>" placeholder="<?php echo $lang['user_manage9'] ?>">
                                                            <span id="valid-msg" class="hide"></span>
                                                            <div id="error-msg" class="hide text-danger"></div>
                                                        </div>
                                                    </div>

                                                </div>
                                                <div class="row">

                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1"><?php echo $lang['user_manage11'] ?></label>
                                                            <select class="form-select " id="gender" name="gender" value="<?php echo $row->gender; ?>" placeholder="<?php echo $lang['user_manage11'] ?>">
                                                                <option value="Male" <?php if ($row->gender == 'Male') {
                                                                                            echo 'selected';
                                                                                        } ?>><?php echo $lang['leftorder178'] ?></option>
                                                                <option value="Female" <?php if ($row->gender == 'Female') {
                                                                                            echo 'selected';
                                                                                        } ?>><?php echo $lang['leftorder179'] ?></option>
                                                                <option value="Other" <?php if ($row->gender == 'Other') {
                                                                                            echo 'selected';
                                                                                        } ?>><?php echo $lang['leftorder180'] ?></option>
                                                            </select>
                                                        </div>
                                                    </div>

                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="lastName1"><?php echo $lang['user_manage24'] ?></label>
                                                            <input class="form-control" id="avatar" name="avatar" type="file" />
                                                        </div>
                                                    </div>
                                                </div>

                                                <hr>


                                                <div class="row">

                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1"><?php echo $lang['user_manage20'] ?></label>
                                                            <div class="btn-group">
                                                                <label class="btn">
                                                                    <div class="custom-control custom-radio">
                                                                        <input type="radio" id="customRadio4" class="custom-control-input" name="active" value="1" <?php cdp_getChecked($row->active, "1"); ?>>
                                                                        <label class="custom-control-label" for="customRadio4"> <?php echo $lang['user_manage16'] ?></label>
                                                                    </div>
                                                                </label>
                                                                <label class="btn">
                                                                    <div class="custom-control custom-radio">
                                                                        <input type="radio" id="customRadio3" class="custom-control-input" name="active" value="0" <?php cdp_getChecked($row->active, "0"); ?>>
                                                                        <label class="custom-control-label" for="customRadio3"> <?php echo $lang['user_manage17'] ?></label>
                                                                    </div>
                                                                </label>

                                                                </label>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6 mb-3">
                                                        <div class="form-group">
                                                            <label for="phoneNumber1"><?php echo $lang['user_manage23'] ?></label>
                                                            <div class="btn-group" data-toggle="buttons">
                                                                <label class="btn">
                                                                    <div class="custom-control custom-radio">
                                                                        <input type="radio" id="customRadio4" name="newsletter" value="1" <?php cdp_getChecked($row->newsletter, 1); ?> class="custom-control-input">
                                                                        <label class="custom-control-label" for="customRadio4"> <?php echo $lang['tools-config14'] ?></label>
                                                                    </div>
                                                                </label>
                                                                <label class="btn">
                                                                    <div class="custom-control custom-radio">
                                                                        <input type="radio" id="customRadio5" name="newsletter" value="0" <?php cdp_getChecked($row->newsletter, 0); ?> class="custom-control-input">
                                                                        <label class="custom-control-label" for="customRadio5"> <?php echo $lang['tools-config15'] ?></label>
                                                                    </div>
                                                                </label>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <hr>
                                                <h4><?php echo $lang['leftorder176'] ?></h4>
                                                <br>


                                                <?php

                                                $count = 0;

                                                foreach ($user_addreses as $row_for) {

                                                    $count++;

                                                ?>

                                                    <div id="div_parent_<?php echo $count; ?>">

                                                        <?php if ($count > 1) {
                                                            echo '<hr>';
                                                        } ?>

                                                        <h4><?php echo $lang['laddress'];
                                                            if ($count > 0) {
                                                                echo ' ' . $count;
                                                            } ?> </h4>

                                                        <div class="row">
                                                            <div class="col-md-6 mb-3">
                                                                <div class="form-group">
                                                                    <label for="phoneNumber1"><?php echo $lang['user_manage10'] ?></label>
                                                                    <input type="text" class="form-control" name="address[]" id="address<?php echo $count; ?>" placeholder="<?php echo $lang['user_manage10'] ?>" value="<?php echo $row_for->address; ?>">
                                                                </div>
                                                            </div>

                                                            <div class="col-md-6 mb-3">
                                                                <div class="form-group">
                                                                    <label for="emailAddress1"><?php echo $lang['user_manage12'] ?></label>
                                                                    <input type="text" class="form-control" name="country[]" id="country<?php echo $count; ?>" placeholder="<?php echo $lang['user_manage12'] ?>" value="<?php echo $row_for->country; ?>">
                                                                </div>
                                                            </div>
                                                        </div>

                                                        <div class="row">
                                                            <div class="col-md-6 mb-3">
                                                                <div class="form-group">
                                                                    <label for="phoneNumber1"><?php echo $lang['user_manage13'] ?></label>
                                                                    <input type="text" class="form-control" id="city<?php echo $count; ?>" name="city[]" placeholder="<?php echo $lang['user_manage13'] ?>" value="<?php echo $row_for->city; ?>">
                                                                </div>
                                                            </div>
                                                            <div class="col-md-6 mb-3">
                                                                <div class="form-group">
                                                                    <label for="phoneNumber1"><?php echo $lang['user_manage14'] ?></label>
                                                                    <input type="text" class="form-control" name="postal[]" id="postal<?php echo $count; ?>" placeholder="<?php echo $lang['user_manage14'] ?>" value="<?php echo $row_for->zip_code; ?>">
                                                                </div>
                                                            </div>

                                                            <input type="hidden" name="address_id[]" id="address_id<?php echo $count; ?>" value="<?php echo $row_for->id_addresses; ?>" />

                                                        </div>

                                                        <?php

                                                        if ($count > 1) { ?>

                                                            <div align="right" class="col-md-12">
                                                                <button type="button" name="remove_row" id="<?php echo $count; ?>" class="btn btn-danger   remove_row mt-2 mb-3"><span class="fa fa-trash"></span> <?php echo $lang['delete_address_recepient'] ?></button>
                                                            </div>
                                                    </div>
                                            <?php
                                                        }
                                                    }

                                            ?>

                                            <input type="hidden" name="total_address" id="total_address" value="<?php echo $count; ?>" />
                                            <input type="hidden" name="phone" id="phone" value="<?php echo $row->phone; ?>" />

                                            <div id="div_address_multiple"></div>

                                            <div align="left">
                                                <button type="button" name="add_row" id="add_row" class="btn btn-success mb-2"><span class="fa fa-plus"></span> <?php echo $lang['add_address_recepient'] ?></button>
                                            </div>


                                            <hr />
                                            <div class="row">
                                                <div class="col-md-12 mb-3">
                                                    <div class="form-group">
                                                        <label for="emailAddress1"><?php echo $lang['user_manage28'] ?></label>
                                                        <textarea class="form-control" name="notes" id="notes" rows="6" name="notes" placeholder="<?php echo $lang['user_manage31'] ?>"><?php echo $row->notes; ?></textarea>
                                                    </div>
                                                </div>
                                            </div>

                                            </section>
                                            <div class="form-actions">
                                                <div class="card-body border-top">
                                                    <div class="mt-3 mt-md-0 ms-auto">
                                                        <button class="btn btn-primary mb-2" id="save_data" name="save_data" type="submit"><i data-feather="save" class="feather-sm me-1 fill-icon"></i> <?php echo $lang['user-account20'] ?>
                                                        </button>

                                                        <a href="customers_list.php" class="btn btn-secondary mb-2"><i data-feather="corner-down-right" class="feather-sm me-1 fill-icon"></i> <?php echo $lang['user_manage30'] ?></a>
                                                    </div>
                                                    <input name="id" id="id" type="hidden" value="<?php echo $row->id; ?>" />
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- Column -->
                </div>

                <input type="hidden" name="count_address" id="count_address" value="<?php echo $count; ?>" />

            </div>

        </div>

        <?php include 'views/inc/footer.php'; ?>

    </div>
    <!-- ============================================================== -->
    <!-- End Page wrapper  -->
    <!-- ============================================================== -->
    <script src="assets/libs/select2/dist/js/select2.full.min.js"></script>
    <script src="assets/libs/select2/dist/js/select2.min.js"></script>
    <script src="dist/js/input-js/intlTelInput.js"></script>
    <script src="assets/libs/sweetalert2/dist/sweetalert2.all.min.js"></script>

    <script src="dataJs/customers_edit.js"></script>


</body>

</html>