Fixes and cleanups
[mailer.git] / inc / modules / admin / what-sub_points.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 11/23/2003 *
4  * ===================                          Last change: 09/23/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-sub_points.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Add manually points to a user                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Manuell einem Mitglied Punkte gutschreiben       *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if (getRequestElement('userid') == 'all') {
47         // Is the form sent?
48         if ((isFormSent()) && (postRequestElement('points') > 0)) {
49                 // Add points to all accounts
50                 $content['points'] = bigintval(postRequestElement('points'));
51
52                 // Load userid
53                 $result_main = SQL_QUERY("SELECT `userid`,`email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC",
54                         __FILE__, __LINE__);
55                 while ($row = SQL_FETCHARRAY($result_main)) {
56                         // Merge both arrays
57                         $content = merge_array($content, $row);
58
59                         // Ok, add points to used points, send an email to him and ignore return status
60                         subtractPoints('admin_sub_all', $content['userid'], postRequestElement('points'));
61
62                         // Prepare content
63                         $content = array(
64                                 'reason'  => SQL_ESCAPE(postRequestElement('reason')),
65                                 'points'  => bigintval(postRequestElement('points')),
66                                 'subject' => 'admin_sub_all',
67                         );
68
69                         // Load message and send it away
70                         $message = loadEmailTemplate('member_sub_points', $content, bigintval($content['userid']));
71                         sendEmail($row['userid'], '{--ADMIN_SUB_SUBJECT--}', $message);
72                 } // END - while
73
74                 // Free memory
75                 SQL_FREERESULT($result_main);
76
77                 // Output message
78                 displayMessage('{--ADMIN_ALL_POINTS_SUBTRACTED--}');
79         } else {
80                 // Display form add points
81                 loadTemplate('admin_sub_points_all');
82         }
83 } elseif (isGetRequestElementSet('userid')) {
84         // User id found in URL so we use this give him some credits
85         if (fetchUserData(getRequestElement('userid'))) {
86                 // Selected user does exist
87                 $content = getUserDataArray();
88
89                 if ((isFormSent()) && (isPostRequestElementSet('points'))) {
90                         // Ok, add to used points, send an email to him and ignore return status
91                         subtractPoints('admin_sub_single', bigintval(getRequestElement('userid')), postRequestElement('points'));
92
93                         // Prepare content
94                         $content = array(
95                                 'reason'  => SQL_ESCAPE(postRequestElement('reason')),
96                                 'points'  => bigintval(postRequestElement('points')),
97                                 'subject' => 'admin_sub_single',
98                         );
99
100                         // Load email and send it away
101                         $message = loadEmailTemplate('member_sub_points', $content, bigintval(getRequestElement('userid')));
102                         sendEmail(getRequestElement('userid'), '{--ADMIN_SUB_SUBJECT--}', $message);
103
104                         // Output message
105                         displayMessage('{--ADMIN_POINTS_SUBTRACTED--}');
106                 } else {
107                         // Prepare content
108                         $content['userid'] = bigintval(getRequestElement('userid'));
109
110                         // Load form
111                         loadTemplate('admin_sub_points', false, $content);
112                 }
113         } else {
114                 // User not found
115                 loadTemplate('admin_settings_unsaved', false, '{%message,ADMIN_MEMBER_404=' . bigintval(getRequestElement('userid')) . '%}');
116         }
117 } else {
118         // Output selection form with all confirmed user accounts listed
119         addMemberSelectionBox(0, true);
120 }
121
122 // [EOF]
123 ?>