A lot variables renamed from all upper-case to hungarian notation
[mailer.git] / inc / modules / admin / what-del_holiday.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/24/2004 *
4  * ================                             Last change: 08/09/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-del_holiday.php                             *
8  * -------------------------------------------------------------------- *
9  * Short description : Remove holiday requests                          *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Urlaubsschaltungen entfernen                     *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR("admin", __FILE__);
47
48 // Check for selected holidays
49 $SUM = 0;
50 if (REQUEST_ISSET_POST('sel')) $SUM = SELECTION_COUNT(REQUEST_POST('sel'));
51
52 // Shall I delete selected holidays???
53 if ($SUM > 0)
54 {
55         // Delete multiple holiday requests (for list_holiday)
56         $cnt = 0;
57         foreach (REQUEST_POST('sel') as $id => $sel)
58         {
59                 // Get the userid
60                 $result = SQL_QUERY_ESC("SELECT userid, holiday_start, holiday_end
61 FROM `{!_MYSQL_PREFIX!}_user_holidays`
62 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
63                 if (SQL_NUMROWS($result) == 1)
64                 {
65                         // Load data and free memory
66                         list($uid, $start, $end) = SQL_FETCHROW($result);
67                         SQL_FREERESULT($result);
68
69                         // Update user's account
70                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data`
71 SET holiday_active='N', holiday_activated='0'
72 WHERE userid=%s LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__);
73
74                         // Remove holiday
75                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays`
76 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
77
78                         // Prepare loaded data for the
79                         $content = array(
80                                 'start' => MAKE_DATETIME($start, "3"),
81                                 'end'   => MAKE_DATETIME($end  , "3")
82                         );
83
84                         // Send email to user
85                         $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, $uid);
86                         SEND_EMAIL($uid, getMessage('HOLIDAY_ADMIN_REMOVED_SUBJ'), $msg);
87                         $cnt++;
88                 }
89         }
90         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('HOLIDAY_ADMIN_MULTI_DEL'), $cnt));
91 } elseif (REQUEST_ISSET_GET(('uid'))) {
92         // Set default message
93         $message = getMessage('HOLIDAY_ADMIN_SINGLE_404');
94
95         // Fetch data
96         $result_load = SQL_QUERY_ESC("SELECT holiday_start AS start, holiday_end AS end
97 FROM `{!_MYSQL_PREFIX!}_user_holidays`
98 WHERE userid=%s LIMIT 1", array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
99         if (SQL_NUMROWS($result_load) == 1) {
100                 // Load data
101                 $content = SQL_FETCHARRAY($result_load);
102
103                 // Delete one holiday request (for task)
104                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays`
105 WHERE userid=%s LIMIT 1", array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
106
107                 // Send email to user
108                 $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, REQUEST_GET('uid'));
109                 SEND_EMAIL(REQUEST_GET('uid'), getMessage('HOLIDAY_ADMIN_REMOVED_SUBJ'), $msg);
110
111                 // Set message
112                 $message = getMessage('HOLIDAY_ADMIN_SINGLE_DELETED');
113         }
114
115         // Free memory
116         SQL_FREERESULT($result_load);
117
118         // Output message
119         LOAD_TEMPLATE("admin_settings_saved", false, $message);
120 } else {
121         // Please call me over other scripts... ;)
122         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('HOLIDAY_NO_DIRECT_CALL'));
123 }
124
125 //
126 ?>