function send_feedback($sender_name, $sender_email, $message, $preview = false)
{
    global $_CLASS, $_CORE_CONFIG;
    $_CLASS['core_template']->assign_array(array('SENT_FROM' => $sender_name, 'SENDER_NAME' => $sender_name, 'SENDER_EMAIL' => $sender_email, 'SENDER_IP' => $_CLASS['core_user']->ip, 'MESSAGE' => $message));
    $body = trim($_CLASS['core_template']->display('modules/Contact/email/index.html', true));
    if ($preview) {
        $_CLASS['core_template']->assign('PREVIEW', $body);
        return;
    }
    require_once $site_file_root . 'includes/mailer.php';
    $mailer = new core_mailer();
    $mailer->to($_CORE_CONFIG['email']['site_mail'], false);
    $mailer->subject($_CLASS['core_user']->get_lang('SITE_FEEDBACK'));
    $mailer->message = $body;
    trigger_error($mailer->send() ? 'SEND_SUCCESSFULL' : $mailer->error);
}
 function send_feedback()
 {
     global $_CLASS, $_CORE_CONFIG;
     $_CLASS['core_template']->assign_array(array('SENT_FROM' => $this->data['NAME'], 'SENDER_NAME' => $this->data['NAME'], 'SENDER_EMAIL' => $this->data['EMAIL'], 'SENDER_IP' => $_CLASS['core_user']->ip, 'MESSAGE' => $this->data['MESSAGE']));
     $body = trim($_CLASS['core_template']->display('email/contact/index.txt', true));
     if ($this->preview) {
         $_CLASS['core_template']->assign('PREVIEW', modify_lines($body, '<br/>'));
         return;
     }
     require_once SITE_FILE_ROOT . 'includes/mailer.php';
     $mailer = new core_mailer();
     $mailer->to($_CORE_CONFIG['email']['site_mail'], $_CORE_CONFIG['global']['site_name']);
     $mailer->subject($_CLASS['core_user']->get_lang('SITE_FEEDBACK'));
     $mailer->message = $body;
     trigger_error($mailer->send() ? 'SEND_SUCCESSFULL' : $mailer->error);
 }
function pm_notification($mode, $author, $recipients, $subject, $message)
{
    global $_CLASS, $_CORE_CONFIG, $config;
    if (empty($recipients)) {
        return;
    }
    $subject = censor_text($subject);
    $recipient_list = implode(', ', array_unique(array_keys($recipients)));
    $sql = 'SELECT user_id, username, user_email, user_lang, user_notify_pm, user_notify_type
		FROM ' . USERS_TABLE . "\n\t\tWHERE user_id IN ({$recipient_list})";
    $result = $_CLASS['core_db']->query($sql);
    $user_list = array();
    // add lang support
    while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) {
        if ($row['user_notify_pm']) {
            $user_list[] = $row;
        }
    }
    $_CLASS['core_db']->free_result($result);
    if (empty($user_list)) {
        return;
    }
    $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
    require_once SITE_FILE_ROOT . 'includes/mailer.php';
    $mailer = new core_mailer();
    $count = count($user_list);
    for ($i = 0; $i < $count; $i++) {
        $mailer->to($user_list[$i]['user_email'], $user_list[$i]['username']);
    }
    $mailer->subject('New Private Message has arrived');
    $_CLASS['core_template']->assign_array(array('EMAIL_SIG' => $email_sig, 'SITENAME' => $_CORE_CONFIG['global']['site_name'], 'SUBJECT' => $subject, 'AUTHOR_NAME' => $author, 'LINK_INBOX' => generate_link('Control_Panel&i=pm&mode=unread', array('full' => true, 'sid' => true))));
    $mailer->message = trim($_CLASS['core_template']->display('email/control_panel/pm_notify.txt', true));
    if (!$mailer->send()) {
        //echo $mailer->error;
    }
}
function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id, $topic_id, $post_id)
{
    global $config, $_CORE_CONFIG, $_CLASS;
    $titles = array('notify_topic' => 'Topic Reply Notification - ' . $topic_title, 'notify_newtopic' => 'New Topic Notification - ' . $topic_title, 'notify_forum' => 'Forum Post Notification - ' . $forum_name);
    if ($mode == 'reply' || $mode == 'quote') {
        $topic_title = $subject;
        $notify_type = 'topic';
        $template = 'notify_topic';
        //notify_forum
        $where = "(w.forum_id = {$forum_id} OR w.topic_id = {$topic_id})";
    } else {
        $topic_title = $topic_title;
        $notify_type = 'forum';
        $template = 'notify_newtopic';
        $where = 'w.forum_id = ' . $forum_id;
    }
    $topic_title = censor_text($topic_title);
    $holding = array();
    // Add use of notification type
    // Lets get all the users that are set to be notified
    $sql = 'SELECT w.notify_type, w.forum_id, u.user_id, u.username, u.user_email, u.user_lang
		FROM ' . FORUMS_WATCH_TABLE . ' w, ' . USERS_TABLE . " u\n\t\tWHERE {$where}\n\t\t\tAND w.notify_status = 0\n\t\t\tAND u.user_status = " . STATUS_ACTIVE . '
			AND u.user_id = w.user_id';
    $result = $_CLASS['core_db']->query($sql);
    while ($user = $_CLASS['core_db']->fetch_row_assoc($result)) {
        $ignore_array[$user['user_id']] = $user['user_id'];
        $holding[$user['user_id']] = $user;
        $holding[$user['user_id']]['template'] = $notify_type == 'topic' && $user['forum_id'] ? 'notify_forum' : $template;
        if ($notify_type == 'topic' && $user['forum_id']) {
            $holding[$user['user_id']]['template'] = 'notify_forum';
            $holding[$user['user_id']]['update'] = 'forum';
        } else {
            $holding[$user['user_id']]['template'] = $template;
            $holding[$user['user_id']]['update'] = $notify_type;
        }
    }
    $_CLASS['core_db']->free_result($result);
    if (empty($holding)) {
        return;
    }
    // Now we remove the users that aren't allowed to read the forum
    $acl_list = $_CLASS['auth']->acl_get_list(array_keys($ignore_array), 'f_read', $forum_id);
    if (!empty($acl_list)) {
        foreach ($acl_list[$forum_id]['f_read'] as $user_id) {
            unset($ignore_array[$user_id]);
        }
    }
    $processed = $delete_array = $update_array = array();
    foreach ($holding as $user) {
        if (!in_array($user['user_id'], $ignore_array)) {
            $processed[$user['template']][] = $user;
            $update_array[$user['update']][] = $user['user_id'];
        } else {
            $delete_array[$user['update']] = $user['user_id'];
        }
    }
    unset($holding, $ignore_array);
    // Now delete the user_ids not authorized to receive notifications on this topic/forum
    if (!empty($delete_array['topic'])) {
        $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_WATCH_TABLE . "\n\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tAND user_id IN (" . implode(', ', $delete_array['topic']) . ")");
    }
    if (!empty($delete_array['forum'])) {
        $_CLASS['core_db']->query('DELETE FROM ' . FORUMS_WATCH_TABLE . "\n\t\t\tWHERE forum_id = {$forum_id}\n\t\t\t\tAND user_id IN (" . implode(', ', $delete_array['forum']) . ")");
    }
    if (empty($processed)) {
        return;
    }
    $email_sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
    require_once SITE_FILE_ROOT . 'includes/mailer.php';
    foreach ($processed as $template => $user_list) {
        $mailer = new core_mailer();
        $count = count($user_list);
        for ($i = 0; $i < $count; $i++) {
            $mailer->to($user_list[$i]['user_email'], $user_list[$i]['username']);
        }
        $mailer->subject($titles[$template]);
        $_CLASS['core_template']->assign_array(array('EMAIL_SIG' => $email_sig, 'SITENAME' => $_CORE_CONFIG['global']['site_name'], 'TOPIC_TITLE' => $topic_title, 'FORUM_NAME' => $forum_name, 'U_FORUM' => generate_link("Forums&file=viewforum&f={$forum_id}&e=0", array('sid' => false, 'full' => true)), 'U_TOPIC' => generate_link("Forums&file=viewtopic&t={$topic_id}&e=0", array('sid' => false, 'full' => true)), 'U_NEWEST_POST' => generate_link("Forums&file=viewtopic&t={$topic_id}&p={$post_id}&e={$post_id}", array('sid' => false, 'full' => true)), 'U_STOP_WATCHING_TOPIC' => generate_link("Forums&file=viewtopic&t={$topic_id}&unwatch=topic", array('sid' => false, 'full' => true)), 'U_STOP_WATCHING_FORUM' => generate_link("Forums&file=viewforum&f={$forum_id}&unwatch=forum", array('sid' => false, 'full' => true))));
        $mailer->message = trim($_CLASS['core_template']->display("email/forums/{$template}.txt", true));
        if (!$mailer->send()) {
            //echo $mailer->error;
        }
    }
    $_CLASS['core_db']->transaction();
    if (!empty($update_array['topic'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_WATCH_TABLE . "\n\t\t\tSET notify_status = 1\n\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tAND user_id IN (" . implode(', ', $update_array['topic']) . ")");
    }
    if (!empty($update_array['forum'])) {
        $_CLASS['core_db']->query('UPDATE ' . FORUMS_WATCH_TABLE . "\n\t\t\tSET notify_status = 1\n\t\t\tWHERE forum_id = {$forum_id}\n\t\t\t\tAND user_id IN (" . implode(', ', $update_array['forum']) . ")");
    }
    $_CLASS['core_db']->transaction('commit');
}
 function ucp_register($id, $mode)
 {
     global $site_file_root, $config, $_CLASS, $_CORE_CONFIG;
     $coppa = isset($_REQUEST['coppa']) ? (int) $_REQUEST['coppa'] : null;
     $submit = isset($_POST['submit']);
     if ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_DISABLE || ($coppa || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) && !$_CORE_CONFIG['email']['email_enable']) {
         trigger_error('UCP_REGISTER_DISABLE');
     }
     $_CLASS['core_template']->assign('S_UCP_ACTION', generate_link('Control_Panel&amp;mode=register'));
     $error = $data = array();
     $s_hidden_fields = '';
     if (!isset($_POST['agreed'])) {
         if ($_CORE_CONFIG['user']['coppa_enable'] && is_null($coppa)) {
             $now = explode(':', gmdate('m:j:Y'));
             $coppa_birthday = $_CLASS['core_user']->format_date(mktime(12, 0, 0, $now[0], $now[1], $now[2] - 13), 'D M d, Y');
             $_CLASS['core_template']->assign_array(array('L_COPPA_NO' => sprintf($_CLASS['core_user']->lang['UCP_COPPA_BEFORE'], $coppa_birthday), 'L_COPPA_YES' => sprintf($_CLASS['core_user']->lang['UCP_COPPA_ON_AFTER'], $coppa_birthday), 'U_COPPA_NO' => generate_link('Control_Panel&amp;mode=register&amp;coppa=0'), 'U_COPPA_YES' => generate_link('Control_Panel&amp;mode=register&amp;coppa=1'), 'S_SHOW_COPPA' => true, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_REGISTER_ACTION' => generate_link('Control_Panel&amp;mode=register')));
         } else {
             $s_hidden_fields .= '<input type="hidden" name="coppa" value="' . $coppa . '" />';
             $_CLASS['core_template']->assign_array(array('S_SHOW_COPPA' => false, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_REGISTER_ACTION' => generate_link('Control_Panel&amp;mode=register')));
         }
         $this->display($_CLASS['core_user']->lang['REGISTER'], 'ucp_agreement.html');
         script_close();
     }
     if ($submit) {
         require_once $site_file_root . 'includes/functions_user.php';
         $error = array();
         $username = get_variable('username', 'POST', false);
         $password = get_variable('password', 'POST', false);
         $email = get_variable('email', 'POST', false);
         $email_confirm = get_variable('email_confirm', 'POST', '');
         //when we add this make sure to confirm that it's one of the installed langs
         $lang = $_CORE_CONFIG['global']['default_lang'];
         $tz = get_variable('tz', 'POST', false);
         if (strpos($username, "\n")) {
             die;
         }
         $username_validate = validate_username($username);
         if ($username_validate !== true) {
             $error[] = $_CLASS['core_user']->get_lang($username_validate);
         }
         if (!$password || $password !== get_variable('password_confirm', 'POST', '')) {
             $error[] = $_CLASS['core_user']->get_lang('PASSWORD_ERROR');
         }
         if (!$email || $email !== $email_confirm) {
             $error[] = $_CLASS['core_user']->get_lang('EMAIL_ERROR');
         } elseif (!check_email($email)) {
             $error[] = $_CLASS['core_user']->get_lang('EMAIL_INVALID');
         }
         if (!$tz || !in_array($tz, tz_array())) {
             $tz = null;
         }
         if ($_CORE_CONFIG['user']['enable_confirm']) {
             $confirmation_code = $_CLASS['core_user']->session_data_get('confirmation_code');
             $confirm_code = trim(get_variable('confirm_code', 'POST', false));
             if (!$confirm_code || !$confirmation_code || $confirm_code != $confirmation_code) {
                 $error[] = $_CLASS['core_user']->get_lang('CONFIRM_CODE_WRONG');
             }
             // we don't need this any more
             $_CLASS['core_user']->user_data_kill('confirmation_code');
         }
         if (empty($error)) {
             $password = encode_password($password, $_CORE_CONFIG['user']['password_encoding']);
             if (!$password) {
                 //do some admin contact thing here
                 die('Activation disabled: Passwaord encoding problem');
             }
             if ($coppa || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF || $_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) {
                 if (!$_CORE_CONFIG['email']['email_enable']) {
                     //do some admin contact thing here
                     die('Activation disabled: Email Disabled');
                 }
                 $user_status = STATUS_PENDING;
                 $user_act_key = generate_string(10);
                 if ($coppa) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_COPPA'];
                     $email_template = 'coppa_welcome_inactive';
                 } elseif ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_SELF) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_INACTIVE'];
                     $email_template = 'user_welcome_inactive';
                 } elseif ($_CORE_CONFIG['user']['activation'] == USER_ACTIVATION_ADMIN) {
                     $message = $_CLASS['core_user']->lang['ACCOUNT_INACTIVE_ADMIN'];
                     $email_template = 'admin_welcome_inactive';
                 }
             } else {
                 $user_status = STATUS_ACTIVE;
                 $user_act_key = null;
                 $email_template = 'user_welcome';
                 $message = $_CLASS['core_user']->lang['ACCOUNT_ADDED'];
             }
             $data = array('username' => (string) $username, 'user_email' => (string) $email, 'user_group' => $coppa ? 3 : 2, 'user_reg_date' => (int) $_CLASS['core_user']->time, 'user_timezone' => (string) $tz, 'user_password' => (string) $password, 'user_password_encoding' => (string) $_CORE_CONFIG['user']['password_encoding'], 'user_lang' => $lang ? (string) $lang : null, 'user_type' => USER_NORMAL, 'user_status' => (int) $user_status, 'user_act_key' => (string) $user_act_key, 'user_ip' => (string) $_CLASS['core_user']->ip);
             user_add($data);
             if ($data['user_status'] === STATUS_ACTIVE) {
                 set_core_config('user', 'newest_user_id', $data['user_id'], false);
                 set_core_config('user', 'newest_username', $data['username'], false);
                 set_core_config('user', 'total_users', $_CORE_CONFIG['user']['total_users'] + 1, false);
             }
             require_once $site_file_root . 'includes/mailer.php';
             $mailer = new core_mailer();
             $mailer->to($email, $username);
             $mailer->subject($subject);
             $_CLASS['core_template']->assign_array(array('SITENAME' => $_CORE_CONFIG['global']['site_name'], 'WELCOME_MSG' => sprintf($_CLASS['core_user']->lang['WELCOME_SUBJECT'], $_CORE_CONFIG['global']['site_name']), 'USERNAME' => $username, 'PASSWORD' => $password, 'EMAIL_SIG' => '', 'U_ACTIVATE' => generate_link('system&amp;mode=activate&user_id=' . $data['user_id'] . '&key=' . $user_act_key, array('sid' => false, 'full' => true))));
             if ($coppa) {
                 $_CLASS['core_template']->assign_array(array('FAX_INFO' => $_CORE_CONFIG['user']['coppa_fax'], 'MAIL_INFO' => $_CORE_CONFIG['user']['coppa_mail'], 'EMAIL_ADDRESS' => $email, 'SITENAME' => $_CORE_CONFIG['global']['site_name']));
             }
             $mailer->message = trim($_CLASS['core_template']->display('modules/Control_Panel/email/' . $email_template, true));
             $mailer->send();
             $message = $message . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_INDEX'], '<a href="' . generate_link() . '">', '</a>');
             trigger_error($message);
         }
     }
     $s_hidden_fields .= '<input type="hidden" name="coppa" value="' . $coppa . '" />';
     $s_hidden_fields .= '<input type="hidden" name="agreed" value="true" />';
     if ($_CORE_CONFIG['user']['enable_confirm']) {
         $_CLASS['core_user']->session_data_set('confirmation_code', generate_string(6));
         $confirm_image = '<img src="' . generate_link('system&amp;mode=confirmation_image') . '" alt="" title="" />';
     } else {
         $confirm_image = false;
     }
     if ($submit) {
         if ($_CORE_CONFIG['user']['max_reg_attempts']) {
             $attempts = (int) $_CLASS['core_user']->session_data_get('reg_attempts', 0);
             if ($attempts > $_CORE_CONFIG['user']['max_reg_attempts']) {
                 trigger_error($_CLASS['core_user']->lang['TOO_MANY_REGISTERS']);
             }
             $_CLASS['core_user']->session_data_get('reg_attempts', $attempts + 1);
         }
     }
     switch ($_CORE_CONFIG['user']['activation']) {
         case USER_ACTIVATION_SELF:
             $l_reg_cond = $_CLASS['core_user']->lang['UCP_EMAIL_ACTIVATE'];
             break;
         case USER_ACTIVATION_ADMIN:
             $l_reg_cond = $_CLASS['core_user']->lang['UCP_ADMIN_ACTIVATE'];
             break;
         default:
             $l_reg_cond = '';
             break;
     }
     $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
     $_CLASS['core_template']->assign_array(array('ERROR' => empty($error) ? false : implode('<br />', $error), 'USERNAME' => isset($username) ? $username : '', 'PASSWORD' => isset($password) ? $password : '', 'EMAIL' => isset($email) ? $email : '', 'EMAIL_CONFIRM' => isset($email_confirm) ? $email_confirm : '', 'CONFIRM_IMG' => $confirm_image, 'SELECT_TZ' => select_tz(isset($tz) ? $tz : $_CORE_CONFIG['global']['default_timezone']), 'L_CONFIRM_EXPLAIN' => sprintf($_CLASS['core_user']->lang['CONFIRM_EXPLAIN'], '<a href="mailto:' . htmlentities($config['board_contact']) . '">', '</a>'), 'L_ITEMS_REQUIRED' => $l_reg_cond, 'L_USERNAME_EXPLAIN' => sprintf($_CLASS['core_user']->lang[$user_char_ary[$_CORE_CONFIG['user']['allow_name_chars']] . '_EXPLAIN'], $_CORE_CONFIG['user']['min_name_chars'], $_CORE_CONFIG['user']['max_name_chars']), 'L_NEW_PASSWORD_EXPLAIN' => sprintf($_CLASS['core_user']->lang['NEW_PASSWORD_EXPLAIN'], $_CORE_CONFIG['user']['min_pass_chars'], $_CORE_CONFIG['user']['max_pass_chars']), 'S_COPPA' => $coppa, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => generate_link("Control_Panel&amp;mode=register")));
     $this->display($_CLASS['core_user']->lang['REGISTER'], 'ucp_register.html');
 }
     if (!$email || !check_email($email)) {
         $error[] = $_CLASS['core_user']->lang['EMPTY_ADDRESS_EMAIL'];
     }
     if (!$name) {
         $error[] = $_CLASS['core_user']->lang['EMPTY_NAME_EMAIL'];
     }
 }
 if (empty($error)) {
     /*
     $sql = 'UPDATE ' . USERS_TABLE . '
     	SET user_last_email = ' . $_CLASS['core_user']->time . '
     	WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
     $result = $_CLASS['core_db']->query($sql);
     */
     require_once SITE_FILE_ROOT . 'includes/mailer.php';
     $mailer = new core_mailer();
     if ($topic_id) {
         $template = 'email_notify.txt';
         $email = $email;
         $subject = $row['topic_title'];
     } else {
         $template = 'profile_send_email.txt';
         $email = $row['user_email'];
         $name = $row['username'];
         $subject .= 'Email a friend';
     }
     $mailer->to($email, $name);
     $mailer->reply_to($_CLASS['core_user']->data['user_email'], $_CLASS['core_user']->data['username']);
     $mailer->subject($subject);
     if ($cc) {
         $mailer->cc($_CLASS['core_user']->data['user_email'], $_CLASS['core_user']->data['username']);
    function ucp_profile($id, $mode)
    {
        global $config, $_CLASS, $site_file_root, $_CORE_CONFIG;
        $preview = isset($_POST['preview']);
        $submit = isset($_POST['submit']);
        $module_link = generate_link("Control_Panel&amp;i={$id}&amp;mode={$mode}");
        $error = $data = array();
        $s_hidden_fields = '';
        switch ($mode) {
            case 'reg_details':
                if ($submit) {
                    $var_ary = array('username' => $_CLASS['core_user']->data['username'], 'email' => $_CLASS['core_user']->data['user_email'], 'email_confirm' => (string) '', 'new_password' => (string) '', 'cur_password' => (string) '', 'password_confirm' => (string) '');
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('username' => array(array('string', false, $_CORE_CONFIG['user']['min_name_chars'], $_CORE_CONFIG['user']['max_name_chars']), array('username', $data['username'])), 'password_confirm' => array('string', true, $_CORE_CONFIG['user']['min_pass_chars'], $_CORE_CONFIG['user']['max_pass_chars']), 'new_password' => array('string', true, $_CORE_CONFIG['user']['min_pass_chars'], $_CORE_CONFIG['user']['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('email', $data['email'])), 'email_confirm' => array('string', true, 6, 60));
                    $error = validate_data($data, $var_ary);
                    extract($data);
                    unset($data);
                    if ($new_password && $password_confirm != $new_password) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if (($new_password || $_CLASS['auth']->acl_get('u_chgemail') && $email != $_CLASS['core_user']->data['user_email'] || $username != $_CLASS['core_user']->data['username'] && $_CLASS['auth']->acl_get('u_chgname') && $_CORE_CONFIG['user']['allow_namechange']) && encode_password($cur_password, $_CLASS['core_user']->data['user_password_encoding']) != $_CLASS['core_user']->data['user_password']) {
                        $error[] = 'CUR_PASSWORD_ERROR';
                    }
                    if ($_CLASS['auth']->acl_get('u_chgemail') && $email != $_CLASS['core_user']->data['user_email'] && $email_confirm != $email) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('user_email' => $_CLASS['auth']->acl_get('u_chgemail') ? $email : $_CLASS['core_user']->data['user_email']);
                        if ($_CORE_CONFIG['email']['email_enable'] && $email != $_CLASS['core_user']->data['user_email'] && ($_CORE_CONFIG['user']['require_activation'] == USER_ACTIVATION_SELF || $_CORE_CONFIG['user']['require_activation'] == USER_ACTIVATION_ADMIN)) {
                            $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive.html' : 'user_activate.html';
                            $mailer = new core_mailer();
                            $messenger->template($template_file, $_CLASS['core_user']->data['user_lang']);
                            $mailer->subject($subject);
                            $messenger->to($email, $username);
                            $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                            $messenger->headers('X-AntiAbuse: User_id - ' . $_CLASS['core_user']->data['user_id']);
                            $messenger->headers('X-AntiAbuse: Username - ' . $_CLASS['core_user']->data['username']);
                            $messenger->headers('X-AntiAbuse: User IP - ' . $_CLASS['core_user']->ip);
                            $messenger->assign_vars(array('SITENAME' => $_CORE_CONFIG['global']['sitename'], 'USERNAME' => $username, 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => generate_link("Control_Panel&amp;mode=activate&u={$_CLASS['core_user']->data['user_id']}&k={$user_actkey}", array('full' => true))));
                            $body = trim($_CLASS['core_template']->display('modules/Contact/email/index.html', true));
                            $messenger->send(NOTIFY_EMAIL);
                            if ($_CORE_CONFIG['user']['require_activation'] == USER_ACTIVATION_ADMIN) {
                                // Grab an array of user_id's with a_user permissions
                                $admin_ary = $_CLASS['auth']->acl_get_list(false, 'a_user', false);
                                $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
									FROM ' . USERS_TABLE . ' 
									WHERE user_id IN (' . implode(', ', $admin_ary[0]['a_user']) . ')';
                                $result = $_CLASS['core_db']->sql_query($sql);
                                while ($row = $_CLASS['core_db']->sql_fetchrow($result)) {
                                    $messenger->template('admin_activate', $row['user_lang']);
                                    $messenger->replyto($config['board_contact']);
                                    $messenger->to($row['user_email'], $row['username']);
                                    $messenger->im($row['user_jabber'], $row['username']);
                                    $messenger->assign_vars(array('USERNAME' => $username, 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => generate_link("Control_Panel&amp;mode=activate&u={$_CLASS['core_user']->data['user_id']}&k={$user_actkey}", array('full' => true))));
                                    $messenger->send($row['user_notify_type']);
                                }
                                $_CLASS['core_db']->sql_freeresult($result);
                            }
                            $messenger->save_queue();
                            $sql_ary += array('user_type' => USER_INACTIVE, 'user_actkey' => $user_actkey);
                        }
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
                        $_CLASS['core_db']->sql_query($sql);
                        // Need to update config, forum, topic, posting, messages, etc.
                        if ($username != $_CLASS['core_user']->data['username'] && $_CLASS['auth']->acl_get('u_chgname') && $_CORE_CONFIG['user']['allow_namechange']) {
                            user_update_name($_CLASS['core_user']->data['username'], $username);
                        }
                        $_CLASS['core_display']->meta_refresh(3, $module_link);
                        $message = $_CLASS['core_user']->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $module_link . '">', '</a>');
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$_CLASS['core_user']->lang['\\1'])) ? \$_CLASS['core_user']->lang['\\1'] : '\\1'", $error);
                }
                $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
                $_CLASS['core_template']->assign(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => isset($username) ? $username : $_CLASS['core_user']->data['username'], 'EMAIL' => isset($email) ? $email : $_CLASS['core_user']->data['user_email'], 'CONFIRM_EMAIL' => '', 'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '', 'NEW_PASSWORD' => isset($new_password) ? $new_password : '', 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => sprintf($_CLASS['core_user']->lang[$user_char_ary[str_replace('\\\\', '\\', $_CORE_CONFIG['user']['allow_name_chars'])] . '_EXPLAIN'], $_CORE_CONFIG['user']['min_name_chars'], $_CORE_CONFIG['user']['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($_CLASS['core_user']->lang['CHANGE_PASSWORD_EXPLAIN'], $_CORE_CONFIG['user']['min_pass_chars'], $_CORE_CONFIG['user']['max_pass_chars']), 'S_FORCE_PASSWORD' => $_CORE_CONFIG['user']['chg_passforce'] && $this->data['user_passchg'] < time() - $_CORE_CONFIG['user']['chg_passforce'] ? true : false, 'S_CHANGE_USERNAME' => $_CORE_CONFIG['user']['allow_namechange'] && $_CLASS['auth']->acl_get('u_chgname') ? true : false, 'S_CHANGE_EMAIL' => $_CLASS['auth']->acl_get('u_chgemail') ? true : false, 'S_CHANGE_PASSWORD' => true));
                break;
            case 'profile_info':
                $error = array();
                $this_year = gmdate('Y', time());
                if ($submit) {
                    $icq = get_variable('icq', 'POST', null);
                    $aim = get_variable('aim', 'POST', null);
                    $msn = get_variable('msn', 'POST', null);
                    $yim = get_variable('yim', 'POST', null);
                    $jabber = get_variable('jabber', 'POST', null);
                    //$google = get_variable('google', 'POST', null);
                    $website = get_variable('website', 'POST', null);
                    $location = get_variable('location', 'POST', null);
                    $occupation = get_variable('occupation', 'POST', null);
                    $interests = get_variable('interests', 'POST', null);
                    $bday_day = get_variable('bday_day', 'POST', false);
                    $bday_month = get_variable('bday_month', 'POST', false);
                    $bday_year = get_variable('bday_year', 'POST', false);
                    if ($bday_day || $bday_month || $bday_year) {
                        if ($bday_day < 1 || $bday_day > 31 || $bday_month < 1 || $bday_month > 12 || $bday_year < $this_year - 100 || $bday_month > $this_year) {
                            $error[] = $_CLASS['core_user']->get_lang('BIRTHDAY_ERROR');
                        }
                    }
                    if (mb_strlen($interests) > 255) {
                        $error[] = $_CLASS['core_user']->get_lang('INTEREST_LONG_ERROR');
                    }
                    if (mb_strlen($occupation) > 255) {
                        $error[] = $_CLASS['core_user']->get_lang('OCCUPATION_LONG_ERROR');
                    }
                    if (empty($error)) {
                        $sql_ary = array('user_icq' => $icq, 'user_aim' => $aim, 'user_msnm' => $msn, 'user_yim' => $yim, 'user_jabber' => $jabber, 'user_website' => $website, 'user_from' => $location, 'user_occ' => $occupation, 'user_interests' => $interests, 'user_birthday' => $bday_day ? sprintf('%2d-%2d-%4d', $bday_day, $bday_month, $bday_year) : null);
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
                        $_CLASS['core_db']->sql_query($sql);
                        $_CLASS['core_display']->meta_refresh(3, $module_link);
                        $message = $_CLASS['core_user']->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $module_link . '">', '</a>');
                        trigger_error($message);
                    }
                }
                if (!isset($bday_day)) {
                    if ($_CLASS['core_user']->data['user_birthday']) {
                        list($bday_day, $bday_month, $bday_year) = explode('-', $_CLASS['core_user']->data['user_birthday']);
                    } else {
                        $bday_day = $bday_month = $bday_year = '';
                    }
                }
                $s_birthday_day_options = '<option value="0"' . (!$bday_day ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $bday_day ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$bday_month ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $bday_month ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_year_options = '';
                $s_birthday_year_options = '<option value="0"' . (!$bday_year ? ' selected="selected"' : '') . '>--</option>';
                $i = $this_year - 100;
                for ($i; $i < $this_year; $i++) {
                    $selected = $i == $bday_year ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $_CLASS['core_template']->assign_array(array('ERROR' => empty($error) ? '' : implode('<br />', $error), 'ICQ' => isset($icq) ? $icq : $_CLASS['core_user']->data['user_icq'], 'YIM' => isset($yim) ? $yim : $_CLASS['core_user']->data['user_yim'], 'AIM' => isset($aim) ? $aim : $_CLASS['core_user']->data['user_aim'], 'MSN' => isset($msn) ? $msn : $_CLASS['core_user']->data['user_msnm'], 'JABBER' => isset($jabber) ? $jabber : $_CLASS['core_user']->data['user_jabber'], 'WEBSITE' => isset($website) ? $website : $_CLASS['core_user']->data['user_website'], 'LOCATION' => isset($location) ? $location : $_CLASS['core_user']->data['user_from'], 'OCCUPATION' => isset($occupation) ? $occupation : $_CLASS['core_user']->data['user_occ'], 'INTERESTS' => isset($interests) ? $interests : $_CLASS['core_user']->data['user_interests'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options));
                break;
            case 'signature':
                require $site_file_root . 'includes/forums/functions_posting.php';
                // Generate smiley listing
                generate_smilies('inline', 0);
                $enable_html = $config['allow_sig_html'] ? isset($_POST['disable_html']) : false;
                $enable_bbcode = $config['allow_sig_bbcode'] ? isset($_POST['disable_bbcode']) ? false : $_CLASS['core_user']->optionget('bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? isset($_POST['disable_smilies']) ? false : $_CLASS['core_user']->optionget('smilies') : false;
                $enable_urls = isset($_POST['disable_magic_url']) ? false : true;
                $signature = request_var('signature', $_CLASS['core_user']->data['user_sig']);
                if ($submit || $preview) {
                    require_once $site_file_root . 'includes/forums/message_parser.php';
                    if ($signature) {
                        $message_parser = new parse_message($signature);
                        // Allowing Quote BBCode
                        $message_parser->parse($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, true, 'sig');
                        if (sizeof($message_parser->warn_msg)) {
                            $error[] = implode('<br />', $message_parser->warn_msg);
                        }
                        if (!sizeof($error) && $submit) {
                            $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => (int) $message_parser->bbcode_bitfield);
                        }
                    } else {
                        $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => (int) '');
                    }
                    if (!sizeof($error) && $submit) {
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
                        $_CLASS['core_db']->sql_query($sql);
                        $message = $_CLASS['core_user']->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $module_link . '\\>', '</a>');
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$_CLASS['core_user']->lang['\\1'])) ? \$_CLASS['core_user']->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview && $signature) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_html, $enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $_CLASS['core_user']->data['user_sig_bbcode_uid']);
                $_CLASS['core_template']->assign(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_HTML_CHECKED' => !$enable_html ? 'checked="checked"' : '', 'S_BBCODE_CHECKED' => !$enable_bbcode ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? 'checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? 'checked="checked"' : '', 'HTML_STATUS' => $config['allow_sig_html'] ? $_CLASS['core_user']->lang['HTML_IS_ON'] : $_CLASS['core_user']->lang['HTML_IS_OFF'], 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($_CLASS['core_user']->lang['BBCODE_IS_ON'], '<a href="' . generate_link('Forums&amp;file=faq&amp;mode=bbcode') . '" target="_phpbbcode">', '</a>') : sprintf($_CLASS['core_user']->lang['BBCODE_IS_OFF'], '<a href="' . generate_link('Forums&amp;file=faq&amp;mode=bbcode') . '" target="_phpbbcode">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $_CLASS['core_user']->lang['SMILIES_ARE_ON'] : $_CLASS['core_user']->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $_CLASS['core_user']->lang['IMAGES_ARE_ON'] : $_CLASS['core_user']->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $_CLASS['core_user']->lang['FLASH_IS_ON'] : $_CLASS['core_user']->lang['FLASH_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($_CLASS['core_user']->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_HTML_ALLOWED' => $config['allow_sig_html'], 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies']));
                break;
            case 'avatar':
                $display_gallery = isset($_POST['display_gallery']);
                $folder = isset($_REQUEST['category']) ? str_replace(array('../', '..\\', './', '.\\'), '', $_REQUEST['category']) : false;
                $delete = isset($_POST['delete']);
                // Can we upload?
                $can_upload = file_exists($config['avatar_path']) && is_writeable($config['avatar_path']) && @ini_get('file_uploads') ? true : false;
                if ($submit) {
                    $gallery_avatar = isset($_POST['avatarselect']) ? str_replace(array('../', '..\\', './', '.\\'), '', $_POST['avatarselect']) : false;
                    if ($config['allow_avatar_local'] && $gallery_avatar) {
                        if (!file_exists($config['avatar_gallery_path'] . '/' . $gallery_avatar)) {
                            $error[] = 'BAD_AVATAR';
                        } else {
                            $type = AVATAR_GALLERY;
                            $filename = $gallery_avatar;
                            list($width, $height) = getimagesize($config['avatar_gallery_path'] . '/' . $gallery_avatar);
                        }
                    } else {
                        $data['uploadurl'] = get_variable('uploadurl', 'POST', false);
                        $data['remotelink'] = get_variable('remotelink', 'POST', '');
                        $data['width'] = get_variable('width', 'POST', '');
                        $data['height'] = get_variable('height', 'POST', '');
                        $data['user_id'] = $_CLASS['core_user']->data['user_id'];
                        require_once $site_file_root . 'includes/forums/functions_user.php';
                        if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) {
                            list($type, $filename, $width, $height) = avatar_upload($data, $error);
                        } elseif ($data['remotelink'] && $config['allow_avatar_remote']) {
                            list($type, $filename, $width, $height) = avatar_remote($data, $error);
                        } elseif ($delete) {
                            $type = $filename = $width = $height = '';
                        } else {
                            $error[] = 'IM_LOST';
                        }
                    }
                    if (empty($error)) {
                        $sql_ary = array('user_avatar' => $filename, 'user_avatar_type' => $type, 'user_avatar_width' => $width, 'user_avatar_height' => $height);
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
                        $_CLASS['core_db']->sql_query($sql);
                        // Delete old avatar if present
                        if ($_CLASS['core_user']->data['user_avatar'] && $filename != $_CLASS['core_user']->data['user_avatar'] && $_CLASS['core_user']->data['user_avatar_type'] != AVATAR_GALLERY) {
                            avatar_delete($_CLASS['core_user']->data['user_avatar']);
                        }
                        $_CLASS['core_display']->meta_refresh(3, $module_link);
                        $message = $_CLASS['core_user']->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_UCP'], '<a href="' . $module_link . '">', '</a>');
                        trigger_error($message);
                    }
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$_CLASS['core_user']->lang['\\1'])) ? \$_CLASS['core_user']->lang['\\1'] : '\\1'", $error);
                }
                // Generate users avatar
                $avatar_img = '';
                if ($_CLASS['core_user']->data['user_avatar']) {
                    switch ($_CLASS['core_user']->data['user_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $_CLASS['core_user']->data['user_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $_CLASS['core_user']->data['user_avatar_width'] . '" height="' . $_CLASS['core_user']->data['user_avatar_height'] . '" border="0" alt="" />';
                }
                $_CLASS['core_template']->assign(array('ERROR' => empty($error) ? '' : implode('<br />', $error), 'AVATAR' => $avatar_img, 'AVATAR_SIZE' => $config['avatar_filesize'], 'S_FORM_ENCTYPE' => $can_upload ? ' enctype="multipart/form-data"' : '', 'L_AVATAR_EXPLAIN' => sprintf($_CLASS['core_user']->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                if ($display_gallery && $config['allow_avatar_local']) {
                    require_once $site_file_root . 'includes/functions_user.php';
                    $avatar_list = avatar_gallery($folder, $folders, $error);
                    array_unshift($folders, '');
                    $s_category_options = '';
                    foreach ($folders as $cat) {
                        $s_category_options .= '<option value="' . $cat . '"' . ($cat == $folder ? ' selected="selected"' : '') . '>' . ($cat ? $cat : '--') . '</option>';
                    }
                    $_CLASS['core_template']->assign(array('S_DISPLAY_GALLERY' => true, 'S_CAT_OPTIONS' => $s_category_options));
                    foreach ($avatar_list as $avatar) {
                        $_CLASS['core_template']->assign_vars_array('avatar', array('AVATAR_IMAGE' => $config['avatar_gallery_path'] . '/' . $avatar['file'], 'AVATAR_NAME' => $avatar['name'], 'AVATAR_FILE' => $avatar['file']));
                    }
                    unset($avatar_list);
                } else {
                    $_CLASS['core_template']->assign(array('AVATAR' => $avatar_img, 'AVATAR_SIZE' => $config['avatar_filesize'], 'WIDTH' => $_CLASS['core_user']->data['user_avatar_width'], 'HEIGHT' => $_CLASS['core_user']->data['user_avatar_height'], 'S_CAN_UPLOAD' => $can_upload, 'S_LINK_AVATAR' => $config['allow_avatar_remote'], 'S_GALLERY_AVATAR' => $config['allow_avatar_local']));
                }
                break;
        }
        $_CLASS['core_template']->assign_array(array('L_TITLE' => $_CLASS['core_user']->lang['UCP_PROFILE_' . strtoupper($mode)], 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => $module_link));
        $this->display($_CLASS['core_user']->lang['UCP_PROFILE'], 'ucp_profile_' . $mode . '.html');
    }
/**
* Disapprove Post/Topic
*/
function disapprove_post($post_id_list, $mode)
{
    global $_CLASS, $_CORE_CONFIG, $config;
    $forum_id = request_var('f', 0);
    if (!check_ids($post_id_list, FORUMS_POSTS_TABLE, 'post_id', 'm_approve')) {
        trigger_error('NOT_AUTHORIZED');
    }
    $redirect = request_var('redirect', $_CLASS['core_user']->data['session_page']);
    $reason = request_var('reason', '', true);
    $reason_id = request_var('reason_id', 0);
    $success_msg = $additional_msg = '';
    $s_hidden_fields = build_hidden_fields(array('i' => 'queue', 'f' => $forum_id, 'mode' => $mode, 'post_id_list' => $post_id_list, 'mode' => 'disapprove', 'redirect' => $redirect));
    $notify_poster = isset($_REQUEST['notify_poster']);
    $disapprove_reason = '';
    if ($reason_id) {
        $sql = 'SELECT reason_title, reason_description
			FROM ' . FORUMS_REPORTS_REASONS_TABLE . " \n\t\t\tWHERE reason_id = {$reason_id}";
        $result = $_CLASS['core_db']->query($sql);
        $row = $_CLASS['core_db']->fetch_row_assoc($result);
        $_CLASS['core_db']->free_result($result);
        if (!$row || !$reason && $row['reason_name'] === 'other') {
            $additional_msg = $_CLASS['core_user']->lang['NO_REASON_DISAPPROVAL'];
            unset($_POST['confirm']);
        } else {
            $disapprove_reason = $row['reason_title'] != 'other' ? isset($_CLASS['core_user']->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]) ? $_CLASS['core_user']->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])] : $row['reason_description'] : '';
            $disapprove_reason .= $reason ? "\n\n" . $reason : '';
            unset($reason);
        }
    }
    require_once SITE_FILE_ROOT . 'includes/forums/functions_display.php';
    $reason = display_reasons($reason_id);
    $_CLASS['core_template']->assign_array(array('S_NOTIFY_POSTER' => true, 'S_APPROVE' => false, 'REASON' => $reason, 'ADDITIONAL_MSG' => $additional_msg));
    if (display_confirmation($_CLASS['core_user']->get_lang('DISAPPROVE_POST' . (sizeof($post_id_list) == 1 ? '' : 'S')), $s_hidden_fields, 'modules/forums/mcp_approve.html')) {
        $post_info = get_post_data($post_id_list, 'm_approve');
        // If Topic -> forum_topics_real -= 1
        // If Post -> topic_replies_real -= 1
        $forum_topics_real = 0;
        $topic_replies_real_sql = $post_disapprove_sql = $topic_id_list = array();
        foreach ($post_info as $post_id => $post_data) {
            $topic_id_list[$post_data['topic_id']] = 1;
            // Topic or Post. ;)
            if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id) {
                if ($post_data['forum_id']) {
                    $forum_topics_real++;
                }
            } else {
                if (!isset($topic_replies_real_sql[$post_data['topic_id']])) {
                    $topic_replies_real_sql[$post_data['topic_id']] = 1;
                } else {
                    $topic_replies_real_sql[$post_data['topic_id']]++;
                }
            }
            $post_disapprove_sql[] = $post_id;
        }
        if ($forum_topics_real) {
            $sql = 'UPDATE ' . FORUMS_FORUMS_TABLE . "\n\t\t\t\tSET forum_topics_real = forum_topics_real - {$forum_topics_real}\n\t\t\t\tWHERE forum_id = {$forum_id}";
            $_CLASS['core_db']->query($sql);
        }
        if (!empty($topic_replies_real_sql)) {
            foreach ($topic_replies_real_sql as $topic_id => $num_replies) {
                $sql = 'UPDATE ' . FORUMS_TOPICS_TABLE . "\n\t\t\t\t\tSET topic_replies_real = topic_replies_real - {$num_replies}\n\t\t\t\t\tWHERE topic_id = {$topic_id}";
                $_CLASS['core_db']->query($sql);
            }
        }
        if (sizeof($post_disapprove_sql)) {
            if (!function_exists('delete_posts')) {
                require_once SITE_FILE_ROOT . 'includes/forums/functions_admin.php';
            }
            // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
            delete_posts('post_id', $post_disapprove_sql);
        }
        unset($post_disapprove_sql, $topic_replies_real_sql);
        update_post_information('topic', array_keys($topic_id_list));
        update_post_information('forum', $forum_id);
        unset($topic_id_list);
        // Notify Poster?
        if ($notify_poster) {
            require_once SITE_FILE_ROOT . 'includes/mailer.php';
            $mailer = new core_mailer();
            foreach ($post_info as $post_id => $post_data) {
                if ($post_data['poster_id'] == ANONYMOUS) {
                    continue;
                }
                $post_data['post_subject'] = censor_text($post_data['post_subject'], true);
                $post_data['topic_title'] = censor_text($post_data['topic_title'], true);
                if ($post_data['post_id'] == $post_data['topic_first_post_id'] && $post_data['post_id'] == $post_data['topic_last_post_id']) {
                    $email_template = 'topic_disapproved.txt';
                    $subject = 'Topic Disapproved - ' . $post_data['topic_title'];
                } else {
                    $email_template = 'post_disapproved.txt';
                    $subject = 'Post Disapproved - ' . $post_data['post_subject'];
                }
                $mailer->to($post_data['user_email'], $post_data['username']);
                //$mailer->reply_to($_CORE_CONFIG['email']['site_email']);
                $mailer->subject($subject);
                //$messenger->im($post_data['user_jabber'], $post_data['username']);
                $_CLASS['core_template']->assign_array(array('SITENAME' => $_CORE_CONFIG['global']['site_name'], 'USERNAME' => $post_data['username'], 'REASON' => stripslashes($disapprove_reason), 'POST_SUBJECT' => $post_data['post_subject'], 'TOPIC_TITLE' => $post_data['topic_title']));
                $mailer->message = trim($_CLASS['core_template']->display('email/forums/' . $email_template, true));
                $mailer->send();
            }
        }
        unset($post_info, $disapprove_reason);
        if ($forum_topics_real) {
            $success_msg = $forum_topics_real == 1 ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
        } else {
            $success_msg = sizeof($post_id_list) == 1 ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
        }
    }
    $redirect = request_var('redirect', generate_link('forums'));
    if (!$success_msg) {
        redirect($redirect);
    } else {
        $_CLASS['core_display']->meta_refresh(3, generate_link("forums&amp;file=viewforum&amp;f={$forum_id}"));
        trigger_error($_CLASS['core_user']->lang[$success_msg] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link('forums&amp;file=viewforum&amp;f=' . $forum_id) . '">', '</a>'));
    }
}