fd9b0e5ee88c3bbe8f6a3ea160b43bcac1f510a8
[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 ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 // Fix a notice
44 if (!isset($_GET['u_id'])) $_GET['u_id'] = "";
45
46 if ($_GET['u_id'] == "all") {
47         // Add points to all accounts
48         if ((isset($_POST['ok'])) && ($_POST['points'] > 0)) {
49                 define('__POINTS_VALUE', $_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                         // User ID found in URL so we use this give him some credits
53                         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
54                          array(bigintval($uid)), __FILE__, __LINE__);
55                         if (SQL_NUMROWS($result) == 1) {
56                                 // Selected user does exist
57                                 list($sname, $fname, $email) = SQL_FETCHROW($result);
58                                 SQL_FREERESULT($result);
59
60                                 if ((isset($_POST['ok'])) && (!empty($_POST['points']))) {
61                                         // Ok, add points and send an email to him...
62                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+(%s) WHERE userid=%s AND ref_depth=0 LIMIT 1",
63                                          array($_POST['points'], bigintval($uid)), __FILE__, __LINE__);
64
65                                         // Update mediadata as well
66                                         if (GET_EXT_VERSION("mediadata") >= "0.0.4") {
67                                                 // Update database
68                                                 MEDIA_UPDATE_ENTRY(array("total_points"), "add", $_POST['points']);
69                                         }
70
71                                         // Load email template and send email away
72                                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $_POST['reason'], $uid);
73                                         SEND_EMAIL($email, ADMIN_ADD_SUBJ, $msg);
74                                 }
75                         }
76                 }
77
78                 // Free memory
79                 SQL_FREERESULT($result_main);
80
81                 // Output message
82                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ALL_POINTS_ADDED);
83         } else {
84                 // Display form add points
85                 LOAD_TEMPLATE("admin_add_points_all");
86         }
87 } elseif (!empty($_GET['u_id'])) {
88         // User ID found in URL so we use this give him some credits
89         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
90          array(bigintval($_GET['u_id'])), __FILE__, __LINE__);
91         if (SQL_NUMROWS($result) == 1) {
92                 // Selected user does exist
93                 list($sname, $fname, $email) = SQL_FETCHROW($result);
94                 SQL_FREERESULT($result);
95
96                 if ((isset($_POST['ok'])) && (!empty($_POST['points']))) {
97                         // Ok, add points and send an email to him...
98                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_points SET points=points+(%s) WHERE userid=%s AND ref_depth=0 LIMIT 1",
99                          array($_POST['points'], bigintval($_GET['u_id'])), __FILE__, __LINE__);
100
101                         // Remember points in constant
102                         define('__POINTS_VALUE', $_POST['points']);
103
104                         // Message laden
105                         $msg = LOAD_EMAIL_TEMPLATE("add-points", $_POST['reason'], $_GET['u_id']);
106
107                         SEND_EMAIL($email, ADMIN_ADD_SUBJ, $msg);
108                         LOAD_TEMPLATE("admin_settings_saved", false, 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_VALUE', $_GET['u_id']);
113                         LOAD_TEMPLATE("admin_add_points");
114                 }
115         } else {
116                 // User not found!
117                 OUTPUT_HTML("<STRONG class=\"admin_failed\">".ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2."</STRONG>");
118         }
119 } else {
120         // Output selection form with all confirmed user accounts listed
121         ADD_MEMBER_SELECTION_BOX("0", true);
122 }
123
124 //
125 ?>