ccb2d887cbbed7acbb321fc1d534ea347be0a12d
[mailer.git] / inc / modules / admin / what-add_rallye.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 06/29/2004 *
4  * ================                             Last change: 08/22/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-add_rallye.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Add new rallye                                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Neue Ref-Rallye einfuegen                        *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 if (IS_FORM_SENT()) {
44         // Generate timestamps
45         $START = mktime(REQUEST_POST('start_hour'), REQUEST_POST('start_min'), REQUEST_POST('start_sec'), REQUEST_POST('start_month'), REQUEST_POST('start_day'), REQUEST_POST('start_year'));
46         $END   = mktime(REQUEST_POST('end_hour')  , REQUEST_POST('end_min')  , REQUEST_POST('end_sec')  , REQUEST_POST('end_month')  , REQUEST_POST('end_day')  , REQUEST_POST('end_year')  );
47
48         // Is there already a rallye running?
49         $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",
50                 array($START, $START, $START, $END), __FILE__, __LINE__);
51
52         if (SQL_NUMROWS($result) == 0) {
53                 // Ok, start and end time did not overlap
54                 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)
55 VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
56  array(
57         GET_CURRENT_ADMIN_ID(),
58         REQUEST_POST('title'),
59         REQUEST_POST('descr'),
60         REQUEST_POST('template'),
61         $START,
62         $END,
63         REQUEST_POST('auto_add'),
64         REQUEST_POST('active'),
65         REQUEST_POST('notify'),
66 ), __FILE__, __LINE__);
67
68                 // Load ID
69                 $result = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_rallye_data` WHERE start_time='%s' AND end_time='%s' AND `title`='%s' LIMIT 1",
70                  array($START, $END, REQUEST_POST('title')), __FILE__, __LINE__);
71                 list($id) = SQL_FETCHROW($result);
72                 SQL_FREERESULT($result);
73
74                 if (!empty($id)) {
75                         // Reload to prices...
76                         LOAD_URL("modules.php?module=admin&amp;what=config_rallye_prices&rallye=".$id);
77                 } else {
78                         // Problem detected...
79                         LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_PROBLEM_CREATE);
80                 }
81         } else {
82                 // Free memory
83                 SQL_FREERESULT($result);
84
85                 // Overlapping detected
86                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_OVERLAP_TIMES);
87         }
88 }
89
90 // Prepare some constants for the template
91 define('_AUTO_ADD_OPTIONS', ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
92 define('_ACTIVE_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('N','Y'), array(NO , YES)));
93 define('_NOTIFY_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
94
95 // Starting day
96 define('_START_SEC'  , ADD_SELECTION("sec"  , "0"              , "start"));
97 define('_START_MIN'  , ADD_SELECTION("min"  , "0"              , "start"));
98 define('_START_HOUR' , ADD_SELECTION("hour" , date("G", time()), "start"));
99 define('_START_DAY'  , ADD_SELECTION("day"  , date("d", time()), "start"));
100 define('_START_MONTH', ADD_SELECTION("month", date("m", time()), "start"));
101 define('_START_YEAR' , ADD_SELECTION("year" , date('Y', time()), "start"));
102
103 // Calcualte ending date
104 $D = date("d", time() + (getConfig('one_day') * 7));
105 $M = date("m", time() + (getConfig('one_day') * 7));
106 $Y = date('Y', time() + (getConfig('one_day') * 7));
107
108 // Ending day
109 define('_END_SEC'  , ADD_SELECTION("sec"  , "0"              , "end"));
110 define('_END_MIN'  , ADD_SELECTION("min"  , "0"              , "end"));
111 define('_END_HOUR' , ADD_SELECTION("hour" , date("G", time()), "end"));
112 define('_END_DAY'  , ADD_SELECTION("day"  , $D               , "end"));
113 define('_END_MONTH', ADD_SELECTION("month", $M               , "end"));
114 define('_END_YEAR' , ADD_SELECTION("year" , $Y               , "end"));
115
116 // Transfer (maybe found) templates into constant for the template
117 define('_TEMPLATES', RALLYE_TEMPLATE_SELECTION());
118
119 // Load template
120 LOAD_TEMPLATE("admin_add_rallye");
121
122 //
123 ?>