Complete rewrite of and , wrapper functions added, see bug #101
[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  *                                                                      *
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 // Fix a notice
44 if (!REQUEST_ISSET_GET(('uid'))) REQUEST_SET_GET('uid', "");
45
46 if (REQUEST_GET('uid') == "all") {
47         // Add points to all accounts
48         if ((IS_FORM_SENT()) && (REQUEST_POST('points') > 0)) {
49                 define('__POINTS_VALUE', REQUEST_POST('points'));
50                 $result_main = SQL_QUERY("SELECT userid FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);
51                 while (list($uid) = SQL_FETCHROW($result_main)) {
52                         // Remove depth to prevent booking errors. This is a bad coding
53                         // practice, thats also why we need to write this project from
54                         // scratch...
55                         $GLOBALS['ref_level'] = -1;
56
57                         // Ok, add points and send an email to him...
58                         ADD_POINTS_REFSYSTEM("admin_all", $uid, bigintval(REQUEST_POST('points')), false, "0", false, "direct");
59
60                         // Prepare content
61                         $content = array(
62                                 'text'   => SQL_ESCAPE(REQUEST_POST('reason')),
63                                 'points' => bigintval(REQUEST_POST('points'))
64                         );
65
66                         // Load email template and send email away
67                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval($uid));
68                         SEND_EMAIL(bigintval($uid), getMessage('ADMIN_ADD_SUBJ'), $msg);
69                 } // END - while
70
71                 // Free memory
72                 SQL_FREERESULT($result_main);
73
74                 // Output message
75                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_ALL_POINTS_ADDED'));
76         } else {
77                 // Display form add points
78                 LOAD_TEMPLATE("admin_add_points_all");
79         }
80 } elseif (REQUEST_ISSET_GET(('uid'))) {
81         // User ID found in URL so we use this give him some credits
82         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s AND `status`='CONFIRMED' LIMIT 1",
83                 array(bigintval(REQUEST_GET('uid'))), __FILE__, __LINE__);
84         if (SQL_NUMROWS($result) == 1) {
85                 // Selected user does exist
86                 list($sname, $fname, $email) = SQL_FETCHROW($result);
87                 SQL_FREERESULT($result);
88
89                 if ((IS_FORM_SENT()) && (REQUEST_ISSET_POST(('points')))) {
90                         // Remove depth to prevent booking errors. This is a bad coding
91                         // practice, thats also why we need to write this project from
92                         // scratch...
93                         unset($GLOBALS['ref_level']);
94
95                         // Ok, add points and send an email to him...
96                         ADD_POINTS_REFSYSTEM("admin_single", bigintval(REQUEST_GET('uid')), bigintval(REQUEST_POST('points')), false, "0", false, "direct");
97
98                         // Prepare content
99                         $content = array(
100                                 'text'   => SQL_ESCAPE(REQUEST_POST('reason')),
101                                 'points' => bigintval(REQUEST_POST('points'))
102                         );
103
104                         // Message laden
105                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $content, bigintval(REQUEST_GET('uid')));
106
107                         SEND_EMAIL(bigintval(REQUEST_GET('uid')), getMessage('ADMIN_ADD_SUBJ'), $msg);
108                         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_POINTS_ADDED'));
109                 } else {
110                         // Opps, missing form here
111                         define('__USER_VALUE', "<a href=\"".CREATE_EMAIL_LINK($email, "user_data")."\">".$sname." ".$fname."</a>");
112                         define('__UID'       , bigintval(REQUEST_GET('uid')));
113                         LOAD_TEMPLATE("admin_add_points");
114                 }
115         } else {
116                 // User not found!
117                 LOAD_TEMPLATE("admin_settings_saved", false, "<div class=\"admin_failed\">".sprintf(getMessage('ADMIN_MEMBER_404'), REQUEST_GET('uid'))."</div>");
118         }
119 } else {
120         // Output selection form with all confirmed user accounts listed
121         ADD_MEMBER_SELECTION_BOX("0", true);
122 }
123
124 //
125 ?>