/**
  * Processes the registration form
  *
  * @access	public
  * @return	void
  */
 public function registerProcessForm()
 {
     $form_errors = array();
     $coppa = $this->request['coppa_user'] == 1 ? 1 : 0;
     $in_password = trim($this->request['PassWord']);
     $in_email = strtolower(trim($this->request['EmailAddress']));
     $_SFS_FOUND = FALSE;
     /* Check */
     if ($this->settings['no_reg'] == 1) {
         $this->registry->output->showError('registration_disabled', 2016, true);
     }
     /* Custom profile field stuff */
     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
     $custom_fields = new customProfileFields();
     $custom_fields->initData('edit');
     $custom_fields->parseToSave($this->request, 'register');
     /* Check */
     if ($custom_fields->error_messages) {
         $form_errors['general'] = $custom_fields->error_messages;
     }
     /* Check the email address */
     if (!$in_email or strlen($in_email) < 6 or !IPSText::checkEmailAddress($in_email)) {
         $form_errors['email'][$this->lang->words['err_invalid_email']] = $this->lang->words['err_invalid_email'];
     }
     if (trim($this->request['PassWord_Check']) != $in_password) {
         $form_errors['password'][$this->lang->words['passwords_not_match']] = $this->lang->words['passwords_not_match'];
     }
     /* Test email address */
     $this->request['EmailAddress_two'] = strtolower(trim($this->request['EmailAddress_two']));
     $this->request['EmailAddress'] = strtolower(trim($this->request['EmailAddress']));
     if (!IPSText::checkEmailAddress($this->request['EmailAddress_two'])) {
         $form_errors['email'][$this->lang->words['reg_error_email_invalid']] = $this->lang->words['reg_error_email_invalid'];
     } else {
         if ($in_email and $this->request['EmailAddress_two'] != $in_email) {
             $form_errors['email'][$this->lang->words['reg_error_email_nm']] = $this->lang->words['reg_error_email_nm'];
         }
     }
     /* Need username? */
     $uses_name = false;
     foreach ($this->cache->getCache('login_methods') as $method) {
         if ($method['login_user_id'] == 'username') {
             $uses_name = true;
         }
     }
     if (!$uses_name) {
         $_REQUEST['UserName'] = $_REQUEST['members_display_name'];
         $this->request['UserName'] = $this->request['members_display_name'];
     }
     /* Check the username */
     $user_check = IPSMember::getFunction()->cleanAndCheckName($this->request['UserName'], array(), 'name');
     if ($this->settings['auth_allow_dnames']) {
         $disp_check = IPSMember::getFunction()->cleanAndCheckName($this->request['members_display_name'], array(), 'members_display_name');
     }
     if (is_array($user_check['errors']) && count($user_check['errors'])) {
         foreach ($user_check['errors'] as $key => $error) {
             $form_errors[$key][] = $error;
         }
     }
     if ($this->settings['auth_allow_dnames'] and is_array($disp_check['errors']) && count($disp_check['errors'])) {
         foreach ($disp_check['errors'] as $key => $error) {
             $form_errors[$key][] = $error;
         }
     }
     /* CHECK 1: Any errors (missing fields, etc)? */
     if (count($form_errors)) {
         $this->registerForm($form_errors);
         return;
     }
     /* Is this email addy taken? */
     if (IPSMember::checkByEmail($in_email) == TRUE) {
         $form_errors['email'][$this->lang->words['reg_error_email_taken']] = $this->lang->words['reg_error_email_taken'];
     }
     /* Load handler... */
     require_once IPS_ROOT_PATH . 'sources/handlers/han_login.php';
     $this->han_login = new han_login($this->registry);
     $this->han_login->init();
     $this->han_login->emailExistsCheck($in_email);
     if ($this->han_login->return_code and $this->han_login->return_code != 'METHOD_NOT_DEFINED' and $this->han_login->return_code != 'EMAIL_NOT_IN_USE') {
         $form_errors['email'][$this->lang->words['reg_error_email_taken']] = $this->lang->words['reg_error_email_taken'];
     }
     /* Are they banned [EMAIL]? */
     if (IPSMember::isBanned('email', $in_email) === TRUE) {
         $form_errors['email'][$this->lang->words['reg_error_email_ban']] = $this->lang->words['reg_error_email_ban'];
     }
     /* Check the CAPTCHA */
     if ($this->settings['bot_antispam']) {
         if ($this->registry->getClass('class_captcha')->validate() !== TRUE) {
             $form_errors['general'][$this->lang->words['err_reg_code']] = $this->lang->words['err_reg_code'];
         }
     }
     /* Check the Q and A */
     if ($this->settings['registration_qanda']) {
         $qanda = intval($this->request['qanda_id']);
         $pass = false;
         if ($qanda) {
             $data = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'question_and_answer', 'where' => 'qa_id=' . $qanda));
             if ($data['qa_id']) {
                 $answers = explode("\n", str_replace("\r", "", $data['qa_answers']));
                 if (count($answers)) {
                     foreach ($answers as $answer) {
                         if (strtolower($answer) == strtolower($this->request['qa_answer'])) {
                             $pass = true;
                             break;
                         }
                     }
                 }
             }
         } else {
             //-----------------------------------------
             // Do we have any questions?
             //-----------------------------------------
             $data = $this->DB->buildAndFetch(array('select' => 'COUNT(*) as questions', 'from' => 'question_and_answer'));
             if (!$data['questions']) {
                 $pass = true;
             }
         }
         if (!$pass) {
             $form_errors['general'][$this->lang->words['err_q_and_a']] = $this->lang->words['err_q_and_a'];
         }
     }
     /* CHECK 2: Any errors ? */
     if (count($form_errors)) {
         $this->registerForm($form_errors);
         return;
     }
     /* Build up the hashes */
     $mem_group = $this->settings['member_group'];
     /* Are we asking the member or admin to preview? */
     if ($this->settings['reg_auth_type']) {
         $mem_group = $this->settings['auth_group'];
     } else {
         if ($coppa == 1) {
             $mem_group = $this->settings['auth_group'];
         }
     }
     /* Create member */
     $member = array('name' => $this->request['UserName'], 'password' => $in_password, 'members_display_name' => $this->settings['auth_allow_dnames'] ? $this->request['members_display_name'] : $this->request['UserName'], 'email' => $in_email, 'member_group_id' => $mem_group, 'joined' => time(), 'ip_address' => $this->member->ip_address, 'time_offset' => $this->request['time_offset'], 'coppa_user' => $coppa, 'members_auto_dst' => intval($this->request['dst']), 'allow_admin_mails' => intval($this->request['allow_admin_mail']), 'hide_email' => $this->request['allow_member_mail'] ? 0 : 1);
     /* Spam Service */
     $spamCode = 0;
     if ($this->settings['spam_service_enabled'] && $this->settings['spam_service_api_key']) {
         /* Query the service */
         $spamCode = IPSMember::querySpamService($in_email);
         /* Action to perform */
         $action = $this->settings['spam_service_action_' . $spamCode];
         /* Perform Action */
         switch ($action) {
             /* Proceed with registraction */
             case 1:
                 break;
                 /* Flag for admin approval */
             /* Flag for admin approval */
             case 2:
                 $member['member_group_id'] = $this->settings['auth_group'];
                 $this->settings['reg_auth_type'] = 'admin';
                 break;
                 /* Approve the account, but ban it */
             /* Approve the account, but ban it */
             case 3:
                 $member['member_banned'] = 1;
                 $member['member_group_id'] = $this->settings['banned_group'];
                 $this->settings['reg_auth_type'] = '';
                 break;
         }
     }
     //-----------------------------------------
     // Create the account
     //-----------------------------------------
     $member = IPSMember::create(array('members' => $member, 'pfields_content' => $this->request));
     //-----------------------------------------
     // Login handler create account callback
     //-----------------------------------------
     $this->han_login->createAccount(array('email' => $member['email'], 'joined' => $member['joined'], 'password' => $in_password, 'ip_address' => $this->member->ip_address, 'username' => $member['members_display_name']));
     //-----------------------------------------
     // We'll just ignore if this fails - it shouldn't hold up IPB anyways
     //-----------------------------------------
     /*if ( $han_login->return_code AND ( $han_login->return_code != 'METHOD_NOT_DEFINED' AND $han_login->return_code != 'SUCCESS' ) )
     		{
     			$this->registry->output->showError( 'han_login_create_failed', 2017, true );
     		}*/
     //-----------------------------------------
     // Validation
     //-----------------------------------------
     $validate_key = md5(IPSLib::makePassword() . time());
     $time = time();
     if ($coppa != 1) {
         if ($this->settings['reg_auth_type'] == 'user' or $this->settings['reg_auth_type'] == 'admin' or $this->settings['reg_auth_type'] == 'admin_user') {
             //-----------------------------------------
             // We want to validate all reg's via email,
             // after email verificiation has taken place,
             // we restore their previous group and remove the validate_key
             //-----------------------------------------
             $this->DB->insert('validating', array('vid' => $validate_key, 'member_id' => $member['member_id'], 'real_group' => $this->settings['member_group'], 'temp_group' => $this->settings['auth_group'], 'entry_date' => $time, 'coppa_user' => $coppa, 'new_reg' => 1, 'ip_address' => $member['ip_address']));
             if ($this->settings['reg_auth_type'] == 'user' or $this->settings['reg_auth_type'] == 'admin_user') {
                 IPSText::getTextClass('email')->getTemplate("reg_validate");
                 IPSText::getTextClass('email')->buildMessage(array('THE_LINK' => $this->settings['base_url'] . "app=core&module=global&section=register&do=auto_validate&uid=" . urlencode($member['member_id']) . "&aid=" . urlencode($validate_key), 'NAME' => $member['members_display_name'], 'MAN_LINK' => $this->settings['base_url'] . "app=core&module=global&section=register&do=05", 'EMAIL' => $member['email'], 'ID' => $member['member_id'], 'CODE' => $validate_key));
                 IPSText::getTextClass('email')->subject = $this->lang->words['new_registration_email'] . $this->settings['board_name'];
                 IPSText::getTextClass('email')->to = $member['email'];
                 IPSText::getTextClass('email')->sendMail();
                 $this->output = $this->registry->output->getTemplate('register')->showAuthorize($member);
             } else {
                 if ($this->settings['reg_auth_type'] == 'admin') {
                     $this->output = $this->registry->output->getTemplate('register')->showPreview($member);
                 }
             }
             if ($this->settings['new_reg_notify']) {
                 $date = $this->registry->class_localization->getDate(time(), 'LONG', 1);
                 IPSText::getTextClass('email')->getTemplate('admin_newuser');
                 IPSText::getTextClass('email')->buildMessage(array('DATE' => $date, 'MEMBER_NAME' => $member['members_display_name']));
                 IPSText::getTextClass('email')->subject = $this->lang->words['new_registration_email1'] . $this->settings['board_name'];
                 IPSText::getTextClass('email')->to = $this->settings['email_in'];
                 IPSText::getTextClass('email')->sendMail();
             }
             $this->registry->output->setTitle($this->lang->words['reg_success']);
             $this->registry->output->addNavigation($this->lang->words['nav_reg'], '');
         } else {
             /* We don't want to preview, or get them to validate via email. */
             $stat_cache = $this->caches['stats'];
             if ($member['members_display_name'] and $member['member_id']) {
                 $stat_cache['last_mem_name'] = $member['members_display_name'];
                 $stat_cache['last_mem_id'] = $member['member_id'];
             }
             $stat_cache['mem_count'] += 1;
             $this->cache->setCache('stats', $stat_cache, array('array' => 1, 'deletefirst' => 0));
             if ($this->settings['new_reg_notify']) {
                 $date = $this->registry->class_localization->getDate(time(), 'LONG', 1);
                 IPSText::getTextClass('email')->getTemplate('admin_newuser');
                 IPSText::getTextClass('email')->buildMessage(array('DATE' => $date, 'MEMBER_NAME' => $member['members_display_name']));
                 IPSText::getTextClass('email')->subject = $this->lang->words['new_registration_email1'] . $this->settings['board_name'];
                 IPSText::getTextClass('email')->to = $this->settings['email_in'];
                 IPSText::getTextClass('email')->sendMail();
             }
             IPSCookie::set('pass_hash', $member['member_login_key'], 1);
             IPSCookie::set('member_id', $member['member_id'], 1);
             //-----------------------------------------
             // Fix up session
             //-----------------------------------------
             $privacy = $this->request['Privacy'] ? 1 : 0;
             if ($member['g_hide_online_list']) {
                 $privacy = 1;
             }
             $this->member->sessionClass()->convertGuestToMember(array('member_name' => $member['members_display_name'], 'member_id' => $member['member_id'], 'member_group' => $member['member_group_id'], 'login_type' => $privacy));
             $this->registry->output->silentRedirect($this->settings['base_url'] . '&app=core&module=global&section=login&do=autologin&fromreg=1');
         }
     } else {
         /* This is a COPPA user, so lets tell them they registered OK and redirect to the form. */
         $this->DB->insert('validating', array('vid' => $validate_key, 'member_id' => $member['member_id'], 'real_group' => $this->settings['member_group'], 'temp_group' => $this->settings['auth_group'], 'entry_date' => $time, 'coppa_user' => $coppa, 'new_reg' => 1, 'ip_address' => $member['ip_address']));
         $this->registry->output->redirectScreen($this->lang->words['cp_success'], $this->settings['base_url'] . 'app=core&amp;module=global&amp;section=register&amp;do=12');
     }
 }
 /**
  * Generate context-menu filter boxes
  * Pass &_nosave=1 to not store / read from a cookie
  *
  * @access	private
  * @author	Matt Mecham
  * @since	IPB 3.0.0
  * @return	void		[Outputs to screen]
  * @todo 	[Future] Allow multiple filter fields
  */
 private function _generateFilterBoxes()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $form = array();
     $custom_fields = array();
     # Filter: Customer contains
     $member_contains = $this->request['f_member_contains'] ? trim($this->request['f_member_contains']) : '';
     $member_contains_type = $this->request['f_member_contains_type'] ? trim($this->request['f_member_contains_type']) : '';
     $member_contains_text = $this->request['f_member_contains_text'] ? trim($this->request['f_member_contains_text']) : '';
     $_member_contains = array(0 => array('members_display_name', $this->lang->words['m_f_display']), 1 => array('name', $this->lang->words['m_f_login']), 2 => array('member_id', $this->lang->words['m_f_id']), 3 => array('email', $this->lang->words['m_f_email']), 4 => array('ip_address', $this->lang->words['m_f_ip']), 5 => array('signature', $this->lang->words['m_f_sig']));
     $_member_contains_type = array(0 => array('contains', $this->lang->words['m_f_contains']), 1 => array('equals', $this->lang->words['m_f_equals']), 2 => array('begins', $this->lang->words['m_f_begins']), 3 => array('ends', $this->lang->words['m_f_ends']));
     # Order by
     $order_by = '';
     $order_by = $this->request['order_by'] ? $this->request['order_by'] : 'members_l_display_name';
     $_order_by = array(0 => array('joined', $this->lang->words['m_f_joined']), 1 => array('members_l_username', $this->lang->words['m_f_slogin']), 2 => array('members_l_display_name', $this->lang->words['m_f_sdisplay']), 3 => array('email', $this->lang->words['m_f_email']));
     # Order direction
     $order_direction = $this->request['order_direction'] ? $this->request['order_direction'] : 'ASC';
     $_order_direction = array(0 => array('asc', $this->lang->words['m_f_orderaz']), 1 => array('desc', $this->lang->words['m_f_orderza']));
     # Filter: member type
     $member_type = $this->request['f_member_type'] ? trim($this->request['f_member_type']) : '';
     $_member_type = array(0 => array('all', $this->lang->words['m_f_showall']), 1 => array('suspended', $this->lang->words['m_f_showsusp']), 2 => array('notsuspended', $this->lang->words['m_f_showunsusp']));
     # Filter: banned type
     $banned_type = $this->request['f_banned_type'] ? trim($this->request['f_banned_type']) : '';
     $_banned_type = array(0 => array('all', $this->lang->words['m_f_showall']), 1 => array('banned', $this->lang->words['m_f_showbanned']), 2 => array('notbanned', $this->lang->words['m_f_shownotbanned']));
     # Filter: SPAM status type
     $spam_type = $this->request['f_spam_type'] ? trim($this->request['f_spam_type']) : '';
     $_spam_type = array(0 => array('all', $this->lang->words['m_f_showall']), 1 => array('spam', $this->lang->words['m_f_showspam']), 2 => array('notspam', $this->lang->words['m_f_shownotspam']));
     # Type of search
     $search_type = $this->request['f_search_type'] ? $this->request['f_search_type'] : 'normal';
     $_search_type = array(0 => array('normal', $this->lang->words['m_f_toedit']));
     if ($this->registry->getClass('class_permissions')->checkPermission('member_delete')) {
         $_search_type[1] = array('delete', $this->lang->words['m_f_todelete']);
     }
     if ($this->registry->getClass('class_permissions')->checkPermission('member_move')) {
         $_search_type[2] = array('move', $this->lang->words['m_f_tomove']);
     }
     # Date Ranges
     $date_reg_from = $this->request['f_date_reg_from'] ? trim($this->request['f_date_reg_from']) : '';
     $date_reg_to = $this->request['f_date_reg_to'] ? trim($this->request['f_date_reg_to']) : '';
     $date_post_from = $this->request['f_date_post_from'] ? trim($this->request['f_date_post_from']) : '';
     $date_post_to = $this->request['f_date_post_to'] ? trim($this->request['f_date_post_to']) : '';
     $date_active_from = $this->request['f_date_active_from'] ? trim($this->request['f_date_active_from']) : '';
     $date_active_to = $this->request['f_date_active_to'] ? trim($this->request['f_date_active_to']) : '';
     $primary_group = $this->request['f_primary_group'] ? trim($this->request['f_primary_group']) : 0;
     $secondary_group = $this->request['f_secondary_group'] ? trim($this->request['f_secondary_group']) : 0;
     $_primary_group = array(0 => array('0', $this->lang->words['m_f_primany']));
     $_secondary_group = array(0 => array('0', $this->lang->words['m_f_secany']));
     $post_count = $this->request['f_post_count'] ? trim($this->request['f_post_count']) : '';
     $post_count_type = $this->request['f_post_count_type'] ? trim($this->request['f_post_count_type']) : '';
     $_post_count_types = array(0 => array('lt', $this->lang->words['pc_lt']), 1 => array('gt', $this->lang->words['pc_gt']), 3 => array('eq', $this->lang->words['pc_eq']));
     foreach (ipsRegistry::cache()->getCache('group_cache') as $_gid => $_gdata) {
         $_primary_group[] = array($_gdata['g_id'], $_gdata['g_title']);
         $_secondary_group[] = array($_gdata['g_id'], $_gdata['g_title']);
     }
     /* Reset Fitlers */
     if ($this->request['reset_filters']) {
         ipsRegistry::getClass('adminFunctions')->staffSaveCookie('memberFilter', array());
     }
     //-----------------------------------------
     // Not posted, so er.. get the cookie
     //-----------------------------------------
     $custom_field_data = array();
     $filters_preset = 0;
     if (!$this->request['__update'] and !$this->request['_nosave']) {
         $_cookie_array = ipsRegistry::getClass('adminFunctions')->staffGetCookie('memberFilter');
         if ($_cookie_array) {
             if (is_array($_cookie_array) and count($_cookie_array)) {
                 $member_type = substr($_cookie_array['c_member_type'], 0, 10);
                 $banned_type = substr($_cookie_array['c_banned_type'], 0, 10);
                 $spam_type = substr($_cookie_array['c_spam_type'], 0, 10);
                 $member_contains = substr($_cookie_array['c_member_contains'], 0, 20);
                 $member_contains_type = substr($_cookie_array['c_member_contains_type'], 0, 20);
                 $member_contains_text = substr($_cookie_array['c_member_contains_text'], 0, 50);
                 $post_count = trim(IPSText::alphanumericalClean($_cookie_array['c_post_count']));
                 $post_count_type = trim(IPSText::alphanumericalClean($_cookie_array['c_post_count_type']));
                 $order_by = trim(IPSText::alphanumericalClean($_cookie_array['c_order_by']));
                 $order_direction = trim(IPSText::alphanumericalClean($_cookie_array['c_order_direction']));
                 $date_reg_from = trim(IPSText::alphanumericalClean($_cookie_array['c_date_reg_from'], '/-'));
                 $date_reg_to = trim(IPSText::alphanumericalClean($_cookie_array['c_date_reg_to'], '/-'));
                 $date_post_from = trim(IPSText::alphanumericalClean($_cookie_array['c_date_post_from'], '/-'));
                 $date_post_to = trim(IPSText::alphanumericalClean($_cookie_array['c_date_post_to'], '/-'));
                 $date_active_from = trim(IPSText::alphanumericalClean($_cookie_array['c_date_active_from'], '/-'));
                 $date_active_to = trim(IPSText::alphanumericalClean($_cookie_array['c_date_active_to'], '/-'));
                 $primary_group = trim(IPSText::alphanumericalClean($_cookie_array['c_primary_group'], '/-'));
                 $secondary_group = trim(IPSText::alphanumericalClean($_cookie_array['c_secondary_group'], '/-'));
                 $custom_field_cookie = explode('||', $_cookie_array['c_custom_fields']);
                 if ($member_type || $member_contains || $member_contains_type || $member_contains_text || $order_by || $order_direction || $date_reg_from || $date_reg_to || $date_post_from || $date_post_to || $date_active_from || $date_active_to || $primary_group || $secondary_group || $post_count || $post_count_type) {
                     $filters_preset = 1;
                 }
                 if (is_array($custom_field_cookie) and count($custom_field_cookie)) {
                     foreach ($custom_field_cookie as $field) {
                         $data = explode('==', $field);
                         $custom_field_data['field_' . $data[0]] = $data[1];
                         ipsRegistry::$request['field_' . $data[0]] = $data[1];
                         if ($data[1]) {
                             $filters_preset = 1;
                         }
                     }
                 }
             }
         }
     }
     $custom_field_data = count($custom_field_data) ? $custom_field_data : $_POST;
     foreach ($custom_field_data as $k => $v) {
         if (strpos($k, 'ignore_field_') === 0) {
             $key = substr($k, 13);
             $custom_field_data['field_' . $key] = '';
         }
     }
     //-----------------------------------------
     // Get custom profile information
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
     $fields = new customProfileFields();
     $fields->member_data = $custom_field_data;
     $fields->initData('edit', 1);
     $fields->parseToEdit();
     //-----------------------------------------
     // Finish forms...
     //-----------------------------------------
     $form['_member_contains'] = $this->registry->output->formDropdown('f_member_contains', $_member_contains, $member_contains);
     $form['_member_contains_type'] = $this->registry->output->formDropdown('f_member_contains_type', $_member_contains_type, $member_contains_type);
     $form['_member_contains_text'] = $this->registry->output->formSimpleInput('f_member_contains_text', $member_contains_text, 15);
     $form['_member_type'] = $this->registry->output->formDropdown('f_member_type', $_member_type, $member_type);
     $form['_banned_type'] = $this->registry->output->formDropdown('f_banned_type', $_banned_type, $banned_type);
     $form['_spam_type'] = $this->registry->output->formDropdown('f_spam_type', $_spam_type, $spam_type);
     $form['_order_by'] = $this->registry->output->formDropdown('order_by', $_order_by, preg_replace("#.*\\.(.*)\$#", "\\1", $order_by));
     $form['_order_direction'] = $this->registry->output->formDropdown('order_direction', $_order_direction, $order_direction);
     $form['_search_type'] = $this->registry->output->formDropdown('f_search_type', $_search_type, $search_type);
     $form['_post_count'] = $this->registry->output->formSimpleInput('f_post_count', $post_count, 10);
     $form['_post_count_type'] = $this->registry->output->formDropdown('f_post_count_type', $_post_count_types, $post_count_type);
     $form['_date_reg_from'] = $this->registry->output->formSimpleInput('f_date_reg_from', $date_reg_from, 10);
     $form['_date_reg_to'] = $this->registry->output->formSimpleInput('f_date_reg_to', $date_reg_to, 10);
     $form['_date_post_from'] = $this->registry->output->formSimpleInput('f_date_post_from', $date_post_from, 10);
     $form['_date_post_to'] = $this->registry->output->formSimpleInput('f_date_post_to', $date_post_to, 10);
     $form['_date_active_from'] = $this->registry->output->formSimpleInput('f_date_active_from', $date_active_from, 10);
     $form['_date_active_to'] = $this->registry->output->formSimpleInput('f_date_active_to', $date_active_to, 10);
     $form['_primary_group'] = $this->registry->output->formDropdown('f_primary_group', $_primary_group, $primary_group);
     $form['_secondary_group'] = $this->registry->output->formDropdown('f_secondary_group', $_secondary_group, $secondary_group);
     //-----------------------------------------
     // Set custom field data for cookie
     //-----------------------------------------
     $custom_field_data_imploded = array();
     foreach ($custom_field_data as $k => $v) {
         if (strpos($k, 'field_') === 0) {
             $custom_field_data_imploded[] = substr($k, 6) . '==' . $v;
         }
     }
     $custom_field_data_imploded = implode('||', $custom_field_data_imploded);
     //-----------------------------------------
     // Store the cooookie
     //-----------------------------------------
     if (!$this->request['_nosave']) {
         $_cookie = array('c_member_type' => $member_type, 'c_banned_type' => $banned_type, 'c_spam_type' => $spam_type, 'c_member_contains' => $member_contains, 'c_member_contains_type' => $member_contains_type, 'c_member_contains_text' => $member_contains_text, 'c_order_by' => preg_replace("#.*\\.(.*)\$#", "\\1", $__order_by), 'c_order_direction' => $__order_direction, 'c_post_count' => $post_count, 'c_post_count_type' => $post_count_type, 'c_date_reg_from' => $date_reg_from, 'c_date_reg_to' => $date_reg_to, 'c_date_post_from' => $date_post_from, 'c_date_post_to' => $date_post_to, 'c_date_active_from' => $date_active_from, 'c_date_active_to' => $date_active_to, 'c_primary_group' => $primary_group, 'c_secondary_group' => $secondary_group, 'c_custom_fields' => $custom_field_data_imploded);
         ipsRegistry::getClass('adminFunctions')->staffSaveCookie('memberFilter', $_cookie);
     }
     //-----------------------------------------
     // Create filter boxes
     //-----------------------------------------
     $this->registry->output->html .= $this->html->member_list_context_menu_filters($form, $fields, $filters_preset);
     //-----------------------------------------
     // Return data
     //-----------------------------------------
     $_return = array('custom_fields' => '');
     if (is_array($fields->out_fields) and count($fields->out_fields)) {
         foreach ($fields->out_fields as $id => $data) {
             $_return['custom_fields'][$id] = $fields->in_fields[$id];
         }
     }
     foreach (array_keys($form) as $_key) {
         $__key = substr($_key, 1);
         $_return[$__key] = ${$__key};
     }
     return $_return;
 }
 /**
  * Create new member
  * Very basic functionality at this point.
  *
  * @access	public
  * @param	array 	Fields to save in the following format: array( 'members'      => array( 'email'     => '*****@*****.**',
  *																				         'joined'   => time() ),
  *															   'extendedProfile' => array( 'signature' => 'My signature' ) );
  *					Tables: members, pfields_content, profile_portal.
  *					You can also use the aliases: 'core [members]', 'extendedProfile [profile_portal]', and 'customFields [pfields_content]'
  * @param	bool	Flag to attempt to auto create a name if the desired is taken
  * @param	bool	Bypass custom field saving (if using the sso session integration this is required as member object isn't ready yet)
  * @return	array 	Final member Data including member_id
  *
  * EXCEPTION CODES
  * CUSTOM_FIELDS_EMPTY    - Custom fields were not populated
  * CUSTOM_FIELDS_INVALID  - Custom fields were invalid
  * CUSTOM_FIELDS_TOOBIG   - Custom fields too big
  */
 public static function create($tables = array(), $autoCreateName = FALSE, $bypassCfields = FALSE)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $finalTables = array();
     $password = '';
     $bitWiseFields = ipsRegistry::fetchBitWiseOptions('global');
     //-----------------------------------------
     // Remap tables if required
     //-----------------------------------------
     foreach ($tables as $table => $data) {
         $_name = isset(self::$remap[$table]) ? self::$remap[$table] : $table;
         if ($_name == 'members') {
             /* Magic password field */
             $password = isset($data['password']) ? trim($data['password']) : IPSLib::makePassword();
             $md_5_password = md5($password);
             unset($data['password']);
         }
         $finalTables[$_name] = $data;
     }
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     if (!$bypassCfields) {
         require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
         $fields = new customProfileFields();
         if (is_array($finalTables['pfields_content']) and count($finalTables['pfields_content'])) {
             $fields->member_data = $finalTables['pfields_content'];
         }
         $_cfieldMode = 'normal';
         $fields->initData('edit');
         $fields->parseToSave($finalTables['pfields_content'], 'register');
         /* Check */
         if (count($fields->error_fields['empty'])) {
             //throw new Exception( 'CUSTOM_FIELDS_EMPTY' );
         }
         if (count($fields->error_fields['invalid'])) {
             //throw new Exception( 'CUSTOM_FIELDS_INVALID' );
         }
         if (count($fields->error_fields['toobig'])) {
             //throw new Exception( 'CUSTOM_FIELDS_TOOBIG' );
         }
     }
     //-----------------------------------------
     // Make sure the account doesn't exist
     //-----------------------------------------
     if ($finalTables['members']['email']) {
         $existing = IPSMember::load($finalTables['members']['email'], 'all');
         if ($existing['member_id']) {
             $existing['full'] = true;
             $existing['timenow'] = time();
             return $existing;
         }
     }
     //-----------------------------------------
     // Fix up usernames and display names
     //-----------------------------------------
     /* Ensure we have a display name */
     $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] ? $finalTables['members']['members_display_name'] : $finalTables['members']['name'];
     //-----------------------------------------
     // Clean up characters
     //-----------------------------------------
     if ($finalTables['members']['name']) {
         $userName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['name'], array(), 'name');
         if ($userName['errors']) {
             $finalTables['members']['name'] = '';
         } else {
             $finalTables['members']['name'] = $userName['username'];
         }
     }
     if ($finalTables['members']['members_display_name']) {
         $displayName = IPSMember::getFunction()->cleanAndCheckName($finalTables['members']['members_display_name']);
         if ($displayName['errors']) {
             $finalTables['members']['members_display_name'] = '';
         } else {
             $finalTables['members']['members_display_name'] = $displayName['members_display_name'];
         }
     }
     //-----------------------------------------
     // Remove some basic HTML tags
     //-----------------------------------------
     $finalTables['members']['members_display_name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['members_display_name']);
     $finalTables['members']['name'] = str_replace(array('<', '>', '"'), '', $finalTables['members']['name']);
     //-----------------------------------------
     // Make sure the names are unique
     //-----------------------------------------
     if ($finalTables['members']['members_display_name']) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['members_display_name'], array(), 'members_display_name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique display name */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_display_name LIKE '" . $this->DB->addSlashes(strtolower($finalTables['members']['members_display_name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['members_display_name'] = $finalTables['members']['members_display_name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['members_display_name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     if ($finalTables['members']['name']) {
         try {
             if (IPSMember::getFunction()->checkNameExists($finalTables['members']['name'], array(), 'name', true) === true) {
                 if ($autoCreateName === TRUE) {
                     /* Now, make sure we have a unique username */
                     $max = ipsRegistry::DB()->buildAndFetch(array('select' => 'MAX(member_id) as max', 'from' => 'members', 'where' => "members_l_username LIKE '" . $this->DB->addSlashes(strtolower($finalTables['members']['name'])) . "%'"));
                     if ($max['max']) {
                         $_num = $max['max'] + 1;
                         $finalTables['members']['name'] = $finalTables['members']['name'] . '_' . $_num;
                     }
                 } else {
                     $finalTables['members']['name'] = '';
                 }
             }
         } catch (Exception $e) {
         }
     }
     //-----------------------------------------
     // Populate member table(s)
     //-----------------------------------------
     $finalTables['members']['members_l_username'] = isset($finalTables['members']['name']) ? strtolower($finalTables['members']['name']) : '';
     $finalTables['members']['joined'] = $finalTables['members']['joined'] ? $finalTables['members']['joined'] : time();
     $finalTables['members']['email'] = $finalTables['members']['email'] ? $finalTables['members']['email'] : $finalTables['members']['name'] . '@' . $finalTables['members']['joined'];
     $finalTables['members']['member_group_id'] = $finalTables['members']['member_group_id'] ? $finalTables['members']['member_group_id'] : ipsRegistry::$settings['member_group'];
     $finalTables['members']['ip_address'] = $finalTables['members']['ip_address'] ? $finalTables['members']['ip_address'] : ipsRegistry::member()->ip_address;
     $finalTables['members']['members_created_remote'] = intval($finalTables['members']['members_created_remote']);
     $finalTables['members']['member_login_key'] = IPSMember::generateAutoLoginKey();
     $finalTables['members']['member_login_key_expire'] = ipsRegistry::$settings['login_key_expire'] ? time() + intval(ipsRegistry::$settings['login_key_expire']) * 86400 : 0;
     $finalTables['members']['view_sigs'] = 1;
     $finalTables['members']['email_pm'] = 1;
     $finalTables['members']['view_img'] = 1;
     $finalTables['members']['view_avs'] = 1;
     $finalTables['members']['restrict_post'] = intval($finalTables['members']['restrict_post']);
     $finalTables['members']['view_pop'] = 1;
     $finalTables['members']['msg_count_total'] = 0;
     $finalTables['members']['msg_count_new'] = 0;
     $finalTables['members']['msg_show_notification'] = 1;
     $finalTables['members']['coppa_user'] = 0;
     $finalTables['members']['auto_track'] = intval($finalTables['members']['auto_track']);
     $finalTables['members']['last_visit'] = $finalTables['members']['last_visit'] ? $finalTables['members']['last_visit'] : time();
     $finalTables['members']['last_activity'] = $finalTables['members']['last_activity'] ? $finalTables['members']['last_activity'] : time();
     $finalTables['members']['language'] = IPSLib::getDefaultLanguage();
     $finalTables['members']['members_editor_choice'] = ipsRegistry::$settings['ips_default_editor'];
     $finalTables['members']['members_pass_salt'] = IPSMember::generatePasswordSalt(5);
     $finalTables['members']['members_pass_hash'] = IPSMember::generateCompiledPasshash($finalTables['members']['members_pass_salt'], $md_5_password);
     $finalTables['members']['members_display_name'] = isset($finalTables['members']['members_display_name']) ? $finalTables['members']['members_display_name'] : '';
     $finalTables['members']['members_l_display_name'] = isset($finalTables['members']['members_display_name']) ? strtolower($finalTables['members']['members_display_name']) : '';
     $finalTables['members']['fb_uid'] = isset($finalTables['members']['fb_uid']) ? $finalTables['members']['fb_uid'] : 0;
     $finalTables['members']['fb_emailhash'] = isset($finalTables['members']['fb_emailhash']) ? strtolower($finalTables['members']['fb_emailhash']) : '';
     $finalTables['members']['members_seo_name'] = IPSText::makeSeoTitle($finalTables['members']['members_display_name']);
     $finalTables['members']['bw_is_spammer'] = intval($finalTables['members']['bw_is_spammer']);
     //-----------------------------------------
     // Insert: MEMBERS
     //-----------------------------------------
     ipsRegistry::DB()->force_data_type = array('name' => 'string', 'members_l_username' => 'string', 'members_display_name' => 'string', 'members_l_display_name' => 'string', 'members_seo_name' => 'string', 'email' => 'string');
     /* Bitwise options */
     if (is_array($bitWiseFields['members'])) {
         $_freeze = array();
         foreach ($bitWiseFields['members'] as $field) {
             if (isset($finalTables['members'][$field])) {
                 /* Add to freezeable array */
                 $_freeze[$field] = $finalTables['members'][$field];
                 /* Remove it from the fields to save to DB */
                 unset($finalTables['members'][$field]);
             }
         }
         if (count($_freeze)) {
             $finalTables['members']['members_bitoptions'] = IPSBWOptions::freeze($_freeze, 'members', 'global');
         }
     }
     ipsRegistry::DB()->insert('members', $finalTables['members']);
     //-----------------------------------------
     // Get the member id
     //-----------------------------------------
     $finalTables['members']['member_id'] = ipsRegistry::DB()->getInsertId();
     //-----------------------------------------
     // Insert: PROFILE PORTAL
     //-----------------------------------------
     $finalTables['profile_portal']['pp_member_id'] = $finalTables['members']['member_id'];
     $finalTables['profile_portal']['pp_setting_count_friends'] = 1;
     $finalTables['profile_portal']['pp_setting_count_comments'] = 1;
     ipsRegistry::DB()->insert('profile_portal', $finalTables['profile_portal']);
     //-----------------------------------------
     // Insert into the custom profile fields DB
     //-----------------------------------------
     if (!$bypassCfields) {
         $fields->out_fields['member_id'] = $finalTables['members']['member_id'];
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', $fields->out_fields);
     } else {
         ipsRegistry::DB()->delete('pfields_content', 'member_id=' . $finalTables['members']['member_id']);
         ipsRegistry::DB()->insert('pfields_content', array('member_id' => $finalTables['members']['member_id']));
     }
     //-----------------------------------------
     // Insert into partial ID table
     //-----------------------------------------
     $full_account = false;
     if ($finalTables['members']['members_display_name'] and $finalTables['members']['name'] and $finalTables['members']['email'] != $finalTables['members']['name'] . '@' . $finalTables['members']['joined']) {
         $full_account = true;
     }
     if (!$full_account) {
         ipsRegistry::DB()->insert('members_partial', array('partial_member_id' => $finalTables['members']['member_id'], 'partial_date' => $finalTables['members']['joined'], 'partial_email_ok' => $finalTables['members']['email'] == $finalTables['members']['name'] . '@' . $finalTables['members']['joined'] ? 0 : 1));
     }
     //IPSMember::updateSearchIndex( $finalTables['members']['member_id'] );
     IPSLib::runMemberSync('onCreateAccount', $finalTables['members']);
     return array_merge($finalTables['members'], $finalTables['profile_portal'], !$bypassCfields ? $fields->out_fields : array(), array('timenow' => $finalTables['members']['joined'], 'full' => $full_account));
 }
 /**
  * Manage validating members
  *
  * @access	private
  * @return	void		[Outputs to screen]
  */
 private function _manageValidating()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $ids = array();
     //-----------------------------------------
     // GET checkboxes
     //-----------------------------------------
     foreach ($this->request as $k => $v) {
         if (preg_match("/^mid_(\\d+)\$/", $k, $match)) {
             if ($v) {
                 $ids[] = $match[1];
             }
         }
     }
     $ids = IPSLib::cleanIntArray($ids);
     //-----------------------------------------
     // Check
     //-----------------------------------------
     if (count($ids) < 1) {
         $this->registry->output->showError($this->lang->words['t_nomemsel'], 11247);
     }
     //-----------------------------------------
     // APPROVE
     //-----------------------------------------
     if ($this->request['type'] == 'approve') {
         IPSText::getTextClass('email')->getTemplate("complete_reg");
         $approved = array();
         //-----------------------------------------
         // Get members
         //-----------------------------------------
         $this->DB->build(array('select' => 'v.*', 'from' => array('validating' => 'v'), 'where' => "m.member_id IN(" . implode(",", $ids) . ")", 'add_join' => array(array('select' => 'm.member_id, m.members_display_name, m.name, m.email, m.member_group_id', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
         $main = $this->DB->execute();
         while ($row = $this->DB->fetch($main)) {
             $approved[] = $row['name'];
             //-----------------------------------------
             // Only approve if the user is validating
             //-----------------------------------------
             if ($row['member_group_id'] != $this->settings['auth_group']) {
                 continue;
             }
             //-----------------------------------------
             // Don't approve if no real_group set
             //-----------------------------------------
             if (!$row['real_group']) {
                 //$row['real_group'] = $this->settings['member_group'];
                 continue;
             }
             //-----------------------------------------
             // We don't approve lost pass requests
             //-----------------------------------------
             if ($row['lost_pass'] == 1) {
                 continue;
             }
             try {
                 IPSMember::save($row['member_id'], array('core' => array('member_group_id' => $row['real_group'])));
             } catch (Exception $error) {
                 $this->registry->output->showError($error->getMessage(), 11247);
             }
             IPSText::getTextClass('email')->buildMessage(array());
             //-----------------------------------------
             // Using 'name' on purpose
             // @see http://forums./index.php?autocom=tracker&showissue=11564&view=findpost&p=45269
             //-----------------------------------------
             IPSText::getTextClass('email')->subject = sprintf($this->lang->words['subject__complete_reg'], $row['name'], $this->settings['board_name']);
             IPSText::getTextClass('email')->to = $row['email'];
             IPSText::getTextClass('email')->sendMail();
             IPSLib::runMemberSync('onGroupChange', $row['member_id'], $row['real_group']);
         }
         $this->DB->delete('validating', "member_id IN(" . implode(",", $ids) . ")");
         ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_memregapp2'] . implode(", ", $approved));
         //-----------------------------------------
         // Stats to Update?
         //-----------------------------------------
         $this->cache->rebuildCache('stats', 'global');
         $this->registry->output->global_message = count($ids) . $this->lang->words['t_memregapp'];
         if ($this->request['_return']) {
             $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . 'app=members&module=members&section=members&do=viewmember&member_id=' . $this->request['_return']);
         }
         $this->_viewQueue('validating');
         return;
     } else {
         if ($this->request['type'] == 'resend') {
             $reset = array();
             $cant = array();
             $main_msgs = array();
             //-----------------------------------------
             // Get members
             //-----------------------------------------
             $this->DB->build(array('select' => 'v.*', 'from' => array('validating' => 'v'), 'where' => "m.member_id IN(" . implode(",", $ids) . ")", 'add_join' => array(array('select' => 'm.member_id, m.members_display_name, m.email, m.member_group_id', 'from' => array('members' => 'm'), 'where' => 'm.member_id=v.member_id', 'type' => 'left'))));
             $main = $this->DB->execute();
             while ($row = $this->DB->fetch($main)) {
                 if ($row['member_group_id'] != $this->settings['auth_group']) {
                     continue;
                 }
                 if ($row['lost_pass']) {
                     IPSText::getTextClass('email')->getTemplate("lost_pass");
                     IPSText::getTextClass('email')->buildMessage(array('NAME' => $row['members_display_name'], 'THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=lostpass&do=sendform&uid=" . $row['member_id'] . "&aid=" . $val['vid'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=lostpass", 'EMAIL' => $row['email'], 'ID' => $row['member_id'], 'CODE' => $row['vid'], 'IP_ADDRESS' => $row['ip_address']));
                     IPSText::getTextClass('email')->subject = $this->lang->words['t_passwordrec'] . $this->settings['board_name'];
                     IPSText::getTextClass('email')->to = $row['email'];
                     IPSText::getTextClass('email')->sendMail();
                 } else {
                     if ($row['new_reg']) {
                         if ($row['user_verified']) {
                             $cant[] = $row['members_display_name'];
                             continue;
                         }
                         IPSText::getTextClass('email')->getTemplate("reg_validate");
                         IPSText::getTextClass('email')->buildMessage(array('THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=auto_validate&uid=" . $row['member_id'] . "&aid=" . $row['vid'], 'NAME' => $row['members_display_name'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=05", 'EMAIL' => $row['email'], 'ID' => $row['member_id'], 'CODE' => $row['vid']));
                         IPSText::getTextClass('email')->subject = $this->lang->words['t_regat'] . $this->settings['board_name'];
                         IPSText::getTextClass('email')->to = $row['email'];
                         IPSText::getTextClass('email')->sendMail();
                     } else {
                         if ($row['email_chg']) {
                             IPSText::getTextClass('email')->getTemplate("newemail");
                             IPSText::getTextClass('email')->buildMessage(array('NAME' => $row['members_display_name'], 'THE_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=auto_validate&type=newemail&uid=" . $row['member_id'] . "&aid=" . $row['vid'], 'ID' => $row['member_id'], 'MAN_LINK' => $this->settings['board_url'] . "/index.php?app=core&module=global&section=register&do=user_validate", 'CODE' => $row['vid']));
                             IPSText::getTextClass('email')->subject = $this->lang->words['t_emailchange'] . $this->settings['board_name'];
                             IPSText::getTextClass('email')->to = $row['email'];
                             IPSText::getTextClass('email')->sendMail();
                         }
                     }
                 }
                 $resent[] = $row['members_display_name'];
             }
             if (count($resent)) {
                 ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($resent) . $this->lang->words['tools_val_resent_log'] . implode(", ", $resent));
                 $main_msgs[] = count($resent) . $this->lang->words['t_vallog'] . implode(", ", $resent);
             }
             if (count($cant)) {
                 $main_msgs[] = $this->lang->words['t_valcannot'] . implode(", ", $cant);
             }
             $this->registry->output->global_message = count($main_msgs) ? implode("<br />", $main_msgs) : '';
             $this->_viewQueue('validating');
             return;
         } else {
             if ($this->request['type'] == 'ban') {
                 $this->DB->update('members', array('member_banned' => 1), "member_id IN(" . implode(",", $ids) . ")");
                 $this->DB->delete('validating', "member_id IN(" . implode(",", $ids) . ")");
                 ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_membanned']);
                 $this->registry->output->global_message = count($ids) . $this->lang->words['t_membanned'];
                 $this->_viewQueue('validating');
                 return;
             } else {
                 if ($this->request['type'] == 'spam') {
                     /* Grab members */
                     $members = IPSMember::load($ids);
                     /* Load moderator's library */
                     require IPSLib::getAppDir('forums') . '/sources/classes/moderate.php';
                     $modLibrary = new moderatorLibrary($this->registry);
                     /* Load custom fields class */
                     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
                     $fields = new customProfileFields();
                     /* Load language file */
                     $this->registry->getClass('class_localization')->loadLanguageFile(array('public_mod'), 'forums');
                     foreach ($members as $member_id => $member) {
                         $toSave = array('core' => array('bw_is_spammer' => 1, 'member_group_id' => $this->settings['member_group']));
                         /* Protected group? */
                         if (strstr(',' . $this->settings['warn_protected'] . ',', ',' . $member['member_group_id'] . ',')) {
                             continue;
                         }
                         /* What do to.. */
                         if ($this->settings['spm_option']) {
                             switch ($this->settings['spm_option']) {
                                 case 'disable':
                                     $toSave['core']['restrict_post'] = 1;
                                     $toSave['core']['members_disable_pm'] = 2;
                                     break;
                                 case 'unapprove':
                                     $toSave['core']['restrict_post'] = 1;
                                     $toSave['core']['members_disable_pm'] = 2;
                                     /* Unapprove posts and topics */
                                     $modLibrary->toggleApproveMemberContent($member_id, FALSE, 'all', intval($this->settings['spm_post_days']) * 24);
                                     break;
                                 case 'ban':
                                     /* Unapprove posts and topics */
                                     $modLibrary->toggleApproveMemberContent($member_id, FALSE, 'all', intval($this->settings['spm_post_days']) * 24);
                                     $toSave = array('core' => array('member_banned' => 1, 'title' => '', 'bw_is_spammer' => 1), 'extendedProfile' => array('signature' => '', 'pp_bio_content' => '', 'pp_about_me' => '', 'pp_status' => ''));
                                     //-----------------------------------------
                                     // Avatar
                                     //-----------------------------------------
                                     $toSave['extendedProfile']['avatar_location'] = "";
                                     $toSave['extendedProfile']['avatar_size'] = "";
                                     try {
                                         IPSMember::getFunction()->removeAvatar($member['member_id']);
                                     } catch (Exception $e) {
                                         // Maybe should show an error or something
                                     }
                                     //-----------------------------------------
                                     // Photo
                                     //-----------------------------------------
                                     IPSMember::getFunction()->removeUploadedPhotos($member['member_id']);
                                     $toSave['extendedProfile'] = array_merge($toSave['extendedProfile'], array('pp_main_photo' => '', 'pp_main_width' => '', 'pp_main_height' => '', 'pp_thumb_photo' => '', 'pp_thumb_width' => '', 'pp_thumb_height' => ''));
                                     //-----------------------------------------
                                     // Profile fields
                                     //-----------------------------------------
                                     $fields->member_data = $member;
                                     $fields->initData('edit');
                                     $fields->parseToSave(array());
                                     if (count($fields->out_fields)) {
                                         $toSave['customFields'] = $fields->out_fields;
                                     }
                                     //-----------------------------------------
                                     // Update signature content cache
                                     //-----------------------------------------
                                     IPSContentCache::update($member['member_id'], 'sig', '');
                                     break;
                             }
                         }
                         /* Send an email */
                         if ($this->settings['spm_notify'] and $this->settings['email_out'] != $this->memberData['email']) {
                             IPSText::getTextClass('email')->getTemplate('possibleSpammer');
                             IPSText::getTextClass('email')->buildMessage(array('DATE' => $this->registry->class_localization->getDate($member['joined'], 'LONG', 1), 'MEMBER_NAME' => $member['members_display_name'], 'IP' => $member['ip_address'], 'EMAIL' => $member['email'], 'LINK' => $this->registry->getClass('output')->buildSEOUrl("showuser="******"member_id IN(" . implode(",", $ids) . ")");
                         $this->registry->output->global_message = count($ids) . ' ' . $this->lang->words['t_setasspammers'];
                         $this->_viewQueue('validating');
                         return;
                     }
                 } else {
                     $denied = array();
                     $this->DB->build(array('select' => 'members_display_name', 'from' => 'members', 'where' => "member_id IN(" . implode(",", $ids) . ")"));
                     $this->DB->execute();
                     while ($r = $this->DB->fetch()) {
                         $denied[] = $r['members_display_name'];
                     }
                     try {
                         IPSMember::remove($ids);
                     } catch (Exception $error) {
                         $this->registry->output->showError($error->getMessage(), 11247);
                     }
                     ipsRegistry::getClass('adminFunctions')->saveAdminLog(count($ids) . $this->lang->words['t_regdenied'] . implode(", ", $denied));
                     $this->registry->output->global_message = count($ids) . $this->lang->words['t_removedmem'];
                     $this->_viewQueue('validating');
                     return;
                 }
             }
         }
     }
 }
 /**
  * UserCP Save Form: Profile Info
  *
  * @access	public
  * @return	array	Errors
  */
 public function saveProfileInfo()
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $pp_setting_notify_comments = trim(substr($this->request['pp_setting_notify_comments'], 0, 10));
     $pp_setting_notify_friend = trim(substr($this->request['pp_setting_notify_friend'], 0, 10));
     $pp_setting_moderate_comments = intval($this->request['pp_setting_moderate_comments']);
     $pp_setting_moderate_friends = intval($this->request['pp_setting_moderate_friends']);
     $pp_setting_count_visitors = intval($this->request['pp_setting_count_visitors']);
     $pp_setting_count_comments = intval($this->request['pp_setting_count_comments']);
     $pp_setting_count_friends = intval($this->request['pp_setting_count_friends']);
     $_gender = $this->request['gender'] == 'male' ? 'male' : ($this->request['gender'] == 'female' ? 'female' : '');
     //-----------------------------------------
     // Check to make sure that we can edit profiles..
     //-----------------------------------------
     if (!$this->memberData['g_edit_profile']) {
         $this->registry->getClass('output')->showError('members_profile_disabled', 10214);
     }
     //-----------------------------------------
     // make sure that either we entered
     // all calendar fields, or we left them
     // all blank
     //-----------------------------------------
     $c_cnt = 0;
     foreach (array('day', 'month', 'year') as $v) {
         if ($this->request[$v]) {
             $c_cnt++;
         }
     }
     if ($c_cnt > 0 && $c_cnt < 2) {
         $this->registry->getClass('output')->showError('member_bad_birthday', 10215);
     } else {
         if ($c_cnt > 0) {
             //-----------------------------------------
             // Make sure it's a legal date
             //-----------------------------------------
             $_year = $this->request['year'] ? $this->request['year'] : 1999;
             if (!checkdate($this->request['month'], $this->request['day'], $_year)) {
                 $this->registry->getClass('output')->showError('member_bad_birthday', 10216);
             }
         }
     }
     if ($this->memberData['g_edit_profile']) {
         $pp_bio_content = IPSText::mbsubstr(nl2br($this->request['pp_bio_content']), 0, 300);
     }
     if (!$this->memberData['g_edit_profile']) {
         $pp_bio_content = $this->memberData['pp_bio_content'];
     }
     //-----------------------------------------
     // Start off our array
     //-----------------------------------------
     $core = array('bday_day' => $this->request['day'], 'bday_month' => $this->request['month'], 'bday_year' => $this->request['year']);
     $extendedProfile = array('pp_bio_content' => IPSText::getTextClass('bbcode')->stripBadWords($pp_bio_content), 'pp_setting_notify_comments' => $pp_setting_notify_comments, 'pp_setting_notify_friend' => $pp_setting_notify_friend, 'pp_setting_moderate_comments' => $pp_setting_moderate_comments, 'pp_setting_moderate_friends' => $pp_setting_moderate_friends, 'pp_setting_count_visitors' => $pp_setting_count_visitors, 'pp_setting_count_comments' => $pp_setting_count_comments, 'pp_setting_count_friends' => $pp_setting_count_friends);
     //-----------------------------------------
     // check to see if we can enter a member title
     // and if one is entered, update it.
     //-----------------------------------------
     if (isset($this->request['member_title']) and $this->settings['post_titlechange'] and $this->memberData['posts'] >= $this->settings['post_titlechange']) {
         $core['title'] = IPSText::getTextClass('bbcode')->stripBadWords($this->request['member_title']);
     }
     //-----------------------------------------
     // Custom profile field stuff
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
     $fields = new customProfileFields();
     $fields->member_data = $this->member->fetchMemberData();
     $fields->initData('edit');
     /* Use $_POST and not ipsRegistry::$request as the custom profile field kernel class has its own cleaning routines for saving and showing
        which means we end up with double & -> &amp; conversion (&amp;lt;, etc) */
     $fields->parseToSave($_POST);
     if ($fields->error_messages) {
         return $fields->error_messages;
     }
     /* Check the website url field */
     $website_field = $fields->getFieldIDByKey('website');
     if ($website_field && $fields->out_fields['field_' . $website_field]) {
         if (!stristr($fields->out_fields['field_' . $website_field], 'http://')) {
             $fields->out_fields['field_' . $website_field] = 'http://' . $fields->out_fields['field_' . $website_field];
         }
     }
     //-----------------------------------------
     // Check...
     //-----------------------------------------
     if (count($fields->error_fields['empty'])) {
         $this->registry->getClass('output')->showError(array('customfields_empty', $fields->error_fields['empty'][0]['pf_title']), 10217);
     }
     if (count($fields->error_fields['invalid'])) {
         $this->registry->getClass('output')->showError(array('customfields_invalid', $fields->error_fields['invalid'][0]['pf_title']), 10218);
     }
     if (count($fields->error_fields['toobig'])) {
         $this->registry->getClass('output')->showError(array('customfields_toobig', $fields->error_fields['toobig'][0]['pf_title']), 10219);
     }
     //-----------------------------------------
     // Update the DB
     //-----------------------------------------
     IPSMember::save($this->memberData['member_id'], array('core' => $core, 'customFields' => $fields->out_fields, 'extendedProfile' => $extendedProfile));
     return TRUE;
 }
 /**
  * Form to edit a member
  *
  * @access	private
  * @return	void		Outputs error screen
  * @todo 	[Future] Determine what items should be editable and allow moderators to edit them
  * @todo 	[Future] Show avatar and profile picture previews?
  */
 private function _editMember()
 {
     $member = $this->_checkAndGetMember();
     if (IPSText::getTextClass('editor')->method == 'rte') {
         $editable['signature'] = IPSText::getTextClass('bbcode')->convertForRTE($member['signature']);
     } else {
         $editable['signature'] = IPSText::getTextClass('bbcode')->preEditParse($member['signature']);
     }
     if (IPSText::getTextClass('editor')->method == 'rte') {
         $editable['aboutme'] = IPSText::getTextClass('bbcode')->convertForRTE($member['pp_about_me']);
     } else {
         $editable['aboutme'] = IPSText::getTextClass('bbcode')->preEditParse($member['pp_about_me']);
     }
     $editable['member_id'] = $member['member_id'];
     $editable['members_display_name'] = $member['members_display_name'];
     $editable['title'] = $member['title'];
     $editable['pp_status'] = $member['pp_status'];
     //-----------------------------------------
     // Profile fields
     //-----------------------------------------
     require_once IPS_ROOT_PATH . 'sources/classes/customfields/profileFields.php';
     $fields = new customProfileFields();
     $fields->member_data = $member;
     $fields->initData('edit');
     $fields->parseToEdit();
     $editable['signature'] = IPSText::getTextClass('editor')->showEditor($editable['signature'], 'Post');
     $editable['aboutme'] = IPSText::getTextClass('editor')->showEditor($editable['aboutme'], 'aboutme');
     //-----------------------------------------
     // Show?
     //-----------------------------------------
     $this->output .= $this->registry->getClass('output')->getTemplate('mod')->editUserForm($editable, $fields);
     $this->registry->getClass('output')->setTitle($this->lang->words['cp_em_title']);
     $this->registry->getClass('output')->addNavigation($this->lang->words['cp_vp_title'], "showuser={$member['member_id']}", $member['members_seo_name'], 'showuser');
     $this->registry->getClass('output')->addNavigation($this->lang->words['cp_em_title'], '');
 }