Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-guest_add.php
index 7e392e0..b17b369 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/28/2003 *
- * ===============                              Last change: 12/13/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 09/28/2003 *
+ * ===================                          Last change: 12/13/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-guest_add.php                               *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Einen neuen Gastmenuepunkt einfuegen             *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  ************************************************************************/
 
 // Some security stuff...
-if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!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__));
-OUTPUT_HTML ("</FONT><BR>");
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
 
-OPEN_TABLE("100%", "admin_content admin_content_align", "");
+// Add description as navigation point
+addYouAreHereLink('admin', __FILE__);
 
 // Check if the admin has entered title and what-php file name...
-if (((empty($_POST['title'])) || (empty($_POST['menu']))) && (isset($_POST['ok'])))
-{
-       unset($_POST['ok']);
-}
+if (((!isPostRequestElementSet('title')) || (!isPostRequestElementSet('menu'))) && (isFormSent())) {
+       // Abort adding the menu entry
+       unsetPostRequestElement('ok');
+} // END - if
 
-if (!isset($_POST['ok']))
-{
+if (!isFormSent()) {
        // Create arrays
        $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='' ORDER BY sort", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       $result_menu = sqlQuery("SELECT
+       `action`, `title`, `sort`
+FROM
+       `{?_MYSQL_PREFIX?}_guest_menu`
+WHERE
+       (`what`='' OR `what` IS NULL)
+ORDER BY
+       `sort` ASC", __FILE__, __LINE__);
+
+       if (!ifSqlHasZeroNumRows($result_menu)) {
                // Read menu structure
-               while (list($act, $title, $sort) = SQL_FETCHROW($result))
-               {
+               // @TODO Cant this be rewritten?
+               while ($content = sqlFetchArray($result_menu)) {
                        // Menu actions
-                       $menus[] = $act;
+                       array_push($menus, $content['action']);
 
                        // Menu titles
-                       $titles[] = $title;
+                       array_push($titles, $content['title']);
 
                        // Below this menu point should the new be added so we simply increase the sort value by 1 :-)
-                       $below[] = $sort + 1;
-               }
-
-               // Free memory
-               SQL_FREERESULT($result);
+                       array_push($below, $content['sort'] + 1);
+               } // END - while
 
                // Remove double eintries
-               $prev = ""; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
-               foreach ($menus as $key=>$value)
-               {
-                       if ($value == $prev)
-                       {
+               // @TODO This can be somehow rewritten to a function
+               $prev = ''; $dmy = $menus; $dmy2 = $titles; $dmy3 = $below;
+               foreach ($menus as $key => $value) {
+                       if ($value == $prev) {
                                unset($dmy[$key]);
                                unset($dmy2[$key]);
                                unset($dmy3[$key]);
-                       }
-                        else
-                       {
+                       } else {
                                $prev = $value;
                        }
                }
-               $menus = $dmy; $titles = $dmy2; $below = $dmy3;
+
+               // Init variables
+               $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."_guest_menu
-WHERE action='%s' AND what != '' ORDER BY sort",
- array(bigintval($value_main)), __FILE__, __LINE__);
-                       if (SQL_NUMROWS($result) > 0)
-                       {
+               foreach ($menus as $key_main => $value_main) {
+                       // Query for sub menus
+                       $result = sqlQueryEscaped("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 (!ifSqlHasZeroNumRows($result)) {
                                // Initialize 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 = sqlFetchArray($result)) {
                                        // Menu actions
-                                       $menus[$value_main][] = $act;
+                                       array_push($menus[$value_main], $content['what']);
 
                                        // Menu titles
-                                       $titles[$value_main][] = $title;
+                                       array_push($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;
-                               }
-
-                               // Free memory
-                               SQL_FREERESULT($result);
+                                       array_push($below[$value_main], $content['sort'] + 1);
+                               } // END - while
 
                                // Remove double eintries
-                               $prev = ""; $dmy = $menus[$value_main]; $dmy2 = $titles[$value_main]; $dmy3 = $below[$value_main];
-                               foreach ($menus[$value_main] as $key=>$value)
-                               {
-                                       if ($value == $prev)
-                                       {
+                               // @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) {
                                                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;
-                       }
-               }
-       }
-
-       $OUT = "    <SELECT class=\"admin_select\" name=\"sort\" size=\"1\">
-      <OPTION value=\"0\">".IS_FIRST_MENU."</OPTION>";
-       foreach ($below as $key=>$m)
-       {
-               if (is_array($m))
-               {
-                       foreach ($m as $key2=>$m2)
-                       {
-                               $OUT .= "      <OPTION value=\"".$m2."\">".$titles[$key][$key2];
-                               foreach ($menus as $k=>$v)
-                               {
-                                       if (($v == $key) && (!is_array($v)))
-                                       {
-                                               $OUT .= " (".$titles[$k].")";
+                               } // END - foreach
+
+                               // Transfer dummy array
+                               $menus[$value_main] = $dmy;
+                               $titles[$value_main] = $dmy2;
+                               $below[$value_main] = $dmy3;
+                       } // END - if
+
+                       // Free memory
+                       sqlFreeResult($result);
+               } // END - foreach
+       } // END - if
+
+       // Free memory
+       sqlFreeResult($result_menu);
+
+       $OUT = '<select class="form_select" name="sort" size="1">
+      <option value="0">{--ADMIN_IS_FIRST_MENU--}</option>';
+       foreach ($below as $key => $m) {
+               if (is_array($m)) {
+                       foreach ($m as $key2 => $m2) {
+                               $OUT .= '<option value="' . $m2 . '">' . $titles[$key][$key2];
+                               foreach ($menus as $k => $v) {
+                                       if (($v == $key) && (!is_array($v))) {
+                                               $OUT .= ' (' . $titles[$k] . ')';
                                        }
                                }
-                               $OUT .= "</OPTION>\n";
+                               $OUT .= '</option>';
                        }
-               }
-                else
-               {
-                       $OUT .= "      <OPTION value=\"".$m."\">".$titles[$key]."</OPTION>\n";
+               } else {
+                       $OUT .= '<option value="' . $m . '">' . $titles[$key] . '</option>';
                }
        }
-       $OUT .= "</SELECT>";
+       $OUT .= '</select>';
 
-       define('__BELOW_SELECTION' , $OUT);
-       define('__WHAT_SELECTION'  , ADMIN_MAKE_MENU_SELECTION("guest", "what", "name"));
-       define('__ACTION_SELECTION', ADMIN_MAKE_MENU_SELECTION("guest", "action", "menu"));
+       // Prepare selections for template
+       $content['below_selection']  = $OUT;
+       $content['what_selection']   = adminAddMenuSelectionBox('guest', 'what'  , 'name');
+       $content['action_selection'] = adminAddMenuSelectionBox('guest', 'action', 'menu');
 
        // Display form
-       LOAD_TEMPLATE("admin_guest_add");
-}
- elseif (!IS_DEMO())
-{
+       loadTemplate('admin_add_guest_menu', FALSE, $content);
+} elseif (!isDemoModeActive()) {
        // Insert new menu entry
-       if (!empty($_POST['menu']))
-       {
-               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_guest_menu
-(action, what, title, sort, visible, locked)
-VALUES('%s', '%s', '%s', '%s', '%s', '%s')",
- array(
-       $_POST['menu'],
-       $_POST['name'],
-       $_POST['title'],
-       bigintval($_POST['sort']),
-       $_POST['visible'],
-       $_POST['active'],
-), __FILE__, __LINE__);
+       if (isPostRequestElementSet('menu')) {
+               sqlQueryEscaped("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__);
+       } else {
+               sqlQueryEscaped("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__);
        }
-        else
-       {
-               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_guest_menu
-(action, title, sort, visible, locked)
-VALUES('%s', '%s', '%s', '%s', '%s')",
- array(
-       $_POST['name'],
-       $_POST['title'],
-       bigintval($_POST['sort']),
-       $_POST['visible'],
-       $_POST['active'],
-), __FILE__, __LINE__);
-       }
-       LOAD_TEMPLATE("admin_settings_saved", false, SAVING_DONE);
-}
- else
-{
+       displayMessage('{--SETTINGS_SAVED--}');
+} else {
        // Demo mode!
-       LOAD_TEMPLATE("admin_settings_saved", false, SETTINGS_NOT_SAVED);
+       displayMessage('{--SETTINGS_NOT_SAVED--}');
 }
 
-CLOSE_TABLE();
-//
+// [EOF]
 ?>