array('default' => 0))); $chkMode = filter_input(INPUT_GET, 'mode'); $chkKey = filter_input(INPUT_GET, 'key'); $chkDef = filter_input(INPUT_GET, 'def'); $chkType = filter_input(INPUT_GET, 'type'); if ($chkDataId === '') { $chkDataId = 0; } $arrDefinition = explode('::', $chkDef); if ($chkType === '') { exit; } if ($chkType === 'host') { $chkLinkTab = 'tbl_lnkHostToHosttemplate'; $chkPreTab = 'host'; } if ($chkType === 'hosttemplate') { $chkLinkTab = 'tbl_lnkHosttemplateToHosttemplate'; $chkPreTab = 'host'; } if ($chkType === 'service') { $chkLinkTab = 'tbl_lnkServiceToServicetemplate'; $chkPreTab = 'service'; } if ($chkType === 'servicetemplate') { $chkLinkTab = 'tbl_lnkServicetemplateToServicetemplate'; $chkPreTab = 'service'; } if ($chkType === 'contact') { $chkLinkTab = 'tbl_lnkContactToContacttemplate'; $chkPreTab = 'contact'; } if ($chkType === 'contacttemplate') { $chkLinkTab = 'tbl_lnkContacttemplateToContacttemplate'; $chkPreTab = 'contact'; } /* Get data */ if ($chkLinkTab !== '') { /** @noinspection SqlResolve */ $strSQL = 'SELECT * FROM `' . $chkLinkTab . "` WHERE `idMaster` = $chkDataId ORDER BY `idSort`"; $booReturn = $myDBClass->hasDataArray($strSQL, $arrDataLines, $intDataCount); /* Store data to session */ if ($chkMode === null) { $_SESSION['templatedefinition'] = array(); $arrTemp = array(); if ($booReturn && ($intDataCount !== 0)) { foreach ($arrDataLines as $elem) { if ((int)$elem['idTable'] === 1) { $strSQL2 = 'SELECT `template_name` ' . 'FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $elem['idSlave']; /** @noinspection SqlResolve */ $strSQL3 = 'SELECT `active` FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $elem['idSlave']; /** @noinspection SqlResolve */ $strSQL4 = 'SELECT `config_id` FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $elem['idSlave']; } else { /** @noinspection SqlResolve */ $strSQL2 = 'SELECT `name` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $elem['idSlave']; /** @noinspection SqlResolve */ $strSQL3 = 'SELECT `active` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $elem['idSlave']; /** @noinspection SqlResolve */ $strSQL4 = 'SELECT `config_id` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $elem['idSlave']; } $arrTemp['idSlave'] = $elem['idSlave']; $arrTemp['definition'] = addslashes($myDBClass->getFieldData($strSQL2)); $arrTemp['idTable'] = $elem['idTable']; $arrTemp['idSort'] = $elem['idSort']; $arrTemp['active'] = (int)$myDBClass->getFieldData($strSQL3); $arrTemp['config_id'] = (int)$myDBClass->getFieldData($strSQL4); $arrTemp['status'] = 0; $_SESSION['templatedefinition'][] = $arrTemp; } } } } /* Add mode */ if ($chkMode === 'add') { $arrTemp = array(); if ((int)$arrDefinition[1] === 1) { /** @noinspection SqlResolve */ $strSQL2 = 'SELECT `template_name` FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $arrDefinition[0]; /** @noinspection SqlResolve */ $strSQL3 = 'SELECT `active` FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $arrDefinition[0]; /** @noinspection SqlResolve */ $strSQL4 = 'SELECT `config_id` FROM `tbl_' . $chkPreTab . 'template` WHERE `id` = ' . $arrDefinition[0]; } else { /** @noinspection SqlResolve */ $strSQL2 = 'SELECT `name` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $arrDefinition[0]; /** @noinspection SqlResolve */ $strSQL3 = 'SELECT `active` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $arrDefinition[0]; /** @noinspection SqlResolve */ $strSQL4 = 'SELECT `config_id` FROM `tbl_' . $chkPreTab . '` WHERE `id` = ' . $arrDefinition[0]; } if (isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition'])) { $intCheck = 0; foreach ($_SESSION['templatedefinition'] as $key => $elem) { if ((int)($elem['idSlave'] === $arrDefinition[0]) && ((int)$elem['idTable'] === (int)$arrDefinition[1]) && ((int)$elem['status'] === 0)) { $intCheck = 1; } } if ($intCheck === 0) { $arrTemp['idSlave'] = $arrDefinition[0]; $arrTemp['definition'] = addslashes($myDBClass->getFieldData($strSQL2)); $arrTemp['idTable'] = $arrDefinition[1]; $arrTemp['idSort'] = 0; $arrTemp['status'] = 0; $arrTemp['active'] = (int)$myDBClass->getFieldData($strSQL3); $arrTemp['config_id'] = (int)$myDBClass->getFieldData($strSQL4); $_SESSION['templatedefinition'][] = $arrTemp; } } else { $arrTemp['idSlave'] = $arrDefinition[0]; $arrTemp['definition'] = addslashes($myDBClass->getFieldData($strSQL2)); $arrTemp['idTable'] = $arrDefinition[1]; $arrTemp['idSort'] = 0; $arrTemp['status'] = 0; $arrTemp['active'] = (int)$myDBClass->getFieldData($strSQL3); $arrTemp['config_id'] = (int)$myDBClass->getFieldData($strSQL4); $_SESSION['templatedefinition'][] = $arrTemp; } } /* Deletion mode */ if ($chkMode === 'del' && isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition'])) { foreach ($_SESSION['templatedefinition'] as $key => $elem) { if (((int)$elem['idSlave'] === (int)$arrDefinition[0]) && ((int)$elem['idTable'] === (int)$arrDefinition[1]) && ((int)$elem['status'] === 0)) { $_SESSION['templatedefinition'][$key]['status'] = 1; } } } /* Sort mode */ if ($chkMode === 'sortup') { $chkKey = (int)$chkKey; if (isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition']) && (count($_SESSION['templatedefinition']) > 1) && ($chkKey !== 0)) { $arrTemp = array(); $arrWait = array(); $intNow = 0; foreach ($_SESSION['templatedefinition'] as $key => $elem) { if ($key !== ($chkKey - 1)) { $arrTemp[] = $elem; if ($intNow === 1) { $intNow = 0; $arrTemp[] = $arrWait; } } else { $arrWait = $elem; $intNow = 1; } } $_SESSION['templatedefinition'] = $arrTemp; } } if ($chkMode === 'sortdown') { $chkKey = (int)$chkKey; if (isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition']) && (count($_SESSION['templatedefinition']) > 1) && ($chkKey < (count($_SESSION['templatedefinition']) - 1))) { $arrTemp = array(); $arrWait = array(); $intNow = 0; foreach ($_SESSION['templatedefinition'] as $key => $elem) { if ($key !== $chkKey) { $arrTemp[] = $elem; if ($intNow === 1) { $intNow = 0; $arrTemp[] = $arrWait; } } else { $arrWait = $elem; $intNow = 1; } } $_SESSION['templatedefinition'] = $arrTemp; } } /* Clean up data structure */ if (isset($_SESSION['templatedefinition']) && is_array($_SESSION['templatedefinition'])) { $arrTemp = array(); foreach ($_SESSION['templatedefinition'] as $key => $elem) { if ((int)$elem['status'] === 0) { $arrTemp[] = $elem; } } $_SESSION['templatedefinition'] = $arrTemp; } ?>
![]() ![]() ![]() |
|