Adding of network advert types partly finished, hard-coded table type fixed to dynamic
[mailer.git] / inc / libs / network_functions.php
index 6c186eac852e989ddb905d84b9fe7dfc797a6d26..4953a1d097c1b2a14af07d150b7bacf226efaa0b 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Funktionen fuer ext-network                      *
  * -------------------------------------------------------------------- *
- * $Revision:: 1194                                                   $ *
- * $Date:: 2009-10-27 18:24:18 +0100 (Tue, 27 Oct 2009)               $ *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author:: quix0r                                                   $ *
+ * $Author::                                                          $ *
  * Needs to be in all Files and every File needs "svn propset           *
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
@@ -41,6 +41,21 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
+// Handle a (maybe) sent form here
+function doNetworkHandleForm () {
+       // Was the form sent?
+       if ((isFormSent()) || (isPostRequestElementSet('edit')) || (isPostRequestElementSet('del')) || (isPostRequestElementSet('change')) || (isPostRequestElementSet('remove'))) {
+               // Do we have a 'do'?
+               if (isGetRequestElementSet('do')) {
+                       // Process the request
+                       doAdminNetworkProcessForm();
+               } else {
+                       // No 'do' found
+                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_DO_404'));
+               }
+       } // END - if
+}
+
 // Processes an admin form
 function doAdminNetworkProcessForm () {
        // Form really sent?
@@ -60,7 +75,7 @@ function doAdminNetworkProcessForm () {
        // Is the function valid?
        if (!function_exists($functionName)) {
                // Invalid function name
-               debug_report_bug('Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.');
+               debug_report_bug('Invalid do ' . getRequestElement('do') . ', function ' . $functionName .' does not exist.', false);
        } // END - if
 
        // Call-back the method handling our request
@@ -129,6 +144,52 @@ function doNetworkUpdateDataByArray ($id, $networkData) {
        return adminSaveSettings($networkData, '_network_data', sprintf("`network_id`=%s", bigintval($id)), array(), false, false);
 }
 
+// Removes given network entry
+function doAdminRemoveNetworkEntry ($table, $column, $id, $limit = 1) {
+       // Remove the entry
+       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_network_%s` WHERE `%s`=%s LIMIT %s",
+               array($table, $column, $id, $limit), __FILE__, __LINE__);
+
+       // Return affected rows
+       return SQL_AFFECTEDROWS();
+}
+
+// Generates a list of networks for given script and returns it
+function generateAdminNetworkList () {
+       // Init output
+       $content = '';
+
+       // Query for all networks
+       $result = SQL_QUERY("SELECT
+       `network_id`, `network_title`
+FROM
+       `{?_MYSQL_PREFIX?}_network_data`
+ORDER BY
+       `network_title` ASC", __FILE__, __LINE__);
+
+       // Do we have entries?
+       if (SQL_NUMROWS($result) > 0) {
+               // List all entries
+               $rows = array();
+               while ($row = SQL_FETCHARRAY($result)) {
+                       // Is this valid, then add it
+                       if ((is_array($row)) && (isset($row['network_id']))) $rows[] = $row;
+               } // END - while
+
+               // Generate the selection box
+               $content = generateSelectionBoxFromArray($rows, 'network', 'network_id', 'network_title');
+       } else {
+               // Nothing selected
+               $content = loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ENTRIES_404'));
+       }
+
+       // Free the result
+       SQL_FREERESULT($result);
+
+       // Return the list
+       return $content;
+}
+
 //------------------------------------------------------------------------------
 //                             Call-back functions
 //------------------------------------------------------------------------------
@@ -173,7 +234,7 @@ function doAdminNetworkProcessHandlenetworkForm () {
        if (countPostSelection() > 0) {
                // Something has been selected, so start displaying one by one
                $SW = 2; $OUT = '';
-               foreach (postRequestElement('sel') as $id=>$sel) {
+               foreach (postRequestElement('sel') as $id => $sel) {
                        // Is this selected?
                        if ($sel == 1) {
                                // Load this network's data
@@ -193,18 +254,20 @@ function doAdminNetworkProcessHandlenetworkForm () {
                                                        $networkData['network_request_type']
                                                );
 
-                                               // Add row template and switch color
+                                               // Add row template for editing
                                                $OUT .= loadTemplate('admin_edit_networks_row', true, $networkData);
                                        } elseif (isPostRequestElementSet('del')) {
                                                // Translate the request type
                                                $networkData['network_request_type'] = getMessage('ADMIN_NETWORK_REQUEST_TYPE_' . $networkData['network_request_type']);
 
-                                               // Add row template and switch color
+                                               // Add row template for deleting
                                                $OUT .= loadTemplate('admin_del_networks_row', true, $networkData);
                                        } else {
                                                // Problem!
                                                debug_report_bug('Cannot detect edit/del.');
                                        }
+
+                                       // Switch colors
                                        $SW = 3 - $SW;
                                } // END - if
                        } // END - if
@@ -246,7 +309,7 @@ function doAdminNetworkProcessChangenetworkForm () {
                                $networkData = array();
 
                                // Transfer whole array, except 'sel'
-                               foreach (postRequestArray() as $key=>$entry) {
+                               foreach (postRequestArray() as $key => $entry) {
                                        // Skip 'sel' and submit button
                                        if (in_array($key, array('sel', 'change'))) continue;
 
@@ -276,5 +339,32 @@ function doAdminNetworkProcessChangenetworkForm () {
        } // END - if
 }
 
+// Removes given networks
+function doAdminNetworkProcessRemovenetworkForm () {
+       // Do we have selections?
+       if (countPostSelection() > 0) {
+               // By default nothing is removed
+               $removed = 0;
+
+               // Something has been selected, so start updating them
+               foreach (postRequestElement('sel') as $id => $sel) {
+                       // Update this entry?
+                       if ($sel == 1) {
+                               // Remove this entry
+                               $removed += doAdminRemoveNetworkEntry('data', 'network_id', $id);
+                       } // END - if
+               } // END - foreach
+
+               // Do we have removes?
+               if ($removed > 0) {
+                       // Removals done
+                       loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_NETWORK_REMOVED'), $removed));
+               } else {
+                       // Nothing removed
+                       loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NETWORK_NOTHING_REMOVED'));
+               }
+       } // END - if
+}
+
 // [EOF]
 ?>