]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/what-admin_add.php
A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[mailer.git] / inc / modules / admin / what-admin_add.php
index 23849f3a724e80faafad53bf03db475ea6974f99..fe314901936ed66a2e4a11b1f069094dcb9fd4d5 100644 (file)
@@ -41,36 +41,35 @@ if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
 ADD_DESCR("admin", __FILE__);
 
 // Check if the admin has entered title and what-php file name...
-if (((empty($_POST['title'])) || (empty($_POST['menu'])) || (empty($_POST['descr']))) && (isset($_POST['ok']))) {
-       unset($_POST['ok']);
+if (((!REQUEST_ISSET_POST(('title'))) || (!REQUEST_ISSET_POST(('menu'))) || (!REQUEST_ISSET_POST(('descr')))) && (IS_FORM_SENT())) {
+       REQUEST_UNSET_POST('ok');
 }
 
-if (!isset($_POST['ok']))
+if (!IS_FORM_SENT())
 {
        // Create arrays
        $menus = array(); $titles = array(); $below = array();
 
        // Get all available main menus
        $result = SQL_QUERY("SELECT action, title, sort FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE (what='' OR `what` IS NULL) ORDER BY `sort`", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       if (SQL_NUMROWS($result) > 0) {
                // Read menu structure
-               while (list($act, $title, $sort) = SQL_FETCHROW($result))
-               {
+               while ($content = SQL_FETCHARRAY($result)) {
                        // Menu actions
-                       $menus[] = $act;
+                       $menus[] = $content['action'];
 
                        // Menu titles
-                       $titles[] = $title;
+                       $titles[] = $content['title'];
 
                        // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
-                       $below[] = $sort + 1;
-               }
+                       $below[] = $content['sort'] + 1;
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
 
                // Remove double eintries
+               // @TODO This can be somehow rewritten to a function
                $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
                foreach ($menus as $key => $value)
                {
@@ -87,47 +86,45 @@ if (!isset($_POST['ok']))
                }
                $menus = $dmy; $titles = $dmy2; $below = $dmy3;
                // Load sub menus :)
-               foreach ($menus as $key_main => $value_main)
-               {
-                       $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE action='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
-                        array($value_main), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) > 0)
-                       {
+               foreach ($menus as $key_main => $value_main) {
+                       $result = SQL_QUERY_ESC("SELECT what, title, sort FROM `{!_MYSQL_PREFIX!}_admin_menu` WHERE `action`='%s' AND `what` != '' AND `what` IS NOT NULL ORDER BY `sort`",
+                               array($value_main), __FILE__, __LINE__);
+                       if (SQL_NUMROWS($result) > 0) {
+                               // Init arrays
                                $menus[$value_main] = array();
                                $titles[$value_main] = array();
                                $below[$value_main] = array();
+
                                // Read menu structure
-                               while (list($act, $title, $sort) = SQL_FETCHROW($result))
-                               {
+                               while ($content = SQL_FETCHROW($result)) {
                                        // Menu actions
-                                       $menus[$value_main][] = $act;
+                                       $menus[$value_main][] = $content['action'];
 
                                        // Menu titles
-                                       $titles[$value_main][] = $title;
+                                       $titles[$value_main][] = $content['title'];
 
                                        // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
-                                       $below[$value_main][] = $sort + 1;
-                               }
+                                       $below[$value_main][] = $content['sort'] + 1;
+                               } // END - while
 
                                // Free memory
                                SQL_FREERESULT($result);
 
                                // Remove double eintries
+                               // @TODO This can be somehow rewritten to a function
                                $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
-                               foreach ($menus[$value_main] as $key => $value)
-                               {
-                                       if ($value == $prev)
-                                       {
+                               foreach ($menus[$value_main] as $key => $value) {
+                                       if ($value == $prev) {
                                                unset($dmy[$key]);
                                                unset($dmy2[$key]);
                                                unset($dmy3[$key]);
-                                       }
-                                        else
-                                       {
+                                       } else {
                                                $prev = $value;
                                        }
                                }
-                               $menus[$value_main] = $dmy; $titles[$value_main] = $dmy2; $below[$value_main] = $dmy3;
+                               $menus[$value_main] = $dmy;
+                               $titles[$value_main] = $dmy2;
+                               $below[$value_main] = $dmy3;
                        }
                }
        }
@@ -163,41 +160,34 @@ if (!isset($_POST['ok']))
 
        // Display form
        LOAD_TEMPLATE("admin_admin_add");
-}
- elseif (!IS_DEMO())
-{
+} elseif (!IS_DEMO()) {
        // Insert new menu entry
-       if (!empty($_POST['menu']))
-       {
+       if (REQUEST_ISSET_POST(('menu'))) {
                // Add sub menu
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (`action`,`what`,`title`,`descr`,`sort`) VALUES ('%s','%s','%s','%s','%s')",
                        array(
-                               $_POST['menu'],
-                               $_POST['name'],
-                               $_POST['title'],
-                               $_POST['descr'],
-                               bigintval($_POST['sort']),
+                               REQUEST_POST('menu'),
+                               REQUEST_POST('name'),
+                               REQUEST_POST('title'),
+                               REQUEST_POST('descr'),
+                               bigintval(REQUEST_POST('sort')),
                        ), __FILE__, __LINE__
                );
-               CACHE_PURGE_ADMIN_MENU(0, $_POST['menu'], $_POST['name']);
-       }
-        else
-       {
+               CACHE_PURGE_ADMIN_MENU(0, REQUEST_POST('menu'), REQUEST_POST('name'));
+       } else {
                // Add main menu
                SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admin_menu` (action, title, descr, sort) VALUES ('%s','%s','%s','%s')",
                        array(
-                               $_POST['name'],
-                               $_POST['title'],
-                               $_POST['descr'],
-                               bigintval($_POST['sort']),
+                               REQUEST_POST('name'),
+                               REQUEST_POST('title'),
+                               REQUEST_POST('descr'),
+                               bigintval(REQUEST_POST('sort')),
                        ), __FILE__, __LINE__
                );
-               CACHE_PURGE_ADMIN_MENU(0, $_POST['name']);
+               CACHE_PURGE_ADMIN_MENU(0, REQUEST_POST('name'));
        }
        LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_SAVED'));
-}
- else
-{
+} else {
        // Is demo login!
        LOAD_TEMPLATE("admin_settings_saved", false, getMessage('SETTINGS_NOT_SAVED'));
 }