Mercurial > hg > vamp-website
comparison forum/Sources/ManageRegistration.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* This file helps the administrator setting registration settings and policy | |
18 as well as allow the administrator to register new members themselves. | |
19 | |
20 void RegCenter() | |
21 - entrance point for the registration center. | |
22 - accessed by ?action=admin;area=regcenter. | |
23 - requires either the moderate_forum or the admin_forum permission. | |
24 - loads the Login language file and the Register template. | |
25 - calls the right function based on the subaction. | |
26 | |
27 void AdminRegister() | |
28 - a function to register a new member from the admin center. | |
29 - accessed by ?action=admin;area=regcenter;sa=register | |
30 - requires the moderate_forum permission. | |
31 - uses the admin_register sub template of the Register template. | |
32 - allows assigning a primary group to the member being registered. | |
33 | |
34 void EditAgreement() | |
35 - allows the administrator to edit the registration agreement, and | |
36 choose whether it should be shown or not. | |
37 - accessed by ?action=admin;area=regcenter;sa=agreement. | |
38 - uses the Admin template and the edit_agreement sub template. | |
39 - requires the admin_forum permission. | |
40 - uses the edit_agreement administration area. | |
41 - writes and saves the agreement to the agreement.txt file. | |
42 | |
43 void SetReserve() | |
44 - set the names under which users are not allowed to register. | |
45 - accessed by ?action=admin;area=regcenter;sa=reservednames. | |
46 - requires the admin_forum permission. | |
47 - uses the reserved_words sub template of the Register template. | |
48 | |
49 void ModifyRegistrationSettings() | |
50 - set general registration settings and Coppa compliance settings. | |
51 - accessed by ?action=admin;area=regcenter;sa=settings. | |
52 - requires the admin_forum permission. | |
53 */ | |
54 | |
55 // Main handling function for the admin approval center | |
56 function RegCenter() | |
57 { | |
58 global $modSettings, $context, $txt, $scripturl; | |
59 | |
60 // Old templates might still request this. | |
61 if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'browse') | |
62 redirectexit('action=admin;area=viewmembers;sa=browse' . (isset($_REQUEST['type']) ? ';type=' . $_REQUEST['type'] : '')); | |
63 | |
64 $subActions = array( | |
65 'register' => array('AdminRegister', 'moderate_forum'), | |
66 'agreement' => array('EditAgreement', 'admin_forum'), | |
67 'reservednames' => array('SetReserve', 'admin_forum'), | |
68 'settings' => array('ModifyRegistrationSettings', 'admin_forum'), | |
69 ); | |
70 | |
71 // Work out which to call... | |
72 $context['sub_action'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) ? $_REQUEST['sa'] : (allowedTo('moderate_forum') ? 'register' : 'settings'); | |
73 | |
74 // Must have sufficient permissions. | |
75 isAllowedTo($subActions[$context['sub_action']][1]); | |
76 | |
77 // Loading, always loading. | |
78 loadLanguage('Login'); | |
79 loadTemplate('Register'); | |
80 | |
81 // Next create the tabs for the template. | |
82 $context[$context['admin_menu_name']]['tab_data'] = array( | |
83 'title' => $txt['registration_center'], | |
84 'help' => 'registrations', | |
85 'description' => $txt['admin_settings_desc'], | |
86 'tabs' => array( | |
87 'register' => array( | |
88 'description' => $txt['admin_register_desc'], | |
89 ), | |
90 'agreement' => array( | |
91 'description' => $txt['registration_agreement_desc'], | |
92 ), | |
93 'reservednames' => array( | |
94 'description' => $txt['admin_reserved_desc'], | |
95 ), | |
96 'settings' => array( | |
97 'description' => $txt['admin_settings_desc'], | |
98 ) | |
99 ) | |
100 ); | |
101 | |
102 // Finally, get around to calling the function... | |
103 $subActions[$context['sub_action']][0](); | |
104 } | |
105 | |
106 // This function allows the admin to register a new member by hand. | |
107 function AdminRegister() | |
108 { | |
109 global $txt, $context, $sourcedir, $scripturl, $smcFunc; | |
110 | |
111 if (!empty($_POST['regSubmit'])) | |
112 { | |
113 checkSession(); | |
114 | |
115 foreach ($_POST as $key => $value) | |
116 if (!is_array($_POST[$key])) | |
117 $_POST[$key] = htmltrim__recursive(str_replace(array("\n", "\r"), '', $_POST[$key])); | |
118 | |
119 $regOptions = array( | |
120 'interface' => 'admin', | |
121 'username' => $_POST['user'], | |
122 'email' => $_POST['email'], | |
123 'password' => $_POST['password'], | |
124 'password_check' => $_POST['password'], | |
125 'check_reserved_name' => true, | |
126 'check_password_strength' => false, | |
127 'check_email_ban' => false, | |
128 'send_welcome_email' => isset($_POST['emailPassword']) || empty($_POST['password']), | |
129 'require' => isset($_POST['emailActivate']) ? 'activation' : 'nothing', | |
130 'memberGroup' => empty($_POST['group']) || !allowedTo('manage_membergroups') ? 0 : (int) $_POST['group'], | |
131 ); | |
132 | |
133 require_once($sourcedir . '/Subs-Members.php'); | |
134 $memberID = registerMember($regOptions); | |
135 if (!empty($memberID)) | |
136 { | |
137 $context['new_member'] = array( | |
138 'id' => $memberID, | |
139 'name' => $_POST['user'], | |
140 'href' => $scripturl . '?action=profile;u=' . $memberID, | |
141 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $memberID . '">' . $_POST['user'] . '</a>', | |
142 ); | |
143 $context['registration_done'] = sprintf($txt['admin_register_done'], $context['new_member']['link']); | |
144 } | |
145 } | |
146 | |
147 // Basic stuff. | |
148 $context['sub_template'] = 'admin_register'; | |
149 $context['page_title'] = $txt['registration_center']; | |
150 | |
151 // Load the assignable member groups. | |
152 if (allowedTo('manage_membergroups')) | |
153 { | |
154 $request = $smcFunc['db_query']('', ' | |
155 SELECT group_name, id_group | |
156 FROM {db_prefix}membergroups | |
157 WHERE id_group != {int:moderator_group} | |
158 AND min_posts = {int:min_posts}' . (allowedTo('admin_forum') ? '' : ' | |
159 AND id_group != {int:admin_group} | |
160 AND group_type != {int:is_protected}') . ' | |
161 AND hidden != {int:hidden_group} | |
162 ORDER BY min_posts, CASE WHEN id_group < {int:newbie_group} THEN id_group ELSE 4 END, group_name', | |
163 array( | |
164 'moderator_group' => 3, | |
165 'min_posts' => -1, | |
166 'admin_group' => 1, | |
167 'is_protected' => 1, | |
168 'hidden_group' => 2, | |
169 'newbie_group' => 4, | |
170 ) | |
171 ); | |
172 $context['member_groups'] = array(0 => $txt['admin_register_group_none']); | |
173 while ($row = $smcFunc['db_fetch_assoc']($request)) | |
174 $context['member_groups'][$row['id_group']] = $row['group_name']; | |
175 $smcFunc['db_free_result']($request); | |
176 } | |
177 else | |
178 $context['member_groups'] = array(); | |
179 } | |
180 | |
181 // I hereby agree not to be a lazy bum. | |
182 function EditAgreement() | |
183 { | |
184 global $txt, $boarddir, $context, $modSettings, $smcFunc, $settings; | |
185 | |
186 // By default we look at agreement.txt. | |
187 $context['current_agreement'] = ''; | |
188 | |
189 // Is there more than one to edit? | |
190 $context['editable_agreements'] = array( | |
191 '' => $txt['admin_agreement_default'], | |
192 ); | |
193 | |
194 // Get our languages. | |
195 getLanguages(); | |
196 | |
197 // Try to figure out if we have more agreements. | |
198 foreach ($context['languages'] as $lang) | |
199 { | |
200 if (file_exists($boarddir . '/agreement.' . $lang['filename'] . '.txt')) | |
201 { | |
202 $context['editable_agreements']['.' . $lang['filename']] = $lang['name']; | |
203 // Are we editing this? | |
204 if (isset($_POST['agree_lang']) && $_POST['agree_lang'] == '.' . $lang['filename']) | |
205 $context['current_agreement'] = '.' . $lang['filename']; | |
206 } | |
207 } | |
208 | |
209 if (isset($_POST['agreement'])) | |
210 { | |
211 checkSession(); | |
212 | |
213 // Off it goes to the agreement file. | |
214 $fp = fopen($boarddir . '/agreement' . $context['current_agreement'] . '.txt', 'w'); | |
215 fwrite($fp, str_replace("\r", '', $_POST['agreement'])); | |
216 fclose($fp); | |
217 | |
218 updateSettings(array('requireAgreement' => !empty($_POST['requireAgreement']))); | |
219 } | |
220 | |
221 $context['agreement'] = file_exists($boarddir . '/agreement' . $context['current_agreement'] . '.txt') ? htmlspecialchars(file_get_contents($boarddir . '/agreement' . $context['current_agreement'] . '.txt')) : ''; | |
222 $context['warning'] = is_writable($boarddir . '/agreement' . $context['current_agreement'] . '.txt') ? '' : $txt['agreement_not_writable']; | |
223 $context['require_agreement'] = !empty($modSettings['requireAgreement']); | |
224 | |
225 $context['sub_template'] = 'edit_agreement'; | |
226 $context['page_title'] = $txt['registration_agreement']; | |
227 } | |
228 | |
229 // Set reserved names/words.... | |
230 function SetReserve() | |
231 { | |
232 global $txt, $context, $modSettings; | |
233 | |
234 // Submitting new reserved words. | |
235 if (!empty($_POST['save_reserved_names'])) | |
236 { | |
237 checkSession(); | |
238 | |
239 // Set all the options.... | |
240 updateSettings(array( | |
241 'reserveWord' => (isset($_POST['matchword']) ? '1' : '0'), | |
242 'reserveCase' => (isset($_POST['matchcase']) ? '1' : '0'), | |
243 'reserveUser' => (isset($_POST['matchuser']) ? '1' : '0'), | |
244 'reserveName' => (isset($_POST['matchname']) ? '1' : '0'), | |
245 'reserveNames' => str_replace("\r", '', $_POST['reserved']) | |
246 )); | |
247 } | |
248 | |
249 // Get the reserved word options and words. | |
250 $modSettings['reserveNames'] = str_replace('\n', "\n", $modSettings['reserveNames']); | |
251 $context['reserved_words'] = explode("\n", $modSettings['reserveNames']); | |
252 $context['reserved_word_options'] = array(); | |
253 $context['reserved_word_options']['match_word'] = $modSettings['reserveWord'] == '1'; | |
254 $context['reserved_word_options']['match_case'] = $modSettings['reserveCase'] == '1'; | |
255 $context['reserved_word_options']['match_user'] = $modSettings['reserveUser'] == '1'; | |
256 $context['reserved_word_options']['match_name'] = $modSettings['reserveName'] == '1'; | |
257 | |
258 // Ready the template...... | |
259 $context['sub_template'] = 'edit_reserved_words'; | |
260 $context['page_title'] = $txt['admin_reserved_set']; | |
261 } | |
262 | |
263 // This function handles registration settings, and provides a few pretty stats too while it's at it. | |
264 function ModifyRegistrationSettings($return_config = false) | |
265 { | |
266 global $txt, $context, $scripturl, $modSettings, $sourcedir; | |
267 | |
268 // This is really quite wanting. | |
269 require_once($sourcedir . '/ManageServer.php'); | |
270 | |
271 $config_vars = array( | |
272 array('select', 'registration_method', array($txt['setting_registration_standard'], $txt['setting_registration_activate'], $txt['setting_registration_approval'], $txt['setting_registration_disabled'])), | |
273 array('check', 'enableOpenID'), | |
274 array('check', 'notify_new_registration'), | |
275 array('check', 'send_welcomeEmail'), | |
276 '', | |
277 array('int', 'coppaAge', 'subtext' => $txt['setting_coppaAge_desc'], 'onchange' => 'checkCoppa();'), | |
278 array('select', 'coppaType', array($txt['setting_coppaType_reject'], $txt['setting_coppaType_approval']), 'onchange' => 'checkCoppa();'), | |
279 array('large_text', 'coppaPost', 'subtext' => $txt['setting_coppaPost_desc']), | |
280 array('text', 'coppaFax'), | |
281 array('text', 'coppaPhone'), | |
282 ); | |
283 | |
284 if ($return_config) | |
285 return $config_vars; | |
286 | |
287 // Setup the template | |
288 $context['sub_template'] = 'show_settings'; | |
289 $context['page_title'] = $txt['registration_center']; | |
290 | |
291 if (isset($_GET['save'])) | |
292 { | |
293 checkSession(); | |
294 | |
295 // Are there some contacts missing? | |
296 if (!empty($_POST['coppaAge']) && !empty($_POST['coppaType']) && empty($_POST['coppaPost']) && empty($_POST['coppaFax'])) | |
297 fatal_lang_error('admin_setting_coppa_require_contact'); | |
298 | |
299 // Post needs to take into account line breaks. | |
300 $_POST['coppaPost'] = str_replace("\n", '<br />', empty($_POST['coppaPost']) ? '' : $_POST['coppaPost']); | |
301 | |
302 saveDBSettings($config_vars); | |
303 | |
304 redirectexit('action=admin;area=regcenter;sa=settings'); | |
305 } | |
306 | |
307 $context['post_url'] = $scripturl . '?action=admin;area=regcenter;save;sa=settings'; | |
308 $context['settings_title'] = $txt['settings']; | |
309 | |
310 // Define some javascript for COPPA. | |
311 $context['settings_post_javascript'] = ' | |
312 function checkCoppa() | |
313 { | |
314 var coppaDisabled = document.getElementById(\'coppaAge\').value == 0; | |
315 document.getElementById(\'coppaType\').disabled = coppaDisabled; | |
316 | |
317 var disableContacts = coppaDisabled || document.getElementById(\'coppaType\').options[document.getElementById(\'coppaType\').selectedIndex].value != 1; | |
318 document.getElementById(\'coppaPost\').disabled = disableContacts; | |
319 document.getElementById(\'coppaFax\').disabled = disableContacts; | |
320 document.getElementById(\'coppaPhone\').disabled = disableContacts; | |
321 } | |
322 checkCoppa();'; | |
323 | |
324 // Turn the postal address into something suitable for a textbox. | |
325 $modSettings['coppaPost'] = !empty($modSettings['coppaPost']) ? preg_replace('~<br ?/?' . '>~', "\n", $modSettings['coppaPost']) : ''; | |
326 | |
327 prepareDBSettingContext($config_vars); | |
328 } | |
329 | |
330 ?> |