<?php

	include '../include/connection.php';
	
	$data = file_get_contents('php://input');
	$dataDecode = json_decode($data, true);

	$name = $dataDecode['email'];
	$password = $dataDecode['password'];


	
	$query = "SELECT * FROM tbl_user WHERE email_user = '$name' AND password = '$password'";
	$check = mysqli_fetch_array(mysqli_query($conn, $query));
	$getData = mysqli_fetch_assoc(mysqli_query($conn, $query));

	if (isset($check)) {

		$scs = 'Successfully login';
		$array = [$getData['id_user'], 
				$getData['name_user'], 
				$getData['email_user'], 
				$getData['photo_user'],
				$getData['hp'],
				$getData['alamat'],
				$getData['lahir'],
				$scs];
		echo json_encode($array);
		
		
		
	}else{
		$invalidSuccess = 'Name or password incorrect or Account not exist';
		$failedMsg = json_encode($invalidSuccess);
		echo $failedMsg;
	}
	mysqli_close($conn);
	
	
	$email = $_POST['email'];
	$password = $_POST['password'];
	
	$curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://penastudio.id/pi/ebook/public/api/login',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_POSTFIELDS => array('email' => $email, 'password' => $password),
      CURLOPT_HTTPHEADER => array(
        'Cookie: PHPSESSID=".$_COOKIE["PHPSESSID"]."'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo '<br>'.$response;
	
	
	$curl = curl_init();

    curl_setopt_array($curl, array(
      CURLOPT_URL => 'https://penastudio.id/pi/akademi/api/login?email='.$email.'&password='.$password,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'Cookie: PHPSESSID=".$_COOKIE["PHPSESSID"]."'
      ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo '<br>'.$response;
    
    $curl = curl_init();
    
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://penastudio.id/pi/store/api/v1/auth/login',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS => array('email' => $email, 'password' =>  $password),
        CURLOPT_HTTPHEADER => array(
        'Cookie: PHPSESSID=".$_COOKIE["PHPSESSID"]."'
    ),
    ));
    
    $response = curl_exec($curl);
    
    curl_close($curl);
    echo '<br>'.$response;
        

?>