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