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__, sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), '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 $msg = LOAD_EMAIL_TEMPLATE('member_holiday_request', REQUEST_POST('comments'), getUserId());
122 sendEmail(getUserId(), getMessage('HOLIDAY_MEMBER_SUBJECT'), $msg);
124 // Send mail to all admins
125 sendAdminNotification(getMessage('HOLIDAY_ADMIN_SUBJECT'), 'admin_holiday_request', REQUEST_POST('comments'), getUserId());
128 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_task_system` (userid, assigned_admin, status, task_type, subject, text, task_created) VALUES ('%s','0','NEW','HOLIDAY_REQUEST','{--HOLIDAY_ADMIN_SUBJECT--}','%s', UNIX_TIMESTAMP())",
129 array(getUserId(), $msg), __FILE__, __LINE__);
132 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_IS_ACTIVATED_NOW'));
136 // Holiday shall be ended now
137 if (REQUEST_ISSET_POST(('stop'))) {
138 // Okay, end the holiday here...
139 $result = SQL_QUERY_ESC("SELECT holiday_active, holiday_activated FROM `{!_MYSQL_PREFIX!}_user_data`
140 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
141 list($active, $locked) = SQL_FETCHROW($result);
142 SQL_FREERESULT($result);
144 if (($active == 'Y') && (($locked + getConfig('holiday_lock')) < time())) {
146 $result = SQL_QUERY_ESC("SELECT holiday_start, holiday_end FROM `{!_MYSQL_PREFIX!}_user_holidays`
147 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
148 if (SQL_NUMROWS($result) == 1) {
150 list($start, $end) = SQL_FETCHROW($result);
151 SQL_FREERESULT($result);
153 // Prepare it for the template
154 define('__HOLIDAY_START', generateDateTime($start, '3'));
155 define('__HOLIDAY_END' , generateDateTime($end , '3'));
158 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
159 SET `holiday_active`='N', holiday_activated='0'
160 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
163 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays`
164 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
166 // Send email to admin
167 sendAdminNotification(getMessage('HOLIDAY_ADMIN_DEAC_SUBJ'), 'admin_holiday_deactivated', array(), getUserId());
169 // Display message to user
170 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_DEACTIVATED_NOW'));
172 // Display message to user
173 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_CANNOT_DEACTIVATE'));
175 } elseif ($active == 'Y') {
177 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));
181 // If something is wrong or link in menu is just clicked display form
182 if ((!IS_FORM_SENT()) && (!REQUEST_ISSET_POST(('stop'))) {
183 // Check if user is in holiday...
184 $result = SQL_QUERY_ESC("SELECT holiday_active, holiday_activated FROM `{!_MYSQL_PREFIX!}_user_data`
185 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
186 list($active, $locked) = SQL_FETCHROW($result);
187 SQL_FREERESULT($result);
190 if (($locked + getConfig('holiday_lock')) < time()) {
191 // User can deactivate his holiday request
194 case 'Y': // Display deactivation form
195 // Load starting and ending date
196 $result = SQL_QUERY_ESC("SELECT holiday_start, holiday_end FROM `{!_MYSQL_PREFIX!}_user_holidays`
197 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
198 if (SQL_NUMROWS($result) == 1) {
200 list($start, $end) = SQL_FETCHROW($result);
201 SQL_FREERESULT($result);
203 // Prepare it for the template
204 define('__HOLIDAY_START', generateDateTime($start , '3'));
205 define('__HOLIDAY_END' , generateDateTime($end , '3'));
206 define('__HOLIDAY_LOCK' , generateDateTime($locked, '1'));
209 LOAD_TEMPLATE('member_holiday_deactivate');
212 SQL_FREERESULT($result);
214 // Remove entry and reload URL
215 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
216 SET `holiday_active`='N'
217 WHERE userid=%s LIMIT 1", array(getUserId()), __FILE__, __LINE__);
218 redirectToUrl('modules.php?module=login&what=holiday');
223 case 'N': // Display activation form
225 define('_START_DAY' , ADD_SELECTION('day' , date('d', (time() + getConfig('one_day'))), 'start'));
226 define('_START_MONTH', ADD_SELECTION('month', date('m', (time() + getConfig('one_day'))), 'start'));
227 define('_START_YEAR' , ADD_SELECTION('year' , date('Y', (time() + getConfig('one_day'))), 'start'));
229 // Calcualte ending date
230 $D = date('d', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
231 $M = date('m', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
232 $Y = date('Y', time() + getConfig('one_day') + (getConfig('one_day') * getConfig('holiday_max')));
235 define('_END_DAY' , ADD_SELECTION('day' , $D, 'end'));
236 define('_END_MONTH', ADD_SELECTION('month', $M, 'end'));
237 define('_END_YEAR' , ADD_SELECTION('year' , $Y, 'end'));
239 // Copy value from configuration
240 define('__HOLIDAY_MAX', getConfig('holiday_max'));
243 LOAD_TEMPLATE('member_holiday_form');
248 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('HOLIDAY_MEMBER_LOCKED'));