2 /************************************************************************
3 * MXChange v0.2.1 Start: 07/10/2004 *
4 * =============== Last change: 07/10/2004 *
6 * -------------------------------------------------------------------- *
7 * File : register_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for register extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktion fuer register-Erweiterung *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
46 function registerMustFillout () {
47 $result = SQL_QUERY("SELECT field_name, field_required FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`",
48 __FUNCTION__, __LINE__);
50 while ($content = SQL_FETCHARRAY($result)) {
52 if ($content['field_required'] == 'Y') $value = "<span class=\\\"guest_failed\\\"> (*)</span>";
53 // @TODO Rewrite these constants
54 $eval = "define('MUST_".strtoupper($content['field_name'])."', \"".$value."\");";
59 SQL_FREERESULT($result);
61 // Also fill other constants
62 // @TODO Rewrite these constants, too
63 define('MUST_GENDER', "<span class=\"guest_failed\"> (*)</span>");
64 define('MUST_ADDY' , "<span class=\"guest_failed\"> (*)</span>");
65 define('MUST_BIRTH' , "<span class=\"guest_failed\"> (*)</span>");
66 define('MUST_MARKER', "<span class=\"guest_failed\"> (*)</span>");
70 function REGISTER_CHECK_REQUIRED_FIELDS (&$array) {
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) {
77 list($chk) = SQL_FETCHROW($result);
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))
85 // Required field not set
92 SQL_FREERESULT($result);
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')) {
103 $array[$content['field_name']] = '';
104 $OUT = constant('REGISTER_'.strtoupper($content['field_name']).'_REQUIRED');
105 registerOutputFailedMessage('', $OUT);
110 SQL_FREERESULT($result);
113 // Generates a 'category table' for the registration form
114 function registerGenerateCategoryTable ($mode, $return=false) {
117 // Guests are mostly not interested in how many members has
118 // choosen an individual category
119 $AND = "WHERE `visible`='Y' ";
121 // Admins are allowed to see every category...
122 if (IS_ADMIN()) $AND = '';
124 // Look for categories
125 $result = SQL_QUERY("SELECT `id`, `cat`, `visible` FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort` ASC",
126 __FUNCTION__, __LINE__);
128 if (SQL_NUMROWS($result) > 0) {
129 // List alle visible modules (or all to the admin)
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'])) {
136 REQUEST_SET_POST(array('cat', $content['id']), '');
139 // Prepare array for the template
142 'cat' => $content['cat'],
145 'id' => $content['id'],
148 if ((REQUEST_POST('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!REQUEST_ISSET_POST('cat', $content['id'])))) {
149 $content['def_y'] = ' checked="checked"';
151 $content['def_n'] = ' checked="checked"';
154 // Load template and switch color
155 $OUT .= LOAD_TEMPLATE("guest_cat_row", true, $content);
158 $OUT .= "</table>\n";
161 SQL_FREERESULT($result);
163 // No categories setted up so far...
164 $OUT .= LOAD_TEMPLATE('admin_settings_saved', true, getMessage('NO_CATEGORIES_VISIBLE'));
167 if ($return === true) {
168 // Return generated HTML code
171 // Output directly (default)
176 // Outputs a 'failed message'
177 function registerOutputFailedMessage ($messageId, $extra='') {
178 if (empty($messageId)) {
179 OUTPUT_HTML('<div class="register_failed">' . $extra . '</div>');
181 OUTPUT_HTML('<div class="register_failed">{--' . $messageId . '--}' . $extra . '</div>');