Renamed function so it might be more understandable
[mailer.git] / inc / modules / admin / what-config_rallye_prices.php
index 91565cf9e3234575182989391ef1fc3b71645895..90e604af84dcb6f6500dd26f795fd9d942e891a7 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 07/03/2004 *
- * ================                             Last change: 08/22/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 07/03/2004 *
+ * ===================                          Last change: 08/22/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-config_rallye_prices.php                    *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Rallye-Preise einrichten                         *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 // 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);
-}
+if ((!defined('__SECURITY')) || (!isAdmin())) {
+       die();
+} // END - if
+
 // Add description as navigation point
-ADD_DESCR("admin", basename(__FILE__));
+addYouAreHereLink('admin', __FILE__);
 
-if (!empty($_GET['rallye']))
-{
+if (isGetRequestParameterSet('rallye')) {
        // Price submitted?
-       if (isset($_POST['add']))
-       {
-               if ((!empty($_POST['level'])) && ((!empty($_POST['points'])) || (!empty($_POST['info']))))
-               {
+       if (isFormSent('add')) {
+               if ((isPostRequestParameterSet('level')) && ((isPostRequestParameterSet('points')) || (isPostRequestParameterSet('info')))) {
                        // Submitted data is valid, but maybe we already have this price level?
-                       $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d AND price_level='%s' LIMIT 1",
-                        array(bigintval($_GET['rallye']), bigintval($_POST['level'])), __FILE__, __LINE__);
+                       $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s AND `price_level`='%s' LIMIT 1",
+                       array(bigintval(getRequestParameter('rallye')), bigintval(postRequestParameter('level'))), __FILE__, __LINE__);
 
-                       if (SQL_NUMROWS($result) == 0)
-                       {
+                       if (SQL_HASZERONUMS($result)) {
                                // Ok, new price level entered!
-                               $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_rallye_prices (rallye_id, price_level, points, info)
-VALUES ('%s', '%s', '%s', '%s')",
- array(
-       bigintval($_GET['rallye']),
-       bigintval($_POST['level']),
-       $_POST['points'],
-       $_POST['info']
-), __FILE__, __LINE__);
-                               LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_PRICE_LEVEL_SAVED);
-                       }
-                        else
-                       {
+                               SQL_QUERY_ESC("INSERT INTO
+       `{?_MYSQL_PREFIX?}_rallye_prices`
+(`rallye_id`, `price_level`, `points`, `info`)
+       VALUES
+(%s, %s, '%s', '%s')",
+                               array(
+                                       bigintval(getRequestParameter('rallye')),
+                                       bigintval(postRequestParameter('level')),
+                                       postRequestParameter('points'),
+                                       postRequestParameter('info')
+                               ), __FILE__, __LINE__);
+                               loadTemplate('admin_settings_saved', false, '{--RALLYE_PRICE_LEVEL_SAVED--}');
+                       } else {
                                // Free memory
                                SQL_FREERESULT($result);
 
                                // Price level found!
-                               LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_PRICE_ALREADY_FOUND);
+                               loadTemplate('admin_settings_saved', false, '{--RALLYE_PRICE_ALREADY_FOUND--}');
                        }
                }
-       }
-        elseif (isset($_POST['remove']))
-       {
+       } elseif (isFormSent('remove')) {
                // Check if at last one line is selected
-               $SEL = SELECTION_COUNT($_POST['sel']);
-               if ($SEL > 0)
-               {
+               if (ifPostContainsSelections()) {
                        // Delete selected entries
-                       foreach ($_POST['sel'] as $id=>$sel)
-                       {
-                               $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
-                                array(bigintval($id)), __FILE__, __LINE__);
-                       }
+                       foreach (postRequestParameter('sel') as $id => $sel) {
+                               SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
+                                       array(bigintval($id)), __FILE__, __LINE__);
+                       } // END - foreach
 
                        // Output message
-                       LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_DELETED);
-               }
-                else
-               {
-                       LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_NOT_DELETED);
+                       loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_DELETED--}');
+               } else {
+                       loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_NOT_DELETED--}');
                }
-       }
-        elseif (isset($_POST['change']))
-       {
+       } elseif (isFormSent('change')) {
                // Change entries
-               foreach ($_POST['level'] as $id=>$level)
-               {
-                       // Secure ID
+               foreach (postRequestParameter('level') as $id => $level) {
+                       // Secure id
                        $id = bigintval($id);
 
                        // Update entry
-                       $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_rallye_prices SET rallye_id=%d, price_level='%s', points='%s', info='%s' WHERE id=%d LIMIT 1",
-                        array($_POST['rallye_id'][$id], bigintval($level), $_POST['points'][$id], $_POST['infos'][$id], $id), __FILE__, __LINE__);
+                       SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_rallye_prices`
+SET
+       `rallye_id`=%s,
+       `price_level`=%d,
+       `points`=%s,
+       `info`='%s'
+WHERE
+       `id`=%s
+LIMIT 1",
+                               array(
+                                       postRequestParameter('rallye_id', $id),
+                                       bigintval($level),
+                                       postRequestParameter('points', $id),
+                                       postRequestParameter('infos', $id),
+                                       $id
+                               ), __FILE__, __LINE__);
                }
 
                // Output message
-               LOAD_TEMPLATE ("admin_settings_saved", false, RALLYE_ENTRIES_CHANGED);
+               loadTemplate('admin_settings_saved', false, '{--RALLYE_ENTRIES_CHANGED--}');
        }
 
-       if (isset($_POST['edit']))
-       {
+       if (isFormSent('edit')) {
                // Check if at last one line is selected
-               $SEL = SELECTION_COUNT($_POST['sel']);
-               if ($SEL > 0)
-               {
+               if (ifPostContainsSelections()) {
                        // Make selected editable
-                       $SW = 2; $OUT = "";
-                       foreach ($_POST['sel'] as $id=>$sel)
-                       {
+                       $OUT = '';
+                       foreach (postRequestParameter('sel') as $id => $sel) {
                                // Load data to selected rallye
-                               $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
-                                array(bigintval($id)), __FILE__, __LINE__);
-                               list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
+                               $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
+                                       array(bigintval($id)), __FILE__, __LINE__);
+                               $content = SQL_FETCHARRAY($result);
                                SQL_FREERESULT($result);
 
-                               // Prepare data for the row template
-                               $content = array(
-                                       'sw'      => $SW,
-                                       'id'      => $id,
-                                       'rallyes' => ADD_OPTION_LINES("rallye_data", "id", "title", $rallye),
-                                       'level'   => $level,
-                                       'points'  => $points,
-                                       'infos'   => $infos,
-                               );
+                               // Add more content
+                               $content['rallye_content'] = generateOptionList('rallye_data', 'id', 'title', $content['rallye_id']);
 
                                // Load row template and switch color
-                               $OUT .= LOAD_TEMPLATE("admin_config_rallye_edit_row", true, $content);
-                               $SW = 3 - $SW;
-                       }
-                       define('__PRICE_ROWS', $OUT);
+                               $OUT .= loadTemplate('admin_config_rallye_edit_row', true, $content);
+                       } // END - foreach
+
+                       // Remember row content
+                       $content['rows'] = $OUT;
 
                        // Prepare data for the main template
-                       define('__RALLYE_ID', $_GET['rallye']);
+                       $content['rallye'] = getRequestParameter('rallye');
 
                        // Load main template
-                       LOAD_TEMPLATE("admin_config_rallye_edit");
-               }
-                else
-               {
+                       loadTemplate('admin_config_rallye_edit', false, $content);
+               } else {
                        // Nothing selected
-                       $content = RALLYE_NO_PRICES_SELECTED_1."<A href=\"".URL."/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".$_GET['rallye']."\">".RALLYE_NO_PRICES_SELECTED_2."</A>".RALLYE_NO_PRICES_SELECTED_3;
-                       LOAD_TEMPLATE("admin_settings_saved", false, $content);
+                       $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
+                       loadTemplate('admin_settings_saved', false, $content);
                }
-       }
-        elseif (isset($_POST['del']))
-       {
+       } elseif (isFormSent('delete')) {
                // Check if at last one line is selected
-               $SEL = SELECTION_COUNT($_POST['sel']);
-               if ($SEL > 0)
-               {
+               if (ifPostContainsSelections()) {
                        // List all prices
-                       $SW = 2; $OUT = "";
-                       foreach ($_POST['sel'] as $id=>$sel)
-                       {
+                       $OUT = '';
+                       foreach (postRequestParameter('sel') as $id => $sel) {
                                // Load data to selected rallye
-                               $result = SQL_QUERY_ESC("SELECT rallye_id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE id=%d LIMIT 1",
-                                array(bigintval($id)), __FILE__, __LINE__);
-                               list($rallye, $level, $points, $infos) = SQL_FETCHROW($result);
+                               $result = SQL_QUERY_ESC("SELECT `rallye_id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `id`=%s LIMIT 1",
+                                       array(bigintval($id)), __FILE__, __LINE__);
+                               $content = SQL_FETCHARRAY($result);
                                SQL_FREERESULT($result);
 
-                               if (empty($infos)) $infos = "---";
-
-                               // Prepare data for the row template
-                               $content = array(
-                                       'sw'      => $SW,
-                                       'id'      => $id,
-                                       'level'   => $level,
-                                       'points'  => $points,
-                                       'infos'   => $infos,
-                               );
-
                                // Load row template and switch color
-                               $OUT .= LOAD_TEMPLATE("admin_config_rallye_del_row", true, $content);
-                               $SW = 3 - $SW;
-                       }
-                       define('__PRICE_ROWS', $OUT);
+                               $OUT .= loadTemplate('admin_config_rallye_del_row', true, $content);
+                       } // END - foreach
+                       $content['rows'] = $OUT;
 
                        // Prepare data for the main template
-                       define('__RALLYE_ID', $_GET['rallye']);
+                       $content['rallye'] = getRequestParameter('rallye');
 
                        // Load main template
-                       LOAD_TEMPLATE("admin_config_rallye_del");
-               }
-                else
-               {
+                       loadTemplate('admin_config_rallye_del', false, $content);
+               } else {
                        // Nothing selected
-                       $content = RALLYE_NO_PRICES_SELECTED_1."<A href=\"".URL."/modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=".$_GET['rallye']."\">".RALLYE_NO_PRICES_SELECTED_2."</A>".RALLYE_NO_PRICES_SELECTED_3;
-                       LOAD_TEMPLATE("admin_settings_saved", false, $content);
+                       $content = '{--RALLYE_NO_PRICES_SELECTED_1--}<a href="{%url=modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye=' . getRequestParameter('rallye') . '%}">{--RALLYE_NO_PRICES_SELECTED_2--}</a>{--RALLYE_NO_PRICES_SELECTED_3--}';
+                       loadTemplate('admin_settings_saved', false, $content);
                }
-       }
-        else
-       {
-               // A rallye was selected, so check if there are already prices assigned...
-               $result = SQL_QUERY_ESC("SELECT id, price_level, points, info FROM "._MYSQL_PREFIX."_rallye_prices WHERE rallye_id=%d ORDER BY price_level",
-                array(bigintval($_GET['rallye'])), __FILE__, __LINE__);
+       } else {
+               // a rallye was selected, so check if there are already prices assigned...
+               $result = SQL_QUERY_ESC("SELECT `id`, `price_level`, `points`, `info` FROM `{?_MYSQL_PREFIX?}_rallye_prices` WHERE `rallye_id`=%s ORDER BY `price_level` ASC",
+                       array(bigintval(getRequestParameter('rallye'))), __FILE__, __LINE__);
 
-               if (SQL_NUMROWS($result) > 0)
-               {
+               if (!SQL_HASZERONUMS($result)) {
                        // Load all prices for the selected rallye
-                       $SW = 2; $OUT = "";
-                       while(list($id, $level, $points, $infos) = SQL_FETCHROW($result))
-                       {
-                               if (empty($infos)) $infos = "---";
-
-                               // Prepare data for the row template
-                               $content = array(
-                                       'sw'      => $SW,
-                                       'id'      => $id,
-                                       'level'   => $level,
-                                       'points'  => $points,
-                                       'infos'   => $infos,
-                               );
-
+                       $OUT = '';
+                       while ($content = SQL_FETCHARRAY($result)) {
                                // Load row template and switch color
-                               $OUT .= LOAD_TEMPLATE("admin_config_rallye_prices_row", true, $content);
-                               $SW = 3 - $SW;
-                       }
+                               $OUT .= loadTemplate('admin_config_rallye_prices_row', true, $content);
+                       } // END - while
 
                        // Free memory
                        SQL_FREERESULT($result);
-                       define('__PRICE_ROWS', $OUT);
+
+                       // @TODO Rewrite these two constants
+                       $content['rows'] = $OUT;
 
                        // Prepare data for the main template
-                       define('__RALLYE_ID', $_GET['rallye']);
+                       $content['rallye'] = getRequestParameter('rallye');
 
                        // Load main template
-                       LOAD_TEMPLATE("admin_config_rallye_prices");
-               }
+                       loadTemplate('admin_config_rallye_prices', false, $content);
+               } // END - if
        }
 
        // Add form for adding new price level
-       if (empty($_POST['edit']))
-       {
-               LOAD_TEMPLATE("admin_add_rallye_prices", false, $_GET['rallye']);
-       }
-}
- else
-{
+       if (!isFormSent('edit')) {
+               loadTemplate('admin_add_rallye_prices', false, getRequestParameter('rallye'));
+       } // END - if
+} else {
        // No rallye selected so display all available without prices
-       $result = SQL_QUERY("SELECT d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
-FROM "._MYSQL_PREFIX."_rallye_data AS d, "._MYSQL_PREFIX."_admins AS a
-WHERE d.admin_id=a.id ORDER BY start_time DESC", __FILE__, __LINE__);
-       if (SQL_NUMROWS($result) > 0)
-       {
+       $result = SQL_QUERY("SELECT
+       d.id, d.admin_id, d.start_time, d.end_time, d.title, a.login, d.is_active
+FROM
+       `{?_MYSQL_PREFIX?}_rallye_data` AS d
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_admins` AS a
+ON
+       d.admin_id=a.id
+ORDER BY
+       d.start_time DESC", __FILE__, __LINE__);
+       if (!SQL_HASZERONUMS($result)) {
                // List found rallyes
-               $SW = 2; $OUT = "";
-               while (list($id, $aid, $start, $end, $title, $alogin, $active) = SQL_FETCHROW($result))
-               {
-                       $select = "<INPUT type=\"checkbox\" name=\"sel[".$id."]\" class=\"admin_normal\" value=\"1\">";
-                       if ($active == 'Y') $select = "<STRONG class=\"big\">".$id."</STRONG>";
-
+               $OUT = '';
+               while ($content = SQL_FETCHARRAY($result)) {
                        // Prepare data for the row template
                        $content = array(
-                               'sw'         => $SW,
-                               'id'         => $id,
-                               'select'     => $select,
-                               'title'      => $title,
-                               'aid'        => $aid,
-                               'email_link' => CREATE_EMAIL_LINK($aid),
-                               'alogin'     => $alogin,
-                               'start'      => MAKE_DATETIME($start, "3"),
-                               'end'        => MAKE_DATETIME($end, "3"),
+                               'id'         => $content['id'],
+                               'title'      => $content['title'],
+                               'admin_id'   => $content['admin_id'],
+                               'login'      => $content['login'],
+                               'start'      => generateDateTime($content['start_time'], 3),
+                               'end'        => generateDateTime($content['end_time'], 3),
                        );
 
                        // Load row template and switch color
-                       $OUT .= LOAD_TEMPLATE("admin_list_rallye_prices_row", true, $content);
-                       $SW = 3 - $SW;
-               }
+                       $OUT .= loadTemplate('admin_list_rallye_prices_row', true, $content);
+               } // END - while
 
                // Free memory
                SQL_FREERESULT($result);
-               define('__RALLYE_ROWS', $OUT);
 
                // Load main template
-               LOAD_TEMPLATE("admin_list_rallye_prices");
-       }
-        else
-       {
+               loadTemplate('admin_list_rallye_prices', false, $OUT);
+       } else {
                // No rallyes setup so far
-               LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_NO_RALLYES_SETUP);
+               loadTemplate('admin_settings_saved', false, '{--RALLYE_NO_RALLYES_SETUP--}');
        }
 }
-//
+
+// [EOF]
 ?>