Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-list_user_cats.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 01/27/2004 *
4  * ===================                          Last change: 07/13/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_cats.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : List selected categories from users              *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Ausgewaehlte Kategorien eines Mitgliedes         *
12  *                     auflisten                                        *
13  * -------------------------------------------------------------------- *
14  * $Revision::                                                        $ *
15  * $Date::                                                            $ *
16  * $Tag:: 0.2.1-FINAL                                                 $ *
17  * $Author::                                                          $ *
18  * -------------------------------------------------------------------- *
19  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
20  * Copyright (c) 2009 - 2015 by Mailer Developer Team                   *
21  * For more information visit: http://mxchange.org                      *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addYouAreHereLink('admin', __FILE__);
46
47 if (isGetRequestElementSet('userid')) {
48         // Check if the user already exists
49         if (fetchUserData(getRequestElement('userid'))) {
50                 // Loads surname, family's name and the email address
51                 $content = getUserDataArray();
52
53                 // Prepare constants
54                 // @TODO No longer needed? define('__CATEGORIES_BASE'   , '<a href="{%url=modules.php?module=admin&amp;userid=');
55                 $content['email']  = '<a href="' . generateEmailLink($content['email'], 'user_data') . '">{%pipe,translateGender=' . $content['gender'] . '%} ' . $content['surname'] . ' ' . $content['family'] . '</a>';
56
57                 // Ok, list categories of this user
58                 $result_cats = sqlQuery("SELECT
59         `id`,
60         `cat`
61 FROM
62         `{?_MYSQL_PREFIX?}_cats`
63 ORDER BY
64         `sort` ASC", __FILE__, __LINE__);
65
66                 if (!ifSqlHasZeroNumRows($result_cats)) {
67                         // List categories
68                         $count = 1; $OUT = '';
69                         while ($row = sqlFetchArray($result_cats)) {
70                                 // Merge both arrays
71                                 $content = merge_array($content, $row);
72
73                                 // Check user's selection
74                                 // @TODO Rewrite this to countSum.....() function
75                                 $result_user = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
76                                         array(bigintval(getRequestElement('userid')), bigintval($content['id'])), __FILE__, __LINE__);
77
78                                 // Set selection
79                                 $selection = '<font color="#ee0000">{--NO--}</div>';
80                                 if (sqlNumRows($result_user) == 1) {
81                                         $selection = '<font color="#00ee00">{--YES--}</div>';
82                                 } // END - if
83
84                                 // Add more elements
85                                 $content['count'] = $count;
86                                 $content['sel']   = $selection;
87
88                                 // Load row template and count up
89                                 $OUT .= loadTemplate('admin_list_user_cats_row', TRUE, $content);
90                                 $count++;
91                         } // END - while
92
93                         // Free memory
94                         sqlFreeResult($result_cats);
95
96                         // Remember all rows in the array
97                         $content['rows'] = $OUT;
98
99                         // Load main template
100                         loadTemplate('admin_list_user_cats', FALSE, $content);
101                 } else {
102                         // No categories selected! :-(
103                         loadTemplate('admin_list_user_cats_404', FALSE, $content);
104                 }
105         } else {
106                 // User not found
107                 displayMessage('{%message,ADMIN_MEMBER_404=' . $content['userid'] . '%}');
108         }
109 } else {
110         // Output selection form with all confirmed user accounts listed
111         addMemberSelectionBox();
112 }
113
114 // [EOF]
115 ?>