Updated copyright notice as there are changes in this year
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         exit();
41 } elseif (!isMember()) {
42         redirectToIndexMemberOnlyModule();
43 }
44
45 // Add description as navigation point
46 addYouAreHereLink('member', __FILE__);
47
48 $whereStatement = " WHERE `visible`='Y'";
49 if (isAdmin()) $whereStatement = '';
50
51 // Get all categories
52 $result = SQL_QUERY('SELECT `id`, `cat` FROM `{?_MYSQL_PREFIX?}_cats`' . $whereStatement . ' ORDER BY `sort` ASC', __FILE__, __LINE__);
53
54 // Are there entries?
55 if (!SQL_HASZERONUMS($result)) {
56         $LEAST = FALSE;
57         if (isFormSent()) {
58                 $count = '0';
59                 foreach (postRequestElement('cat') as $categoryId => $joined) {
60                         if ($joined != 'Y') $count++;
61                 } // END - foreach
62
63                 if ((SQL_NUMROWS($result) - $count) < getLeastCats()) {
64                         unsetPostRequestElement('ok');
65                         $LEAST = TRUE;
66                 } // END - if
67         } // END - if
68
69         // Is the form sent?
70         if (isFormSent()) {
71                 // Start counting all
72                 $count = '0';
73
74                 // Ini SQLs here
75                 initSqls();
76
77                 // Go through all entries
78                 foreach (postRequestElement('cat') as $categoryId => $joined) {
79                         // Has the user joined on this category?
80                         switch ($joined) {
81                                 case 'Y':
82                                         // Check if this category has an entry
83                                         if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($categoryId))) == 0) {
84                                                 // No, so add it
85                                                 addSql(sprintf('INSERT INTO `{?_MYSQL_PREFIX?}_user_cats` (`userid`, `cat_id`) VALUES (%s,%s)', getMemberId(), bigintval($categoryId)));
86                                         } // END - if
87                                         break;
88
89                                 case 'N':
90                                         addSql(sprintf('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_user_cats` WHERE `userid`=%s AND `cat_id`=%s LIMIT 1', getMemberId(), bigintval($categoryId)));
91                                         break;
92                         } // END - switch
93                 } // END - foreach
94
95                 // Are there entries?
96                 if (countSqls() > 0) {
97                         // Run SQL commands
98                         $count = runFilterChain('run_sqls');
99                 } // END - if
100
101                 // Categories saved?
102                 if ($count > 0) {
103                         // Output message
104                         displayMessage('{--MEMBER_CATEGORIES_SAVED--}');
105                 } else {
106                         // None save
107                         displayMessage('{--MEMBER_CATEGORIES_NOT_SAVED--}');
108                 }
109         } else {
110                 if ($LEAST === TRUE) {
111                         // Also here we have to secure it... :(
112                         displayMessage('{--CHOOSE_MORE_CATEGORIES--}');
113                 } // END - if
114
115                 // Load all categories of this member
116                 $OUT = '';
117                 while ($content = SQL_FETCHARRAY($result)) {
118                         // Default he has not joined, add color switch
119                         $content['jn'] = ' checked="checked"';
120                         $content['jy'] = '';
121
122                         // When we found an entry don't read it, just change the jx elements
123                         if ((isFormSent()) && (isPostRequestElementSet('cat'))) {
124                                 // Form sent?
125                                 if (postRequestElement('cat', $content['id']) =='Y') {
126                                         $content['jy'] = ' checked="checked"';
127                                         $content['jn'] = '';
128                                 } // END - if
129                         } else {
130                                 // Check if he has an entry
131                                 if (countSumTotalData(getMemberId(), 'user_cats', 'id', 'userid', TRUE, sprintf(' AND `cat_id`=%s', bigintval($content['id']))) == 1) {
132                                         $content['jn'] = '';
133                                         $content['jy'] = ' checked="checked"';
134                                 } // END - if
135                         }
136
137                         // Load row template
138                         $OUT .= loadTemplate('member_cats_row', TRUE, $content);
139                 } // END - while
140
141                 // Free result
142                 SQL_FREERESULT($result);
143
144                 // Load footer template
145                 loadTemplate('member_cats', FALSE, $OUT);
146         }
147 } else {
148         // No cateogries are defined yet
149         displayMessage('{--MEMBER_NO_CATEGORIES--}');
150 }
151
152 // Free result
153 SQL_FREERESULT($result);
154
155 // [EOF]
156 ?>