0cb4d2e5aed861f8f4a74c3ca1ca2fe20e73ae7a
[mailer.git] / inc / modules / admin / what-add_rallye.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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::                                                        $ *
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 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (isFormSent()) {
49         // Generate timestamps
50         $START = mktime(postRequestParameter('start_hour'), postRequestParameter('start_min'), postRequestParameter('start_sec'), postRequestParameter('start_month'), postRequestParameter('start_day'), postRequestParameter('start_year'));
51         $END   = mktime(postRequestParameter('end_hour')  , postRequestParameter('end_min')  , postRequestParameter('end_sec')  , postRequestParameter('end_month')  , postRequestParameter('end_day')  , postRequestParameter('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_HASZERONUMS($result)) {
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                                 getCurrentAdminId(),
63                                 postRequestParameter('title'),
64                                 postRequestParameter('descr'),
65                                 postRequestParameter('template'),
66                                 $START,
67                                 $END,
68                                 postRequestParameter('auto_add'),
69                                 postRequestParameter('active'),
70                                 postRequestParameter('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, postRequestParameter('title')), __FILE__, __LINE__);
76                 list($id) = SQL_FETCHROW($result);
77                 SQL_FREERESULT($result);
78
79                 if (!empty($id)) {
80                         // Reload to prices...
81                         redirectToUrl('modules.php?module=admin&amp;what=config_rallye_prices&amp;rallye='.$id);
82                 } else {
83                         // Problem detected...
84                         loadTemplate('admin_settings_saved', false, getMessage('RALLYE_PROBLEM_CREATE'));
85                 }
86         } else {
87                 // Free memory
88                 SQL_FREERESULT($result);
89
90                 // Overlapping detected
91                 loadTemplate('admin_settings_saved', false, getMessage('RALLYE_OVERLAP_TIMES'));
92         }
93 }
94
95 // Prepare some constants for the template
96 $content['auto_add_options'] = generateOptionList('/ARRAY/', array('Y','N'), array(getMessage('YES'), getMessage('NO') ));
97 $content['active_options']   = generateOptionList('/ARRAY/', array('N','Y'), array(getMessage('NO') , getMessage('YES')));
98 $content['notify_options']   = generateOptionList('/ARRAY/', array('Y','N'), array(getMessage('YES'), getMessage('NO') ));
99
100 // Starting day
101 $content['start_sec']   = addSelectionBox('sec'  , 0              , 'start');
102 $content['start_min']   = addSelectionBox('min'  , 0              , 'start');
103 $content['start_hour']  = addSelectionBox('hour' , date('G', time()), 'start');
104 $content['start_day']   = addSelectionBox('day'  , date('d', time()), 'start');
105 $content['start_month'] = addSelectionBox('month', date('m', time()), 'start');
106 $content['start_year']  = addSelectionBox('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 $content['end_sec']   = addSelectionBox('sec'  , 0              , 'end');
115 $content['end_min']   = addSelectionBox('min'  , 0              , 'end');
116 $content['end_hour']  = addSelectionBox('hour' , date('G', time()), 'end');
117 $content['end_day']   = addSelectionBox('day'  , $D               , 'end');
118 $content['end_month'] = addSelectionBox('month', $M               , 'end');
119 $content['end_year']  = addSelectionBox('year' , $Y               , 'end');
120
121 // Transfer (maybe found) templates into constant for the template
122 $content['templates_selection'] = addReferalRallyeTemplateSelection();
123
124 // Load template
125 loadTemplate('admin_add_rallye', false, $content);
126
127 // [EOF]
128 ?>