Samples

 

You can find a full code on the GitHub.

 

 

 

The report generator, the viewer, and the report designer can invoke events on the client-side, send them to the PHP server for next processing, and take a prepared report from the PHP server. Everything you need to work with the events you may find in the StiHandler class, which you need to add to the <script> block before the rest of the components:

 

index.php

 

<?php

$handler = new \Stimulsoft\StiHandler();

$handler->renderHtml();

?>

 

 

 

If necessary, you can set the server script file of the event handler in the options and the timeout for waiting for a response:

 

index.php

 

<?php

$handler = new \Stimulsoft\StiHandler();

$handler->options->url = 'handler.php';

$handler->options->timeout = 30;

$handler->renderHtml();

?>

 

 

 

After performing the renderHtml() function, the JavaScript code necessary for working with events will be added to the PHP page. To transfer data to the server side, you should enable the processing of the required event. Set the corresponding property of the component to true:

 

index.php

 

<?php

$report = new \Stimulsoft\Report\StiReport();

$report->onBeginProcessData = true;

$report->renderHtml();

?>

 

 

 

It is possible to define a JavaScript function for the event if it is necessary to process the parameters passed to the server side before passing them. In this case, all passed parameters will be contained in the function arguments, and if necessary, the values of the arguments can be changed:

 

index.php

 

<?php

$report = new \Stimulsoft\Report\StiReport();

$report->onBeginProcessData = 'onBeginProcessData';

$report->renderHtml();

?>

 

function onBeginProcessData(args) {

 

}

 

 

 

In the event handler on the PHP server-side, in the event of the same name in arguments, you can read all available parameters, transferred from the report generator, check them and correct something, if needed. For example, in this case the onBeginProcessData event will be invoked in the handler.php file.

 

handler.php

 

$handler->onBeginProcessData = function ($args) {

...

 

return \Stimulsoft\StiResult::success();

};

 

 

 

After the event processing on the PHP server-side, the handler should return a response to the client-side about the result of the event. Two static functions are provided for it: the StiResult::success() is the event made successfully, and the StiResult::error() is an error occurred during the execution. You control this process and make decision about the response you need. You can transfer a string message, which will be displayed on the client-side after the event as the function parameter, for example.

 

handler.php

 

$handler->onBeginProcessData = function ($args) {

...

 

// You can send a successful result

return \Stimulsoft\StiResult::success();

 

// You can send an informational message

//return \Stimulsoft\StiResult::success('Some warning or other useful information.');

// You can send an error message

//return \Stimulsoft\StiResult::error('A message about some error.');

};

 

 

Information

 

There is an option to automatically send information about an error to the client-side if critical errors occur on the PHP server-side. If the specified functionality is not required, it can be disabled by setting false to the $registerErrorHandlers parameter in the server-side event handler constructor:

 

$handler = new \Stimulsoft\StiHandler(false);

 

 

 

Data encryption, transmitted to the PHP server-side

To avoid theft of transmitted data to intruders, we recommend you to use HTTPS protocol, mostly that's not enough. In addition, by default all transmitted data goes through a special coding algorithm and transmitted to the server in encrypted form. It allows you to hide your confidential data, such as log in and password in the connection string from curious users, who work with your application.

 

However, if it's not required or if you need to display the input data of a request to debug an application, the encryption disable capability is envisaged. To do this, just set the $encryptData property to false in the event handler:

 

index.php

 

<?php

$handler = new \Stimulsoft\StiHandler();

$handler->encryptData = false;

$handler->renderHtml();

?>

 

 

 

Transferring GET parameter values to the PHP event handler

You can automatically transfer all the values of the GET request parameters to the event handler, where their values can be accessed in all events. To enable this feature, simply set the passQueryParameters option to true, and all GET request parameters will be passed with each request to the event handler. By default, this option is disabled.

 

index.php

 

<?php

$handler = new \Stimulsoft\StiHandler();

$handler->options->passQueryParameters = true;

$handler->renderHtml();

?>