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 - 2012 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 = SQL_QUERY('SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`' . $whereStatement . ' ORDER BY `sort` ASC', __FILE__, __LINE__);
55 if (!SQL_HASZERONUMS($result)) {
59 foreach (postRequestElement('cat') as $categoryId => $joined) {
60 if ($joined != 'Y') $count++;
63 if ((SQL_NUMROWS($result) - $count) < getLeastCats()) {
64 unsetPostRequestElement('ok');
77 // Go through all entries
78 foreach (postRequestElement('cat') as $categoryId => $joined) {
79 // Has the user joined on this category?
82 // Check if this category has an entry
83 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($categoryId))) == 0) {
85 addSql(sprintf('INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)', getMemberId(), bigintval($categoryId)));
90 addSql(sprintf('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1', getMemberId(), bigintval($categoryId)));
96 if (countSqls() > 0) {
98 $count = runFilterChain('run_sqls');
104 displayMessage('{--MEMBER_CATEGORIES_SAVED--}');
107 displayMessage('{--MEMBER_CATEGORIES_NOT_SAVED--}');
110 if ($LEAST === TRUE) {
111 // Also here we have to secure it... :(
112 displayMessage('{--CHOOSE_MORE_CATEGORIES--}');
115 // Load all categories of this member
117 while ($content = SQL_FETCHARRAY($result)) {
118 // Default he has not joined, add color switch
119 $content['jn'] = ' checked="checked"';
122 // When we found an entry don't read it, just change the jx elements
123 if ((isFormSent()) && (isPostRequestElementSet('cat'))) {
125 if (postRequestElement('cat', $content['id']) =='Y') {
126 $content['jy'] = ' checked="checked"';
130 // Check if he has an entry
131 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($content['id']))) == 1) {
133 $content['jy'] = ' checked="checked"';
138 $OUT .= loadTemplate('member_cats_row', TRUE, $content);
142 SQL_FREERESULT($result);
144 // Load footer template
145 loadTemplate('member_cats', FALSE, $OUT);
148 // No cateogries are defined yet
149 displayMessage('{--MEMBER_NO_CATEGORIES--}');
153 SQL_FREERESULT($result);