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 * 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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
43 } elseif (!isMember()) {
44 redirectToIndexMemberOnlyModule();
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
50 $whereStatement = " WHERE `visible`='Y'";
51 if (isAdmin()) $whereStatement = '';
54 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC", __FILE__, __LINE__);
57 $numCategories = SQL_NUMROWS($result);
59 if ($numCategories > 0) {
63 foreach (postRequestParameter('cat') as $cat => $joined) {
64 if ($joined != 'Y') $cnt++;
67 if (($numCategories - $cnt) < getConfig('least_cats')) {
68 unsetPostRequestParameter('ok');
78 // Go through all entries
79 foreach (postRequestParameter('cat') as $cat => $joined) {
83 // Has the user joined on this category?
86 $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
87 array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
89 if (!SQL_HASZERONUMS($result_user)) {
90 $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
94 SQL_FREERESULT($result_user);
98 $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1";
104 SQL_QUERY_ESC(trim($sql), array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
107 $cnt += SQL_AFFECTEDROWS();
114 loadTemplate('admin_settings_saved', false, '{--MEMBER_CATEGORIES_SAVED--}');
117 loadTemplate('admin_settings_saved', false, '{--MEMBER_CATEGORIES_NOT_SAVED--}');
120 if ($LEAST === true) {
121 // Also here we have to secure it... :(
122 loadTemplate('admin_settings_saved', false, '{--CATS_LEAST--}');
125 // Put some data into constants for the template
126 $content['rows'] = ($numCategories * 2 + 4);
128 // Load header template
129 loadTemplate('member_cats_header', false, $content);
131 // Start switching colors and load all visible categories
132 // @TODO Rewrite this to use $OUT .= ...
134 while ($content = SQL_FETCHARRAY($result)) {
135 // Default he has not joined
136 $content['jn'] = ' checked="checked"';
139 // When we found an entry don't read it, just change the jx elements
140 if (isPostRequestParameterSet('cat')) {
142 if (postRequestParameter('cat', $content['id']) =='Y') {
143 $content['jy'] = ' checked="checked"';
147 // Check if he has an entry
148 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($content['id']))) == 1) {
150 $content['jy'] = ' checked="checked"';
154 // Load row template and switch colors
155 loadTemplate('member_cat_row', false, $content);
158 // Load footer template
159 loadTemplate('member_cats_footer');
162 // No cateogries are defined yet
163 loadTemplate('admin_settings_saved', false, '{--MEMBER_NO_CATEGORIES--}');
167 SQL_FREERESULT($result);