A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-config_home.php
index 64bcfd3b71af4a44490f1afe36c78591a2ce02c4..3a1af21e8508d5ced8929f330a9a4b29f717aefd 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__);
 
+// Init "sub" value
 $sub = "";
-if (!empty($_GET['sub'])) $sub = $_GET['sub'];
+if (REQUEST_ISSET_GET(('sub'))) $sub = REQUEST_GET('sub');
 
 switch ($sub)
 {
-case "": // Output selection table
-       LOAD_TEMPLATE("admin_config_home_main");
-       break;
-
 case "settings": // Settings related to the index page
-       if (isset($_POST['ok']))
-       {
+       if (IS_FORM_SENT()) {
                // Save settings
-               ADMIN_SAVE_SETTINGS($_POST);
-               OUTPUT_HTML("<A href=\"".URL."/modules.php?module=admin&amp;what=config_home&amp;sub=settings\">".ADMIN_CONTINUE_TO_CONFIG."</A>");
-       }
-        else
-       {
+               ADMIN_SAVE_SETTINGS_POST();
+               OUTPUT_HTML("<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_home&amp;sub=settings\">{--ADMIN_CONTINUE_TO_CONFIG--}</a>");
+       } else {
                // Prepare data for the template
                $content = array_fill(-1, 60, "");
-               $content[$_CONFIG['index_delay']] = " selected=\"selected\"";
+               $content[getConfig('index_delay')] = " selected=\"selected\"";
 
-               define('__INDEX_COOKIE_SELECTION', CREATE_TIME_SELECTIONS($_CONFIG['index_cookie'], "index_cookie", "YMWD"));
+               define('__INDEX_COOKIE_SELECTION', CREATE_TIME_SELECTIONS(getConfig('index_cookie'), "index_cookie", "YMWD"));
                LOAD_TEMPLATE("admin_config_home_settings", false, $content);
        }
        break;
 
 case "target": // Set which what-file will be placed in home-page (only modules.php?module=index)
-       if (isset($_GET['home'])) {
+       if (REQUEST_ISSET_GET(('home'))) {
                // Set new home
-               UPDATE_CONFIG("index_home", $_GET['home']);
-               $_CONFIG['index_home'] = SQL_ESCAPE($_GET['home']);
+               UPDATE_CONFIG("index_home", REQUEST_GET(('home')));
        } // END - if
 
        // Load all what menu points
        $result = SQL_QUERY("SELECT id, what, title
- FROM "._MYSQL_PREFIX."_guest_menu
- WHERE action='main' AND what != '' AND what IS NOT NULL AND locked='N'
- ORDER BY sort", __FILE__, __LINE__);
-
-       $SW = 2; $OUT = ""; $atitle = "";
-       while (list($id, $wht, $wtitle) = SQL_FETCHROW($result))
-       {
-               $LINK = "<A href=\"".URL."/modules.php?module=admin&amp;what=config_home&amp;sub=target&amp;home=".$wht."\">"._IS_NEW_HOME."</A>";
-               if ($wht == $_CONFIG['index_home'])
-               {
+FROM `{!_MYSQL_PREFIX!}_guest_menu`
+WHERE `action`='main' AND `what` != '' AND `what` IS NOT NULL AND `locked`='N'
+ORDER BY `sort` ASC", __FILE__, __LINE__);
+
+       // Init variables
+       $SW = 2;
+       $OUT = "";
+
+       // Process all entries
+       while ($content = SQL_FETCHARRAY($result)) {
+               // Link for setting 'what' as new "home"
+               $LINK = "<a href=\"{!URL!}/modules.php?module=admin&amp;what=config_home&amp;sub=target&amp;home=".$content['what']."\">{--_IS_NEW_HOME--}</a>";
+
+               // Is this current home?
+               if ($content['what'] == getConfig('index_home')) {
                        // Is current home
-                       $LINK   = "<STRONG class=\"admin_note\">"._IS_CURRENT_HOME."</STRONG>";
-                       $atitle = "<STRONG class=\"admin_note\">".$atitle."</STRONG>";
-                       $wtitle = "<STRONG class=\"admin_note\">".$wtitle."</STRONG>";
-               }
-
-               // Add row...
-               $OUT .= "<TR>
-         <TD class=\"switch_sw".$SW." bottom right\">&nbsp;".$id."</TD>
-         <TD class=\"switch_sw".$SW." bottom right\">&nbsp;".$wtitle."</TD>
-         <TD class=\"switch_sw".$SW." bottom\" align=\"center\">
-           ".$LINK."
-         </TD>
-       </TR>\n";
+                       $LINK = "<div class=\"admin_note\">{!_IS_CURRENT_HOME!}</div>";
+                       $content['title'] = "<div class=\"admin_note\">".$content['title']."</div>";
+               } // END - if
+
+               // Prepare content
+               $content['sw'] = $SW;
+               $content['link'] = $LINK;
+
+               // Load row template
+               $OUT .= LOAD_TEMPLATE("admin_config_home_row", true, $content);
 
                // Switch color
                $SW = 3 - $SW;
-       }
+       } // END - while
 
        // Free memory
        SQL_FREERESULT($result);
@@ -112,6 +107,12 @@ case "target": // Set which what-file will be placed in home-page (only modules.
        // Load template
        LOAD_TEMPLATE("admin_config_home");
        break;
+
+default: // Output selection table
+       LOAD_TEMPLATE("admin_config_home_main");
+       break;
+
 }
+
 //
 ?>