More misc fixes and rewrites (sorry, lame description)
[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` ASC",
48                 __FUNCTION__, __LINE__);
49
50         while ($content = SQL_FETCHARRAY($result)) {
51                 $value = '';
52                 if ($content['field_required'] == 'Y') $value = "<span class=\\\"guest_failed\\\">&nbsp;(*)</span>";
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', "<span class=\"guest_failed\">&nbsp;(*)</span>");
64         define('MUST_ADDY'  , "<span class=\"guest_failed\">&nbsp;(*)</span>");
65         define('MUST_BIRTH' , "<span class=\"guest_failed\">&nbsp;(*)</span>");
66         define('MUST_MARKER', "<span class=\"guest_failed\">&nbsp;(*)</span>");
67 }
68
69 //
70 function ifRequiredRegisterFieldsAreSet (&$array) {
71         // By default all is fine
72         $ret = true;
73         foreach ($array as $key => $value) {
74                 // Check all fields that must register
75                 $result = SQL_QUERY("SELECT `id` FROM `{!_MYSQL_PREFIX!}_must_register` WHERE `field_name`='".$key."' AND `field_required`='Y' LIMIT 1",
76                         __FUNCTION__, __LINE__);
77                 if (SQL_NUMROWS($result) == 1) {
78                         // Check if extension country is not found (you have to enter the 2-chars long country code) or
79                         // if extensions is present check if country code was selected
80                         //         01              2         21    12             3         32    234     5      54    4               43    34                      4    4      5      5432    2      3                      3210
81                         $country = ((!EXT_IS_ACTIVE('country')) || ((EXT_IS_ACTIVE('country')) && (((empty($value)) && ($key == 'cntry')) || (($key == 'country_code') && (!empty($value)))) && (!empty($array['country_code']))));
82                         if ((empty($value)) && (!$country)) {
83                                 // Required field not set
84                                 $array[$key] = '!';
85                                 $ret = false;
86                         } // END - if
87                 } // END - if
88
89                 // Free result
90                 SQL_FREERESULT($result);
91         } // END - foreach
92
93         // Return result
94         return $ret;
95 }
96
97 // @TODO This function is no longer used???
98 function REGISTER_OUTPUT_REQUIRE_CHECK (&$array) {
99         // Get all fields for output
100         $result = SQL_QUERY("SELECT `field_name`, `field_required` FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`", __FUNCTION__, __LINE__);
101
102         // Loop through them
103         while ($content = SQL_FETCHARRAY($result)) {
104                 if (($array[$content['field_name']] == '!') && ($content['field_required'] == 'Y')) {
105                         // Empty entry found
106                         $array[$content['field_name']] = '';
107                         $OUT = constant('REGISTER_'.strtoupper($content['field_name']).'_REQUIRED');
108                         registerOutputFailedMessage('', $OUT);
109                 } // END - if
110         } // END - while
111
112         // Free memory
113         SQL_FREERESULT($result);
114 }
115
116 // Generates a 'category table' for the registration form
117 function registerGenerateCategoryTable ($mode, $return=false) {
118         $OUT = '';
119
120         // Guests are mostly not interested in how many members has
121         // choosen an individual category
122         $AND = "WHERE `visible`='Y' ";
123
124         // Admins are allowed to see every category...
125         if (IS_ADMIN()) $AND = '';
126
127         // Look for categories
128         $result = SQL_QUERY("SELECT `id`, `cat`, `visible` FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort` ASC",
129                 __FUNCTION__, __LINE__);
130
131         if (SQL_NUMROWS($result) > 0) {
132                 // List alle visible modules (or all to the admin)
133                 $SW = 2;
134                 $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
135                 while ($content = SQL_FETCHARRAY($result)) {
136                         // Is the array element not set?
137                         if (!REQUEST_ISSET_POST('cat', $content['id'])) {
138                                 // Then set it
139                                 REQUEST_SET_POST('cat', array($content['id'] => ''));
140                         } // END - if
141
142                         // Prepare array for the template
143                         $content = array(
144                                 'sw'    => $SW,
145                                 'cat'   => $content['cat'],
146                                 'def_y' => '',
147                                 'def_n' => '',
148                                 'id'    => $content['id'],
149                         );
150
151                         if ((REQUEST_POST('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!REQUEST_ISSET_POST('cat', $content['id'])))) {
152                                 $content['def_y'] = ' checked="checked"';
153                         } else {
154                                 $content['def_n'] = ' checked="checked"';
155                         }
156
157                         // Load template and switch color
158                         $OUT .= LOAD_TEMPLATE("guest_cat_row", true, $content);
159                         $SW = 3 - $SW;
160                 }
161                 $OUT .= "</table>\n";
162
163                 // Free memory
164                 SQL_FREERESULT($result);
165         } else {
166                 // No categories setted up so far...
167                 $OUT .= LOAD_TEMPLATE('admin_settings_saved', true, getMessage('NO_CATEGORIES_VISIBLE'));
168         }
169
170         if ($return === true) {
171                 // Return generated HTML code
172                 return $OUT;
173         } else {
174                 // Output directly (default)
175                 OUTPUT_HTML($OUT);
176         }
177 }
178
179 // Outputs a 'failed message'
180 function registerOutputFailedMessage ($messageId, $extra='') {
181         if (empty($messageId)) {
182                 OUTPUT_HTML('<div class="register_failed">' . $extra . '</div>');
183         } else {
184                 OUTPUT_HTML('<div class="register_failed">{--' . $messageId . '--}' . $extra . '</div>');
185         }
186 }
187
188 //
189 ?>