Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-add_rallye.php
index 12798e889970eb523980b60d6f0bc647a8e8ec23..4424423e8aaf2d5c83fbfda2ac2ef6f95751745e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 06/29/2004 *
- * ================                             Last change: 08/22/2004 *
+ * Mailer v0.2.1-FINAL                                Start: 06/29/2004 *
+ * ===================                          Last change: 08/22/2004 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-add_rallye.php                              *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Neue Ref-Rallye 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 ((!defined('__SECURITY')) || (!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", __FILE__);
+addYouAreHereLink('admin', __FILE__);
 
-if (isset($_POST['ok']))
-{
+if (isFormSent()) {
        // Generate timestamps
-       $START = mktime($_POST['start_hour'], $_POST['start_min'], $_POST['start_sec'], $_POST['start_month'], $_POST['start_day'], $_POST['start_year']);
-       $END   = mktime($_POST['end_hour']  , $_POST['end_min']  , $_POST['end_sec']  , $_POST['end_month']  , $_POST['end_day']  , $_POST['end_year']  );
+       $START = mktime(postRequestElement('start_time_ho'), postRequestElement('start_time_mi'), 0, postRequestElement('start_time_mo'), postRequestElement('start_time_da'), postRequestElement('start_time_ye'));
+       $END   = mktime(postRequestElement('end_time_ho')  , postRequestElement('end_time_mi')  , 0, postRequestElement('end_time_mo')  , postRequestElement('end_time_da')  , postRequestElement('end_time_ye')  );
 
        // Is there already a rallye running?
-       $result = SQL_QUERY_ESC("SELECT id, admin_id FROM `{!_MYSQL_PREFIX!}_rallye_data` WHERE (start_time <= %s AND end_time >= %s) OR (start_time >= %s AND start_time <= %s) LIMIT 1",
-        array($START, $START, $START, $END), __FILE__, __LINE__);
+       $result = sqlQueryEscaped("SELECT `id`, `admin_id` FROM `{?_MYSQL_PREFIX?}_rallye_data` WHERE (`start_time` <= %s AND `end_time` >= %s) OR (`start_time` >= %s AND `start_time` <= %s) LIMIT 1",
+               array($START, $START, $START, $END), __FILE__, __LINE__);
 
-       if (SQL_NUMROWS($result) == 0)
-       {
+       if (ifSqlHasZeroNumRows($result)) {
                // Ok, start and end time did not overlap
-               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_rallye_data` (admin_id, title, descr, template, start_time, end_time, auto_add_new_user, is_active, send_notify)
-VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
- array(
-       GET_CURRENT_ADMIN_ID(),
-       $_POST['title'],
-       $_POST['descr'],
-       $_POST['template'],
-       $START,
-       $END,
-       $_POST['auto_add'],
-       $_POST['active'],
-       $_POST['notify'],
-), __FILE__, __LINE__);
+               sqlQueryEscaped("INSERT INTO
+       `{?_MYSQL_PREFIX?}_rallye_data`
+(
+       `admin_id`,
+       `title`,
+       `descr`,
+       `template`,
+       `start_time`,
+       `end_time`,
+       `auto_add_new_user`,
+       `is_active`,
+       `send_notify`,
+       `min_users`,
+       `min_prices`
+) VALUES (
+       %s,
+       '%s',
+       '%s',
+       '%s',
+       %s,
+       %s,
+       '%s',
+       '%s',
+       '%s',
+       %s,
+       %s
+)",
+                       array(
+                               getCurrentAdminId(),
+                               postRequestElement('title'),
+                               postRequestElement('descr'),
+                               postRequestElement('template'),
+                               $START,
+                               $END,
+                               postRequestElement('auto_add'),
+                               postRequestElement('active'),
+                               postRequestElement('notify'),
+                               bigintval(postRequestElement('min_users')),
+                               bigintval(postRequestElement('min_prices'))
+                       ), __FILE__, __LINE__);
 
-               // Load ID
-               $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_rallye_data` WHERE start_time='%s' AND end_time='%s' AND `title`='%s' LIMIT 1",
-                array($START, $END, $_POST['title']), __FILE__, __LINE__);
-               list($id) = SQL_FETCHROW($result);
-               SQL_FREERESULT($result);
+               // Load id
+               $id = getSqlInsertId();
 
-               if (!empty($id))
-               {
+               if (!empty($id)) {
                        // Reload to prices...
-                       LOAD_URL("modules.php?module=admin&amp;what=config_rallye_prices&rallye=".$id);
-               }
-                else
-               {
+                       redirectToUrl('modules.php?module=admin&amp;what=list_rallye_prices&amp;rallye_id=' . bigintval($id));
+               } else {
                        // Problem detected...
-                       LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_PROBLEM_CREATE);
+                       displayMessage('{--ADMIN_RALLYE_PROBLEM_CREATE--}');
                }
-       }
-        else
-       {
-               // Free memory
-               SQL_FREERESULT($result);
+       } else {
 
                // Overlapping detected
-               LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_OVERLAP_TIMES);
+               displayMessage('{--ADMIN_RALLYE_OVERLAP_TIMES--}');
        }
-}
 
-// Prepare some constants for the template
-define('_AUTO_ADD_OPTIONS', ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
-define('_ACTIVE_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('N','Y'), array(NO , YES)));
-define('_NOTIFY_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
+       // Free memory
+       sqlFreeResult($result);
+} // END - if
 
 // Starting day
-define('_START_SEC'  , ADD_SELECTION("sec"  , "0"              , "start"));
-define('_START_MIN'  , ADD_SELECTION("min"  , "0"              , "start"));
-define('_START_HOUR' , ADD_SELECTION("hour" , date("G", time()), "start"));
-define('_START_DAY'  , ADD_SELECTION("day"  , date("d", time()), "start"));
-define('_START_MONTH', ADD_SELECTION("month", date("m", time()), "start"));
-define('_START_YEAR' , ADD_SELECTION("year" , date('Y', time()), "start"));
+$content['start_min']   = addSelectionBox('mi', 0                   , 'start_time');
+$content['start_hour']  = addSelectionBox('ho', getShortHour()      , 'start_time');
+$content['start_day']   = addSelectionBox('da', getDay()            , 'start_time');
+$content['start_month'] = addSelectionBox('mo', getMonth()          , 'start_time');
+$content['start_year']  = addSelectionBox('ye', getYear()           , 'start_time');
 
-// Calcualte ending date
-$D = date("d", time() + (getConfig('one_day') * 7));
-$M = date("m", time() + (getConfig('one_day') * 7));
-$Y = date('Y', time() + (getConfig('one_day') * 7));
+// Ending timestamp
+$endingStamp = time() + (getOneDay() * 7);
 
 // Ending day
-define('_END_SEC'  , ADD_SELECTION("sec"  , "0"              , "end"));
-define('_END_MIN'  , ADD_SELECTION("min"  , "0"              , "end"));
-define('_END_HOUR' , ADD_SELECTION("hour" , date("G", time()), "end"));
-define('_END_DAY'  , ADD_SELECTION("day"  , $D               , "end"));
-define('_END_MONTH', ADD_SELECTION("month", $M               , "end"));
-define('_END_YEAR' , ADD_SELECTION("year" , $Y               , "end"));
-
-// Transfer (maybe found) templates into constant for the template
-define('_TEMPLATES', RALLYE_TEMPLATE_SELECTION());
+$content['end_min']   = addSelectionBox('mi', 0                     , 'end_time');
+$content['end_hour']  = addSelectionBox('ho', getShortHour()        , 'end_time');
+$content['end_day']   = addSelectionBox('da', getDay($endingStamp)  , 'end_time');
+$content['end_month'] = addSelectionBox('mo', getMonth($endingStamp), 'end_time');
+$content['end_year']  = addSelectionBox('ye', getYear($endingStamp) , 'end_time');
 
 // Load template
-LOAD_TEMPLATE("admin_add_rallye");
+loadTemplate('admin_add_rallye', FALSE, $content);
 
-//
+// [EOF]
 ?>