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'));
50 // Add description as navigation point
51 ADD_DESCR('member', __FILE__);
53 // Check for running mail orders in pool
54 $result1 = SQL_QUERY_ESC("SELECT timestamp FROM `{!_MYSQL_PREFIX!}_pool`
55 WHERE sender=%s ORDER BY timestamp DESC LIMIT 1", array(getUserId()), __FILE__, __LINE__);
57 // Check for sent mail orders in stats
58 $result2 = SQL_QUERY_ESC("SELECT timestamp_ordered FROM `{!_MYSQL_PREFIX!}_user_stats`
59 WHERE userid=%s ORDER BY timestamp_ordered DESC LIMIT 1", array(getUserId()), __FILE__, __LINE__);
61 if ((SQL_NUMROWS($result1) == 1) || (SQL_NUMROWS($result2) == 1)) {
63 list($stamp1) = SQL_FETCHROW($result1);
64 list($stamp2) = SQL_FETCHROW($result2);
65 if (empty($stamp1)) $stamp1 = 0;
66 if (empty($stamp2)) $stamp2 = 0;
68 if ((($stamp1 + getConfig('holiday_lock')) > time()) || (($stamp2 + getConfig('holiday_lock')) > time())) {
69 // Mail order is to close away!
70 REQUEST_UNSET_POST('ok');
71 REQUEST_UNSET_POST('stop');
73 if (($stamp1 + getConfig('holiday_lock')) > time()) {
77 // Mail found in stats
81 // Display message and exit here
82 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('HOLIDAY_MEMBER_ORDER'), generateDateTime($stamp, '1')));
88 SQL_FREERESULT($result1);
89 SQL_FREERESULT($result2);
92 // Check holiday request...
93 $START = mktime(0, 0, 0, REQUEST_POST('start_month'), REQUEST_POST('start_day'), REQUEST_POST('start_year'));
94 $END = mktime(0, 0, 0, REQUEST_POST('end_month') , REQUEST_POST('end_day') , REQUEST_POST('end_year') );
97 $TEST = $END - $START;
98 if (($TEST < 0) || ($TEST > (getConfig('one_day') * getConfig('holiday_max'))) || ($START < time()) || ($END < time())) {
100 REQUEST_UNSET_POST('ok');
102 // Everything went okay so let's store his request and send mails
103 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_user_holidays` (userid, holiday_start, holiday_end, comments) VALUES ('%s','%s','%s','%s')",
104 array(getUserId(), $START, $END, REQUEST_POST('comments')), __FILE__, __LINE__);
106 // Activate holiday system
107 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
108 SET `holiday_active`='N', holiday_activated=UNIX_TIMESTAMP()
109 WHERE userid=%s LIMIT 1",
110 array(getUserId()), __FILE__, __LINE__);
113 define('_START_DAY' , REQUEST_POST('start_day'));
114 define('_START_MONTH', $GLOBALS['month_descr'][REQUEST_POST('start_month')]);
115 define('_START_YEAR' , REQUEST_POST('start_year'));
116 define('_END_DAY' , REQUEST_POST('end_day'));
117 define('_END_MONTH' , $GLOBALS['month_descr'][REQUEST_POST('end_month')]);
118 define('_END_YEAR' , REQUEST_POST('end_year'));
120 // Send mail to member
121 $message = LOAD_EMAIL_TEMPLATE('member_holiday_request', REQUEST_POST('comments'), getUserId());
122 sendEmail(getUserId(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $message);
124 // Send mail to all admins
125 sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', REQUEST_POST('comments'), getUserId());
128 createNewTask('{--HOLIDAY_ADMIN_SUBJECT--}', $message, 'HOLIDAY_REQUEST', getUserId());
131 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_IS_ACTIVATED_NOW'));
135 // Holiday shall be ended now
136 if (REQUEST_ISSET_POST('stop')) {
137 // Okay, end the holiday here...
138 $result = SQL_QUERY_ESC("SELECT `holiday_active`, `holiday_activated` FROM `{!_MYSQL_PREFIX!}_user_data`
139 WHERE `userid`=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
140 list($active, $locked) = SQL_FETCHROW($result);
141 SQL_FREERESULT($result);
143 if (($active == 'Y') && (($locked + getConfig('holiday_lock')) < time())) {
145 $result = SQL_QUERY_ESC("SELECT `holiday_start`, `holiday_end` FROM `{!_MYSQL_PREFIX!}_user_holidays`
146 WHERE `userid`=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
147 if (SQL_NUMROWS($result) == 1) {
149 list($start, $end) = SQL_FETCHROW($result);
150 SQL_FREERESULT($result);
152 // Prepare it for the template
153 define('__HOLIDAY_START', generateDateTime($start, '3'));
154 define('__HOLIDAY_END' , generateDateTime($end , '3'));
157 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
158 SET `holiday_active`='N', holiday_activated='0'
159 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
162 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays`
163 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
165 // Send email to admin
166 sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', array(), getUserId());
168 // Display message to user
169 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
171 // Display message to user
172 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
174 } elseif ($active == 'Y') {
176 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
180 // If something is wrong or link in menu is just clicked display form
181 if ((!isFormSent()) && (!REQUEST_ISSET_POST('stop'))) {
182 // Check if user is in holiday...
183 $result = SQL_QUERY_ESC("SELECT holiday_active, holiday_activated FROM `{!_MYSQL_PREFIX!}_user_data`
184 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
185 list($active, $locked) = SQL_FETCHROW($result);
186 SQL_FREERESULT($result);
189 if (($locked + getConfig('holiday_lock')) < time()) {
190 // User can deactivate his holiday request
193 case 'Y': // Display deactivation form
194 // Load starting and ending date
195 $result = SQL_QUERY_ESC("SELECT holiday_start, holiday_end FROM `{!_MYSQL_PREFIX!}_user_holidays`
196 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
197 if (SQL_NUMROWS($result) == 1) {
199 list($start, $end) = SQL_FETCHROW($result);
200 SQL_FREERESULT($result);
202 // Prepare it for the template
203 define('__HOLIDAY_START', generateDateTime($start , '3'));
204 define('__HOLIDAY_END' , generateDateTime($end , '3'));
205 define('__HOLIDAY_LOCK' , generateDateTime($locked, '1'));
208 LOAD_TEMPLATE('member_holiday_deactivate');
211 SQL_FREERESULT($result);
213 // Remove entry and reload URL
214 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
215 SET `holiday_active`='N'
216 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
217 redirectToUrl('modules.php?module=login&what=holiday');
222 case 'N': // Display activation form
224 define('_START_DAY' , ADD_SELECTION('day' , date('d', (time() + getConfig('one_day'))), 'start'));
225 define('_START_MONTH', ADD_SELECTION('month', date('m', (time() + getConfig('one_day'))), 'start'));
226 define('_START_YEAR' , ADD_SELECTION('year' , date('Y', (time() + getConfig('one_day'))), 'start'));
228 // Calcualte ending date
229 $D = date('d', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
230 $M = date('m', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
231 $Y = date('Y', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
234 define('_END_DAY' , ADD_SELECTION('day' , $D, 'end'));
235 define('_END_MONTH', ADD_SELECTION('month', $M, 'end'));
236 define('_END_YEAR' , ADD_SELECTION('year' , $Y, 'end'));
238 // Copy value from configuration
239 define('__HOLIDAY_MAX', getConfig('holiday_max'));
242 LOAD_TEMPLATE('member_holiday_form');
247 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));