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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 elseif (!IS_LOGGED_IN())
42 LOAD_URL("modules.php[13~?module=index");
45 // Add description as navigation point
46 ADD_DESCR("member", basename(__FILE__));
48 $UID = $GLOBALS['userid'];
49 $whereStatement = " WHERE visible='Y'";
50 if (IS_ADMIN()) $whereStatement = "";
52 $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats".$whereStatement." ORDER BY sort", __FILE__, __LINE__);
53 $cats = SQL_NUMROWS($result);
58 if (isset($_POST['ok']))
61 foreach ($_POST['cat'] as $cat=>$joined)
63 if ($joined == 'N') $cnt++;
65 if (($cats - $cnt) < $_CONFIG['least_cats'])
71 if (isset($_POST['ok']))
73 foreach ($_POST['cat'] as $cat=>$joined)
79 $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1",
80 array($UID, bigintval($cat)), __FILE__, __LINE__);
82 if (SQL_NUMROWS($result_user) == 0)
84 $sql = "INSERT INTO "._MYSQL_PREFIX."_user_cats (userid, cat_id) VALUES ('%s', '%s')";
89 SQL_FREERESULT($result_user);
94 $sql = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1";
100 $result = SQL_QUERY_ESC(trim($sql), array($UID, bigintval($cat)), __FILE__, __LINE__);
103 // Categories saved...
104 LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_CATS_SAVED);
110 // Also here we have to secure it... :(
111 LOAD_TEMPLATE("admin_settings_saved", true, CATS_LEAST.": ".$_CONFIG['least_cats']);
113 // Put some data into constants for the template
114 define('__ROWS', ($cats*2+4));
116 // Load header template
117 LOAD_TEMPLATE("member_cats_header");
119 // Start switching colors and load all visible categories
121 while (list($id, $cat) = SQL_FETCHROW($result))
123 // Default he has not joined
124 $JOINED_N = ' checked'; $JOINED_Y = "";
126 // Check category selection
127 $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1",
128 array($UID, bigintval($id)), __FILE__, __LINE__);
130 // When we found an entry don't read it, just change the JOINED_x variables
131 if (isset($_POST['cat']))
133 if ($_POST['cat'][$id] =='Y') { $JOINED_Y = ' checked'; $JOINED_N = ""; }
137 if (SQL_NUMROWS($result_user) == 1)
139 $JOINED_Y = ' checked'; $JOINED_N = "";
143 SQL_FREERESULT($result_user);
146 // Prepare data for the template
155 // Load row template and switch colors
156 LOAD_TEMPLATE("member_cat_row", false, $content);
160 // Load footer template
161 LOAD_TEMPLATE("member_cats_footer");
166 // No cateogries are defined yet
167 LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_CATS);
170 SQL_FREERESULT($result);