A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-config_rewrite.php
index bc6c58fd7b4e043cde1904851bde6592d099a1fe..3da28b7a3c6e18e1aebc082c4f57d96d9b89e6c4 100644 (file)
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!is_admin()))
-{
+if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
        $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
        require($INC);
 }
+
 // Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+ADD_DESCR("admin", __FILE__);
 
-if (isset($_POST['ok']))
-{
+if (IS_FORM_SENT()) {
        // Generate string
        $MODs = array();
-       foreach ($_POST['mod'] as $mod=>$sel)
-       {
+       foreach (REQUEST_POST('mod') as $mod => $sel) {
                // Now you can never deselect the admin module, bah!!! ;-)
-               if (($sel == 'Y') || ($mod == "admin"))
-               {
+               if (($sel == "Y") || ($mod == "admin")) {
                        // Add module to queue
                        $MODs[] = $mod;
                }
        }
 
        // Implode array to string and remove posted mod array
-       $_POST['rewrite_skip'] = implode(":", $MODs);
-       unset($_POST['mod']);
+       REQUEST_SET_POST('rewrite_skip', implode(":", $MODs));
+       REQUEST_UNSET_POST('mod');
 
        // Save settings
-       ADMIN_SAVE_SETTINGS($_POST, "_config", "config='0'");
-}
- else
-{
+       ADMIN_SAVE_SETTINGS_POST();
+} else {
        // Load existing modules and generate TR rows for the template
-       $result = SQL_QUERY("SELECT module, title FROM "._MYSQL_PREFIX."_mod_reg ORDER BY module", __FILE__, __LINE__);
-       $SW = 2; $OUT = "";
-       while(list($mod, $title) = SQL_FETCHROW($result))
-       {
+       $result = SQL_QUERY("SELECT module, title FROM `{!_MYSQL_PREFIX!}_mod_reg` ORDER BY module", __FILE__, __LINE__);
+       $OUT = ""; $SW = 2;
+       while ($content = SQL_FETCHARRAY($result)) {
                // Set title to three dashes when no title is supplied
-               if (empty($title)) $title = "---";
+               if (empty($content['title'])) $content['title'] = "---";
 
                // Already registered module?
-               if (ereg($mod, $CONFIG['rewrite_skipped_mods']))
-               {
+               if (ereg($content['module'], getConfig('rewrite_skip'))) {
                        // Found
-                       $y = " checked";
+                       $y = " checked=\"checked\"";
                        $n = "";
-               }
-                else
-               {
+               } else {
                        // Not found
                        $y = "";
-                       $n = " checked";
+                       $n = " checked=\"checked\"";
                }
 
                // Remember data in array for the dynamic row template
-               $content = array(
-                       'module'    => $mod,
-                       'title'     => $title,
-                       'y_default' => $y,
-                       'n_default' => $n,
-                       'sw'        => $SW,
-               );
+               $content['y_default'] = $y;
+               $content['n_default'] = $n;
+               $content['sw']        = $SW;
 
                // Load template and switch colors
                $OUT .= LOAD_TEMPLATE("admin_config_rewrite_rows", true, $content);
@@ -101,10 +88,13 @@ if (isset($_POST['ok']))
 
        // Free memory
        SQL_FREERESULT($result);
+
+       // @TODO Rewrite this constant
        define('__MODULE_ROWS', $OUT);
 
        // Load main template
        LOAD_TEMPLATE("admin_config_rewrite");
 }
+
 //
 ?>