<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public $apicall;
    public $manager;

    public function makeconnection()
    {
        $this->apicall = 'http://185.2.103.78:17019/ManagerAPILive/';
        $url = $this->apicall . 'INITIAL_ADD_MANAGER';

        $postdata = '{"ManagerID":2012,
					"CreatedBy":0 ,
					"Manager_Index":0,
					"oStatus":1,
					"Password":"s7wrsNs",
					"ServerConfig":"209.126.104.34:443",
					"ServerCODE":"Live",
					"oDemo":1}';


        $ch = curl_init($url);
        # Setup request to send json via POST.

        curl_setopt($ch, CURLOPT_POSTFIELDS,  $postdata);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        # Return response instead of printing.
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        # Send request.
        $result = curl_exec($ch);
        if ($result == false) {
            dd('Site under maintenance');
        }
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            //dd($error_msg);
        }
        $getdata = json_decode($result);
        curl_close($ch);

        $this->manager = $getdata->Result;
    }
}
