<?php
namespace App\Http\Controllers\v2019;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\JsonResponse;

class TendersController extends Controller
{ 
    public function __construct(Request $request) {
        if($request->has('debug') && $request->input('debug') == true) {
            $this->debug = true;			
        }
    }
	
	public function getTenders(Request $request)
    {      
		$result = array();;

		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/web/web_tenders_pre.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/web_tenders_post.php";
			}
		} else {
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			// $auth = new authentication();
				$token = $request->input('accessToken');
				if($token==''){
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tenders_pre.php";
					$code = 2013;
					$message = "User not found.";
				}else{
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tenders_post.php";
					$code = 1001;
					$message = "Success";
				}
			}else{
				//if($source=='home')
					include_once "/home/steelmin/public_html/api/storage/v2019/tenders_pre.php";
				
				$code = 1001;
				$message = "Success";
			}
		}	
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    }  
	
	public function getTendersFilter(Request $request)
    {      
		$result = array();
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/tender_filter_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/tender_filter_post.php";
			}
		} else {
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			// $auth = new authentication();
				$token = $request->input('accessToken');
				if(empty($token)){
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tender_filter_post.php";
					$code = 2013;
					$message = "User not found.";
				}else{
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tender_filter_post.php";
					$code = 1001;
					$message = "Success";
				}
			}else{
				//if($source=='home')
					include_once "/home/steelmin/public_html/api/storage/v2019/tender_filter_post.php";
				
				$code = 1001;
				$message = "Success";
			}
	  }	
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}
	
	public function getTendersCommodityCount(Request $request)
    {      
		$result = array();
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
				include_once "/home/steelmin/public_html/api/storage/v2019/tender_count_post.php";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/tender_count_post.php";
			}
		} else {
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			// $auth = new authentication();
				$token = $request->input('accessToken');
				if(empty($token)){
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tender_count_post.php";
					$code = 2013;
					$message = "User not found.";
				}else{
					//if($source=='home')
						include_once "/home/steelmin/public_html/api/storage/v2019/tender_count_post.php";
					$code = 1001;
					$message = "Success";
				}
			}else{
				//if($source=='home')
					include_once "/home/steelmin/public_html/api/storage/v2019/tender_count_post.php";
				
				$code = 1001;
				$message = "Success";
			}
	}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}
	
	
	public function getTendersCollection(Request $request)
    {      
		$result = array();
		///$source = $request->input('source');
		include_once "/home/steelmin/public_html/api/storage/v2019/tenders_collection_list.php";
		$resourceType = "APP";		
		if ($request->has('resourceType'))
			$resourceType = strtolower($request->input('resourceType'));
		
		if($resourceType=='web'){
			$code = 1001;
			$message = "Success";
			if ($request->has('memid') && $request->input('memid')!=''){
			 //	
			}else{
			 // 
			}
		} else {
			if ($request->has('accessToken') && $request->input('accessToken')!='') {
			// $auth = new authentication();
				$token = $request->input('accessToken');
				if(empty($token)){
					
					$code = 2013;
					$message = "User not found.";
				}else{
					$code = 1001;
					$message = "Success";
				}
			}else{
				
				$code = 1001;
				$message = "Success";
			}
	 }
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
	}

	public function getTenderDetails(Request $request)
    {      
		$result = array();
		$source = $request->input('source');
		
		if ($request->has('memid') && $request->input('memid')!='') {
           // $auth = new authentication();
            $token = $request->input('memid');
			if($token == ''){
				include_once "/home/steelmin/public_html/api/storage/v2019/web/tenders_details_pre.php";
				$code = 2013;
				$message = "User not found.";
			}else{
				include_once "/home/steelmin/public_html/api/storage/v2019/web/tenders_details_post.php";
				$code = 1001;
				$message = "Success";
			}
        }else{
			include_once "/home/steelmin/public_html/api/storage/v2019/web/tenders_details_pre.php";
			$code = 1001;
			$message = "Success";
		}
	   return new JsonResponse(array("status"=>array("code" => $code, "message" => $message), "data"=> $result));
    }
	
}
