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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif (!IS_MEMBER()) {
39 LOAD_URL("modules.php[13~?module=index");
42 // Add description as navigation point
43 ADD_DESCR("member", __FILE__);
45 $UID = $GLOBALS['userid'];
46 $whereStatement = " WHERE `visible`='Y'";
47 if (IS_ADMIN()) $whereStatement = "";
49 $result = SQL_QUERY("SELECT id, cat FROM `{!_MYSQL_PREFIX!}_cats`".$whereStatement." ORDER BY `sort`", __FILE__, __LINE__);
50 $cats = SQL_NUMROWS($result);
56 foreach (REQUEST_POST('cat') as $cat => $joined) {
57 if ($joined == "N") $cnt++;
60 if (($cats - $cnt) < getConfig('least_cats')) {
61 REQUEST_UNSET_POST('ok');
67 foreach (REQUEST_POST('cat') as $cat => $joined) {
71 $result_user = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE userid=%s AND cat_id=%s LIMIT 1",
72 array($UID, bigintval($cat)), __FILE__, __LINE__);
74 if (SQL_NUMROWS($result_user) == 0) {
75 $sql = "INSERT INTO `{!_MYSQL_PREFIX!}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
78 SQL_FREERESULT($result_user);
83 $sql = "DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_user_cats` WHERE userid=%s AND cat_id=%s LIMIT 1";
89 $result = SQL_QUERY_ESC(trim($sql), array($UID, bigintval($cat)), __FILE__, __LINE__);
93 // Categories saved...
94 LOAD_TEMPLATE("admin_settings_saved", true, getMessage('MEMBER_CATS_SAVED'));
97 // Also here we have to secure it... :(
98 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('CATS_LEAST'), getConfig('least_cats')));
100 // Put some data into constants for the template
101 define('__ROWS', ($cats*2+4));
103 // Load header template
104 LOAD_TEMPLATE("member_cats_header");
106 // Start switching colors and load all visible categories
107 // @TODO Rewrite this to use $OUT .= ...
109 while ($content = SQL_FETCHARRAY($result)) {
110 // Default he has not joined
111 $content['jn'] = " checked=\"checked\"";
114 // When we found an entry don't read it, just change the jx elements
115 if (REQUEST_ISSET_POST(('cat'))) {
117 if (REQUEST_POST('cat', $content['id']) =='Y') {
118 $content['jy'] = " checked=\"checked\"";
122 // Check if he has an entry
123 if (GET_TOTAL_DATA($UID, "user_cats", "id", "userid", true, sprintf(" AND cat_id=%s", bigintval($content['id']))) == 1) {
125 $content['jy'] = " checked=\"checked\"";
130 $content['sw'] = $SW;
132 // Load row template and switch colors
133 LOAD_TEMPLATE("member_cat_row", false, $content);
137 // Load footer template
138 LOAD_TEMPLATE("member_cats_footer");
141 // No cateogries are defined yet
142 LOAD_TEMPLATE("admin_settings_saved", true, getMessage('MEMBER_NO_CATS'));
146 SQL_FREERESULT($result);