<?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                         *
// *                                                                       *
// *************************************************************************

require_once('helpers/querys.php');

if (isset($_GET['recipient'])) {
    $data = cdp_getRecipientEdit($_GET['recipient']);
}

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

$row_recipient = $data['data'];

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



$userData = $user->cdp_getUserData();

?>
<!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['edit_recipient'] ?> | <?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-8 align-self-center offset-1">
                        <h4 class="page-title"><?php
                                                // echo $lang['shiplist'] 
                                                ?>
                            <?php echo $lang['edit_recipient']; ?></h4>

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


            <div class="container-fluid">


                <div class="row">
                    <!-- Column -->
                    <div class="col-lg-12 col-xlg-12 col-md-12">
                        <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_recipient']; ?></a>
                                    </li>
                                </ul>
                            </div>
                            <div class="card-body">
                                <!-- <div id="loader" style="display:none"></div> -->
                                <div id="resultados_ajax"></div>
                                <form class="form-horizontal form-material" id="save_user" name="save_user" method="post">
                                    <section>


                                        <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" placeholder="<?php echo $lang['user_manage6'] ?>" value="<?php echo $row_recipient->fname; ?>">
                                                </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" placeholder="<?php echo $lang['user_manage7'] ?>" value="<?php echo $row_recipient->lname; ?>">
                                                </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" placeholder="<?php echo $lang['user_manage5'] ?>" value="<?php echo $row_recipient->email; ?>">
                                                </div>
                                            </div>

                                            <div class="col-md-6 mb-3">
                                                <div class="form-group">
                                                    <label for="phoneNumber1"><?php echo $lang['user_manage9'] ?></label>
                                                    <br>
                                                    <input type="tel" class="form-control" name="phone_custom" id="phone_custom" value="<?php echo $row_recipient->phone; ?>">

                                                    <span id="valid-msg" class="hide"></span>
                                                    <div id="error-msg" class="hide text-danger"></div>
                                                </div>
                                            </div>
                                        </div>
                                        <br>
                                        <hr>
                                        <h4><?php echo $lang['leftorder176'] ?></h4>
                                        <br>

                                        <?php

                                        $count = 0;

                                        foreach ($recipient_addreses as $row) {

                                            $count++;

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

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

                                                <h4><?php echo $lang['laddress'];
                                                    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->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->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->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->zip_code; ?>">
                                                        </div>
                                                        <input type="hidden" name="address_id[]" id="address_id<?php echo $count; ?>" value="<?php echo $row->id_addresses; ?>" />

                                                    </div>
                                                </div>

                                                <?php

                                                if ($count > 1) { ?>

                                                    <div align="right" class="col-md-12 mb-3">
                                                        <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_recipient->phone; ?>" />

                                    <input type="hidden" name="recipient_id" id="recipient_id" value="<?php echo $row_recipient->id; ?>" />

                                    <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>

                                    </section>
                                    <br>
                                    <div class="form-group">
                                        <div class="col-sm-12">
                                            <button class="btn btn-primary btn-confirmation" id="save_data" name="save_data" type="submit"><?php echo $lang['edit_recipient'] ?><i class="icon-ok"></i></button>

                                            <a href="recipients_list.php" class="btn btn-secondary btn-confirmation"><i class="ti-share-alt"></i> <?php echo $lang['user_manage30'] ?></a>
                                        </div>
                                    </div>
                                </form>
                            </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/recipients_edit.js"></script>


</body>

</html>