1<?php
2///////////////////////////////////////////////////////////////////////////////
3//
4// NagiosQL
5//
6///////////////////////////////////////////////////////////////////////////////
7//
8// (c) 2005-2020 by Martin Willisegger
9//
10// Project   : NagiosQL
11// Component : Content Class
12// Website   : https://sourceforge.net/projects/nagiosql/
13// Version   : 3.4.1
14// GIT Repo  : https://gitlab.com/wizonet/NagiosQL
15//
16///////////////////////////////////////////////////////////////////////////////////////////////
17//
18///////////////////////////////////////////////////////////////////////////////////////////////
19//
20// Class: Common content functions
21//
22///////////////////////////////////////////////////////////////////////////////////////////////
23//
24// Includes all functions used to display the application data
25//
26// Name: nagcontent
27//
28///////////////////////////////////////////////////////////////////////////////////////////////
29namespace functions;
30
31class NagContentClass
32{
33    // Define class variables
34    private $arrSettings         = array();  // Array includes all global settings
35    //
36    public $arrSession           = array();  // Session content
37    public $arrDescription       = array();  // Text values from fieldvars.php
38    public $intLimit             = 15;       // Data limit value
39    public $intDomainId          = 0;        // Configuration domain ID
40    public $intSortBy            = -1;       // Sort by field id
41    public $intGlobalWriteAccess = -1;       // Global write access id
42    public $intVersion           = 0;        // Nagios version id
43    public $intGroupAdm          = 0;        // Group admin enabled/disabled
44    public $intWriteAccessId     = 0;        // Write access id
45    public $strTableName         = '';       // Data table name
46    public $strSearchSession     = '';       // Search session name
47    public $strErrorMessage      = '';       // String including error messages
48    public $strSortDir           = 'ASC';    // SQL sort direction (ASC/DESC)
49    public $strBrowser           = '';       // Browser string
50
51    // Class includes
52    /** @var MysqliDbClass */
53    public $myDBClass;                       // Database class reference
54    /** @var NagConfigClass */
55    public $myConfigClass;                   // NagiosQL configuration class object
56    /** @var NagVisualClass */
57    public $myVisClass;                      // NagiosQL visual class object
58
59    /**
60     * NagContentClass constructor.
61     * @param array $arrSession                 PHP Session array
62     */
63    public function __construct($arrSession)
64    {
65        if (isset($arrSession['SETS'])) {
66            // Read global settings
67            $this->arrSettings = $arrSession['SETS'];
68        }
69        if (isset($arrSession['domain'])) {
70            $this->intDomainId = $arrSession['domain'];
71        }
72        $this->arrSession    = $arrSession;
73    }
74
75    /**
76     * Data list view - form initialization
77     * @param \HTML_Template_IT $objTemplate    Form template object
78     */
79    public function listViewInit($objTemplate)
80    {
81        // Language text replacements from fieldvars.php file
82        foreach ($this->arrDescription as $elem) {
83            $objTemplate->setVariable($elem['name'], $elem['string']);
84        }
85        // Some single replacements
86        $objTemplate->setVariable('LIMIT', $this->intLimit);
87        $objTemplate->setVariable('ACTION_MODIFY', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
88        $objTemplate->setVariable('TABLE_NAME', $this->strTableName);
89        if (isset($this->arrSession['search'][$this->strSearchSession])) {
90            $objTemplate->setVariable('DAT_SEARCH', $this->arrSession['search'][$this->strSearchSession]);
91        }
92        $objTemplate->setVariable('MAX_ID', '0');
93        $objTemplate->setVariable('MIN_ID', '0');
94    }
95
96    /**
97     * Data list view - value insertions
98     * @param \HTML_Template_IT $objTemplate    Form template object
99     * @param array $arrData                    Database values
100     * @param int $intDLCount1                  Total count of data lines for one page
101     * @param int $intDLCount2                  Total count of data lines (all data)
102     * @param string $strField1                 Field name for data field 1
103     * @param string $strField2                 Field name for data field 2
104     * @param int $intLimit                     Actual data char limit for field 2
105     */
106    public function listData(
107        $objTemplate,
108        $arrData,
109        $intDLCount1,
110        $intDLCount2,
111        $strField1,
112        $strField2,
113        $intLimit = 0
114    ) {
115        // Template block names
116        $strTplPart = 'datatable';
117        $strTplRow  = 'datarow';
118        if ($this->strTableName == 'tbl_host') {
119            $strTplPart = 'datatablehost';
120            $strTplRow  = 'datarowhost';
121        }
122        if ($this->strTableName == 'tbl_service') {
123            $strTplPart = 'datatableservice';
124            $strTplRow  = 'datarowservice';
125        }
126        if (($this->strTableName == 'tbl_user') || ($this->strTableName == 'tbl_group') ||
127            ($this->strTableName == 'tbl_datadomain') || ($this->strTableName == 'tbl_configtarget')) {
128            $strTplPart = 'datatablecommon';
129            $strTplRow  = 'datarowcommon';
130        }
131        // Some single replacements
132        $objTemplate->setVariable('IMAGE_PATH_HEAD', $this->arrSettings['path']['base_url']. 'images/');
133        $objTemplate->setVariable('CELLCLASS_L', 'tdlb');
134        $objTemplate->setVariable('CELLCLASS_M', 'tdmb');
135        $objTemplate->setVariable('DISABLED', 'disabled');
136        $objTemplate->setVariable('DATA_FIELD_1', translate('No data'));
137        $objTemplate->setVariable('DATA_FIELD_2', '&nbsp;');
138        $objTemplate->setVariable('DATA_REGISTERED', '&nbsp;');
139        $objTemplate->setVariable('DATA_ACTIVE', '&nbsp;');
140        $objTemplate->setVariable('DATA_FILE', '&nbsp;');
141        $objTemplate->setVariable('PICTURE_CLASS', 'elementHide');
142        $objTemplate->setVariable('DOMAIN_SPECIAL', '&nbsp;');
143        $objTemplate->setVariable('SORT_BY', $this->intSortBy);
144        // Inserting data values
145        if ($intDLCount1 != 0) {
146            $intMinID = 0;
147            $intMaxID = 0;
148            for ($i=0; $i<$intDLCount1; $i++) {
149                // Get biggest and smalest value
150                if ($i == 0) {
151                    $intMinID = $arrData[$i]['id'];
152                    $intMaxID = $arrData[$i]['id'];
153                }
154                if ($arrData[$i]['id'] < $intMinID) {
155                    $intMinID = $arrData[$i]['id'];
156                }
157                if ($arrData[$i]['id'] > $intMaxID) {
158                    $intMaxID = $arrData[$i]['id'];
159                }
160                $objTemplate->setVariable('MAX_ID', $intMaxID);
161                $objTemplate->setVariable('MIN_ID', $intMinID);
162                // Line colours
163                $strClassL = 'tdld';
164                $strClassM = 'tdmd';
165                if ($i%2 == 1) {
166                    $strClassL = 'tdlb';
167                    $strClassM = 'tdmb';
168                }
169                if (isset($arrData[$i]['register']) && ($arrData[$i]['register'] == 0)) {
170                    $strRegister = translate('No');
171                } else {
172                    $strRegister = translate('Yes');
173                }
174                if ($arrData[$i]['active']   == 0) {
175                    $strActive     = translate('No');
176                } else {
177                    $strActive    = translate('Yes');
178                }
179                // Get file date for hosts and services
180                $intTimeInfo = 0;
181                $arrTimeData = array();
182                if ($this->strTableName == 'tbl_host') {
183                    $intReturn = $this->myConfigClass->lastModifiedDir(
184                        $this->strTableName,
185                        $arrData[$i]['host_name'],
186                        $arrData[$i]['id'],
187                        $arrTimeData,
188                        $intTimeInfo
189                    );
190                    if ($intReturn == 1) {
191                        $this->strErrorMessage = $this->myConfigClass->strErrorMessage;
192                    }
193                }
194                if ($this->strTableName == 'tbl_service') {
195                    $intReturn = $this->myConfigClass->lastModifiedDir(
196                        $this->strTableName,
197                        $arrData[$i]['config_name'],
198                        $arrData[$i]['id'],
199                        $arrTimeData,
200                        $intTimeInfo
201                    );
202                    if ($intReturn == 1) {
203                        $this->strErrorMessage = $this->myConfigClass->strErrorMessage;
204                    }
205                }
206                // Set datafields
207                foreach ($this->arrDescription as $elem) {
208                    $objTemplate->setVariable($elem['name'], $elem['string']);
209                }
210                if ($arrData[$i][$strField1] == '') {
211                    $arrData[$i][$strField1] = 'NOT DEFINED - ' .$arrData[$i]['id'];
212                }
213                $objTemplate->setVariable('DATA_FIELD_1', htmlentities($arrData[$i][$strField1], ENT_COMPAT, 'UTF-8'));
214                $objTemplate->setVariable('DATA_FIELD_1S', addslashes(htmlentities(
215                    $arrData[$i][$strField1],
216                    ENT_COMPAT,
217                    'UTF-8'
218                )));
219                if ($strField2 == 'process_field') {
220                    $arrData[$i]['process_field'] = $this->processField($arrData[$i], $this->strTableName);
221                } else {
222                    $objTemplate->setVariable('DATA_FIELD_2S', addslashes(htmlentities(
223                        $arrData[$i][$strField2],
224                        ENT_COMPAT,
225                        'UTF-8'
226                    )));
227                }
228                if ($intLimit != 0) {
229                    if (\strlen($arrData[$i][$strField2]) > $intLimit) {
230                        $strAdd = ' ...';
231                    } else {
232                        $strAdd = '';
233                    }
234                    $objTemplate->setVariable('DATA_FIELD_2', htmlentities(substr(
235                            $arrData[$i][$strField2],
236                            0,
237                            $intLimit
238                        ), ENT_COMPAT, 'UTF-8').$strAdd);
239                } else {
240                    $objTemplate->setVariable('DATA_FIELD_2', htmlentities(
241                        $arrData[$i][$strField2],
242                        ENT_COMPAT,
243                        'UTF-8'
244                    ));
245                }
246                $objTemplate->setVariable('DATA_REGISTERED', $strRegister);
247                if (substr_count($this->strTableName, 'template') != 0) {
248                    $objTemplate->setVariable('DATA_REGISTERED', '-');
249                }
250                $objTemplate->setVariable('DATA_ACTIVE', $strActive);
251                $objTemplate->setVariable('DATA_FILE', '<span class="redmessage">'.translate('out-of-date').'</span>');
252                if ($intTimeInfo == 4) {
253                    $objTemplate->setVariable('DATA_FILE', translate('no target'));
254                }
255                if ($intTimeInfo == 3) {
256                    $objTemplate->setVariable('DATA_FILE', '<span class="greenmessage">'.translate('missed').'</span>');
257                }
258                if ($intTimeInfo == 2) {
259                    $objTemplate->setVariable('DATA_FILE', '<span class="redmessage">'.translate('missed').'</span>');
260                }
261                if ($intTimeInfo == 0) {
262                    $objTemplate->setVariable('DATA_FILE', translate('up-to-date'));
263                }
264                $objTemplate->setVariable('LINE_ID', $arrData[$i]['id']);
265                $objTemplate->setVariable('CELLCLASS_L', $strClassL);
266                $objTemplate->setVariable('CELLCLASS_M', $strClassM);
267                $objTemplate->setVariable('IMAGE_PATH', $this->arrSettings['path']['base_url']. 'images/');
268                $objTemplate->setVariable('PICTURE_CLASS', 'elementShow');
269                $objTemplate->setVariable('DOMAIN_SPECIAL', '');
270                $objTemplate->setVariable('DISABLED', '');
271                // Disable common domain objects
272                if (isset($arrData[$i]['config_id'])) {
273                    if ($arrData[$i]['config_id'] != $this->intDomainId) {
274                        $objTemplate->setVariable('PICTURE_CLASS', 'elementHide');
275                        $objTemplate->setVariable('DOMAIN_SPECIAL', ' [common]');
276                        $objTemplate->setVariable('DISABLED', 'disabled');
277                    } else {
278                        // Inactive items should not be written/downloaded
279                        if ($arrData[$i]['active'] == 0) {
280                            $objTemplate->setVariable('ACTIVE_CONTROL', 'elementHide');
281                        }
282                    }
283                }
284                // Check access rights for list objects
285                if (isset($arrData[$i]['access_group'])) {
286                    if ($this->myVisClass->checkAccountGroup($arrData[$i]['access_group'], 'write') != 0) {
287                        $objTemplate->setVariable('LINE_CONTROL', 'elementHide');
288                    }
289                } else {
290                    if ($this->intGlobalWriteAccess != 0) {
291                        $objTemplate->setVariable('LINE_CONTROL', 'elementHide');
292                    }
293                }
294                // Check global access rights for list objects
295                if ($this->intGlobalWriteAccess != 0) {
296                    $objTemplate->setVariable('LINE_CONTROL', 'elementHide');
297                }
298                $objTemplate->parse($strTplRow);
299            }
300        } else {
301            $objTemplate->setVariable('IMAGE_PATH', $this->arrSettings['path']['base_url']. 'images/');
302            $objTemplate->parse($strTplRow);
303        }
304        $objTemplate->setVariable('BUTTON_CLASS', 'elementShow');
305        if ($this->intDomainId == 0) {
306            $objTemplate->setVariable('BUTTON_CLASS', 'elementHide');
307        }
308        // Check access rights for adding new objects
309        if ($this->intGlobalWriteAccess != 0) {
310            $objTemplate->setVariable('ADD_CONTROL', 'disabled="disabled"');
311        }
312        // Show page numbers
313        $objTemplate->setVariable('PAGES', $this->myVisClass->buildPageLinks(filter_input(
314            INPUT_SERVER,
315            'PHP_SELF',
316            FILTER_SANITIZE_STRING
317        ), $intDLCount2, $this->intLimit, $this->intSortBy, $this->strSortDir));
318        $objTemplate->parse($strTplPart);
319        $objTemplate->show($strTplPart);
320    }
321
322    /**
323     * Display information messages
324     * @param \HTML_Template_IT $objTemplate    Form template object
325     * @param string $strErrorMessage           Error messages
326     * @param string $strInfoMessage            Information messages
327     * @param string $strConsistMessage         Consistency messages
328     * @param array $arrTimeData                Time data array
329     * @param string $strTimeInfoString         Time information message
330     * @param int $intNoTime                    Status value for showing time information (0 = show time)
331     */
332    public function showMessages(
333        $objTemplate,
334        $strErrorMessage,
335        $strInfoMessage,
336        $strConsistMessage,
337        $arrTimeData,
338        $strTimeInfoString,
339        $intNoTime = 0
340    ) {
341        // Display info messages
342        if ($strInfoMessage != '') {
343            $objTemplate->setVariable('INFOMESSAGE', $strInfoMessage);
344            $objTemplate->parse('infomessage');
345        }
346        // Display error messages
347        if ($strErrorMessage != '') {
348            $objTemplate->setVariable('ERRORMESSAGE', $strErrorMessage);
349            $objTemplate->parse('errormessage');
350        }
351        // Display time informations
352        if (($this->intDomainId != 0) && ($intNoTime == 0)) {
353            foreach ($arrTimeData as $key => $elem) {
354                if ($key == 'table') {
355                    $objTemplate->setVariable('LAST_MODIFIED_TABLE', translate('Last database update:'). ' <b>' .
356                        $elem. '</b>');
357                    $objTemplate->parse('table_time');
358                } else {
359                    $objTemplate->setVariable('LAST_MODIFIED_FILE', translate('Last file change of the configuration '.
360                            'target '). ' <i>' .$key. '</i>: <b>' .$elem. '</b>');
361                    $objTemplate->parse('file_time');
362                }
363            }
364            if ($strTimeInfoString != '') {
365                $objTemplate->setVariable('MODIFICATION_STATUS', $strTimeInfoString);
366                $objTemplate->parse('modification_status');
367            }
368        }
369        // Display consistency messages
370        if ($strConsistMessage != '') {
371            $objTemplate->setVariable('CONSIST_USAGE', $strConsistMessage);
372            $objTemplate->parse('consistency');
373        }
374        $objTemplate->parse('msgfooter');
375        $objTemplate->show('msgfooter');
376    }
377
378    /**
379     * Display page footer
380     * @param \HTML_Template_IT $objTemplate    Form template object
381     * @param string $setFileVersion            NagiosQL version
382     */
383    public function showFooter($objTemplate, $setFileVersion)
384    {
385        $objTemplate->setVariable('VERSION_INFO', "<a href='https://sourceforge.net/projects/nagiosql/' ".
386            "target='_blank'>NagiosQL</a> $setFileVersion");
387        $objTemplate->parse('footer');
388        $objTemplate->show('footer');
389    }
390
391    /**
392     * Single data form initialization
393     * @param \HTML_Template_IT $objTemplate    Form template object
394     * @param string $strChbFields              Comma separated string of checkbox value names
395     */
396    public function addFormInit($objTemplate, $strChbFields = '')
397    {
398        // Language text replacements from fieldvars.php file
399        foreach ($this->arrDescription as $elem) {
400            $objTemplate->setVariable($elem['name'], $elem['string']);
401        }
402        // Some single replacements
403        $objTemplate->setVariable('ACTION_INSERT', filter_input(INPUT_SERVER, 'PHP_SELF', FILTER_SANITIZE_STRING));
404        $objTemplate->setVariable('IMAGE_PATH', $this->arrSettings['path']['base_url']. 'images/');
405        $objTemplate->setVariable('DOCUMENT_ROOT', $this->arrSettings['path']['base_url']);
406        $objTemplate->setVariable('ACT_CHECKED', 'checked');
407        $objTemplate->setVariable('REG_CHECKED', 'checked');
408        $objTemplate->setVariable('MODUS', 'insert');
409        $objTemplate->setVariable('VERSION', $this->intVersion);
410        $objTemplate->setVariable('LIMIT', $this->intLimit);
411        $objTemplate->setVariable('RELATION_CLASS', 'elementHide');
412        $objTemplate->setVariable('IFRAME_SRC', $this->arrSettings['path']['base_url']. 'admin/commandline.php');
413        // Some conditional replacements
414        if ($this->strBrowser != 'msie') {
415            $objTemplate->setVariable('MSIE_DISABLED', 'disabled="disabled"');
416        }
417        if ($this->intGroupAdm == 0) {
418            $objTemplate->setVariable('RESTRICT_GROUP_ADMIN', 'class="elementHide"');
419        }
420        if ($this->arrSettings['common']['seldisable'] == 0) {
421            $objTemplate->setVariable('MSIE_DISABLED', '');
422        }
423        if ($this->arrSettings['common']['tplcheck'] == 0) {
424            $objTemplate->setVariable('CHECK_BYPASS', 'return true;');
425            $objTemplate->setVariable('CHECK_BYPASS_NEW', '1');
426        } else {
427            $objTemplate->setVariable('CHECK_BYPASS_NEW', '0');
428        }
429        // Some replacements based on nagios version
430        if ($this->intVersion < 3) {
431            $objTemplate->setVariable('VERSION_20_VISIBLE', 'elementShow');
432            $objTemplate->setVariable('VERSION_30_VISIBLE', 'elementHide');
433            $objTemplate->setVariable('VERSION_40_VISIBLE', 'elementHide');
434            $objTemplate->setVariable('VERSION_20_MUST', 'inpmust');
435            $objTemplate->setVariable('VERSION_30_MUST', '');
436            $objTemplate->setVariable('VERSION_40_MUST', '');
437            $objTemplate->setVariable('VERSION_20_STAR', '*');
438            $objTemplate->setVariable('NAGIOS_VERSION', '2');
439        }
440        if ($this->intVersion >= 3) {
441            $objTemplate->setVariable('VERSION_20_VISIBLE', 'elementHide');
442            $objTemplate->setVariable('VERSION_30_VISIBLE', 'elementShow');
443            $objTemplate->setVariable('VERSION_40_VISIBLE', 'elementHide');
444            $objTemplate->setVariable('VERSION_20_MUST', '');
445            $objTemplate->setVariable('VERSION_30_MUST', 'inpmust');
446            $objTemplate->setVariable('VERSION_40_MUST', '');
447            $objTemplate->setVariable('VERSION_20_STAR', '');
448            $objTemplate->setVariable('NAGIOS_VERSION', '3');
449        }
450        if ($this->intVersion >= 4) {
451            $objTemplate->setVariable('VERSION_40_VISIBLE', 'elementShow');
452            $objTemplate->setVariable('VERSION_40_MUST', 'inpmust');
453            $objTemplate->setVariable('NAGIOS_VERSION', '4');
454        }
455        // Checkbox and radio field value replacements
456        if ($strChbFields != '') {
457            foreach (explode(',', $strChbFields) as $elem) {
458                $objTemplate->setVariable('DAT_' .$elem. '0_CHECKED', '');
459                $objTemplate->setVariable('DAT_' .$elem. '1_CHECKED', '');
460                $objTemplate->setVariable('DAT_' .$elem. '2_CHECKED', 'checked');
461            }
462        }
463    }
464
465    /**
466     * Single data form - value insertion
467     * @param \HTML_Template_IT $objTemplate    Form template object
468     * @param array $arrModifyData              Database values
469     * @param int $intLocked                    Data is locked (0 = no / 1 = yes)
470     * @param string $strInfo                   Information string
471     * @param string $strChbFields              Comma separated string of checkbox value names
472     */
473    public function addInsertData($objTemplate, $arrModifyData, $intLocked, $strInfo, $strChbFields = '')
474    {
475        // Insert text data values
476        foreach ($arrModifyData as $key => $value) {
477            if (($key == 'active') || ($key == 'register') || ($key == 'last_modified') || ($key == 'access_rights')) {
478                continue;
479            }
480            $objTemplate->setVariable('DAT_' .strtoupper($key), htmlentities($value, ENT_QUOTES, 'UTF-8'));
481        }
482        // Insert checkbox data values
483        if (isset($arrModifyData['active']) && ($arrModifyData['active']   != 1)) {
484            $objTemplate->setVariable('ACT_CHECKED', '');
485        }
486        if (isset($arrModifyData['register']) && ($arrModifyData['register'] != 1)) {
487            $objTemplate->setVariable('REG_CHECKED', '');
488        }
489        // Deselect any checkboxes
490        if ($strChbFields != '') {
491            foreach (explode(',', $strChbFields) as $elem) {
492                $objTemplate->setVariable('DAT_' .$elem. '0_CHECKED', '');
493                $objTemplate->setVariable('DAT_' .$elem. '1_CHECKED', '');
494                $objTemplate->setVariable('DAT_' .$elem. '2_CHECKED', '');
495            }
496        }
497        // Change some status values in locked data sets
498        if ($intLocked != 0) {
499            $objTemplate->setVariable('ACT_DISABLED', 'disabled');
500            $objTemplate->setVariable('ACT_CHECKED', 'checked');
501            $objTemplate->setVariable('ACTIVE', '1');
502            $objTemplate->setVariable('CHECK_MUST_DATA', $strInfo);
503            $objTemplate->setVariable('RELATION_CLASS', 'elementShow');
504        }
505        // Change mode to modify
506        $objTemplate->setVariable('MODUS', 'modify');
507        // Check write permission
508        if ($this->intWriteAccessId == 1) {
509            $objTemplate->setVariable('DISABLE_SAVE', 'disabled="disabled"');
510        }
511        if ($this->intGlobalWriteAccess == 1) {
512            $objTemplate->setVariable('DISABLE_SAVE', 'disabled="disabled"');
513        }
514    }
515
516    /**
517     * Process field view
518     * @param array $arrData                    Data array
519     * @param string $strTableName              Table name
520     * @return string                           String includung field data
521     */
522    public function processField($arrData, $strTableName)
523    {
524        $strField          = '';
525        $arrDataHosts      = array();
526        $arrDataHostgroups = array();
527        $arrDataService    = array();
528        $arrDataServices   = array();
529        // Hostdependency table
530        if ($strTableName == 'tbl_hostdependency') {
531            if ($arrData['dependent_host_name'] != 0) {
532                $strSQLHost = 'SELECT `host_name`, `exclude` FROM `tbl_host` ' .
533                    'LEFT JOIN `tbl_lnkHostdependencyToHost_DH` ON `id`=`idSlave` ' .
534                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `host_name`';
535                $this->myDBClass->hasDataArray($strSQLHost, $arrDataHosts, $intDCHost);
536                if ($intDCHost != 0) {
537                    foreach ($arrDataHosts as $elem) {
538                        if ($elem['exclude'] == 1) {
539                            $strField .= 'H:!' .$elem['host_name']. ',';
540                        } else {
541                            $strField .= 'H:' .$elem['host_name']. ',';
542                        }
543                    }
544                }
545            }
546            if ($arrData['dependent_hostgroup_name'] != 0) {
547                $strSQLHost = 'SELECT `hostgroup_name`, `exclude` FROM `tbl_hostgroup` ' .
548                    'LEFT JOIN `tbl_lnkHostdependencyToHostgroup_DH` ON `id`=`idSlave` ' .
549                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `hostgroup_name`';
550                $this->myDBClass->hasDataArray($strSQLHost, $arrDataHostgroups, $intDCHostgroup);
551                if ($intDCHostgroup != 0) {
552                    foreach ($arrDataHostgroups as $elem) {
553                        if ($elem['exclude'] == 1) {
554                            $strField .= 'HG:!' .$elem['hostgroup_name']. ',';
555                        } else {
556                            $strField .= 'HG:' .$elem['hostgroup_name']. ',';
557                        }
558                    }
559                }
560            }
561        }
562        // Hostescalation table
563        if ($strTableName == 'tbl_hostescalation') {
564            if ($arrData['host_name'] != 0) {
565                $strSQLHost = 'SELECT `host_name` FROM `tbl_host` ' .
566                    'LEFT JOIN `tbl_lnkHostescalationToHost` ON `id`=`idSlave` ' .
567                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `host_name`';
568                $this->myDBClass->hasDataArray($strSQLHost, $arrDataHosts, $intDCHost);
569                if ($intDCHost != 0) {
570                    foreach ($arrDataHosts as $elem) {
571                        $strField .= 'H:' .$elem['host_name']. ',';
572                    }
573                }
574            }
575            if ($arrData['hostgroup_name'] != 0) {
576                $strSQLHost = 'SELECT `hostgroup_name` FROM `tbl_hostgroup` ' .
577                    'LEFT JOIN `tbl_lnkHostescalationToHostgroup` ON `id`=`idSlave` ' .
578                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `hostgroup_name`';
579                $this->myDBClass->hasDataArray($strSQLHost, $arrDataHostgroups, $intDCHostgroup);
580                if ($intDCHostgroup != 0) {
581                    foreach ($arrDataHostgroups as $elem) {
582                        $strField .= 'HG:' .$elem['hostgroup_name']. ',';
583                    }
584                }
585            }
586        }
587        // Servicedependency table
588        if ($strTableName == 'tbl_servicedependency') {
589            if ($arrData['dependent_service_description'] == 2) {
590                $strField .= '*';
591            } elseif ($arrData['dependent_service_description'] != 0) {
592                $strSQLService = 'SELECT `strSlave` FROM `tbl_lnkServicedependencyToService_DS` ' .
593                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `strSlave`';
594                $this->myDBClass->hasDataArray($strSQLService, $arrDataService, $intDCService);
595                if ($intDCService != 0) {
596                    foreach ($arrDataService as $elem) {
597                        $strField .= $elem['strSlave']. ',';
598                    }
599                }
600            }
601            if ($strField == '') {
602                $strSQLService = 'SELECT `servicegroup_name` FROM `tbl_servicegroup` ' .
603                    'LEFT JOIN `tbl_lnkServicedependencyToServicegroup_DS` ON `idSlave`=`id` ' .
604                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `servicegroup_name`';
605                $this->myDBClass->hasDataArray($strSQLService, $arrDataService, $intDCService);
606                if ($intDCService != 0) {
607                    foreach ($arrDataService as $elem) {
608                        $strField .= $elem['servicegroup_name']. ',';
609                    }
610                }
611            }
612        }
613        // Serviceescalation table
614        if ($strTableName == 'tbl_serviceescalation') {
615            if ($arrData['service_description'] == 2) {
616                $strField .= '*';
617            } elseif ($arrData['service_description'] != 0) {
618                $strSQLService = 'SELECT `strSlave` FROM `tbl_lnkServiceescalationToService` ' .
619                    'WHERE `idMaster`=' .$arrData['id'];
620                $this->myDBClass->hasDataArray($strSQLService, $arrDataServices, $intDCServices);
621                if ($intDCServices != 0) {
622                    foreach ($arrDataServices as $elem) {
623                        $strField .= $elem['strSlave']. ',';
624                    }
625                }
626            }
627            if ($strField == '') {
628                $strSQLService = 'SELECT `servicegroup_name` FROM `tbl_servicegroup` ' .
629                    'LEFT JOIN `tbl_lnkServiceescalationToServicegroup` ON `idSlave`=`id` ' .
630                    'WHERE `idMaster`=' .$arrData['id']. ' ORDER BY `servicegroup_name`';
631                $this->myDBClass->hasDataArray($strSQLService, $arrDataService, $intDCService);
632                if ($intDCService != 0) {
633                    foreach ($arrDataService as $elem) {
634                        $strField .= $elem['servicegroup_name']. ',';
635                    }
636                }
637            }
638        }
639        // Some string manipulations - remove comma on line end
640        if (substr($strField, -1) == ',') {
641            $strField = substr($strField, 0, -1);
642        }
643        return $strField;
644    }
645}
646