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