ManageRegistration.php 12 KB

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