New method generateExtensionInactiveMessage() introduced
[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 - 2008 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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 // Add description as navigation point
46 ADD_DESCR('admin', __FILE__);
47
48 // Fix a notice
49 if (!REQUEST_ISSET_GET('uid')) REQUEST_SET_GET('uid', '');
50
51 if (REQUEST_GET('uid') == "all") {
52         // Add points to all accounts
53         if ((isFormSent()) && (REQUEST_POST('points') > 0)) {
54                 // @TODO Rewrite this constant
55                 define('__POINTS_VALUE', REQUEST_POST('points'));
56
57                 // Select all users
58                 $result_main = SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED' ORDER BY `userid` ASC",
59                 __FILE__, __LINE__);
60
61                 // Process all entries
62                 while ($content = SQL_FETCHARRAY($result_main)) {
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                         ADD_POINTS_REFSYSTEM_DIRECT('admin_all', $content['userid'], bigintval(REQUEST_POST('points')));
70
71                         // Prepare content
72                         $content['text']   = SQL_ESCAPE(REQUEST_POST('reason'));
73                         $content['points'] = bigintval(REQUEST_POST('points'));
74
75                         // Load email template and send email away
76                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval($content['userid']));
77                         sendEmail(bigintval($content['userid']), getMessage('ADMIN_ADD_SUBJ'), $msg);
78                 } // END - while
79
80                 // Free memory
81                 SQL_FREERESULT($result_main);
82
83                 // Output message
84                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_ALL_POINTS_ADDED'));
85         } else {
86                 // Display form add points
87                 LOAD_TEMPLATE("admin_add_points_all");
88         }
89 } elseif (REQUEST_ISSET_GET('uid')) {
90         // User ID found in URL so we use this give him some credits
91         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' LIMIT 1",
92         array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
93         if (SQL_NUMROWS($result) == 1) {
94                 // Selected user does exist
95                 list($sname, $fname, $email) = SQL_FETCHROW($result);
96                 SQL_FREERESULT($result);
97
98                 if ((isFormSent()) && (REQUEST_ISSET_POST(('points')))) {
99                         // Remove depth to prevent booking errors. This is a bad coding
100                         // practice, thats also why we need to write this project from
101                         // scratch...
102                         unset($GLOBALS['ref_level']);
103
104                         // Ok, add points and send an email to him...
105                         ADD_POINTS_REFSYSTEM_DIRECT('admin_single', bigintval(REQUEST_GET('uid')), bigintval(REQUEST_POST('points')));
106
107                         // Prepare content
108                         $content = array(
109                                 'text'   => SQL_ESCAPE(REQUEST_POST('reason')),
110                                 'points' => bigintval(REQUEST_POST('points'))
111                         );
112
113                         // Message laden
114                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval(REQUEST_GET('uid')));
115
116                         sendEmail(bigintval(REQUEST_GET('uid')), getMessage('ADMIN_ADD_SUBJ'), $msg);
117                         LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_POINTS_ADDED'));
118                 } else {
119                         // Opps, missing form here
120                         // @TODO Rewrite these both constants
121                         define('__USER_VALUE', "<a href=\"".generateMemberEmailLink($email, "user_data")."\">".$sname." ".$fname."</a>");
122                         define('__UID'       , bigintval(REQUEST_GET('uid')));
123                         LOAD_TEMPLATE("admin_add_points");
124                 }
125         } else {
126                 // User not found!
127                 LOAD_TEMPLATE('admin_settings_saved', false, "<div class=\"admin_failed\">".sprintf(getMessage('ADMIN_MEMBER_404'), REQUEST_GET('uid'))."</div>");
128         }
129 } else {
130         // Output selection form with all confirmed user accounts listed
131         ADD_MEMBER_SELECTION_BOX('0', true);
132 }
133
134 //
135 ?>