<?php

// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Factory\AppFactory;
use Psr\Log\LoggerInterface;

// use Slim\Psr7\Response;

require __DIR__ . '/vendor/autoload.php';
$app = AppFactory::create();
function defaultLayers($url,$argp = false, $data = false){
    if($argp){
     define('property_id',$argp); 
    }else{
     define('property_id',false); 
    }
    if($data){
        $arr_data = $data;
       }else{
        $arr_data = false;
       }

    define('url',$url);
    require 'app/bank.php';
    require 'layout/header.php';
    require 'views/'.url.'.php';
    require 'layout/footer.php';
}
function loginpage(){
    require 'layout/header.php';
    require 'views/login.php';
    require 'layout/footer.php';
    return true;
}
    function secureUserLayer($url,$argp = false, $data = false){
    require 'app/hmailer.php';
    // $Hmailer = new Hmailer;
    require 'app/bank.php';
    $login_state = new bankUser;
    if(!($login_state->chk_login_user())){
        loginpage();
        }elseif($url == 'login'){
            loginpage();
        }elseif($url == 'otp' && $login_state->chk_login_user() && !$login_state->isOtpVerified()){
        require 'views/loginauth.php';    
        }elseif($url == 'logout'){
                $login_state->logout_user();
                loginpage();
        }else{
    if($login_state->isOtpVerified()){
        $url = ($url == 'otp')?'account':$url;
    if($argp){
     define('property_id',$argp); 
    }else{
     define('property_id',false); 
    }
    if($data){
        $arr_data = $data;
       }else{
        $arr_data = false;
       }
    define('secureurl',$url);
    // if(secureurl == 'welcome'){
            // require 'layout/acct_header.php';
            // require 'views/loginauth.php';
        // require 'layout/acct_footer.php';
    // }else{
        require 'layout/acct_header.php';
    require 'views/'.secureurl.'.php';
    require 'layout/acct_footer.php';    
    // }

    }else{
        print_r($_SESSION);
        require 'views/loginauth.php';
    }        
    }
}
function secureAdminLayer($url,$argp = false, $data = false){
    require 'app/bank.php';
    $login_state = new adminUser;
if(!($login_state->chk_login_user())){
require 'adm_dashboard/login.php';
}elseif($url == 'logout'){
        $login_state->logout_user();
        require 'adm_dashboard/login.php';
    }else{
    if($argp){
     define('pages',$argp); 
    }else{
     define('pages',false); 
    }
    if($data){
        $arr_data = $data;
    }else{
        $arr_data = false;
    }
    define('adminurl',$url);
    require 'adm_dashboard/main.php';
    }
}
$app->any('/', function (Request $request, Response $response, $args) {
    defaultLayers('index');
    return $response;
});
$app->any('/index', function (Request $request, Response $response, $args) {
    defaultLayers('index');
    return $response;
});
$app->any('/accounts', function (Request $request, Response $response, $args) {
    defaultLayers('accounts');
    return $response;
});
$app->any('/contact', function (Request $request, Response $response, $args) {
    defaultLayers('contact_us');
    return $response;
});
$app->any('/testimonials', function (Request $request, Response $response, $args) {
    defaultLayers('testimonials');
    return $response;
});
$app->any('/email', function (Request $request, Response $response, $args) {
    require('views/email.html');
    return $response;
});
$app->any('/loans', function (Request $request, Response $response, $args) {
    defaultLayers('loans');
    return $response;
});
$app->any('/careers', function (Request $request, Response $response, $args) {
    defaultLayers('careers');
    return $response;
});
$app->any('/about', function (Request $request, Response $response, $args) {
    defaultLayers('about');
    return $response;
});
$app->any('/team', function (Request $request, Response $response, $args) {
    defaultLayers('team');
    return $response;
});
$app->any('/cards', function (Request $request, Response $response, $args) {
    defaultLayers('cards');
    return $response;
});
$app->any('/login', function (Request $request, Response $response, $args) {
    secureUserLayer('login');
    return $response;
});
$app->any('/register', function (Request $request, Response $response, $args) {
    defaultLayers('register');
    return $response;
});
$app->any('/account', function (Request $request, Response $response, $args) {
    secureUserLayer('account');
    return $response;
});
$app->any('/account/transaction', function (Request $request, Response $response, $args) {
    secureUserLayer('transaction');
    return $response;
});
$app->any('/account/fund-transfer', function (Request $request, Response $response, $args) {
    secureUserLayer('fund-transfer');
    return $response;
});
$app->any('/account/verify-cheque', function (Request $request, Response $response, $args) {
    secureUserLayer('verify-cheque');
    return $response;
});
$app->any('/welcome', function (Request $request, Response $response, $args) {
    secureUserLayer('otp');
    return $response;
});
$app->any('/account/security', function (Request $request, Response $response, $args) {
    secureUserLayer('security');
    return $response;
});
$app->any('/account/contact', function (Request $request, Response $response, $args) {
    secureUserLayer('contact');
    return $response;
});
$app->any('/account/changepass', function (Request $request, Response $response, $args) {
    secureUserLayer('changepass');
    return $response;
});
$app->any('/account/changepin', function (Request $request, Response $response, $args) {
    secureUserLayer('changepin');
    return $response;
});
$app->any('/logout', function (Request $request, Response $response, $args) {
    secureUserLayer('logout');
    return $response;
});
$app->any('/admin/login', function (Request $request, Response $response, $args) {
    secureAdminLayer('login');
    return $response;
});
$app->any('/admin/logout', function (Request $request, Response $response, $args) {
    secureAdminLayer('logout');
    return $response;
});
$app->any('/admin', function (Request $request, Response $response, $args) {
    secureAdminLayer('login');
    return $response;
});
$app->any('/admin/{pages}', function (Request $request, Response $response, $args) {
    secureAdminLayer('admin',$args['pages']);
    return $response;
});
$app->any('/admin/view_client/{pages}', function (Request $request, Response $response, $args) {
    secureAdminLayer($args['pages'],'view_client');
    return $response;
});
$app->any('/admin/view_register/{pages}', function (Request $request, Response $response, $args) {
    secureAdminLayer($args['pages'],'view_register');
    return $response;
});
$app->any('/fpass', function (Request $request, Response $response, $args) {
    require 'views/fpass.php';
    return $response;
});
$app->any('/faqs', function (Request $request, Response $response, $args) {
    defaultLayers('faqs');
    return $response;
});
$app->run();

?>