Your IP : 216.73.216.91


Current Path : /var/www/html/llcfapp/api/
Upload File :
Current File : /var/www/html/llcfapp/api/index.php

<?php 
require_once('autoload.php');
if (session_status() == PHP_SESSION_NONE) {
	session_start();
}
if(!isset($_SESSION['login']) || !$_SESSION['login']){
	echo json_encode(['status' => false, 'error' => 'Authentication failed']);
	exit();
}
$validApiConsumers = Config::getConsumerNamesAgainstApiKeys();
if(isset($_REQUEST['auth']) && $_REQUEST['auth'] != '' && isset($validApiConsumers[$_REQUEST['auth']])){
	$consumerName = $validApiConsumers[$_REQUEST['auth']];
}else{
	$consumerName = 'Invalid';
}
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$resource = (isset($_REQUEST['resource'])) ? $_REQUEST['resource'] : '';
require_once('controller/'.$resource.'.php');
$obj = new $resource();
$mendetoryParam = $obj->validateRequestsParams();
if(isset($_REQUEST['action']) && isset($mendetoryParam[$action]) && isset($_REQUEST['auth']) && $_REQUEST['auth'] != ''){
	$data = array();
	$missingFields = array();
	$invalidFields = array();
	$validApiKeys = Config::getValidApiKeys();
	if (!in_array($_REQUEST['auth'], $validApiKeys)) {
		$invalidFields[] = "auth";
	}
	if (count($mendetoryParam[$_REQUEST['action']]) > 0) {
		foreach($mendetoryParam[$_REQUEST['action']] as $value){
			if(!isset($_REQUEST[$value]) || $_REQUEST[$value] == ''){
				$missingFields[] = $value;
			}	
		}
	}
	if(count($missingFields) > 0 || count($invalidFields) > 0){
		$data['status'] =  'false';
		$data['error'] =  'Required parameter(s) missing or have invalid value(s)';
		$data['missingParameters'] = implode(',',$missingFields);
		$data['invalidParameters'] = implode(',',$invalidFields);
		$response = $data;
	}else{
		$data = $_REQUEST;
		unset($data['resource']);
		unset($data['action']);
		unset($data['auth']);
		unset($data['response_type']);
		$action = (string)$_REQUEST['action'];
		$response = $obj->$action($data);
	}
	if(!isset($_REQUEST['response_type']) || $_REQUEST['response_type'] == 'json'){
		echo json_encode($response);
	}else{
		echo "<pre>";
		print_r($response);
	}
}else{
	echo json_encode(['status'=>false,'error'=>'Invalid action or auth']);
}
?>