Possible further fix for #128
[mailer.git] / inc / libs / register_functions.php
index 575f193a548304c1a68b9e10089c61a0083aa855..5ffff9c02f29f97cdae09c60e4d23c6f7aaf7910 100644 (file)
@@ -43,13 +43,13 @@ if (!defined('__SECURITY')) {
 }
 
 //
-function REGISTER_FILL_MUST_CONSTANTS () {
-       $result = SQL_QUERY("SELECT field_name, field_required FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`",
+function registerMustFillout () {
+       $result = SQL_QUERY("SELECT `field_name`, `field_required` FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id` ASC",
                __FUNCTION__, __LINE__);
 
        while ($content = SQL_FETCHARRAY($result)) {
                $value = '';
-               if ($content['field_required'] == 'Y') $value = "<div class=\\\"guest_failed\\\">&nbsp;(*)</div>";
+               if ($content['field_required'] == 'Y') $value = "<span class=\\\"guest_failed\\\">&nbsp;(*)</span>";
                // @TODO Rewrite these constants
                $eval = "define('MUST_".strtoupper($content['field_name'])."', \"".$value."\");";
                eval($eval);
@@ -59,49 +59,53 @@ function REGISTER_FILL_MUST_CONSTANTS () {
        SQL_FREERESULT($result);
 
        // Also fill other constants
-       define('MUST_GENDER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
-       define('MUST_ADDY'  , "<div class=\"guest_failed\">&nbsp;(*)</div>");
-       define('MUST_BIRTH' , "<div class=\"guest_failed\">&nbsp;(*)</div>");
-       define('MUST_MARKER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
+       // @TODO Rewrite these constants, too
+       define('MUST_GENDER', "<span class=\"guest_failed\">&nbsp;(*)</span>");
+       define('MUST_ADDY'  , "<span class=\"guest_failed\">&nbsp;(*)</span>");
+       define('MUST_BIRTH' , "<span class=\"guest_failed\">&nbsp;(*)</span>");
+       define('MUST_MARKER', "<span class=\"guest_failed\">&nbsp;(*)</span>");
 }
 
 //
-function REGISTER_CHECK_REQUIRED_FIELDS (&$array) {
-       $ret = false;
+function ifRequiredRegisterFieldsAreSet (&$array) {
+       // By default all is fine
+       $ret = true;
        foreach ($array as $key => $value) {
-               $result = SQL_QUERY("SELECT field_required FROM `{!_MYSQL_PREFIX!}_must_register` WHERE field_name='".$key."' LIMIT 1",
+               // Check all fields that must register
+               $result = SQL_QUERY("SELECT `id` FROM `{!_MYSQL_PREFIX!}_must_register` WHERE `field_name`='".$key."' AND `field_required`='Y' LIMIT 1",
                        __FUNCTION__, __LINE__);
                if (SQL_NUMROWS($result) == 1) {
-                       // "Must-line" found
-                       list($chk) = SQL_FETCHROW($result);
-
                        // Check if extension country is not found (you have to enter the 2-chars long country code) or
                        // if extensions is present check if country code was selected
                        //         01              2         21    12             3         32    234     5      54    4               43    34                      4    4      5      5432    2      3                      3210
-                       $country = ((!EXT_IS_ACTIVE('country')) || ((EXT_IS_ACTIVE('country')) && (((empty($value)) && ($key == "cntry")) || (($key == "country_code") && (!empty($value)))) && (!empty($array['country_code']))));
-                       if ((empty($value)) && ($chk == 'Y') && (!$country))
-                       {
+                       $country = ((!EXT_IS_ACTIVE('country')) || ((EXT_IS_ACTIVE('country')) && (((empty($value)) && ($key == 'cntry')) || (($key == 'country_code') && (!empty($value)))) && (!empty($array['country_code']))));
+                       if ((empty($value)) && (!$country)) {
                                // Required field not set
-                               $array[$key] = "!";
-                               $ret = true;
-                       }
-               }
+                               $array[$key] = '!';
+                               $ret = false;
+                       } // END - if
+               } // END - if
 
                // Free result
                SQL_FREERESULT($result);
-       }
+       } // END - foreach
+
+       // Return result
        return $ret;
 }
 
-//
+// @TODO This function is no longer used???
 function REGISTER_OUTPUT_REQUIRE_CHECK (&$array) {
-       $result = SQL_QUERY("SELECT field_name, field_required FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`", __FUNCTION__, __LINE__);
+       // Get all fields for output
+       $result = SQL_QUERY("SELECT `field_name`, `field_required` FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`", __FUNCTION__, __LINE__);
+
+       // Loop through them
        while ($content = SQL_FETCHARRAY($result)) {
-               if (($array[$content['field_name']] == "!") && ($content['field_required'] == 'Y')) {
+               if (($array[$content['field_name']] == '!') && ($content['field_required'] == 'Y')) {
                        // Empty entry found
                        $array[$content['field_name']] = '';
                        $OUT = constant('REGISTER_'.strtoupper($content['field_name']).'_REQUIRED');
-                       OUTPUT_HTML("<div class=\"register_failed\">".$OUT."</div>");
+                       registerOutputFailedMessage('', $OUT);
                } // END - if
        } // END - while
 
@@ -109,8 +113,8 @@ function REGISTER_OUTPUT_REQUIRE_CHECK (&$array) {
        SQL_FREERESULT($result);
 }
 
-//
-function REGISTER_ADD_CATEGORY_TABLE ($mode, $return=false) {
+// Generates a 'category table' for the registration form
+function registerGenerateCategoryTable ($mode, $return=false) {
        $OUT = '';
 
        // Guests are mostly not interested in how many members has
@@ -121,7 +125,7 @@ function REGISTER_ADD_CATEGORY_TABLE ($mode, $return=false) {
        if (IS_ADMIN()) $AND = '';
 
        // Look for categories
-       $result = SQL_QUERY("SELECT id, cat, visible FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort`",
+       $result = SQL_QUERY("SELECT `id`, `cat`, `visible` FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort` ASC",
                __FUNCTION__, __LINE__);
 
        if (SQL_NUMROWS($result) > 0) {
@@ -132,22 +136,22 @@ function REGISTER_ADD_CATEGORY_TABLE ($mode, $return=false) {
                        // Is the array element not set?
                        if (!REQUEST_ISSET_POST('cat', $content['id'])) {
                                // Then set it
-                               REQUEST_SET_POST(array('cat', $content['id']), '');
+                               REQUEST_SET_POST('cat', array($content['id'] => ''));
                        } // END - if
 
                        // Prepare array for the template
                        $content = array(
                                'sw'    => $SW,
                                'cat'   => $content['cat'],
-                               'def_y' => "",
-                               'def_n' => "",
+                               'def_y' => '',
+                               'def_n' => '',
                                'id'    => $content['id'],
                        );
 
                        if ((REQUEST_POST('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!REQUEST_ISSET_POST('cat', $content['id'])))) {
-                               $content['def_y'] = ' chkecked="checked"';
+                               $content['def_y'] = ' checked="checked"';
                        } else {
-                               $content['def_n'] = ' chkecked="checked"';
+                               $content['def_n'] = ' checked="checked"';
                        }
 
                        // Load template and switch color
@@ -171,5 +175,15 @@ function REGISTER_ADD_CATEGORY_TABLE ($mode, $return=false) {
                OUTPUT_HTML($OUT);
        }
 }
+
+// Outputs a 'failed message'
+function registerOutputFailedMessage ($messageId, $extra='') {
+       if (empty($messageId)) {
+               OUTPUT_HTML('<div class="register_failed">' . $extra . '</div>');
+       } else {
+               OUTPUT_HTML('<div class="register_failed">{--' . $messageId . '--}' . $extra . '</div>');
+       }
+}
+
 //
 ?>