<?php
include("zoho-work-drive-refresh-token.php");
$department_brand_folders = [
    'Customer Brand Perception' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    'Lorem Ipsum' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
];
if (array_key_exists('Customer Brand Perception', $department_brand_folders)) {
    $resource_id = $department_brand_folders['Customer Brand Perception'];
    
    $token = $value["access_token"];
    $postFields = array(
                            'data' => array(
                                'attributes' => array(
                                    'resource_id' => $resource_id,
                                    'shared_type' =>  "publish",
                                    'role_id' => "6" 
                                    ),
                                'type' => "permissions"  
                            )
                    );
                    
    $data_to_post = json_encode($postFields);
    $curl_variable = curl_init();
    curl_setopt($curl_variable, CURLOPT_URL, $curl_url);
    curl_setopt($curl_variable, CURLOPT_POST, 1);
    curl_setopt($curl_variable, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_variable, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl_variable, CURLOPT_POSTFIELDS, $data_to_post);
    curl_setopt($curl_variable, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $token, 'cache-control: no-cache'));
    $response = curl_exec($curl_variable);
    $err = curl_error($curl_variable);
    if ($err) {
        echo "cURL Error #:" . $err;
    } else{
        $data = json_decode($response,true);
        $link = $data['data']['attributes']['permalink'];
    }
} else{
    echo '<br>';
    echo '<pre>';
    echo "ERROR";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
            body, html
            {
                margin: 0; padding: 0; height: 100%; overflow: hidden;
            }
            #content
            {
                position:absolute; left: 0; right: 0; bottom: 0; top: 0px; 
            }
        </style>
</head>
<body>
    <div id="content">
         <iframe width="100%" height="100%" frameborder="0" src=<?php echo $link ?>></iframe>
    </div>     
</body>
</html>