Anonymity/privacy extension 'removeip' added
[mailer.git] / inc / modules / member / what-categories.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 10/19/2003 *
4  * ===============                              Last change: 06/30/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-categories.php                              *
8  * -------------------------------------------------------------------- *
9  * Short description : Select or unselect categories                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Kategorien ab- bzw. anwaehlen                    *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         LOAD_URL("modules.php[13~?module=index");
40 }
41
42 // Add description as navigation point
43 ADD_DESCR("member", basename(__FILE__));
44
45 $UID = $GLOBALS['userid'];
46 $whereStatement = " WHERE visible='Y'";
47 if (IS_ADMIN()) $whereStatement = "";
48
49 $result = SQL_QUERY("SELECT id, cat FROM "._MYSQL_PREFIX."_cats".$whereStatement." ORDER BY sort", __FILE__, __LINE__);
50 $cats = SQL_NUMROWS($result);
51
52 if ($cats > 0)
53 {
54         $LEAST = false;
55         if (isset($_POST['ok']))
56         {
57                 $cnt = 0;
58                 foreach ($_POST['cat'] as $cat => $joined)
59                 {
60                         if ($joined == "N") $cnt++;
61                 }
62                 if (($cats - $cnt) < $_CONFIG['least_cats'])
63                 {
64                         unset($_POST['ok']);
65                         $LEAST = true;
66                 }
67         }
68         if (isset($_POST['ok']))
69         {
70                 foreach ($_POST['cat'] as $cat => $joined)
71                 {
72                         switch ($joined)
73                         {
74                                 case 'Y':
75                                         $sql = "";
76                                         $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%s AND cat_id=%s LIMIT 1",
77                                          array($UID, bigintval($cat)), __FILE__, __LINE__);
78
79                                         if (SQL_NUMROWS($result_user) == 0)
80                                         {
81                                                 $sql = "INSERT INTO "._MYSQL_PREFIX."_user_cats (userid, cat_id) VALUES ('%s','%s')";
82                                         }
83                                          else
84                                         {
85                                                 // Free memory
86                                                 SQL_FREERESULT($result_user);
87                                         }
88                                         break;
89
90                                 case 'N':
91                                         $sql = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%s AND cat_id=%s LIMIT 1";
92                                         break;
93                         }
94                         if (!empty($sql))
95                         {
96                                 // Run SQL command
97                                 $result = SQL_QUERY_ESC(trim($sql), array($UID, bigintval($cat)), __FILE__, __LINE__);
98                         }
99                 }
100                 // Categories saved...
101                 LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_CATS_SAVED);
102         }
103          else
104         {
105                 if ($LEAST)
106                 {
107                         // Also here we have to secure it... :(
108                         LOAD_TEMPLATE("admin_settings_saved", true, CATS_LEAST.": ".$_CONFIG['least_cats']);
109                 }
110                 // Put some data into constants for the template
111                 define('__ROWS', ($cats*2+4));
112
113                 // Load header template
114                 LOAD_TEMPLATE("member_cats_header");
115
116                 // Start switching colors and load all visible categories
117                 $SW = 2;
118                 while (list($id, $cat) = SQL_FETCHROW($result))
119                 {
120                         // Default he has not joined
121                         $JOINED_N = " checked=\"checked\""; $JOINED_Y = "";
122
123                         // Check category selection
124                         $result_user = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_cats WHERE userid=%s AND cat_id=%s LIMIT 1",
125                          array($UID, bigintval($id)), __FILE__, __LINE__);
126
127                         // When we found an entry don't read it, just change the JOINED_x variables
128                         if (isset($_POST['cat']))
129                         {
130                                 if ($_POST['cat'][$id] =='Y') { $JOINED_Y = " checked=\"checked\""; $JOINED_N = ""; }
131                         }
132                          else
133                         {
134                                 if (SQL_NUMROWS($result_user) == 1)
135                                 {
136                                         $JOINED_Y = " checked=\"checked\""; $JOINED_N = "";
137                                 }
138
139                                 // Free memory
140                                 SQL_FREERESULT($result_user);
141                         }
142
143                         // Prepare data for the template
144                         $content = array(
145                                 'sw'  => $SW,
146                                 'id'  => $id,
147                                 'cat' => $cat,
148                                 'jy'  => $JOINED_Y,
149                                 'jn'  => $JOINED_N,
150                         );
151
152                         // Load row template and switch colors
153                         LOAD_TEMPLATE("member_cat_row", false, $content);
154                         $SW = 3 - $SW;
155                 }
156
157                 // Load footer template
158                 LOAD_TEMPLATE("member_cats_footer");
159         }
160 }
161  else
162 {
163         // No cateogries are defined yet
164         LOAD_TEMPLATE("admin_settings_saved", true, MEMBER_NO_CATS);
165 }
166
167 SQL_FREERESULT($result);
168
169 //
170 ?>