File: /home/awaldron/_accomods/api.accomods.com/index.php
<?php
/*
header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Authorization, Origin');
header('Access-Control-Max-Age: 86400');
*/
// Access-Control headers are received during OPTIONS requests
if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
// may also be using PUT, PATCH, HEAD etc
header("Access-Control-Allow-Methods: GET, POST, PUT, HEAD, DELETE, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
exit(0);
}
error_reporting(E_ALL);
// DECLARE GLOBALS
$host = 'api.accomods.com';
define('ROOT_DIR', '/alanwaldron.com/home/awaldron/_accomods/'.$host);
require_once 'vendor/Exception.php';
require_once 'vendor/PHPMailer.php';
require_once 'vendor/SMTP.php';
require_once 'vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// INCLUDE OUR FUNCTION FILES
require_once "v1/_globals.php";
require_once "v1/_pdf_template.php";
require_once "v1/auth.php";
require_once "v1/order.php";
require_once "v1/school.php";
require_once "v1/thrive.php";
require_once "v1/pdf.php";
//// SET CORS POLICY
//cors();
// PARSE THE URL AND DATA
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', substr($_SERVER['REQUEST_URI'],1));
$function = strtolower($method.'_'.$request[0].'_'.$request[1].'_'.$request[2]);
// remove the first 3 items from the request
array_shift($request);
array_shift($request);
array_shift($request);
// format the post body
$body = [];
$postBody = file_get_contents('php://input');
if ( strlen($postBody) > 0 ) {
$body = json_decode( $postBody, true );
}
// Connect to the database
$db = dbconnect();
// Check the token
//$auth_user = check_token( $db, $_SERVER['HTTP_AUTHORIZATION'] );
// Check if user is an Admin
$is_admin = false; // empty($auth_user) ? false : !!qVal( $db, "SELECT admin FROM users WHERE user_id=".$auth_user." AND admin=1");
// Call the endpoint
if (function_exists($function)) {
call_user_func($function, $request, $body, $auth_user, $is_admin, $db);
} else {
response( 404, ['success'=>false,'error'=>'Endpoint not found: '.$function] );
}