/** * Smaže hostgrupu i její použití v hostech * * @param int $id * @return boolean */ function delete($id = null) { if (isset($id) && $this->getId() != $id) { $this->loadFromSQL($id); } else { $id = $this->getId(); } $host = new IEHost(); $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn), array('hostgroups' => '%' . $this->getName() . '%')); foreach ($hosts as $hostInfo) { $hostId = intval(current($hostInfo)); $host->loadFromMySQL($hostId); $hostgroupNames = $host->getDataValue('hostgroups'); if ($hostgroupNames) { foreach ($hostgroupNames as $hostgroupId => $hostgroupName) { if ($hostgroupId == $this->getId()) { if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName)) { $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'success'); } else { $this->addStatusMessage(sprintf(_('host %s byl odstraněn ze skupiny %s'), $host->getName(), $hostgroupName), 'error'); } } } } } $subgroup = new IEHostgroup(); $subgroups = $subgroup->getColumnsFromMySQL(array($subgroup->myKeyColumn), array('hostgroup_members' => '%' . $this->getName() . '%')); foreach ($subgroups as $subgroupInfo) { $subgroupId = intval(current($subgroupInfo)); $subgroup->loadFromMySQL($subgroupId); $subgroupgroupNames = $subgroup->getDataValue('hostgroup_members'); if ($subgroupgroupNames) { foreach ($subgroupgroupNames as $subgroupgroupId => $subgroupgroupName) { if ($subgroupgroupId == $this->getId()) { if ($subgroup->delMember('hostgroup_members', $subgroupgroupId, $subgroupgroupName)) { $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'success'); } else { $this->addStatusMessage(sprintf(_('subgroup %s byl odstraněn ze skupiny %s'), $subgroup->getName(), $subgroupgroupName), 'error'); } } } } } return parent::delete($id); }
public function delete($id = null) { if (is_null($id)) { $id = $this->getId(); } if ($id != $this->getId()) { $this->loadFromMySQL($id); } $userGroup = new IEUserGroup(); $userGroup->delUser($id); $command = new IECommand(); $myCommand = $command->getOwned($id); if ($myCommand) { foreach ($myCommand as $command_id => $cmd) { $command->loadFromMySQL((int) $command_id); $command->delete(); } } $contact = new IEContact(); $myContact = $contact->getOwned($id); if ($myContact) { foreach ($myContact as $contact_id => $cmd) { if ($contact->loadFromMySQL((int) $contact_id)) { $contact->delete(); } } } $contactgroup = new IEContactgroup(); $myContactgroup = $contactgroup->getOwned($id); if ($myContactgroup) { foreach ($myContactgroup as $contactgroup_id => $cmd) { $contactgroup->loadFromMySQL((int) $contactgroup_id); $contactgroup->delete(); } } $hostgroup = new IEHostgroup(); $myHostgroup = $hostgroup->getOwned($id); if ($myHostgroup) { foreach ($myHostgroup as $hostgroup_id => $cmd) { $hostgroup->loadFromMySQL((int) $hostgroup_id); $hostgroup->delete(); } } $host = new IEHost(); $myHost = $host->getOwned($id); if ($myHost) { foreach ($myHost as $host_id => $cmd) { $host->loadFromMySQL((int) $host_id); $host->delete(); } } $servicegroup = new IEServicegroup(); $myServicegroup = $servicegroup->getOwned($id); if ($myServicegroup) { foreach ($myServicegroup as $servicegroup_id => $cmd) { $servicegroup->loadFromMySQL((int) $servicegroup_id); $servicegroup->delete(); } } $service = new IEService(); $myService = $service->getOwned($id); if ($myService) { foreach ($myService as $service_id => $cmd) { $service->loadFromMySQL((int) $service_id); $service->delete(); } } $timeperiod = new IETimeperiod(); $myTimeperiod = $timeperiod->getOwned($id); if ($myTimeperiod) { foreach ($myTimeperiod as $timeperiod_id => $cmd) { $timeperiod->loadFromMySQL((int) $timeperiod_id); $timeperiod->delete(); } } $cfgfile = constant('CFG_GENERATED') . '/' . $this->getUserLogin() . '.cfg'; if (file_exists($cfgfile)) { if (unlink($cfgfile)) { $this->addStatusMessage(sprintf(_('Konfigurace uživatele %s byla smazána'), $this->getUserLogin()), 'success'); } else { $this->addStatusMessage(sprintf(_('Konfigurace uživatele %s nebyla smazána'), $this->getUserLogin()), 'error'); } } if ($this->deleteFromMySQL()) { $this->addStatusMessage(sprintf(_('Uživatel %s byl smazán'), $this->getUserLogin())); require_once 'Ease/EaseMail.php'; $email = new EaseMail($this->getDataValue('email'), _('Oznámení o zrušení účtu')); $email->setMailHeaders(array('From' => EMAIL_FROM)); $email->addItem(new EaseHtmlDivTag(null, "Právě jste byl/a smazán/a z Aplikace VSMonitoring s těmito přihlašovacími údaji:\n")); $email->addItem(new EaseHtmlDivTag(null, ' Login: ' . $this->GetUserLogin() . "\n")); $email->send(); return true; } else { return FALSE; } }
function fixHostHostgroupID() { $hostgroupsOK = array(); $hostgroupsErr = array(); $host = new IEHost(); $hostgroup = new IEHostgroup(); $hosts = $host->getColumnsFromMySQL(array($host->myKeyColumn)); foreach ($hosts as $hostInfo) { $hostId = intval(current($hostInfo)); $host->loadFromMySQL($hostId); $hostgroupNames = $host->getDataValue('hostgroups'); if ($hostgroupNames) { foreach ($hostgroupNames as $hostgroupId => $hostgroupName) { $hostgroupFound = $hostgroup->loadFromMySQL($hostgroupName); if ($hostgroupId != $hostgroup->getId()) { if ($host->delMember('hostgroups', $hostgroupId, $hostgroupName) && $host->addMember('hostgroups', $hostgroup->getId(), $hostgroupName)) { $hostgroupsOK[] = $hostgroupName; } else { $hostgroupsErr[] = $hostgroupName; } } } } if (count($hostgroupsOK)) { if ($host->saveToMySQL()) { $this->addItemSmart(sprintf(_('<strong>%s</strong> : %s'), $host->getName(), implode(',', $hostgroupsOK)), array('class' => 'list-group-item')); $this->addStatusMessage(sprintf(_('%s : %s'), $host->getName(), implode(',', $hostgroupsOK)), 'success'); $hostgroupsOK = array(); } } } }