<?php
// include the SSRS library
require_once 'SSRSReport.php';
define("REPORT", "/AdventureWorks 2008 Sample Reports/TopStoresBegin");
$settings = parse_ini_file("app.config", 1);
// Create a connection to the SSRS Server
$rs = new SSRSReport(new Credentials($settings["UID"],
$settings["PASWD"]),
$settings["SERVICE_URL"]);
// Load the report and specify the params required for its execution
$executionInfo = $rs->LoadReport2(REPORT, NULL);
$parameters = array();
$parameters[0] = new ParameterValue();
$parameters[0]->Name = "ProductCategory";
$parameters[0]->Value = "1";
$parameters[1] = new ParameterValue();
$parameters[1]->Name = "StartDate";
$parameters[1]->Value = "1/1/2003";
$parameters[2] = new ParameterValue();
$parameters[2]->Name = "EndDate";
$parameters[2]->Value = "12/31/2003";
$parameters[3] = new ParameterValue();
$parameters[3]->Name = "ProductSubcategory";
$parameters[3]->Value = "2";
$rs->SetExecutionParameters2($parameters);
// Require the Report to be rendered in HTML format
$renderAsHTML = new RenderAsHTML();
// Set the links in the reports to point to the php app
$renderAsHTML->ReplacementRoot = getPageURL();
// Set the root path on the server for any image included in the report
$renderAsHTML->StreamRoot = './images/';
// Execute the Report
$result_html = $rs->Render2($renderAsHTML,
PageCountModeEnum::$Actual,
$Extension,
$MimeType,
$Encoding,
$Warnings,
$StreamIds);
// Save all images on the server (under /images/ dir)
foreach($StreamIds as $StreamId)
{
$renderAsHTML->StreamRoot = null;
$result_png = $rs->RenderStream($renderAsHTML,
$StreamId,
$Encoding,
$MimeType);
if (!$handle = fopen("./images/" . $StreamId, 'wb'))
{
echo "Cannot open file for writing output";
exit;
}
if (fwrite($handle, $result_png) === FALSE)
{
echo "Cannot write to file";
exit;
}
fclose($handle);
}
// include the Report within a Div on the page
echo '<html><body><br/><br/>';
echo '<div align="center">';
echo '<div style="overflow:auto; width:700px; height:600px">';
echo $result_html;
echo '</div>';
echo '</div>';
echo '</body></html>';
?>