<?php
$title = 'Upload Log';
require_once('header-links.php');
// require_once('../lib/basic-function.php');
// require_once('../lib/user-functions.php');
// require_once('../lib/investment-plan-functions.php');
// require_once('../lib/package-functions.php');
// require_once('../lib/currency-functions.php');

$subcategory = $basicFunctn->selectAllDlt($basicFunctn->subcategory_tb);
$category = $basicFunctn->selectAllDlt($basicFunctn->category_tb);

$product = $basicFunctn->getDataDlt($_GET['product'], $basicFunctn->product_tb);
?>

<body>
    <div class="app">
        <div class="layout">
            <?php require_once('sidebar.php'); ?>

            <!-- Page Container START -->
            <div class="page-container">
                <?php require_once('header.php'); ?>

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-title">
                            <h4><?php print $title; ?></h4>
                        </div>
                        <div class="row">
                            <div class="col-md-8">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="row">

                                            <div class="col-lg-9 col-xl-6">
                                                <form action="" method="POST" enctype="multipart/form-data">
                                                    <span class="btn btn-default img-span">Choose Image</span>
                                                    <input type="file" id="user_profile_img" name="file" class="upload-img-form">
                                                    <input type="hidden" id="product_id" value="<?php print $_GET['product'] ?>">
                                                    <p class="">*zip your log using a compression software then upload the zipped file here.</p>
                                                    <button type="submit" class="btn btn-primary font-weight-bolder upload_img_btn">Upload File</button>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade zoomInUp" id="delete_package_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Delete Category?</h4>
                            </div>
                            <form class="delete_package_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this category will be deleted permanently. <br> Users won't be able to purchase products under this category.</p>
                                </div>
                            </form>
                            <div class="modal-footer no-border">
                                <div class="text-right">
                                    <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary btn-sm delete_package_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->
                <?php require_once('footer.php'); ?>
                <!-- Footer END -->

            </div>
            <!-- Page Container END -->

        </div>
    </div>

    <?php require_once('footer-links.php'); ?>
    <script>
        $('.upload_img_btn').click(async function(e) {
            e.preventDefault();
            let product_id = $('#product_id').val();
            let user_img = $('#user_profile_img').prop('files')[0];
            let img_data = [{
                    name: "user_profile_img",
                    value: user_img
                },
                {
                    name: "product_id",
                    value: product_id
                }
            ]
            // console.log(img_data);
            // return;
            let form_data = set_form_data(img_data);
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'upload-log?product=' + product_id, 1);
        });



        $('.delete_package_modal').click(function(e) {
            e.preventDefault();
            append_id('delete_category_id', '.delete_package_form', '#delete_package_modal', this)
            $('#delete_package_modal').modal('toggle');
        });

        $('.new_package_btn').click(async function(e) {
            e.preventDefault();
            let new_package_form = $('.new_package_form').serializeArray();
            let form_data = set_form_data(new_package_form);
            // console.log(new_package_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            throwSweetalert(returned, 'edit-product?product=' + new_package_form[0].value, 1);
        });
        $('.delete_package_btn').click(async function(e) {
            e.preventDefault();
            let delete_package_form = $('.delete_package_form').serializeArray();
            let form_data = set_form_data(delete_package_form);
            // console.log(delete_package_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'category', 1);
        });
    </script>