Deleting of network type handler partialy finished
[mailer.git] / inc / libs / register_functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 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         die();
42 }
43
44 //
45 function ifRequiredRegisterFieldsAreSet (&$array) {
46         // By default all is fine
47         $ret = true;
48         foreach ($array as $key => $value) {
49                 // Check all fields that must register
50                 $result = SQL_QUERY("SELECT `id` FROM `{?_MYSQL_PREFIX?}_must_register` WHERE `field_name`='".$key."' AND `field_required`='Y' LIMIT 1",
51                         __FUNCTION__, __LINE__);
52                 if (SQL_NUMROWS($result) == 1) {
53                         // Check if extension country is not found (you have to enter the 2-chars long country code) or
54                         // if extensions is present check if country code was selected
55                         //         01              2         21    12             3         32    234     5      54    4               43    34                      4    4      5      5432    2      3                      3210
56                         $country = ((!isExtensionActive('country')) || ((isExtensionActive('country')) && (((empty($value)) && ($key == 'cntry')) || (($key == 'country_code') && (!empty($value)))) && (!empty($array['country_code']))));
57                         if ((empty($value)) && ($country === false)) {
58                                 // Required field not set
59                                 $array[$key] = '!';
60                                 $ret = false;
61                         } // END - if
62                 } // END - if
63
64                 // Free result
65                 SQL_FREERESULT($result);
66         } // END - foreach
67
68         // Return result
69         return $ret;
70 }
71
72 // Generates a 'category table' for the registration form
73 function registerGenerateCategoryTable ($mode, $return=false) {
74         $OUT = '';
75
76         // Guests are mostly not interested in how many members has
77         // choosen an individual category
78         $AND = "WHERE `visible`='Y' ";
79
80         // Admins are allowed to see every category...
81         if (isAdmin()) $AND = '';
82
83         // Look for categories
84         $result = SQL_QUERY("SELECT `id`, `cat`, `visible` FROM `{?_MYSQL_PREFIX?}_cats` ".$AND." ORDER BY `sort` ASC",
85                 __FUNCTION__, __LINE__);
86
87         if (SQL_NUMROWS($result) > 0) {
88                 // List alle visible modules (or all to the admin)
89                 $SW = 2;
90                 $OUT .= "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n";
91                 while ($content = SQL_FETCHARRAY($result)) {
92                         // Prepare array for the template
93                         $content = array(
94                                 'sw'    => $SW,
95                                 'cat'   => $content['cat'],
96                                 'def_y' => '',
97                                 'def_n' => '',
98                                 'id'    => $content['id'],
99                         );
100
101                         // Mark categories
102                         if ((postRequestElement('cat', $content['id']) == 'Y') || ((getConfig('register_default') == 'Y') && (!isPostRequestElementSet('cat', $content['id'])))) {
103                                 $content['def_y'] = ' checked="checked"';
104                         } else {
105                                 $content['def_n'] = ' checked="checked"';
106                         }
107
108                         // Load template and switch color
109                         $OUT .= loadTemplate('guest_cat_row', true, $content);
110                         $SW = 3 - $SW;
111                 }
112                 $OUT .= "</table>\n";
113
114                 // Free memory
115                 SQL_FREERESULT($result);
116         } else {
117                 // No categories setted up so far...
118                 $OUT .= loadTemplate('admin_settings_saved', true, getMessage('NO_CATEGORIES_VISIBLE'));
119         }
120
121         if ($return === true) {
122                 // Return generated HTML code
123                 return $OUT;
124         } else {
125                 // Output directly (default)
126                 outputHtml($OUT);
127         }
128 }
129
130 // Outputs a 'failed message'
131 function registerOutputFailedMessage ($messageId, $extra='') {
132         if (empty($messageId)) {
133                 outputHtml('<div class="register_failed">' . $extra . '</div>');
134         } else {
135                 outputHtml('<div class="register_failed">{--' . $messageId . '--}' . $extra . '</div>');
136         }
137 }
138
139 // Run a filter for must-fillout fields
140 function FILTER_REGISTER_MUST_FILLOUT ($content) {
141         // Get all fields for output
142         $result = SQL_QUERY("SELECT `field_name`, `field_required` FROM `{?_MYSQL_PREFIX?}_must_register` ORDER BY `id` ASC",
143                 __FUNCTION__, __LINE__);
144
145         // Walk through all entries
146         while ($row = SQL_FETCHARRAY($result)) {
147                 // Must the user fill out this element?
148                 $value = '';
149                 if ($row['field_required'] == 'Y') $value = "<span class=\\\"guest_failed\\\">&nbsp;(*)</span>";
150
151                 // Add it
152                 $content['must_fillout_'.strtolower($row['field_name']).''] = $value;
153         } // END - while
154
155         // Free memory
156         SQL_FREERESULT($result);
157
158         // Return it
159         return $content;
160 }
161
162 //
163 ?>