Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terug naar eerste versie #68

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
versie 2
  • Loading branch information
SpectiaDigital authored Jul 26, 2024
commit de65cb614346886c6a79c2562188019db5e0c48a
95 changes: 93 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,94 @@
<?php
<!doctype html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Visor de Reportes PBI</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap.min.css" integrity="sha512-Vk7tk4y6z5+Yi54gyCN+DmxbWQPKK1lLZL6yCwuK7cV9Wm+j1l0lRlLU98e2vNLRr6t98kKGy3RlsJSzdF8uw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<link rel="stylesheet" href="css/styles.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="./dist/powerbi.js"></script>
</head>
<body>
<div id="reportContainer" style="background-color:white"></div>
<!--class="h-100 h-720-sm h-1080-lg -->
<?php

//get URL parameters
if(!is_null($_GET['group']) && !is_null($_GET['reports']))
{
$group = $_GET['group'];
$reports = $_GET['reports'];
$filters = $_GET['filters'];
$refresh = $_GET['refresh'];
$params = $_GET['p'];
include 'process.php';
//echo $params;
};
?>
<script>
// Obtener el alto de la pantalla
//var screenHeight = window.innerHeight;

// Definir las alturas para pantallas pequeñas y grandes
//var smallScreenHeight = 720;
//var largeScreenHeight = 1080;

// Definir la altura del div en función del tamaño de la pantalla
//var reportContainer = document.getElementById('reportContainer');
//if (screenHeight < largeScreenHeight) {
// reportContainer.style.height = smallScreenHeight + 'px';
//} else {
// reportContainer.style.height = largeScreenHeight + 'px';
//}
// Obtener el alto de la pantalla
var screenHeight = window.innerHeight;
var devicePixelRatio = window.devicePixelRatio || 1;

// Definir la altura del div en función de la pantalla
var reportContainer = document.getElementById('reportContainer');
reportContainer.style.height = (screenHeight) + 'px';
// Obtengo los modelos para configuración de pbiEmbed
var models = window['powerbi-client'].models;
var embedConfiguration= {
type: 'report',
embedUrl: "<?php echo $embedUrl; ?>",
accessToken: "<?php echo $token; ?>",
permissions: models.Permissions.Read,
settings: {
//background: models.BackgroundType.Transparent,
panes:{
bookmarks: {
visible: false
},
fields: {
expanded: true
},
filters: {
expanded: false,
visible: <?php if($filters == "1"){
echo "true";
}else{
echo "false";}?>
},
pageNavigation: {
visible: true
},
selection: {
visible: true
},
syncSlicers: {
visible: true
},
visualizations: {
expanded: true
}
}
}
};

echo "Hello World!";
var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);

</script>
</body>
</html>
74 changes: 74 additions & 0 deletions process.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

<?php
//Start authentication for masterUser using appid, user and psw as message parameters
$url = 'https://login.windows.net/common/oauth2/token';
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"client_id=6d1f09f3-30d3-48ba-a2bc-276644eddf35&grant_type=password&username=reportes@gelcointernational.com&password=Row25050&resource=https://analysis.windows.net/powerbi/api");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));


// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec ($ch);

curl_close ($ch);
$arreglo = json_decode($server_output, true);
//get the connection token
$token = $arreglo['access_token'];
$embeddedToken = "Bearer " . ' ' . $token;
if ($params == ""){
$uri = "https://api.powerbi.com/v1.0/myorg/groups/".$group."/reports/".$reports;
}
else {
$uri = "https://api.powerbi.com/v1.0/myorg/groups/".$group."/reports/".$reports."?rp:".$params;
}
//echo $uri;
/* ---------------------- Sección 1 -----------------------------------*/
//begin the second stage of the process: bring the report through the embedUrl and then show it with the script
$curlGetUrl = curl_init();
curl_setopt_array($curlGetUrl, array(
CURLOPT_URL => $uri,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: $embeddedToken",
"Cache-Control: no-cache",
),
));
$embedResponse = curl_exec($curlGetUrl);
$embedError = curl_error($curlGetUrl);
curl_close($curlGetUrl);
// Obtengo el Dataset ID
$arreglo1 = json_decode($embedResponse, true);
$datasetID = $arreglo1['datasetId'];
//echo "DatasetId: ", $datasetID." GroupID: ".$group." Token: ".$embeddedToken;

//Start of dataset refresh stage
if ($update="1"){
$actDs = curl_init();
curl_setopt($actDs, CURLOPT_URL,$url);
curl_setopt($actDs, CURLOPT_POST, 1);
curl_setopt($actDs, CURLOPT_URL,"https://api.powerbi.com/v1.0/myorg/groups/".$group."/datasets/".$datasetID."/refreshes");
curl_setopt($actDs, CURLOPT_HTTPHEADER, array( "Authorization: $embeddedToken", "Cache-Control: no-cache",));
curl_setopt($actDs, CURLOPT_RETURNTRANSFER, true);
$respuesta1 = curl_exec ($actDs);
curl_close ($actDs);
}
//define embed Url to present with JS
if ($embedError) {
echo "cURL Error #:" . $embedError;
} else {
$embedResponse = json_decode($embedResponse, true);
$embedUrl = $embedResponse['embedUrl'];
}

?>