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