Naming convention applied, ext-network menu resorted:
[mailer.git] / inc / modules / member / what-categories.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
21  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if (!defined('__SECURITY')) {
42         die();
43 } elseif (!isMember()) {
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Add description as navigation point
48 addMenuDescription('member', __FILE__);
49
50 $whereStatement = " WHERE `visible`='Y'";
51 if (isAdmin()) $whereStatement = '';
52
53 // Get all categories
54 $result = SQL_QUERY("SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`".$whereStatement." ORDER BY `sort` ASC", __FILE__, __LINE__);
55
56 // Do we have entries?
57 if (SQL_NUMROWS($result) > 0) {
58         $LEAST = false;
59         if (isFormSent()) {
60                 $cnt = '0';
61                 foreach (postRequestParameter('cat') as $cat => $joined) {
62                         if ($joined != 'Y') $cnt++;
63                 } // END - foreach
64
65                 if ((SQL_NUMROWS($result) - $cnt) < getConfig('least_cats')) {
66                         unsetPostRequestParameter('ok');
67                         $LEAST = true;
68                 } // END - if
69         } // END - if
70
71         // Is the form sent?
72         if (isFormSent()) {
73                 // Start counting all
74                 $cnt = '0';
75
76                 // Go through all entries
77                 foreach (postRequestParameter('cat') as $cat => $joined) {
78                         // Ini sql here
79                         $sql = '';
80
81                         // Has the user joined on this category?
82                         switch ($joined) {
83                                 case 'Y':
84                                         $result_user = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1",
85                                                 array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
86
87                                         if (!SQL_HASZERONUMS($result_user)) {
88                                                 $sql = "INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (userid, cat_id) VALUES ('%s','%s')";
89                                         } // END - if
90
91                                         // Free memory
92                                         SQL_FREERESULT($result_user);
93                                         break;
94
95                                 case 'N':
96                                         $sql = "DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1";
97                                         break;
98                         } // END - switch
99
100                         if (!empty($sql)) {
101                                 // Run SQL command
102                                 SQL_QUERY_ESC(trim($sql), array(getMemberId(), bigintval($cat)), __FILE__, __LINE__);
103
104                                 // Count this row
105                                 $cnt += SQL_AFFECTEDROWS();
106                         } // END - if
107                 } // END - foreach
108
109                 // Categories saved?
110                 if ($cnt > 0) {
111                         // Output message
112                         loadTemplate('admin_settings_saved', false, '{--MEMBER_CATEGORIES_SAVED--}');
113                 } else {
114                         // None save
115                         loadTemplate('admin_settings_saved', false, '{--MEMBER_CATEGORIES_NOT_SAVED--}');
116                 }
117         } else {
118                 if ($LEAST === true) {
119                         // Also here we have to secure it... :(
120                         loadTemplate('admin_settings_saved', false, '{--CATS_LEAST--}');
121                 } // END - if
122
123                 // Put some data into constants for the template
124                 $content['rows'] = (SQL_NUMROWS($result) * 2 + 4);
125
126                 // Load header template
127                 loadTemplate('member_cats_header', false, $content);
128
129                 // Start switching colors and load all visible categories
130                 // @TODO Rewrite this to use $OUT .= ...
131                 $OUT = '';
132                 while ($content = SQL_FETCHARRAY($result)) {
133                         // Default he has not joined
134                         $content['jn'] = ' checked="checked"';
135                         $content['jy'] = '';
136
137                         // When we found an entry don't read it, just change the jx elements
138                         if (isPostRequestParameterSet('cat')) {
139                                 // Form sent?
140                                 if (postRequestParameter('cat', $content['id']) =='Y') {
141                                         $content['jy'] = ' checked="checked"';
142                                         $content['jn'] = '';
143                                 } // END - if
144                         } else {
145                                 // Check if he has an entry
146                                 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', true, sprintf(" AND `cat_id`=%s", bigintval($content['id']))) == 1) {
147                                         $content['jn'] = '';
148                                         $content['jy'] = ' checked="checked"';
149                                 }
150                         }
151
152                         // Load row template and switch colors
153                         loadTemplate('member_cat_row', false, $content);
154                 } // END - while
155
156                 // Load footer template
157                 loadTemplate('member_cats_footer');
158         }
159 } else {
160         // No cateogries are defined yet
161         loadTemplate('admin_settings_saved', false, '{--MEMBER_NO_CATEGORIES--}');
162 }
163
164 // Free result
165 SQL_FREERESULT($result);
166
167 // [EOF]
168 ?>