Code-style applied, surfbar URLs can now be edited
[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 (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 //
42 function REGISTER_FILL_MUST_CONSTANTS()
43 {
44         $result = SQL_QUERY("SELECT field_name, field_required FROM "._MYSQL_PREFIX."_must_register ORDER BY id", __FILE__, __LINE__);
45         while(list($name, $required) = SQL_FETCHROW($result))
46         {
47                 $value = "";
48                 if ($required == "Y") $value = "<FONT class=\\\"guest_failed\\\">&nbsp;(*)</FONT>";
49                 $eval = "define('MUST_".strtoupper($name)."', \"".$value."\");";
50                 eval($eval);
51         }
52
53         // Free memory
54         SQL_FREERESULT($result);
55
56         // Also fill other constants
57         define('MUST_SEX'   , "<FONT class=\"guest_failed\">&nbsp;(*)</FONT>");
58         define('MUST_ADDY'  , "<FONT class=\"guest_failed\">&nbsp;(*)</FONT>");
59         define('MUST_BIRTH' , "<FONT class=\"guest_failed\">&nbsp;(*)</FONT>");
60         define('MUST_MARKER', "<FONT class=\"guest_failed\">&nbsp;(*)</FONT>");
61 }
62 //
63 function REGISTER_CHECK_REQUIRED_FIELDS(&$array)
64 {
65         $ret = false;
66         foreach ($array as $key => $value)
67         {
68                 $result = SQL_QUERY("SELECT field_required FROM "._MYSQL_PREFIX."_must_register WHERE field_name='".$key."' LIMIT 1", __FILE__, __LINE__);
69                 if (SQL_NUMROWS($result) == 1)
70                 {
71                         // "Must-line" found
72                         list($chk) = SQL_FETCHROW($result);
73                         SQL_FREERESULT($result);
74
75                         // Check if extension country is not found (you have to enter the 2-chars long country code) or
76                         // if extensions is present check if country code was selected
77                         //         01              2         21    12             3         32    234     5      54    4               43    34                      4    4      5      5432    2      3                      3210
78                         $country = ((!EXT_IS_ACTIVE("country")) || ((EXT_IS_ACTIVE("country")) && (((empty($value)) && ($key == "cntry")) || (($key == "country_code") && (!empty($value)))) && (!empty($array['country_code']))));
79                         if ((empty($value)) && ($chk == "Y") && (!$country))
80                         {
81                                 // Required field not set
82                                 $array[$key] = "!";
83                                 $ret = true;
84                         }
85                 }
86         }
87         return $ret;
88 }
89 //
90 function REGISTER_OUTPUT_REQUIRE_CHECK(&$array)
91 {
92         $result = SQL_QUERY("SELECT field_name, field_required FROM "._MYSQL_PREFIX."_must_register ORDER BY id", __FILE__, __LINE__);
93         while(list($name, $required) = SQL_FETCHROW($result))
94         {
95                 if (($array[$name] == "!") && ($required == "Y"))
96                 {
97                         // Empty entry found
98                         $array[$name] = "";
99                         $eval = "\$OUT = REGISTER_".strtoupper($name)."_REQUIRED;";
100                         eval($eval);
101                         OUTPUT_HTML("<STRONG><SPAN class=\"register_failed\">".$OUT."</SPAN></STRONG><br /><br />");
102                 }
103         }
104
105         // Free memory
106         SQL_FREERESULT($result);
107 }
108 //
109 function REGISTER_ADD_CATEGORY_TABLE ($MODE, $return=false)
110 {
111         global $_POST, $_CONFIG;
112         $OUT = "";
113
114         // Guests are mostly not interested in how many members has
115         // choosen an individual category
116         $AND = "WHERE visible='Y' ";
117         // Admins are allowed to see every category...
118         if (IS_ADMIN()) $AND = "";
119         $result = SQL_QUERY("SELECT id, cat, visible FROM "._MYSQL_PREFIX."_cats ".$AND." ORDER BY sort", __FILE__, __LINE__);
120         if (SQL_NUMROWS($result) > 0)
121         {
122                 // List alle visible modules (or all to the admin)
123                 $SW = 2;
124                 $OUT .= "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
125                 while (list($id, $cat, $visible) = SQL_FETCHROW($result))
126                 {
127                         if (empty($_POST['cat'][$id])) $_POST['cat'][$id] = "";
128                         // Prepare array for the template
129                         $content = array(
130                                 'sw'    => $SW,
131                                 'cat'   => $cat,
132                                 'def_y' => "",
133                                 'def_n' => "",
134                                 'id'    => $id,
135                         );
136
137                         if (($_POST['cat'][$id] == "Y") || (($_CONFIG['register_default'] == "Y") && (empty($_POST['cat'][$id]))))
138                         {
139                                 $content['def_y'] = ' checked';
140                         }
141                          else
142                         {
143                                 $content['def_n'] = ' checked';
144                         }
145
146                         // Load template and switch color
147                         $OUT .= LOAD_TEMPLATE("guest_cat_row", true, $content);
148                         $SW = 3 - $SW;
149                 }
150                 $OUT .= "</TABLE>\n";
151
152                 // Free memory
153                 SQL_FREERESULT($result);
154         }
155          else
156         {
157                 // No categories setted up so far...
158                 $OUT .= LOAD_TEMPLATE("admin_settings_saved", true, NO_CATEGORIES_VISIBLE);
159         }
160
161         if ($return)
162         {
163                 // Return generated HTML code
164                 return $OUT;
165         }
166          else
167         {
168                 // Output directly (default)
169                 OUTPUT_HTML($OUT);
170         }
171 }
172 //
173 ?>