2 /************************************************************************
3 * MXChange v0.2.1 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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
42 } elseif (!isMember()) {
43 redirectToIndexMemberOnlyModule();
46 // Add description as navigation point
47 addMenuDescription('member', __FILE__);
50 $whereStatement = " WHERE `visible`='Y'";
51 if (isAdmin()) $whereStatement = '';
53 $result = SQL_QUERY("SELECT id, cat FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort`", __FILE__, __LINE__);
54 $cats = SQL_NUMROWS($result);
60 foreach (postRequestElement('cat') as $cat => $joined) {
61 if ($joined != 'Y') $cnt++;
64 if (($cats - $cnt) < getConfig('least_cats')) {
65 unsetPostRequestElement('ok');
75 // Go through all entries
76 foreach (postRequestElement('cat') as $cat => $joined) {
80 // Has the user joined on this category?
83 $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
84 array($UID, bigintval($cat)), __FILE__, __LINE__);
86 if (SQL_NUMROWS($result_user) == 0) {
87 $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
91 SQL_FREERESULT($result_user);
95 $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1";
101 SQL_QUERY_ESC(trim($sql), array($UID, bigintval($cat)), __FILE__, __LINE__);
104 $cnt += SQL_AFFECTEDROWS();
111 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_CATS_SAVED'));
114 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_CATS_NOT_SAVED'));
118 // Also here we have to secure it... :(
119 loadTemplate('admin_settings_saved', false, sprintf(getMessage('CATS_LEAST'), getConfig('least_cats')));
122 // Put some data into constants for the template
123 $content['rows'] = ($cats*2+4);
125 // Load header template
126 loadTemplate('member_cats_header', false, $content);
128 // Start switching colors and load all visible categories
129 // @TODO Rewrite this to use $OUT .= ...
131 while ($content = SQL_FETCHARRAY($result)) {
132 // Default he has not joined
133 $content['jn'] = ' checked="checked"';
136 // When we found an entry don't read it, just change the jx elements
137 if (isPostRequestElementSet(('cat'))) {
139 if (postRequestElement('cat', $content['id']) =='Y') {
140 $content['jy'] = ' checked="checked"';
144 // Check if he has an entry
145 if (countSumTotalData($UID, 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($content['id']))) == 1) {
147 $content['jy'] = ' checked="checked"';
152 $content['sw'] = $SW;
154 // Load row template and switch colors
155 loadTemplate('member_cat_row', false, $content);
159 // Load footer template
160 loadTemplate('member_cats_footer');
163 // No cateogries are defined yet
164 loadTemplate('admin_settings_saved', true, getMessage('MEMBER_NO_CATS'));
168 SQL_FREERESULT($result);