]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/network_functions.php
Adding of network type handlers finished (listing is still work-in-progress)
[mailer.git] / inc / libs / network_functions.php
index e173bad283bed37d2914c517f99cf0b91bee4d90..7b982e3ab72d8e10a2b7cacdea1263d9dd7df8fc 100644 (file)
@@ -98,6 +98,22 @@ function isNetworkNameValid ($name) {
        return $isValid;
 }
 
+// Checks wether the given network type is already used (valid)
+function isNetworkTypeHandleValid ($type, $networkId) {
+       // Query for it
+       $result = SQL_QUERY_ESC("SELECT `network_type_id` FROM `{?_MYSQL_PREFIX?}_network_types` WHERE `network_id`=%s AND `network_type_handle`='%s' LIMIT 1",
+               array($networkId, $type), __FUNCTION__, __LINE__);
+
+       // Does it exist?
+       $isValid = (SQL_NUMROWS($result) == 1);
+
+       // Free result
+       SQL_FREERESULT($result);
+
+       // Return result
+       return $isValid;
+}
+
 // "Getter" for a network's data by provided id number
 function getNetworkDataById ($id) {
        // Ids lower one are not accepted
@@ -200,7 +216,7 @@ function doAdminNetworkProcessAddnetworkForm () {
        if (isNetworkNameValid(postRequestElement('network_short_name'))) {
                // Already there
                loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_ALREADY_ADDED', postRequestElement('network_short_name')));
-               return;
+               return false;
        } // END - if
 
        // Remove the 'ok' part
@@ -216,7 +232,7 @@ function doAdminNetworkProcessAddnetworkForm () {
 )", __FUNCTION__, __LINE__);
 
        // Add the id for output only
-       setRequestPostElement('network_id', SQL_INSERTID());
+       setPostRequestElement('network_id', SQL_INSERTID());
 
        // Output message
        if (SQL_AFFECTEDROWS() == 1) {
@@ -250,7 +266,10 @@ function doAdminNetworkProcessHandlenetworkForm () {
                                                $networkData['network_request_type'] = generateOptionList(
                                                        '/ARRAY/',
                                                        array('GET','POST'),
-                                                       array(getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'), getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')),
+                                                       array(
+                                                               getMessage('ADMIN_NETWORK_REQUEST_TYPE_GET'),
+                                                               getMessage('ADMIN_NETWORK_REQUEST_TYPE_POST')
+                                                       ),
                                                        $networkData['network_request_type']
                                                );
 
@@ -366,5 +385,41 @@ function doAdminNetworkProcessRemovenetworkForm () {
        } // END - if
 }
 
+// Add a network type if not yet found
+function doAdminNetworkProcessAddnetworktypeForm () {
+       // Is the network type handle already used with given network?
+       if (isNetworkTypeHandleValid(postRequestElement('network_type_handle'), getRequestElement('network'))) {
+               // Already added
+               loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPE_HANDLE_ALREADY_ADDED', postRequestElement('network_type_handle')));
+
+               // ... so abort here
+               return false;
+       } // END - if
+
+       // Remove the 'ok' part
+       unsetPostRequestElement('ok');
+
+       // Add id
+       setPostRequestElement('network_id', getRequestElement('network'));
+
+       // Add the whole request to database
+       SQL_QUERY("INSERT INTO
+       `{?_MYSQL_PREFIX?}_network_types`
+(
+       `" . implode('`,`', array_keys(postRequestArray())) . "`
+) VALUES (
+       '" . implode("','", array_values(postRequestArray())) . "'
+)", __FUNCTION__, __LINE__);
+
+       // Output message
+       if (SQL_AFFECTEDROWS() == 1) {
+               // Successfully added
+               loadTemplate('admin_network_type_added', false, postRequestArray());
+       } else {
+               // Not added
+               loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_NETWORK_TYPE_NOT_ADDED', postRequestElement('network_type_handle')));
+       }
+}
+
 // [EOF]
 ?>