Skip to content

Instantly share code, notes, and snippets.

@atapatel
Created January 5, 2021 07:23
Show Gist options
  • Save atapatel/67015b08cbec15b2e96b435cdde695af to your computer and use it in GitHub Desktop.
Save atapatel/67015b08cbec15b2e96b435cdde695af to your computer and use it in GitHub Desktop.
Viewer Wave Php file
<?php
require_once 'stimulsoft/helper.php';
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Stimulsoft Reports.PHP - JS Viewer</title>
<!-- Office2013 style -->
<link href="css/stimulsoft.viewer.office2013.whiteteal.css" rel="stylesheet">
<!-- Stimusloft Reports.JS -->
<script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
<!-- <script src="scripts/stimulsoft.reports.maps.js" type="text/javascript"></script>-->
<!-- Stimusloft Dashboards.JS -->
<script src="scripts/stimulsoft.dashboards.js" type="text/javascript"></script>
<script src="scripts/stimulsoft.viewer.js" type="text/javascript"></script>
<script src="config.js" type="text/javascript"></script>
<?php
StiHelper::init('handler.php', 30);
?>
<script type="text/javascript">
newCorsXHR = function(type, url) {
var xhr = false;
try {
xhr = new XMLHttpRequest();
} catch(e) {}
if (xhr && "withCredentials" in xhr) {
xhr.open(type, url, true); // Standard Cors request
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest(); // IE Cors request
xhr.open(type, url);
xhr.onload = function() {
this.readyState = 4;
if (this.onreadystatechange instanceof Function) this.onreadystatechange();
};
} else if (xhr) {
xhr.open(type, url, true);
}
return xhr;
};
</script>
<script type="text/javascript">
Stimulsoft.Base.StiLicense.loadFromFile("stimulsoft/license.php");
Stimulsoft.StiOptions.Engine.useSyncRenderMode = true;
var arguments = [{}, ()=>{}];
var orgSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function () {
var args = [].slice.call(arguments);
this.setRequestHeader('Authorization', JSON.parse(localStorage.getItem('authToken')));
orgSend.apply(this, args);
};
var options = new Stimulsoft.Viewer.StiViewerOptions();
options.appearance.fullScreenMode = true;
options.toolbar.showSendEmailButton = true;
options.toolbar.displayMode = Stimulsoft.Viewer.StiToolbarDisplayMode.Separated;
options.height = "600px"; // Height for non-fullscreen mode
var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
// Process SQL data source
viewer.onBeginProcessData = function (event, callback) {
<?php StiHelper::createHandler(); ?>
}
// Manage export settings on the server side
viewer.onBeginExportReport = function (args) {
<?php //StiHelper::createHandler(); ?>
//args.fileName = "MyReportName";
}
// Process exported report file on the server side
/*viewer.onEndExportReport = function (event) {
event.preventDefault = true; // Prevent client default event handler (save the exported report as a file)
}*/
// Send exported report to Email
viewer.onEmailReport = function (event) {
<?php StiHelper::createHandler(); ?>
}
var getParams = query => {
if (!query) {
return {};
}
return (/^[?#]/.test(query) ? query.slice(1) : query)
.split('&')
.reduce((params, param) => {
var paramArray = param.split('=');
var key = paramArray.shift();
var value = paramArray.join('=');
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : '';
return params;
}, {});
};
var pageUrl = window.location.href;
var queryQbject = getParams(pageUrl.split('?').pop());
// Load and show report
var report = new Stimulsoft.Report.StiReport();
// report.loadFile("reports/SimpleList.mrt");
// viewer.report = report;
var xhr = newCorsXHR("GET", stimulSoftConfig.apiBaseUrl + 'cloud/report/' + queryQbject.id + '/content');
// // Set future closure
xhr.onreadystatechange=function() {
if (xhr.readyState == 4) {
var responseJSON = xhr.responseText;
// var cleanedResponse = responseJSON.substring(0,responseJSON.indexOf('<link '));
// console.log(cleanedResponse);
report.load(JSON.parse(xhr.responseText));
var database = new Stimulsoft.Report.Dictionary.StiMySqlDatabase("Client", "Client", queryQbject.client_db, false);
report.dictionary.databases.clear();
report.dictionary.databases.add(database);
viewer.report = report;
viewer.renderHtml("viewerContent");
}
};
// Initiate the request
xhr.send();
function onLoad() {
//viewer.renderHtml("viewerContent");
}
</script>
</head>
<body onload="onLoad();">
<div id="viewerContent"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment