Extension ext-network continued:
[mailer.git] / inc / libs / network_functions.php
index 85ade7690060a7ca29650de6acf8c43863a96574..db3196125f93239771b5a5c9632c0917c7a7e4a8 100644 (file)
@@ -803,6 +803,25 @@ function isNetworkApiConfigured ($networkId) {
        return $GLOBALS[__FUNCTION__][$networkId];
 }
 
+// Checks wether the given network type handler is configured
+function isNetworkTypeHandlerConfigured ($networkId, $networkTypeId) {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__][$networkId][$networkTypeId])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__][$networkId][$networkTypeId] = (countSumTotalData(
+                       bigintval($networkTypeId),
+                       'network_types_config',
+                       'network_data_id',
+                       'network_type_id',
+                       true,
+                       sprintf(' AND `network_id`=%s', bigintval($networkId))
+               ) == 1);
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$networkId][$networkTypeId];
+}
+
 //------------------------------------------------------------------------------
 //                             Call-back functions
 //------------------------------------------------------------------------------
@@ -1376,6 +1395,62 @@ function doAdminNetworkProcessNetworkApiConfig () {
        }
 }
 
+// Only adds network type configuration if not yet present
+function doAdminNetworkProcessAddNetworkTypesConfig () {
+       // Remove the 'ok' part
+       unsetPostRequestElement('ok');
+
+       // Add both ids
+       setPostRequestElement('network_id', bigintval(getRequestElement('network_id')));
+       setPostRequestElement('network_type_id', bigintval(getRequestElement('network_type_id')));
+
+       /*
+        * Some parameters are optional, at least one must be given so check a bunch
+        * of parameters.
+        */
+       foreach (array('network_min_waiting_time', 'network_min_remain_clicks', 'network_min_payment', 'network_allow_erotic') as $element) {
+               // Is this element empty?
+               if (postRequestElement($element) == '') {
+                       // Then unset it to get a NULL for optional parameter
+                       unsetPostRequestElement($element);
+               } // END - if
+       } // END - foreach
+
+       // Initialize variables
+       $content = array();
+       $id = 'network_max_reload_time_ye';
+       $skip = false;
+       $postData = postRequestArray();
+
+       // Convert "reload time selections"
+       convertSelectionsToEpocheTime($postData, $content, $id, $skip);
+
+       // Set the POST array back
+       setPostRequestArray($postData);
+
+       // Is there already an entry?
+       if (isNetworkTypeHandlerConfigured(getRequestElement('network_id'), getRequestElement('network_type_id'))) {
+               // This network type handler is already configured
+               displayMessage('{--ADMIN_NETWORK_TYPE_HANDLER_ALREADY_CONFIGURED--}');
+               return;
+       } // END - if
+
+       // Get SQL query for new entry
+       $SQL = getInsertSqlFromArray(postRequestArray(), 'network_types_config');
+
+       // Run the query
+       SQL_QUERY($SQL, __FUNCTION__, __LINE__);
+
+       // Output message
+       if (!SQL_HASZEROAFFECTED()) {
+               // Successfully added
+               displayMessage('{--ADMIN_NETWORK_TYPE_HANDLER_CONFIG_SAVED--}');
+       } else {
+               // Not added
+               loadTemplate('admin_settings_unsaved', false, '{--ADMIN_NETWORK_TYPE_HANDLER_CONFIG_NOT_SAVED--}');
+       }
+}
+
 // Do expression code for this extension
 function doExpressionNetwork ($data) {
        // Construct replacer