Renamed many stuff (again), added points/user breakup:
[mailer.git] / inc / modules / admin / what-list_user_amounts.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 10/24/2012 *
4  * ===================                          Last change: 10/24/2012 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_user_amounts.php                       *
8  * -------------------------------------------------------------------- *
9  * Short description :                                                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  :                                                  *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Run through all "points columns"
47 $sql = '';
48 foreach (runFilterChain('locked_points_columns_array', array('points')) as $column) {
49         // Add it with/-out locked
50         $sql .= 'p.`' . $column . '` + p.`locked_' . $column . '` +';
51 } // END - foreach
52
53 // Remove last plus
54 $sql = substr($sql, 0, -1);
55
56 // Run the query to obtain all user's amounts (regardless of their status)
57 $result = SQL_QUERY('SELECT
58         d.`userid`,
59         SUM(
60                 ' . $sql . ' -
61                 d.`used_points`
62         ) AS `points`
63 FROM
64         `{?_MYSQL_PREFIX?}_user_points` AS `p`
65 INNER JOIN
66         `{?_MYSQL_PREFIX?}_user_data` AS `d`
67 ON
68         d.`userid`=p.`userid`
69 GROUP BY
70         d.`userid`
71 ORDER BY
72         d.`userid` ASC', __FILE__, __LINE__);
73
74 // Are there entries? (sorry, the XML functions cannot "produce" the above SQL statement)
75 if (!SQL_HASZERONUMS($result)) {
76         // Init amounts and points
77         $totalPoints = '0';
78         $amounts = array();
79
80         // Then load all
81         while ($row = SQL_FETCHARRAY($result)) {
82                 // Add it
83                 $amounts[$row['userid']] = $row;
84                 $totalPoints            += $row['points'];
85         } // END - while
86
87         // Init output
88         $out = array(
89                 'rows'  => '',
90                 'total' => $totalPoints
91         );
92
93         // ... and display all
94         foreach ($amounts as $userid => $row) {
95                 // Calculate and add percentage to data array
96                 $row['percents'] = $row['points'] / $totalPoints * 100;
97
98                 // Load row template
99                 $out['rows'] .= loadTemplate('admin_list_user_amounts_row', TRUE, $row);
100         } // END - foreach
101
102         // Load main template
103         loadTemplate('admin_list_user_amounts', FALSE, $out);
104 } else {
105         // No members found
106         displayMessage('{--ADMIN_LIST_USER_AMOUNTS_404--}');
107 }
108
109 // Free result
110 SQL_FREERESULT($result);
111
112 // [EOF]
113 ?>