2 /************************************************************************
\r
3 * MXChange v0.2.1 Start: 10/19/2003 *
\r
4 * =============== Last change: 06/30/2004 *
\r
6 * -------------------------------------------------------------------- *
\r
7 * File : what-categories.php *
\r
8 * -------------------------------------------------------------------- *
\r
9 * Short description : Select or unselect categories *
\r
10 * -------------------------------------------------------------------- *
\r
11 * Kurzbeschreibung : Kategorien ab- bzw. anw�hlen *
\r
12 * -------------------------------------------------------------------- *
\r
14 * -------------------------------------------------------------------- *
\r
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
\r
16 * For more information visit: http://www.mxchange.org *
\r
18 * This program is free software; you can redistribute it and/or modify *
\r
19 * it under the terms of the GNU General Public License as published by *
\r
20 * the Free Software Foundation; either version 2 of the License, or *
\r
21 * (at your option) any later version. *
\r
23 * This program is distributed in the hope that it will be useful, *
\r
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
\r
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
\r
26 * GNU General Public License for more details. *
\r
28 * You should have received a copy of the GNU General Public License *
\r
29 * along with this program; if not, write to the Free Software *
\r
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
\r
31 * MA 02110-1301 USA *
\r
32 ************************************************************************/
\r
34 // Some security stuff...
\r
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
\r
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
\r
40 elseif (!IS_LOGGED_IN())
\r
42 LOAD_URL(URL."/modules.php[13~?module=index");
\r
45 // Add description as navigation point
\r
46 ADD_DESCR("member", basename(__FILE__));
\r
48 $UID = $GLOBALS['userid'];
\r
49 $WHERE = " WHERE visible='Y'";
\r
50 if (IS_ADMIN()) $WHERE = "";
\r
52 $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats".$WHERE." ORDER BY sort", __FILE__, __LINE__);
\r
53 $cats = SQL_NUMROWS($result);
\r
58 if (isset($_POST['ok']))
\r
61 foreach ($_POST['cat'] as $cat=>$joined)
\r
63 if ($joined == "N") $cnt++;
\r
65 if (($cats - $cnt) < $CONFIG['least_cats'])
\r
67 unset($_POST['ok']);
\r
71 if (isset($_POST['ok']))
\r
73 foreach ($_POST['cat'] as $cat=>$joined)
\r
79 $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1",
\r
80 array($UID, bigintval($cat)), __FILE__, __LINE__);
\r
82 if (SQL_NUMROWS($result_user) == 0)
\r
84 $sql = "INSERT INTO "._MYSQL_PREFIX."_user_cats (userid, cat_id) VALUES ('%s', '%s')";
\r
89 SQL_FREERESULT($result_user);
\r
94 $sql = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1";
\r
100 $result = SQL_QUERY_ESC(trim($sql), array($UID, bigintval($cat)), __FILE__, __LINE__);
\r
103 // Categories saved...
\r
104 LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_CATS_SAVED);
\r
110 // Also here we have to secure it... :(
\r
111 LOAD_TEMPLATE("admin_settings_saved", true, CATS_LEAST.": ".$CONFIG['least_cats']);
\r
113 // Put some data into constants for the template
\r
114 define('__ROWS', ($cats*2+4));
\r
116 // Load header template
\r
117 LOAD_TEMPLATE("member_cats_header");
\r
119 // Start switching colors and load all visible categories
\r
121 while (list($id, $cat) = SQL_FETCHROW($result))
\r
123 // Default he has not joined
\r
124 $JOINED_N = " checked"; $JOINED_Y = "";
\r
126 // Check category selection
\r
127 $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%d AND cat_id=%d LIMIT 1",
\r
128 array($UID, bigintval($id)), __FILE__, __LINE__);
\r
130 // When we found an entry don't read it, just change the JOINED_x variables
\r
131 if (isset($_POST['cat']))
\r
133 if ($_POST['cat'][$id] =="Y") { $JOINED_Y = " checked"; $JOINED_N = ""; }
\r
137 if (SQL_NUMROWS($result_user) == 1)
\r
139 $JOINED_Y = " checked"; $JOINED_N = "";
\r
143 SQL_FREERESULT($result_user);
\r
146 // Prepare data for the template
\r
155 // Load row template and switch colors
\r
156 LOAD_TEMPLATE("member_cat_row", false, $content);
\r
160 // Load footer template
\r
161 LOAD_TEMPLATE("member_cats_footer");
\r
166 // No cateogries are defined yet
\r
167 LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_CATS);
\r
170 SQL_FREERESULT($result);
\r