Files
Commerce/admin/index.php
2025-03-07 15:07:15 +01:00

52 lines
2.3 KiB
PHP

<?php
define('admin', true);
//error reporting
// Determine the base URL
$base_url = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] === 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'https' : 'http';
$base_url .= '://' . rtrim($_SERVER['HTTP_HOST'], '/');
$base_url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 || strpos($_SERVER['HTTP_HOST'], ':') !== false ? '' : ':' . $_SERVER['SERVER_PORT'];
$base_url .= '/' . ltrim(substr(str_replace('\\', '/', realpath(__DIR__)), strlen($_SERVER['DOCUMENT_ROOT'])), '/');
define('base_url', rtrim($base_url, '/') . '/');
session_start();
// Include the configuration file, this contains settings you can change.
include '../custom/settings/config.php';
// Include functions and connect to the database using PDO MySQL
include '../functions.php';
// Connect to MySQL database
$pdo = pdo_connect_mysql();
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
//LOGIN TO API
//+++++++++++++++++++++++++++++++++++++++++++++++++++++
$data = json_encode(array("clientID" => clientID, "clientsecret" => clientsecret), JSON_UNESCAPED_UNICODE);
$responses = ioAPIv2('/v2/authorization', $data,'');
//Decode Payload
if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';}
$clientsecret = $responses['token'];
// If the user is not logged-in redirect them to the login page
if (!isset($_SESSION['account_loggedin'])) {
header('Location: ' . url('../index.php?page=myaccount'));
exit;
}
// If the user is not admin redirect them back to the shopping cart home page
$account = ioAPIv2('/v2/identity/userkey='.$_SESSION['account_id'].'&isverified=1','',$clientsecret);
$account = json_decode($account,true);
if (!$account || $account[0]['profile'] != 1) {
header('Location: ' . url('../index.php'));
exit;
}
// Page is set to home (home.php) by default, so when the visitor visits that will be the page they see.
$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'settings';
if (isset($_GET['page']) && $_GET['page'] == 'logout') {
session_destroy();
header('Location: ' . url('../index.php'));
exit;
}
// Output error variable
$error = '';
// Include the requested page
include $page . '.php';
?>