1<?php
2///////////////////////////////////////////////////////////////////////////////
3//
4// NagiosQL
5//
6///////////////////////////////////////////////////////////////////////////////
7//
8// (c) 2005-2020 by Martin Willisegger
9//
10// Project   : NagiosQL
11// Component : Contact template definitions
12// Website   : https://sourceforge.net/projects/nagiosql/
13// Version   : 3.4.1
14// GIT Repo  : https://gitlab.com/wizonet/NagiosQL
15//
16///////////////////////////////////////////////////////////////////////////////
17//
18// Path settings
19// ===================
20$strPattern = '(admin/[^/]*.php)';
21$preRelPath  = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
22$preBasePath = preg_replace($strPattern, '', filter_input(INPUT_SERVER, 'SCRIPT_FILENAME', FILTER_SANITIZE_STRING));
23//
24// Define common variables
25// =======================
26$prePageId        = 17;
27$preContent       = 'admin/contacttemplates.htm.tpl';
28$preListTpl       = 'admin/datalist.htm.tpl';
29$preSearchSession = 'contacttemplate';
30$preTableName     = 'tbl_contacttemplate';
31$preKeyField      = 'template_name';
32$preAccess        = 1;
33$preFieldvars     = 1;
34//
35// Include preprocessing files
36// ===========================
37require $preBasePath.'functions/prepend_adm.php';
38require $preBasePath.'functions/prepend_content.php';
39//
40// Checkbox data processing
41// ========================
42if (($intVersion == 3) || ($intVersion == 4)) {
43    $strHO = substr($chkChbGr1a.$chkChbGr1b.$chkChbGr1c.$chkChbGr1d.$chkChbGr1e.$chkChbGr1f, 0, -1);
44    $strSO = substr($chkChbGr2a.$chkChbGr2b.$chkChbGr2c.$chkChbGr2d.$chkChbGr2e.$chkChbGr2f.$chkChbGr2g, 0, -1);
45} else {
46    $strHO = substr($chkChbGr1a.$chkChbGr1b.$chkChbGr1c.$chkChbGr1d.$chkChbGr1f, 0, -1);
47    $strSO = substr($chkChbGr2a.$chkChbGr2b.$chkChbGr2c.$chkChbGr2d.$chkChbGr2e.$chkChbGr2g, 0, -1);
48}
49//
50// Add or modify data
51// ==================
52if ((($chkModus == 'insert') || ($chkModus == 'modify')) && ($intGlobalWriteAccess == 0)) {
53    $strSQLx = "`$preTableName` SET `$preKeyField`='$chkTfValue1', `alias`='$chkTfValue2', "
54             . "`contactgroups`=$intMselValue1, `contactgroups_tploptions`=$chkRadValue1, "
55             . "`minimum_importance`=$chkTfNullVal1, "
56             . "`host_notifications_enabled`='$chkRadValue2', `service_notifications_enabled`='$chkRadValue3', "
57             . "`host_notification_period`='$chkSelValue1', `service_notification_period`='$chkSelValue2', "
58             . "`host_notification_options`='$strHO', `host_notification_commands_tploptions`=$chkRadValue4, "
59             . "`service_notification_options`='$strSO', `host_notification_commands`=$intMselValue2, "
60             . "`service_notification_commands`=$intMselValue3, "
61             . "`service_notification_commands_tploptions`=$chkRadValue5, `can_submit_commands`='$chkRadValue8', "
62             . "`retain_status_information`='$chkRadValue6', `retain_nonstatus_information`='$chkRadValue7', "
63             . "`email`='$chkTfValue3', `pager`='$chkTfValue4', `address1`='$chkTfValue5', `address2`='$chkTfValue6', "
64             . "`address3`='$chkTfValue7', `address4`='$chkTfValue8', `address5`='$chkTfValue9', "
65             . "`address6`='$chkTfValue10', `use_variables`='$intVariables', `use_template`=$intTemplates, "
66             . $preSQLCommon2;
67    if ($chkModus == 'insert') {
68        $strSQL = 'INSERT INTO ' .$strSQLx;
69    } else {
70        $strSQL = 'UPDATE ' .$strSQLx. ' WHERE `id`=' .$chkDataId;
71    }
72    if ($intWriteAccessId == 0) {
73        if ($chkTfValue1 != '') {
74            $intReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
75            if ($chkModus == 'insert') {
76                $chkDataId = $intInsertId;
77            }
78            if ($intReturn == 1) {
79                $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
80            } else {
81                $myVisClass->processMessage($myDataClass->strInfoMessage, $strInfoMessage);
82                $myDataClass->updateStatusTable($preTableName);
83                if ($chkModus  == 'insert') {
84                    $myDataClass->writeLog(translate('New contact template inserted:'). ' ' .$chkTfValue1);
85                }
86                if ($chkModus  == 'modify') {
87                    $myDataClass->writeLog(translate('Contact template modified:'). ' ' .$chkTfValue1);
88                }
89                //
90                // Insert/update relations
91                // =======================
92                if ($chkModus == 'insert') {
93                    if ($intMselValue1 != 0) {
94                        $intRet1 = $myDataClass->dataInsertRelation(
95                            'tbl_lnkContacttemplateToContactgroup',
96                            $chkDataId,
97                            $chkMselValue1
98                        );
99                    }
100                    if (isset($intRet1) && ($intRet1 != 0)) {
101                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
102                    }
103                    if ($intMselValue2 != 0) {
104                        $intRet2 = $myDataClass->dataInsertRelation(
105                            'tbl_lnkContacttemplateToCommandHost',
106                            $chkDataId,
107                            $chkMselValue2
108                        );
109                    }
110                    if (isset($intRet2) && ($intRet2 != 0)) {
111                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
112                    }
113                    if ($intMselValue3 != 0) {
114                        $intRet3 = $myDataClass->dataInsertRelation(
115                            'tbl_lnkContacttemplateToCommandService',
116                            $chkDataId,
117                            $chkMselValue3
118                        );
119                    }
120                    if (isset($intRet3) && ($intRet3 != 0)) {
121                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
122                    }
123                } elseif ($chkModus == 'modify') {
124                    if ($intMselValue1 != 0) {
125                        $intRet1 = $myDataClass->dataUpdateRelation(
126                            'tbl_lnkContacttemplateToContactgroup',
127                            $chkDataId,
128                            $chkMselValue1
129                        );
130                    } else {
131                        $intRet1 = $myDataClass->dataDeleteRelation('tbl_lnkContacttemplateToContactgroup', $chkDataId);
132                    }
133                    if ($intRet1 != 0) {
134                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
135                    }
136                    if ($intMselValue2 != 0) {
137                        $intRet2 = $myDataClass->dataUpdateRelation(
138                            'tbl_lnkContacttemplateToCommandHost',
139                            $chkDataId,
140                            $chkMselValue2
141                        );
142                    } else {
143                        $intRet2 = $myDataClass->dataDeleteRelation('tbl_lnkContacttemplateToCommandHost', $chkDataId);
144                    }
145                    if ($intRet2 != 0) {
146                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
147                    }
148                    if ($intMselValue3 != 0) {
149                        $intRet3 = $myDataClass->dataUpdateRelation(
150                            'tbl_lnkContacttemplateToCommandService',
151                            $chkDataId,
152                            $chkMselValue3
153                        );
154                    } else {
155                        $intRet3 = $myDataClass->dataDeleteRelation(
156                            'tbl_lnkContacttemplateToCommandService',
157                            $chkDataId
158                        );
159                    }
160                    if ($intRet3 != 0) {
161                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
162                    }
163                }
164                //if (($intRet1 + $intRet2 + $intRet3) != 0) {
165                    //$strInfoMessage = "";
166                //}
167                //
168                // Insert/update templates from session data
169                // =========================================
170                if ($chkModus == 'modify') {
171                    $strSQL    = 'DELETE FROM `tbl_lnkContacttemplateToContacttemplate` WHERE `idMaster`=' .$chkDataId;
172                    $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
173                    if ($booReturn == false) {
174                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
175                    }
176                }
177                if (isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition']) &&
178                    (count($_SESSION['templatedefinition']) != 0)) {
179                    $intSortId = 1;
180                    /** @noinspection ForeachSourceInspection */
181                    foreach ($_SESSION['templatedefinition'] as $elem) {
182                        if ($elem['status'] == 0) {
183                            $strSQL    = 'INSERT INTO `tbl_lnkContacttemplateToContacttemplate` (`idMaster`, '
184                                       . "`idSlave`,`idTable`,`idSort`) VALUES ($chkDataId,".$elem['idSlave']. ', '
185                                       . $elem['idTable']. ',' .$intSortId. ')';
186                            $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
187                            if ($booReturn == false) {
188                                $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
189                            }
190                        }
191                        $intSortId++;
192                    }
193                }
194                //
195                // Insert/update variables from session data
196                // =========================================
197                if ($chkModus == 'modify') {
198                    $strSQL    = 'SELECT * '
199                               . 'FROM `tbl_lnkContacttemplateToVariabledefinition` WHERE `idMaster`=' .$chkDataId;
200                    $booReturn = $myDBClass->hasDataArray($strSQL, $arrData, $intDataCount);
201                    if ($booReturn == false) {
202                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
203                    }
204                    if ($intDataCount != 0) {
205                        foreach ($arrData as $elem) {
206                            $strSQL    = 'DELETE FROM `tbl_variabledefinition` WHERE `id`=' .$elem['idSlave'];
207                            $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
208                            if ($booReturn == false) {
209                                $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
210                            }
211                        }
212                    }
213                    $strSQL    = 'DELETE FROM `tbl_lnkContacttemplateToVariabledefinition` '
214                               . 'WHERE `idMaster`=' .$chkDataId;
215                    $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
216                    if ($booReturn == false) {
217                        $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
218                    }
219                }
220                if (isset($_SESSION['variabledefinition']) && is_array($_SESSION['variabledefinition']) &&
221                    (count($_SESSION['variabledefinition']) != 0)) {
222                    foreach ($_SESSION['variabledefinition'] as $elem) {
223                        if ($elem['status'] == 0) {
224                            $strSQL    = 'INSERT INTO `tbl_variabledefinition` (`name`,`value`,`last_modified`) '
225                                       . "VALUES ('".$elem['definition']."','".$elem['range']."',now())";
226                            $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
227                            if ($booReturn == false) {
228                                $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
229                            }
230                            $strSQL    = 'INSERT INTO `tbl_lnkContacttemplateToVariabledefinition` (`idMaster`, '
231                                       . "`idSlave`) VALUES ($chkDataId,$intInsertId)";
232                            $booReturn = $myDataClass->dataInsert($strSQL, $intInsertId);
233                            if ($booReturn == false) {
234                                $myVisClass->processMessage($myDataClass->strErrorMessage, $strErrorMessage);
235                            }
236                        }
237                    }
238                }
239            }
240        } else {
241            $myVisClass->processMessage(
242                translate('Database entry failed! Not all necessary data filled in!'),
243                $strErrorMessage
244            );
245        }
246    } else {
247        $myVisClass->processMessage(translate('Database entry failed! No write access!'), $strErrorMessage);
248    }
249    $chkModus = 'display';
250}
251if ($chkModus != 'add') {
252    $chkModus = 'display';
253}
254//
255// Get date/time of last database and config file manipulation
256// ===========================================================
257$intReturn = $myConfigClass->lastModifiedFile($preTableName, $arrTimeData, $strTimeInfoString);
258if ($intReturn != 0) {
259    $myVisClass->processMessage($myConfigClass->strErrorMessage, $strErrorMessage);
260}
261//
262// Singe data form
263// ===============
264if ($chkModus == 'add') {
265    $conttp->setVariable('TITLE', translate('Define contact templates (contacttemplates.cfg)'));
266    // Do not show modified time list
267    $intNoTime = 1;
268    // Process template selection fields (Spezial)
269    $strWhere = '';
270    if (isset($arrModifyData) && ($chkSelModify == 'modify')) {
271        $strWhere = 'AND `id` <> ' .$arrModifyData['id'];
272    }
273    $strSQL1    = "SELECT `id`,`$preKeyField`, `active` FROM `$preTableName` "
274                . "WHERE $strDomainWhere $strWhere ORDER BY `$preKeyField`";
275    $booReturn1 = $myDBClass->hasDataArray($strSQL1, $arrDataTpl, $intDataCountTpl);
276    if ($booReturn1 == false) {
277        $myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
278    }
279    if ($intDataCountTpl != 0) {
280        /** @var array $arrDataTpl */
281        foreach ($arrDataTpl as $elem) {
282            if ($elem['active'] == 0) {
283                $strActive = ' [inactive]';
284                $conttp->setVariable('SPECIAL_STYLE', 'inactive_option');
285            } else {
286                $strActive = '';
287                $conttp->setVariable('SPECIAL_STYLE', '');
288            }
289            $conttp->setVariable('DAT_TEMPLATE', htmlspecialchars($elem[$preKeyField], ENT_QUOTES, 'UTF-8').$strActive);
290            $conttp->setVariable('DAT_TEMPLATE_ID', $elem['id']. '::1');
291            $conttp->parse('template');
292        }
293    }
294    $strSQL2    = 'SELECT `id`, `name`, `active` FROM `tbl_contact` '
295                . "WHERE `name` <> '' AND $strDomainWhere2 ORDER BY name";
296    $booReturn2 = $myDBClass->hasDataArray($strSQL2, $arrDataHpl, $intDataCountHpl);
297    if ($booReturn2 == false) {
298        $myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
299    }
300    if ($intDataCountHpl != 0) {
301        /** @var array $arrDataHpl */
302        foreach ($arrDataHpl as $elem) {
303            if ($elem['active'] == 0) {
304                $strActive = ' [inactive]';
305                $conttp->setVariable('SPECIAL_STYLE', 'inactive_option');
306            } else {
307                $strActive = '';
308                $conttp->setVariable('SPECIAL_STYLE', '');
309            }
310            $conttp->setVariable('DAT_TEMPLATE', htmlspecialchars($elem['name'], ENT_QUOTES, 'UTF-8').$strActive);
311            $conttp->setVariable('DAT_TEMPLATE_ID', $elem['id']. '::2');
312            $conttp->parse('template');
313        }
314    }
315    // Process timeperiod selection fields
316    if (isset($arrModifyData['host_notification_period'])) {
317        $intFieldId = $arrModifyData['host_notification_period'];
318    } else {
319        $intFieldId = 0;
320    }
321    $intReturn1 = $myVisClass->parseSelectSimple('tbl_timeperiod', 'timeperiod_name', 'host_time', 1, $intFieldId);
322    if ($intReturn1 != 0) {
323        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
324    }
325    if (isset($arrModifyData['service_notification_period'])) {
326        $intFieldId = $arrModifyData['service_notification_period'];
327    } else {
328        $intFieldId = 0;
329    }
330    $intReturn2 = $myVisClass->parseSelectSimple('tbl_timeperiod', 'timeperiod_name', 'service_time', 1, $intFieldId);
331    if ($intReturn2 != 0) {
332        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
333    }
334    // Process command selection fields
335    if (isset($arrModifyData['host_notification_commands'])) {
336        $intFieldId = $arrModifyData['host_notification_commands'];
337    } else {
338        $intFieldId = 0;
339    }
340    $intReturn3 = $myVisClass->parseSelectMulti(
341        'tbl_command',
342        'command_name',
343        'host_command',
344        'tbl_lnkContacttemplateToCommandHost',
345        0,
346        $intFieldId
347    );
348    if ($intReturn3 != 0) {
349        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
350    }
351    if (isset($arrModifyData['service_notification_commands'])) {
352        $intFieldId = $arrModifyData['service_notification_commands'];
353    } else {
354        $intFieldId = 0;
355    }
356    $intReturn4 = $myVisClass->parseSelectMulti(
357        'tbl_command',
358        'command_name',
359        'service_command',
360        'tbl_lnkContacttemplateToCommandService',
361        0,
362        $intFieldId
363    );
364    if ($intReturn4 != 0) {
365        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
366    }
367    // Process contactgroup selection field
368    if (isset($arrModifyData['contactgroups'])) {
369        $intFieldId = $arrModifyData['contactgroups'];
370    } else {
371        $intFieldId = 0;
372    }
373    $intReturn5 = $myVisClass->parseSelectMulti(
374        'tbl_contactgroup',
375        'contactgroup_name',
376        'contactgroup',
377        'tbl_lnkContacttemplateToContactgroup',
378        2,
379        $intFieldId
380    );
381    if ($intReturn5 != 0) {
382        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
383    }
384    // Process acces group selection field
385    if (isset($arrModifyData['access_group'])) {
386        $intFieldId = $arrModifyData['access_group'];
387    } else {
388        $intFieldId = 0;
389    }
390    $intReturn6 = $myVisClass->parseSelectSimple('tbl_group', 'groupname', 'acc_group', 0, $intFieldId);
391    if ($intReturn6 != 0) {
392        $myVisClass->processMessage($myVisClass->strErrorMessage, $strErrorMessage);
393    }
394    // Initial add/modify form definitions
395    $strChbFields = 'HNE,SNE,RSI,CSC,RNS,TPL,SEC,HOC,COG';
396    $myContentClass->addFormInit($conttp, $strChbFields);
397    if ($intDataWarning == 1) {
398        $conttp->setVariable('WARNING', $strDBWarning. '<br>' .translate('Saving not possible!'));
399    }
400    if ($intVersion == 4) {
401        $conttp->setVariable('HOST_OPTION_FIELDS', 'chbGr1a,chbGr1b,chbGr1c,chbGr1d,chbGr1e,chbGr1f');
402        $conttp->setVariable('SERVICE_OPTION_FIELDS', 'chbGr2a,chbGr2b,chbGr2c,chbGr2d,chbGr2e,chbGr2f,chbGr2g');
403    }
404    if ($intVersion == 3) {
405        $conttp->setVariable('HOST_OPTION_FIELDS', 'chbGr1a,chbGr1b,chbGr1c,chbGr1d,chbGr1e,chbGr1f');
406        $conttp->setVariable('SERVICE_OPTION_FIELDS', 'chbGr2a,chbGr2b,chbGr2c,chbGr2d,chbGr2e,chbGr2f,chbGr2g');
407    }
408    if ($intVersion < 3) {
409        $conttp->setVariable('HOST_OPTION_FIELDS', 'chbGr1a,chbGr1b,chbGr1c,chbGr1d,chbGr1f');
410        $conttp->setVariable('SERVICE_OPTION_FIELDS', 'chbGr2a,chbGr2b,chbGr2c,chbGr2d,chbGr2e,chbGr2g');
411        $conttp->setVariable('VERSION_20_VALUE_MUST', ',tfValue2');
412    }
413    // Insert data from database in "modify" mode
414    if (isset($arrModifyData) && ($chkSelModify == 'modify')) {
415        // Check relation information to find out locked configuration datasets
416        $intLocked = $myDataClass->infoRelation($preTableName, $arrModifyData['id'], $preKeyField);
417        $myVisClass->processMessage($myDataClass->strInfoMessage, $strRelMessage);
418        $strInfo  = '<br><span class="redmessage">' .translate('Entry cannot be activated because it is used by '
419                  . 'another configuration'). ':</span>';
420        $strInfo .= '<br><span class="greenmessage">' .$strRelMessage. '</span>';
421        // Process data
422        $myContentClass->addInsertData($conttp, $arrModifyData, $intLocked, $strInfo, $strChbFields);
423        // Process radio fields
424        $conttp->setVariable('DAT_HNE' .$arrModifyData['host_notifications_enabled']. '_CHECKED', 'checked');
425        $conttp->setVariable('DAT_SNE' .$arrModifyData['service_notifications_enabled']. '_CHECKED', 'checked');
426        $conttp->setVariable('DAT_RSI' .$arrModifyData['retain_status_information']. '_CHECKED', 'checked');
427        $conttp->setVariable('DAT_CSC' .$arrModifyData['can_submit_commands']. '_CHECKED', 'checked');
428        $conttp->setVariable('DAT_RNS' .$arrModifyData['retain_nonstatus_information']. '_CHECKED', 'checked');
429        $conttp->setVariable('DAT_TPL' .$arrModifyData['use_template_tploptions']. '_CHECKED', 'checked');
430        $conttp->setVariable(
431            'DAT_SEC' .$arrModifyData['service_notification_commands_tploptions']. '_CHECKED',
432            'checked'
433        );
434        $conttp->setVariable('DAT_HOC' .$arrModifyData['host_notification_commands_tploptions']. '_CHECKED', 'checked');
435        $conttp->setVariable('DAT_COG' .$arrModifyData['contactgroups_tploptions']. '_CHECKED', 'checked');
436        // Process option fields
437        foreach (explode(',', $arrModifyData['host_notification_options']) as $elem) {
438            $conttp->setVariable('DAT_HO' .strtoupper($elem). '_CHECKED', 'checked');
439        }
440        foreach (explode(',', $arrModifyData['service_notification_options']) as $elem) {
441            $conttp->setVariable('DAT_SO' .strtoupper($elem). '_CHECKED', 'checked');
442        }
443    }
444    $conttp->parse('datainsert');
445    $conttp->show('datainsert');
446}
447//
448// List view
449// ==========
450if ($chkModus == 'display') {
451    // Initial list view definitions
452    $myContentClass->listViewInit($mastertp);
453    $mastertp->setVariable('TITLE', translate('Define contact templates (contacttemplates.cfg)'));
454    $mastertp->setVariable('FIELD_1', translate('Contact name'));
455    $mastertp->setVariable('FIELD_2', translate('Description'));
456    $mastertp->setVariable('FILTER_VISIBLE', 'visibility: hidden');
457    // Process filter string
458    if ($_SESSION['search'][$preSearchSession] != '') {
459        $strSearchTxt   = $_SESSION['search'][$preSearchSession];
460        $strSearchWhere = "AND (`$preKeyField` LIKE '%".$strSearchTxt."%' OR `alias` LIKE '%".$strSearchTxt."%' OR "
461                        . "`email` LIKE '%".$strSearchTxt."%' OR `pager` LIKE '%".$strSearchTxt."%' OR "
462                        . "`address1` LIKE '%".$strSearchTxt."%' OR `address2` LIKE '%".$strSearchTxt."%' OR "
463                        . "`address3` LIKE '%".$strSearchTxt."%' OR `address4` LIKE '%".$strSearchTxt."%' OR "
464                        . "`address5` LIKE '%".$strSearchTxt."%' OR `address6` LIKE '%".$strSearchTxt."%')";
465    }
466    // Row sorting
467    $strOrderString = "ORDER BY `config_id`, `$preKeyField` $hidSortDir";
468    if ($hidSortBy == 2) {
469        $strOrderString = "ORDER BY `config_id`, `alias` $hidSortDir";
470    }
471    // Count datasets
472    $strSQL     = 'SELECT count(*) AS `number` '
473                . "FROM `$preTableName` WHERE $strDomainWhere $strSearchWhere AND `access_group` IN ($strAccess)";
474    $booReturn1 = $myDBClass->hasSingleDataset($strSQL, $arrDataLinesCount);
475    if ($booReturn1 == false) {
476        $myVisClass->processMessage(translate('Error while selecting data from database:'), $strErrorMessage);
477        $myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
478    } else {
479        $intLineCount = (int)$arrDataLinesCount['number'];
480        if ($intLineCount < $chkLimit) {
481            $chkLimit = 0;
482        }
483    }
484    // Get datasets
485    $strSQL     = "SELECT `id`, `$preKeyField`, `alias`, `active`, `register`, `config_id`, `access_group` "
486                . "FROM `$preTableName` WHERE $strDomainWhere $strSearchWhere AND `access_group` IN ($strAccess) "
487                . "$strOrderString LIMIT $chkLimit,".$SETS['common']['pagelines'];
488    $booReturn2 = $myDBClass->hasDataArray($strSQL, $arrDataLines, $intDataCount);
489    if ($booReturn2 == false) {
490        $myVisClass->processMessage(translate('Error while selecting data from database:'), $strErrorMessage);
491        $myVisClass->processMessage($myDBClass->strErrorMessage, $strErrorMessage);
492    }
493    // Process data
494    $myContentClass->listData($mastertp, $arrDataLines, $intDataCount, $intLineCount, $preKeyField, 'alias');
495}
496// Show messages
497$myContentClass->showMessages(
498    $mastertp,
499    $strErrorMessage,
500    $strInfoMessage,
501    $strConsistMessage,
502    $arrTimeData,
503    $strTimeInfoString,
504    $intNoTime
505);
506//
507// Process footer
508// ==============
509$myContentClass->showFooter($maintp, $setFileVersion);
510