(no commit message)
[mailer.git] / 0.2.1 / inc / modules / admin / what-sub_points.php
1 <?php\r
2 /************************************************************************\r
3  * MXChange v0.2.1                                    Start: 11/23/2003 *\r
4  * ===============                              Last change: 09/23/2004 *\r
5  *                                                                      *\r
6  * -------------------------------------------------------------------- *\r
7  * File              : what-sub_points.php                              *\r
8  * -------------------------------------------------------------------- *\r
9  * Short description : Add manually points to a user                    *\r
10  * -------------------------------------------------------------------- *\r
11  * Kurzbeschreibung  : Manuell einem Mitglied Punkte gutschreiben       *\r
12  * -------------------------------------------------------------------- *\r
13  *                                                                      *\r
14  * -------------------------------------------------------------------- *\r
15  * Copyright (c) 2003 - 2007 by Roland Haeder                           *\r
16  * For more information visit: http://www.mxchange.org                  *\r
17  *                                                                      *\r
18  * This program is free software; you can redistribute it and/or modify *\r
19  * it under the terms of the GNU General Public License as published by *\r
20  * the Free Software Foundation; either version 2 of the License, or    *\r
21  * (at your option) any later version.                                  *\r
22  *                                                                      *\r
23  * This program is distributed in the hope that it will be useful,      *\r
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *\r
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *\r
26  * GNU General Public License for more details.                         *\r
27  *                                                                      *\r
28  * You should have received a copy of the GNU General Public License    *\r
29  * along with this program; if not, write to the Free Software          *\r
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *\r
31  * MA  02110-1301  USA                                                  *\r
32  ************************************************************************/\r
33 \r
34 // Some security stuff...\r
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))\r
36 {\r
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4)."/security.php";\r
38         require($INC);\r
39 }\r
40 // Add description as navigation point\r
41 ADD_DESCR("admin", basename(__FILE__));\r
42 \r
43 // Fix a notice\r
44 if (!isset($_GET['u_id'])) $_GET['u_id'] = "";\r
45 \r
46 OPEN_TABLE("100%", "admin_content admin_content_align", "");\r
47 if ($_GET['u_id'] == "all")\r
48 {\r
49         // Add points to all accounts\r
50         define('__POINTS_VALUE', $_POST['points']);\r
51         if ((isset($_POST['ok'])) && ($_POST['points'] > 0))\r
52         {\r
53                 $result_main = SQL_QUERY("SELECT userid FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED' ORDER BY userid", __FILE__, __LINE__);\r
54                 while (list($uid) = SQL_FETCHROW($result_main))\r
55                 {\r
56                         // User ID found in URL so we use this give him some credits\r
57                         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",\r
58                          array(bigintval($uid)), __FILE__, __LINE__);\r
59                         if (SQL_NUMROWS($result) == 1)\r
60                         {\r
61                                 // Selected user does exist\r
62                                 list($sname, $fname, $email) = SQL_FETCHROW($result);\r
63                                 SQL_FREERESULT($result);\r
64 \r
65                                 if ((isset($_POST['ok'])) && (!empty($_POST['points'])))\r
66                                 {\r
67                                         // Ok, add points to used points and send an email to him...\r
68                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET used_points=used_points+%s WHERE userid=%d LIMIT 1",\r
69                                          array(bigintval($_POST['points'], bigintval($uid))), __FILE__, __LINE__);\r
70 \r
71                                         // Load message and send it away\r
72                                         $msg = LOAD_EMAIL_TEMPLATE("sub-points", $_POST['reason'], $uid);\r
73                                         SEND_EMAIL($email, ADMIN_SUB_SUBJ, $msg);\r
74                                 }\r
75                         }\r
76                 }\r
77                 // Free memory\r
78                 SQL_FREERESULT($result_main);\r
79 \r
80                 // Output message\r
81                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ALL_POINTS_SUBTRACTED);\r
82         }\r
83          else\r
84         {\r
85                 // Display form add points\r
86                 LOAD_TEMPLATE("admin_sub_points_all");\r
87         }\r
88 }\r
89  elseif (!empty($_GET['u_id']))\r
90 {\r
91         // User ID found in URL so we use this give him some credits\r
92         $result = SQL_QUERY_ESC("SELECT surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%d AND status='CONFIRMED' LIMIT 1",\r
93          array(bigintval($_GET['u_id'])),__FILE__, __LINE__);\r
94         if (SQL_NUMROWS($result) == 1)\r
95         {\r
96                 // Selected user does exist\r
97                 list($sname, $fname, $email) = SQL_FETCHROW($result);\r
98                 SQL_FREERESULT($result);\r
99 \r
100                 if ((isset($_POST['ok'])) && (!empty($_POST['points'])))\r
101                 {\r
102                         // Ok, add to used points and send an email to him...\r
103                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_user_data SET used_points=used_points+%s WHERE userid=%d LIMIT 1",\r
104                          array(bigintval($_POST['points']), bigintval($_GET['u_id'])), __FILE__, __LINE__);\r
105 \r
106                         // Update mediadata as well\r
107                         if (GET_EXT_VERSION("mediadata") >= "0.0.4")\r
108                         {\r
109                                 // Update database\r
110                                 MEDIA_UPDATE_ENTRY(array("total_points"), "sub", bigintval($_POST['points']));\r
111                         }\r
112 \r
113                         // Remember points in template\r
114                         define('__POINTS_VALUE', bigintval($_POST['points']));\r
115 \r
116                         // Load email and send it away\r
117                         $msg = LOAD_EMAIL_TEMPLATE("sub-points", $_POST['reason'], $_GET['u_id']);\r
118                         SEND_EMAIL($email, ADMIN_SUB_SUBJ, $msg);\r
119 \r
120                         // Output message\r
121                         LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_POINTS_SUBTRACTED);\r
122                 }\r
123                  else\r
124                 {\r
125                         // Opps, missing form here\r
126                         define('__USER_VALUE', "<A href=\"".CREATE_EMAIL_LINK($email, "user_data")."\">".$sname." ".$fname."</A>");\r
127                         define('__UID_VALUE', $_GET['u_id']);\r
128                         LOAD_TEMPLATE("admin_sub_points");\r
129                 }\r
130         }\r
131          else\r
132         {\r
133                 // User not found!\r
134                 OUTPUT_HTML ("<STRONG class=\"admin_failed\">".ADMIN_MEMBER_404_1.$_GET['u_id'].ADMIN_MEMBER_404_2."</STRONG>");\r
135         }\r
136 }\r
137  else\r
138 {\r
139         // Output selection form with all confirmed user accounts listed\r
140         ADD_MEMBER_SELECTION_BOX(true);\r
141 }\r
142 CLOSE_TABLE();\r
143 //\r
144 ?>\r