<?php
header("Expires: 0");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

require_once 'ResourcesHolder/core/CoreSystem.php';
require_once 'ResourcesHolder/core/DAL/DAL.php';

$DAL = new DAL('constant.php');
$index = new CoreSystem();

if ($index->checkState() AND $index->checkStateKey("register-acceptor")) { ?>
    <!DOCTYPE html>
    <html>
    <!--<IfModule mod_headers.c>
        Header set Cache-Control "no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires 0
    </IfModule>-->
    <head>
        <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
        <meta http-equiv="Pragma" content="no-cache"/>
        <meta http-equiv="Expires" content="0"/>
        <?php
        $index->publicLoadPlugin(
            array('meta 1', 'meta 2', 'meta 3')
        );
        ?>
        <title><?php echo $index->Title(); ?></title>
        <?php
        $index->publicLoadPlugin(
            array(
                'Google Fonts Roboto',
                'Google Fonts Material',
                'fav 1',
                'Bootstrap Core Css',
                'Waves Effect Css',
                'Animation Css',
                'font awesome',
                'Custom Css',
                'Farsi Font',
                'AdminBSB Themes',
                'Jquery Core Js',
//                'Main Script',
                'Sweet Alert Css',
                'Select Plugin Css',
                'Bootstrap Tags Input Plugin Css',
                'TimePicker Css',
                'JQuery DataTable Css',
                'Jquery Spinner Plugin Css',
                'Multi Select Css',
                'JQuery Nestable Css',
                'Light Gallery Plugin Css',
                'Bootstrap Toggle Css',
//                'Security'
            )
        );
        ?>
    </head>
    <body class="theme-red">
    <script type="text/javascript">
        <?php
        echo "\n";
        if ($index->CheckAllDataInArray(
            array(
                'fName',
                'lName',
                'cell-number',
                'fix-number',
                'category',
                'shop-name',
                'address',
                'more-details',
                'DEVICE-KEY'
            )
            , $_REQUEST)) {
            echo "let mode = true;";
            require_once 'ResourcesHolder/core/ApplicationSystem.php';
            $app = new ApplicationSystem(@$_REQUEST, "NO-HEADER");
            $output = $app->AcceptorRegister(@$_REQUEST);
            echo "let send_state = " . ($output['error'] === 0 ? "true" : "false") . ";";
            echo "\n";
            echo 'let message = "' . str_replace("\n", "", $output['msg']) . '";';
            echo "\n";
        } else {
            echo "let mode = false;";
        }
        ?>
    </script>
    <div class="reset-this">
        <div class="four-zero-four">
            <div class="container ">
                <div class="row center text-center">
                    <div class="col-sm-12 ">
                        <div class="card ">
                            <div class="header">
                                <h2 class="fBKoodakBold ">فرم ثبت نام اصناف</h2>
                            </div>
                            <div class="body" dir="rtl">
                                <form action="" method="get">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text" class="form-control fBKoodakBold"
                                                           name="fName"
                                                           placeholder="نام" required/>
                                                </div>
                                            </div>
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text" class="form-control fBKoodakBold"
                                                           name="lName"
                                                           placeholder="نام خانوداگی" required/>
                                                </div>
                                            </div>
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text"
                                                           class="form-control fBKoodakBold" name="cell-number"
                                                           placeholder="شماره همراه" required>
                                                </div>
                                            </div>
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text" class="form-control fBKoodakBold"
                                                           name="fix-number"
                                                           placeholder="شماره ثابت"
                                                           required>
                                                </div>
                                            </div>
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text"
                                                           class="form-control fBKoodakBold" name="category"
                                                           placeholder="نوع صنف" required>
                                                </div>
                                            </div>
                                            <div class="form-group success" dir="rtl">
                                                <div class="form-line">
                                                    <input type="text" class="form-control fBKoodakBold"
                                                           name="shop-name"
                                                           placeholder="نام فروشگاه"
                                                           required>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="form-line">
                                                    <textarea lang="fa" rows="4"
                                                              class="form-control no-resize fBKoodakBold" name="address"
                                                              placeholder="آدرس" required></textarea>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="form-line">
                                                    <textarea lang="fa" rows="4"
                                                              class="form-control no-resize fBKoodakBold"
                                                              name="more-details"
                                                              placeholder="توضیحات تکمیلی" required></textarea>
                                                </div>
                                            </div>
                                            <input id="input-key" hidden type="hidden" value="" name="DEVICE-KEY">
                                        </div>
                                        <button class="btn btn-success waves-effect send-commend btn-lg fBKoodakBold btn-block"
                                                type="submit">
                                           <span class="fa-2x ">
                                          ارسال درخواست
                                               </span>
                                        </button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        (function ($) {
            $(document).ready(function () {
                setKey(GetURLParameter('DEVICE-KEY'));
                $(".send-commend").unbind().bind("tap", function (e) {

                });
                if (android !== undefined || android !== null) {
                    if (mode) {
                        console.log(android.makeToast(message, send_state));
                    }
                }

                function setKey(key) {
                    $('#input-key').val(key);
                }
            });

            /**
             * @return {string}
             */
            function GetURLParameter(sParam) {
                let sPageURL = window.location.search.substring(1);
                let sURLVariables = sPageURL.split('&');
                for (let i = 0; i < sURLVariables.length; i++) {
                    let sParameterName = sURLVariables[i].split('=');
                    if (sParameterName[0] === sParam) {
                        return decodeURIComponent(sParameterName[1]);
                    }
                }
            }

        }(jQuery));
    </script>


    <?php
    $index->publicLoadPlugin(
        array(
            'Jquery CountTo Plugin Js',
            'Bootstrap Core Js ',
            'Select Plugin Js ',
            'Slimscroll Plugin Js ',
            'Waves Effect Plugin Js ',
//            'Custom Js admin',
            'Demo Js',
            'Second Script',
            'Jquery Touch Events',
            'tooltips popovers',
            'Bootstrap Notify Plugin Js',
            'Jquery Validation Plugin Css',
            'JQuery Steps Plugin Js',
            'Copy Clip Bord',//for test
            'Sweet Alert Plugin Js',
            'Input Mask Plugin Js',
            'Select Plugin Js',
            'Bootstrap Tags Input Plugin Js',
            'Google Api Kay',
            'TimePicker Js',
            'Jquery DataTable Plugin Js',
            'Jquery Spinner Plugin Js',
            'Multi Select Js',
            'JQuery Nestable Js',
            'Light Gallery Plugin Js',
            'Bootstrap Toggle Js',
            'jQuery qr js',
            'TinyMC js',
        )
    );
    ?>
    </body>
    </html>
<?php } else { ?>

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
    <head>
        <title>500 Internal Server Error</title>
    </head>
    <body>
    <h1>Internal Server Error</h1>
    <p>The server encountered an internal error or
        misconfiguration and was unable to complete
        your request.</p>
    <p>Please contact the server administrator at
        webmaster@android.kashancard.digihelp.net to inform them of the time this error occurred,
        and the actions you performed just before this error.</p>
    <p>More information about this error may be available
        in the server error log.</p>
    <p>Additionally, a 500 Internal Server Error
        error was encountered while trying to use an ErrorDocument to handle the request.</p>
    </body>
    </html>
<?php } ?>
