]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/network_functions.php
More networks deactivated, isAdminsExpertSettingEnabled() introduced and some others...
[mailer.git] / inc / libs / network_functions.php
index e90aa3b06a1e20abfdd122404aec371634ca779c..0e184b9d39ca5e48df9a5000f20b6a44490935be 100644 (file)
@@ -115,18 +115,56 @@ function doAdminNetworkProcessForm () {
 
 // Checks whether the (short) network name is already used (valid)
 function isNetworkNameValid ($name) {
-       // Query for it
-       $result = SQL_QUERY_ESC("SELECT `network_id` FROM `{?_MYSQL_PREFIX?}_network_data` WHERE `network_short_name`='%s' LIMIT 1",
-               array($name), __FUNCTION__, __LINE__);
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$name])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$name] = (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', true) == 1);
+       } // END - if
 
-       // Does it exist?
-       $isValid = (SQL_NUMROWS($result) == 1);
+       // Return result
+       return $GLOBALS[__FUNCTION__][$name];
+}
 
-       // Free result
-       SQL_FREERESULT($result);
+// Checks whether the (short) named network is activated
+function isNetworkActiveByShortName ($name) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$name])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$name] = ((isNetworkNameValid($name)) && (countSumTotalData($name, 'network_data', 'network_id', 'network_short_name', true, " AND `network_active`='Y'") == 1));
+       } // END - if
 
        // Return result
-       return $isValid;
+       return $GLOBALS[__FUNCTION__][$name];
+}
+
+// Checks whether the network by given id is activated
+function isNetworkActiveById ($networkId) {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId])) {
+               // Does it exist?
+               $GLOBALS[__FUNCTION__][$networkId] = (countSumTotalData(bigintval($networkId), 'network_data', 'network_id', 'network_id', true, " AND `network_active`='Y'") == 1);
+       } // END - if
+
+       // Return result
+       return $GLOBALS[__FUNCTION__][$networkId];
+}
+
+// "Getter" for 'network_activated' column depending on current administrator's expert setting
+function getNetworkActivatedColumn ($whereAnd = 'WHERE', $table = '') {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__][$whereAnd][$table])) {
+               // Default is exclude deactivated networks
+               $GLOBALS[__FUNCTION__][$whereAnd][$table] = ' ' . $whereAnd . ' ' . $table . "`network_active`='Y'";
+
+               // Is the export setting on?
+               if (isAdminsExpertSettingEnabled()) {
+                       // Then allow all networks
+                       $GLOBALS[__FUNCTION__][$whereAnd][$table] = '';
+               } // END - if
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$whereAnd][$table];
 }
 
 // Checks whether the given network type is already used (valid)
@@ -213,7 +251,10 @@ function getNetworkDataById ($networkId, $column = '') {
        if ($networkId < 1) {
                // Not good, should be fixed
                reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is smaller than 1.');
-       } // END - if
+       } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
+               // Do not load inactive network data
+               reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
+       }
 
        // Set current network id
        setCurrentNetworkId($networkId);
@@ -253,13 +294,16 @@ LIMIT 1',
        } // END - if
 
        // Return result
-       if (empty($column)) {
+       if ((empty($column)) && (isset($GLOBALS['network_data'][$networkId]))) {
                // Return array
                return $GLOBALS['network_data'][$networkId];
-       } else {
+       } elseif (isset($GLOBALS['network_data'][$networkId][$column])) {
                // Return column
                return $GLOBALS['network_data'][$networkId][$column];
        }
+
+       // Return NULL
+       return NULL;
 }
 
 // "Getter" for a network's data by provided type id number
@@ -268,7 +312,10 @@ function getNetworkDataByTypeId ($networkId, $column = '') {
        if ($networkId < 1) {
                // Not good, should be fixed
                reportBug(__FUNCTION__, __LINE__, 'Network type id ' . $networkId . ' is smaller than 1.');
-       } // END - if
+       } elseif ((!isNetworkActiveById($networkId)) && (!isAdminsExpertSettingEnabled())) {
+               // Do not load inactive network data
+               reportBug(__FUNCTION__, __LINE__, 'Network id ' . $networkId . ' is not active.');
+       }
 
        // Set current network id
        setCurrentNetworkId($networkId);
@@ -279,7 +326,7 @@ function getNetworkDataByTypeId ($networkId, $column = '') {
                $GLOBALS['network_data'][$networkId] = array();
 
                // Query for the network data
-               $result = SQL_QUERY_ESC("SELECT
+               $result = SQL_QUERY_ESC('SELECT
        d.`network_id`,
        d.`network_short_name`,
        d.`network_title`,
@@ -303,7 +350,7 @@ ON
        d.`network_id`=t.`network_id`
 WHERE
        t.`network_type_id`=%s
-LIMIT 1",
+LIMIT 1',
                        array(bigintval($networkId)), __FUNCTION__, __LINE__);
 
                // Is there an entry?
@@ -511,16 +558,15 @@ function generateAdminNetworkList () {
        $content = '';
 
        // Query for all networks
-       $result = SQL_QUERY("SELECT
+       $result = SQL_QUERY('SELECT
        `network_id`,
        `network_short_name`,
        `network_title`
 FROM
        `{?_MYSQL_PREFIX?}_network_data`
-WHERE
-       `network_active`='Y'
+' . getNetworkActivatedColumn() . '
 ORDER BY
-       `network_short_name` ASC", __FUNCTION__, __LINE__);
+       `network_short_name` ASC', __FUNCTION__, __LINE__);
 
        // Are there entries?
        if (!SQL_HASZERONUMS($result)) {
@@ -561,6 +607,7 @@ FROM
        `{?_MYSQL_PREFIX?}_network_types`
 WHERE
        `network_id`=%s
+       ' . getNetworkActivatedColumn('AND') . '
 ORDER BY
        `network_type_handler` ASC',
                array(
@@ -599,7 +646,7 @@ function generateAdminDistinctNetworkTypeList () {
        $content = '';
 
        // Query all types of this network
-       $result = SQL_QUERY("SELECT
+       $result = SQL_QUERY('SELECT
        t.`network_type_id`,
        t.`network_type_handler`,
        d.`network_title`
@@ -609,11 +656,10 @@ LEFT JOIN
        `{?_MYSQL_PREFIX?}_network_data` AS d
 ON
        t.`network_id`=d.`network_id`
-WHERE
-       d.`network_active`='Y'
+' . getNetworkActivatedColumn('WHERE', 'd') . '
 ORDER BY
        d.`network_short_name` ASC,
-       t.`network_type_handler` ASC", __FUNCTION__, __LINE__);
+       t.`network_type_handler` ASC', __FUNCTION__, __LINE__);
 
        // Are there entries?
        if (!SQL_HASZERONUMS($result)) {
@@ -646,6 +692,7 @@ ORDER BY
 function generateNetworkTypeOptions ($networkId) {
        // Is this an array, then we just came back from edit/delete actions
        if (is_array($networkId)) {
+               // Set it as empty string
                $networkId = '';
        } // END - if
 
@@ -659,7 +706,7 @@ function generateNetworkTypeOptions ($networkId) {
                        $networkId,
                        '',
                        sprintf(
-                               "WHERE `network_id`=%s",
+                               "WHERE `network_id`=%s" . getNetworkActivatedColumn('AND'),
                                bigintval(getRequestElement('network_id'))
                        ),
                        '',
@@ -1015,7 +1062,10 @@ function translateNetworkApiConfiguredStatusById ($networkId) {
                $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_CONFIGURED--}';
 
                // So is it configured?
-               if (isNetworkApiConfigured($networkId)) {
+               if (!isNetworkActiveById($networkId)) {
+                       // Network is not active
+                       $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_NOT_ACTIVE--}';
+               } elseif (isNetworkApiConfigured($networkId)) {
                        // Yes, it is
                        $GLOBALS[__FUNCTION__][$networkId] = '{--ADMIN_NETWORK_API_CONFIGURED--}';
                } // END - if
@@ -1079,7 +1129,11 @@ function doAdminNetworkProcessAddNetwork () {
                // Already there
                loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_ALREADY_ADDED=' . postRequestElement('network_short_name') . '%}');
                return false;
-       } // END - if
+       } elseif (!isNetworkActiveByShortName(postRequestElement('network_short_name'))) {
+               // Network is not active
+               loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_NETWORK_NOT_ACTIVE=' . postRequestElement('network_short_name') . '%}');
+               return false;
+       }
 
        // Remove the 'ok' part
        unsetPostRequestElement('ok');