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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isMember()) {
42 redirectToIndexMemberOnlyModule();
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
48 if ((!isExtensionActive('holiday')) && (!isAdmin())) {
49 displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=holiday%}');
56 // Check for running mail orders in pool
57 $result1 = SQL_QUERY_ESC("SELECT
60 `{?_MYSQL_PREFIX?}_pool`
65 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
67 // Check for sent mail orders in stats
68 $result2 = SQL_QUERY_ESC("SELECT
71 `{?_MYSQL_PREFIX?}_user_stats`
75 `timestamp_ordered` DESC
76 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
78 if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) {
80 $content = merge_array($content, SQL_FETCHARRAY($result1));
81 $content = merge_array($content, SQL_FETCHARRAY($result2));
83 // Fix missing entries
84 if (empty($content['timestamp'])) $content['timestamp'] = '0';
85 if (empty($content['timestamp_ordered'])) $content['timestamp_ordered'] = '0';
87 if ((($content['timestamp'] + getConfig('holiday_lock')) > time()) || (($content['timestamp_ordered'] + getConfig('holiday_lock')) > time())) {
88 // Mail order is to close away!
89 unsetPostRequestElement('ok');
90 unsetPostRequestElement('stop');
92 if (($content['timestamp'] + getConfig('holiday_lock')) > time()) {
94 $stamp = $content['timestamp'];
96 // Mail found in stats
97 $stamp = $content['timestamp_ordered'];
100 // Display message and exit here
101 displayMessage('{%message,MEMBER_HOLIDAY_ORDER', generateDateTime($stamp, '1') . '%}');
107 SQL_FREERESULT($result1);
108 SQL_FREERESULT($result2);
111 // Check holiday request...
112 $START = mktime(0, 0, 0, postRequestElement('start_month'), postRequestElement('start_day'), postRequestElement('start_year'));
113 $content['holiday_end'] = mktime(0, 0, 0, postRequestElement('end_month') , postRequestElement('end_day') , postRequestElement('end_year') );
116 $TEST = $content['holiday_end'] - $START;
117 if (($TEST < 0) || ($TEST > (getOneDay() * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) {
119 unsetPostRequestElement('ok');
121 // Everything went okay so let's store his request and send mails
122 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_holidays` (`userid`,`holiday_start`,`holiday_end`,`comments`) VALUES ('%s','%s','%s','%s')",
123 array(getMemberId(), $START, $content['holiday_end'], postRequestElement('comments')), __FILE__, __LINE__);
125 // Activate holiday system
126 SQL_QUERY_ESC("UPDATE
127 `{?_MYSQL_PREFIX?}_user_data`
129 `holiday_active`='N',
130 `holiday_activated`=UNIX_TIMESTAMP()
134 array(getMemberId()), __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'] = postRequestElement('comments');
145 // Send mail to member
146 $message = loadEmailTemplate('member_holiday_request', $content, getMemberId());
147 sendEmail(getMemberId(), '{--MEMBER_HOLIDAY_SUBJECT--}', $message);
149 // Send mail to all admins
150 sendAdminNotification('{--ADMIN_HOLIDAY_SUBJECT--}', 'admin_holiday_request', $content, getMemberId());
152 // Create task (we ignore the task id here)
153 createNewTask('{--ADMIN_HOLIDAY_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId());
156 displayMessage('{--MEMBER_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(getMemberId()), __FILE__, __LINE__);
171 // Do we have an entry?
172 if (SQL_NUMROWS($result) == 1) {
174 $content = merge_array($content, SQL_FETCHARRAY($result));
176 if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
178 $result2 = SQL_QUERY_ESC("SELECT
179 `holiday_start`,`holiday_end`
181 `{?_MYSQL_PREFIX?}_user_holidays`
184 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
185 if (SQL_NUMROWS($result2) == 1) {
186 // Data was found so merge it
187 $content = merge_array($content, SQL_FETCHARRAY($result2));
189 // Prepare it for the template
190 $content['start'] = generateDateTime($content['holiday_start'], 3);
191 $content['end'] = generateDateTime($content['holiday_end'] , 3);
194 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
196 `holiday_active`='N',
197 `holiday_activated`=0
201 array(getMemberId()), __FILE__, __LINE__);
204 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
205 `{?_MYSQL_PREFIX?}_user_holidays`
209 array(getMemberId()), __FILE__, __LINE__);
211 // Send email to admin
212 sendAdminNotification('{--ADMIN_HOLIDAY_DEACTIVATED_SUBJECT--}', 'admin_holiday_deactivated', $content, getMemberId());
214 // Display message to user
215 displayMessage('{--MEMBER_HOLIDAY_DEACTIVATED_NOW--}');
217 // Display message to user
218 displayMessage('{--MEMBER_HOLIDAY_CANNOT_DEACTIVATE--}');
222 SQL_FREERESULT($result2);
223 } elseif ($content['holiday_active'] == 'Y') {
225 displayMessage('{--MEMBER_HOLIDAY_LOCKED--}');
229 displayMessage('{--MEMBER_HOLIDAY_NOT_STOPPED_404--}');
233 SQL_FREERESULT($result);
236 // If something is wrong or link in menu is just clicked display form
237 if ((!isFormSent()) && (!isPostRequestElementSet('stop'))) {
238 // Check if user is in holiday...
239 $result = SQL_QUERY_ESC("SELECT
240 `holiday_active`,`holiday_activated`
242 `{?_MYSQL_PREFIX?}_user_data`
245 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
246 $content = SQL_FETCHARRAY($result);
247 SQL_FREERESULT($result);
250 if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
251 // User can deactivate his holiday request
252 switch ($content['holiday_active']) {
253 case 'Y': // Display deactivation form
254 // Load starting and ending date
255 $result = SQL_QUERY_ESC("SELECT
256 `holiday_start`,`holiday_end`
258 `{?_MYSQL_PREFIX?}_user_holidays`
261 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
262 if (SQL_NUMROWS($result) == 1) {
263 // Data was found so merge it
264 $content = merge_array($content, SQL_FETCHARRAY($result));
266 // Prepare it for the template
267 $content['start'] = generateDateTime($content['holiday_start'] , 3);
268 $content['end'] = generateDateTime($content['holiday_end'] , 3);
269 $content['lock'] = generateDateTime($content['holiday_activated'], 1);
272 loadTemplate('member_holiday_deactivate', false, $content);
275 SQL_FREERESULT($result);
277 // Remove entry and reload URL
278 SQL_QUERY_ESC("UPDATE
279 `{?_MYSQL_PREFIX?}_user_data`
285 array(getMemberId()), __FILE__, __LINE__);
286 redirectToUrl('modules.php?module=login&what=holiday');
291 SQL_FREERESULT($result);
294 case 'N': // Display activation form
296 $startingStamp = time() + getOneDay();
297 $endingStamp = $startingStamp + (getOneDay() * getConfig('holiday_max'));
300 $content['start_day'] = addSelectionBox('day' , getDay($startingStamp) , 'start');
301 $content['start_month'] = addSelectionBox('month', getMonth($startingStamp), 'start');
302 $content['start_year'] = addSelectionBox('year' , getYear($startingStamp) , 'start');
305 $content['end_day'] = addSelectionBox('day' , getDay($endingStamp) , 'end');
306 $content['end_month'] = addSelectionBox('month', getMonth($endingStamp), 'end');
307 $content['end_year'] = addSelectionBox('year' , getYear($endingStamp) , 'end');
310 loadTemplate('member_holiday_form', false, $content);
315 displayMessage('{--MEMBER_HOLIDAY_LOCKED--}');