2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/24/2004 *
4 * =================== Last change: 07/31/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-holiday.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Holiday requests *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Urlaubsschaltungen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
43 } elseif (!isMember()) {
44 redirectToIndexMemberOnlyModule();
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
50 if ((!isExtensionActive('holiday')) && (!isAdmin())) {
51 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('holiday'));
58 // Check for running mail orders in pool
59 $result1 = SQL_QUERY_ESC("SELECT
62 `{?_MYSQL_PREFIX?}_pool`
67 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
69 // Check for sent mail orders in stats
70 $result2 = SQL_QUERY_ESC("SELECT
73 `{?_MYSQL_PREFIX?}_user_stats`
77 `timestamp_ordered` DESC
78 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
80 if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) {
82 $content = merge_array($content, SQL_FETCHARRAY($result1));
83 $content = merge_array($content, SQL_FETCHARRAY($result2));
85 // Fix missing entries
86 if (empty($content['timestamp'])) $content['timestamp'] = '0';
87 if (empty($content['timestamp_ordered'])) $content['timestamp_ordered'] = '0';
89 if ((($content['timestamp'] + getConfig('holiday_lock')) > time()) || (($content['timestamp_ordered'] + getConfig('holiday_lock')) > time())) {
90 // Mail order is to close away!
91 unsetPostRequestParameter('ok');
92 unsetPostRequestParameter('stop');
94 if (($content['timestamp'] + getConfig('holiday_lock')) > time()) {
96 $stamp = $content['timestamp'];
98 // Mail found in stats
99 $stamp = $content['timestamp_ordered'];
102 // Display message and exit here
103 loadTemplate('admin_settings_saved', false, getMaskedMessage('HOLIDAY_MEMBER_ORDER', generateDateTime($stamp, 1)));
109 SQL_FREERESULT($result1);
110 SQL_FREERESULT($result2);
113 // Check holiday request...
114 $START = mktime(0, 0, 0, postRequestParameter('start_month'), postRequestParameter('start_day'), postRequestParameter('start_year'));
115 $content['holiday_end'] = mktime(0, 0, 0, postRequestParameter('end_month') , postRequestParameter('end_day') , postRequestParameter('end_year') );
118 $TEST = $content['holiday_end'] - $START;
119 if (($TEST < 0) || ($TEST > (getConfig('ONE_DAY') * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) {
121 unsetPostRequestParameter('ok');
123 // Everything went okay so let's store his request and send mails
124 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_holidays` (`userid`, `holiday_start`, `holiday_end`, `comments`) VALUES ('%s','%s','%s','%s')",
125 array(getMemberId(), $START, $content['holiday_end'], postRequestParameter('comments')), __FILE__, __LINE__);
127 // Activate holiday system
128 SQL_QUERY_ESC("UPDATE
129 `{?_MYSQL_PREFIX?}_user_data`
131 `holiday_active`='N', `holiday_activated`=UNIX_TIMESTAMP()
135 array(getMemberId()), __FILE__, __LINE__);
138 $content['start_day'] = bigintval(postRequestParameter('start_day'));
139 $content['start_month'] = $GLOBALS['month_descr'][postRequestParameter('start_month')];
140 $content['start_year'] = bigintval(postRequestParameter('start_year'));
141 $content['end_day'] = bigintval(postRequestParameter('end_day'));
142 $content['end_month'] = $GLOBALS['month_descr'][postRequestParameter('end_month')];
143 $content['end_year'] = bigintval(postRequestParameter('end_year'));
144 $content['comments'] = secureString(postRequestParameter('comments'));
146 // Send mail to member
147 $message = loadEmailTemplate('member_holiday_request', $content, getMemberId());
148 sendEmail(getMemberId(), '{--HOLIDAY_MEMBER_SUBJECT--}', $message);
150 // Send mail to all admins
151 sendAdminNotification('{--ADMIN_HOLIDAY_SUBJECT--}', 'admin_holiday_request', $content, getMemberId());
153 // Create task (we ignore the task id here)
154 createNewTask('{--ADMIN_HOLIDAY_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId());
157 loadTemplate('admin_settings_saved', false, '{--HOLIDAY_IS_ACTIVATED_NOW--}');
161 // Holiday shall be ended now
162 if (isPostRequestParameterSet('stop')) {
163 // Okay, end the holiday here...
164 $result = SQL_QUERY_ESC("SELECT
165 `holiday_active`, `holiday_activated`
167 `{?_MYSQL_PREFIX?}_user_data`
170 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
172 // Do we have an entry?
173 if (SQL_NUMROWS($result) == 1) {
175 $content = merge_array($content, SQL_FETCHARRAY($result));
177 if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
179 $result2 = SQL_QUERY_ESC("SELECT
180 `holiday_start`, `holiday_end`
182 `{?_MYSQL_PREFIX?}_user_holidays`
185 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
186 if (SQL_NUMROWS($result2) == 1) {
187 // Data was found so merge it
188 $content = merge_array($content, SQL_FETCHARRAY($result2));
190 // Prepare it for the template
191 $content['start'] = generateDateTime($content['holiday_start'], 3);
192 $content['end'] = generateDateTime($content['holiday_end'] , 3);
195 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
197 `holiday_active`='N',
198 `holiday_activated`=0
202 array(getMemberId()), __FILE__, __LINE__);
205 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
206 `{?_MYSQL_PREFIX?}_user_holidays`
210 array(getMemberId()), __FILE__, __LINE__);
212 // Send email to admin
213 sendAdminNotification('{--ADMIN_HOLIDAY_DEAC_SUBJECT--}', 'admin_holiday_deactivated', $content, getMemberId());
215 // Display message to user
216 loadTemplate('admin_settings_saved', false, '{--HOLIDAY_MEMBER_DEACTIVATED_NOW--}');
218 // Display message to user
219 loadTemplate('admin_settings_saved', false, '{--HOLIDAY_MEMBER_CANNOT_DEACTIVATE--}');
223 SQL_FREERESULT($result2);
224 } elseif ($content['holiday_active'] == 'Y') {
226 loadTemplate('admin_settings_saved', false, '{--HOLIDAY_MEMBER_LOCKED--}');
230 loadTemplate('admin_settings_saved', false, getMaskedMessage('HOLIDAY_MEMBER_NOT_STOPPED_404', getMemberId()));
234 SQL_FREERESULT($result);
237 // If something is wrong or link in menu is just clicked display form
238 if ((!isFormSent()) && (!isPostRequestParameterSet('stop'))) {
239 // Check if user is in holiday...
240 $result = SQL_QUERY_ESC("SELECT
241 `holiday_active`, `holiday_activated`
243 `{?_MYSQL_PREFIX?}_user_data`
246 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
247 $content = SQL_FETCHARRAY($result);
248 SQL_FREERESULT($result);
251 if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
252 // User can deactivate his holiday request
253 switch ($content['holiday_active'])
255 case 'Y': // Display deactivation form
256 // Load starting and ending date
257 $result = SQL_QUERY_ESC("SELECT
258 `holiday_start`, `holiday_end`
260 `{?_MYSQL_PREFIX?}_user_holidays`
263 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
264 if (SQL_NUMROWS($result) == 1) {
265 // Data was found so merge it
266 $content = merge_array($content, SQL_FETCHARRAY($result));
268 // Prepare it for the template
269 $content['start'] = generateDateTime($content['holiday_start'] , 3);
270 $content['end'] = generateDateTime($content['holiday_end'] , 3);
271 $content['lock'] = generateDateTime($content['holiday_activated'], 1);
274 loadTemplate('member_holiday_deactivate', false, $content);
277 SQL_FREERESULT($result);
279 // Remove entry and reload URL
280 SQL_QUERY_ESC("UPDATE
281 `{?_MYSQL_PREFIX?}_user_data`
286 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
287 redirectToUrl('modules.php?module=login&what=holiday');
292 SQL_FREERESULT($result);
295 case 'N': // Display activation form
297 $content['start_day'] = addSelectionBox('day' , date('d', (time() + getConfig('ONE_DAY'))), 'start');
298 $content['start_month'] = addSelectionBox('month', date('m', (time() + getConfig('ONE_DAY'))), 'start');
299 $content['start_year'] = addSelectionBox('year' , date('Y', (time() + getConfig('ONE_DAY'))), 'start');
301 // Calcualte ending date
302 $D = date('d', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
303 $M = date('m', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
304 $Y = date('Y', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
307 $content['end_day'] = addSelectionBox('day' , $D, 'end');
308 $content['end_month'] = addSelectionBox('month', $M, 'end');
309 $content['end_year'] = addSelectionBox('year' , $Y, 'end');
312 loadTemplate('member_holiday_form', false, $content);
317 loadTemplate('admin_settings_saved', false, '{--HOLIDAY_MEMBER_LOCKED--}');