<?php
require_once('inc/loader.php');
require_once('inc/login.php');
$filter = ['token' => $_COOKIE['econtoken']];
$result = $auth->getApiDataFilter("get/user", $filter);
$user = $result[0];
if ($_SERVER['HTTP_HOST'] != APPURL && !isset($user->email)) {
    die("Not Authorized Acces");
} else {
    $reqUrl = substr($_SERVER['REQUEST_URI'], 6);
    if (strpos($reqUrl, '?') > 0) {
        $reqUrl = substr($reqUrl, 0, (strlen($reqUrl) - strpos($reqUrl, '?')) * -1);
    }
    //echo $reqUrl;
}
$data = $_GET;
//KIVÉTELEK!!!!!
if ($reqUrl == "get/partner") {
    if($user->accesslevel>1){
        $data['companySales']=$user->id;
        $result = $auth->getApiDataFilter("get/partner",$data);
    }else{
        $result = $auth->getApiData("get/partner");
    }
}
//KIVÉTELEK!!!!!
if ($reqUrl == "get/partner/search") {
    if($user->accesslevel>1){
        $data['companySales']=$user->id;
        $result = $auth->getApiDataFilter("get/partner/search",$data);
    }else{
        $data['companySales']=$user->id;
        $result = $auth->getApiDataFilter("get/partner/search",$data);
    }
}
//echo $reqUrl;
if(isset($_POST)&&$_POST!=[]){
    $data = $_POST;
    $res = $auth->getApiDataFilter($reqUrl, $data);
} else if (isset($_GET)&&$_GET!=[]) {
    $data = $_GET;
    $res = $auth->getApiDataFilter($reqUrl, $data);
}else {
    $filter = [];
    $res = $auth->getApiData($reqUrl);
}
////print_r($res);
$res = json_encode($res);
print_r($res);
