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