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(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message);
150 // Send mail to all admins
151 sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', $content, getMemberId());
154 createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getMemberId());
157 loadTemplate('admin_settings_saved', false, getMessage('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__);
171 $content = merge_array($content, SQL_FETCHARRAY($result));
172 SQL_FREERESULT($result);
174 if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
176 $result = SQL_QUERY_ESC("SELECT
177 `holiday_start`, `holiday_end`
179 `{?_MYSQL_PREFIX?}_user_holidays`
182 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
183 if (SQL_NUMROWS($result) == 1) {
185 $content = merge_array($content, SQL_FETCHARRAY($result));
186 SQL_FREERESULT($result);
188 // Prepare it for the template
189 $content['start'] = generateDateTime($content['holiday_start'], 3);
190 $content['end'] = generateDateTime($content['holiday_end'] , 3);
193 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data`
195 `holiday_active`='N',
196 `holiday_activated`=0
200 array(getMemberId()), __FILE__, __LINE__);
203 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
204 `{?_MYSQL_PREFIX?}_user_holidays`
208 array(getMemberId()), __FILE__, __LINE__);
210 // Send email to admin
211 sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', $content, getMemberId());
213 // Display message to user
214 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
216 // Display message to user
217 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
219 } elseif ($content['holiday_active'] == 'Y') {
221 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
225 // If something is wrong or link in menu is just clicked display form
226 if ((!isFormSent()) && (!isPostRequestParameterSet('stop'))) {
227 // Check if user is in holiday...
228 $result = SQL_QUERY_ESC("SELECT
229 `holiday_active`, `holiday_activated`
231 `{?_MYSQL_PREFIX?}_user_data`
234 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
235 $content = SQL_FETCHARRAY($result);
236 SQL_FREERESULT($result);
239 if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
240 // User can deactivate his holiday request
241 switch ($content['holiday_active'])
243 case 'Y': // Display deactivation form
244 // Load starting and ending date
245 $result = SQL_QUERY_ESC("SELECT
246 `holiday_start`, `holiday_end`
248 `{?_MYSQL_PREFIX?}_user_holidays`
251 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
252 if (SQL_NUMROWS($result) == 1) {
254 $content = merge_array($content, SQL_FETCHARRAY($result));
255 SQL_FREERESULT($result);
257 // Prepare it for the template
258 $content['start'] = generateDateTime($content['holiday_start'] , 3);
259 $content['end'] = generateDateTime($content['holiday_end'] , 3);
260 $content['lock'] = generateDateTime($content['holiday_activated'], 1);
263 loadTemplate('member_holiday_deactivate', false, $content);
266 SQL_FREERESULT($result);
268 // Remove entry and reload URL
269 SQL_QUERY_ESC("UPDATE
270 `{?_MYSQL_PREFIX?}_user_data`
275 LIMIT 1", array(getMemberId()), __FILE__, __LINE__);
276 redirectToUrl('modules.php?module=login&what=holiday');
281 case 'N': // Display activation form
283 $content['start_day'] = addSelectionBox('day' , date('d', (time() + getConfig('ONE_DAY'))), 'start');
284 $content['start_month'] = addSelectionBox('month', date('m', (time() + getConfig('ONE_DAY'))), 'start');
285 $content['start_year'] = addSelectionBox('year' , date('Y', (time() + getConfig('ONE_DAY'))), 'start');
287 // Calcualte ending date
288 $D = date('d', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
289 $M = date('m', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
290 $Y = date('Y', time() + getConfig('ONE_DAY') + (getConfig('ONE_DAY') * getConfig('holiday_max')));
293 $content['end_day'] = addSelectionBox('day' , $D, 'end');
294 $content['end_month'] = addSelectionBox('month', $M, 'end');
295 $content['end_year'] = addSelectionBox('year' , $Y, 'end');
298 loadTemplate('member_holiday_form', false, $content);
303 loadTemplate('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));