2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 10/19/2003 *
4 * =================== Last change: 06/30/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-categories.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Select or unselect categories *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Kategorien ab- bzw. anwaehlen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
41 } elseif (!isMember()) {
42 redirectToIndexMemberOnlyModule();
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
48 $whereStatement = " WHERE `visible`='Y'";
49 if (isAdmin()) $whereStatement = '';
52 $result = sqlQuery('SELECT
56 `{?_MYSQL_PREFIX?}_cats`
57 ' . $whereStatement . '
59 `sort` ASC', __FILE__, __LINE__);
62 if (!ifSqlHasZeroNumRows($result)) {
66 foreach (postRequestElement('cat') as $categoryId => $joined) {
67 if ($joined != 'Y') $count++;
70 if ((sqlNumRows($result) - $count) < getLeastCats()) {
71 unsetPostRequestElement('ok');
84 // Go through all entries
85 foreach (postRequestElement('cat') as $categoryId => $joined) {
86 // Has the user joined on this category?
89 // Check if this category has an entry
90 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($categoryId))) == 0) {
92 addSql(sprintf('INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)', getMemberId(), bigintval($categoryId)));
97 addSql(sprintf('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1', getMemberId(), bigintval($categoryId)));
102 // Are there entries?
103 if (countSqls() > 0) {
105 $count = runFilterChain('run_sqls');
111 displayMessage('{--MEMBER_CATEGORIES_SAVED--}');
114 displayMessage('{--MEMBER_CATEGORIES_NOT_SAVED--}');
117 if ($LEAST === TRUE) {
118 // Also here we have to secure it... :(
119 displayMessage('{--CHOOSE_MORE_CATEGORIES--}');
122 // Load all categories of this member
124 while ($content = sqlFetchArray($result)) {
125 // Default he has not joined, add color switch
126 $content['jn'] = ' checked="checked"';
129 // When we found an entry don't read it, just change the jx elements
130 if ((isFormSent()) && (isPostRequestElementSet('cat'))) {
132 if (postRequestElement('cat', $content['id']) =='Y') {
133 $content['jy'] = ' checked="checked"';
137 // Check if he has an entry
138 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($content['id']))) == 1) {
140 $content['jy'] = ' checked="checked"';
145 $OUT .= loadTemplate('member_cats_row', TRUE, $content);
149 sqlFreeResult($result);
151 // Load footer template
152 loadTemplate('member_cats', FALSE, $OUT);
155 // No cateogries are defined yet
156 displayMessage('{--MEMBER_NO_CATEGORIES--}');
160 sqlFreeResult($result);