e16508200fc34bdcaa0a91897acb0c9fcf2a33f5
[mailer.git] / inc / modules / admin / what-sub_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-sub_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 (!isset($_GET['u_id'])) $_GET['u_id'] = "";
45
46 if ($_GET['u_id'] == "all")
47 {
48         // Add points to all accounts
49         define('__POINTS_VALUE', $_POST['points']);
50         if ((isset($_POST['ok'])) && ($_POST['points'] > 0))
51         {
52                 $result_main = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);
53                 while (list($uid) = SQL_FETCHROW($result_main))
54                 {
55                         // User ID found in URL so we use this give him some credits
56                         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
57                          array(bigintval($uid)), __FILE__, __LINE__);
58                         if (SQL_NUMROWS($result) == 1)
59                         {
60                                 // Selected user does exist
61                                 list($sname, $fname, $email) = SQL_FETCHROW($result);
62                                 SQL_FREERESULT($result);
63
64                                 if ((isset($_POST['ok'])) && (!empty($_POST['points'])))
65                                 {
66                                         // Ok, add points to used points and send an email to him...
67                                         SUB_POINTS("admin_all", $uid, $_POST['points']);
68
69                                         // Prepare content
70                                         $content = array(
71                                                 'text'   => SQL_ESCAPE($_POST['reason']),
72                                                 'points' => bigintval($_POST['points'])
73                                         );
74
75                                         // Load message and send it away
76                                         $msg = LOAD_EMAIL_TEMPLATE("sub-points", $content, bigintval($uid));
77                                         SEND_EMAIL(bigintval($uid), ADMIN_SUB_SUBJ, $msg);
78                                 }
79                         }
80                 }
81                 // Free memory
82                 SQL_FREERESULT($result_main);
83
84                 // Output message
85                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ALL_POINTS_SUBTRACTED);
86         }
87          else
88         {
89                 // Display form add points
90                 LOAD_TEMPLATE("admin_sub_points_all");
91         }
92 }
93  elseif (!empty($_GET['u_id']))
94 {
95         // User ID found in URL so we use this give him some credits
96         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s AND status='CONFIRMED' LIMIT 1",
97          array(bigintval($_GET['u_id'])),__FILE__, __LINE__);
98         if (SQL_NUMROWS($result) == 1)
99         {
100                 // Selected user does exist
101                 list($sname, $fname, $email) = SQL_FETCHROW($result);
102                 SQL_FREERESULT($result);
103
104                 if ((isset($_POST['ok'])) && (!empty($_POST['points'])))
105                 {
106                         // Ok, add to used points and send an email to him...
107                         SUB_POINTS("admin_single", bigintval($_GET['u_id']), $_POST['points']);
108
109                         // Prepare content
110                         $content = array(
111                                 'text'   => SQL_ESCAPE($_POST['reason']),
112                                 'points' => bigintval($_POST['points'])
113                         );
114
115                         // Load email and send it away
116                         $msg = LOAD_EMAIL_TEMPLATE("sub-points", $content, bigintval($_GET['u_id']));
117                         SEND_EMAIL(bigintval($_GET['u_id']), ADMIN_SUB_SUBJ, $msg);
118
119                         // Output message
120                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_POINTS_SUBTRACTED);
121                 }
122                  else
123                 {
124                         // Opps, missing form here
125                         define('__USER_VALUE', "<A href=\"".CREATE_EMAIL_LINK($email, "user_data")."\">".$sname." ".$fname."</A>");
126                         define('__UID', bigintval($_GET['u_id']));
127                         LOAD_TEMPLATE("admin_sub_points");
128                 }
129         }
130          else
131         {
132                 // User not found!
133                 OUTPUT_HTML("<STRONG class=\"admin_failed\">".ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2."</STRONG>");
134         }
135 }
136  else
137 {
138         // Output selection form with all confirmed user accounts listed
139         ADD_MEMBER_SELECTION_BOX("0", true);
140 }
141
142 //
143 ?>