<?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("comment-complaints")) { ?>

    <script type="text/javascript">
        <?php
        if (isset($_REQUEST['full-name']) AND isset($_REQUEST['cell_number']) AND isset($_REQUEST['subject']) AND isset($_REQUEST['message']) AND isset($_REQUEST["DEVICE-KEY"])) {
            echo "let mode = true;";
            $value = "'{$_REQUEST['full-name']}', '{$_REQUEST['cell_number']}', '{$_REQUEST['subject']}', '{$_REQUEST['message']}', '{$_REQUEST['DEVICE-KEY']}'";
            echo "let send_state = " . ($DAL->DoCommand("INSERT INTO `app_comment_system` (`FullName`, `Communicate`, `Subject`, `Message`, `DeviceCode`) VALUES ($value)") ? "true" : "false") . ';';
        } else {
            echo "let mode = false;";
        }
        ?>
    </script>
    <!DOCTYPE html>
    <html lang="en">
    <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',
//                'croppic css'
            )
        );
        ?>
    </head>

    <body class="theme-red">
    <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="full-name"
                                                           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="subject"
                                                           placeholder="موضوع پیام"
                                                           required>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <div class="form-line">
                                                    <textarea lang="fa" rows="4"
                                                              class="form-control no-resize fBKoodakBold" name="message"
                                                              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) {
                        let message = (send_state ? "پیام شما ارسال شد." : "پیام شما ارسال نشد.");
                        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',
//            'croppic 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 } ?>