Even more rewrites/fixes from EL branch (please report any broken part after you...
[mailer.git] / inc / modules / admin / what-add_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-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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (getRequestParameter('userid') == 'all') {
49         // Add points to all accounts
50         if ((isFormSent()) && (postRequestParameter('points') > 0)) {
51                 // Points
52                 $content['points'] = bigintval(postRequestParameter('points'));
53
54                 // Select all users
55                 $result_main = SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC",
56                         __FILE__, __LINE__);
57
58                 // Process all entries
59                 while ($row = SQL_FETCHARRAY($result_main)) {
60                         // Merge both arrays
61                         $content = merge_array($content, $row);
62
63                         // Remove depth to prevent booking errors. This is a bad coding
64                         // practice, thats also why we need to write this project from
65                         // scratch...
66                         $GLOBALS['ref_level'] = -1;
67
68                         // Ok, add points and send an email to him...
69                         addPointsDirectly('admin_all', $content['userid'], bigintval(postRequestParameter('points')));
70
71                         // Prepare content
72                         $content['text']   = SQL_ESCAPE(postRequestParameter('reason'));
73                         $content['points'] = bigintval(postRequestParameter('points'));
74
75                         // Load email template and send email away
76                         $message = loadEmailTemplate('add-points', $content, bigintval($content['userid']));
77                         sendEmail(bigintval($content['userid']), getMessage('ADMIN_ADD_SUBJ'), $message);
78                 } // END - while
79
80                 // Free memory
81                 SQL_FREERESULT($result_main);
82
83                 // Output message
84                 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ALL_POINTS_ADDED'));
85         } else {
86                 // Display form add points
87                 loadTemplate('admin_add_points_all');
88         }
89 } elseif (isGetRequestParameterSet('userid')) {
90         // User id found in URL so we use this give him some credits
91         if (fetchUserData(getRequestParameter('userid'))) {
92                 // Selected user does exist
93                 $content = getUserDataArray();
94
95                 if ((isFormSent()) && (isPostRequestParameterSet('points'))) {
96                         // Add points and send an email to him...
97                         addPointsDirectly('admin_single', bigintval(getRequestParameter('userid')), bigintval(postRequestParameter('points')));
98
99                         // Prepare content
100                         $content = array(
101                                 'text'   => SQL_ESCAPE(postRequestParameter('reason')),
102                                 'points' => bigintval(postRequestParameter('points'))
103                         );
104
105                         // Message laden
106                         $message = loadEmailTemplate('add-points', $content, bigintval(getRequestParameter('userid')));
107
108                         sendEmail(bigintval(getRequestParameter('userid')), getMessage('ADMIN_ADD_SUBJ'), $message);
109                         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED'));
110                 } else {
111                         // Prepare content
112                         $content['user']   = '<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['surname'] . ' ' . $content['family'] . '</a>';
113                         $content['userid'] = bigintval(getRequestParameter('userid'));
114
115                         // Output template
116                         loadTemplate('admin_add_points', false, $content);
117                 }
118         } else {
119                 // User not found!
120                 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))) . '</div>');
121         }
122 } else {
123         // Output selection form with all confirmed user accounts listed
124         addMemberSelectionBox(0, true);
125 }
126
127 // [EOF]
128 ?>