"copied"
[mailer.git] / 0.2.1-FINAL / 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
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Check for selected holidays
44 $SUM = 0;
45 if (isset($_POST['sel'])) $SUM = SELECTION_COUNT($_POST['sel']);
46
47 // Shall I delete selected holidays???
48 if ($SUM > 0)
49 {
50         // Delete multiple holiday requests (for list_holiday)
51         $cnt = 0;
52         foreach ($_POST['sel'] as $id => $sel)
53         {
54                 // Get the userid
55                 $result = SQL_QUERY_ESC("SELECT userid, holiday_start, holiday_end
56 FROM "._MYSQL_PREFIX."_user_holidays
57 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
58                 if (SQL_NUMROWS($result) == 1)
59                 {
60                         // Load data and free memory
61                         list($uid, $start, $end) = SQL_FETCHROW($result);
62                         SQL_FREERESULT($result);
63
64                         // Update user's account
65                         SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data
66 SET holiday_active='N', holiday_activated='0'
67 WHERE userid=%s LIMIT 1", array(bigintval($uid)), __FILE__, __LINE__);
68
69                         // Remove holiday
70                         SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_holidays
71 WHERE id=%s LIMIT 1", array(bigintval($id)), __FILE__, __LINE__);
72
73                         // Prepare loaded data for the
74                         $content = array(
75                                 'start' => MAKE_DATETIME($start, "3"),
76                                 'end'   => MAKE_DATETIME($end  , "3")
77                         );
78
79                         // Send email to user
80                         $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, $uid);
81                         SEND_EMAIL($uid, HOLIDAY_ADMIN_REMOVED_SUBJ, $msg);
82                         $cnt++;
83                 }
84         }
85         LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_ADMIN_MULTI_DEL_1.$cnt.HOLIDAY_ADMIN_MULTI_DEL_2);
86 }
87  elseif (!empty($_GET['u_id']))
88 {
89         // Set default message
90         $MSG = HOLIDAY_ADMIN_SINGLE_404;
91
92         // Fetch data
93         $result_load = SQL_QUERY_ESC("SELECT holiday_start AS start, holiday_end AS end
94 FROM "._MYSQL_PREFIX."_user_holidays
95 WHERE userid=%s LIMIT 1", array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
96         if (SQL_NUMROWS($result_load) == 1)
97         {
98                 // Load data
99                 $content = SQL_FETCHARRAY($result_load);
100
101                 // Free some memory
102                 unset($content[0]);
103                 unset($content[1]);
104
105                 // Delete one holiday request (for task)
106                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_holidays
107 WHERE userid=%s LIMIT 1", array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
108
109                 // Send email to user
110                 $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, $_GET['u_id']);
111                 SEND_EMAIL($_GET['u_id'], HOLIDAY_ADMIN_REMOVED_SUBJ, $msg);
112
113                 // Set message
114                 $MSG = HOLIDAY_ADMIN_SINGLE_DELETED;
115         }
116
117         // Free memory
118         SQL_FREERESULT($result_load);
119
120         // Output message
121         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
122 }
123  else
124 {
125         // Please call me over other scripts... ;)
126         LOAD_TEMPLATE("admin_settings_saved", false, HOLIDAY_NO_DIRECT_CALL);
127 }
128 //
129 ?>