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 - 2008 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')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43 } elseif (!IS_MEMBER()) {
44 redirectToUrl('modules.php?module=index');
45 } elseif ((!EXT_IS_ACTIVE('holiday')) && (!IS_ADMIN())) {
46 addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('holiday'));
53 // Add description as navigation point
54 ADD_DESCR('member', __FILE__);
56 // Check for running mail orders in pool
57 $result1 = SQL_QUERY_ESC("SELECT
60 `{!_MYSQL_PREFIX!}_pool`
65 LIMIT 1", array(getUserId()), __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(getUserId()), __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 REQUEST_UNSET_POST('ok');
90 REQUEST_UNSET_POST('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 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('HOLIDAY_MEMBER_ORDER'), generateDateTime($stamp, '1')));
107 SQL_FREERESULT($result1);
108 SQL_FREERESULT($result2);
111 // Check holiday request...
112 $START = mktime(0, 0, 0, REQUEST_POST('start_month'), REQUEST_POST('start_day'), REQUEST_POST('start_year'));
113 $content['holiday_end'] = mktime(0, 0, 0, REQUEST_POST('end_month') , REQUEST_POST('end_day') , REQUEST_POST('end_year') );
116 $TEST = $content['holiday_end'] - $START;
117 if (($TEST < 0) || ($TEST > (getConfig('one_day') * getConfig('holiday_max'))) || ($START < time()) || ($content['holiday_end'] < time())) {
119 REQUEST_UNSET_POST('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(getUserId(), $START, $content['holiday_end'], REQUEST_POST('comments')), __FILE__, __LINE__);
125 // Activate holiday system
126 SQL_QUERY_ESC("UPDATE
127 `{!_MYSQL_PREFIX!}_user_data`
129 `holiday_active`='N', `holiday_activated`=UNIX_TIMESTAMP()
133 array(getUserId()), __FILE__, __LINE__);
136 define('_START_DAY' , REQUEST_POST('start_day'));
137 define('_START_MONTH', $GLOBALS['month_descr'][REQUEST_POST('start_month')]);
138 define('_START_YEAR' , REQUEST_POST('start_year'));
139 define('_END_DAY' , REQUEST_POST('end_day'));
140 define('_END_MONTH' , $GLOBALS['month_descr'][REQUEST_POST('end_month')]);
141 define('_END_YEAR' , REQUEST_POST('end_year'));
143 // Send mail to member
144 $message = LOAD_EMAIL_TEMPLATE('member_holiday_request', REQUEST_POST('comments'), getUserId());
145 sendEmail(getUserId(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message);
147 // Send mail to all admins
148 sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', REQUEST_POST('comments'), getUserId());
151 createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getUserId());
154 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_IS_ACTIVATED_NOW'));
158 // Holiday shall be ended now
159 if (REQUEST_ISSET_POST('stop')) {
160 // Okay, end the holiday here...
161 $result = SQL_QUERY_ESC("SELECT
162 `holiday_active`, `holiday_activated`
164 `{!_MYSQL_PREFIX!}_user_data`
167 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
168 $content = merge_array($content, SQL_FETCHARRAY($result));
169 SQL_FREERESULT($result);
171 if (($content['holiday_active'] == 'Y') && (($content['holiday_activated'] + getConfig('holiday_lock')) < time())) {
173 $result = SQL_QUERY_ESC("SELECT
174 `holiday_start`, `holiday_end`
176 `{!_MYSQL_PREFIX!}_user_holidays`
179 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
180 if (SQL_NUMROWS($result) == 1) {
182 $content = merge_array($content, SQL_FETCHARRAY($result));
183 SQL_FREERESULT($result);
185 // Prepare it for the template
186 define('__HOLIDAY_START', generateDateTime($content['holiday_start'], '3'));
187 define('__HOLIDAY_END' , generateDateTime($content['holiday_end'] , '3'));
190 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
192 `holiday_active`='N',
193 `holiday_activated`=0
196 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
199 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM
200 `{!_MYSQL_PREFIX!}_user_holidays`
203 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
205 // Send email to admin
206 sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', array(), getUserId());
208 // Display message to user
209 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
211 // Display message to user
212 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
214 } elseif ($content['holiday_active'] == 'Y') {
216 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
220 // If something is wrong or link in menu is just clicked display form
221 if ((!isFormSent()) && (!REQUEST_ISSET_POST('stop'))) {
222 // Check if user is in holiday...
223 $result = SQL_QUERY_ESC("SELECT
224 `holiday_active`, `holiday_activated`
226 `{!_MYSQL_PREFIX!}_user_data`
229 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
230 $content = SQL_FETCHARRAY($result);
231 SQL_FREERESULT($result);
234 if (($content['holiday_activated'] + getConfig('holiday_lock')) < time()) {
235 // User can deactivate his holiday request
236 switch ($content['holiday_active'])
238 case 'Y': // Display deactivation form
239 // Load starting and ending date
240 $result = SQL_QUERY_ESC("SELECT
241 `holiday_start`, `holiday_end`
243 `{!_MYSQL_PREFIX!}_user_holidays`
246 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
247 if (SQL_NUMROWS($result) == 1) {
249 $content = merge_array($content, SQL_FETCHARRAY($result));
250 SQL_FREERESULT($result);
252 // Prepare it for the template
253 define('__HOLIDAY_START', generateDateTime($content['holiday_start'] , '3'));
254 define('__HOLIDAY_END' , generateDateTime($content['holiday_end'] , '3'));
255 define('__HOLIDAY_LOCK' , generateDateTime($content['holiday_activated'], '1'));
258 LOAD_TEMPLATE('member_holiday_deactivate');
261 SQL_FREERESULT($result);
263 // Remove entry and reload URL
264 SQL_QUERY_ESC("UPDATE
265 `{!_MYSQL_PREFIX!}_user_data`
270 LIMIT 1", array(getUserId()), __FILE__, __LINE__);
271 redirectToUrl('modules.php?module=login&what=holiday');
276 case 'N': // Display activation form
278 define('_START_DAY' , ADD_SELECTION('day' , date('d', (time() + getConfig('one_day'))), 'start'));
279 define('_START_MONTH', ADD_SELECTION('month', date('m', (time() + getConfig('one_day'))), 'start'));
280 define('_START_YEAR' , ADD_SELECTION('year' , date('Y', (time() + getConfig('one_day'))), 'start'));
282 // Calcualte ending date
283 $D = date('d', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
284 $M = date('m', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
285 $Y = date('Y', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
288 define('_END_DAY' , ADD_SELECTION('day' , $D, 'end'));
289 define('_END_MONTH', ADD_SELECTION('month', $M, 'end'));
290 define('_END_YEAR' , ADD_SELECTION('year' , $Y, 'end'));
292 // Copy value from configuration
293 define('__HOLIDAY_MAX', getConfig('holiday_max'));
296 LOAD_TEMPLATE('member_holiday_form');
301 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));