<?php

/**
 * Created by PhpStorm.
 * User: Kavand
 * Date: 2/25/2019
 * Time: 1:49 AM
 */
class ClientPanel
{

    protected $DAL = null;
    protected $index = null;
    protected $address = "";

    protected $page_mode = "";
    protected $page_id = "";
    protected $mobile = "";
    protected $loginAs = "";

    public function ClientPanel($DAL, $index)
    {
        define("local", "Client/Panel/");
        $this->DAL = $DAL;
        $this->index = $index;
        $this->address = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
    }

    public function __construct($DAL, $index)
    {
        define("local", "Client/Panel/");
        $this->DAL = $DAL;
        $this->index = $index;
        $this->address = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
    }

    function RunPanel($AccessLevelCode, $ClientID, $FullName, $mobile, $loginAs)
    {
        $this->page_id = $ClientID;
        $this->page_mode = $AccessLevelCode;
        $this->mobile = $mobile;
        $this->loginAs = $loginAs;

        /*if ($this->index->CheckAllDataInArray(array("form-mode", "call-back"), $_REQUEST)) {
            if ($this->index->CheckAllDataInArray(
                array('fName', 'lName', 'nCode', 'bnCode', 'bank', 'mobile'), $_REQUEST)) {
                $query = "UPDATE `app_client_register` SET ";
                $query .= "`FirstName`= '{$_REQUEST['fName']}', ";
                $query .= "`LastName`= '{$_REQUEST['lName']}', ";
                $query .= "`NationalCode`= '{$_REQUEST['nCode']}', ";
                $query .= "`NationalSecurityCode`= '{$_REQUEST['bnCode']}', ";
                $query .= "`BankCardNumber`= '{$_REQUEST['bank']}' WHERE `Mobile`='{$_REQUEST['mobile']}'";
                $out = $this->DAL->DoCommand($query);
                header("Location: " . $_REQUEST['call-back']);
                exit;
            }
        }*/
        $this->headerHTML();
        $this->initScript($FullName);
        $this->contentHTML();
        $this->footerHTML();
    }

    protected function headerHTML()
    {
        ?>
        <!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
            $this->index->publicLoadPlugin(
                array('meta 1', 'meta 2', 'meta 3')
            );
            ?>
            <title><?php echo $this->index->Title(); ?></title>
            <?php
            $this->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">
        <?php
    }


    protected function initScript($FullName)
    {
        echo "<script type='text/javascript'>";
        echo "let client_service_data = { 'name':'$FullName', 'acceptor_id':'', 'image_slide_count':'', 'p_id':'$this->page_id', 'p_roll':'$this->loginAs', 'p_mode':'$this->page_mode', 'image_slide':[] };";

        if ($this->loginAs == 'acceptor') {
            $select = $this->DAL->Select("SELECT `ID`, `image_limit` FROM `app_acceptor_list` where `pNumber`='{$this->mobile}'");
            if ($select) {
                echo "client_service_data.acceptor_id=" . $select[0]['ID'] . ';';
                $num = $select[0]['image_limit'];
                $num = (is_numeric($num) ? $num : 0);
                echo "client_service_data.image_slide_count=" . $num . ";";
                if ($num > 0) {
                    $select = $this->DAL->Select("SELECT `imgSrc`, `ID` FROM `app_acceptor_image_slider` where `imgFor`='{$select[0]['ID'] }' ORDER BY `imgIndex` DESC");
                    if ($select) {
                        foreach ($select as $item) {
                            echo "client_service_data.image_slide.push({src:'" . $item['imgSrc'] . "',id:" . $item['ID'] . "});";
                        }
                    }
                } else {
                    echo "client_service_data.image_slide_count=0;";
                }

            }
        }
        echo "</script>";
    }

    protected function contentHTML()
    {
        $this->index->content(
            array(
                'Page Loader',
                'Overlay For Sidebars',
                /*  'Search Bar',*/
                'Client Top Bar',
                'content'
            )
        );
    }

    protected function footerHTML()
    {
        $this->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',
            )
        );
    }
}
