完善打印相关功能

去掉无用的前端文件
修改版权描述
This commit is contained in:
2021-02-26 05:52:52 +08:00
parent 37229cac4a
commit 427dabb95d
101 changed files with 442 additions and 7350 deletions
-15
View File
@@ -1,15 +0,0 @@
<html>
<head>
<title>Stimulsoft Reports.PHP</title>
</head>
<body>
Stimulsoft Reports.PHP (JS version) - How to Activate
<hr><br>
The Trial version of the product does not contain any restrictions, except for the Trial watermark on the report pages.<br><br>
To activate the product, it is enough to copy the 'license.key' file to the 'stimulsoft' subfolder of this project (in the same place, where is the 'license.php' file is located). The license will be loaded automatically. You can add some conditions in the 'license.php' script to load the license file, if it required for security.
<br><br>
<a href="index.php">Back</a>
</body>
-63
View File
@@ -1,63 +0,0 @@
<?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 Designer</title>
<!-- Office2013 style -->
<link href="css/stimulsoft.viewer.office2013.whiteblue.css" rel="stylesheet">
<link href="css/stimulsoft.designer.office2013.whiteblue.css" rel="stylesheet">
<!-- Stimulsoft Reports.JS -->
<script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
<script src="scripts/stimulsoft.viewer.js" type="text/javascript"></script>
<script src="scripts/stimulsoft.designer.js" type="text/javascript"></script>
<?php
$options = StiHelper::createOptions();
$options->handler = "handler.php";
$options->timeout = 30;
StiHelper::initialize($options);
?>
<script type="text/javascript">
//Stimulsoft.Base.StiLicense.loadFromFile("stimulsoft/license.php");
var options = new Stimulsoft.Designer.StiDesignerOptions();
options.appearance.fullScreenMode = true;
options.toolbar.showSendEmailButton = true;
options.appearance.showLocalization = false;
options.appearance.zoom = 130;
Stimulsoft.Base.Localization.StiLocalization.addLocalizationFile("localization/zh-CHS.xml", false, "Chinese (Simplified)");
Stimulsoft.Base.Localization.StiLocalization.cultureName = "Chinese (Simplified)";
var designer = new Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
// Process SQL data source
designer.onBeginProcessData = function (event, callback) {
<?php StiHelper::createHandler(); ?>
}
// Save report template on the server side
designer.onSaveReport = function (event) {
<?php StiHelper::createHandler(); ?>
}
// Load and design report
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/SimpleList.mrt");
designer.report = report;
function onLoad() {
designer.renderHtml("designerContent");
}
</script>
</head>
<body onload="onLoad();">
<div id="designerContent"></div>
</body>
</html>
-94
View File
@@ -1,94 +0,0 @@
<?php
require_once 'stimulsoft/helper.php';
error_reporting(0);
// Please configure the security level as you required.
// By default is to allow any requests from any domains.
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Engaged-Auth-Token");
$handler = new StiHandler();
$handler->registerErrorHandlers();
$handler->onBeginProcessData = function ($event) {
// Current database type: 'XML', 'JSON', 'MySQL', 'MS SQL', 'PostgreSQL', 'Firebird', 'Oracle'
$database = $event->database;
// Current connection name
$connection = $event->connection;
// Current data source name
$dataSource = $event->dataSource;
// Connection string for the current data source
$connectionString = $event->connectionString;
// SQL query string for the current data source
$queryString = $event->queryString;
// You can change the connection string
//if ($connection == "MyConnectionName")
// $event->connectionString = "Server=localhost;Database=test;Port=3306;";
// You can change the SQL query
//if ($dataSource == "MyDataSource")
// $event->queryString = "SELECT * FROM MyTable";
// You can replace the SQL query parameters with the required values
// For example: SELECT * FROM {Variable1} WHERE Id={Variable2}
// If the report contains a variable with this name, its value will be used instead of the specified value
//$event->parameters["Variable1"] = "TableName";
//$event->parameters["Variable2"] = 10;
return StiResult::success();
//return StiResult::error("Message for some connection error.");
};
$handler->onPrintReport = function ($event) {
return StiResult::success();
};
$handler->onBeginExportReport = function ($event) {
$settings = $event->settings;
$format = $event->format;
return StiResult::success();
};
$handler->onEndExportReport = function ($event) {
$format = $event->format; // Export format
$data = $event->data; // Base64 export data
$fileName = $event->fileName; // Report file name
file_put_contents('reports/'.$fileName.'.'.strtolower($format), base64_decode($data));
//return StiResult::success();
return StiResult::success("Export OK. Message from server side.");
//return StiResult::error("Export ERROR. Message from server side.");
};
$handler->onEmailReport = function ($event) {
$event->settings->from = "******@gmail.com";
$event->settings->host = "smtp.gmail.com";
$event->settings->login = "******";
$event->settings->password = "******";
};
$handler->onDesignReport = function ($event) {
return StiResult::success();
};
$handler->onCreateReport = function ($event) {
$fileName = $event->fileName;
return StiResult::success();
};
$handler->onSaveReport = function ($event) {
$report = $event->report; // Report object
$reportJson = $event->reportJson; // Report JSON
$fileName = $event->fileName; // Report file name
file_put_contents('reports/'.$fileName.".mrt", $reportJson);
return StiResult::success("保存成功:".$fileName);
};
$handler->onSaveAsReport = function ($event) {
return StiResult::success();
};
$handler->process();
-19
View File
@@ -1,19 +0,0 @@
<?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</title>
</head>
<body>
Stimulsoft Reports.PHP (JS version) - Quick Start Demo
<hr><br>
<a href="viewer.php">Open Report Viewer page</a><br>
<a href="designer.php">Open Report Designer page</a><br><br>
<a href="activate.php">How to Activate</a><br>
<a href="https://www.stimulsoft.com/en/documentation">Documentation</a><br>
</body>
</html>
-45
View File
@@ -1,45 +0,0 @@
<?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 - Render & Export</title>
<!-- Stimulsoft Reports.JS -->
<script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
<?php
$options = StiHelper::createOptions();
$options->handler = "handler.php";
$options->timeout = 30;
StiHelper::initialize($options);
?>
<script type="text/javascript">
function onLoad() {
// Load and show report
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/SimpleList.mrt");
// Process SQL data source
report.onBeginProcessData = function (event, callback) {
<?php StiHelper::createHandler(); ?>
}
report.renderAsync(function() {
var pdfData = report.exportDocument(Stimulsoft.Report.StiExportFormat.Pdf);
// Get report file name
var fileName = String.isNullOrEmpty(report.reportAlias) ? report.reportName : report.reportAlias;
// Save data to file
Stimulsoft.System.StiObject.saveAs(pdfData, fileName + ".pdf", "application/pdf");
});
}
</script>
</head>
<body onload="onLoad();">
Render & Export
</body>
</html>
@@ -1,181 +0,0 @@
<?php
class StiMsSqlAdapter {
private $connectionString = null;
private $connectionInfo = null;
private $link = null;
private $isMicrosoftDriver = false;
private function getLastErrorResult() {
$error = null;
if ($this->isMicrosoftDriver) {
if (($errors = sqlsrv_errors()) != null) {
$error = $errors[count($errors) - 1];
return StiResult::error("[".$error['code']."] ".$error['message']);
}
}
else $error = mssql_get_last_message();
if ($error) return StiResult::error($error);
return StiResult::error("Unknown");
}
private function connect() {
if ($this->isMicrosoftDriver) {
if (!function_exists("sqlsrv_connect")) return StiResult::error("MS SQL driver not found. Please configure your PHP server to work with MS SQL.");
$this->link = sqlsrv_connect(
$this->connectionInfo->host,
array(
"UID" => $this->connectionInfo->userId,
"PWD" => $this->connectionInfo->password,
"Database" => $this->connectionInfo->database,
"LoginTimeout" => 10,
"ReturnDatesAsStrings" => true,
"CharacterSet" => $this->connectionInfo->charset
));
if (!$this->link) return $this->getLastErrorResult();
}
else {
$this->link = mssql_connect($this->connectionInfo->host, $this->connectionInfo->userId, $this->connectionInfo->password);
if (!$this->link) return $this->getLastErrorResult();
$db = mssql_select_db($this->connectionInfo->database, $this->link);
mssql_close($this->link);
if (!$db) return $this->getLastErrorResult();
}
return StiResult::success();
}
private function disconnect() {
if (!$this->link) return;
$this->isMicrosoftDriver ? sqlsrv_close($this->link) : mssql_close($this->link);
}
public function parse($connectionString) {
$info = new stdClass();
$info->host = "";
$info->database = "";
$info->userId = "";
$info->password = "";
$info->charset = "UTF-8";
$parameters = explode(";", $connectionString);
foreach($parameters as $parameter) {
if (strpos($parameter, "=") < 1) continue;
$spos = strpos($parameter, "=");
$name = strtolower(trim(substr($parameter, 0, $spos)));
$value = trim(substr($parameter, $spos + 1));
switch ($name) {
case "server":
case "data source":
$info->host = $value;
break;
case "database":
case "initial catalog":
$info->database = $value;
break;
case "uid":
case "user":
case "user id":
$info->userId = $value;
break;
case "pwd":
case "password":
$info->password = $value;
break;
case "charset":
$info->charset = $value;
break;
}
}
$this->connectionString = $connectionString;
$this->connectionInfo = $info;
}
private function parseType($meta) {
switch ($meta["Type"]) {
// integer
case -6:
case -5:
case 4:
case 5:
return 'int';
// number (decimal)
case 2:
case 3:
case 6:
case 7:
return 'number';
// datetime
case -155:
case -154:
case -2:
case 91:
case 93:
return 'datetime';
// string
case -152:
case -10:
case -9:
case -8:
case -1:
case 1:
case 12:
return 'string';
}
// base64 array for unknown
return 'array';
}
public function test() {
$result = $this->connect();
if ($result->success) $this->disconnect();
return $result;
}
public function execute($queryString) {
$result = $this->connect();
if ($result->success) {
$query = $this->isMicrosoftDriver ? sqlsrv_query($this->link, $queryString) : mssql_query($queryString, $this->link);
if (!$query) return $this->getLastErrorResult();
$result->types = array();
$result->columns = array();
$result->rows = array();
if ($this->isMicrosoftDriver) {
foreach (sqlsrv_field_metadata($query) as $meta) {
$result->columns[] = $meta["Name"];
$result->types[] = $this->parseType($meta);
}
}
$isColumnsEmpty = count($result->columns) == 0;
while ($rowItem = $this->isMicrosoftDriver ? sqlsrv_fetch_array($query, SQLSRV_FETCH_ASSOC) : mssql_fetch_assoc($query)) {
$row = array();
foreach ($rowItem as $key => $value) {
if ($isColumnsEmpty && count($result->columns) < count($rowItem)) $result->columns[] = $key;
$row[] = $value;
}
$result->rows[] = $row;
}
$this->disconnect();
}
return $result;
}
function __construct() {
$this->isMicrosoftDriver = !function_exists("mssql_connect");
}
}
@@ -1,161 +0,0 @@
<?php
class StiMySqlAdapter {
private $connectionString = null;
private $connectionInfo = null;
private $link = null;
private function getLastErrorResult() {
if ($this->link->errno == 0) return StiResult::error("Unknown");
return StiResult::error("[".$this->link->errno."] ".$this->link->error);
}
private function connect() {
$this->link = new mysqli($this->connectionInfo->host, $this->connectionInfo->userId, $this->connectionInfo->password, $this->connectionInfo->database, $this->connectionInfo->port);
if ($this->link->connect_error) return StiResult::error("[".$this->link->connect_errno."] ".$this->link->connect_error);
if (!$this->link->set_charset($this->connectionInfo->charset)) return $this->getLastErrorResult();
return StiResult::success();
}
private function disconnect() {
if (!$this->link) return;
$this->link->close();
}
public function parse($connectionString) {
$info = new stdClass();
$info->host = "";
$info->port = 3306;
$info->database = "";
$info->userId = "";
$info->password = "";
$info->charset = "utf8";
$parameters = explode(";", $connectionString);
foreach($parameters as $parameter)
{
if (strpos($parameter, "=") < 1) continue;
$spos = strpos($parameter, "=");
$name = strtolower(trim(substr($parameter, 0, $spos)));
$value = trim(substr($parameter, $spos + 1));
switch ($name)
{
case "server":
case "host":
case "location":
$info->host = $value;
break;
case "port":
$info->port = $value;
break;
case "database":
case "data source":
$info->database = $value;
break;
case "uid":
case "user":
case "username":
case "userid":
case "user id":
$info->userId = $value;
break;
case "pwd":
case "password":
$info->password = $value;
break;
case "charset":
$info->charset = $value;
break;
}
}
$this->connectionString = $connectionString;
$this->connectionInfo = $info;
}
private function parseType($meta) {
switch ($meta->type) {
// integer
case 1:
case 2:
case 3:
case 8:
case 9:
return 'int';
// number (decimal)
case 4:
case 5:
case 16:
case 246:
return 'number';
// datetime
case 7:
case 10:
case 11:
case 12:
case 13:
return 'datetime';
// array, string
case 249:
case 250:
case 251:
case 252:
case 253:
case 254:
if ($meta->flags & 128) return 'array';
return 'string';
}
// base64 array for unknown
return 'array';
}
public function test() {
$result = $this->connect();
if ($result->success) $this->disconnect();
return $result;
}
public function execute($queryString) {
$result = $this->connect();
if ($result->success) {
$query = $this->link->query($queryString);
if (!$query) return $this->getLastErrorResult();
$result->types = array();
$result->columns = array();
$result->rows = array();
while ($meta = $query->fetch_field()) {
$result->columns[] = $meta->name;
$result->types[] = $this->parseType($meta);
}
if ($query->num_rows > 0) {
$isColumnsEmpty = count($result->columns) == 0;
while ($rowItem = $query->fetch_assoc()) {
$row = array();
foreach ($rowItem as $key => $value) {
if ($isColumnsEmpty && count($result->columns) < count($rowItem)) $result->columns[] = $key;
$type = $result->types[count($row)];
$row[] = ($type == 'array') ? base64_encode($value) : $value;
}
$result->rows[] = $row;
}
}
$this->disconnect();
}
return $result;
}
}
@@ -1,225 +0,0 @@
<?php
class StiConnectionInfo {
public $host = "";
public $port = "";
public $database = "";
public $userId = "";
public $password = "";
public $charset = "";
public $dsn = "";
public $privilege = "";
public $dataPath = "";
public $schemaPath = "";
}
class StiSender {
const Viewer = "Viewer";
const Designer = "Designer";
}
class StiDatabaseType {
const XML = "XML";
const JSON = "JSON";
const MySQL = "MySQL";
const MSSQL = "MS SQL";
const PostgreSQL = "PostgreSQL";
const Firebird = "Firebird";
const Oracle = "Oracle";
}
class StiEventType {
const ExecuteQuery = "ExecuteQuery";
const BeginProcessData = "BeginProcessData";
//const EndProcessData = "EndProcessData";
const CreateReport = "CreateReport";
const OpenReport = "OpenReport";
const SaveReport = "SaveReport";
const SaveAsReport = "SaveAsReport";
const PrintReport = "PrintReport";
const BeginExportReport = "BeginExportReport";
const EndExportReport = "EndExportReport";
const EmailReport = "EmailReport";
const DesignReport = "DesignReport";
}
class StiExportFormat {
const Html = "Html";
const Html5 = "Html5";
const Pdf = "Pdf";
const Excel2007 = "Excel2007";
const Word2007 = "Word2007";
const Csv = "Csv";
}
class StiRequest {
public $sender = null;
public $event = null;
public $connectionString = null;
public $queryString = null;
public $database = null;
public $report = null;
public $data = null;
public $fileName = null;
public $format = null;
public $settings = null;
public function parse() {
$data = file_get_contents("php://input");
$obj = json_decode($data);
if ($obj == null) return StiResult::error("JSON parser error");
if (isset($obj->sender)) $this->sender = $obj->sender;
if (isset($obj->command)) $this->event = $obj->command;
if (isset($obj->event)) $this->event = $obj->event;
if (isset($obj->connectionString)) $this->connectionString = $obj->connectionString;
if (isset($obj->queryString)) $this->queryString = $obj->queryString;
if (isset($obj->database)) $this->database = $obj->database;
if (isset($obj->dataSource)) $this->dataSource = $obj->dataSource;
if (isset($obj->connection)) $this->connection = $obj->connection;
if (isset($obj->data)) $this->data = $obj->data;
if (isset($obj->fileName)) $this->fileName = $obj->fileName;
if (isset($obj->format)) $this->format = $obj->format;
if (isset($obj->settings)) $this->settings = $obj->settings;
if (isset($obj->report)) {
$this->report = $obj->report;
if (defined('JSON_UNESCAPED_SLASHES')) $this->reportJson = json_encode($this->report, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
else {
// for PHP 5.3
$this->reportJson = str_replace('\/', '/', json_encode($this->report));
$this->reportJson = preg_replace_callback('/\\\\u(\w{4})/', function ($matches) {
return html_entity_decode('&#x' . $matches[1] . ';', ENT_COMPAT, 'UTF-8');
}, $this->reportJson);
}
}
return StiResult::success(null, $this);
}
}
class StiResponse {
public static function json($result, $exit = true) {
unset($result->object);
if (defined('JSON_UNESCAPED_SLASHES')) echo json_encode($result, JSON_UNESCAPED_SLASHES);
else echo json_encode($result);
if ($exit) exit;
}
}
class StiResult {
public $success = true;
public $notice = null;
public $object = null;
public static function success($notice = null, $object = null) {
$result = new StiResult();
$result->success = true;
$result->notice = $notice;
$result->object = $object;
return $result;
}
public static function error($notice = null) {
$result = new StiResult();
$result->success = false;
$result->notice = $notice;
return $result;
}
}
class StiEmailSettings {
/** Email address of the sender */
public $from = null;
/** Name and surname of the sender */
public $name = "John Smith";
/** Email address of the recipient */
public $to = null;
/** Email Subject */
public $subject = null;
/** Text of the Email */
public $message = null;
/** Attached file name */
public $attachmentName = null;
/** Charset for the message */
public $charset = "UTF-8";
/** Address of the SMTP server */
public $host = null;
/** Port of the SMTP server */
public $port = 465;
/** The secure connection prefix - ssl or tls */
public $secure = "ssl";
/** Login (Username or Email) */
public $login = null;
/** Password */
public $password = null;
}
class StiDatabaseEventArgs {
public $sender = null;
public $database = null;
public $connectionInfo = null;
public $queryString = null;
function __construct($sender, $database, $connectionInfo, $queryString = null) {
$this->sender = $sender;
$this->database = $database;
$this->connectionInfo = $connectionInfo;
$this->queryString = $queryString;
}
}
class StiReportEventArgs {
public $sender = null;
public $report = null;
function __construct($sender, $report = null) {
$this->sender = $sender;
$this->report = $report;
}
}
class StiExportReportEventArgs {
public $sender = null;
public $settings = null;
public $format = null;
public $fileName = null;
public $data = null;
function __construct($settings, $format, $fileName, $data = null) {
$this->settings = $settings;
$this->format = $format;
$this->fileName = $fileName;
$this->data = $data;
}
}
class StiSaveReportEventArgs {
public $sender = null;
public $report = null;
public $fileName = null;
function __construct($report, $fileName) {
$this->report = $report;
$this->fileName = $fileName;
}
}
class StiDesignReportEventArgs {
public $fileName = null;
function __construct($fileName) {
$this->fileName = $fileName;
}
}
@@ -1,443 +0,0 @@
<?php
require_once 'classes.php';
require_once 'adapters/mysql.php';
require_once 'adapters/mssql.php';
function stiErrorHandler($errNo, $errStr, $errFile, $errLine) {
$result = StiResult::error("[".$errNo."] ".$errStr." (".$errFile.", Line ".$errLine.")");
StiResponse::json($result);
}
function stiShutdownFunction() {
$err = error_get_last();
if ($err != null && (($err["type"] & E_COMPILE_ERROR) || ($err["type"] & E_ERROR) || ($err["type"] & E_CORE_ERROR) || ($err["type"] & E_RECOVERABLE_ERROR))) {
$result = StiResult::error("[".$err["type"]."] ".$err["message"]." (".$err["file"].", Line ".$err["line"].")");
StiResponse::json($result);
}
}
class StiHandler {
private function checkEventResult($event, $args) {
if (isset($event)) $result = $event($args);
if (!isset($result)) $result = StiResult::success();
if ($result === true) return StiResult::success();
if ($result === false) return StiResult::error();
if (gettype($result) == "string") return StiResult::error($result);
if (isset($args)) $result->object = $args;
return $result;
}
private function getQueryParameters($query) {
$result = array();
while (strpos($query, "{") !== false) {
$query = substr($query, strpos($query, "{") + 1);
$parameterName = substr($query, 0, strpos($query, "}"));
$result[$parameterName] = null;
}
return $result;
}
private function applyQueryParameters($query, $values) {
$result = "";
while (strpos($query, "{") !== false) {
$result .= substr($query, 0, strpos($query, "{"));
$query = substr($query, strpos($query, "{") + 1);
$parameterName = substr($query, 0, strpos($query, "}"));
if (isset($values) && isset($values[$parameterName]) && !is_null($values[$parameterName])) $result .= strval($values[$parameterName]);
else $result .= "{".$parameterName."}";
$query = substr($query, strpos($query, "}") + 1);
}
return $result.$query;
}
//--- Events
public $onBeginProcessData = null;
private function invokeBeginProcessData($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->database = $request->database;
$args->connectionString = isset($request->connectionString) ? base64_decode(str_rot13($request->connectionString)) : null;
$args->queryString = isset($request->queryString) ? base64_decode(str_rot13($request->queryString)) : null;
$args->dataSource = isset($request->dataSource) ? $request->dataSource : null;
$args->connection = isset($request->connection) ? $request->connection : null;
if (isset($request->queryString)) $args->parameters = $this->getQueryParameters($request->queryString);
$result = $this->checkEventResult($this->onBeginProcessData, $args);
if (isset($result->object->queryString) && isset($args->parameters)) $result->object->queryString = $this->applyQueryParameters($result->object->queryString, $args->parameters);
return $result;
}
public $onEndProcessData = null;
private function invokeEndProcessData($request, $result) {
$args = new stdClass();
$args->sender = $request->sender;
$args->result = $result;
return $this->checkEventResult($this->onEndProcessData, $args);
}
public $onCreateReport = null;
private function invokeCreateReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
return $this->checkEventResult($this->onCreateReport, $args);
}
public $onOpenReport = null;
private function invokeOpenReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
return $this->checkEventResult($this->onOpenReport, $args);
}
public $onSaveReport = null;
private function invokeSaveReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->report = $request->report;
$args->reportJson = $request->reportJson;
$args->fileName = $request->fileName;
return $this->checkEventResult($this->onSaveReport, $args);
}
public $onSaveAsReport = null;
private function invokeSaveAsReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->report = $request->report;
$args->reportJson = $request->reportJson;
$args->fileName = $request->fileName;
return $this->checkEventResult($this->onSaveAsReport, $args);
}
public $onPrintReport = null;
private function invokePrintReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->fileName = $request->fileName;
return $this->checkEventResult($this->onPrintReport, $args);
}
public $onBeginExportReport = null;
private function invokeBeginExportReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->settings = $request->settings;
$args->format = $request->format;
$args->fileName = $request->fileName;
return $this->checkEventResult($this->onBeginExportReport, $args);
}
public $onEndExportReport = null;
private function invokeEndExportReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->format = $request->format;
$args->fileName = $request->fileName;
$args->data = $request->data;
return $this->checkEventResult($this->onEndExportReport, $args);
}
public $onEmailReport = null;
private function invokeEmailReport($request) {
$settings = new StiEmailSettings();
$settings->to = $request->settings->email;
$settings->subject = $request->settings->subject;
$settings->message = $request->settings->message;
$settings->attachmentName = $request->fileName.'.'.$this->getFileExtension($request->format);
$args = new stdClass();
$args->sender = $request->sender;
$args->settings = $settings;
$args->format = $request->format;
$args->fileName = $request->fileName;
$args->data = base64_decode($request->data);
$result = $this->checkEventResult($this->onEmailReport, $args);
if (!$result->success) return $result;
$guid = substr(md5(uniqid().mt_rand()), 0, 12);
if (!file_exists('tmp')) mkdir('tmp');
file_put_contents('tmp/'.$guid.'.'.$args->fileName, $args->data);
// Detect auth mode
$auth = $settings->host != null && $settings->login != null && $settings->password != null;
$mail = substr(PHP_VERSION, 0, 1) == '5' ? new PHPMailer(true) : new PHPMailer\PHPMailer\PHPMailer(true);
if ($auth) $mail->IsSMTP();
try {
$mail->CharSet = $settings->charset;
$mail->IsHTML(false);
$mail->From = $settings->from;
$mail->FromName = $settings->name;
// Add Emails list
$emails = preg_split('/,|;/', $settings->to);
foreach ($emails as $settings->to) {
$mail->AddAddress(trim($settings->to));
}
// Fill email fields
$mail->Subject = htmlspecialchars($settings->subject);
$mail->Body = $settings->message;
$mail->AddAttachment('tmp/'.$guid.'.'.$args->fileName, $settings->attachmentName);
// Fill auth fields
if ($auth) {
$mail->Host = $settings->host;
$mail->Port = $settings->port;
$mail->SMTPAuth = true;
$mail->SMTPSecure = $settings->secure;
$mail->Username = $settings->login;
$mail->Password = $settings->password;
}
$mail->Send();
}
catch (phpmailerException $e) {
$error = strip_tags($e->errorMessage());
return StiResult::error($error);
}
catch (Exception $e) {
$error = strip_tags($e->getMessage());
}
unlink('tmp/'.$guid.'.'.$args->fileName);
if (isset($error)) return StiResult::error($error);
return $result;
}
public $onDesignReport = null;
private function invokeDesignReport($request) {
$args = new stdClass();
$args->sender = $request->sender;
$args->fileName = $request->fileName;
return $this->checkEventResult($this->onDesignReport, $args);
}
//--- Methods
public function registerErrorHandlers() {
set_error_handler("stiErrorHandler");
register_shutdown_function("stiShutdownFunction");
}
public function process($response = true) {
$result = $this->innerProcess();
if ($response) StiResponse::json($result);
return $result;
}
//--- Private methods
private function createConnection($args) {
switch ($args->database) {
case StiDatabaseType::MySQL: $connection = new StiMySqlAdapter(); break;
case StiDatabaseType::MSSQL: $connection = new StiMsSqlAdapter(); break;
case StiDatabaseType::Firebird: $connection = new StiFirebirdAdapter(); break;
case StiDatabaseType::PostgreSQL: $connection = new StiPostgreSqlAdapter(); break;
case StiDatabaseType::Oracle: $connection = new StiOracleAdapter(); break;
}
if (isset($connection)) {
$connection->parse($args->connectionString);
return StiResult::success(null, $connection);
}
return StiResult::error("Unknown database type [".$args->database."]");
}
private function innerProcess() {
$request = new StiRequest();
$result = $request->parse();
if ($result->success) {
switch ($request->event) {
case StiEventType::BeginProcessData:
case StiEventType::ExecuteQuery:
$result = $this->invokeBeginProcessData($request);
if (!$result->success) return $result;
$queryString = $result->object->queryString;
$result = $this->createConnection($result->object);
if (!$result->success) return $result;
$connection = $result->object;
if (isset($queryString)) $result = $connection->execute($queryString);
else $result = $connection->test();
$result = $this->invokeEndProcessData($request, $result);
if (!$result->success) return $result;
if (isset($result->object) && isset($result->object->result)) return $result->object->result;
return $result;
case StiEventType::CreateReport:
return $this->invokeCreateReport($request);
case StiEventType::OpenReport:
return $this->invokeOpenReport($request);
case StiEventType::SaveReport:
return $this->invokeSaveReport($request);
case StiEventType::SaveAsReport:
return $this->invokeSaveReport($request);
case StiEventType::PrintReport:
return $this->invokePrintReport($request);
case StiEventType::BeginExportReport:
return $this->invokeBeginExportReport($request);
case StiEventType::EndExportReport:
return $this->invokeEndExportReport($request);
case StiEventType::EmailReport:
return $this->invokeEmailReport($request);
case StiEventType::DesignReport;
return $this->invokeDesignReport($request);
}
$result = StiResult::error("Unknown event [".$request->event."]");
}
return $result;
}
private function getFileExtension($format) {
switch ($format) {
case StiExportFormat::Html:
case StiExportFormat::Html5:
return "html";
case StiExportFormat::Pdf:
return "pdf";
case StiExportFormat::Excel2007:
return "xlsx";
case StiExportFormat::Word2007:
return "docx";
case StiExportFormat::Csv:
return "csv";
}
return "";
}
}
//---------- Helper ----------//
class StiHelper {
public static function createOptions() {
$options = new stdClasS();
$options->handler = "handler.php";
$options->timeout = 30;
return $options;
}
public static function initialize($options) {
if (!isset($options)) $options = StiHelper::createOptions();
?>
<script type="text/javascript">
StiHelper.prototype.process = function (args, callback) {
if (args) {
if (args.event == 'BeginProcessData') {
args.preventDefault = true;
if (args.database == 'XML' || args.database == 'JSON' || args.database == 'Excel')
return callback(null);
if (args.database == 'Data from DataSet, DataTables')
return callback(args);
}
var command = {};
for (var p in args) {
if (p == 'report' && args.report != null) command.report = JSON.parse(args.report.saveToJsonString());
else if (p == 'settings' && args.settings != null) command.settings = args.settings;
else if (p == 'data') command.data = Stimulsoft.System.Convert.toBase64String(args.data);
else if (p == 'connectionString' || p == 'queryString') command[p] = jsHelper.getStringValue(args[p]);
else command[p] = args[p];
}
var isNullOrEmpty = function (value) {
return value == null || value === '' || value === undefined;
}
var json = JSON.stringify(command);
if (!callback) callback = function (message) {
if (Stimulsoft.System.StiError.errorMessageForm && !isNullOrEmpty(message)) {
var obj = JSON.parse(message);
if (!obj.success || !isNullOrEmpty(obj.notice)) {
var message = isNullOrEmpty(obj.notice) ? 'There was some error' : obj.notice;
Stimulsoft.System.StiError.errorMessageForm.show(message, obj.success);
}
}
}
jsHelper.send(json, callback);
}
}
StiHelper.prototype.send = function (json, callback) {
try {
var request = new XMLHttpRequest();
request.open('post', this.url, true);
request.setRequestHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
request.setRequestHeader('Cache-Control', 'max-age=0');
request.setRequestHeader('Pragma', 'no-cache');
request.timeout = this.timeout * 1000;
request.onload = function () {
if (request.status == 200) {
var responseText = request.responseText;
request.abort();
callback(responseText);
}
else {
Stimulsoft.System.StiError.showError('[' + request.status + '] ' + request.statusText, false);
}
};
request.onerror = function (e) {
var errorMessage = 'Connect to remote error: [' + request.status + '] ' + request.statusText;
Stimulsoft.System.StiError.showError(errorMessage, false);
};
request.send(json);
}
catch (e) {
var errorMessage = 'Connect to remote error: ' + e.message;
Stimulsoft.System.StiError.showError(errorMessage, false);
request.abort();
}
};
StiHelper.prototype.getStringValue = function (value) {
return Stimulsoft.System.Convert.toBase64String(value).replace(/[a-zA-Z]/g, function (c) {
return String.fromCharCode((c <= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26);
});
};
StiHelper.prototype.getUrlVars = function (json, callback) {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
function (m, key, value) {
vars[key] = decodeURI(value);
});
return vars;
}
function StiHelper(url, timeout) {
this.url = url;
this.timeout = timeout;
}
jsHelper = new StiHelper('<?php echo $options->handler; ?>', <?php echo $options->timeout; ?>);
</script>
<?php
}
public static function createHandler() {
?>jsHelper.process(arguments[0], arguments[1]);
<?php
}
}
@@ -1 +0,0 @@
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
@@ -1,10 +0,0 @@
<?php
// You can check the user authorization to send a license key only if the result is positive.
if (file_exists("license.key")) {
$license = file_get_contents("license.key");
echo $license;
}
?>
-72
View File
@@ -1,72 +0,0 @@
<?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.whiteblue.css" rel="stylesheet">
<!-- Stimulsoft Reports.JS -->
<script src="scripts/stimulsoft.reports.js" type="text/javascript"></script>
<!-- Stimulsoft JS Viewer -->
<script src="scripts/stimulsoft.viewer.js" type="text/javascript"></script>
<?php
$options = StiHelper::createOptions();
$options->handler = "handler.php";
$options->timeout = 30;
StiHelper::initialize($options);
?>
<script type="text/javascript">
//Stimulsoft.Base.StiLicense.loadFromFile("stimulsoft/license.php");
var options = new Stimulsoft.Viewer.StiViewerOptions();
options.appearance.fullScreenMode = true;
options.toolbar.showSendEmailButton = true;
Stimulsoft.Base.Localization.StiLocalization.addLocalizationFile("localization/zh-CHS.xml", false, "Chinese (Simplified)");
Stimulsoft.Base.Localization.StiLocalization.cultureName = "Chinese (Simplified)";
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)
<?php StiHelper::createHandler(); ?>
}*/
// Send exported report to Email
viewer.onEmailReport = function (event) {
<?php StiHelper::createHandler(); ?>
}
// Load and show report
var report = new Stimulsoft.Report.StiReport();
report.loadFile("reports/SimpleList.mrt");
viewer.report = report;
function onLoad() {
viewer.renderHtml("viewerContent");
}
</script>
</head>
<body onload="onLoad();">
<div id="viewerContent"></div>
</body>
</html>