Fixes for menu system (still SQL is broken)
[mailer.git] / inc / modules / admin / what-guest_add.php
index f23636efd305a9b921f88c0ee0f8564dc417c357..8db69b86c711ad8452f8e7aff5d15d2368e86c99 100644 (file)
@@ -45,7 +45,7 @@ if ((!defined('__SECURITY')) || (!isAdmin())) {
 addMenuDescription('admin', __FILE__);
 
 // Check if the admin has entered title and what-php file name...
-if (((!isPostRequestElementSet('title')) || (!isPostRequestElementSet(('menu')))) && (isFormSent())) {
+if (((!isPostRequestElementSet('title')) || (!isPostRequestElementSet('menu'))) && (isFormSent())) {
        // Abort adding the menu entry
        unsetPostRequestElement('ok');
 } // END - if
@@ -55,7 +55,14 @@ if (!isFormSent()) {
        $menus = array(); $titles = array(); $below = array();
 
        // Get all available main menus
-       $result = SQL_QUERY("SELECT action, title, sort FROM `{?_MYSQL_PREFIX?}_guest_menu` WHERE (`what`='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
+       $result = SQL_QUERY("SELECT
+       `action`, `title`, `sort`
+FROM
+       `{?_MYSQL_PREFIX?}_guest_menu`
+WHERE
+       (`what`='' OR `what` IS NULL)
+ORDER BY
+       `sort` ASC", __FILE__, __LINE__);
        if (SQL_NUMROWS($result) > 0) {
                // Read menu structure
                // @TODO Cant this be rewritten?
@@ -93,10 +100,17 @@ if (!isFormSent()) {
 
                // Load sub menus :)
                foreach ($menus as $key_main => $value_main) {
-                       $result = SQL_QUERY_ESC("SELECT what, title, sort
-FROM `{?_MYSQL_PREFIX?}_guest_menu`
-WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
-                       array($value_main), __FILE__, __LINE__);
+                       // Query for sub menus
+                       $result = SQL_QUERY_ESC("SELECT
+       `what`, `title`, `sort`
+FROM
+       `{?_MYSQL_PREFIX?}_guest_menu`
+WHERE
+       `action`='%s' AND
+       `what` != '' AND
+       `what` IS NOT NULL
+ORDER BY `sort` ASC",
+                               array($value_main), __FILE__, __LINE__);
                        if (SQL_NUMROWS($result) > 0) {
                                // Initialize arrays
                                $menus[$value_main] = array();
@@ -106,7 +120,7 @@ WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
                                // Read menu structure
                                while ($content = SQL_FETCHARRAY($result)) {
                                        // Menu actions
-                                       $menus[$value_main][] = $content['action'];
+                                       $menus[$value_main][] = $content['what'];
 
                                        // Menu titles
                                        $titles[$value_main][] = $content['title'];
@@ -140,7 +154,7 @@ WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
        }
 
        $OUT = "    <select class=\"admin_select\" name=\"sort\" size=\"1\">
-      <option value=\"0\">".IS_FIRST_MENU."</option>";
+      <option value=\"0\">{--IS_FIRST_MENU--}</option>";
        foreach ($below as $key => $m) {
                if (is_array($m)) {
                        foreach ($m as $key2 => $m2) {
@@ -167,25 +181,25 @@ WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
        loadTemplate('admin_guest_add', false, $content);
 } elseif (!isDemoModeActive()) {
        // Insert new menu entry
-       if (isPostRequestElementSet(('menu'))) {
+       if (isPostRequestElementSet('menu')) {
                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`,`what`,`title`,`sort`,`visible`,`locked`) VALUES ('%s','%s','%s','%s','%s','%s')",
-               array(
-               postRequestElement('menu'),
-               postRequestElement('name'),
-               postRequestElement('title'),
-               bigintval(postRequestElement('sort')),
-               postRequestElement('visible'),
-               postRequestElement('active'),
-               ), __FILE__, __LINE__);
+                       array(
+                               postRequestElement('menu'),
+                               postRequestElement('name'),
+                               postRequestElement('title'),
+                               bigintval(postRequestElement('sort')),
+                               postRequestElement('visible'),
+                               postRequestElement('active'),
+                       ), __FILE__, __LINE__);
        } else {
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (action, title, sort, visible, locked) VALUES ('%s','%s','%s','%s','%s')",
-               array(
-               postRequestElement('name'),
-               postRequestElement('title'),
-               bigintval(postRequestElement('sort')),
-               postRequestElement('visible'),
-               postRequestElement('active'),
-               ), __FILE__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_guest_menu` (`action`, `title`, `sort`, `visible`, `locked`) VALUES ('%s','%s','%s','%s','%s')",
+                       array(
+                               postRequestElement('name'),
+                               postRequestElement('title'),
+                               bigintval(postRequestElement('sort')),
+                               postRequestElement('visible'),
+                               postRequestElement('active'),
+                       ), __FILE__, __LINE__);
        }
        loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_SAVED'));
 } else {
@@ -193,5 +207,5 @@ WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
        loadTemplate('admin_settings_saved', false, getMessage('SETTINGS_NOT_SAVED'));
 }
 
-//
+// [EOF]
 ?>