/**
  * 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');
                     }
                 }
             }
         }
     }
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 case 'applystemplate':
     $stemplate = new IEStemplate($oPage->getRequestValue('stemplate_id', 'int'));
     $services = $stemplate->getDataValue('services');
     if (count($services)) {
         $service = new IEService();
         foreach ($services as $service_id => $service_name) {
             $service->loadFromMySQL($service_id);
             $service->addMember('host_name', $host->getId(), $host->getName());
             $service->saveToMySQL();
             $service->dataReset();
         }
     }
     $contacts = $stemplate->getDataValue('contacts');
     if (count($contacts)) {
         foreach ($contacts as $contact_id => $contact_name) {
             $host->addMember('contacts', $contact_id, $contact_name);
         }
         $host->saveToMySQL();
     }
     break;
 case 'populate':
     $host->autoPopulateServices();
     break;
 case 'icon':
     $icourl = $oPage->getRequestValue('icourl');
     if (strlen($icourl)) {
         $tmpfilename = sys_get_temp_dir() . '/' . EaseSand::randomString();
         $fp = fopen($tmpfilename, 'w');
         $ch = curl_init($icourl);
         curl_setopt($ch, CURLOPT_FILE, $fp);
         $data = curl_exec($ch);
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
require_once 'classes/IEPassiveCheckedHostForm.php';
$oPage->onlyForLogged();
$hostName = trim($oPage->getRequestValue('host_name'));
$platform = trim($oPage->getRequestValue('platform'));
$host_group = $oPage->getRequestValue('host_group', 'int');
$host = new IEHost();
$host->owner =& $oUser;
if ($hostName && $platform) {
    $host->setData(array($host->userColumn => $oUser->getUserID(), 'host_name' => $hostName, 'use' => 'generic-host', 'platform' => 'generic', 'register' => true, 'generate' => TRUE, 'platform' => $platform, 'alias' => $hostName, 'active_checks_enabled' => 0, 'passive_checks_enabled' => 1, 'check_freshness' => 1, 'freshness_threshold' => 900, 'flap_detection_enabled' => 0, 'check_command' => 'return-unknown'));
    if ($host_group) {
        $hostgroup = new IEHostgroup($host_group);
        $host->addMember('hostgroups', $hostgroup->getId(), $hostgroup->getName());
        $hostgroup->addMember('members', $host->getId(), $host->getName());
        $hostgroup->saveToMySQL();
    }
    if ($host->saveToMysql()) {
        $hostGroup = new IEHostgroup();
        if ($hostGroup->loadDefault()) {
            $hostGroup->setDataValue($hostGroup->nameColumn, EaseShared::user()->getUserLogin());
            $hostGroup->addMember('members', $host->getId(), $host->getName());
            $hostGroup->saveToMySQL();
            $host->addMember('hostgroups', $hostGroup->getId(), $hostGroup->getName());
            $host->saveToMysql();
        }
        $oPage->redirect('host.php?host_id=' . $host->getId());
        exit;
    }
Example #5
0
 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();
             }
         }
     }
 }
Example #6
0
 * @subpackage WebUI
 * @author     Vitex <*****@*****.**>
 * @copyright  2012 Vitex@hippy.cz (G)
 */
require_once 'includes/IEInit.php';
$oPage->onlyForLogged();
$hostgroup = new IEHostgroup($oPage->getRequestValue('hostgroup_id', 'int'));
switch ($oPage->getRequestValue('action')) {
    case 'contactAsign':
        $contact = new IEContact($oPage->getRequestValue('contact_id', 'int'));
        if ($contact->getId()) {
            $host = new IEHost();
            $groupMembers = $hostgroup->getMembers();
            foreach ($groupMembers as $gmID => $hostName) {
                $host->loadFromSQL((int) $gmID);
                $host->addMember('contacts', $contact->getId(), $contact->getName());
                if ($host->saveToMySQL()) {
                    $host->addStatusMessage(sprintf(_('<strong>%s</strong> byl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'success');
                } else {
                    $host->addStatusMessage(sprintf(_('<strong>%s</strong> nebyl přidán mezi kontakty <strong>%s</strong>'), $contact->getName(), $host->getName()), 'warning');
                }
            }
        } else {
            $hostgroup->addStatusMessage(_('Chyba přiřazení kontaktu'), 'warning');
        }
        break;
    default:
        if ($oPage->isPosted()) {
            $hostgroup->takeData($_POST);
            if (!$hostgroup->getId()) {
                $hostgroup->setDataValue('members', array());