Firebird PHP Generator online Help
| Prev | Return to chapter overview | Next |
Events
Event is a fragment of PHP/Javascript code executed before or after a record was added, edited, or deleted, etc. Therefore events allow you to define some actions that will be activated when certain conditions are met. All events are grouped into 2 categories: Client side events and Server side events. Client side events are written on Javascript and executed by browsers while Server side events are written on PHP and executed by webserver.
Working with events
To add/edit an event handler, select the necessary event in the list and double-click the Code column or use Ctrl+Enter. Then type PHP code in the Event Editor window.
To temporarily disable/enable an event, select the appropriate line in the list and uncheck/check the corresponding Enabled box.
Using variables
Firebird PHP Generator supports some environment variables (such as CURRENT_USER_ID, CURRENT_USER_NAME, UNIQUE_ID) in events. To obtain a complete list of supported variables, uncomment the define('SHOW_VARIABLES', 1); line in the generated settings.php file and open any generated web page. The following example demonstrates how to use variables within the OnBeforeInsertRecord event.
Example:
$rowData['ip_address'] = $this->GetEnvVar('REMOTE_ADDR');
$userName = $this->GetEnvVar('CURRENT_USER_NAME');
if ($userName != 'admin')
$rowData['changed_by'] = $userName;
Firebird PHP Generator supports the following events:
Client side events:
Occurs before page loading. Allows you to declare functions and global variables.
|
Occurs after page has been fully rendered. This event does not get triggered until all assets such as images have been completely received and DOM hierarchy has been fully constructed.
|
Occurs before submitting the insert form. This allows errors to be detected on the client before the form is submitted, thus avoiding the round trip of information necessary for server-side validation.
Parameters: $fieldValues- associative array of values contains user input. $errorInfo - object that provides interface (the SetMessage method) to set a validation error message.
Example: if (fieldValues['percents'] < 0 || fieldValues['percents'] > 100) { errorInfo.SetMessage('Percent value should be between 0 and 100.'); return false; }
|
Occurs before submitting the edit form. This allows errors to be detected on the client before the form is submitted, thus avoiding the round trip of information necessary for server-side validation.
Parameters: $fieldValues- associative array of values contains user input. $errorInfo - object that provides interface (the SetMessage method) to set a validation error message.
Example: if (fieldValues['percents'] < 0 || fieldValues['percents'] > 100) { errorInfo.SetMessage('Percent value should be between 0 and 100.'); return false; }
|
Occurs on changing a value in the Insert form.
Parameters: $sender - a control whose value has been changed $editors - associative array of form controls
Example: if (sender.getFieldName() == 'country_id') { editors['college_id'].enabled(sender.getValue() == 1); if (sender.getValue() != 1) editors['college_id'].setValue(null); }
|
Occurs on changing a value in the Edit form.
Parameters: $sender - a control whose value has been changed $editors - associative array of form controls
Example: if (sender.getFieldName() == 'current_team_id') { if (sender.getValue() == '') { editors['current_number'].setValue(''); editors['current_number'].enabled(false); } else { editors['current_number'].enabled(true); } } |
Occurs after the Insert form is loaded.
Parameters: $editors - associative array of form controls
|
Occurs after the Edit form is loaded.
Parameters: $editors - associative array of form controls
|
Server side events:
Occurs before all page events has been declared. Allows to create global objects, declare functions, and include third-party libraries.
Example: Suppose we decided to implement a syntax highlighting using the GeSHi library somewhere in the generated application. To implement such a feature, we need (among other things) to include the main library file into the generated scripts:
include_once '../geshi/geshi.php';
|
Occurs before column rendering. Allows to replace cell content. It is an extremely useful event for conditional rendering or embedding third-party components to extend standard functionality.
Parameters: $fieldName - field name of currently processed cell. $fieldData - data of currently processed cell. $rowData - associative array of values that corresponds to the currently processed row. $customText - a string to replace original cell content.
Example: Suppose a table 'employee' has a column storing data about the employee's sex in that way that '1' corresponds to male and '2' to female. Our goal is to represent the employees sex as 'M' and 'F' for men and women accordingly. To do so, you could specify the OnCustomRenderColumn event handler as follows:
if ($fieldName == 'sex') { $customText = $rowData['sex'] == 1 ? 'M' : 'F'; $handled = true; }
|
Occurs before column rendering on print page. Allow to replace cell content. It is an extremely useful for conditional rendering or embedding third-party components to extend standard functionality.
Parameters: $fieldName - field name of currently processed cell. $fieldData - data of currently processed cell. $rowData - associative array of valued that corresponds to the currently processed row. $rowData - a string to replace original cell content.
|
Occurs before column rendering into Word, Excel, etc. Allow to replace cell content. It is an extremely useful event for conditional rendering.
Parameters: $exportType - a string contains exporting format short name (word, excel, pdf, csv, xml). $fieldName - field name of currently processed cell. $fieldData - data of currently processed cell. $rowData - associative array of valued that corresponds to the currently processed row. $rowData - a string to replace original cell content.
|
Occurs when generating the head section of the page. Use this event to provide additional information for the HEAD section of the page (such as keywords, author, or description).
Parameters: $page - the page raised the event. $customHtmlHeaderText - a string to place into the head section.
Example: $customHtmlHeaderText = '<meta name="copyright" content="SQL Maestro Group"/>';
|
Occurs when rendering a grid row (advanced features). It is an extremely useful event for conditional formatting such as changing font color, font styles, row background color, cell background color, etc.
Parameters: $rowData - associative array of values that corresponds to the currently processed row. $cellStyles - associative array of styles. Each field name is associated with its style string. $rowStyles - use this string to modify styles of a whole row.
This event (as well as OnCustomDrawRow) is used for conditional formatting. The only difference between these two events is that OnCustomDrawRow has a more understandable parameter list while OnExtendedCustomDrawRow provides more flexible abilities.
Example: Please find below an example of the conditional row formatting from our online demo. We need to display winning team score in red and losing team score in black; moreover, both scores should be in bold and displayed by a 16pt font.
$rowCellStyles['home_team_score'] = 'font-size: 16pt;font-weight: bold;'; $rowCellStyles['away_team_score'] = 'font-size: 16pt;font-weight: bold;'; if ($rowData['home_team_score'] > $rowData['away_team_score']) $rowCellStyles['home_team_score'] .= 'color: #F65317;'; else $rowCellStyles['away_team_score'] .= 'color: #000000;';
|
Occurs before total values rendering. Allows to replace default total footer content. Enabling this event don't forget to enable the grid footer in the View properties of the corresponding column.
Parameters: $totalValue - total value of currently processed total. $aggregate - string representation of total aggregate ('AVG', 'SUM', 'MIN', 'MAX', 'COUNT'). $columnName - column name of currently processed total. &$customText - a string to replace total cell content. &$handled - indicates whether the event handler executed. Set $handled to true in the event handler to apply new content.
Example: Suppose we need to change the text of the 'TOTAL_VALUE' column grid footer.
Set if ($columnName == 'TOTAL_VALUE') { $customText = 'Total value average: ' . $totalValue . '$'; $handled = true; } Now we can compare the result webpages without using the event and with the enabled one:
|
This event handler occurs on opening a custom template and allows to use a custom template instead of the default one. The basic principles of custom template usage are shown in this article.
In PHP Generator creates a set of templates written on Smarty 2.0 to be used by the prepared application in the certain situations. To change a webpage look in such application, you need to specify a new template to be used and set it in this event. The template file should be uploaded to the 'components/templates/custom_template' directory.
Parameters: $part - the part of the page to be affected by the template. Possible values are: PagePart::Grid allows to change the appearance of table grid. PagePart::GridRow allows to set the one row look. PagePart::VerticalGrid allows to apply the template to data grid placed at edit form, view form and insert form. PagePart::PageList allows you to change the appearance of Navigation bar at the webpage. PagePart::Layout - allows to completely redesign the webpage look. PagePart::RecordCard - data represented at the modal dialog
$mode - the current state of the webpage the template to be used. Possible values are: PageMode::ViewAll allows to change the look of webpage representing table data. PageMode::View allows to specify a custom template. PageMode::Edit allows to modify the edit form of the table. PageMode::Insert allows to modify the insert form. PageMode::ModalView, PageMode::ModalEdit, PageMode::ModalInsert allow to change the appearance of data on viewing, editing and inserting in a modal dialog.
$result - the path to the file to be used as template according to the components/templates/custom_templates folder.
Example: Suppose we need to use components/templates/custom_templates/staff_edit.tpl file as a template for the edit form data.
if ($part == PagePart::VerticalGrid && $mode == PageMode::Edit) { $result = 'staff_edit.tpl'; }
Now we can compare the result webpages without using the event and with the enabled one:
|
Occurs when rendering a grid row (basic features). It is an extremely useful event for conditional formatting such as changing font color, font styles, row background color, cell background color, etc.
Parameters: $rowData - associative array of values that corresponds to the currently processed row. $cellFontColor, $cellFontSize, $cellBgColor, $cellItalicAttr, $cellBoldAttr - associative arrays of cell attributes.
This event (as well as OnExtendedCustomDrawRow) is used for conditional formatting. The only difference between these two events is that OnCustomDrawRow has a more understandable parameter list while OnExtendedCustomDrawRow provides more flexible abilities.
Example: Please find below an example of the conditional row formatting from our online demo. We need to display winning team score in red and losing team score in black; moreover, both scores should be in bold and displayed by a 16pt font.
$cellFontSize['home_team_score'] = '16pt'; $cellBoldAttr['home_team_score'] = true;
$cellFontSize['away_team_score'] = '16pt'; $cellBoldAttr['away_team_score'] = true;
if ($rowData['home_team_score'] > $rowData['away_team_score']) $cellFontColor['home_team_score'] = '#F65317'; else $cellFontColor['away_team_score'] = '#000000';
|
Occurs when the Update command is executed, but before the actual update. This event is often used to cancel the update operation.
Parameters: $rowData - associative array of values that corresponds to the currently processed row. $cancel - value indicating whether the operation should be canceled. $message - message string that is displayed after the operation is completed (or canceled)
Example: $cancel = true; $message = 'Updating is disabled.';
|
Occurs when the Delete command is executed, but before the actual deletion. This event is often used to cancel the delete operation.
Parameters: $rowData - associative array of values that corresponds to the currently processed row. $cancel - value indicating whether the operation should be canceled. $message - message string that is displayed after the operation is completed (or canceled)
Example: $cancel = true; $message = 'Deleting is disabled.';
|
Occurs when the Insert command is executed, but before the actual insertion. This event is often used to cancel the insert operation.
Parameters: $rowData - associative array of values that corresponds to the currently processed row. $cancel - value indicating whether the operation should be canceled. $message - message string that is displayed after the operation is completed (or canceled)
Example: $cancel = true; $message = 'Inserting is disabled.';
|
Events specified as project options will be used for all generated web pages.






