Security line in all includes changed
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39 // Add description as navigation point
40 ADD_DESCR("admin", basename(__FILE__));
41
42 // Check for selected holidays
43 $SUM = 0;
44 if (isset($_POST['sel'])) $SUM = SELECTION_COUNT($_POST['sel']);
45
46 // Shall I delete selected holidays???
47 if ($SUM > 0)
48 {
49         // Delete multiple holiday requests (for list_holiday)
50         $cnt = 0;
51         foreach ($_POST['sel'] as $id => $sel)
52         {
53                 // Get the userid
54                 $result = SQL_QUERY_ESC("SELECT userid, holiday_start, holiday_end
55 FROM "._MYSQL_PREFIX."_user_holidays
56 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
57                 if (SQL_NUMROWS($result) == 1)
58                 {
59                         // Load data and free memory
60                         list($uid, $start, $end) = SQL_FETCHROW($result);
61                         SQL_FREERESULT($result);
62
63                         // Update user's account
64                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
65 SET holiday_active='N', holiday_activated='0'
66 WHERE userid=%s LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__);
67
68                         // Remove holiday
69                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_holidays
70 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
71
72                         // Prepare loaded data for the
73                         $content = array(
74                                 'start' => MAKE_DATETIME($start, "3"),
75                                 'end'   => MAKE_DATETIME($end  , "3")
76                         );
77
78                         // Send email to user
79                         $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, $uid);
80                         SEND_EMAIL($uid, HOLIDAY_ADMIN_REMOVED_SUBJ, $msg);
81                         $cnt++;
82                 }
83         }
84         LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_ADMIN_MULTI_DEL_1.$cnt.HOLIDAY_ADMIN_MULTI_DEL_2);
85 }
86  elseif (!empty($_GET['u_id']))
87 {
88         // Set default message
89         $MSG = HOLIDAY_ADMIN_SINGLE_404;
90
91         // Fetch data
92         $result_load = SQL_QUERY_ESC("SELECT holiday_start AS start, holiday_end AS end
93 FROM "._MYSQL_PREFIX."_user_holidays
94 WHERE userid=%s LIMIT 1", array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
95         if (SQL_NUMROWS($result_load) == 1)
96         {
97                 // Load data
98                 $content = SQL_FETCHARRAY($result_load);
99
100                 // Free some memory
101                 unset($content[0]);
102                 unset($content[1]);
103
104                 // Delete one holiday request (for task)
105                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_holidays
106 WHERE userid=%s LIMIT 1", array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
107
108                 // Send email to user
109                 $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, $_GET['u_id']);
110                 SEND_EMAIL($_GET['u_id'], HOLIDAY_ADMIN_REMOVED_SUBJ, $msg);
111
112                 // Set message
113                 $MSG = HOLIDAY_ADMIN_SINGLE_DELETED;
114         }
115
116         // Free memory
117         SQL_FREERESULT($result_load);
118
119         // Output message
120         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
121 }
122  else
123 {
124         // Please call me over other scripts... ;)
125         LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_NO_DIRECT_CALL);
126 }
127 //
128 ?>