*
 * @package    IcingaEditor
 * @subpackage WebUI
 * @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();
        }
         if ($address) {
             $hostName = gethostbyaddr($address);
         } else {
             if ($addressSix) {
                 $hostName = gethostbyaddr6($addressSix);
             }
         }
     }
 }
 if (!$addressSix) {
     $addressSix = gethostbyname6($hostName);
 }
 $oUser->addStatusMessage('HostName: ' . $hostName);
 $oUser->addStatusMessage('Address: ' . $address);
 $oUser->addStatusMessage('Address6: ' . $addressSix);
 $host->setData(array($host->userColumn => $oUser->getUserID(), 'host_name' => $hostName, 'address' => $address, 'address6' => $addressSix, 'use' => 'generic-host', 'platform' => $platform, 'register' => true, 'generate' => TRUE, 'alias' => $hostName, 'active_checks_enabled' => 1, 'passive_checks_enabled' => 0));
 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()) {
     $service = new IEService('PING');
     $service->addMember('host_name', $host->getId(), $host->getName());
     $service->saveToMySQL();
     $host->autoPopulateServices();
     $hostGroup = new IEHostgroup();
     if ($hostGroup->loadDefault()) {
         $hostGroup->setDataValue($hostGroup->nameColumn, EaseShared::user()->getUserLogin());
         $hostGroup->addMember('members', $host->getId(), $host->getName());