More double- to single-quotes rewritten
[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 REGISTER_FILL_MUST_CONSTANTS () {
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         define('MUST_GENDER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
63         define('MUST_ADDY'  , "<div class=\"guest_failed\">&nbsp;(*)</div>");
64         define('MUST_BIRTH' , "<div class=\"guest_failed\">&nbsp;(*)</div>");
65         define('MUST_MARKER', "<div class=\"guest_failed\">&nbsp;(*)</div>");
66 }
67
68 //
69 function REGISTER_CHECK_REQUIRED_FIELDS (&$array) {
70         $ret = false;
71         foreach ($array as $key => $value) {
72                 $result = SQL_QUERY("SELECT field_required FROM `{!_MYSQL_PREFIX!}_must_register` WHERE field_name='".$key."' LIMIT 1",
73                         __FUNCTION__, __LINE__);
74                 if (SQL_NUMROWS($result) == 1) {
75                         // "Must-line" found
76                         list($chk) = SQL_FETCHROW($result);
77
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)) && ($chk == 'Y') && (!$country))
83                         {
84                                 // Required field not set
85                                 $array[$key] = "!";
86                                 $ret = true;
87                         }
88                 }
89
90                 // Free result
91                 SQL_FREERESULT($result);
92         }
93         return $ret;
94 }
95
96 //
97 function REGISTER_OUTPUT_REQUIRE_CHECK (&$array) {
98         $result = SQL_QUERY("SELECT field_name, field_required FROM `{!_MYSQL_PREFIX!}_must_register` ORDER BY `id`", __FUNCTION__, __LINE__);
99         while ($content = SQL_FETCHARRAY($result)) {
100                 if (($array[$content['field_name']] == "!") && ($content['field_required'] == 'Y')) {
101                         // Empty entry found
102                         $array[$content['field_name']] = '';
103                         $OUT = constant('REGISTER_'.strtoupper($content['field_name']).'_REQUIRED');
104                         OUTPUT_HTML("<div class=\"register_failed\">".$OUT."</div>");
105                 } // END - if
106         } // END - while
107
108         // Free memory
109         SQL_FREERESULT($result);
110 }
111
112 //
113 function REGISTER_ADD_CATEGORY_TABLE ($mode, $return=false) {
114         $OUT = '';
115
116         // Guests are mostly not interested in how many members has
117         // choosen an individual category
118         $AND = "WHERE `visible`='Y' ";
119
120         // Admins are allowed to see every category...
121         if (IS_ADMIN()) $AND = '';
122
123         // Look for categories
124         $result = SQL_QUERY("SELECT id, cat, visible FROM `{!_MYSQL_PREFIX!}_cats` ".$AND." ORDER BY `sort`",
125                 __FUNCTION__, __LINE__);
126
127         if (SQL_NUMROWS($result) > 0) {
128                 // List alle visible modules (or all to the admin)
129                 $SW = 2;
130                 $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
131                 while ($content = SQL_FETCHARRAY($result)) {
132                         // Is the array element not set?
133                         if (!REQUEST_ISSET_POST('cat', $content['id'])) {
134                                 // Then set it
135                                 REQUEST_SET_POST(array('cat', $content['id']), '');
136                         } // END - if
137
138                         // Prepare array for the template
139                         $content = array(
140                                 'sw'    => $SW,
141                                 'cat'   => $content['cat'],
142                                 'def_y' => "",
143                                 'def_n' => "",
144                                 'id'    => $content['id'],
145                         );
146
147                         if ((REQUEST_POST('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!REQUEST_ISSET_POST('cat', $content['id'])))) {
148                                 $content['def_y'] = ' chkecked="checked"';
149                         } else {
150                                 $content['def_n'] = ' chkecked="checked"';
151                         }
152
153                         // Load template and switch color
154                         $OUT .= LOAD_TEMPLATE("guest_cat_row", true, $content);
155                         $SW = 3 - $SW;
156                 }
157                 $OUT .= "</table>\n";
158
159                 // Free memory
160                 SQL_FREERESULT($result);
161         } else {
162                 // No categories setted up so far...
163                 $OUT .= LOAD_TEMPLATE('admin_settings_saved', true, getMessage('NO_CATEGORIES_VISIBLE'));
164         }
165
166         if ($return === true) {
167                 // Return generated HTML code
168                 return $OUT;
169         } else {
170                 // Output directly (default)
171                 OUTPUT_HTML($OUT);
172         }
173 }
174 //
175 ?>