-
Notifications
You must be signed in to change notification settings - Fork 23
/
handler.php
172 lines (141 loc) · 5.99 KB
/
handler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace Stimulsoft;
require_once 'vendor/autoload.php';
// You can 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');
header('Cache-Control: no-cache');
$handler = new StiHandler();
/** @var $args StiVariablesEventArgs */
$handler->onPrepareVariables = function ($args)
{
// You can set the values of the report variables, the value types must match the original types
// If the variable contained an expression, the already calculated value will be passed
// The new values will be passed to the report generator
/*
$args->variables['VariableString']->value = 'Value from Server-Side';
$args->variables['VariableDateTime']->value = '2020-01-31 22:00:00';
$args->variables['VariableStringRange']->value->from = 'Aaa';
$args->variables['VariableStringRange']->value->to = 'Zzz';
$args->variables['VariableStringList']->value[0] = 'Test';
$args->variables['VariableStringList']->value = ['1', '2', '2'];
$args->variables['NewVariable'] = ['value' => 'New Value'];
*/
// Values for 'Variables.mrt' report template
if (count($args->variables) > 0) {
$args->variables['Name']->value = 'Maria';
$args->variables['Surname']->value = 'Anders';
$args->variables['Email']->value = '[email protected]';
$args->variables['Address']->value = 'Obere Str. 57, Berlin';
$args->variables['Sex']->value = false;
$args->variables['BirthDay']->value = '1982-03-20 00:00:00';
}
return StiResult::success();
};
/** @var $args StiDataEventArgs */
$handler->onBeginProcessData = function ($args)
{
// You can change the connection string
/*
if ($args->connection == 'MyConnectionName')
$args->connectionString = 'Server=localhost;Database=test;uid=root;password=******;';
*/
// You can change the SQL query
/*
if ($args->dataSource == 'MyDataSource')
$args->queryString = 'SELECT * FROM MyTable';
*/
// You can change the SQL query parameters with the required values
// For example: SELECT * FROM @Parameter1 WHERE Id = @Parameter2 AND Date > @Parameter3
/*
if ($args->dataSource == 'MyDataSourceWithParams') {
$args->parameters['Parameter1']->value = 'TableName';
$args->parameters['Parameter2']->value = 10;
$args->parameters['Parameter3']->value = '2019-01-20';
}
*/
// Values for 'SimpleListSQLParameters.mrt' report template
if ($args->dataSource == 'customers' && count($args->parameters) > 0) {
$args->parameters['Country']->value = "Germany";
}
// You can send a successful result
return StiResult::success();
// You can send an informational message
//return StiResult::success('Some warning or other useful information.');
// You can send an error message
//return StiResult::error('Message about any connection error.');
};
/** @var $args StiDataEventArgs */
$handler->onEndProcessData = function ($args)
{
return StiResult::success();
};
/** @var $args StiExportEventArgs */
$handler->onPrintReport = function ($args)
{
return StiResult::success();
};
/** @var $args StiExportEventArgs */
$handler->onBeginExportReport = function ($args)
{
return StiResult::success();
};
/** @var $args StiExportEventArgs */
$handler->onEndExportReport = function ($args)
{
// Getting the file name with the extension
$reportName = $args->fileName;
if (substr($reportName, -strlen($args->fileExtension) - 1) !== '.' . $args->fileExtension)
$reportName .= '.' . $args->fileExtension;
// By default, the exported file is saved to the 'reports' folder
// You can change this behavior if required
file_put_contents('reports/' . $reportName, base64_decode($args->data));
//return StiResult::success();
return StiResult::success("The exported report is saved successfully as $reportName");
//return StiResult::error('An error occurred while exporting the report.');
};
/** @var $args StiExportEventArgs */
$handler->onEmailReport = function ($args)
{
// Defining the required options for sending (host, login, password), they will not be passed to the client side
$args->emailSettings->from = '*****@gmail.com';
$args->emailSettings->host = 'smtp.google.com';
$args->emailSettings->login = '*****';
$args->emailSettings->password = '*****';
// These parameters are optional
//$args->emailSettings->name = 'John Smith';
//$args->emailSettings->port = 465;
//$args->emailSettings->cc[] = '[email protected]';
//$args->emailSettings->bcc[] = '[email protected]';
//$args->emailSettings->bcc[] = '[email protected] John Smith';
return StiResult::success('Email sent successfully.');
};
/** @var $args StiReportEventArgs */
$handler->onCreateReport = function ($args)
{
// You can load a new report and send it to the designer
//$args->report = file_get_contents('reports/SimpleList.mrt');
return StiResult::success();
};
/** @var $args StiReportEventArgs */
$handler->onSaveReport = function ($args)
{
// Getting the correct file name of the report template
$reportFileName = strlen($args->fileName) > 0 ? $args->fileName : 'Report.mrt';
if (strlen($reportFileName) < 5 || substr($reportFileName, -4) !== '.mrt')
$reportFileName .= '.mrt';
// For example, you can save a report to the 'reports' folder on the server-side
file_put_contents('reports/' . $reportFileName, $args->reportJson);
//return StiResult::success();
return StiResult::success('Report file saved successfully as ' . $args->fileName);
//return StiResult::error('An error occurred while saving the report file on the server side.');
};
/** @var $args StiReportEventArgs */
$handler->onSaveAsReport = function ($args)
{
// This event works the same as the 'onSaveReport' event
return StiResult::success();
};
// Process request
$handler->process();