5e53d23b013b4aa141f75369692e218105af1606
[mailer.git] / inc / modules / admin / what-add_points.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 11/23/2003 *
4  * ===============                              Last change: 09/23/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-add_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  * 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 - 2009 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')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (getRequestElement('userid') == 'all') {
48         // Add points to all accounts
49         if ((isFormSent()) && (postRequestElement('points') > 0)) {
50                 // Points
51                 $content['points'] = bigintval(postRequestElement('points'));
52
53                 // Select all users
54                 $result_main = SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC",
55                         __FILE__, __LINE__);
56
57                 // Process all entries
58                 while ($content = merge_array($content, SQL_FETCHARRAY($result_main))) {
59                         // Remove depth to prevent booking errors. This is a bad coding
60                         // practice, thats also why we need to write this project from
61                         // scratch...
62                         $GLOBALS['ref_level'] = -1;
63
64                         // Ok, add points and send an email to him...
65                         addPointsDirectly('admin_all', $content['userid'], bigintval(postRequestElement('points')));
66
67                         // Prepare content
68                         $content['text']   = SQL_ESCAPE(postRequestElement('reason'));
69                         $content['points'] = bigintval(postRequestElement('points'));
70
71                         // Load email template and send email away
72                         $message = loadEmailTemplate('add-points', $content, bigintval($content['userid']));
73                         sendEmail(bigintval($content['userid']), getMessage('ADMIN_ADD_SUBJ'), $message);
74                 } // END - while
75
76                 // Free memory
77                 SQL_FREERESULT($result_main);
78
79                 // Output message
80                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ALL_POINTS_ADDED'));
81         } else {
82                 // Display form add points
83                 loadTemplate('admin_add_points_all');
84         }
85 } elseif (isGetRequestElementSet('userid')) {
86         // User id found in URL so we use this give him some credits
87         $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `email` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s AND `status`='CONFIRMED' LIMIT 1",
88                 array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
89         if (SQL_NUMROWS($result) == 1) {
90                 // Selected user does exist
91                 $content = SQL_FETCHARRAY($result);
92
93                 if ((isFormSent()) && (isPostRequestElementSet(('points')))) {
94                         // Add points and send an email to him...
95                         addPointsDirectly('admin_single', bigintval(getRequestElement('userid')), bigintval(postRequestElement('points')));
96
97                         // Prepare content
98                         $content = array(
99                                 'text'   => SQL_ESCAPE(postRequestElement('reason')),
100                                 'points' => bigintval(postRequestElement('points'))
101                         );
102
103                         // Message laden
104                         $message = loadEmailTemplate('add-points', $content, bigintval(getRequestElement('userid')));
105
106                         sendEmail(bigintval(getRequestElement('userid')), getMessage('ADMIN_ADD_SUBJ'), $message);
107                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED'));
108                 } else {
109                         // Prepare content
110                         $content['user']   = "<a href=\"".generateEmailLink($content['email'], 'user_data')."\">".$content['surname']." ".$content['family']."</a>";
111                         $content['userid'] = bigintval(getRequestElement('userid'));
112
113                         // Output template
114                         loadTemplate('admin_add_points', false, $content);
115                 }
116         } else {
117                 // User not found!
118                 loadTemplate('admin_settings_saved', false, "<div class=\"admin_failed\">".sprintf(getMessage('ADMIN_MEMBER_404'), getRequestElement('userid'))."</div>");
119         }
120
121         // Free result
122         SQL_FREERESULT($result);
123 } else {
124         // Output selection form with all confirmed user accounts listed
125         addMemberSelectionBox(0, true);
126 }
127
128 // [EOF]
129 ?>