1eb0f2f44879818f9c17b18d817311e0f6497414
[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", basename(__FILE__));
42
43 if (isset($_POST['ok']))
44 {
45         // Generate timestamps
46         $START = mktime($_POST['start_hour'], $_POST['start_min'], $_POST['start_sec'], $_POST['start_month'], $_POST['start_day'], $_POST['start_year']);
47         $END   = mktime($_POST['end_hour']  , $_POST['end_min']  , $_POST['end_sec']  , $_POST['end_month']  , $_POST['end_day']  , $_POST['end_year']  );
48
49         // Is there already a rallye running?
50         $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",
51          array($START, $START, $START, $END), __FILE__, __LINE__);
52
53         if (SQL_NUMROWS($result) == 0)
54         {
55                 // Ok, start and end time did not overlap
56                 $result = 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)
57 VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')",
58  array(
59         GET_ADMIN_ID(get_session('admin_login')),
60         $_POST['title'],
61         $_POST['descr'],
62         $_POST['template'],
63         $START,
64         $END,
65         $_POST['auto_add'],
66         $_POST['active'],
67         $_POST['notify'],
68 ), __FILE__, __LINE__);
69
70                 // Load ID
71                 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_rallye_data WHERE start_time='%s' AND end_time='%s' AND title='%s' LIMIT 1",
72                  array($START, $END, $_POST['title']), __FILE__, __LINE__);
73                 list($id) = SQL_FETCHROW($result);
74                 SQL_FREERESULT($result);
75
76                 if (!empty($id))
77                 {
78                         // Reload to prices...
79                         LOAD_URL("modules.php?module=admin&amp;what=config_rallye_prices&rallye=".$id);
80                 }
81                  else
82                 {
83                         // Problem detected...
84                         LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_PROBLEM_CREATE);
85                 }
86         }
87          else
88         {
89                 // Free memory
90                 SQL_FREERESULT($result);
91
92                 // Overlapping detected
93                 LOAD_TEMPLATE("admin_settings_saved", false, RALLYE_OVERLAP_TIMES);
94         }
95 }
96
97 // Prepare some constants for the template
98 define('_AUTO_ADD_OPTIONS', ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
99 define('_ACTIVE_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('N','Y'), array(NO , YES)));
100 define('_NOTIFY_OPTIONS'  , ADD_OPTION_LINES("/ARRAY/", array('Y','N'), array(YES, NO )));
101
102 // Starting day
103 define('_START_SEC'  , ADD_SELECTION("sec"  , "0"              , "start"));
104 define('_START_MIN'  , ADD_SELECTION("min"  , "0"              , "start"));
105 define('_START_HOUR' , ADD_SELECTION("hour" , date("G", time()), "start"));
106 define('_START_DAY'  , ADD_SELECTION("day"  , date("d", time()), "start"));
107 define('_START_MONTH', ADD_SELECTION("month", date("m", time()), "start"));
108 define('_START_YEAR' , ADD_SELECTION("year" , date('Y', time()), "start"));
109
110 // Calcualte ending date
111 $D = date("d", time() + ($_CONFIG['one_day'] * 7));
112 $M = date("m", time() + ($_CONFIG['one_day'] * 7));
113 $Y = date('Y', time() + ($_CONFIG['one_day'] * 7));
114
115 // Ending day
116 define('_END_SEC'  , ADD_SELECTION("sec"  , "0"              , "end"));
117 define('_END_MIN'  , ADD_SELECTION("min"  , "0"              , "end"));
118 define('_END_HOUR' , ADD_SELECTION("hour" , date("G", time()), "end"));
119 define('_END_DAY'  , ADD_SELECTION("day"  , $D               , "end"));
120 define('_END_MONTH', ADD_SELECTION("month", $M               , "end"));
121 define('_END_YEAR' , ADD_SELECTION("year" , $Y               , "end"));
122
123 // Transfer (maybe found) templates into constant for the template
124 define('_TEMPLATES', RALLYE_TEMPLATE_SELECTION());
125
126 // Load template
127 LOAD_TEMPLATE("admin_add_rallye");
128
129 //
130 ?>