config.php partly solved, see #117
[mailer.git] / inc / libs / register_functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/10/2004 *
4  * ===============                              Last change: 07/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : register_functions.php                           *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for register extension         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezielle Funktion fuer register-Erweiterung     *
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 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 }
44
45 //
46 function registerMustFillout () {
47         $result = SQL_QUERY("SELECT field_name, field_required FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`",
48                 __FUNCTION__, __LINE__);
49
50         while ($content = SQL_FETCHARRAY($result)) {
51                 $value = '';
52                 if ($content['field_required'] == 'Y') $value = "<div class=\\\"guest_failed\\\">&nbsp;(*)</div>";
53                 // @TODO Rewrite these constants
54                 $eval = "define('MUST_".strtoupper($content['field_name'])."', \"".$value."\");";
55                 eval($eval);
56         } // END - while
57
58         // Free memory
59         SQL_FREERESULT($result);
60
61         // Also fill other constants
62         // @TODO Rewrite these constants, too
63         define('MUST_GENDER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
64         define('MUST_ADDY'  , "<div class=\"guest_failed\">&nbsp;(*)</div>");
65         define('MUST_BIRTH' , "<div class=\"guest_failed\">&nbsp;(*)</div>");
66         define('MUST_MARKER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
67 }
68
69 //
70 function REGISTER_CHECK_REQUIRED_FIELDS (&$array) {
71         $ret = false;
72         foreach ($array as $key => $value) {
73                 $result = SQL_QUERY("SELECT field_required FROM `{!_MYSQL_PREFIX!}_must_register` WHERE field_name='".$key."' LIMIT 1",
74                         __FUNCTION__, __LINE__);
75                 if (SQL_NUMROWS($result) == 1) {
76                         // "Must-line" found
77                         list($chk) = SQL_FETCHROW($result);
78
79                         // Check if extension country is not found (you have to enter the 2-chars long country code) or
80                         // if extensions is present check if country code was selected
81                         //         01              2         21    12             3         32    234     5      54    4               43    34                      4    4      5      5432    2      3                      3210
82                         $country = ((!EXT_IS_ACTIVE('country')) || ((EXT_IS_ACTIVE('country')) && (((empty($value)) && ($key == "cntry")) || (($key == "country_code") && (!empty($value)))) && (!empty($array['country_code']))));
83                         if ((empty($value)) && ($chk == 'Y') && (!$country))
84                         {
85                                 // Required field not set
86                                 $array[$key] = '!';
87                                 $ret = true;
88                         }
89                 }
90
91                 // Free result
92                 SQL_FREERESULT($result);
93         }
94         return $ret;
95 }
96
97 //
98 function REGISTER_OUTPUT_REQUIRE_CHECK (&$array) {
99         $result = SQL_QUERY("SELECT `field_name`, `field_required` FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`", __FUNCTION__, __LINE__);
100         while ($content = SQL_FETCHARRAY($result)) {
101                 if (($array[$content['field_name']] == '!') && ($content['field_required'] == 'Y')) {
102                         // Empty entry found
103                         $array[$content['field_name']] = '';
104                         $OUT = constant('REGISTER_'.strtoupper($content['field_name']).'_REQUIRED');
105                         registerOutputFailedMessage('', $OUT);
106                 } // END - if
107         } // END - while
108
109         // Free memory
110         SQL_FREERESULT($result);
111 }
112
113 // Generates a 'category table' for the registration form
114 function registerGenerateCategoryTable ($mode, $return=false) {
115         $OUT = '';
116
117         // Guests are mostly not interested in how many members has
118         // choosen an individual category
119         $AND = "WHERE `visible`='Y' ";
120
121         // Admins are allowed to see every category...
122         if (IS_ADMIN()) $AND = '';
123
124         // Look for categories
125         $result = SQL_QUERY("SELECT `id`, `cat`, `visible` FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort` ASC",
126                 __FUNCTION__, __LINE__);
127
128         if (SQL_NUMROWS($result) > 0) {
129                 // List alle visible modules (or all to the admin)
130                 $SW = 2;
131                 $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
132                 while ($content = SQL_FETCHARRAY($result)) {
133                         // Is the array element not set?
134                         if (!REQUEST_ISSET_POST('cat', $content['id'])) {
135                                 // Then set it
136                                 REQUEST_SET_POST(array('cat', $content['id']), '');
137                         } // END - if
138
139                         // Prepare array for the template
140                         $content = array(
141                                 'sw'    => $SW,
142                                 'cat'   => $content['cat'],
143                                 'def_y' => '',
144                                 'def_n' => '',
145                                 'id'    => $content['id'],
146                         );
147
148                         if ((REQUEST_POST('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!REQUEST_ISSET_POST('cat', $content['id'])))) {
149                                 $content['def_y'] = ' checked="checked"';
150                         } else {
151                                 $content['def_n'] = ' checked="checked"';
152                         }
153
154                         // Load template and switch color
155                         $OUT .= LOAD_TEMPLATE("guest_cat_row", true, $content);
156                         $SW = 3 - $SW;
157                 }
158                 $OUT .= "</table>\n";
159
160                 // Free memory
161                 SQL_FREERESULT($result);
162         } else {
163                 // No categories setted up so far...
164                 $OUT .= LOAD_TEMPLATE('admin_settings_saved', true, getMessage('NO_CATEGORIES_VISIBLE'));
165         }
166
167         if ($return === true) {
168                 // Return generated HTML code
169                 return $OUT;
170         } else {
171                 // Output directly (default)
172                 OUTPUT_HTML($OUT);
173         }
174 }
175
176 // Outputs a 'failed message'
177 function registerOutputFailedMessage ($messageId, $extra='') {
178         if (empty($messageId)) {
179                 OUTPUT_HTML('<div class="register_failed">' . $extra . '</div>');
180         } else {
181                 OUTPUT_HTML('<div class="register_failed">{--' . $messageId . '--}' . $extra . '</div>');
182         }
183 }
184
185 //
186 ?>