]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/what-del_holiday.php
A lot while() conditions rewritten to SQL_FETCHARRAY(), see bug #107, @TODO tags...
[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
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
42
43 // Check for selected holidays
44 $SUM = 0;
45 if (REQUEST_ISSET_POST('sel')) $SUM = SELECTION_COUNT(REQUEST_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 (REQUEST_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, getMessage('HOLIDAY_ADMIN_REMOVED_SUBJ'), $msg);
82                         $cnt++;
83                 }
84         }
85         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('HOLIDAY_ADMIN_MULTI_DEL'), $cnt));
86 } elseif (REQUEST_ISSET_GET(('uid'))) {
87         // Set default message
88         $MSG = getMessage('HOLIDAY_ADMIN_SINGLE_404');
89
90         // Fetch data
91         $result_load = SQL_QUERY_ESC("SELECT holiday_start AS start, holiday_end AS end
92 FROM `{!_MYSQL_PREFIX!}_user_holidays`
93 WHERE userid=%s LIMIT 1", array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
94         if (SQL_NUMROWS($result_load) == 1) {
95                 // Load data
96                 $content = SQL_FETCHARRAY($result_load);
97
98                 // Delete one holiday request (for task)
99                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_holidays`
100 WHERE userid=%s LIMIT 1", array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
101
102                 // Send email to user
103                 $msg = LOAD_EMAIL_TEMPLATE("member_holiday_removed", $content, REQUEST_GET('uid'));
104                 SEND_EMAIL(REQUEST_GET('uid'), getMessage('HOLIDAY_ADMIN_REMOVED_SUBJ'), $msg);
105
106                 // Set message
107                 $MSG = getMessage('HOLIDAY_ADMIN_SINGLE_DELETED');
108         }
109
110         // Free memory
111         SQL_FREERESULT($result_load);
112
113         // Output message
114         LOAD_TEMPLATE("admin_settings_saved", false, $MSG);
115 } else {
116         // Please call me over other scripts... ;)
117         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('HOLIDAY_NO_DIRECT_CALL'));
118 }
119
120 //
121 ?>