/** * Smaže kontakt i jeho subkontakty * * @return boolean */ public function delete($id = null) { if (is_null($id)) { $id = $this->getId(); } else { if ($id != $this->getId()) { $this->loadFromMySQL($id); } } $childs = $this->getChilds(); if ($childs) { $parent = $id; foreach ($childs as $child_id => $child) { $this->delete($child_id); } $this->loadFromMySQL($parent); $id = $parent; } $contactgroup = new IEContactgroup(); $contactgroups = $this->myDbLink->queryTo2DArray('SELECT ' . $contactgroup->getmyKeyColumn() . ' FROM ' . $contactgroup->myTable . ' WHERE members LIKE \'%' . $this->getName() . '%\''); if (count($contactgroups)) { foreach ($contactgroups as $contactgroupID) { $contactgroup->loadFromMySQL((int) $contactgroupID); if ($contactgroup->delMember('members', null, $this->getName())) { if ($contactgroup->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán ze skupiny <strong>%s</strong>'), $this->getName(), $contactgroup->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán ze skupiny <strong>%s</strong>'), $this->getName(), $contactgroup->getName()), 'warning'); } } } $service = new IEService(); $services = $this->myDbLink->queryTo2DArray('SELECT ' . $service->getmyKeyColumn() . ' FROM ' . $service->myTable . ' WHERE contacts LIKE \'%' . $this->getName() . '%\''); if (count($services)) { foreach ($services as $serviceID) { $service->loadFromMySQL((int) $serviceID); if ($service->delMember('contacts', $id)) { if ($service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán ze služby <strong>%s</strong>'), $this->getName(), $service->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán ze služby <strong>%s</strong>'), $this->getName(), $service->getName()), 'warning'); } } } $host = new IEHost(); $hosts = $this->myDbLink->queryTo2DArray('SELECT ' . $host->getmyKeyColumn() . ' FROM ' . $host->myTable . ' WHERE contacts LIKE \'%' . $this->getName() . '%\''); if (count($hosts)) { foreach ($hosts as $hostID) { $host->loadFromMySQL((int) $hostID); if ($host->delMember('contacts', $id)) { if ($host->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> byl odebrán z hosta <strong>%s</strong>'), $this->getName(), $host->getName()), 'success'); } } else { $this->addStatusMessage(sprintf(_('Kontakt <strong>%s</strong> nebyl odebrán z hosta <strong>%s</strong>'), $this->getName(), $host->getName()), 'warning'); } } } $this->myDbLink->exeQuery('DELETE FROM `' . $this->myTable . '` WHERE `parent_id`=' . $id); return parent::delete($id); }
/** * Přejmenuje hosta a závistlosti * @param type $newname */ public function rename($newname) { $oldname = $this->getName(); $this->setDataValue($this->nameColumn, $newname); $hostGroup = new IEHostgroup(); $hostGroup->renameHost($oldname, $newname); $renameAll = true; $service = new IEService(); $servicesAssigned = $service->myDbLink->queryToArray('SELECT ' . $service->myKeyColumn . ',' . $service->nameColumn . ' FROM ' . $service->myTable . ' WHERE ' . 'host_name' . ' LIKE \'%"' . $oldname . '"%\'', $service->myKeyColumn); foreach ($servicesAssigned as $serviceID => $serviceInfo) { $service->loadFromMySQL($serviceID); $service->renameHostName($this->getId(), $newname); if (!$service->saveToMySQL()) { $this->addStatusMessage(sprintf(_('Nepodařilo se přejmenovat %s ve službě %s'), $this->getName(), $service->getName()), $Type); $renameAll = false; } } $childsAssigned = $this->myDbLink->queryToArray('SELECT ' . $this->myKeyColumn . ',' . $this->nameColumn . ' FROM ' . $this->myTable . ' WHERE ' . 'parents' . ' LIKE \'%"' . $oldname . '"%\'', $this->myKeyColumn); foreach ($childsAssigned as $chid_id => $child_info) { $child = new IEHost($chid_id); $child->delMember('parents', $this->getId(), $oldname); $child->addMember('parents', $this->getId(), $newname); $child->updateToMySQL(); } if ($this->save() && $renameAll) { return true; } 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(); } } } }
/** * 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); }
/** * Uloží položky * * @param array $request */ public static function saveMembers($request) { $host = new IEHost(); if (isset($request[$host->myKeyColumn])) { if ($host->loadFromMySQL($request[$host->myKeyColumn])) { if (isset($request['addhost']) || isset($request['delhost'])) { if (isset($request['addhost'])) { $host->addMember('service_name', $request['service_id'], $request['service_name']); if ($host->saveToMySQL()) { $host->addStatusMessage(sprintf(_('položka %s byla přidána'), $request['addhost']), 'success'); } else { $host->addStatusMessage(sprintf(_('položka %s nebyla přidána'), $request['addhost']), 'warning'); } } if (isset($request['delhost'])) { $host->delMember('service_name', $request['service_id'], $request['service_name']); if ($host->saveToMySQL()) { $host->addStatusMessage(sprintf(_('položka %s byla odebrána'), $request['delhost']), 'success'); } else { $host->addStatusMessage(sprintf(_('položka %s nebyla odebrána'), $request['delhost']), 'warning'); } } } } } }