From 641bf1468a369dc3265fb0cecf983b9d88f6f1cb Mon Sep 17 00:00:00 2001
From: Guillaume28 <Guillaume28@users.noreply.github.com>
Date: Mon, 5 Mar 2018 14:13:27 +0100
Subject: [PATCH] First 100 commits and refacto of DB-Func.php (#6104)

* doc(release note) : Add empty release note for the 2.8.19

* Security Fix : SQL injections on Ldap Parameters page

* update Centreon web 2.8.6 release notes

* improve documentations

* fix(style):Using if instead of ternary

* fix(doc): Remove header

* fix(error): Missing }

* fix(query): Wrong utilisation of query

* fix(space):Missing space
---
 .../centreon-2.8/centreon-2.8.1.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.2.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.3.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.4.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.5.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.6.rst           |   35 +-
 .../centreon-2.8/centreon-2.8.7.rst           |    6 +-
 doc/en/release_notes/centreon-2.8/index.rst   |    2 +
 .../centreon-2.8/centreon-2.8.1.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.2.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.3.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.4.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.5.rst           |    6 +-
 .../centreon-2.8/centreon-2.8.6.rst           |   35 +-
 .../centreon-2.8/centreon-2.8.7.rst           |    6 +-
 doc/fr/release_notes/centreon-2.8/index.rst   |    2 +
 www/class/centreonLDAP.class.php              |  114 +-
 .../Administration/parameters/ldap/form.php   |    2 +-
 .../configuration/configNagios/DB-Func.php    | 2533 +++++++++++------
 19 files changed, 1896 insertions(+), 899 deletions(-)

diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.1.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.1.rst
index f2d1fac9cb..678b8c626a 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.1.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.1.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.1
-##############
+##################
+Centreon Web 2.8.1
+##################
 
 Released November 14th, 2016
 
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.2.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.2.rst
index 6c1a885bc8..26b068cbdf 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.2.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.2.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.2
-##############
+##################
+Centreon Web 2.8.2
+##################
 
 Released December 8th, 2016.
 
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.3.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.3.rst
index 05cedb4e8c..78248e2430 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.3.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.3.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.3
-##############
+##################
+Centreon Web 2.8.3
+##################
 
 Released January 11th, 2017.
 
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.4.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.4.rst
index 2562c2dd7a..fa547c51e2 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.4.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.4.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.4
-##############
+##################
+Centreon Web 2.8.4
+##################
 
 Released February 8th, 2017.
 
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.5.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.5.rst
index 765be83393..c949287867 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.5.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.5.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.5
-##############
+##################
+Centreon Web 2.8.5
+##################
 
 Released March 29th, 2017.
 
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.6.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.6.rst
index 5148a03e01..647be20148 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.6.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.6.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.6
-##############
+##################
+Centreon Web 2.8.6
+##################
 
 Bug Fixes
 =========
@@ -8,7 +8,34 @@ Bug Fixes
 KB
 --
 
-* Fix wiki links of objects with spaces in their name
+* Downtimes - Display real BA name instead of _Module_ - #5014, PR #5094
+* InfluxDB broker output config: metric columns not stored properly - #5058, PR #5089
+* Poller status still working when the poller is disabled - #5126
+* Filter on the status host/service on the motiroring isn't working #5131, #5140
+* Fix acl on host categories for inheritance
+* Avoid infinite loop in acl category
+* Fix error message in install process
+* Fix path to centengine and cbd init scripts
+* Fix topcounter must count all meta services - #5071, PR #5100
+* Fix access downtime page for users with ACL - #4952, #5025, PR #5093
+* Centreon > Services - Services listed twice - #5158, PR #5010
+* Custom views - problem with multiselect users when sharing View - #5029, PR #5074
+* Massive change  - impossible to add servive group - #5132
+* Fix URL decode probelm with character '+' in object's name - #5128, PR #4883
+* Fix CLAPI import
+* Poller status still working when the poller is disabled - #5126, PR #5133
+
+Enhancements
+============
+
+* Display inherited categories in host details page
+* Do not check modification of configuration on disabled poller for better performance - PR #4928
+* Improve access to services configuration page - PR #5077, PR #5076
+* Improve global performance - PR #4900
+* Improve Knowledge Base configuration
+* Fix wiki links of objects with spaces in their name - #4306
+* Improve documentation
+* Set geo_coords parameter with clapi
 
 If you already used a knowledge base, please execute following script :
 ::
diff --git a/doc/en/release_notes/centreon-2.8/centreon-2.8.7.rst b/doc/en/release_notes/centreon-2.8/centreon-2.8.7.rst
index a3e6b99bcc..d9e124d965 100644
--- a/doc/en/release_notes/centreon-2.8/centreon-2.8.7.rst
+++ b/doc/en/release_notes/centreon-2.8/centreon-2.8.7.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.7
-##############
+##################
+Centreon Web 2.8.7
+##################
 
 Bug Fixes
 =========
diff --git a/doc/en/release_notes/centreon-2.8/index.rst b/doc/en/release_notes/centreon-2.8/index.rst
index 5f550d2109..3c75036eda 100644
--- a/doc/en/release_notes/centreon-2.8/index.rst
+++ b/doc/en/release_notes/centreon-2.8/index.rst
@@ -24,3 +24,5 @@ Please find here the release notes dedicated to the last 2.8.x version of Centre
     centreon-2.8.15
     centreon-2.8.16
     centreon-2.8.17
+    centreon-2.8.18
+    centreon-2.8.19
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.1.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.1.rst
index 15c0aa752e..9eb257ce5f 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.1.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.1.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.1
-##############
+##################
+Centreon Web 2.8.1
+##################
 
 Released November 14th, 2016
 
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.2.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.2.rst
index 6c1a885bc8..26b068cbdf 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.2.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.2.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.2
-##############
+##################
+Centreon Web 2.8.2
+##################
 
 Released December 8th, 2016.
 
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.3.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.3.rst
index 05cedb4e8c..78248e2430 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.3.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.3.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.3
-##############
+##################
+Centreon Web 2.8.3
+##################
 
 Released January 11th, 2017.
 
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.4.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.4.rst
index 2562c2dd7a..fa547c51e2 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.4.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.4.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.4
-##############
+##################
+Centreon Web 2.8.4
+##################
 
 Released February 8th, 2017.
 
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.5.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.5.rst
index 765be83393..c949287867 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.5.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.5.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.5
-##############
+##################
+Centreon Web 2.8.5
+##################
 
 Released March 29th, 2017.
 
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.6.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.6.rst
index 5148a03e01..647be20148 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.6.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.6.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.6
-##############
+##################
+Centreon Web 2.8.6
+##################
 
 Bug Fixes
 =========
@@ -8,7 +8,34 @@ Bug Fixes
 KB
 --
 
-* Fix wiki links of objects with spaces in their name
+* Downtimes - Display real BA name instead of _Module_ - #5014, PR #5094
+* InfluxDB broker output config: metric columns not stored properly - #5058, PR #5089
+* Poller status still working when the poller is disabled - #5126
+* Filter on the status host/service on the motiroring isn't working #5131, #5140
+* Fix acl on host categories for inheritance
+* Avoid infinite loop in acl category
+* Fix error message in install process
+* Fix path to centengine and cbd init scripts
+* Fix topcounter must count all meta services - #5071, PR #5100
+* Fix access downtime page for users with ACL - #4952, #5025, PR #5093
+* Centreon > Services - Services listed twice - #5158, PR #5010
+* Custom views - problem with multiselect users when sharing View - #5029, PR #5074
+* Massive change  - impossible to add servive group - #5132
+* Fix URL decode probelm with character '+' in object's name - #5128, PR #4883
+* Fix CLAPI import
+* Poller status still working when the poller is disabled - #5126, PR #5133
+
+Enhancements
+============
+
+* Display inherited categories in host details page
+* Do not check modification of configuration on disabled poller for better performance - PR #4928
+* Improve access to services configuration page - PR #5077, PR #5076
+* Improve global performance - PR #4900
+* Improve Knowledge Base configuration
+* Fix wiki links of objects with spaces in their name - #4306
+* Improve documentation
+* Set geo_coords parameter with clapi
 
 If you already used a knowledge base, please execute following script :
 ::
diff --git a/doc/fr/release_notes/centreon-2.8/centreon-2.8.7.rst b/doc/fr/release_notes/centreon-2.8/centreon-2.8.7.rst
index a3e6b99bcc..d9e124d965 100644
--- a/doc/fr/release_notes/centreon-2.8/centreon-2.8.7.rst
+++ b/doc/fr/release_notes/centreon-2.8/centreon-2.8.7.rst
@@ -1,6 +1,6 @@
-##############
-Centreon 2.8.7
-##############
+##################
+Centreon Web 2.8.7
+##################
 
 Bug Fixes
 =========
diff --git a/doc/fr/release_notes/centreon-2.8/index.rst b/doc/fr/release_notes/centreon-2.8/index.rst
index 5f550d2109..3c75036eda 100644
--- a/doc/fr/release_notes/centreon-2.8/index.rst
+++ b/doc/fr/release_notes/centreon-2.8/index.rst
@@ -24,3 +24,5 @@ Please find here the release notes dedicated to the last 2.8.x version of Centre
     centreon-2.8.15
     centreon-2.8.16
     centreon-2.8.17
+    centreon-2.8.18
+    centreon-2.8.19
diff --git a/www/class/centreonLDAP.class.php b/www/class/centreonLDAP.class.php
index 76c923da95..b2f6d1eac2 100644
--- a/www/class/centreonLDAP.class.php
+++ b/www/class/centreonLDAP.class.php
@@ -92,7 +92,10 @@ class CentreonLDAP
         }
 
         $dbresult = $this->db->query(
-            "SELECT `key`, `value` FROM `options` WHERE `key` IN ('debug_ldap_import', 'debug_path')"
+            "SELECT `key`, `value` 
+            FROM `options` 
+            WHERE `key` 
+            IN ('debug_ldap_import', 'debug_path')"
         );
         while ($row = $dbresult->fetchRow()) {
             if ($row['key'] == 'debug_ldap_import') {
@@ -123,9 +126,9 @@ class CentreonLDAP
             $dns_query = '_ldap._tcp';
             $dbresult = $this->db->query(
                 "SELECT `ari_value` 
-                                           FROM auth_ressource_info 
-                                           WHERE `ari_name` = 'ldap_dns_use_domain' 
-                                           AND ar_id = " . $this->db->escape($arId)
+                FROM auth_ressource_info 
+                WHERE `ari_name` = 'ldap_dns_use_domain' 
+                AND ar_id = " . $this->db->escape($arId)
             );
             $row = $dbresult->fetchRow();
             $dbresult->closeCursor();
@@ -146,9 +149,9 @@ class CentreonLDAP
         } else {
             $dbresult = $this->db->query(
                 "SELECT ldap_host_id, host_address
-                                           FROM auth_ressource_host
-                                           WHERE auth_ressource_id = " . $this->db->escape($arId) . "
-                                           ORDER BY host_order"
+                FROM auth_ressource_host
+                WHERE auth_ressource_id = " . $this->db->escape($arId) . "
+                ORDER BY host_order"
             );
             while ($row = $dbresult->fetchRow()) {
                 $ldap = array();
@@ -698,8 +701,8 @@ class CentreonLDAP
     {
         $dbresult = $this->db->query(
             "SELECT use_ssl, use_tls, host_port as port
-                                       FROM auth_ressource_host
-                                       WHERE ldap_host_id = " . CentreonDB::escape($id)
+            FROM auth_ressource_host
+            WHERE ldap_host_id = " . CentreonDB::escape($id)
         );
         $row = $dbresult->fetchRow();
         return $row;
@@ -737,9 +740,9 @@ class CentreonLDAP
             return $this->constuctCache[$id];
         }
         $query = "SELECT ari_name, ari_value 
-                  FROM auth_ressource_info 
-                  WHERE ari_name IN ('bind_dn', 'bind_pass', 'protocol_version') 
-                  AND ar_id = " . CentreonDB::escape($id);
+                 FROM auth_ressource_info 
+                 WHERE ari_name IN ('bind_dn', 'bind_pass', 'protocol_version') 
+                 AND ar_id = " . CentreonDB::escape($id);
         $dbresult = $this->db->query($query);
         $infos = array();
         while ($row = $dbresult->fetchRow()) {
@@ -883,25 +886,25 @@ class CentreonLdapAdmin
         if (!count($gopt) && isset($options['ar_name']) && isset($options['ar_description'])) {
             $this->db->query(
                 "INSERT INTO auth_ressource (ar_name, ar_description, ar_type, ar_enable) 
-                                   VALUES ('" . $this->db->escape($options['ar_name']) . "', 
-                                           '" . $this->db->escape($options['ar_description']) . "', 
-                                           'ldap', 
-                                           '" . $options['ldap_auth_enable']['ldap_auth_enable'] . "')"
+                VALUES ('" . $this->db->escape($options['ar_name']) . "', 
+                        '" . $this->db->escape($options['ar_description']) . "', 
+                        'ldap', 
+                        '" . $options['ldap_auth_enable']['ldap_auth_enable'] . "')"
             );
             $maxArIdSql = "SELECT MAX(ar_id) as last_id
-                FROM auth_ressource
-                WHERE ar_name = '" . $this->db->escape($options['ar_name']) . "'";
+                          FROM auth_ressource
+                          WHERE ar_name = '" . $this->db->escape($options['ar_name']) . "'";
             $res = $this->db->query($maxArIdSql);
             $row = $res->fetchRow();
             $arId = $row['last_id'];
             unset($res);
         } else {
             $this->db->query(
-                "UPDATE auth_ressource SET 
-                                   ar_name = '" . $this->db->escape($options['ar_name']) . "', 
-                                   ar_description = '" . $this->db->escape($options['ar_description']) . "', 
-                                   ar_enable = '" . $options['ldap_auth_enable']['ldap_auth_enable'] . "'
-                                   WHERE ar_id = " . $this->db->escape($arId)
+                "UPDATE auth_ressource 
+                SET ar_name = '" . $this->db->escape($options['ar_name']) . "', 
+                ar_description = '" . $this->db->escape($options['ar_description']) . "', 
+                ar_enable = '" . $options['ldap_auth_enable']['ldap_auth_enable'] . "'
+                WHERE ar_id = " . $this->db->escape($arId)
             );
         }
 
@@ -915,14 +918,14 @@ class CentreonLdapAdmin
             }
             if (isset($gopt[$key])) {
                 $query = "UPDATE `auth_ressource_info` 
-                              SET `ari_value` = '" . $this->db->escape($value, false) . "' 
-                              WHERE `ari_name` = '" . $this->db->escape($key) . "' 
-                              AND ar_id = " . $this->db->escape($arId);
+                         SET `ari_value` = '" . $this->db->escape($value, false) . "' 
+                         WHERE `ari_name` = '" . $this->db->escape($key) . "' 
+                         AND ar_id = " . $this->db->escape($arId);
             } else {
                 $query = "INSERT INTO `auth_ressource_info`
-                    (`ar_id`, `ari_name`, `ari_value`) 
-                    VALUES (" . $this->db->escape($arId) . ", '" . $this->db->escape($key) . "', '" .
-                    $this->db->escape($value, false) . "')";
+                         (`ar_id`, `ari_name`, `ari_value`) 
+                         VALUES (" . $this->db->escape($arId) . ", '" . $this->db->escape($key) . "', '" .
+                         $this->db->escape($value, false) . "')";
             }
             $this->db->query($query);
         }
@@ -940,8 +943,8 @@ class CentreonLdapAdmin
     {
         $gopt = array();
         $query = "SELECT `ari_name`, `ari_value` 
-                      FROM `auth_ressource_info`
-                      WHERE ar_id = " . $this->db->escape($arId);
+                 FROM `auth_ressource_info`
+                 WHERE ar_id = " . $this->db->escape($arId);
         $res = $this->db->query($query);
         while ($row = $res->fetchRow()) {
             $gopt[$row['ari_name']] = $row['ari_value'];
@@ -961,12 +964,12 @@ class CentreonLdapAdmin
         $use_ssl = isset($params['use_ssl']) ? 1 : 0;
         $use_tls = isset($params['use_tls']) ? 1 : 0;
         $sql = "INSERT INTO auth_ressource_host " .
-            "(auth_ressource_id, host_address, host_port, use_ssl, use_tls, host_order) " .
-            "VALUES ($arId, '" . $this->db->escape($params['hostname']) . "', '" .
-            $this->db->escape($params['port']) . "', " .
-            $use_ssl . ", " .
-            $use_tls . ", '" .
-            $this->db->escape($params['order']) . "')";
+               "(auth_ressource_id, host_address, host_port, use_ssl, use_tls, host_order) " .
+               "VALUES ($arId, '" . $this->db->escape($params['hostname']) . "', '" .
+               $this->db->escape($params['port']) . "', " .
+               $use_ssl . ", " .
+               $use_tls . ", '" .
+               $this->db->escape($params['order']) . "')";
         $this->db->query($sql);
     }
 
@@ -984,14 +987,14 @@ class CentreonLdapAdmin
         }
         $use_ssl = isset($params['use_ssl']) ? 1 : 0;
         $use_tls = isset($params['use_tls']) ? 1 : 0;
-        $sql = "UPDATE auth_ressource_host SET 
-                    host_address = '" . $this->db->escape($params['hostname']) . "',
-                    host_port = '" . $this->db->escape($params['port']) . "',
-                    host_order = '" . $this->db->escape($params['order']) . "', 
-                    use_ssl = " . $use_ssl . ", 
-                    use_tls = " . $use_tls . "
-                    WHERE ldap_host_id = " . $this->db->escape($params['id']) . "
-                    AND auth_ressource_id = " . $arId;
+        $sql = "UPDATE auth_ressource_host 
+               SET host_address = '" . $this->db->escape($params['hostname']) . "',
+               host_port = '" . $this->db->escape($params['port']) . "',
+               host_order = '" . $this->db->escape($params['order']) . "', 
+               use_ssl = " . $use_ssl . ", 
+               use_tls = " . $use_tls . "
+               WHERE ldap_host_id = " . $this->db->escape($params['id']) . "
+               AND auth_ressource_id = " . $arId;
         $this->db->query($sql);
     }
 
@@ -1050,7 +1053,7 @@ class CentreonLdapAdmin
                 if (isset($config[$key])) {
                     $sth = $this->db->query(
                         "UPDATE auth_ressource_info SET ari_value = '" . $this->db->escape($value) . "'
-                    WHERE ar_id = " . CentreonDB::escape($id) . " AND ari_name = '" . $this->db->escape($key) . "'"
+                        WHERE ar_id = " . CentreonDB::escape($id) . " AND ari_name = '" . $this->db->escape($key) . "'"
                     );
                 } else {
                     $sth = $this->db->query(
@@ -1075,7 +1078,9 @@ class CentreonLdapAdmin
     public function getTemplate($id = 0)
     {
         if ($id == 0) {
-            $queryTemplate = "SELECT ar_id FROM auth_ressource WHERE ar_type = 'ldap_tmpl'";
+            $queryTemplate = "SELECT ar_id 
+                             FROM auth_ressource 
+                             WHERE ar_type = 'ldap_tmpl'";
             $res = $this->db->query($queryTemplate);
             if ($res->rowCount() == 0) {
                 return array();
@@ -1084,8 +1089,8 @@ class CentreonLdapAdmin
             $id = $row['ar_id'];
         }
         $query = "SELECT ari_name, ari_value
-			FROM auth_ressource_info
-			WHERE ar_id = " . CentreonDB::escape($id);
+			     FROM auth_ressource_info
+			     WHERE ar_id = " . CentreonDB::escape($id);
         $res = $this->db->query($query);
         $list = array();
         while ($row = $res->fetchRow()) {
@@ -1184,7 +1189,8 @@ class CentreonLdapAdmin
         if (count($configList)) {
             $this->db->query(
                 "DELETE FROM auth_ressource 
-                WHERE ar_id IN (" . implode(',', $configList) . ")"
+                WHERE ar_id 
+                IN (" . implode(',', $configList) . ")"
             );
         }
     }
@@ -1201,8 +1207,8 @@ class CentreonLdapAdmin
         if (count($configList)) {
             $this->db->query(
                 "UPDATE auth_ressource 
-                                   SET ar_enable = '" . $this->db->escape($status) . "'
-                                   WHERE ar_id IN (" . implode(',', $configList) . ")"
+                SET ar_enable = '" . $this->db->escape($status) . "'
+                WHERE ar_id IN (" . implode(',', $configList) . ")"
             );
         }
     }
@@ -1217,8 +1223,8 @@ class CentreonLdapAdmin
     {
         $res = $this->db->query(
             "SELECT host_address, host_port, use_ssl, use_tls
-                                FROM auth_ressource_host
-                                WHERE auth_ressource_id = " . $this->db->escape($arId) .
+            FROM auth_ressource_host
+            WHERE auth_ressource_id = " . $this->db->escape($arId) .
             " ORDER BY host_order"
         );
         $arr = array();
diff --git a/www/include/Administration/parameters/ldap/form.php b/www/include/Administration/parameters/ldap/form.php
index 84ef43abbb..7039a348fc 100644
--- a/www/include/Administration/parameters/ldap/form.php
+++ b/www/include/Administration/parameters/ldap/form.php
@@ -177,7 +177,7 @@ if ($arId) {
     $gopt = $ldapAdmin->getGeneralOptions($arId);
     $res = $pearDB->query("SELECT `ar_name`, `ar_description`, `ar_enable`
                             FROM `auth_ressource`
-                            WHERE ar_id = " .$pearDB->escape($arId));
+                            WHERE ar_id = " . $pearDB->escape($arId));
     while ($row = $res->fetchRow()) {
         $gopt['ar_name'] = $row['ar_name'];
         $gopt['ar_description'] = $row['ar_description'];
diff --git a/www/include/configuration/configNagios/DB-Func.php b/www/include/configuration/configNagios/DB-Func.php
index 37e9c8bd8d..7531d65d6a 100644
--- a/www/include/configuration/configNagios/DB-Func.php
+++ b/www/include/configuration/configNagios/DB-Func.php
@@ -256,267 +256,705 @@ function insertNagios($ret = array(), $brokerTab = array())
         . "`cfg_file`, `log_pid`, `use_check_result_path`) ";
     $rq .= "VALUES (";
     $rq .= "NULL, ";
-    isset($ret["nagios_name"]) && $ret["nagios_name"] != null ?
-        $rq .= "'" . htmlentities($ret["nagios_name"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["use_timezone"]) && $ret["use_timezone"] != null ?
-        $rq .= "'" . htmlentities($ret["use_timezone"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["nagios_server_id"]) && $ret["nagios_server_id"] != null ?
-        $rq .= "'" . htmlentities($ret["nagios_server_id"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["log_file"]) && $ret["log_file"] != null ?
-        $rq .= "'" . htmlentities($ret["log_file"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["cfg_dir"]) && $ret["cfg_dir"] != null ?
-        $rq .= "'" . htmlentities($ret["cfg_dir"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["temp_file"]) && $ret["temp_file"] != null ?
-        $rq .= "'" . htmlentities($ret["temp_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["check_result_path"]) && $ret["check_result_path"] != null ?
-        $rq .= "'" . htmlentities($ret["check_result_path"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["max_check_result_file_age"]) && $ret["max_check_result_file_age"] != null ?
-        $rq .= "'" . htmlentities($ret["max_check_result_file_age"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["status_file"]) && $ret["status_file"] != null ?
-        $rq .= "'" . htmlentities($ret["status_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["status_update_interval"]) && $ret["status_update_interval"] != null ?
-        $rq .= "'" . (int)$ret["status_update_interval"] . "',  " : $rq .= "NULL, ";
-    isset($ret["nagios_user"]) && $ret["nagios_user"] != null ?
-        $rq .= "'" . htmlentities($ret["nagios_user"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["nagios_group"]) && $ret["nagios_group"] != null ?
-        $rq .= "'" . htmlentities($ret["nagios_group"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["enable_notifications"]["enable_notifications"])
-    && $ret["enable_notifications"]["enable_notifications"] != 2 ?
-        $rq .= "'" . $ret["enable_notifications"]["enable_notifications"] . "',  " : $rq .= "'2', ";
-    isset($ret["execute_service_checks"]["execute_service_checks"])
-    && $ret["execute_service_checks"]["execute_service_checks"] != 2 ?
-        $rq .= "'" . $ret["execute_service_checks"]["execute_service_checks"] . "',  " : $rq .= "'2', ";
-    isset($ret["accept_passive_service_checks"]["accept_passive_service_checks"])
-    && $ret["accept_passive_service_checks"]["accept_passive_service_checks"] != 2 ?
-        $rq .= "'" . $ret["accept_passive_service_checks"]["accept_passive_service_checks"] . "',  " : $rq .= "'2', ";
-    isset($ret["execute_host_checks"]["execute_host_checks"])
-    && $ret["execute_host_checks"]["execute_host_checks"] != 2 ?
-        $rq .= "'" . $ret["execute_host_checks"]["execute_host_checks"] . "',  " : $rq .= "'2', ";
-    isset($ret["accept_passive_host_checks"]["accept_passive_host_checks"])
-    && $ret["accept_passive_host_checks"]["accept_passive_host_checks"] != 2 ?
-        $rq .= "'" . $ret["accept_passive_host_checks"]["accept_passive_host_checks"] . "',  " : $rq .= "'2', ";
-    isset($ret["enable_event_handlers"]["enable_event_handlers"])
-    && $ret["enable_event_handlers"]["enable_event_handlers"] != 2 ?
-        $rq .= "'" . $ret["enable_event_handlers"]["enable_event_handlers"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_rotation_method"]["log_rotation_method"])
-    && $ret["log_rotation_method"]["log_rotation_method"] != 2 ?
-        $rq .= "'" . $ret["log_rotation_method"]["log_rotation_method"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_archive_path"]) && $ret["log_archive_path"] != null ?
-        $rq .= "'" . htmlentities($ret["log_archive_path"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["check_external_commands"]["check_external_commands"])
-    && $ret["check_external_commands"]["check_external_commands"] != 2 ?
-        $rq .= "'" . $ret["check_external_commands"]["check_external_commands"] . "',  " : $rq .= "'2', ";
-    isset($ret["command_check_interval"]) && $ret["command_check_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["command_check_interval"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["command_file"]) && $ret["command_file"] != null ?
-        $rq .= "'" . htmlentities($ret["command_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["downtime_file"]) && $ret["downtime_file"] != null ?
-        $rq .= "'" . htmlentities($ret["downtime_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["comment_file"]) && $ret["comment_file"] != null ?
-        $rq .= "'" . htmlentities($ret["comment_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["lock_file"]) && $ret["lock_file"] != null ?
-        $rq .= "'" . htmlentities($ret["lock_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["retain_state_information"]["retain_state_information"])
-    && $ret["retain_state_information"]["retain_state_information"] != 2 ?
-        $rq .= "'" . $ret["retain_state_information"]["retain_state_information"] . "',  " : $rq .= "'2', ";
-    isset($ret["state_retention_file"]) && $ret["state_retention_file"] != null ?
-        $rq .= "'" . htmlentities($ret["state_retention_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["retention_update_interval"]) && $ret["retention_update_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["retention_update_interval"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["use_retained_program_state"]["use_retained_program_state"])
-    && $ret["use_retained_program_state"]["use_retained_program_state"] != 2 ?
-        $rq .= "'" . $ret["use_retained_program_state"]["use_retained_program_state"] . "',  " : $rq .= "'2', ";
-    isset($ret["use_retained_scheduling_info"]["use_retained_scheduling_info"])
-    && $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] != 2 ?
-        $rq .= "'" . $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] . "',  " : $rq .= "'2', ";
-    isset($ret["retained_contact_host_attribute_mask"]) && $ret["retained_contact_host_attribute_mask"] != null ?
-        $rq .= "'" . htmlentities($ret["retained_contact_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["retained_contact_service_attribute_mask"]) && $ret["retained_contact_service_attribute_mask"] != null ?
-        $rq .= "'" . htmlentities($ret["retained_contact_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["retained_process_host_attribute_mask"]) && $ret["retained_process_host_attribute_mask"] != null ?
-        $rq .= "'" . htmlentities($ret["retained_process_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["retained_process_service_attribute_mask"]) && $ret["retained_process_service_attribute_mask"] != null ?
-        $rq .= "'" . htmlentities($ret["retained_process_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["retained_host_attribute_mask"]) && $ret["retained_host_attribute_mask"] != null ?
-        $rq .= "'" . htmlentities($ret["retained_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["retained_service_attribute_mask"]) && $ret["retained_service_attribute_mask"] != null
-        ? $rq .= "'" . htmlentities($ret["retained_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["use_syslog"]["use_syslog"]) && $ret["use_syslog"]["use_syslog"] != 2 ?
-        $rq .= "'" . $ret["use_syslog"]["use_syslog"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_notifications"]["log_notifications"]) && $ret["log_notifications"]["log_notifications"] != 2 ?
-        $rq .= "'" . $ret["log_notifications"]["log_notifications"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_service_retries"]["log_service_retries"])
-    && $ret["log_service_retries"]["log_service_retries"] != 2 ?
-        $rq .= "'" . $ret["log_service_retries"]["log_service_retries"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_host_retries"]["log_host_retries"])
-    && $ret["log_host_retries"]["log_host_retries"] != 2 ?
-        $rq .= "'" . $ret["log_host_retries"]["log_host_retries"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_event_handlers"]["log_event_handlers"])
-    && $ret["log_event_handlers"]["log_event_handlers"] != 2 ?
-        $rq .= "'" . $ret["log_event_handlers"]["log_event_handlers"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_external_commands"]["log_external_commands"])
-    && $ret["log_external_commands"]["log_external_commands"] != 2 ?
-        $rq .= "'" . $ret["log_external_commands"]["log_external_commands"] . "',  " : $rq .= "'2', ";
-    isset($ret["log_passive_checks"]["log_passive_checks"])
-    && $ret["log_passive_checks"]["log_passive_checks"] != 2 ?
-        $rq .= "'" . $ret["log_passive_checks"]["log_passive_checks"] . "',  " : $rq .= "'2', ";
-    isset($ret["global_host_event_handler"]) && $ret["global_host_event_handler"] != null ?
-        $rq .= "'" . $ret["global_host_event_handler"] . "',  " : $rq .= "NULL, ";
-    isset($ret["global_service_event_handler"]) && $ret["global_service_event_handler"] != null ?
-        $rq .= "'" . $ret["global_service_event_handler"] . "',  " : $rq .= "NULL, ";
-    isset($ret["sleep_time"]) && $ret["sleep_time"] != null ?
-        $rq .= "'" . htmlentities($ret["sleep_time"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["service_inter_check_delay_method"]) && $ret["service_inter_check_delay_method"] != null ?
-        $rq .= "'" . $ret["service_inter_check_delay_method"] . "',  " : $rq .= "NULL, ";
-    isset($ret["host_inter_check_delay_method"]) && $ret["host_inter_check_delay_method"] != null ?
-        $rq .= "'" . $ret["host_inter_check_delay_method"] . "',  " : $rq .= "NULL, ";
-    isset($ret["service_interleave_factor"]["service_interleave_factor"])
-    && $ret["service_interleave_factor"]["service_interleave_factor"] != 2 ?
-        $rq .= "'" . $ret["service_interleave_factor"]["service_interleave_factor"] . "',  " : $rq .= "'2', ";
-    isset($ret["max_concurrent_checks"]) && $ret["max_concurrent_checks"] != null ?
-        $rq .= "'" . htmlentities($ret["max_concurrent_checks"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["max_service_check_spread"]) && $ret["max_service_check_spread"] != null ?
-        $rq .= "'" . htmlentities($ret["max_service_check_spread"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["max_host_check_spread"]) && $ret["max_host_check_spread"] != null ?
-        $rq .= "'" . htmlentities($ret["max_host_check_spread"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["check_result_reaper_frequency"]) && $ret["check_result_reaper_frequency"] != null
-        ? $rq .= "'" . htmlentities($ret["check_result_reaper_frequency"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["max_check_result_reaper_time"]) && $ret["max_check_result_reaper_time"] != null ?
-        $rq .= "'" . htmlentities($ret["max_check_result_reaper_time"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["auto_reschedule_checks"]["auto_reschedule_checks"])
-    && $ret["auto_reschedule_checks"]["auto_reschedule_checks"] != 2 ?
-        $rq .= "'" . $ret["auto_reschedule_checks"]["auto_reschedule_checks"] . "', " : $rq .= "'2', ";
-    isset($ret["auto_rescheduling_interval"]) && $ret["auto_rescheduling_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["auto_rescheduling_interval"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["auto_rescheduling_window"]) && $ret["auto_rescheduling_window"] != null ?
-        $rq .= "'" . htmlentities($ret["auto_rescheduling_window"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["use_aggressive_host_checking"]["use_aggressive_host_checking"])
-    && $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] != 0 ?
-        $rq .= "'" . $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] . "',  " : $rq .= "'0', ";
-    isset($ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"])
-    && $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] != 2 ?
+
+    if (isset($ret["nagios_name"]) && $ret["nagios_name"] != null) {
+        $rq .= "'" . htmlentities($ret["nagios_name"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["use_timezone"]) && $ret["use_timezone"] != null) {
+        $rq .= "'" . htmlentities($ret["use_timezone"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["nagios_server_id"]) && $ret["nagios_server_id"] != null) {
+        $rq .= "'" . htmlentities($ret["nagios_server_id"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["log_file"]) && $ret["log_file"] != null) {
+        $rq .= "'" . htmlentities($ret["log_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["cfg_dir"]) && $ret["cfg_dir"] != null) {
+        $rq .= "'" . htmlentities($ret["cfg_dir"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["temp_file"]) && $ret["temp_file"] != null) {
+        $rq .= "'" . htmlentities($ret["temp_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["check_result_path"]) && $ret["check_result_path"] != null) {
+        $rq .= "'" . htmlentities($ret["check_result_path"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["max_check_result_file_age"]) && $ret["max_check_result_file_age"] != null) {
+        $rq .= "'" . htmlentities($ret["max_check_result_file_age"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["status_file"]) && $ret["status_file"] != null) {
+        $rq .= "'" . htmlentities($ret["status_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["status_update_interval"]) && $ret["status_update_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["status_update_interval"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["nagios_user"]) && $ret["nagios_user"] != null) {
+        $rq .= "'" . htmlentities($ret["nagios_user"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["nagios_group"]) && $ret["nagios_group"] != null) {
+        $rq .= "'" . htmlentities($ret["nagios_group"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["enable_notifications"]["enable_notifications"]) &&
+        $ret["enable_notifications"]["enable_notifications"] != 2
+    ) {
+        $rq .= "'" . $ret["enable_notifications"]["enable_notifications"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["execute_service_checks"]["execute_service_checks"]) &&
+        $ret["execute_service_checks"]["execute_service_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["execute_service_checks"]["execute_service_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["accept_passive_service_checks"]["accept_passive_service_checks"]) &&
+        $ret["accept_passive_service_checks"]["accept_passive_service_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["accept_passive_service_checks"]["accept_passive_service_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["execute_host_checks"]["execute_host_checks"]) &&
+        $ret["execute_host_checks"]["execute_host_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["execute_host_checks"]["execute_host_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["accept_passive_host_checks"]["accept_passive_host_checks"]) &&
+        $ret["accept_passive_host_checks"]["accept_passive_host_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["accept_passive_host_checks"]["accept_passive_host_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["enable_event_handlers"]["enable_event_handlers"]) &&
+        $ret["enable_event_handlers"]["enable_event_handlers"] != 2
+    ) {
+        $rq .= "'" . $ret["enable_event_handlers"]["enable_event_handlers"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_rotation_method"]["log_rotation_method"]) &&
+        $ret["log_rotation_method"]["log_rotation_method"] != 2
+    ) {
+        $rq .= "'" . $ret["log_rotation_method"]["log_rotation_method"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_archive_path"]) && $ret["log_archive_path"] != null) {
+        $rq .= "'" . htmlentities($ret["log_archive_path"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["check_external_commands"]["check_external_commands"]) &&
+        $ret["check_external_commands"]["check_external_commands"] != 2
+    ) {
+        $rq .= "'" . $ret["check_external_commands"]["check_external_commands"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["command_check_interval"]) && $ret["command_check_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["command_check_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["command_file"]) && $ret["command_file"] != null) {
+        $rq .= "'" . htmlentities($ret["command_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["downtime_file"]) && $ret["downtime_file"] != null) {
+        $rq .= "'" . htmlentities($ret["downtime_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["comment_file"]) && $ret["comment_file"] != null) {
+        $rq .= "'" . htmlentities($ret["comment_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["lock_file"]) && $ret["lock_file"] != null) {
+        $rq .= "'" . htmlentities($ret["lock_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retain_state_information"]["retain_state_information"]) &&
+        $ret["retain_state_information"]["retain_state_information"] != 2
+    ) {
+        $rq .= "'" . $ret["retain_state_information"]["retain_state_information"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["state_retention_file"]) && $ret["state_retention_file"] != null) {
+        $rq .= "'" . htmlentities($ret["state_retention_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retention_update_interval"]) && $ret["retention_update_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["retention_update_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["use_retained_program_state"]["use_retained_program_state"]) &&
+        $ret["use_retained_program_state"]["use_retained_program_state"] != 2
+    ) {
+        $rq .= "'" . $ret["use_retained_program_state"]["use_retained_program_state"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["use_retained_scheduling_info"]["use_retained_scheduling_info"]) &&
+        $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] != 2
+    ) {
+        $rq .= "'" . $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["retained_contact_host_attribute_mask"]) && $ret["retained_contact_host_attribute_mask"] != null) {
+        $rq .= "'" . htmlentities($ret["retained_contact_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retained_contact_service_attribute_mask"]) &&
+        $ret["retained_contact_service_attribute_mask"] != null
+    ) {
+        $rq .= "'" . htmlentities($ret["retained_contact_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retained_process_host_attribute_mask"]) && $ret["retained_process_host_attribute_mask"] != null) {
+        $rq .= "'" . htmlentities($ret["retained_process_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retained_process_service_attribute_mask"]) &&
+        $ret["retained_process_service_attribute_mask"] != null
+    ) {
+        $rq .= "'" . htmlentities($ret["retained_process_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retained_host_attribute_mask"]) && $ret["retained_host_attribute_mask"] != null) {
+        $rq .= "'" . htmlentities($ret["retained_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["retained_service_attribute_mask"]) && $ret["retained_service_attribute_mask"] != null) {
+        $rq .= "'" . htmlentities($ret["retained_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["use_syslog"]["use_syslog"]) && $ret["use_syslog"]["use_syslog"] != 2) {
+        $rq .= "'" . $ret["use_syslog"]["use_syslog"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_notifications"]["log_notifications"]) && $ret["log_notifications"]["log_notifications"] != 2) {
+        $rq .= "'" . $ret["log_notifications"]["log_notifications"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_service_retries"]["log_service_retries"]) &&
+        $ret["log_service_retries"]["log_service_retries"] != 2
+    ) {
+        $rq .= "'" . $ret["log_service_retries"]["log_service_retries"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_host_retries"]["log_host_retries"]) && $ret["log_host_retries"]["log_host_retries"] != 2) {
+        $rq .= "'" . $ret["log_host_retries"]["log_host_retries"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_event_handlers"]["log_event_handlers"])
+        && $ret["log_event_handlers"]["log_event_handlers"] != 2
+    ) {
+        $rq .= "'" . $ret["log_event_handlers"]["log_event_handlers"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_external_commands"]["log_external_commands"])
+        && $ret["log_external_commands"]["log_external_commands"] != 2
+    ) {
+        $rq .= "'" . $ret["log_external_commands"]["log_external_commands"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["log_passive_checks"]["log_passive_checks"])
+        && $ret["log_passive_checks"]["log_passive_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["log_passive_checks"]["log_passive_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["global_host_event_handler"]) && $ret["global_host_event_handler"] != null) {
+        $rq .= "'" . $ret["global_host_event_handler"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["global_service_event_handler"]) && $ret["global_service_event_handler"] != null) {
+        $rq .= "'" . $ret["global_service_event_handler"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["sleep_time"]) && $ret["sleep_time"] != null) {
+        $rq .= "'" . htmlentities($ret["sleep_time"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_inter_check_delay_method"]) && $ret["service_inter_check_delay_method"] != null) {
+        $rq .= "'" . $ret["service_inter_check_delay_method"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_inter_check_delay_method"]) && $ret["host_inter_check_delay_method"] != null) {
+        $rq .= "'" . $ret["host_inter_check_delay_method"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_interleave_factor"]["service_interleave_factor"])
+        && $ret["service_interleave_factor"]["service_interleave_factor"] != 2
+    ) {
+        $rq .= "'" . $ret["service_interleave_factor"]["service_interleave_factor"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["max_concurrent_checks"]) && $ret["max_concurrent_checks"] != null) {
+        $rq .= "'" . htmlentities($ret["max_concurrent_checks"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["max_service_check_spread"]) && $ret["max_service_check_spread"] != null) {
+        $rq .= "'" . htmlentities($ret["max_service_check_spread"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["max_host_check_spread"]) && $ret["max_host_check_spread"] != null) {
+        $rq .= "'" . htmlentities($ret["max_host_check_spread"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["check_result_reaper_frequency"]) && $ret["check_result_reaper_frequency"] != null) {
+        $rq .= "'" . htmlentities($ret["check_result_reaper_frequency"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["max_check_result_reaper_time"]) && $ret["max_check_result_reaper_time"] != null) {
+        $rq .= "'" . htmlentities($ret["max_check_result_reaper_time"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["auto_reschedule_checks"]["auto_reschedule_checks"])
+        && $ret["auto_reschedule_checks"]["auto_reschedule_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["auto_reschedule_checks"]["auto_reschedule_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["auto_rescheduling_interval"]) && $ret["auto_rescheduling_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["auto_rescheduling_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["auto_rescheduling_window"]) && $ret["auto_rescheduling_window"] != null) {
+        $rq .= "'" . htmlentities($ret["auto_rescheduling_window"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["use_aggressive_host_checking"]["use_aggressive_host_checking"])
+        && $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] != 0
+    ) {
+        $rq .= "'" . $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] . "',  ";
+    } else {
+        $rq .= "'0', ";
+    }
+
+    if (isset($ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"])
+        && $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] != 2
+    ) {
         $rq .= "'" .
-            $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] . "',  "
-        : $rq .= "'2', ";
-    isset($ret["enable_flap_detection"]["enable_flap_detection"])
-    && $ret["enable_flap_detection"]["enable_flap_detection"] != 2 ?
-        $rq .= "'" . $ret["enable_flap_detection"]["enable_flap_detection"] . "',  " : $rq .= "'2', ";
-    isset($ret["low_service_flap_threshold"]) && $ret["low_service_flap_threshold"] != null ?
-        $rq .= "'" . htmlentities($ret["low_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["high_service_flap_threshold"]) && $ret["high_service_flap_threshold"] != null ?
-        $rq .= "'" . htmlentities($ret["high_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["low_host_flap_threshold"]) && $ret["low_host_flap_threshold"] != null ?
-        $rq .= "'" . htmlentities($ret["low_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["high_host_flap_threshold"]) && $ret["high_host_flap_threshold"] != null ?
-        $rq .= "'" . htmlentities($ret["high_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["soft_state_dependencies"]["soft_state_dependencies"])
-    && $ret["soft_state_dependencies"]["soft_state_dependencies"] != 2 ?
-        $rq .= "'" . $ret["soft_state_dependencies"]["soft_state_dependencies"] . "',  " : $rq .= "'2', ";
-    isset($ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"])
-    && $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] != 2 ?
-        $rq .= "'" . $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"]
-            . "',  "
-        : $rq .= "'2', ";
-    isset($ret["service_check_timeout"]) && $ret["service_check_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["service_check_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["host_check_timeout"]) && $ret["host_check_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["host_check_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["event_handler_timeout"]) && $ret["event_handler_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["event_handler_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["notification_timeout"]) && $ret["notification_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["notification_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["ocsp_timeout"]) && $ret["ocsp_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["ocsp_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["ochp_timeout"]) && $ret["ochp_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["ochp_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["perfdata_timeout"]) && $ret["perfdata_timeout"] != null ?
-        $rq .= "'" . htmlentities($ret["perfdata_timeout"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["obsess_over_services"]["obsess_over_services"])
-    && $ret["obsess_over_services"]["obsess_over_services"] != 2 ?
-        $rq .= "'" . $ret["obsess_over_services"]["obsess_over_services"] . "',  " : $rq .= "'2', ";
-    isset($ret["ocsp_command"]) && $ret["ocsp_command"] != null ?
-        $rq .= "'" . htmlentities($ret["ocsp_command"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["obsess_over_hosts"]["obsess_over_hosts"])
-    && $ret["obsess_over_hosts"]["obsess_over_hosts"] != 2 ?
-        $rq .= "'" . $ret["obsess_over_hosts"]["obsess_over_hosts"] . "',  " : $rq .= "'2', ";
-    isset($ret["ochp_command"]) && $ret["ochp_command"] != null ?
-        $rq .= "'" . htmlentities($ret["ochp_command"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["process_performance_data"]["process_performance_data"])
-    && $ret["process_performance_data"]["process_performance_data"] != 2 ?
-        $rq .= "'" . $ret["process_performance_data"]["process_performance_data"] . "',  " : $rq .= "'2', ";
-    isset($ret["host_perfdata_command"]) && $ret["host_perfdata_command"] != null ?
-        $rq .= "'" . htmlentities($ret["host_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["service_perfdata_command"]) && $ret["service_perfdata_command"] != null ?
-        $rq .= "'" . htmlentities($ret["service_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["host_perfdata_file"]) && $ret["host_perfdata_file"] != null ?
-        $rq .= "'" . htmlentities($ret["host_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["service_perfdata_file"]) && $ret["service_perfdata_file"] != null ?
-        $rq .= "'" . htmlentities($ret["service_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["host_perfdata_file_template"]) && $ret["host_perfdata_file_template"] != null ?
-        $rq .= "'" . $pearDB->quote($ret["host_perfdata_file_template"]) . "',  " : $rq .= "NULL, ";
-    isset($ret["service_perfdata_file_template"]) && $ret["service_perfdata_file_template"] != null ?
-        $rq .= "'" . $pearDB->quote($ret["service_perfdata_file_template"]) . "',  " : $rq .= "NULL, ";
-    isset($ret["host_perfdata_file_mode"]["host_perfdata_file_mode"])
-    && $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] != null ?
-        $rq .= "'" . $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] . "',  " : $rq .= "NULL, ";
-    isset($ret["service_perfdata_file_mode"]["service_perfdata_file_mode"])
-    && $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] != null ?
-        $rq .= "'" . $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] . "',  " : $rq .= "NULL, ";
-    isset($ret["host_perfdata_file_processing_interval"])
-    && $ret["host_perfdata_file_processing_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["host_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["service_perfdata_file_processing_interval"])
-    && $ret["service_perfdata_file_processing_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["service_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["host_perfdata_file_processing_command"])
-    && $ret["host_perfdata_file_processing_command"] != null ?
-        $rq .= "'" . htmlentities($ret["host_perfdata_file_processing_command"]) . "',  " : $rq .= "NULL, ";
-    isset($ret["service_perfdata_file_processing_command"])
-    && $ret["service_perfdata_file_processing_command"] != null ?
-        $rq .= "'" . htmlentities($ret["service_perfdata_file_processing_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["check_for_orphaned_services"]["check_for_orphaned_services"])
-    && $ret["check_for_orphaned_services"]["check_for_orphaned_services"] != 2 ?
-        $rq .= "'" . $ret["check_for_orphaned_services"]["check_for_orphaned_services"] . "',  " : $rq .= "'2', ";
-    isset($ret["check_service_freshness"]["check_service_freshness"])
-    && $ret["check_service_freshness"]["check_service_freshness"] != 2 ?
-        $rq .= "'" . $ret["check_service_freshness"]["check_service_freshness"] . "',  " : $rq .= "'2', ";
-    isset($ret["service_freshness_check_interval"]) && $ret["service_freshness_check_interval"] != null ?
-        $rq .= "'" . htmlentities($ret["service_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["cached_host_check_horizon"]) && $ret["cached_host_check_horizon"] != null ?
-        $rq .= "'" . htmlentities($ret["cached_host_check_horizon"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["cached_service_check_horizon"]) && $ret["cached_service_check_horizon"] != null ?
-        $rq .= "'" . htmlentities($ret["cached_service_check_horizon"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["additional_freshness_latency"]) && $ret["additional_freshness_latency"] != null ?
-        $rq .= "'" . htmlentities($ret["additional_freshness_latency"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["check_host_freshness"]["check_host_freshness"])
-    && $ret["check_host_freshness"]["check_host_freshness"] != 2 ?
-        $rq .= "'" . $ret["check_host_freshness"]["check_host_freshness"] . "',  " : $rq .= "'2', ";
-    isset($ret["host_freshness_check_interval"]) && $ret["host_freshness_check_interval"] != null
-        ? $rq .= "'" . htmlentities($ret["host_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["date_format"]) && $ret["date_format"] != null ?
-        $rq .= "'" . htmlentities($ret["date_format"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["illegal_object_name_chars"]) && $ret["illegal_object_name_chars"] != null
-        ? $rq .= "'" . $pearDB->quote($ret["illegal_object_name_chars"]) . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["illegal_macro_output_chars"]) && $ret["illegal_macro_output_chars"] != null
-        ? $rq .= "'" . $pearDB->quote($ret["illegal_macro_output_chars"]) . "',  "
-        : $rq .= "NULL, ";
-    isset($ret["use_large_installation_tweaks"]["use_large_installation_tweaks"])
-    && $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] != 2 ?
-        $rq .= "'" . $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] . "',  " : $rq .= "'2', ";
-    isset($ret["debug_file"]) && $ret["debug_file"] != null ?
-        $rq .= "'" . htmlentities($ret["debug_file"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
+        $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["enable_flap_detection"]["enable_flap_detection"])
+        && $ret["enable_flap_detection"]["enable_flap_detection"] != 2
+    ) {
+        $rq .= "'" . $ret["enable_flap_detection"]["enable_flap_detection"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["low_service_flap_threshold"]) && $ret["low_service_flap_threshold"] != null) {
+        $rq .= "'" . htmlentities($ret["low_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["high_service_flap_threshold"]) && $ret["high_service_flap_threshold"] != null) {
+        $rq .= "'" . htmlentities($ret["high_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["low_host_flap_threshold"]) && $ret["low_host_flap_threshold"] != null) {
+        $rq .= "'" . htmlentities($ret["low_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["high_host_flap_threshold"]) && $ret["high_host_flap_threshold"] != null) {
+        $rq .= "'" . htmlentities($ret["high_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["soft_state_dependencies"]["soft_state_dependencies"])
+        && $ret["soft_state_dependencies"]["soft_state_dependencies"] != 2
+    ) {
+        $rq .= "'" . $ret["soft_state_dependencies"]["soft_state_dependencies"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"])
+        && $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] != 2
+    ) {
+        $rq .= "'" .
+        $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["service_check_timeout"]) && $ret["service_check_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["service_check_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_check_timeout"]) && $ret["host_check_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["host_check_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["event_handler_timeout"]) && $ret["event_handler_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["event_handler_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["notification_timeout"]) && $ret["notification_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["notification_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["ocsp_timeout"]) && $ret["ocsp_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["ocsp_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["ochp_timeout"]) && $ret["ochp_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["ochp_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["perfdata_timeout"]) && $ret["perfdata_timeout"] != null) {
+        $rq .= "'" . htmlentities($ret["perfdata_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["obsess_over_services"]["obsess_over_services"])
+        && $ret["obsess_over_services"]["obsess_over_services"] != 2
+    ) {
+        $rq .= "'" . $ret["obsess_over_services"]["obsess_over_services"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["ocsp_command"]) && $ret["ocsp_command"] != null) {
+        $rq .= "'" . htmlentities($ret["ocsp_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["obsess_over_hosts"]["obsess_over_hosts"])
+        && $ret["obsess_over_hosts"]["obsess_over_hosts"] != 2
+    ) {
+        $rq .= "'" . $ret["obsess_over_hosts"]["obsess_over_hosts"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["ochp_command"]) && $ret["ochp_command"] != null) {
+        $rq .= "'" . htmlentities($ret["ochp_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["process_performance_data"]["process_performance_data"])
+        && $ret["process_performance_data"]["process_performance_data"] != 2
+    ) {
+        $rq .= "'" . $ret["process_performance_data"]["process_performance_data"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["host_perfdata_command"]) && $ret["host_perfdata_command"] != null) {
+        $rq .= "'" . htmlentities($ret["host_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_command"]) && $ret["service_perfdata_command"] != null) {
+        $rq .= "'" . htmlentities($ret["service_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file"]) && $ret["host_perfdata_file"] != null) {
+        $rq .= "'" . htmlentities($ret["host_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file"]) && $ret["service_perfdata_file"] != null) {
+        $rq .= "'" . htmlentities($ret["service_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_template"]) && $ret["host_perfdata_file_template"] != null) {
+        $rq .= "'" . $pearDB->quote($ret["host_perfdata_file_template"]) . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_template"]) && $ret["service_perfdata_file_template"] != null) {
+        $rq .= "'" . $pearDB->quote($ret["service_perfdata_file_template"]) . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_mode"]["host_perfdata_file_mode"]) &&
+        $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] != null
+    ) {
+        $rq .= "'" . $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_mode"]["service_perfdata_file_mode"]) &&
+        $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] != null
+    ) {
+        $rq .= "'" . $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_processing_interval"]) &&
+        $ret["host_perfdata_file_processing_interval"] != null
+    ) {
+        $rq .= "'" . htmlentities($ret["host_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_processing_interval"]) &&
+        $ret["service_perfdata_file_processing_interval"] != null
+    ) {
+        $rq .= "'" . htmlentities($ret["service_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_processing_command"]) && $ret["host_perfdata_file_processing_command"] != null) {
+        $rq .= "'" . htmlentities($ret["host_perfdata_file_processing_command"]) . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_processing_command"]) &&
+        $ret["service_perfdata_file_processing_command"] != null
+    ) {
+        $rq .= "'" . htmlentities($ret["service_perfdata_file_processing_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["check_for_orphaned_services"]["check_for_orphaned_services"])
+        && $ret["check_for_orphaned_services"]["check_for_orphaned_services"] != 2
+    ) {
+        $rq .= "'" . $ret["check_for_orphaned_services"]["check_for_orphaned_services"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["check_service_freshness"]["check_service_freshness"])
+        && $ret["check_service_freshness"]["check_service_freshness"] != 2
+    ) {
+        $rq .= "'" . $ret["check_service_freshness"]["check_service_freshness"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["service_freshness_check_interval"]) && $ret["service_freshness_check_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["service_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["cached_host_check_horizon"]) && $ret["cached_host_check_horizon"] != null) {
+        $rq .= "'" . htmlentities($ret["cached_host_check_horizon"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["cached_service_check_horizon"]) && $ret["cached_service_check_horizon"] != null) {
+        $rq .= "'" . htmlentities($ret["cached_service_check_horizon"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["additional_freshness_latency"]) && $ret["additional_freshness_latency"] != null) {
+        $rq .= "'" . htmlentities($ret["additional_freshness_latency"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["check_host_freshness"]["check_host_freshness"])
+        && $ret["check_host_freshness"]["check_host_freshness"] != 2
+    ) {
+        $rq .= "'" . $ret["check_host_freshness"]["check_host_freshness"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["host_freshness_check_interval"]) && $ret["host_freshness_check_interval"] != null) {
+        $rq .= "'" . htmlentities($ret["host_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["date_format"]) && $ret["date_format"] != null) {
+        $rq .= "'" . htmlentities($ret["date_format"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["illegal_object_name_chars"]) && $ret["illegal_object_name_chars"] != null) {
+        $rq .= "'" . $pearDB->quote($ret["illegal_object_name_chars"]) . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["illegal_macro_output_chars"]) && $ret["illegal_macro_output_chars"] != null) {
+        $rq .= "'" . $pearDB->quote($ret["illegal_macro_output_chars"]) . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["use_large_installation_tweaks"]["use_large_installation_tweaks"])
+        && $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] != 2
+    ) {
+        $rq .= "'" . $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["debug_file"]) && $ret["debug_file"] != null) {
+        $rq .= "'" . htmlentities($ret["debug_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
     $level = 0;
     if (isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null) {
         foreach ($ret["nagios_debug_level"] as $key => $value) {
@@ -524,56 +962,142 @@ function insertNagios($ret = array(), $brokerTab = array())
         }
     }
     $rq .= "'.$level.', ";
-    isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null ?
-        $rq .= "'" . implode(",", array_keys($ret["nagios_debug_level"])) . "',  " : $rq .= "'0', ";
-    isset($ret["debug_verbosity"]["debug_verbosity"])
-    && $ret["debug_verbosity"]["debug_verbosity"] != 2 ?
-        $rq .= "'" . $ret["debug_verbosity"]["debug_verbosity"] . "',  " : $rq .= "'2', ";
-    isset($ret["max_debug_file_size"]) && $ret["max_debug_file_size"] != null ?
-        $rq .= "'" . htmlentities($ret["max_debug_file_size"], ENT_QUOTES, "UTF-8") . "',  " : $rq .= "NULL, ";
-    isset($ret["daemon_dumps_core"]["daemon_dumps_core"])
-    && $ret["daemon_dumps_core"]["daemon_dumps_core"] ?
-        $rq .= "'1', " : $rq .= "'0', ";
-    isset($ret["enable_environment_macros"]["enable_environment_macros"])
-    && $ret["enable_environment_macros"]["enable_environment_macros"] != 2 ?
-        $rq .= "'" . $ret["enable_environment_macros"]["enable_environment_macros"] . "',  " : $rq .= "'2', ";
-    isset($ret["use_setpgid"]["use_setpgid"]) && $ret["use_setpgid"]["use_setpgid"] != 2 ?
-        $rq .= "'" . $ret["use_setpgid"]["use_setpgid"] . "',  " : $rq .= "'2', ";
-    isset($ret["use_regexp_matching"]["use_regexp_matching"])
-    && $ret["use_regexp_matching"]["use_regexp_matching"] != 2 ?
-        $rq .= "'" . $ret["use_regexp_matching"]["use_regexp_matching"] . "',  " : $rq .= "'2', ";
-    isset($ret["use_true_regexp_matching"]["use_true_regexp_matching"])
-    && $ret["use_true_regexp_matching"]["use_true_regexp_matching"] != 2 ?
-        $rq .= "'" . $ret["use_true_regexp_matching"]["use_true_regexp_matching"] . "',  " : $rq .= "'2', ";
-    isset($ret["admin_email"]) && $ret["admin_email"] != null ?
-        $rq .= "'" . htmlentities($ret["admin_email"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["admin_pager"]) && $ret["admin_pager"] != null ?
-        $rq .= "'" . htmlentities($ret["admin_pager"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["nagios_comment"]) && $ret["nagios_comment"] != null ?
-        $rq .= "'" . htmlentities($ret["nagios_comment"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["nagios_activate"]["nagios_activate"])
-    && $ret["nagios_activate"]["nagios_activate"] != null ?
-        $rq .= "'" . $ret["nagios_activate"]["nagios_activate"] . "'," : $rq .= "'0',";
-    isset($ret["event_broker_options"]) && $ret["event_broker_options"] != null ?
-        $rq .= "'" . htmlentities($ret["event_broker_options"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "'-1', ";
-    isset($ret["translate_passive_host_checks"]["translate_passive_host_checks"])
-    && $ret["translate_passive_host_checks"]["translate_passive_host_checks"] != 2 ?
-        $rq .= "'" . $ret["translate_passive_host_checks"]["translate_passive_host_checks"] . "', " : $rq .= "'2', ";
-    isset($ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"])
-    && $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] != 2 ?
-        $rq .= "'" . $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] . "', " : $rq .= "'2', ";
-    isset($ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"])
-    && $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] != 2 ?
-        $rq .= "'" . $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] . "', " : $rq .= "'2', ";
-    isset($ret["external_command_buffer_slots"]["external_command_buffer_slots"])
-    && $ret["external_command_buffer_slots"]["external_command_buffer_slots"] != 2 ?
-        $rq .= "'" . $ret["external_command_buffer_slots"]["external_command_buffer_slots"] . "', " : $rq .= "'2', ";
-    isset($ret["cfg_file"]) && $ret["cfg_file"] != null ?
-        $rq .= "'" . htmlentities($ret["cfg_file"], ENT_QUOTES, "UTF-8") . "', " : $rq .= "NULL, ";
-    isset($ret["log_pid"]["log_pid"]) && $ret["log_pid"]["log_pid"] ? $rq .= "'1', " : $rq .= "'0', ";
-    isset($ret['use_check_result_path']['use_check_result_path'])
-    && $ret['use_check_result_path']['use_check_result_path'] ?
-        $rq .= "'1')" : $rq .= "'0')";
+
+    if (isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null) {
+        $rq .= "'" . implode(",", array_keys($ret["nagios_debug_level"])) . "',  ";
+    } else {
+        $rq .= "'0', ";
+    }
+
+    if (isset($ret["debug_verbosity"]["debug_verbosity"]) && $ret["debug_verbosity"]["debug_verbosity"] != 2) {
+        $rq .= "'" . $ret["debug_verbosity"]["debug_verbosity"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["max_debug_file_size"]) && $ret["max_debug_file_size"] != null) {
+        $rq .= "'" . htmlentities($ret["max_debug_file_size"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["daemon_dumps_core"]["daemon_dumps_core"]) && $ret["daemon_dumps_core"]["daemon_dumps_core"]) {
+        $rq .= "'1', ";
+    } else {
+        $rq .= "'0', ";
+    }
+
+    if (isset($ret["enable_environment_macros"]["enable_environment_macros"]) &&
+        $ret["enable_environment_macros"]["enable_environment_macros"] != 2
+    ) {
+        $rq .= "'" . $ret["enable_environment_macros"]["enable_environment_macros"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["use_setpgid"]["use_setpgid"]) && $ret["use_setpgid"]["use_setpgid"] != 2) {
+        $rq .= "'" . $ret["use_setpgid"]["use_setpgid"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["use_regexp_matching"]["use_regexp_matching"]) &&
+        $ret["use_regexp_matching"]["use_regexp_matching"] != 2
+    ) {
+        $rq .= "'" . $ret["use_regexp_matching"]["use_regexp_matching"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["use_true_regexp_matching"]["use_true_regexp_matching"]) &&
+        $ret["use_true_regexp_matching"]["use_true_regexp_matching"] != 2
+    ) {
+        $rq .= "'" . $ret["use_true_regexp_matching"]["use_true_regexp_matching"] . "',  ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["admin_email"]) && $ret["admin_email"] != null) {
+        $rq .= "'" . htmlentities($ret["admin_email"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["admin_pager"]) && $ret["admin_pager"] != null) {
+        $rq .= "'" . htmlentities($ret["admin_pager"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["nagios_comment"]) && $ret["nagios_comment"] != null) {
+        $rq .= "'" . htmlentities($ret["nagios_comment"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["nagios_activate"]["nagios_activate"]) && $ret["nagios_activate"]["nagios_activate"] != null) {
+        $rq .= "'" . $ret["nagios_activate"]["nagios_activate"] . "',";
+    } else {
+        $rq .= "'0',";
+    }
+
+    if (isset($ret["event_broker_options"]) && $ret["event_broker_options"] != null) {
+        $rq .= "'" . htmlentities($ret["event_broker_options"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "'-1', ";
+    }
+
+    if (isset($ret["translate_passive_host_checks"]["translate_passive_host_checks"])
+        && $ret["translate_passive_host_checks"]["translate_passive_host_checks"] != 2
+    ) {
+        $rq .= "'" . $ret["translate_passive_host_checks"]["translate_passive_host_checks"] . "', ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"])
+        && $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] != 2
+    ) {
+        $rq .= "'" . $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] . "', ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"])
+        && $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] != 2
+    ) {
+        $rq .= "'" . $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] . "', ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["external_command_buffer_slots"]["external_command_buffer_slots"])
+        && $ret["external_command_buffer_slots"]["external_command_buffer_slots"] != 2
+    ) {
+        $rq .= "'" . $ret["external_command_buffer_slots"]["external_command_buffer_slots"] . "', ";
+    } else {
+        $rq .= "'2', ";
+    }
+
+    if (isset($ret["cfg_file"]) && $ret["cfg_file"] != null) {
+        $rq .= "'" . htmlentities($ret["cfg_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "NULL, ";
+    }
+
+    if (isset($ret["log_pid"]["log_pid"]) && $ret["log_pid"]["log_pid"]) {
+        $rq .= "'1', ";
+    } else {
+        $rq .= "'0', ";
+    }
+
+    if (isset($ret['use_check_result_path']['use_check_result_path'])
+        && $ret['use_check_result_path']['use_check_result_path']
+    ) {
+        $rq .= "'1')";
+    } else {
+        $rq .= "'0')";
+    }
 
     $DBRESULT = $pearDB->query($rq);
     $DBRESULT = $pearDB->query("SELECT MAX(nagios_id) FROM cfg_nagios");
@@ -611,537 +1135,946 @@ function insertNagios($ret = array(), $brokerTab = array())
     return ($nagios_id["MAX(nagios_id)"]);
 }
 
-function updateNagios($nagios_id = null)
-{
-    global $form, $pearDB, $centreon;
+function updateNagios($nagios_id = null)
+{
+    global $form, $pearDB, $centreon;
+
+    if (!$nagios_id) {
+        return;
+    }
+
+    if (isset($ret["nagios_server_id"])) {
+        $DBRESULT = $pearDB->query("UPDATE cfg_nagios SET `nagios_server_id` != '" . $ret["nagios_server_id"] . "'");
+    }
+
+    $ret = array();
+    $ret = $form->getSubmitValues();
+    $rq = "UPDATE cfg_nagios SET ";
+    if (isset($ret["nagios_name"]) && $ret["nagios_name"] != null) {
+        $rq .= "nagios_name = '" . htmlentities($ret["nagios_name"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "nagios_name = NULL, ";
+    }
+
+    if (isset($ret["nagios_server_id"]) && $ret["nagios_server_id"] != null) {
+        $rq .= "nagios_server_id = '" . htmlentities($ret["nagios_server_id"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "nagios_server_id = NULL, ";
+    }
+
+    if (isset($ret["use_timezone"]) && $ret["use_timezone"] != null) {
+        $rq .= "use_timezone = '" . htmlentities($ret["use_timezone"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "use_timezone = NULL, ";
+    }
+
+    if (isset($ret["log_file"]) && $ret["log_file"] != null) {
+        $rq .= "log_file = '" . htmlentities($ret["log_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "log_file = NULL, ";
+    }
+
+    if (isset($ret["cfg_dir"]) && $ret["cfg_dir"] != null) {
+        $rq .= "cfg_dir = '" . htmlentities($ret["cfg_dir"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "cfg_dir = NULL, ";
+    }
+
+    if (isset($ret["temp_file"]) && $ret["temp_file"] != null) {
+        $rq .= "temp_file = '" . htmlentities($ret["temp_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "temp_file = NULL, ";
+    }
+
+    if (isset($ret["check_result_path"]) && $ret["check_result_path"] != null) {
+        $rq .= "check_result_path = '" . htmlentities($ret["check_result_path"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "check_result_path = NULL, ";
+    }
+
+    if (isset($ret["max_check_result_file_age"]) && $ret["max_check_result_file_age"] != null) {
+        $rq .= "max_check_result_file_age = '"
+            . htmlentities($ret["max_check_result_file_age"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "max_check_result_file_age = NULL, ";
+    }
+
+    if (isset($ret["status_file"]) && $ret["status_file"] != null) {
+        $rq .= "status_file = '" . htmlentities($ret["status_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "status_file = NULL, ";
+    }
+
+    if (isset($ret["status_update_interval"]) && $ret["status_update_interval"] != null) {
+        $rq .= "status_update_interval = '" . (int)$ret["status_update_interval"] . "',  ";
+    } else {
+        $rq .= "status_update_interval = NULL, ";
+    }
+
+    if (isset($ret["nagios_user"]) && $ret["nagios_user"] != null) {
+        $rq .= "nagios_user = '" . htmlentities($ret["nagios_user"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "nagios_user = NULL, ";
+    }
+
+    if (isset($ret["nagios_group"]) && $ret["nagios_group"] != null) {
+        $rq .= "nagios_group = '" . htmlentities($ret["nagios_group"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "nagios_group = NULL, ";
+    }
+
+    if (isset($ret["enable_notifications"]["enable_notifications"])
+        && $ret["enable_notifications"]["enable_notifications"] != 2
+    ) {
+        $rq .= "enable_notifications = '" . $ret["enable_notifications"]["enable_notifications"] . "',  ";
+    } else {
+        $rq .= "enable_notifications = '2', ";
+    }
+
+    if (isset($ret["execute_service_checks"]["execute_service_checks"])
+        && $ret["execute_service_checks"]["execute_service_checks"] != 2
+    ) {
+        $rq .= "execute_service_checks = '" . $ret["execute_service_checks"]["execute_service_checks"] . "',  ";
+    } else {
+        $rq .= "execute_service_checks = '2', ";
+    }
+
+    if (isset($ret["accept_passive_service_checks"]["accept_passive_service_checks"])
+        && $ret["accept_passive_service_checks"]["accept_passive_service_checks"] != 2
+    ) {
+        $rq .= "accept_passive_service_checks = '"
+            . $ret["accept_passive_service_checks"]["accept_passive_service_checks"]
+            . "',  ";
+    } else {
+        $rq .= "accept_passive_service_checks = '2', ";
+    }
+
+    if (isset($ret["execute_host_checks"]["execute_host_checks"])
+        && $ret["execute_host_checks"]["execute_host_checks"] != 2
+    ) {
+        $rq .= "execute_host_checks = '" . $ret["execute_host_checks"]["execute_host_checks"] . "',  ";
+    } else {
+        $rq .= "execute_host_checks = '2', ";
+    }
+
+    if (isset($ret["accept_passive_host_checks"]["accept_passive_host_checks"])
+        && $ret["accept_passive_host_checks"]["accept_passive_host_checks"] != 2
+    ) {
+        $rq .= "accept_passive_host_checks = '"
+            . $ret["accept_passive_host_checks"]["accept_passive_host_checks"]
+            . "',  ";
+    } else {
+        $rq .= "accept_passive_host_checks = '2', ";
+    }
+
+    if (isset($ret["enable_event_handlers"]["enable_event_handlers"])
+        && $ret["enable_event_handlers"]["enable_event_handlers"] != 2
+    ) {
+        $rq .= "enable_event_handlers = '" . $ret["enable_event_handlers"]["enable_event_handlers"] . "',  ";
+    } else {
+        $rq .= "enable_event_handlers = '2', ";
+    }
+
+    if (isset($ret["log_rotation_method"]["log_rotation_method"])
+        && $ret["log_rotation_method"]["log_rotation_method"] != 2
+    ) {
+        $rq .= "log_rotation_method = '" . $ret["log_rotation_method"]["log_rotation_method"] . "',  ";
+    } else {
+        $rq .= "log_rotation_method = '2', ";
+    }
+
+    if (isset($ret["log_archive_path"]) && $ret["log_archive_path"] != null) {
+        $rq .= "log_archive_path = '" . htmlentities($ret["log_archive_path"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "log_archive_path = NULL, ";
+    }
+
+    if (isset($ret["check_external_commands"]["check_external_commands"])
+        && $ret["check_external_commands"]["check_external_commands"] != 2
+    ) {
+        $rq .= "check_external_commands = '" . $ret["check_external_commands"]["check_external_commands"] . "',  ";
+    } else {
+        $rq .= "check_external_commands = '2', ";
+    }
+
+    if (isset($ret["command_check_interval"]) && $ret["command_check_interval"] != null) {
+        $rq .= "command_check_interval = '"
+            . htmlentities($ret["command_check_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "command_check_interval = NULL, ";
+    }
+
+    if (isset($ret["command_file"]) && $ret["command_file"] != null) {
+        $rq .= "command_file = '" . htmlentities($ret["command_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "command_file = NULL, ";
+    }
+
+    if (isset($ret["downtime_file"]) && $ret["downtime_file"] != null) {
+        $rq .= "downtime_file = '" . htmlentities($ret["downtime_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "downtime_file = NULL, ";
+    }
+
+    if (isset($ret["comment_file"]) && $ret["comment_file"] != null) {
+        $rq .= "comment_file = '" . htmlentities($ret["comment_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "comment_file = NULL, ";
+    }
+
+    if (isset($ret["lock_file"]) && $ret["lock_file"] != null) {
+        $rq .= "lock_file = '" . htmlentities($ret["lock_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "lock_file = NULL, ";
+    }
+
+    if (isset($ret["retain_state_information"]["retain_state_information"])
+        && $ret["retain_state_information"]["retain_state_information"] != 2
+    ) {
+        $rq .= "retain_state_information = '" . $ret["retain_state_information"]["retain_state_information"] . "',  ";
+    } else {
+        $rq .= "retain_state_information = '2', ";
+    }
+
+    if (isset($ret["state_retention_file"]) && $ret["state_retention_file"] != null) {
+        $rq .= "state_retention_file = '" . htmlentities($ret["state_retention_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "state_retention_file = NULL, ";
+    }
+
+    if (isset($ret["retention_update_interval"]) && $ret["retention_update_interval"] != null) {
+        $rq .= "retention_update_interval = '"
+            . htmlentities($ret["retention_update_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retention_update_interval = NULL, ";
+    }
+
+    if (isset($ret["use_retained_program_state"]["use_retained_program_state"])
+        && $ret["use_retained_program_state"]["use_retained_program_state"] != 2
+    ) {
+        $rq .= "use_retained_program_state = '"
+            . $ret["use_retained_program_state"]["use_retained_program_state"]
+            . "',  ";
+    } else {
+        $rq .= "use_retained_program_state = '2', ";
+    }
+
+    if (isset($ret["use_retained_scheduling_info"]["use_retained_scheduling_info"])
+        && $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] != 2
+    ) {
+        $rq .= "use_retained_scheduling_info = '"
+            . $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"]
+            . "',  ";
+    } else {
+        $rq .= "use_retained_scheduling_info = '2', ";
+    }
+
+    if (isset($ret["retained_contact_host_attribute_mask"]) && $ret["retained_contact_host_attribute_mask"] != null) {
+        $rq .= "retained_contact_host_attribute_mask = '"
+            . htmlentities($ret["retained_contact_host_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_contact_host_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["retained_contact_service_attribute_mask"]) &&
+        $ret["retained_contact_service_attribute_mask"] != null
+    ) {
+        $rq .= "retained_contact_service_attribute_mask = '"
+            . htmlentities($ret["retained_contact_service_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_contact_service_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["retained_process_host_attribute_mask"]) && $ret["retained_process_host_attribute_mask"] != null) {
+        $rq .= "retained_process_host_attribute_mask = '"
+            . htmlentities($ret["retained_process_host_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_process_host_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["retained_process_service_attribute_mask"]) &&
+        $ret["retained_process_service_attribute_mask"] != null
+    ) {
+        $rq .= "retained_process_service_attribute_mask = '"
+            . htmlentities($ret["retained_process_service_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_process_service_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["retained_host_attribute_mask"]) && $ret["retained_host_attribute_mask"] != null) {
+        $rq .= "retained_host_attribute_mask = '"
+            . htmlentities($ret["retained_host_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_host_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["retained_service_attribute_mask"]) && $ret["retained_service_attribute_mask"] != null) {
+        $rq .= "retained_service_attribute_mask = '"
+            . htmlentities($ret["retained_service_attribute_mask"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "retained_service_attribute_mask = NULL, ";
+    }
+
+    if (isset($ret["use_syslog"]["use_syslog"]) && $ret["use_syslog"]["use_syslog"] != 2) {
+        $rq .= "use_syslog = '" . $ret["use_syslog"]["use_syslog"] . "',  ";
+    } else {
+        $rq .= "use_syslog = '2', ";
+    }
+
+    if (isset($ret["log_notifications"]["log_notifications"]) && $ret["log_notifications"]["log_notifications"] != 2) {
+        $rq .= "log_notifications = '" . $ret["log_notifications"]["log_notifications"] . "',  ";
+    } else {
+        $rq .= "log_notifications = '2', ";
+    }
+
+    if (isset($ret["log_service_retries"]["log_service_retries"]) &&
+        $ret["log_service_retries"]["log_service_retries"] != 2
+    ) {
+        $rq .= "log_service_retries = '" . $ret["log_service_retries"]["log_service_retries"] . "',  ";
+    } else {
+        $rq .= "log_service_retries = '2', ";
+    }
+
+    if (isset($ret["log_host_retries"]["log_host_retries"]) && $ret["log_host_retries"]["log_host_retries"] != 2) {
+        $rq .= "log_host_retries = '" . $ret["log_host_retries"]["log_host_retries"] . "',  ";
+    } else {
+        $rq .= "log_host_retries = '2', ";
+    }
+
+    if (isset($ret["log_event_handlers"]["log_event_handlers"]) &&
+        $ret["log_event_handlers"]["log_event_handlers"] != 2
+    ) {
+        $rq .= "log_event_handlers = '" . $ret["log_event_handlers"]["log_event_handlers"] . "',  ";
+    } else {
+        $rq .= "log_event_handlers = '2', ";
+    }
+
+    if (isset($ret["log_external_commands"]["log_external_commands"]) &&
+        $ret["log_external_commands"]["log_external_commands"] != 2
+    ) {
+        $rq .= "log_external_commands = '" . $ret["log_external_commands"]["log_external_commands"] . "',  ";
+    } else {
+        $rq .= "log_external_commands = '2', ";
+    }
+
+    if (isset($ret["log_passive_checks"]["log_passive_checks"]) &&
+        $ret["log_passive_checks"]["log_passive_checks"] != 2
+    ) {
+        $rq .= "log_passive_checks = '" . $ret["log_passive_checks"]["log_passive_checks"] . "',  ";
+    } else {
+        $rq .= "log_passive_checks = '2', ";
+    }
+
+    if (isset($ret["global_host_event_handler"]) && $ret["global_host_event_handler"] != null) {
+        $rq .= "global_host_event_handler = '" . $ret["global_host_event_handler"] . "',  ";
+    } else {
+        $rq .= "global_host_event_handler = NULL, ";
+    }
 
-    if (!$nagios_id) {
-        return;
+    if (isset($ret["global_service_event_handler"]) && $ret["global_service_event_handler"] != null) {
+        $rq .= "global_service_event_handler = '" . $ret["global_service_event_handler"] . "',  ";
+    } else {
+        $rq .= "global_service_event_handler = NULL, ";
     }
 
-    if (isset($ret["nagios_server_id"])) {
-        $DBRESULT = $pearDB->query("UPDATE cfg_nagios SET `nagios_server_id` != '" . $ret["nagios_server_id"] . "'");
+    if (isset($ret["sleep_time"]) && $ret["sleep_time"] != null) {
+        $rq .= "sleep_time = '" . htmlentities($ret["sleep_time"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "sleep_time = NULL, ";
     }
 
-    $ret = array();
-    $ret = $form->getSubmitValues();
-    $rq = "UPDATE cfg_nagios SET ";
-    isset($ret["nagios_name"]) && $ret["nagios_name"] != null ?
-        $rq .= "nagios_name = '" . htmlentities($ret["nagios_name"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "nagios_name = NULL, ";
-    isset($ret["nagios_server_id"]) && $ret["nagios_server_id"] != null ?
-        $rq .= "nagios_server_id = '" . htmlentities($ret["nagios_server_id"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "nagios_server_id = NULL, ";
-    isset($ret["use_timezone"]) && $ret["use_timezone"] != null ?
-        $rq .= "use_timezone = '" . htmlentities($ret["use_timezone"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "use_timezone = NULL, ";
-    isset($ret["log_file"]) && $ret["log_file"] != null ?
-        $rq .= "log_file = '" . htmlentities($ret["log_file"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "log_file = NULL, ";
-    isset($ret["cfg_dir"]) && $ret["cfg_dir"] != null ?
-        $rq .= "cfg_dir = '" . htmlentities($ret["cfg_dir"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "cfg_dir = NULL, ";
-    isset($ret["temp_file"]) && $ret["temp_file"] != null ?
-        $rq .= "temp_file = '" . htmlentities($ret["temp_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "temp_file = NULL, ";
-    isset($ret["check_result_path"]) && $ret["check_result_path"] != null ?
-        $rq .= "check_result_path = '" . htmlentities($ret["check_result_path"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "check_result_path = NULL, ";
-    isset($ret["max_check_result_file_age"]) && $ret["max_check_result_file_age"] != null ?
-        $rq .= "max_check_result_file_age = '"
-            . htmlentities($ret["max_check_result_file_age"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_check_result_file_age = NULL, ";
-    isset($ret["status_file"]) && $ret["status_file"] != null ?
-        $rq .= "status_file = '" . htmlentities($ret["status_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "status_file = NULL, ";
-    isset($ret["status_update_interval"]) && $ret["status_update_interval"] != null ?
-        $rq .= "status_update_interval = '" . (int)$ret["status_update_interval"] . "',  "
-        : $rq .= "status_update_interval = NULL, ";
-    isset($ret["nagios_user"]) && $ret["nagios_user"] != null ?
-        $rq .= "nagios_user = '" . htmlentities($ret["nagios_user"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "nagios_user = NULL, ";
-    isset($ret["nagios_group"]) && $ret["nagios_group"] != null ?
-        $rq .= "nagios_group = '" . htmlentities($ret["nagios_group"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "nagios_group = NULL, ";
-    isset($ret["enable_notifications"]["enable_notifications"])
-    && $ret["enable_notifications"]["enable_notifications"] != 2 ?
-        $rq .= "enable_notifications = '"
-            . $ret["enable_notifications"]["enable_notifications"] . "',  "
-        : $rq .= "enable_notifications = '2', ";
-    isset($ret["execute_service_checks"]["execute_service_checks"])
-    && $ret["execute_service_checks"]["execute_service_checks"] != 2 ?
-        $rq .= "execute_service_checks = '"
-            . $ret["execute_service_checks"]["execute_service_checks"] . "',  "
-        : $rq .= "execute_service_checks = '2', ";
-    isset($ret["accept_passive_service_checks"]["accept_passive_service_checks"])
-    && $ret["accept_passive_service_checks"]["accept_passive_service_checks"] != 2 ?
-        $rq .= "accept_passive_service_checks = '"
-            . $ret["accept_passive_service_checks"]["accept_passive_service_checks"] . "',  "
-        : $rq .= "accept_passive_service_checks = '2', ";
-    isset($ret["execute_host_checks"]["execute_host_checks"])
-    && $ret["execute_host_checks"]["execute_host_checks"] != 2 ?
-        $rq .= "execute_host_checks = '" . $ret["execute_host_checks"]["execute_host_checks"] . "',  "
-        : $rq .= "execute_host_checks = '2', ";
-    isset($ret["accept_passive_host_checks"]["accept_passive_host_checks"])
-    && $ret["accept_passive_host_checks"]["accept_passive_host_checks"] != 2 ?
-        $rq .= "accept_passive_host_checks = '"
-            . $ret["accept_passive_host_checks"]["accept_passive_host_checks"] . "',  "
-        : $rq .= "accept_passive_host_checks = '2', ";
-    isset($ret["enable_event_handlers"]["enable_event_handlers"])
-    && $ret["enable_event_handlers"]["enable_event_handlers"] != 2 ?
-        $rq .= "enable_event_handlers = '"
-            . $ret["enable_event_handlers"]["enable_event_handlers"] . "',  "
-        : $rq .= "enable_event_handlers = '2', ";
-    isset($ret["log_rotation_method"]["log_rotation_method"])
-    && $ret["log_rotation_method"]["log_rotation_method"] != 2 ?
-        $rq .= "log_rotation_method = '"
-            . $ret["log_rotation_method"]["log_rotation_method"] . "',  "
-        : $rq .= "log_rotation_method = '2', ";
-    isset($ret["log_archive_path"]) && $ret["log_archive_path"] != null ?
-        $rq .= "log_archive_path = '"
-            . htmlentities($ret["log_archive_path"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "log_archive_path = NULL, ";
-    isset($ret["check_external_commands"]["check_external_commands"])
-    && $ret["check_external_commands"]["check_external_commands"] != 2 ?
-        $rq .= "check_external_commands = '"
-            . $ret["check_external_commands"]["check_external_commands"] . "',  "
-        : $rq .= "check_external_commands = '2', ";
-    isset($ret["command_check_interval"]) && $ret["command_check_interval"] != null ?
-        $rq .= "command_check_interval = '"
-            . htmlentities($ret["command_check_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "command_check_interval = NULL, ";
-    isset($ret["command_file"]) && $ret["command_file"] != null ?
-        $rq .= "command_file = '" . htmlentities($ret["command_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "command_file = NULL, ";
-    isset($ret["downtime_file"]) && $ret["downtime_file"] != null ?
-        $rq .= "downtime_file = '" . htmlentities($ret["downtime_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "downtime_file = NULL, ";
-    isset($ret["comment_file"]) && $ret["comment_file"] != null ?
-        $rq .= "comment_file = '" . htmlentities($ret["comment_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "comment_file = NULL, ";
-    isset($ret["lock_file"]) && $ret["lock_file"] != null ?
-        $rq .= "lock_file = '" . htmlentities($ret["lock_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "lock_file = NULL, ";
-    isset($ret["retain_state_information"]["retain_state_information"])
-    && $ret["retain_state_information"]["retain_state_information"] != 2 ?
-        $rq .= "retain_state_information = '"
-            . $ret["retain_state_information"]["retain_state_information"] . "',  "
-        : $rq .= "retain_state_information = '2', ";
-    isset($ret["state_retention_file"]) && $ret["state_retention_file"] != null ?
-        $rq .= "state_retention_file = '"
-            . htmlentities($ret["state_retention_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "state_retention_file = NULL, ";
-    isset($ret["retention_update_interval"]) && $ret["retention_update_interval"] != null ?
-        $rq .= "retention_update_interval = '"
-            . htmlentities($ret["retention_update_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retention_update_interval = NULL, ";
-    isset($ret["use_retained_program_state"]["use_retained_program_state"])
-    && $ret["use_retained_program_state"]["use_retained_program_state"] != 2 ?
-        $rq .= "use_retained_program_state = '"
-            . $ret["use_retained_program_state"]["use_retained_program_state"] . "',  "
-        : $rq .= "use_retained_program_state = '2', ";
-    isset($ret["use_retained_scheduling_info"]["use_retained_scheduling_info"])
-    && $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] != 2 ?
-        $rq .= "use_retained_scheduling_info = '"
-            . $ret["use_retained_scheduling_info"]["use_retained_scheduling_info"] . "',  "
-        : $rq .= "use_retained_scheduling_info = '2', ";
-    isset($ret["retained_contact_host_attribute_mask"])
-    && $ret["retained_contact_host_attribute_mask"] != null ?
-        $rq .= "retained_contact_host_attribute_mask = '"
-            . htmlentities($ret["retained_contact_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_contact_host_attribute_mask = NULL, ";
-    isset($ret["retained_contact_service_attribute_mask"])
-    && $ret["retained_contact_service_attribute_mask"] != null ?
-        $rq .= "retained_contact_service_attribute_mask = '"
-            . htmlentities($ret["retained_contact_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_contact_service_attribute_mask = NULL, ";
-    isset($ret["retained_process_host_attribute_mask"])
-    && $ret["retained_process_host_attribute_mask"] != null ?
-        $rq .= "retained_process_host_attribute_mask = '"
-            . htmlentities($ret["retained_process_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_process_host_attribute_mask = NULL, ";
-    isset($ret["retained_process_service_attribute_mask"])
-    && $ret["retained_process_service_attribute_mask"] != null ?
-        $rq .= "retained_process_service_attribute_mask = '"
-            . htmlentities($ret["retained_process_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_process_service_attribute_mask = NULL, ";
-    isset($ret["retained_host_attribute_mask"]) && $ret["retained_host_attribute_mask"] != null ?
-        $rq .= "retained_host_attribute_mask = '"
-            . htmlentities($ret["retained_host_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_host_attribute_mask = NULL, ";
-    isset($ret["retained_service_attribute_mask"])
-    && $ret["retained_service_attribute_mask"] != null ?
-        $rq .= "retained_service_attribute_mask = '"
-            . htmlentities($ret["retained_service_attribute_mask"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "retained_service_attribute_mask = NULL, ";
-    isset($ret["use_syslog"]["use_syslog"]) && $ret["use_syslog"]["use_syslog"] != 2 ?
-        $rq .= "use_syslog = '" . $ret["use_syslog"]["use_syslog"] . "',  "
-        : $rq .= "use_syslog = '2', ";
-    isset($ret["log_notifications"]["log_notifications"])
-    && $ret["log_notifications"]["log_notifications"] != 2 ?
-        $rq .= "log_notifications = '" . $ret["log_notifications"]["log_notifications"] . "',  "
-        : $rq .= "log_notifications = '2', ";
-    isset($ret["log_service_retries"]["log_service_retries"])
-    && $ret["log_service_retries"]["log_service_retries"] != 2 ?
-        $rq .= "log_service_retries = '"
-            . $ret["log_service_retries"]["log_service_retries"] . "',  "
-        : $rq .= "log_service_retries = '2', ";
-    isset($ret["log_host_retries"]["log_host_retries"])
-    && $ret["log_host_retries"]["log_host_retries"] != 2 ?
-        $rq .= "log_host_retries = '" . $ret["log_host_retries"]["log_host_retries"] . "',  "
-        : $rq .= "log_host_retries = '2', ";
-    isset($ret["log_event_handlers"]["log_event_handlers"])
-    && $ret["log_event_handlers"]["log_event_handlers"] != 2 ?
-        $rq .= "log_event_handlers = '" . $ret["log_event_handlers"]["log_event_handlers"] . "',  "
-        : $rq .= "log_event_handlers = '2', ";
-    isset($ret["log_external_commands"]["log_external_commands"])
-    && $ret["log_external_commands"]["log_external_commands"] != 2 ?
-        $rq .= "log_external_commands = '" . $ret["log_external_commands"]["log_external_commands"] . "',  "
-        : $rq .= "log_external_commands = '2', ";
-    isset($ret["log_passive_checks"]["log_passive_checks"])
-    && $ret["log_passive_checks"]["log_passive_checks"] != 2 ?
-        $rq .= "log_passive_checks = '" . $ret["log_passive_checks"]["log_passive_checks"] . "',  "
-        : $rq .= "log_passive_checks = '2', ";
-    isset($ret["global_host_event_handler"]) && $ret["global_host_event_handler"] != null ?
-        $rq .= "global_host_event_handler = '" . $ret["global_host_event_handler"] . "',  "
-        : $rq .= "global_host_event_handler = NULL, ";
-    isset($ret["global_service_event_handler"]) && $ret["global_service_event_handler"] != null ?
-        $rq .= "global_service_event_handler = '" . $ret["global_service_event_handler"] . "',  "
-        : $rq .= "global_service_event_handler = NULL, ";
-    isset($ret["sleep_time"]) && $ret["sleep_time"] != null ?
-        $rq .= "sleep_time = '" . htmlentities($ret["sleep_time"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "sleep_time = NULL, ";
-    isset($ret["service_inter_check_delay_method"])
-    && $ret["service_inter_check_delay_method"] != null ?
-        $rq .= "service_inter_check_delay_method = '" . $ret["service_inter_check_delay_method"] . "',  "
-        : $rq .= "service_inter_check_delay_method = NULL, ";
-    isset($ret["max_service_check_spread"]) && $ret["max_service_check_spread"] != null ?
+    if (isset($ret["service_inter_check_delay_method"]) && $ret["service_inter_check_delay_method"] != null) {
+        $rq .= "service_inter_check_delay_method = '" . $ret["service_inter_check_delay_method"] . "',  ";
+    } else {
+        $rq .= "service_inter_check_delay_method = NULL, ";
+    }
+
+    if (isset($ret["max_service_check_spread"]) && $ret["max_service_check_spread"] != null) {
         $rq .= "max_service_check_spread = '"
-            . htmlentities($ret["max_service_check_spread"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_service_check_spread = NULL, ";
-    isset($ret["service_interleave_factor"]["service_interleave_factor"])
-    && $ret["service_interleave_factor"]["service_interleave_factor"] != 2 ?
+            . htmlentities($ret["max_service_check_spread"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "max_service_check_spread = NULL, ";
+    }
+
+    if (isset($ret["service_interleave_factor"]["service_interleave_factor"]) &&
+        $ret["service_interleave_factor"]["service_interleave_factor"] != 2
+    ) {
         $rq .= "service_interleave_factor = '"
-            . $ret["service_interleave_factor"]["service_interleave_factor"] . "',  "
-        : $rq .= "service_interleave_factor = '2', ";
-    isset($ret["max_concurrent_checks"]) && $ret["max_concurrent_checks"] != null ?
-        $rq .= "max_concurrent_checks = '"
-            . htmlentities($ret["max_concurrent_checks"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_concurrent_checks = NULL, ";
-    isset($ret["check_result_reaper_frequency"]) && $ret["check_result_reaper_frequency"] != null ?
+            . $ret["service_interleave_factor"]["service_interleave_factor"]
+            . "',  ";
+    } else {
+        $rq .= "service_interleave_factor = '2', ";
+    }
+
+    if (isset($ret["max_concurrent_checks"]) && $ret["max_concurrent_checks"] != null) {
+        $rq .= "max_concurrent_checks = '" . htmlentities($ret["max_concurrent_checks"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "max_concurrent_checks = NULL, ";
+    }
+
+    if (isset($ret["check_result_reaper_frequency"]) && $ret["check_result_reaper_frequency"] != null) {
         $rq .= "check_result_reaper_frequency = '"
-            . htmlentities($ret["check_result_reaper_frequency"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "check_result_reaper_frequency = NULL, ";
-    isset($ret["max_check_result_reaper_time"]) && $ret["max_check_result_reaper_time"] != null ?
+            . htmlentities($ret["check_result_reaper_frequency"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "check_result_reaper_frequency = NULL, ";
+    }
+
+    if (isset($ret["max_check_result_reaper_time"]) && $ret["max_check_result_reaper_time"] != null) {
         $rq .= "max_check_result_reaper_time = '"
-            . htmlentities($ret["max_check_result_reaper_time"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_check_result_reaper_time = NULL, ";
-    isset($ret["host_inter_check_delay_method"]) && $ret["host_inter_check_delay_method"] != null ?
-        $rq .= "host_inter_check_delay_method  = '" . $ret["host_inter_check_delay_method"] . "',  "
-        : $rq .= "host_inter_check_delay_method  = NULL, ";
-    isset($ret["max_host_check_spread"]) && $ret["max_host_check_spread"] != null ?
+            . htmlentities($ret["max_check_result_reaper_time"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "max_check_result_reaper_time = NULL, ";
+    }
+
+    if (isset($ret["host_inter_check_delay_method"]) && $ret["host_inter_check_delay_method"] != null) {
+        $rq .= "host_inter_check_delay_method  = '" . $ret["host_inter_check_delay_method"] . "',  ";
+    } else {
+        $rq .= "host_inter_check_delay_method  = NULL, ";
+    }
+
+    if (isset($ret["max_host_check_spread"]) && $ret["max_host_check_spread"] != null) {
         $rq .= "max_host_check_spread = '"
-            . htmlentities($ret["max_host_check_spread"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_host_check_spread = NULL, ";
-    isset($ret["auto_reschedule_checks"]["auto_reschedule_checks"])
-    && $ret["auto_reschedule_checks"]["auto_reschedule_checks"] != 2 ?
-        $rq .= "auto_reschedule_checks = '" . $ret["auto_reschedule_checks"]["auto_reschedule_checks"] . "', "
-        : $rq .= "auto_reschedule_checks = '2', ";
-    isset($ret["auto_rescheduling_interval"]) && $ret["auto_rescheduling_interval"] != null ?
+            . htmlentities($ret["max_host_check_spread"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "max_host_check_spread = NULL, ";
+    }
+
+    if (isset($ret["auto_reschedule_checks"]["auto_reschedule_checks"]) &&
+        $ret["auto_reschedule_checks"]["auto_reschedule_checks"] != 2
+    ) {
+        $rq .= "auto_reschedule_checks = '" . $ret["auto_reschedule_checks"]["auto_reschedule_checks"] . "',  ";
+    } else {
+        $rq .= "auto_reschedule_checks = '2', ";
+    }
+
+    if (isset($ret["auto_rescheduling_interval"]) && $ret["auto_rescheduling_interval"] != null) {
         $rq .= "auto_rescheduling_interval = '"
-            . htmlentities($ret["auto_rescheduling_interval"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "auto_rescheduling_interval = NULL, ";
-    isset($ret["auto_rescheduling_window"]) && $ret["auto_rescheduling_window"] != null ?
+            . htmlentities($ret["auto_rescheduling_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "auto_rescheduling_interval = NULL, ";
+    }
+
+    if (isset($ret["auto_rescheduling_window"]) && $ret["auto_rescheduling_window"] != null) {
         $rq .= "auto_rescheduling_window = '"
-            . htmlentities($ret["auto_rescheduling_window"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "auto_rescheduling_window = NULL, ";
-    isset($ret["use_aggressive_host_checking"]["use_aggressive_host_checking"])
-    && $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] != 2 ?
-        $rq .= "use_aggressive_host_checking   = '"
-            . $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] . "',  "
-        : $rq .= "use_aggressive_host_checking   = '2', ";
-    isset($ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"])
-    && $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] != 2 ?
-        $rq .= "enable_predictive_host_dependency_checks   = '"
-            . $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] . "',  "
-        : $rq .= "enable_predictive_host_dependency_checks   = '2', ";
-    isset($ret["enable_flap_detection"]["enable_flap_detection"])
-    && $ret["enable_flap_detection"]["enable_flap_detection"] != 2 ?
-        $rq .= "enable_flap_detection = '" . $ret["enable_flap_detection"]["enable_flap_detection"] . "',  "
-        : $rq .= "enable_flap_detection = '2', ";
-    isset($ret["low_service_flap_threshold"]) && $ret["low_service_flap_threshold"] != null ?
+            . htmlentities($ret["auto_rescheduling_window"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "auto_rescheduling_window = NULL, ";
+    }
+
+    if (isset($ret["use_aggressive_host_checking"]["use_aggressive_host_checking"]) &&
+        $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"] != 2
+    ) {
+        $rq .= "use_aggressive_host_checking = '"
+            . $ret["use_aggressive_host_checking"]["use_aggressive_host_checking"]
+            . "',  ";
+    } else {
+        $rq .= "use_aggressive_host_checking = '2', ";
+    }
+
+    if (isset($ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"]) &&
+        $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"] != 2
+    ) {
+        $rq .= "enable_predictive_host_dependency_checks = '"
+            . $ret["enable_predictive_host_dependency_checks"]["enable_predictive_host_dependency_checks"]
+            . "',  ";
+    } else {
+        $rq .= "enable_predictive_host_dependency_checks = '2', ";
+    }
+
+    if (isset($ret["enable_flap_detection"]["enable_flap_detection"]) &&
+        $ret["enable_flap_detection"]["enable_flap_detection"] != 2
+    ) {
+        $rq .= "enable_flap_detection = '" . $ret["enable_flap_detection"]["enable_flap_detection"] . "',  ";
+    } else {
+        $rq .= "enable_flap_detection = '2', ";
+    }
+
+    if (isset($ret["low_service_flap_threshold"]) && $ret["low_service_flap_threshold"] != null) {
         $rq .= "low_service_flap_threshold = '"
-            . htmlentities($ret["low_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "low_service_flap_threshold = NULL, ";
-    isset($ret["high_service_flap_threshold"]) && $ret["high_service_flap_threshold"] != null ?
+            . htmlentities($ret["low_service_flap_threshold"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "low_service_flap_threshold = NULL, ";
+    }
+
+    if (isset($ret["high_service_flap_threshold"]) && $ret["high_service_flap_threshold"] != null) {
         $rq .= "high_service_flap_threshold = '"
-            . htmlentities($ret["high_service_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "high_service_flap_threshold = NULL, ";
-    isset($ret["low_host_flap_threshold"]) && $ret["low_host_flap_threshold"] != null ?
+            . htmlentities($ret["high_service_flap_threshold"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "high_service_flap_threshold = NULL, ";
+    }
+
+    if (isset($ret["low_host_flap_threshold"]) && $ret["low_host_flap_threshold"] != null) {
         $rq .= "low_host_flap_threshold = '"
-            . htmlentities($ret["low_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "low_host_flap_threshold = NULL, ";
-    isset($ret["high_host_flap_threshold"]) && $ret["high_host_flap_threshold"] != null ?
+            . htmlentities($ret["low_host_flap_threshold"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "low_host_flap_threshold = NULL, ";
+    }
+
+    if (isset($ret["high_host_flap_threshold"]) && $ret["high_host_flap_threshold"] != null) {
         $rq .= "high_host_flap_threshold = '"
-            . htmlentities($ret["high_host_flap_threshold"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "high_host_flap_threshold = NULL, ";
-    isset($ret["soft_state_dependencies"]["soft_state_dependencies"])
-    && $ret["soft_state_dependencies"]["soft_state_dependencies"] != 2 ?
-        $rq .= "soft_state_dependencies   = '" . $ret["soft_state_dependencies"]["soft_state_dependencies"] . "',  "
-        : $rq .= "soft_state_dependencies   = '2', ";
-    isset($ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"])
-    && $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] != 2 ?
-        $rq .= "enable_predictive_service_dependency_checks   = '"
-            . $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] .
-            "',  " : $rq .= "enable_predictive_service_dependency_checks   = '2', ";
-    isset($ret["service_check_timeout"]) && $ret["service_check_timeout"] != null ?
-        $rq .= "service_check_timeout = '"
-            . htmlentities($ret["service_check_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_check_timeout = NULL, ";
-    isset($ret["host_check_timeout"]) && $ret["host_check_timeout"] != null ?
-        $rq .= "host_check_timeout = '"
-            . htmlentities($ret["host_check_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "host_check_timeout = NULL, ";
-    isset($ret["event_handler_timeout"]) && $ret["event_handler_timeout"] != null ?
-        $rq .= "event_handler_timeout = '"
-            . htmlentities($ret["event_handler_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "event_handler_timeout = NULL, ";
-    isset($ret["notification_timeout"]) && $ret["notification_timeout"] != null ?
-        $rq .= "notification_timeout = '"
-            . htmlentities($ret["notification_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "notification_timeout = NULL, ";
-    isset($ret["ocsp_timeout"]) && $ret["ocsp_timeout"] != null ?
-        $rq .= "ocsp_timeout = '"
-            . htmlentities($ret["ocsp_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "ocsp_timeout = NULL, ";
-    isset($ret["ochp_timeout"]) && $ret["ochp_timeout"] != null ?
-        $rq .= "ochp_timeout = '"
-            . htmlentities($ret["ochp_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "ochp_timeout = NULL, ";
-    isset($ret["perfdata_timeout"]) && $ret["perfdata_timeout"] != null ?
-        $rq .= "perfdata_timeout = '"
-            . htmlentities($ret["perfdata_timeout"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "perfdata_timeout = NULL, ";
-    isset($ret["obsess_over_services"]["obsess_over_services"])
-    && $ret["obsess_over_services"]["obsess_over_services"] != 2 ?
-        $rq .= "obsess_over_services  = '"
-            . $ret["obsess_over_services"]["obsess_over_services"] . "',  "
-        : $rq .= "obsess_over_services  = '2', ";
-    isset($ret["ocsp_command"]) && $ret["ocsp_command"] != null ?
-        $rq .= "ocsp_command = '"
-            . htmlentities($ret["ocsp_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "ocsp_command = NULL, ";
-    isset($ret["obsess_over_hosts"]["obsess_over_hosts"])
-    && $ret["obsess_over_hosts"]["obsess_over_hosts"] != 2 ?
-        $rq .= "obsess_over_hosts = '" . $ret["obsess_over_hosts"]["obsess_over_hosts"] . "',  "
-        : $rq .= "obsess_over_hosts = '2', ";
-    isset($ret["ochp_command"]) && $ret["ochp_command"] != null ?
-        $rq .= "ochp_command  = '"
-            . htmlentities($ret["ochp_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "ochp_command  = NULL, ";
-    isset($ret["process_performance_data"]["process_performance_data"])
-    && $ret["process_performance_data"]["process_performance_data"] != 2 ?
-        $rq .= "process_performance_data   = '"
-            . $ret["process_performance_data"]["process_performance_data"] . "',  "
-        : $rq .= "process_performance_data   = '2', ";
-    isset($ret["host_perfdata_command"]) && $ret["host_perfdata_command"] != null ?
-        $rq .= "host_perfdata_command = '"
-            . htmlentities($ret["host_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "host_perfdata_command = NULL, ";
-    isset($ret["service_perfdata_command"]) && $ret["service_perfdata_command"] != null ?
+            . htmlentities($ret["high_host_flap_threshold"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "high_host_flap_threshold = NULL, ";
+    }
+
+    if (isset($ret["soft_state_dependencies"]["soft_state_dependencies"]) &&
+        $ret["soft_state_dependencies"]["soft_state_dependencies"] != 2
+    ) {
+        $rq .= "soft_state_dependencies = '" . $ret["soft_state_dependencies"]["soft_state_dependencies"] . "',  ";
+    } else {
+        $rq .= "soft_state_dependencies = '2', ";
+    }
+
+    if (isset($ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"]) &&
+        $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"] != 2
+    ) {
+        $rq .= "enable_predictive_service_dependency_checks = '"
+            . $ret["enable_predictive_service_dependency_checks"]["enable_predictive_service_dependency_checks"]
+            . "',  ";
+    } else {
+        $rq .= "enable_predictive_service_dependency_checks = '2', ";
+    }
+
+    if (isset($ret["service_check_timeout"]) && $ret["service_check_timeout"] != null) {
+        $rq .= "service_check_timeout = '" . htmlentities($ret["service_check_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "service_check_timeout = NULL, ";
+    }
+
+    if (isset($ret["host_check_timeout"]) && $ret["host_check_timeout"] != null) {
+        $rq .= "host_check_timeout = '" . htmlentities($ret["host_check_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "host_check_timeout = NULL, ";
+    }
+
+    if (isset($ret["event_handler_timeout"]) && $ret["event_handler_timeout"] != null) {
+        $rq .= "event_handler_timeout = '" . htmlentities($ret["event_handler_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "event_handler_timeout = NULL, ";
+    }
+
+    if (isset($ret["notification_timeout"]) && $ret["notification_timeout"] != null) {
+        $rq .= "notification_timeout = '" . htmlentities($ret["notification_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "notification_timeout = NULL, ";
+    }
+
+    if (isset($ret["ocsp_timeout"]) && $ret["ocsp_timeout"] != null) {
+        $rq .= "ocsp_timeout = '" . htmlentities($ret["ocsp_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "ocsp_timeout = NULL, ";
+    }
+
+    if (isset($ret["ochp_timeout"]) && $ret["ochp_timeout"] != null) {
+        $rq .= "ochp_timeout = '" . htmlentities($ret["ochp_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "ochp_timeout = NULL, ";
+    }
+
+    if (isset($ret["perfdata_timeout"]) && $ret["perfdata_timeout"] != null) {
+        $rq .= "perfdata_timeout = '" . htmlentities($ret["perfdata_timeout"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "perfdata_timeout = NULL, ";
+    }
+
+    if (isset($ret["obsess_over_services"]["obsess_over_services"]) &&
+        $ret["obsess_over_services"]["obsess_over_services"] != 2
+    ) {
+        $rq .= "obsess_over_services = '" . $ret["obsess_over_services"]["obsess_over_services"] . "',  ";
+    } else {
+        $rq .= "obsess_over_services = '2', ";
+    }
+
+    if (isset($ret["ocsp_command"]) && $ret["ocsp_command"] != null) {
+        $rq .= "ocsp_command = '" . htmlentities($ret["ocsp_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "ocsp_command = NULL, ";
+    }
+
+    if (isset($ret["obsess_over_hosts"]["obsess_over_hosts"]) && $ret["obsess_over_hosts"]["obsess_over_hosts"] != 2
+    ) {
+        $rq .= "obsess_over_hosts = '" . $ret["obsess_over_hosts"]["obsess_over_hosts"] . "',  ";
+    } else {
+        $rq .= "obsess_over_hosts = '2', ";
+    }
+
+    if (isset($ret["ochp_command"]) && $ret["ochp_command"] != null) {
+        $rq .= "ochp_command = '" . htmlentities($ret["ochp_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "ochp_command = NULL, ";
+    }
+
+    if (isset($ret["process_performance_data"]["process_performance_data"]) &&
+        $ret["process_performance_data"]["process_performance_data"] != 2
+    ) {
+        $rq .= "process_performance_data = '" . $ret["process_performance_data"]["process_performance_data"] . "',  ";
+    } else {
+        $rq .= "process_performance_data = '2', ";
+    }
+
+    if (isset($ret["host_perfdata_command"]) && $ret["host_perfdata_command"] != null) {
+        $rq .= "host_perfdata_command = '" . htmlentities($ret["host_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "host_perfdata_command = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_command"]) && $ret["service_perfdata_command"] != null) {
         $rq .= "service_perfdata_command = '"
-            . htmlentities($ret["service_perfdata_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_perfdata_command = NULL, ";
-    isset($ret["host_perfdata_file"]) && $ret["host_perfdata_file"] != null ?
-        $rq .= "host_perfdata_file = '"
-            . htmlentities($ret["host_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "host_perfdata_file = NULL, ";
-    isset($ret["service_perfdata_file"]) && $ret["service_perfdata_file"] != null ?
-        $rq .= "service_perfdata_file = '"
-            . htmlentities($ret["service_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_perfdata_file = NULL, ";
-    isset($ret["host_perfdata_file_template"]) && $ret["host_perfdata_file_template"] != null ?
-        $rq .= "host_perfdata_file_template = '"
-            . $pearDB->quote($ret["host_perfdata_file_template"]) . "',  "
-        : $rq .= "host_perfdata_file_template = NULL, ";
-    isset($ret["service_perfdata_file_template"]) && $ret["service_perfdata_file_template"] != null ?
-        $rq .= "service_perfdata_file_template = '"
-            . $pearDB->quote($ret["service_perfdata_file_template"]) . "',  "
-        : $rq .= "service_perfdata_file_template = NULL, ";
-    isset($ret["host_perfdata_file_mode"]["host_perfdata_file_mode"])
-    && $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] != null ?
-        $rq .= "host_perfdata_file_mode  = '"
-            . $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] . "',  "
-        : $rq .= "host_perfdata_file_mode  = NULL, ";
-    isset($ret["service_perfdata_file_mode"]["service_perfdata_file_mode"])
-    && $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] != null ?
+            . htmlentities($ret["service_perfdata_command"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "service_perfdata_command = NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file"]) && $ret["host_perfdata_file"] != null) {
+        $rq .= "host_perfdata_file = '" . htmlentities($ret["host_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "host_perfdata_file = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file"]) && $ret["service_perfdata_file"] != null) {
+        $rq .= "service_perfdata_file = '" . htmlentities($ret["service_perfdata_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "service_perfdata_file = NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_template"]) && $ret["host_perfdata_file_template"] != null) {
+        $rq .= "host_perfdata_file_template = '" . $pearDB->quote($ret["host_perfdata_file_template"]) . "',  ";
+    } else {
+        $rq .= "host_perfdata_file_template = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_template"]) && $ret["service_perfdata_file_template"] != null) {
+        $rq .= "service_perfdata_file_template = '" . $pearDB->quote($ret["service_perfdata_file_template"]) . "',  ";
+    } else {
+        $rq .= "service_perfdata_file_template = NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_mode"]["host_perfdata_file_mode"])
+        && $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] != null
+    ) {
+        $rq .= "host_perfdata_file_mode  = '" . $ret["host_perfdata_file_mode"]["host_perfdata_file_mode"] . "',  ";
+    } else {
+        $rq .= "host_perfdata_file_mode  = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_mode"]["service_perfdata_file_mode"])
+        && $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] != null
+    ) {
         $rq .= "service_perfdata_file_mode  = '"
-            . $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"] . "',  "
-        : $rq .= "service_perfdata_file_mode  = NULL, ";
-    isset($ret["host_perfdata_file_processing_interval"])
-    && $ret["host_perfdata_file_processing_interval"] != null ?
+            . $ret["service_perfdata_file_mode"]["service_perfdata_file_mode"]
+            . "',  ";
+    } else {
+        $rq .= "service_perfdata_file_mode  = NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_processing_interval"]) &&
+        $ret["host_perfdata_file_processing_interval"] != null
+    ) {
         $rq .= "host_perfdata_file_processing_interval  = '"
-            . htmlentities($ret["host_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "host_perfdata_file_processing_interval  = NULL, ";
-    isset($ret["service_perfdata_file_processing_interval"])
-    && $ret["service_perfdata_file_processing_interval"] != null ?
+            . htmlentities($ret["host_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "host_perfdata_file_processing_interval = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_processing_interval"]) &&
+        $ret["service_perfdata_file_processing_interval"] != null
+    ) {
         $rq .= "service_perfdata_file_processing_interval  = '"
-            . htmlentities($ret["service_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_perfdata_file_processing_interval  = NULL, ";
-    isset($ret["host_perfdata_file_processing_command"])
-    && $ret["host_perfdata_file_processing_command"] != null ?
+            . htmlentities($ret["service_perfdata_file_processing_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "service_perfdata_file_processing_interval = NULL, ";
+    }
+
+    if (isset($ret["host_perfdata_file_processing_command"]) && $ret["host_perfdata_file_processing_command"] != null) {
         $rq .= "host_perfdata_file_processing_command  = '"
-            . htmlentities($ret["host_perfdata_file_processing_command"]) . "',  "
-        : $rq .= "host_perfdata_file_processing_command  = NULL, ";
-    isset($ret["service_perfdata_file_processing_command"])
-    && $ret["service_perfdata_file_processing_command"] != null ?
+            . htmlentities($ret["host_perfdata_file_processing_command"])
+            . "',  ";
+    } else {
+        $rq .= "host_perfdata_file_processing_command  = NULL, ";
+    }
+
+    if (isset($ret["service_perfdata_file_processing_command"]) &&
+        $ret["service_perfdata_file_processing_command"] != null
+    ) {
         $rq .= "service_perfdata_file_processing_command  = '"
-            . htmlentities($ret["service_perfdata_file_processing_command"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_perfdata_file_processing_command  = NULL, ";
-    isset($ret["check_for_orphaned_services"]["check_for_orphaned_services"])
-    && $ret["check_for_orphaned_services"]["check_for_orphaned_services"] != 2 ?
-        $rq .= "check_for_orphaned_services  = '"
-            . $ret["check_for_orphaned_services"]["check_for_orphaned_services"] . "',  "
-        : $rq .= "check_for_orphaned_services  = '2', ";
-    isset($ret["check_service_freshness"]["check_service_freshness"])
-    && $ret["check_service_freshness"]["check_service_freshness"] != 2 ?
-        $rq .= "check_service_freshness  = '"
-            . $ret["check_service_freshness"]["check_service_freshness"] . "',  "
-        : $rq .= "check_service_freshness   = '2', ";
-    isset($ret["service_freshness_check_interval"])
-    && $ret["service_freshness_check_interval"] != null ?
-        $rq .= "service_freshness_check_interval   = '"
-            . htmlentities($ret["service_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "service_freshness_check_interval   = NULL, ";
-    isset($ret["cached_host_check_horizon"]) && $ret["cached_host_check_horizon"] != null ?
-        $rq .= "cached_host_check_horizon   = '"
-            . htmlentities($ret["cached_host_check_horizon"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "cached_host_check_horizon   = NULL, ";
-    isset($ret["cached_service_check_horizon"]) && $ret["cached_service_check_horizon"] != null ?
-        $rq .= "cached_service_check_horizon   = '"
-            . htmlentities($ret["cached_service_check_horizon"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "cached_service_check_horizon   = NULL, ";
-    isset($ret["additional_freshness_latency"]) && $ret["additional_freshness_latency"] != null ?
-        $rq .= "additional_freshness_latency = '"
-            . htmlentities($ret["additional_freshness_latency"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "additional_freshness_latency = NULL, ";
-    isset($ret["check_host_freshness"]["check_host_freshness"])
-    && $ret["check_host_freshness"]["check_host_freshness"] != 2 ?
-        $rq .= "check_host_freshness = '"
-            . $ret["check_host_freshness"]["check_host_freshness"] . "',  "
-        : $rq .= "check_host_freshness = '2', ";
-    isset($ret["host_freshness_check_interval"])
-    && $ret["host_freshness_check_interval"] != null ?
-        $rq .= "host_freshness_check_interval = '"
-            . htmlentities($ret["host_freshness_check_interval"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "host_freshness_check_interval = NULL, ";
-    isset($ret["date_format"]) && $ret["date_format"] != null ?
-        $rq .= "date_format = '"
-            . htmlentities($ret["date_format"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "date_format = NULL, ";
-    isset($ret["illegal_object_name_chars"]) && $ret["illegal_object_name_chars"] != null
-        ? $rq .= "illegal_object_name_chars  = " . $pearDB->quote($ret["illegal_object_name_chars"]) . ",  "
-        : $rq .= "illegal_object_name_chars  = NULL, ";
-    isset($ret["illegal_macro_output_chars"]) && $ret["illegal_macro_output_chars"] != null
-        ? $rq .= "illegal_macro_output_chars  = " . $pearDB->quote($ret["illegal_macro_output_chars"]) . ",  "
-        : $rq .= "illegal_macro_output_chars  = NULL, ";
-    isset($ret["use_large_installation_tweaks"]["use_large_installation_tweaks"])
-    && $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] != 2 ?
+            . htmlentities($ret["service_perfdata_file_processing_command"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "service_perfdata_file_processing_command  = NULL, ";
+    }
+
+    if (isset($ret["check_for_orphaned_services"]["check_for_orphaned_services"]) &&
+        $ret["check_for_orphaned_services"]["check_for_orphaned_services"] != 2
+    ) {
+        $rq .= "check_for_orphaned_services = '"
+            . $ret["check_for_orphaned_services"]["check_for_orphaned_services"]
+            . "',  ";
+    } else {
+        $rq .= "check_for_orphaned_services = '2', ";
+    }
+
+    if (isset($ret["check_service_freshness"]["check_service_freshness"]) &&
+        $ret["check_service_freshness"]["check_service_freshness"] != 2
+    ) {
+        $rq .= "check_service_freshness = '"
+            . $ret["check_service_freshness"]["check_service_freshness"]
+            . "',  ";
+    } else {
+        $rq .= "check_service_freshness = '2', ";
+    }
+
+    if (isset($ret["service_freshness_check_interval"]) && $ret["service_freshness_check_interval"] != null) {
+        $rq .= "service_freshness_check_interval  = '"
+            . htmlentities($ret["service_freshness_check_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "service_freshness_check_interval  = NULL, ";
+    }
+
+    if (isset($ret["cached_host_check_horizon"]) && $ret["cached_host_check_horizon"] != null) {
+        $rq .= "cached_host_check_horizon  = '"
+            . htmlentities($ret["cached_host_check_horizon"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "cached_host_check_horizon  = NULL, ";
+    }
+
+    if (isset($ret["cached_service_check_horizon"]) && $ret["cached_service_check_horizon"] != null) {
+        $rq .= "cached_service_check_horizon  = '"
+            . htmlentities($ret["cached_service_check_horizon"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "cached_service_check_horizon  = NULL, ";
+    }
+
+    if (isset($ret["additional_freshness_latency"]) && $ret["additional_freshness_latency"] != null) {
+        $rq .= "additional_freshness_latency  = '"
+            . htmlentities($ret["additional_freshness_latency"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "additional_freshness_latency  = NULL, ";
+    }
+
+    if (isset($ret["check_host_freshness"]["check_host_freshness"]) &&
+        $ret["check_host_freshness"]["check_host_freshness"] != 2
+    ) {
+        $rq .= "check_host_freshness = '" . $ret["check_host_freshness"]["check_host_freshness"] . "',  ";
+    } else {
+        $rq .= "check_host_freshness = '2', ";
+    }
+
+    if (isset($ret["host_freshness_check_interval"]) && $ret["host_freshness_check_interval"] != null) {
+        $rq .= "host_freshness_check_interval  = '"
+            . htmlentities($ret["host_freshness_check_interval"], ENT_QUOTES, "UTF-8")
+            . "',  ";
+    } else {
+        $rq .= "host_freshness_check_interval  = NULL, ";
+    }
+
+    if (isset($ret["date_format"]) && $ret["date_format"] != null) {
+        $rq .= "date_format  = '" . htmlentities($ret["date_format"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "date_format  = NULL, ";
+    }
+
+    if (isset($ret["illegal_object_name_chars"]) && $ret["illegal_object_name_chars"] != null) {
+        $rq .= "illegal_object_name_chars = '" . $pearDB->quote($ret["illegal_object_name_chars"]) . "',  ";
+    } else {
+        $rq .= "illegal_object_name_chars = NULL, ";
+    }
+
+    if (isset($ret["illegal_macro_output_chars"]) && $ret["illegal_macro_output_chars"] != null) {
+        $rq .= "illegal_macro_output_chars = '" . $pearDB->quote($ret["illegal_macro_output_chars"]) . "',  ";
+    } else {
+        $rq .= "illegal_macro_output_chars = NULL, ";
+    }
+
+    if (isset($ret["use_large_installation_tweaks"]["use_large_installation_tweaks"]) &&
+        $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] != 2
+    ) {
         $rq .= "use_large_installation_tweaks = '"
-            . $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"] . "',  "
-        : $rq .= "use_large_installation_tweaks = '2', ";
-    isset($ret["enable_environment_macros"]["enable_environment_macros"])
-    && $ret["enable_environment_macros"]["enable_environment_macros"] != 2 ?
+            . $ret["use_large_installation_tweaks"]["use_large_installation_tweaks"]
+            . "',  ";
+    } else {
+        $rq .= "use_large_installation_tweaks = '2', ";
+    }
+
+    if (isset($ret["enable_environment_macros"]["enable_environment_macros"]) &&
+        $ret["enable_environment_macros"]["enable_environment_macros"] != 2
+    ) {
         $rq .= "enable_environment_macros = '"
-            . $ret["enable_environment_macros"]["enable_environment_macros"] . "',  "
-        : $rq .= "enable_environment_macros = '2', ";
-    isset($ret["use_setpgid"]["use_setpgid"]) && $ret["use_setpgid"]["use_setpgid"] != 2 ?
-        $rq .= "use_setpgid = '" . $ret["use_setpgid"]["use_setpgid"] . "',  "
-        : $rq .= "use_setpgid = '2', ";
-    isset($ret["use_regexp_matching"]["use_regexp_matching"])
-    && $ret["use_regexp_matching"]["use_regexp_matching"] != 2 ?
-        $rq .= "use_regexp_matching = '" . $ret["use_regexp_matching"]["use_regexp_matching"] . "',  "
-        : $rq .= "use_regexp_matching = '2', ";
-    isset($ret["use_true_regexp_matching"]["use_true_regexp_matching"])
-    && $ret["use_true_regexp_matching"]["use_true_regexp_matching"] != 2 ?
-        $rq .= "use_true_regexp_matching = '"
-            . $ret["use_true_regexp_matching"]["use_true_regexp_matching"] . "',  "
-        : $rq .= "use_true_regexp_matching = '2', ";
-    isset($ret["admin_email"]) && $ret["admin_email"] != null ?
-        $rq .= "admin_email = '"
-            . htmlentities($ret["admin_email"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "admin_email = NULL, ";
-    isset($ret["admin_pager"]) && $ret["admin_pager"] != null ?
-        $rq .= "admin_pager = '"
-            . htmlentities($ret["admin_pager"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "admin_pager = NULL, ";
-    isset($ret["nagios_comment"]) && $ret["nagios_comment"] != null ?
-        $rq .= "nagios_comment = '"
-            . htmlentities($ret["nagios_comment"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "nagios_comment = NULL, ";
-    isset($ret["event_broker_options"]) && $ret["event_broker_options"] != null ?
-        $rq .= "event_broker_options = '"
-            . htmlentities($ret["event_broker_options"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= "event_broker_options = '-1', ";
-    isset($ret["debug_file"]) && $ret["debug_file"] != null ?
-        $rq .= "debug_file = '"
-            . htmlentities($ret["debug_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "debug_file = NULL, ";
+            . $ret["enable_environment_macros"]["enable_environment_macros"]
+            . "',  ";
+    } else {
+        $rq .= "use_large_installation_tweaks = '2', ";
+    }
+
+    if (isset($ret["use_setpgid"]["use_setpgid"]) && $ret["use_setpgid"]["use_setpgid"] != 2) {
+        $rq .= "use_setpgid = '" . $ret["use_setpgid"]["use_setpgid"] . "',  ";
+    } else {
+        $rq .= "use_setpgid = '2', ";
+    }
+
+    if (isset($ret["use_regexp_matching"]["use_regexp_matching"]) &&
+        $ret["use_regexp_matching"]["use_regexp_matching"] != 2
+    ) {
+        $rq .= "use_regexp_matching = '" . $ret["use_regexp_matching"]["use_regexp_matching"] . "',  ";
+    } else {
+        $rq .= "use_regexp_matching = '2', ";
+    }
+
+    if (isset($ret["use_true_regexp_matching"]["use_true_regexp_matching"]) &&
+        $ret["use_true_regexp_matching"]["use_true_regexp_matching"] != 2
+    ) {
+        $rq .= "use_true_regexp_matching = '" . $ret["use_true_regexp_matching"]["use_true_regexp_matching"] . "',  ";
+    } else {
+        $rq .= "use_true_regexp_matching = '2', ";
+    }
+
+    if (isset($ret["admin_email"]) && $ret["admin_email"] != null) {
+        $rq .= "admin_email = '" . htmlentities($ret["admin_email"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "admin_email = NULL, ";
+    }
+
+    if (isset($ret["admin_pager"]) && $ret["admin_pager"] != null) {
+        $rq .= "admin_pager = '" . htmlentities($ret["admin_pager"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "admin_pager = NULL, ";
+    }
+
+    if (isset($ret["nagios_comment"]) && $ret["nagios_comment"] != null) {
+        $rq .= "nagios_comment = '" . htmlentities($ret["nagios_comment"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "nagios_comment = NULL, ";
+    }
+
+    if (isset($ret["event_broker_options"]) && $ret["event_broker_options"] != null) {
+        $rq .= "event_broker_options = '" . htmlentities($ret["event_broker_options"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "event_broker_options = '-1', ";
+    }
+
+    if (isset($ret["debug_file"]) && $ret["debug_file"] != null) {
+        $rq .= "debug_file = '" . htmlentities($ret["debug_file"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "debug_file = NULL, ";
+    }
+
     $level = 0;
     if (isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null) {
         foreach ($ret["nagios_debug_level"] as $key => $value) {
             $level += $key;
         }
     }
+
     $rq .= "debug_level = '" . $level . "', ";
-    isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null ?
-        $rq .= "debug_level_opt = '" . implode(",", array_keys($ret["nagios_debug_level"])) . "',  "
-        : $rq .= "debug_level = NULL, ";
-    isset($ret["debug_verbosity"]["debug_verbosity"])
-    && $ret["debug_verbosity"]["debug_verbosity"] != 2 ?
-        $rq .= "debug_verbosity   = '" . $ret["debug_verbosity"]["debug_verbosity"] . "',  "
-        : $rq .= "debug_verbosity   = '2', ";
-    isset($ret["max_debug_file_size"]) && $ret["max_debug_file_size"] != null ?
-        $rq .= "max_debug_file_size = '"
-            . htmlentities($ret["max_debug_file_size"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "max_debug_file_size = NULL, ";
-    isset($ret["daemon_dumps_core"]["daemon_dumps_core"])
-    && $ret["daemon_dumps_core"]["daemon_dumps_core"] ?
-        $rq .= "daemon_dumps_core = '1',  "
-        : $rq .= "daemon_dumps_core = '0', ";
-
-    isset($ret["translate_passive_host_checks"]["translate_passive_host_checks"])
-    && $ret["translate_passive_host_checks"]["translate_passive_host_checks"] != null ?
+    if (isset($ret["nagios_debug_level"]) && $ret["nagios_debug_level"] != null) {
+        $rq .= "debug_level_opt = '" . implode(",", array_keys($ret["nagios_debug_level"])) . "',  ";
+    } else {
+        $rq .= "debug_level = NULL, ";
+    }
+
+    if (isset($ret["debug_verbosity"]["debug_verbosity"]) && $ret["debug_verbosity"]["debug_verbosity"] != 2) {
+        $rq .= "debug_verbosity = '" . $ret["debug_verbosity"]["debug_verbosity"] . "',  ";
+    } else {
+        $rq .= "debug_verbosity = '2', ";
+    }
+
+    if (isset($ret["max_debug_file_size"]) && $ret["max_debug_file_size"] != null) {
+        $rq .= "max_debug_file_size = '" . htmlentities($ret["max_debug_file_size"], ENT_QUOTES, "UTF-8") . "',  ";
+    } else {
+        $rq .= "max_debug_file_size = NULL, ";
+    }
+
+    if (isset($ret["daemon_dumps_core"]["daemon_dumps_core"]) && $ret["daemon_dumps_core"]["daemon_dumps_core"]) {
+        $rq .= "daemon_dumps_core = '1',  ";
+    } else {
+        $rq .= "daemon_dumps_core = '0', ";
+    }
+
+    if (isset($ret["translate_passive_host_checks"]["translate_passive_host_checks"])
+        && $ret["translate_passive_host_checks"]["translate_passive_host_checks"] != null
+    ) {
         $rq .= "translate_passive_host_checks = '"
             . htmlentities($ret["translate_passive_host_checks"]["translate_passive_host_checks"], ENT_QUOTES, "UTF-8")
-            . "',  "
-        : $rq .= "translate_passive_host_checks = NULL, ";
-    isset($ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"])
-    && $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] != null ?
+            . "',  ";
+    } else {
+        $rq .= "translate_passive_host_checks = NULL, ";
+    }
+
+    if (isset($ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"])
+        && $ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"] != null
+    ) {
         $rq .= "passive_host_checks_are_soft = '"
             . htmlentities($ret["passive_host_checks_are_soft"]["passive_host_checks_are_soft"], ENT_QUOTES, "UTF-8")
-            . "',  "
-        : $rq .= "passive_host_checks_are_soft = NULL, ";
-    isset($ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"])
-    && $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] != null ?
+            . "',  ";
+    } else {
+        $rq .= "passive_host_checks_are_soft = NULL, ";
+    }
+
+    if (isset($ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"])
+        && $ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"] != null
+    ) {
         $rq .= "check_for_orphaned_hosts = '"
             . htmlentities($ret["check_for_orphaned_hosts"]["check_for_orphaned_hosts"], ENT_QUOTES, "UTF-8")
-            . "',  "
-        : $rq .= "check_for_orphaned_hosts = NULL, ";
-    isset($ret["external_command_buffer_slots"]) && $ret["external_command_buffer_slots"] != null ?
+            . "',  ";
+    } else {
+        $rq .= "check_for_orphaned_hosts = NULL, ";
+    }
+
+    if (isset($ret["external_command_buffer_slots"]) && $ret["external_command_buffer_slots"] != null) {
         $rq .= "external_command_buffer_slots = '"
-            . htmlentities($ret["external_command_buffer_slots"], ENT_QUOTES, "UTF-8") . "', "
-        : $rq .= " external_command_buffer_slots = NULL, ";
+            . htmlentities($ret["external_command_buffer_slots"], ENT_QUOTES, "UTF-8")
+            . "', ";
+    } else {
+        $rq .= "external_command_buffer_slots = NULL, ";
+    }
+
+    if (isset($ret["cfg_file"]) && $ret["cfg_file"] != null) {
+        $rq .= "cfg_file = '" . htmlentities($ret["cfg_file"], ENT_QUOTES, "UTF-8") . "', ";
+    } else {
+        $rq .= "cfg_file = NULL, ";
+    }
 
-    isset($ret["cfg_file"]) && $ret["cfg_file"] != null ?
-        $rq .= "cfg_file = '"
-            . htmlentities($ret["cfg_file"], ENT_QUOTES, "UTF-8") . "',  "
-        : $rq .= "cfg_file = NULL, ";
     isset($ret["log_pid"]["log_pid"]) && $ret["log_pid"]["log_pid"] ?
         $rq .= "log_pid = '1',  " : $rq .= "log_pid = '0', ";
-    isset($ret['use_check_result_path']['use_check_result_path'])
-    && $ret['use_check_result_path']['use_check_result_path'] ?
-        $rq .= "use_check_result_path = '1', " : $rq .= "use_check_result_path = '0', ";
+
+    if (isset($ret["log_pid"]["log_pid"]) && $ret["log_pid"]["log_pid"]) {
+        $rq .= "log_pid = '1',  ";
+    } else {
+        $rq .= "log_pid = '0', ";
+    }
+
+    if (isset($ret['use_check_result_path']['use_check_result_path'])
+        && $ret['use_check_result_path']['use_check_result_path']
+    ) {
+        $rq .= "use_check_result_path = '1', ";
+    } else {
+        $rq .= "use_check_result_path = '0', ";
+    }
 
     $rq .= "nagios_activate = '" . $ret["nagios_activate"]["nagios_activate"] . "' ";
     $rq .= "WHERE nagios_id = '" . $nagios_id . "'";
-- 
GitLab