2 /************************************************************************
3 * MXChange v0.2.1 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 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif (!isMember()) {
43 redirectToIndexMemberOnlyModule();
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
49 if ((!isExtensionActive('holiday')) && (!isAdmin())) {
50 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('holiday'));
57 // Check for running mail orders in pool
58 $result1 = SQL_QUERY_ESC("SELECT
61 `{?_MYSQL_PREFIX?}_pool`
66 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
68 // Check for sent mail orders in stats
69 $result2 = SQL_QUERY_ESC("SELECT
72 `{?_MYSQL_PREFIX?}_user_stats`
76 `timestamp_ordered` DESC
77 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
79 if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) {
81 $content = merge_array($content, SQL_FETCHARRAY($result1));
82 $content = merge_array($content, SQL_FETCHARRAY($result2));
84 // Fix missing entries
85 if (empty($content['timestamp'])) $content['timestamp'] = 0;
86 if (empty($content['timestamp_ordered'])) $content['timestamp_ordered'] = 0;
88 if ((($content['timestamp'] + getConfig('holiday_lock')) > time()) || (($content['timestamp_ordered'] + getConfig('holiday_lock')) > time())) {
89 // Mail order is to close away!
90 unsetPostRequestElement('ok');
91 unsetPostRequestElement('stop');
93 if (($content['timestamp'] + getConfig('holiday_lock')) > time()) {
95 $stamp = $content['timestamp'];
97 // Mail found in stats
98 $stamp = $content['timestamp_ordered'];
101 // Display message and exit here
102 loadTemplate('admin_settings_saved', false, sprintf(getMessage('HOLIDAY_MEMBER_ORDER'), generateDateTime($stamp, 1)));
108 SQL_FREERESULT($result1);
109 SQL_FREERESULT($result2);
112 // Check holiday request...
113 $START = mktime(0, 0, 0, postRequestElement('start_month'), postRequestElement('start_day'), postRequestElement('start_year'));
114 $content['holiday_end'] = mktime(0, 0, 0, postRequestElement('end_month') , postRequestElement('end_day') , postRequestElement('end_year') );
117 $TEST = $content['holiday_end'] - $START;
118 if (($TEST < 0) || ($TEST > (getConfig('ONE_DAY') * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) {
120 unsetPostRequestElement('ok');
122 // Everything went okay so let's store his request and send mails
123 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_holidays` (`userid`, `holiday_start`, `holiday_end`, `comments`) VALUES ('%s','%s','%s','%s')",
124 array(getUserId(), $START, $content['holiday_end'], postRequestElement('comments')), __FILE__, __LINE__);
126 // Activate holiday system
127 SQL_QUERY_ESC("UPDATE
128 `{?_MYSQL_PREFIX?}_user_data`
130 `holiday_active`='N', `holiday_activated`=UNIX_TIMESTAMP()
134 array(getUserId()), __FILE__, __LINE__);
137 $content['start_day'] = bigintval(postRequestElement('start_day'));
138 $content['start_month'] = $GLOBALS['month_descr'][postRequestElement('start_month')];
139 $content['start_year'] = bigintval(postRequestElement('start_year'));
140 $content['end_day'] = bigintval(postRequestElement('end_day'));
141 $content['end_month'] = $GLOBALS['month_descr'][postRequestElement('end_month')];
142 $content['end_year'] = bigintval(postRequestElement('end_year'));
143 $content['comments'] = secureString(postRequestElement('comments'));
145 // Send mail to member
146 $message = loadEmailTemplate('member_holiday_request', $content, getUserId());
147 sendEmail(getUserId(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message);
149 // Send mail to all admins
150 sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', $content, getUserId());
153 createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getUserId());
156 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_IS_ACTIVATED_NOW'));
160 // Holiday shall be ended now
161 if (isPostRequestElementSet('stop')) {
162 // Okay, end the holiday here...
163 $result = SQL_QUERY_ESC("SELECT
164 `holiday_active`, `holiday_activated`
166 `{?_MYSQL_PREFIX?}_user_data`
169 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
170 $content = merge_array($content, SQL_FETCHARRAY($result));
171 SQL_FREERESULT($result);
173 if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
175 $result = SQL_QUERY_ESC("SELECT
176 `holiday_start`, `holiday_end`
178 `{?_MYSQL_PREFIX?}_user_holidays`
181 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
182 if (SQL_NUMROWS($result) == 1) {
184 $content = merge_array($content, SQL_FETCHARRAY($result));
185 SQL_FREERESULT($result);
187 // Prepare it for the template
188 $content['start'] = generateDateTime($content['holiday_start'], 3);
189 $content['end'] = generateDateTime($content['holiday_end'] , 3);
192 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
194 `holiday_active`='N',
195 `holiday_activated`=0
199 array(getUserId()), __FILE__, __LINE__);
202 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
203 `{?_MYSQL_PREFIX?}_user_holidays`
207 array(getUserId()), __FILE__, __LINE__);
209 // Send email to admin
210 sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', $content, getUserId());
212 // Display message to user
213 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
215 // Display message to user
216 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
218 } elseif ($content['holiday_active'] == 'Y') {
220 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
224 // If something is wrong or link in menu is just clicked display form
225 if ((!isFormSent()) && (!isPostRequestElementSet('stop'))) {
226 // Check if user is in holiday...
227 $result = SQL_QUERY_ESC("SELECT
228 `holiday_active`, `holiday_activated`
230 `{?_MYSQL_PREFIX?}_user_data`
233 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
234 $content = SQL_FETCHARRAY($result);
235 SQL_FREERESULT($result);
238 if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
239 // User can deactivate his holiday request
240 switch ($content['holiday_active'])
242 case 'Y': // Display deactivation form
243 // Load starting and ending date
244 $result = SQL_QUERY_ESC("SELECT
245 `holiday_start`, `holiday_end`
247 `{?_MYSQL_PREFIX?}_user_holidays`
250 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
251 if (SQL_NUMROWS($result) == 1) {
253 $content = merge_array($content, SQL_FETCHARRAY($result));
254 SQL_FREERESULT($result);
256 // Prepare it for the template
257 $content['start'] = generateDateTime($content['holiday_start'] , 3);
258 $content['end'] = generateDateTime($content['holiday_end'] , 3);
259 $content['lock'] = generateDateTime($content['holiday_activated'], 1);
262 loadTemplate('member_holiday_deactivate', false, $content);
265 SQL_FREERESULT($result);
267 // Remove entry and reload URL
268 SQL_QUERY_ESC("UPDATE
269 `{?_MYSQL_PREFIX?}_user_data`
274 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
275 redirectToUrl('modules.php?module=login&what=holiday');
280 case 'N': // Display activation form
282 $content['start_day'] = addSelectionBox('day' , date('d', (time() + getConfig('ONE_DAY'))), 'start');
283 $content['start_month'] = addSelectionBox('month', date('m', (time() + getConfig('ONE_DAY'))), 'start');
284 $content['start_year'] = addSelectionBox('year' , date('Y', (time() + getConfig('ONE_DAY'))), 'start');
286 // Calcualte ending date
287 $D = date('d', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
288 $M = date('m', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
289 $Y = date('Y', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
292 $content['end_day'] = addSelectionBox('day' , $D, 'end');
293 $content['end_month'] = addSelectionBox('month', $M, 'end');
294 $content['end_year'] = addSelectionBox('year' , $Y, 'end');
297 loadTemplate('member_holiday_form', false, $content);
302 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));