ManageRegistration.php 11 KB

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