
<center><h2><strong>Ubuntu</strong></h2>
­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
    session_start();

$_SESSION['CROUGE']['Sites']=[];
error_reporting(E_ALL);
ini_set("display_errors", 0);
require "gestion.lib.php";

$CRouge = new CRouge();

$refresh_token  = "1000.fe3f0d89d1928355a5f8da32083669ba.e0ad331744b086fdc06eda48ea013e90";
$client_id      = "1000.KL48ACSNU2NS34520ESYY3FWZUBS0E";
$client_secret  = "3b4a8173e9dbd396aaeb2603db7560f5ff9a323bb6";

//  1/ Refresh le token initial

$refresh_token  = "1000.fe3f0d89d1928355a5f8da32083669ba.e0ad331744b086fdc06eda48ea013e90"; // Si l acces token change il faut changer ce code
$Url            = "https://accounts.zoho.com/oauth/v2/token?refresh_token=$refresh_token&client_id=$client_id&client_secret=$client_secret&grant_type=refresh_token";
$Param          = ['url'=>$Url,'method'=>'POST'];
$Result         = $CRouge->MyCurl_APIZOHO_V2($Param);
$Result         = json_decode($Result,TRUE );
$Token          = "Zoho-oauthtoken ".$Result['access_token'];

//echo $Token;

/*
$Url            = "https://www.zohoapis.com/crm/v2/Accounts/search?criteria=(Parent_Account:starts_with:LA%20CROIX*)&page=1";
$Param2         = ['url'=>$Url,'method'=>'GET','header'=>["Authorization: $Token","contentType: application/json"]];
$Result         = $CRouge->MyCurl_APIZOHO_V2($Param2);
$Result         = json_decode($Result,TRUE );
echo "<pre>";
print_r($Result);
echo "</pre>";
exit;
*/
//  2/ Liste les comptes

// 10
for($index=1; $index < 10; $index++) {

//    $Url = "https://www.zohoapis.com/crm/v2/Sites_Croix_Rouge?page=" . $index;
    $Url = "https://www.zohoapis.com/crm/v2/Accounts/search?criteria=(Parent_Account:starts_with:LA%20CROIX*)&page=" . $index;
//Parent_Account

//$Url    = "https://crm.zoho.com/crm/private/json/Sites_Croix_Rouge/getRecords?authtoken=".$Result['access_token']."&scope=crmapi&fromIndex=20&toIndex=200&sortColumnString=Account%20Name&sortOrderString=asc&newFormat=2";

    $Param2 = ['url' => $Url, 'method' => 'GET', 'header' => ["Authorization: $Token", "contentType: application/json"]];
    $Result = $CRouge->MyCurl_APIZOHO_V2($Param2);
    $Result2 = json_decode($Result, TRUE);


    $i = 0;
    foreach ($Result2['data'] as $Key => $Dtl) {
        $i = uniqid();
        $Rslt[$Dtl['Account_Name']] = "<option value='".$i."' >".trim($Dtl['Account_Name'])."</option>";
    //  SESSION EMAIL<=>SITE
        $_SESSION['CROUGE']['Sites'][$i] = $Dtl['Mail_Facturation']."|".trim($Dtl['Account_Name']."|".$Dtl['Account_Type']."|".$Dtl['id']);
    }
}
// Inject la liste dans MySQL
$CRouge->InjectSites();

//  Tri
    ksort($Rslt);
//  DEBUG : affichage
//    echo "<pre>"; print_r($Rslt); echo "</pre>";
//  Charge
/*
    foreach($Rslt as $NomChamp=>$Obj) {
    echo $Obj;
    }*/
?>

