示例#1
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $this->page_title = 'ACP_USER_' . strtoupper($mode);
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
        $error = array();
        $username = request_var('username', '', true);
        $user_id = request_var('u', 0);
        $action = request_var('action', '');
        $submit = isset($_POST['update']) ? true : false;
        // Whois (special case)
        if ($action == 'whois') {
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = request_var('user_ip', '');
            $domain = gethostbyaddr($user_ip);
            $ipwhois = '';
            if ($ipwhois = user_ipwhois($user_ip)) {
                $ipwhois = preg_replace('#(\\s)([\\w\\-\\._\\+]+@[\\w\\-\\.]+)(\\s)#', '\\1<a href="mailto:\\2">\\2</a>\\3', $ipwhois);
                $ipwhois = preg_replace('#(\\s)(http:/{2}[^\\s]*)(\\s)#', '\\1<a href="\\2" target="_blank">\\2</a>\\3', $ipwhois);
            }
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=select_user&amp;field=username')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username = '******'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query($sql);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Include info file...
        include_once $phpbb_root_path . 'includes/acp/info/acp_users.' . $phpEx;
        $forms_ary = acp_users_info::module();
        foreach ($forms_ary['modes'] as $value => $ary) {
            if (!$this->is_authed($ary['auth'])) {
                continue;
            }
            $selected = $mode == $value ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($value)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action));
        }
        switch ($mode) {
            case 'overview':
                $delete = request_var('delete', 0);
                $delete_type = request_var('delete_type', '');
                $ip = request_var('ip', 'ip');
                if ($submit) {
                    // You can't delete the founder
                    if ($delete && $user_row['user_type'] != USER_FOUNDER) {
                        if (!$auth->acl_get('a_userdel')) {
                            trigger_error($user->lang['NO_ADMIN'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        // Check if the user wants to remove himself or the guest user account
                        if ($user_id == ANONYMOUS) {
                            trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if (confirm_box(true)) {
                            user_delete($delete_type, $user_id);
                            add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
                            trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type)));
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    $log = 'LOG_USER_BAN_USER';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    $log = 'LOG_USER_BAN_EMAIL';
                                    break;
                                case 'banip':
                                    $ban[] = $user_row['user_ip'];
                                    $sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}";
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $ban[] = $row['poster_ip'];
                                    }
                                    $db->sql_freeresult($result);
                                    $reason = 'USER_ADMIN_BAN_IP_REASON';
                                    $log = 'LOG_USER_BAN_IP';
                                    break;
                            }
                            user_ban(substr($action, 3), $ban, 0, 0, 0, $user->lang[$reason]);
                            add_log('admin', $log, $user->lang[$reason]);
                            add_log('user', $user_id, $log, $user->lang[$reason]);
                            trigger_error($user->lang['BAN_SUCCESSFUL'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($config['email_enable']) {
                                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(10);
                                $key_len = 54 - strlen($server_url);
                                $key_len = $key_len > 6 ? $key_len : 6;
                                $user_actkey = substr($user_actkey, 0, $key_len);
                                if ($user_row['user_type'] != USER_INACTIVE) {
                                    user_active_flip($user_id, $user_row['user_type'], $user_actkey, $user_row['username']);
                                }
                                $messenger = new messenger(false);
                                $messenger->template('user_resend_inactive', $user_row['user_lang']);
                                $messenger->replyto($config['board_contact']);
                                $messenger->to($user_row['user_email'], $user_row['username']);
                                $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                                $messenger->assign_vars(array('SITENAME' => $config['sitename'], 'WELCOME_MSG' => sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), 'USERNAME' => html_entity_decode($user_row['username']), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
                                add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            user_active_flip($user_id, $user_row['user_type'], false, $user_row['username']);
                            $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
                            $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
                            add_log('user', $user_id, $log . '_USER');
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                set_config('num_users', $config['num_users'] + 1, true);
                            } else {
                                set_config('num_users', $config['num_users'] - 1, true);
                            }
                            // Update latest username
                            update_last_username();
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            $sql_ary = array('user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                            add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
									FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tGROUP BY topic_id";
                                $result = $db->sql_query($sql);
                                $topic_id_ary = array();
                                while ($row = $db->sql_fetchrow($result)) {
                                    $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                                }
                                $db->sql_freeresult($result);
                                if (sizeof($topic_id_ary)) {
                                    $sql = 'SELECT topic_id, topic_replies, topic_replies_real
										FROM ' . TOPICS_TABLE . '
										WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                    $result = $db->sql_query($sql);
                                    $del_topic_ary = array();
                                    while ($row = $db->sql_fetchrow($result)) {
                                        if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                            $del_topic_ary[] = $row['topic_id'];
                                        }
                                    }
                                    $db->sql_freeresult($result);
                                    if (sizeof($del_topic_ary)) {
                                        $sql = 'DELETE FROM ' . TOPICS_TABLE . '
											WHERE topic_id IN (' . implode(', ', $del_topic_ary) . ')';
                                        $db->sql_query($sql);
                                    }
                                }
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'delattach':
                            if (confirm_box(true)) {
                                delete_attachments('user', $user_id);
                                add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'moveposts':
                            $new_forum_id = request_var('new_f', 0);
                            if (!$new_forum_id) {
                                $this->page_title = 'USER_ADMIN_MOVE_POSTS';
                                $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)));
                                return;
                            }
                            // Two stage?
                            // Move topics comprising only posts from this user
                            $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
                            $forum_id_ary = array($new_forum_id);
                            $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real
									FROM ' . TOPICS_TABLE . '
									WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                        $move_topic_ary[] = $row['topic_id'];
                                    } else {
                                        $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
                                        $move_post_ary[$row['topic_id']]['attach'] = $row['attach'] ? 1 : 0;
                                    }
                                    $forum_id_ary[] = $row['forum_id'];
                                }
                                $db->sql_freeresult($result);
                            }
                            // Entire topic comprises posts by this user, move these topics
                            if (sizeof($move_topic_ary)) {
                                move_topics($move_topic_ary, $new_forum_id, false);
                            }
                            if (sizeof($move_post_ary)) {
                                // Create new topic
                                // Update post_ids, report_ids, attachment_ids
                                foreach ($move_post_ary as $topic_id => $post_ary) {
                                    // Create new topic
                                    $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_approved' => 1, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach']));
                                    $db->sql_query($sql);
                                    $new_topic_id = $db->sql_nextid();
                                    // Move posts
                                    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                    $db->sql_query($sql);
                                    if ($post_ary['attach']) {
                                        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                        $db->sql_query($sql);
                                    }
                                    $new_topic_id_ary[] = $new_topic_id;
                                }
                            }
                            $forum_id_ary = array_unique($forum_id_ary);
                            $topic_id_ary = array_unique(array_merge($topic_id_ary, $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('reported', 'topic_id', $topic_id_ary);
                                sync('topic', 'topic_id', $topic_id_ary);
                            }
                            if (sizeof($forum_id_ary)) {
                                sync('forum', 'forum_id', $forum_id_ary);
                            }
                            $sql = 'SELECT forum_name
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql, 3600);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
                            add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                    }
                    $data = array();
                    // Handle registration info updates
                    $var_ary = array('user' => (string) $user_row['username'], 'user_founder' => (int) ($user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'user_email' => (string) $user_row['user_email'], 'email_confirm' => (string) '', 'user_password' => (string) '', 'password_confirm' => (string) '', 'warnings' => (int) $user_row['user_warnings']);
                    // Get the data from the form. Use data from the database if no info is provided
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    // We use user within the form to circumvent auto filling
                    $data['username'] = $data['user'];
                    unset($data['user']);
                    // Validation data
                    $var_ary = array('password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'user_password' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'warnings' => array('num'));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $var_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username'])));
                    }
                    // Check email if altered
                    if ($data['user_email'] != $user_row['user_email']) {
                        $var_ary += array('user_email' => array(array('string', false, 6, 60), array('email', $user_row['user_email'])), 'email_confirm' => array('string', true, 6, 60));
                    }
                    $error = validate_data($data, $var_ary);
                    if ($data['user_password'] && $data['password_confirm'] != $data['user_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if ($data['user_email'] != $user_row['user_email'] && $data['email_confirm'] != $data['user_email']) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    // Which updates do we need to do?
                    $update_warning = $user_row['user_warnings'] != $data['warnings'] ? true : false;
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['user_password'] && $user_row['user_password'] != md5($data['user_password']) ? true : false;
                    $update_email = $data['user_email'] != $user_row['user_email'] ? $data['user_email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            if ($update_warning) {
                                $sql_ary['user_warnings'] = $data['warnings'];
                            }
                            if ($user_row['user_type'] == USER_FOUNDER && !$data['user_founder'] || $user_row['user_type'] != USER_FOUNDER && $data['user_founder']) {
                                $sql_ary['user_type'] = $data['user_founder'] ? USER_FOUNDER : USER_NORMAL;
                            }
                        }
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => crc32(strtolower($update_email)) . strlen($update_email));
                            add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => md5($data['user_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                        }
                        /**
                         * @todo adjust every data based in the number of user warnings
                         */
                        if ($update_warning) {
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
                $quick_tool_ary = array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP', 'active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE', 'delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
                if ($config['email_enable']) {
                    $quick_tool_ary['reactivate'] = 'FORCE';
                }
                $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
                foreach ($quick_tool_ary as $value => $lang) {
                    $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
                }
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$user_char_ary[$config['allow_name_chars']] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang['CHANGE_PASSWORD_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'U_SHOW_IP' => $this->u_action . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}", 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&amp;u={$user_row['user_id']}") : '', 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $user_row['user_lastvisit'] ? $user->format_date($user_row['user_lastvisit']) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings']));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = request_var('mark', array(0));
                $message = request_var('message', '', true);
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND log_id IN (' . implode(', ', $sql_in) . ')';
                        unset($sql_in);
                    }
                    if ($where_sql || $deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
                    }
                }
                if ($submit && $message) {
                    add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
                    add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                // Sorting
                $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $template->assign_vars(array('S_FEEDBACK' => true, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
                foreach ($log_data as $row) {
                    $template->assign_block_vars('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'profile':
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                $data = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user_row['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                if ($submit) {
                    $var_ary = array('icq' => (string) '', 'aim' => (string) '', 'msn' => (string) '', 'yim' => (string) '', 'jabber' => (string) '', 'website' => (string) '', 'location' => (string) '', 'occupation' => (string) '', 'interests' => (string) '', 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = in_array($var, array('location', 'occupation', 'interests')) ? request_var($var, $default, true) : ($data[$var] = request_var($var, $default));
                    }
                    $var_ary = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 17), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('match', true, '#^[a-z0-9\\.\\-_\\+]+?@(.*?\\.)*?[a-z0-9\\-_]+?\\.[a-z]{2,4}(/.*)?$#i')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 255), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())));
                    $error = validate_data($data, $var_ary);
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_birthday' => sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']));
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Update Custom Fields
                        if (sizeof($cp_data)) {
                            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            if (!$db->sql_affectedrows()) {
                                $cp_data['user_id'] = (int) $user_id;
                                $db->return_on_error = true;
                                $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
                                $db->sql_query($sql);
                                $db->return_on_error = false;
                            }
                        }
                        trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!isset($data['bday_day'])) {
                    if ($user_row['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                    } else {
                        $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    }
                }
                $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_year_options = '';
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i < $now['year']; $i++) {
                    $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('ICQ' => isset($data['icq']) ? $data['icq'] : $user_row['user_icq'], 'YIM' => isset($data['yim']) ? $data['yim'] : $user_row['user_yim'], 'AIM' => isset($data['aim']) ? $data['aim'] : $user_row['user_aim'], 'MSN' => isset($data['msn']) ? $data['msn'] : $user_row['user_msnm'], 'JABBER' => isset($data['jabber']) ? $data['jabber'] : $user_row['user_jabber'], 'WEBSITE' => isset($data['website']) ? $data['website'] : $user_row['user_website'], 'LOCATION' => isset($data['location']) ? $data['location'] : $user_row['user_from'], 'OCCUPATION' => isset($data['occupation']) ? $data['occupation'] : $user_row['user_occ'], 'INTERESTS' => isset($data['interests']) ? $data['interests'] : $user_row['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, 'S_PROFILE' => true));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user_id);
                $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
                break;
            case 'prefs':
                $data = array();
                if ($submit) {
                    $var_ary = array('dateformat' => (string) $config['default_dateformat'], 'lang' => (string) $config['default_lang'], 'tz' => (double) $config['board_timezone'], 'style' => (int) $config['default_style'], 'dst' => (bool) $config['board_dst'], 'viewemail' => false, 'massemail' => true, 'hideonline' => false, 'notifymethod' => 0, 'notifypm' => true, 'popuppm' => false, 'allowpm' => true, 'topic_sk' => (string) 't', 'topic_sd' => (string) 'd', 'topic_st' => 0, 'post_sk' => (string) 't', 'post_sd' => (string) 'a', 'post_st' => 0, 'view_images' => true, 'view_flash' => false, 'view_smilies' => true, 'view_sigs' => true, 'view_avatars' => true, 'view_wordcensor' => false, 'bbcode' => true, 'smilies' => true, 'sig' => true, 'notify' => false);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('dateformat' => array('string', false, 3, 30), 'lang' => array('match', false, '#^[a-z_]{2,}$#i'), 'tz' => array('num', false, -14, 14), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'popuppm', $data['popuppm']);
                        $this->optionset($user_row, 'viewimg', $data['view_images']);
                        $this->optionset($user_row, 'viewflash', $data['view_flash']);
                        $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
                        $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
                        $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
                        $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
                        $this->optionset($user_row, 'bbcode', $data['bbcode']);
                        $this->optionset($user_row, 'smilies', $data['smilies']);
                        $this->optionset($user_row, 'attachsig', $data['sig']);
                        $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $notify_method = isset($data['notifymethod']) ? $data['notifymethod'] : $user_row['user_notify_type'];
                $dateformat = isset($data['dateformat']) ? $data['dateformat'] : $user_row['user_dateformat'];
                $lang = isset($data['lang']) ? $data['lang'] : $user_row['user_lang'];
                $style = isset($data['style']) ? $data['style'] : $user_row['user_style'];
                $tz = isset($data['tz']) ? $data['tz'] : $user_row['user_timezone'];
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $dateformat ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, true) . (strpos($format, '|') !== false ? ' [' . $user->lang['RELATIVE_DAYS'] . ']' : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!in_array($dateformat, array_keys($user->lang['dateformats']))) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $topic_sk = isset($data['topic_sk']) ? $data['topic_sk'] : ($user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't');
                $post_sk = isset($data['post_sk']) ? $data['post_sk'] : ($user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't');
                $topic_sd = isset($data['topic_sd']) ? $data['topic_sd'] : ($user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd');
                $post_sd = isset($data['post_sd']) ? $data['post_sd'] : ($user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'd');
                $topic_st = isset($data['topic_st']) ? $data['topic_st'] : ($user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0);
                $post_st = isset($data['post_st']) ? $data['post_st'] : ($user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0);
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                // Topic ordering options
                $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
                // Post ordering options
                $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
                $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
                $_options = array('topic', 'post');
                foreach ($_options as $sort_option) {
                    ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
                    foreach (${'limit_' . $sort_option . '_days'} as $day => $text) {
                        $selected = ${$sort_option . '_st'} == $day ? ' selected="selected"' : '';
                        ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_limit_' . $sort_option . '_days'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
                    foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) {
                        $selected = ${$sort_option . '_sk'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_key'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
                    foreach ($sort_dir_text as $key => $value) {
                        $selected = ${$sort_option . '_sd'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                $template->assign_vars(array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => isset($data['viewemail']) ? $data['viewemail'] : $user_row['user_allow_viewemail'], 'MASS_EMAIL' => isset($data['massemail']) ? $data['massemail'] : $user_row['user_allow_massemail'], 'ALLOW_PM' => isset($data['allowpm']) ? $data['allowpm'] : $user_row['user_allow_pm'], 'HIDE_ONLINE' => isset($data['hideonline']) ? $data['hideonline'] : !$user_row['user_allow_viewonline'], 'NOTIFY_EMAIL' => $notify_method == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $notify_method == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $notify_method == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => isset($data['notifypm']) ? $data['notifypm'] : $user_row['user_notify_pm'], 'POPUP_PM' => isset($data['popuppm']) ? $data['popuppm'] : $this->optionget($user_row, 'popuppm'), 'DST' => isset($data['dst']) ? $data['dst'] : $user_row['user_dst'], 'BBCODE' => isset($data['bbcode']) ? $data['bbcode'] : $this->optionget($user_row, 'bbcode'), 'SMILIES' => isset($data['smilies']) ? $data['smilies'] : $this->optionget($user_row, 'smilies'), 'ATTACH_SIG' => isset($data['sig']) ? $data['sig'] : $this->optionget($user_row, 'attachsig'), 'NOTIFY' => isset($data['notify']) ? $data['notify'] : $user_row['user_notify'], 'VIEW_IMAGES' => isset($data['view_images']) ? $data['view_images'] : $this->optionget($user_row, 'viewimg'), 'VIEW_FLASH' => isset($data['view_flash']) ? $data['view_flash'] : $this->optionget($user_row, 'viewflash'), 'VIEW_SMILIES' => isset($data['view_smilies']) ? $data['view_smilies'] : $this->optionget($user_row, 'viewsmilies'), 'VIEW_SIGS' => isset($data['view_sigs']) ? $data['view_sigs'] : $this->optionget($user_row, 'viewsigs'), 'VIEW_AVATARS' => isset($data['view_avatars']) ? $data['view_avatars'] : $this->optionget($user_row, 'viewavatars'), 'VIEW_WORDCENSOR' => isset($data['view_wordcensor']) ? $data['view_wordcensor'] : $this->optionget($user_row, 'viewcensors'), 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $dateformat, 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($lang), 'S_STYLE_OPTIONS' => style_select($style), 'S_TZ_OPTIONS' => tz_select($tz)));
                break;
            case 'avatar':
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
                $data = array();
                if ($submit) {
                    $delete = request_var('delete', '');
                    $var_ary = array('uploadurl' => (string) '', 'remotelink' => (string) '', 'width' => (string) '', 'height' => (string) '');
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $data['user_id'] = $user_id;
                        if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload && $config['allow_avatar_upload']) {
                            list($type, $filename, $width, $height) = avatar_upload($data, $error);
                        } else {
                            if ($data['remotelink'] && $config['allow_avatar_remote']) {
                                list($type, $filename, $width, $height) = avatar_remote($data, $error);
                            } else {
                                if ($avatar_select && $config['allow_avatar_local']) {
                                    $type = AVATAR_GALLERY;
                                    $filename = $avatar_select;
                                    // check avatar gallery
                                    if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                        $type = $width = $height = 0;
                                        $filename = '';
                                    } else {
                                        list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $filename);
                                        $filename = $category . '/' . $filename;
                                    }
                                } else {
                                    if ($delete) {
                                        $filename = '';
                                        $type = $width = $height = 0;
                                    } else {
                                        $data = array();
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        // Do we actually have any data to update?
                        if (sizeof($data)) {
                            $sql_ary = array('user_avatar' => $filename, 'user_avatar_type' => $type, 'user_avatar_width' => $width, 'user_avatar_height' => $height);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $filename != $user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                        }
                        trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                // Generate users avatar
                if ($user_row['user_avatar']) {
                    $avatar_img = '';
                    switch ($user_row['user_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $user_row['user_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $user_row['user_avatar_width'] . '" height="' . $user_row['user_avatar_height'] . '" alt="" />';
                } else {
                    $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                }
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $template->assign_vars(array('S_AVATAR' => true, 'S_CAN_UPLOAD' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_ALLOW_REMOTE' => $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                break;
            case 'rank':
                if ($submit) {
                    $rank_id = request_var('user_rank', 0);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                    $db->sql_query($sql);
                    trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                $sql = 'SELECT * 
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : '';
                    $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options));
                break;
            case 'sig':
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('enable_bbcode', $this->optionget($user_row, 'bbcode')) : false;
                $enable_smilies = $config['allow_sig_smilies'] ? request_var('enable_smilies', $this->optionget($user_row, 'smilies')) : false;
                $enable_urls = request_var('enable_urls', true);
                $signature = request_var('signature', $user_row['user_sig'], true);
                $preview = isset($_POST['preview']) ? true : false;
                if ($submit || $preview) {
                    include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $message_parser = new parse_message($signature);
                    // Allowing Quote BBCode
                    $message_parser->parse($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);
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $user_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user_row['user_sig_bbcode_uid']);
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? 'checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? 'checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies']));
                break;
            case 'attach':
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = request_var('mark', array(0));
                // Sort keys
                $sort_key = request_var('sk', 'a');
                $sort_dir = request_var('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE attach_id IN (' . implode(', ', $marked) . ')';
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        delete_attachments('attach', $marked);
                        $log = sizeof($log_attachments) == 1 ? 'ATTACHMENT_DELETED' : 'ATTACHMENTS_DELETED';
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        add_log('admin', $log, implode(', ', $log_attachments));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'deletemark' => true, 'mark' => $marked)));
                    }
                }
                $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
                $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
                $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                $s_sort_key = '';
                foreach ($sk_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sd_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $order_by = $sk_sql[$sort_key] . '  ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                $sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}";
                $result = $db->sql_query_limit($sql, 1);
                $num_attachments = (int) $db->sql_fetchfield('num_attachments');
                $db->sql_freeresult($result);
                $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a 
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}#{$row['post_msg_id']}");
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['comment']), 'EXTENSION' => $row['extension'], 'SIZE' => $row['filesize'] >= 1048576 ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : ($row['filesize'] >= 1024 ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download.{$phpEx}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&amp;sk={$sort_key}&amp;sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true)));
                break;
            case 'groups':
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = request_var('g', 0);
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        group_user_attributes($action, $group_id, $user_id);
                        if ($action == 'default') {
                            $user_row['group_id'] = $group_id;
                        }
                        break;
                    case 'delete':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            $error = array();
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                }
                // Add user to group?
                if ($submit) {
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Add user/s to group
                    if ($error = group_user_add($group_id, $user_id)) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    $error = array();
                }
                $sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
                $result = $db->sql_query($sql);
                $i = 0;
                $group_data = $id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal');
                    $group_data[$type][$i]['group_id'] = $row['group_id'];
                    $group_data[$type][$i]['group_name'] = $row['group_name'];
                    $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0;
                    $id_ary[] = $row['group_id'];
                    $i++;
                }
                $db->sql_freeresult($result);
                // Select box for other groups
                $sql = 'SELECT group_id, group_name, group_type
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE group_id NOT IN (' . implode(', ', $id_ary) . ')' : '') . '
					ORDER BY group_type DESC, group_name ASC';
                $result = $db->sql_query($sql);
                $s_group_options = '';
                while ($row = $db->sql_fetchrow($result)) {
                    if ($config['coppa_hide_groups'] && in_array($row['group_name'], array('INACTIVE_COPPA', 'REGISTERED_COPPA'))) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
                }
                $db->sql_freeresult($result);
                $current_type = '';
                foreach ($group_data as $group_type => $data_ary) {
                    if ($current_type != $group_type) {
                        $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]));
                    }
                    foreach ($data_ary as $data) {
                        $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false));
                    }
                }
                $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options));
                break;
            case 'perm':
                include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                $user->add_lang('acp/permissions_phpbb');
                // Select auth options
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_global = 1\n\t\t\t\t\tORDER BY auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\tORDER BY is_global DESC, auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'local', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id)));
                break;
        }
        // Assign general variables
        $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
    }
示例#2
0
文件: ucp_groups.php 项目: html/PI
    function main($id, $mode)
    {
        global $config, $phpbb_root_path, $phpEx;
        global $db, $user, $auth, $cache, $template;
        $user->add_lang('groups');
        $return_page = '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '">', '</a>');
        $mark_ary = request_var('mark', array(0));
        $submit = !empty($_POST['submit']) ? true : false;
        $delete = !empty($_POST['delete']) ? true : false;
        $error = $data = array();
        switch ($mode) {
            case 'membership':
                $this->page_title = 'UCP_USERGROUPS_MEMBER';
                if ($submit || isset($_POST['change_default'])) {
                    $action = isset($_POST['change_default']) ? 'change_default' : request_var('action', '');
                    $group_id = $action == 'change_default' ? request_var('default', 0) : request_var('selected', 0);
                    if (!$group_id) {
                        trigger_error('NO_GROUP_SELECTED');
                    }
                    $sql = 'SELECT group_id, group_name, group_type
						FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id IN ({$group_id}, {$user->data['group_id']})";
                    $result = $db->sql_query($sql);
                    $group_row = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $row['group_name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
                        $group_row[$row['group_id']] = $row;
                    }
                    $db->sql_freeresult($result);
                    if (!sizeof($group_row)) {
                        trigger_error('GROUP_NOT_EXIST');
                    }
                    switch ($action) {
                        case 'change_default':
                            // User already having this group set as default?
                            if ($group_id == $user->data['group_id']) {
                                trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page);
                            }
                            if (!$auth->acl_get('u_chggrp')) {
                                trigger_error($user->lang['NOT_AUTHORISED'] . $return_page);
                            }
                            // User needs to be member of the group in order to make it default
                            if (!group_memberships($group_id, $user->data['user_id'], true)) {
                                trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                            }
                            if (confirm_box(true)) {
                                group_user_attributes('default', $group_id, $user->data['user_id']);
                                add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_CHANGE', sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name']));
                                meta_refresh(3, $this->u_action);
                                trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page);
                            } else {
                                $s_hidden_fields = array('default' => $group_id, 'change_default' => true);
                                confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields));
                            }
                            break;
                        case 'resign':
                            // User tries to resign from default group but is not allowed to change it?
                            if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp')) {
                                trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page);
                            }
                            if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                                trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                            }
                            list(, $row) = each($row);
                            $sql = 'SELECT group_type
								FROM ' . GROUPS_TABLE . '
								WHERE group_id = ' . $group_id;
                            $result = $db->sql_query($sql);
                            $group_type = (int) $db->sql_fetchfield('group_type');
                            $db->sql_freeresult($result);
                            if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE) {
                                trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page);
                            }
                            if (confirm_box(true)) {
                                group_user_del($group_id, $user->data['user_id']);
                                add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_RESIGN', $group_row[$group_id]['group_name']);
                                meta_refresh(3, $this->u_action);
                                trigger_error($user->lang[$row['user_pending'] ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page);
                            } else {
                                $s_hidden_fields = array('selected' => $group_id, 'action' => 'resign', 'submit' => true);
                                confirm_box(false, $row['user_pending'] ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields));
                            }
                            break;
                        case 'join':
                            $sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email
								FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
								WHERE ug.user_id = u.user_id
									AND ug.group_id = ' . $group_id . '
									AND ug.user_id = ' . $user->data['user_id'];
                            $result = $db->sql_query($sql);
                            $row = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            if ($row) {
                                if ($row['user_pending']) {
                                    trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page);
                                }
                                trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page);
                            }
                            // Check permission to join (open group or request)
                            if ($group_row[$group_id]['group_type'] != GROUP_OPEN && $group_row[$group_id]['group_type'] != GROUP_FREE) {
                                trigger_error($user->lang['CANNOT_JOIN_GROUP'] . $return_page);
                            }
                            if (confirm_box(true)) {
                                if ($group_row[$group_id]['group_type'] == GROUP_FREE) {
                                    group_user_add($group_id, $user->data['user_id']);
                                    $email_template = 'group_added';
                                } else {
                                    group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1);
                                    $email_template = 'group_request';
                                }
                                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                $messenger = new messenger();
                                $sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang
									FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
									WHERE ug.user_id = u.user_id
										AND ' . ($group_row[$group_id]['group_type'] == GROUP_FREE ? "ug.user_id = {$user->data['user_id']}" : 'ug.group_leader = 1') . "\n\t\t\t\t\t\t\t\t\t\tAND ug.group_id = {$group_id}";
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    $messenger->template($email_template, $row['user_lang']);
                                    $messenger->to($row['user_email'], $row['username']);
                                    $messenger->im($row['user_jabber'], $row['username']);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($row['username']), 'GROUP_NAME' => htmlspecialchars_decode($group_row[$group_id]['group_name']), 'REQUEST_USERNAME' => $user->data['username'], 'U_PENDING' => generate_board_url() . "/ucp.{$phpEx}?i=groups&mode=manage&action=list&g={$group_id}", 'U_GROUP' => generate_board_url() . "/memberlist.{$phpEx}?mode=group&g={$group_id}"));
                                    $messenger->send($row['user_notify_type']);
                                }
                                $db->sql_freeresult($result);
                                $messenger->save_queue();
                                add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . ($group_row[$group_id]['group_type'] == GROUP_FREE ? '' : '_PENDING'), $group_row[$group_id]['group_name']);
                                meta_refresh(3, $this->u_action);
                                trigger_error($user->lang[$group_row[$group_id]['group_type'] == GROUP_FREE ? 'GROUP_JOINED' : 'GROUP_JOINED_PENDING'] . $return_page);
                            } else {
                                $s_hidden_fields = array('selected' => $group_id, 'action' => 'join', 'submit' => true);
                                confirm_box(false, $group_row[$group_id]['group_type'] == GROUP_FREE ? 'GROUP_JOIN' : 'GROUP_JOIN_PENDING', build_hidden_fields($s_hidden_fields));
                            }
                            break;
                        case 'demote':
                            if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                                trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                            }
                            list(, $row) = each($row);
                            if (!$row['group_leader']) {
                                trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                            }
                            if (confirm_box(true)) {
                                group_user_attributes('demote', $group_id, $user->data['user_id']);
                                add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_DEMOTE', $group_row[$group_id]['group_name']);
                                meta_refresh(3, $this->u_action);
                                trigger_error($user->lang['USER_GROUP_DEMOTED'] . $return_page);
                            } else {
                                $s_hidden_fields = array('selected' => $group_id, 'action' => 'demote', 'submit' => true);
                                confirm_box(false, 'USER_GROUP_DEMOTE', build_hidden_fields($s_hidden_fields));
                            }
                            break;
                    }
                }
                $sql = 'SELECT g.*, ug.group_leader, ug.user_pending
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
					WHERE ug.user_id = ' . $user->data['user_id'] . '
						AND g.group_id = ug.group_id
					ORDER BY g.group_type DESC, g.group_name';
                $result = $db->sql_query($sql);
                $group_id_ary = array();
                $leader_count = $member_count = $pending_count = 0;
                while ($row = $db->sql_fetchrow($result)) {
                    $block = $row['group_leader'] ? 'leader' : ($row['user_pending'] ? 'pending' : 'member');
                    switch ($row['group_type']) {
                        case GROUP_OPEN:
                            $group_status = 'OPEN';
                            break;
                        case GROUP_CLOSED:
                            $group_status = 'CLOSED';
                            break;
                        case GROUP_HIDDEN:
                            $group_status = 'HIDDEN';
                            break;
                        case GROUP_SPECIAL:
                            $group_status = 'SPECIAL';
                            break;
                        case GROUP_FREE:
                            $group_status = 'FREE';
                            break;
                    }
                    $template->assign_block_vars($block, array('GROUP_ID' => $row['group_id'], 'GROUP_NAME' => $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_DESC' => $row['group_type'] != GROUP_SPECIAL ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'], 'GROUP_SPECIAL' => $row['group_type'] != GROUP_SPECIAL ? false : true, 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status], 'GROUP_COLOUR' => $row['group_colour'], 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&amp;g=' . $row['group_id']), 'S_GROUP_DEFAULT' => $row['group_id'] == $user->data['group_id'] ? true : false, 'S_ROW_COUNT' => ${$block . '_count'}++));
                    $group_id_ary[] = (int) $row['group_id'];
                }
                $db->sql_freeresult($result);
                // Hide hidden groups unless user is an admin with group privileges
                $sql_and = $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? '<> ' . GROUP_SPECIAL : 'NOT IN (' . GROUP_SPECIAL . ', ' . GROUP_HIDDEN . ')';
                $sql = 'SELECT group_id, group_name, group_colour, group_desc, group_desc_uid, group_desc_bitfield, group_desc_options, group_type, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					WHERE ' . (sizeof($group_id_ary) ? $db->sql_in_set('group_id', $group_id_ary, true) . ' AND ' : '') . "\n\t\t\t\t\t\tgroup_type {$sql_and}\n\t\t\t\t\tORDER BY group_type DESC, group_name";
                $result = $db->sql_query($sql);
                $nonmember_count = 0;
                while ($row = $db->sql_fetchrow($result)) {
                    switch ($row['group_type']) {
                        case GROUP_OPEN:
                            $group_status = 'OPEN';
                            break;
                        case GROUP_CLOSED:
                            $group_status = 'CLOSED';
                            break;
                        case GROUP_HIDDEN:
                            $group_status = 'HIDDEN';
                            break;
                        case GROUP_SPECIAL:
                            $group_status = 'SPECIAL';
                            break;
                        case GROUP_FREE:
                            $group_status = 'FREE';
                            break;
                    }
                    $template->assign_block_vars('nonmember', array('GROUP_ID' => $row['group_id'], 'GROUP_NAME' => $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name'], 'GROUP_DESC' => $row['group_type'] != GROUP_SPECIAL ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'], 'GROUP_SPECIAL' => $row['group_type'] != GROUP_SPECIAL ? false : true, 'GROUP_CLOSED' => $row['group_type'] != GROUP_CLOSED || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? false : true, 'GROUP_STATUS' => $user->lang['GROUP_IS_' . $group_status], 'S_CAN_JOIN' => $row['group_type'] == GROUP_OPEN || $row['group_type'] == GROUP_FREE ? true : false, 'GROUP_COLOUR' => $row['group_colour'], 'U_VIEW_GROUP' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&amp;g=' . $row['group_id']), 'S_ROW_COUNT' => $nonmember_count++));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_CHANGE_DEFAULT' => $auth->acl_get('u_chggrp') ? true : false, 'S_LEADER_COUNT' => $leader_count, 'S_MEMBER_COUNT' => $member_count, 'S_PENDING_COUNT' => $pending_count, 'S_NONMEMBER_COUNT' => $nonmember_count, 'S_UCP_ACTION' => $this->u_action));
                break;
            case 'manage':
                $this->page_title = 'UCP_USERGROUPS_MANAGE';
                $action = isset($_POST['addusers']) ? 'addusers' : request_var('action', '');
                $group_id = request_var('g', 0);
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                add_form_key('ucp_groups');
                if ($group_id) {
                    $sql = 'SELECT *
						FROM ' . GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE group_id = {$group_id}";
                    $result = $db->sql_query($sql);
                    $group_row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    if (!$group_row) {
                        trigger_error($user->lang['NO_GROUP'] . $return_page);
                    }
                    // Check if the user is allowed to manage this group if set to founder only.
                    if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) {
                        trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . $return_page, E_USER_WARNING);
                    }
                    $group_name = $group_row['group_name'];
                    $group_type = $group_row['group_type'];
                    $avatar_img = !empty($group_row['group_avatar']) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_root_path . 'adm/images/no_avatar.gif" alt="" />';
                    $template->assign_vars(array('GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_DESC_DISP' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']), 'GROUP_TYPE' => $group_row['group_type'], 'AVATAR' => $avatar_img, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : ''));
                }
                switch ($action) {
                    case 'edit':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . $return_page);
                        }
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $file_uploads = @ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on' ? true : false;
                        $user->add_lang(array('acp/groups', 'acp/common'));
                        $data = $submit_ary = array();
                        $update = isset($_POST['update']) ? true : false;
                        $error = array();
                        $avatar_select = basename(request_var('avatar_select', ''));
                        $category = basename(request_var('category', ''));
                        $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
                        // Did we submit?
                        if ($update) {
                            $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
                            $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
                            $group_type = request_var('group_type', GROUP_FREE);
                            $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
                            $allow_desc_urls = request_var('desc_parse_urls', false);
                            $allow_desc_smilies = request_var('desc_parse_smilies', false);
                            $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0), 'max_recipients' => request_var('group_max_recipients', 0));
                            $data['uploadurl'] = request_var('uploadurl', '');
                            $data['remotelink'] = request_var('remotelink', '');
                            $data['width'] = request_var('width', '');
                            $data['height'] = request_var('height', '');
                            $delete = request_var('delete', '');
                            if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) {
                                // Avatar stuff
                                $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                                if (!($error = validate_data($data, $var_ary))) {
                                    $data['user_id'] = "g{$group_id}";
                                    if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) {
                                        list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
                                    } else {
                                        if ($data['remotelink']) {
                                            list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
                                        }
                                    }
                                }
                            } else {
                                if ($avatar_select && $config['allow_avatar_local']) {
                                    // check avatar gallery
                                    if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                        $submit_ary['avatar_type'] = AVATAR_GALLERY;
                                        list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
                                        $submit_ary['avatar'] = $category . '/' . $avatar_select;
                                    }
                                } else {
                                    if ($delete) {
                                        $submit_ary['avatar'] = '';
                                        $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
                                    } else {
                                        if ($data['width'] && $data['height']) {
                                            // Only update the dimensions?
                                            if ($config['avatar_max_width'] || $config['avatar_max_height']) {
                                                if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) {
                                                    $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                                                }
                                            }
                                            if (!sizeof($error)) {
                                                if ($config['avatar_min_width'] || $config['avatar_min_height']) {
                                                    if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) {
                                                        $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                                                    }
                                                }
                                            }
                                            if (!sizeof($error)) {
                                                $submit_ary['avatar_width'] = $data['width'];
                                                $submit_ary['avatar_height'] = $data['height'];
                                            }
                                        }
                                    }
                                }
                            }
                            if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && !isset($group_row['group_avatar']) || $delete) {
                                if (isset($group_row['group_avatar']) && $group_row['group_avatar']) {
                                    avatar_delete('group', $group_row, true);
                                }
                            }
                            if (!check_form_key('ucp_groups')) {
                                $error[] = $user->lang['FORM_INVALID'];
                            }
                            if (!sizeof($error)) {
                                // Only set the rank, colour, etc. if it's changed or if we're adding a new
                                // group. This prevents existing group members being updated if no changes
                                // were made.
                                $group_attributes = array();
                                $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit', 'max_recipients');
                                foreach ($test_variables as $test) {
                                    if ($action == 'add' || isset($submit_ary[$test]) && $group_row['group_' . $test] != $submit_ary[$test]) {
                                        $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
                                    }
                                }
                                if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) {
                                    $cache->destroy('sql', GROUPS_TABLE);
                                    $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED';
                                    trigger_error($user->lang[$message] . $return_page);
                                }
                            }
                            if (sizeof($error)) {
                                $group_rank = $submit_ary['rank'];
                                $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls);
                            }
                        } else {
                            if (!$group_id) {
                                $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
                                $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                                $group_rank = 0;
                                $group_type = GROUP_OPEN;
                            } else {
                                $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
                                $group_rank = $group_row['group_rank'];
                            }
                        }
                        $sql = 'SELECT *
							FROM ' . RANKS_TABLE . '
							WHERE rank_special = 1
							ORDER BY rank_title';
                        $result = $db->sql_query($sql);
                        $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
                        while ($row = $db->sql_fetchrow($result)) {
                            $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : '';
                            $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                        }
                        $db->sql_freeresult($result);
                        $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : '';
                        $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : '';
                        $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : '';
                        $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : '';
                        $display_gallery = isset($_POST['display_gallery']) ? true : false;
                        if ($config['allow_avatar_local'] && $display_gallery) {
                            avatar_gallery($category, $avatar_select, 4);
                        }
                        $avatars_enabled = $can_upload || ($config['allow_avatar_local'] || $config['allow_avatar_remote']) ? true : false;
                        $template->assign_vars(array('S_EDIT' => true, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_FORM_ENCTYPE' => $can_upload ? ' enctype="multipart/form-data"' : '', 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_AVATARS_ENABLED' => $avatars_enabled, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_DESC' => $group_desc_data['text'], 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_SWATCH' => append_sid("{$phpbb_root_path}adm/swatch.{$phpEx}", 'form=ucp&amp;name=group_colour'), 'S_UCP_ACTION' => $this->u_action . "&amp;action={$action}&amp;g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024)));
                        break;
                    case 'list':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . $return_page);
                        }
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $user->add_lang(array('acp/groups', 'acp/common'));
                        $start = request_var('start', 0);
                        // Grab the leaders - always, on every page...
                        $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
							FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\t\t\tORDER BY ug.user_pending DESC, u.username_clean";
                        $result = $db->sql_query($sql);
                        while ($row = $db->sql_fetchrow($result)) {
                            $template->assign_block_vars('leader', array('USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']), 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                        }
                        $db->sql_freeresult($result);
                        // Total number of group members (non-leaders)
                        $sql = 'SELECT COUNT(user_id) AS total_members
							FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND group_leader = 0";
                        $result = $db->sql_query($sql);
                        $total_members = (int) $db->sql_fetchfield('total_members');
                        $db->sql_freeresult($result);
                        // Grab the members
                        $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
							FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\t\t\tORDER BY ug.user_pending DESC, u.username_clean";
                        $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
                        $pending = false;
                        $approved = false;
                        while ($row = $db->sql_fetchrow($result)) {
                            if ($row['user_pending'] && !$pending) {
                                $template->assign_block_vars('member', array('S_PENDING' => true));
                                $template->assign_var('S_PENDING_SET', true);
                                $pending = true;
                            } else {
                                if (!$row['user_pending'] && !$approved) {
                                    $template->assign_block_vars('member', array('S_APPROVED' => true));
                                    $template->assign_var('S_APPROVED_SET', true);
                                    $approved = true;
                                }
                            }
                            $template->assign_block_vars('member', array('USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_VIEW' => get_username_string('profile', $row['user_id'], $row['username']), 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                        }
                        $db->sql_freeresult($result);
                        $s_action_options = '';
                        $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'deleteusers' => 'DELETE');
                        foreach ($options as $option => $lang) {
                            $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
                        }
                        $template->assign_vars(array('S_LIST' => true, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;action={$action}&amp;g={$group_id}", $total_members, $config['topics_per_page'], $start), 'U_ACTION' => $this->u_action . "&amp;g={$group_id}", 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=ucp&amp;field=usernames')));
                        break;
                    case 'approve':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . $return_page);
                        }
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $user->add_lang('acp/groups');
                        // Approve, demote or promote
                        group_user_attributes('approve', $group_id, $mark_ary, false, false);
                        trigger_error($user->lang['USERS_APPROVED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                        break;
                    case 'default':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . $return_page);
                        }
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $group_row['group_name'] = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                        if (confirm_box(true)) {
                            if (!sizeof($mark_ary)) {
                                $start = 0;
                                do {
                                    $sql = 'SELECT user_id
										FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\t\t\tORDER BY user_id";
                                    $result = $db->sql_query_limit($sql, 200, $start);
                                    $mark_ary = array();
                                    if ($row = $db->sql_fetchrow($result)) {
                                        do {
                                            $mark_ary[] = $row['user_id'];
                                        } while ($row = $db->sql_fetchrow($result));
                                        group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
                                        $start = sizeof($mark_ary) < 200 ? 0 : $start + 200;
                                    } else {
                                        $start = 0;
                                    }
                                    $db->sql_freeresult($result);
                                } while ($start);
                            } else {
                                group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
                            }
                            $user->add_lang('acp/groups');
                            trigger_error($user->lang['GROUP_DEFS_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                        } else {
                            $user->add_lang('acp/common');
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                        }
                        break;
                    case 'deleteusers':
                        $user->add_lang(array('acp/groups', 'acp/common'));
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $group_row['group_name'] = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . $return_page);
                            }
                            $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']);
                            if ($error) {
                                trigger_error($user->lang[$error] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                            }
                            trigger_error($user->lang['GROUP_USERS_REMOVE'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                        }
                        break;
                    case 'addusers':
                        $user->add_lang(array('acp/groups', 'acp/common'));
                        $names = utf8_normalize_nfc(request_var('usernames', '', true));
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . $return_page);
                        }
                        if (!$names) {
                            trigger_error($user->lang['NO_USERS'] . $return_page);
                        }
                        if (!($row = group_memberships($group_id, $user->data['user_id']))) {
                            trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
                        }
                        list(, $row) = each($row);
                        if (!$row['group_leader']) {
                            trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
                        }
                        $name_ary = array_unique(explode("\n", $names));
                        $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                        $default = request_var('default', 0);
                        if (confirm_box(true)) {
                            // Add user/s to group
                            if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, 0, 0, $group_row)) {
                                trigger_error($user->lang[$error] . $return_page);
                            }
                            trigger_error($user->lang['GROUP_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                        } else {
                            $s_hidden_fields = array('default' => $default, 'usernames' => $names, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action);
                            confirm_box(false, sprintf($user->lang['GROUP_CONFIRM_ADD_USER' . (sizeof($name_ary) == 1 ? '' : 'S')], implode(', ', $name_ary)), build_hidden_fields($s_hidden_fields));
                        }
                        trigger_error($user->lang['NO_USERS_ADDED'] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $this->u_action . '&amp;action=list&amp;g=' . $group_id . '">', '</a>'));
                        break;
                    default:
                        $user->add_lang('acp/common');
                        $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_desc, g.group_desc_uid, g.group_desc_bitfield, g.group_desc_options, g.group_type, ug.group_leader
							FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
							WHERE ug.user_id = ' . $user->data['user_id'] . '
								AND g.group_id = ug.group_id
								AND ug.group_leader = 1
							ORDER BY g.group_type DESC, g.group_name';
                        $result = $db->sql_query($sql);
                        while ($value = $db->sql_fetchrow($result)) {
                            $template->assign_block_vars('leader', array('GROUP_NAME' => $value['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $value['group_name']] : $value['group_name'], 'GROUP_DESC' => generate_text_for_display($value['group_desc'], $value['group_desc_uid'], $value['group_desc_bitfield'], $value['group_desc_options']), 'GROUP_TYPE' => $value['group_type'], 'GROUP_ID' => $value['group_id'], 'GROUP_COLOUR' => $value['group_colour'], 'U_LIST' => $this->u_action . "&amp;action=list&amp;g={$value['group_id']}", 'U_EDIT' => $this->u_action . "&amp;action=edit&amp;g={$value['group_id']}"));
                        }
                        $db->sql_freeresult($result);
                        break;
                }
                break;
        }
        $this->tpl_name = 'ucp_groups_' . $mode;
    }
示例#3
0
/**
* Uploading/Changing user avatar
*/
function avatar_process_user(&$error, $custom_userdata = false)
{
    global $config, $phpbb_root_path, $auth, $user, $db;
    $data = array('uploadurl' => request_var('uploadurl', ''), 'remotelink' => request_var('remotelink', ''), 'width' => request_var('width', 0), 'height' => request_var('height', 0));
    $error = validate_data($data, array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3)));
    if (sizeof($error)) {
        return false;
    }
    $sql_ary = array();
    if ($custom_userdata === false) {
        $userdata =& $user->data;
    } else {
        $userdata =& $custom_userdata;
    }
    $data['user_id'] = $userdata['user_id'];
    $change_avatar = $custom_userdata === false ? $auth->acl_get('u_chgavatar') : true;
    $avatar_select = basename(request_var('avatar_select', ''));
    // Can we upload?
    $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
    if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) {
        list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error);
    } else {
        if ($data['remotelink'] && $change_avatar && $config['allow_avatar_remote']) {
            list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_remote($data, $error);
        } else {
            if ($avatar_select && $change_avatar && $config['allow_avatar_local']) {
                $category = basename(request_var('category', ''));
                $sql_ary['user_avatar_type'] = AVATAR_GALLERY;
                $sql_ary['user_avatar'] = $avatar_select;
                // check avatar gallery
                if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                    $sql_ary['user_avatar'] = '';
                    $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0;
                } else {
                    list($sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $sql_ary['user_avatar']);
                    $sql_ary['user_avatar'] = $category . '/' . $sql_ary['user_avatar'];
                }
            } else {
                if (isset($_POST['delete']) && $change_avatar) {
                    $sql_ary['user_avatar'] = '';
                    $sql_ary['user_avatar_type'] = $sql_ary['user_avatar_width'] = $sql_ary['user_avatar_height'] = 0;
                } else {
                    if (!empty($userdata['user_avatar'])) {
                        // Only update the dimensions
                        if (empty($data['width']) || empty($data['height'])) {
                            if ($dims = avatar_get_dimensions($userdata['user_avatar'], $userdata['user_avatar_type'], $error, $data['width'], $data['height'])) {
                                list($guessed_x, $guessed_y) = $dims;
                                if (empty($data['width'])) {
                                    $data['width'] = $guessed_x;
                                }
                                if (empty($data['height'])) {
                                    $data['height'] = $guessed_y;
                                }
                            }
                        }
                        if (($config['avatar_max_width'] || $config['avatar_max_height']) && ($data['width'] != $userdata['user_avatar_width'] || $data['height'] != $userdata['user_avatar_height'])) {
                            if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) {
                                $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                            }
                        }
                        if (!sizeof($error)) {
                            if ($config['avatar_min_width'] || $config['avatar_min_height']) {
                                if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) {
                                    $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                                }
                            }
                        }
                        if (!sizeof($error)) {
                            $sql_ary['user_avatar_width'] = $data['width'];
                            $sql_ary['user_avatar_height'] = $data['height'];
                        }
                    }
                }
            }
        }
    }
    if (!sizeof($error)) {
        // Do we actually have any data to update?
        if (sizeof($sql_ary)) {
            $ext_new = $ext_old = '';
            if (isset($sql_ary['user_avatar'])) {
                $userdata = $custom_userdata === false ? $user->data : $custom_userdata;
                $ext_new = empty($sql_ary['user_avatar']) ? '' : substr(strrchr($sql_ary['user_avatar'], '.'), 1);
                $ext_old = empty($userdata['user_avatar']) ? '' : substr(strrchr($userdata['user_avatar'], '.'), 1);
                if ($userdata['user_avatar_type'] == AVATAR_UPLOAD) {
                    // Delete old avatar if present
                    if (!empty($userdata['user_avatar']) && empty($sql_ary['user_avatar']) || !empty($userdata['user_avatar']) && !empty($sql_ary['user_avatar']) && $ext_new !== $ext_old) {
                        avatar_delete('user', $userdata);
                    }
                }
            }
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
				WHERE user_id = ' . ($custom_userdata === false ? $user->data['user_id'] : $custom_userdata['user_id']);
            $db->sql_query($sql);
        }
    }
    return sizeof($error) ? false : true;
}
示例#4
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang('acp/groups');
        $this->tpl_name = 'acp_groups';
        $this->page_title = 'ACP_GROUPS_MANAGE';
        $form_key = 'acp_groups';
        add_form_key($form_key);
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        // Check and set some common vars
        $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', ''));
        $group_id = request_var('g', 0);
        $mark_ary = request_var('mark', array(0));
        $name_ary = request_var('usernames', '', true);
        $leader = request_var('leader', 0);
        $default = request_var('default', 0);
        $start = request_var('start', 0);
        $update = isset($_POST['update']) ? true : false;
        // Clear some vars
        $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
        $group_row = array();
        // Grab basic data for group, if group_id is set and exists
        if ($group_id) {
            $sql = 'SELECT *
				FROM ' . GROUPS_TABLE . "\n\t\t\t\tWHERE group_id = {$group_id}";
            $result = $db->sql_query($sql);
            $group_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$group_row) {
                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
            // Check if the user is allowed to manage this group if set to founder only.
            if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage']) {
                trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
        }
        // Which page?
        switch ($action) {
            case 'approve':
            case 'demote':
            case 'promote':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                // Approve, demote or promote
                $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
                if (!$error) {
                    switch ($action) {
                        case 'demote':
                            $message = 'GROUP_MODS_DEMOTED';
                            break;
                        case 'promote':
                            $message = 'GROUP_MODS_PROMOTED';
                            break;
                        case 'approve':
                            $message = 'USERS_APPROVED';
                            break;
                    }
                    trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
                } else {
                    trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
                }
                break;
            case 'default':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (confirm_box(true)) {
                    $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                    if (!sizeof($mark_ary)) {
                        $start = 0;
                        do {
                            $sql = 'SELECT user_id
								FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\t\t\tORDER BY user_id";
                            $result = $db->sql_query_limit($sql, 200, $start);
                            $mark_ary = array();
                            if ($row = $db->sql_fetchrow($result)) {
                                do {
                                    $mark_ary[] = $row['user_id'];
                                } while ($row = $db->sql_fetchrow($result));
                                group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
                                $start = sizeof($mark_ary) < 200 ? 0 : $start + 200;
                            } else {
                                $start = 0;
                            }
                            $db->sql_freeresult($result);
                        } while ($start);
                    } else {
                        group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
                    }
                    trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                }
                break;
            case 'deleteusers':
            case 'delete':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                } else {
                    if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL) {
                        trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                }
                if (confirm_box(true)) {
                    $error = '';
                    switch ($action) {
                        case 'delete':
                            if (!$auth->acl_get('a_groupdel')) {
                                trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                            }
                            $error = group_delete($group_id, $group_row['group_name']);
                            break;
                        case 'deleteusers':
                            $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                            $error = group_user_del($group_id, $mark_ary, false, $group_name);
                            break;
                    }
                    $back_link = $action == 'delete' ? $this->u_action : $this->u_action . '&amp;action=list&amp;g=' . $group_id;
                    if ($error) {
                        trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING);
                    }
                    $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
                    trigger_error($user->lang[$message] . adm_back_link($back_link));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                }
                break;
            case 'addusers':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if (!$name_ary) {
                    trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
                }
                $name_ary = array_unique(explode("\n", $name_ary));
                $group_name = $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
                // Add user/s to group
                if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row)) {
                    trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
                }
                $message = $leader ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
                trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
                break;
            case 'edit':
            case 'add':
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $data = $submit_ary = array();
                if ($action == 'edit' && !$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                if ($action == 'add' && !$auth->acl_get('a_groupadd')) {
                    trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $error = array();
                $user->add_lang('ucp');
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                // Did we submit?
                if ($update) {
                    if (!check_form_key($form_key)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
                    }
                    $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
                    $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
                    $group_type = request_var('group_type', GROUP_FREE);
                    $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
                    $allow_desc_urls = request_var('desc_parse_urls', false);
                    $allow_desc_smilies = request_var('desc_parse_smilies', false);
                    $data['uploadurl'] = request_var('uploadurl', '');
                    $data['remotelink'] = request_var('remotelink', '');
                    $data['width'] = request_var('width', '');
                    $data['height'] = request_var('height', '');
                    $delete = request_var('delete', '');
                    $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0), 'max_recipients' => request_var('group_max_recipients', 0), 'founder_manage' => 0, 'skip_auth' => request_var('group_skip_auth', 0));
                    if ($user->data['user_type'] == USER_FOUNDER) {
                        $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
                    }
                    if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) {
                        // Avatar stuff
                        $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                        if (!($error = validate_data($data, $var_ary))) {
                            $data['user_id'] = "g{$group_id}";
                            if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) {
                                list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
                            } else {
                                if ($data['remotelink']) {
                                    list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
                                }
                            }
                        }
                    } else {
                        if ($avatar_select && $config['allow_avatar_local']) {
                            // check avatar gallery
                            if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                $submit_ary['avatar_type'] = AVATAR_GALLERY;
                                list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
                                $submit_ary['avatar'] = $category . '/' . $avatar_select;
                            }
                        } else {
                            if ($delete) {
                                $submit_ary['avatar'] = '';
                                $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
                            } else {
                                if ($data['width'] && $data['height']) {
                                    // Only update the dimensions?
                                    if ($config['avatar_max_width'] || $config['avatar_max_height']) {
                                        if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height']) {
                                            $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                                        }
                                    }
                                    if (!sizeof($error)) {
                                        if ($config['avatar_min_width'] || $config['avatar_min_height']) {
                                            if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height']) {
                                                $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
                                            }
                                        }
                                    }
                                    if (!sizeof($error)) {
                                        $submit_ary['avatar_width'] = $data['width'];
                                        $submit_ary['avatar_height'] = $data['height'];
                                    }
                                }
                            }
                        }
                    }
                    if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && !isset($group_row['group_avatar']) || $delete) {
                        if (isset($group_row['group_avatar']) && $group_row['group_avatar']) {
                            avatar_delete('group', $group_row, true);
                        }
                    }
                    // Validate the length of "Maximum number of allowed recipients per private message" setting.
                    // We use 16777215 as a maximum because it matches MySQL unsigned mediumint maximum value
                    // which is the lowest amongst DBMSes supported by phpBB3
                    if ($max_recipients_error = validate_data($submit_ary, array('max_recipients' => array('num', false, 0, 16777215)))) {
                        // Replace "error" string with its real, localised form
                        $error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error));
                    }
                    if (!sizeof($error)) {
                        // Only set the rank, colour, etc. if it's changed or if we're adding a new
                        // group. This prevents existing group members being updated if no changes
                        // were made.
                        $group_attributes = array();
                        $test_variables = array('rank' => 'int', 'colour' => 'string', 'avatar' => 'string', 'avatar_type' => 'int', 'avatar_width' => 'int', 'avatar_height' => 'int', 'receive_pm' => 'int', 'legend' => 'int', 'message_limit' => 'int', 'max_recipients' => 'int', 'founder_manage' => 'int', 'skip_auth' => 'int');
                        foreach ($test_variables as $test => $type) {
                            if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) {
                                settype($submit_ary[$test], $type);
                                $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
                            }
                        }
                        if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) {
                            $group_perm_from = request_var('group_perm_from', 0);
                            // Copy permissions?
                            // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
                            // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions.
                            // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
                            if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) {
                                $sql = 'SELECT group_founder_manage
									FROM ' . GROUPS_TABLE . '
									WHERE group_id = ' . $group_perm_from;
                                $result = $db->sql_query($sql);
                                $check_row = $db->sql_fetchrow($result);
                                $db->sql_freeresult($result);
                                // Check the group if non-founder
                                if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0)) {
                                    // From the mysql documentation:
                                    // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
                                    // Due to this we stay on the safe side if we do the insertion "the manual way"
                                    // Copy permisisons from/to the acl groups table (only group_id gets changed)
                                    $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
										FROM ' . ACL_GROUPS_TABLE . '
										WHERE group_id = ' . $group_perm_from;
                                    $result = $db->sql_query($sql);
                                    $groups_sql_ary = array();
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']);
                                    }
                                    $db->sql_freeresult($result);
                                    // Now insert the data
                                    $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
                                    $auth->acl_clear_prefetch();
                                }
                            }
                            $cache->destroy('sql', GROUPS_TABLE);
                            $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED';
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action));
                        }
                    }
                    if (sizeof($error)) {
                        $group_rank = $submit_ary['rank'];
                        $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls);
                    }
                } else {
                    if (!$group_id) {
                        $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
                        $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                        $group_rank = 0;
                        $group_type = GROUP_OPEN;
                    } else {
                        $group_name = $group_row['group_name'];
                        $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
                        $group_type = $group_row['group_type'];
                        $group_rank = $group_row['group_rank'];
                    }
                }
                $sql = 'SELECT *
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : '';
                    $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : '';
                $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : '';
                $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : '';
                $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : '';
                $avatar_img = !empty($group_row['group_avatar']) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $back_link = request_var('back_link', '');
                switch ($back_link) {
                    case 'acp_users_groups':
                        $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&amp;mode=groups&amp;u=' . request_var('u', 0));
                        break;
                    default:
                        $u_back = $this->u_action;
                        break;
                }
                $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_GROUP_PERM' => $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth') ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'S_USER_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_FOUNDER_MANAGE' => isset($group_row['group_founder_manage']) && $group_row['group_founder_manage'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_MAX_RECIPIENTS' => isset($group_row['group_max_recipients']) ? $group_row['group_max_recipients'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'GROUP_SKIP_AUTH' => !empty($group_row['group_skip_auth']) ? ' checked="checked"' : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, $user->data['user_type'] == USER_FOUNDER ? false : 0), 'AVATAR' => $avatar_img, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&amp;name=group_colour'), 'U_ACTION' => "{$this->u_action}&amp;action={$action}&amp;g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                return;
                break;
            case 'list':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $this->page_title = 'GROUP_MEMBERS';
                // Grab the leaders - always, on every page...
                $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
					FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 1\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;action=edit&amp;u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                }
                $db->sql_freeresult($result);
                // Total number of group members (non-leaders)
                $sql = 'SELECT COUNT(user_id) AS total_members
					FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\tWHERE group_id = {$group_id}\n\t\t\t\t\t\tAND group_leader = 0";
                $result = $db->sql_query($sql);
                $total_members = (int) $db->sql_fetchfield('total_members');
                $db->sql_freeresult($result);
                $s_action_options = '';
                $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
                foreach ($options as $option => $lang) {
                    $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
                }
                $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;action={$action}&amp;g={$group_id}", $total_members, $config['topics_per_page'], $start, true), 'GROUP_NAME' => $group_row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'], 'U_ACTION' => $this->u_action . "&amp;g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=list&amp;field=usernames'), 'U_DEFAULT_ALL' => "{$this->u_action}&amp;action=default&amp;g={$group_id}"));
                // Grab the members
                $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
					FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.group_id = {$group_id}\n\t\t\t\t\t\tAND u.user_id = ug.user_id\n\t\t\t\t\t\tAND ug.group_leader = 0\n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
                $pending = false;
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['user_pending'] && !$pending) {
                        $template->assign_block_vars('member', array('S_PENDING' => true));
                        $pending = true;
                    }
                    $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;action=edit&amp;u={$row['user_id']}"), 'USERNAME' => $row['username'], 'USERNAME_COLOUR' => $row['user_colour'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                }
                $db->sql_freeresult($result);
                return;
                break;
        }
        $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false));
        // Get us all the groups
        $sql = 'SELECT g.group_id, g.group_name, g.group_type
			FROM ' . GROUPS_TABLE . ' g
			ORDER BY g.group_type ASC, g.group_name';
        $result = $db->sql_query($sql);
        $lookup = $cached_group_data = array();
        while ($row = $db->sql_fetchrow($result)) {
            $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal';
            // used to determine what type a group is
            $lookup[$row['group_id']] = $type;
            // used for easy access to the data within a group
            $cached_group_data[$type][$row['group_id']] = $row;
            $cached_group_data[$type][$row['group_id']]['total_members'] = 0;
        }
        $db->sql_freeresult($result);
        // How many people are in which group?
        $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
			FROM ' . USER_GROUP_TABLE . ' ug
			WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
			GROUP BY ug.group_id';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $type = $lookup[$row['group_id']];
            $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
        }
        $db->sql_freeresult($result);
        // The order is... normal, then special
        ksort($cached_group_data);
        foreach ($cached_group_data as $type => $row_ary) {
            if ($type == 'special') {
                $template->assign_block_vars('groups', array('S_SPECIAL' => true));
            }
            foreach ($row_ary as $group_id => $row) {
                $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
                $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&amp;action=list&amp;g={$group_id}", 'U_EDIT' => "{$this->u_action}&amp;action=edit&amp;g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&amp;action=delete&amp;g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members']));
            }
        }
    }
示例#5
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang('acp/groups');
        $this->tpl_name = 'acp_groups';
        $this->page_title = 'ACP_GROUPS_MANAGE';
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        // Check and set some common vars
        $action = isset($_POST['add']) ? 'add' : (isset($_POST['addusers']) ? 'addusers' : request_var('action', ''));
        $group_id = request_var('g', 0);
        $mark_ary = request_var('mark', array(0));
        $name_ary = request_var('usernames', '');
        $leader = request_var('leader', 0);
        $default = request_var('default', 0);
        $start = request_var('start', 0);
        $update = isset($_POST['update']) ? true : false;
        // Clear some vars
        $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
        $group_row = array();
        // Grab basic data for group, if group_id is set and exists
        if ($group_id) {
            $sql = 'SELECT * 
				FROM ' . GROUPS_TABLE . " \n\t\t\t\tWHERE group_id = {$group_id}";
            $result = $db->sql_query($sql);
            $group_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$group_row) {
                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
            }
        }
        // Which page?
        switch ($action) {
            case 'approve':
            case 'demote':
            case 'promote':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                }
                // Approve, demote or promote
                group_user_attributes($action, $group_id, $mark_ary, false, $group_id ? $group_row['group_name'] : false);
                switch ($action) {
                    case 'demote':
                        $message = 'GROUP_MODS_DEMOTED';
                        break;
                    case 'promote':
                        $message = 'GROUP_MODS_PROMOTED';
                        break;
                    case 'approve':
                        $message = 'USERS_APPROVED';
                        break;
                }
                trigger_error($user->lang[$message] . adm_back_link($this->u_action));
                break;
            case 'default':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                }
                if (confirm_box(true)) {
                    if (!sizeof($mark_ary)) {
                        $start = 0;
                        do {
                            $sql = 'SELECT user_id 
								FROM ' . USER_GROUP_TABLE . "\n\t\t\t\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\t\t\tORDER BY user_id";
                            $result = $db->sql_query_limit($sql, 200, $start);
                            $mark_ary = array();
                            if ($row = $db->sql_fetchrow($result)) {
                                do {
                                    $mark_ary[] = $row['user_id'];
                                } while ($row = $db->sql_fetchrow($result));
                                group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
                                $start = sizeof($mark_ary) < 200 ? 0 : $start + 200;
                            } else {
                                $start = 0;
                            }
                            $db->sql_freeresult($result);
                        } while ($start);
                    } else {
                        group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
                    }
                    trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                }
                break;
            case 'deleteusers':
            case 'delete':
                if (confirm_box(true)) {
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                    }
                    $error = '';
                    switch ($action) {
                        case 'delete':
                            if (!$auth->acl_get('a_groupdel')) {
                                trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action));
                            }
                            $error = group_delete($group_id, $group_row['group_name']);
                            break;
                        case 'deleteusers':
                            $error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']);
                            break;
                    }
                    if ($error) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action));
                    }
                    $message = $action == 'delete' ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
                    trigger_error($user->lang[$message] . adm_back_link($this->u_action));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('mark' => $mark_ary, 'g' => $group_id, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                }
                break;
            case 'addusers':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                }
                if (!$name_ary) {
                    trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action));
                }
                $name_ary = array_unique(explode("\n", $name_ary));
                // Add user/s to group
                if ($error = group_user_add($group_id, false, $name_ary, $group_row['group_name'], $default, $leader, 0, $group_row)) {
                    trigger_error($user->lang[$error] . adm_back_link($this->u_action));
                }
                $message = $action == 'addleaders' ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
                trigger_error($user->lang[$message] . adm_back_link($this->u_action));
                break;
            case 'edit':
            case 'add':
                $data = $submit_ary = array();
                if ($action == 'edit' && !$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                }
                if ($action == 'add' && !$auth->acl_get('a_groupadd')) {
                    trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action));
                }
                $error = array();
                $user->add_lang('ucp');
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                // Did we submit?
                if ($update) {
                    $group_name = request_var('group_name', '', true);
                    $group_desc = request_var('group_desc', '', true);
                    $group_type = request_var('group_type', GROUP_FREE);
                    $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
                    $allow_desc_urls = request_var('desc_parse_urls', false);
                    $allow_desc_smilies = request_var('desc_parse_smilies', false);
                    $data['uploadurl'] = request_var('uploadurl', '');
                    $data['remotelink'] = request_var('remotelink', '');
                    $delete = request_var('delete', '');
                    $submit_ary = array('colour' => request_var('group_colour', ''), 'rank' => request_var('group_rank', 0), 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0, 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0, 'message_limit' => request_var('group_message_limit', 0));
                    if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink']) {
                        $data['width'] = request_var('width', '');
                        $data['height'] = request_var('height', '');
                        // Avatar stuff
                        $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                        if (!($error = validate_data($data, $var_ary))) {
                            $data['user_id'] = "g{$group_id}";
                            if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload) {
                                list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
                            } else {
                                if ($data['remotelink']) {
                                    list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
                                }
                            }
                        }
                    } else {
                        if ($avatar_select && $config['allow_avatar_local']) {
                            // check avatar gallery
                            if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                $submit_ary['avatar_type'] = AVATAR_GALLERY;
                                list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
                                $submit_ary['avatar'] = $category . '/' . $avatar_select;
                            }
                        } else {
                            if ($delete) {
                                $submit_ary['avatar'] = '';
                                $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
                            }
                        }
                    }
                    if (isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']) || $group_row['group_avatar'] != $submit_ary['avatar']) || $delete) {
                        if (isset($group_row['group_avatar']) && $group_row['group_avatar']) {
                            avatar_delete($group_row['group_avatar']);
                        }
                    }
                    if (!sizeof($error)) {
                        // Only set the rank, colour, etc. if it's changed or if we're adding a new
                        // group. This prevents existing group members being updated if no changes
                        // were made.
                        $group_attributes = array();
                        $test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit');
                        foreach ($test_variables as $test) {
                            if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test])) {
                                $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
                            }
                        }
                        if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies))) {
                            $group_perm_from = request_var('group_perm_from', 0);
                            // Copy permissions?
                            if ($group_perm_from && $action == 'add') {
                                // From the mysql documentation:
                                // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
                                // Due to this we stay on the safe side if we do the insertion "the manual way"
                                // Copy permisisons from/to the acl groups table (only group_id gets changed)
                                $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
									FROM ' . ACL_GROUPS_TABLE . '
									WHERE group_id = ' . $group_perm_from;
                                $result = $db->sql_query($sql);
                                $groups_sql_ary = array();
                                while ($row = $db->sql_fetchrow($result)) {
                                    $groups_sql_ary[] = array('group_id' => (int) $group_id, 'forum_id' => (int) $row['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']);
                                }
                                $db->sql_freeresult($result);
                                // Now insert the data
                                if (sizeof($groups_sql_ary)) {
                                    switch (SQL_LAYER) {
                                        case 'mysql':
                                        case 'mysql4':
                                        case 'mysqli':
                                            $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $groups_sql_ary));
                                            break;
                                        default:
                                            foreach ($groups_sql_ary as $ary) {
                                                $db->sql_query('INSERT INTO ' . ACL_GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
                                            }
                                            break;
                                    }
                                }
                                $auth->acl_clear_prefetch();
                            }
                            $cache->destroy('sql', GROUPS_TABLE);
                            $message = $action == 'edit' ? 'GROUP_UPDATED' : 'GROUP_CREATED';
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action));
                        }
                    }
                    if (sizeof($error)) {
                        $group_rank = $submit_ary['rank'];
                        $group_desc_data = array('text' => $group_desc, 'allow_bbcode' => $allow_desc_bbcode, 'allow_smilies' => $allow_desc_smilies, 'allow_urls' => $allow_desc_urls);
                    }
                } else {
                    if (!$group_id) {
                        $group_name = request_var('group_name', '', true);
                        $group_desc_data = array('text' => '', 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true);
                        $group_rank = 0;
                        $group_type = GROUP_OPEN;
                    } else {
                        $group_name = $group_row['group_name'];
                        $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield']);
                        $group_type = $group_row['group_type'];
                        $group_rank = $group_row['group_rank'];
                    }
                }
                $sql = 'SELECT * 
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $rank_options = '<option value="0"' . (!$group_rank ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $group_rank && $row['rank_id'] == $group_rank ? ' selected="selected"' : '';
                    $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $type_free = $group_type == GROUP_FREE ? ' checked="checked"' : '';
                $type_open = $group_type == GROUP_OPEN ? ' checked="checked"' : '';
                $type_closed = $group_type == GROUP_CLOSED ? ' checked="checked"' : '';
                $type_hidden = $group_type == GROUP_HIDDEN ? ' checked="checked"' : '';
                if (isset($group_row['group_avatar']) && $group_row['group_avatar']) {
                    switch ($group_row['group_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $group_row['group_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $group_row['group_avatar_width'] . '" height="' . $group_row['group_avatar_height'] . '" alt="" />';
                } else {
                    $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                }
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $back_link = request_var('back_link', '');
                switch ($back_link) {
                    case 'acp_users_groups':
                        $u_back = append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&amp;mode=groups&amp;u=' . request_var('u', 0));
                        break;
                    default:
                        $u_back = $this->u_action;
                        break;
                }
                $template->assign_vars(array('S_EDIT' => true, 'S_ADD_GROUP' => $action == 'add' ? true : false, 'S_INCLUDE_SWATCH' => true, 'S_CAN_UPLOAD' => $can_upload, 'S_ERROR' => sizeof($error) ? true : false, 'S_SPECIAL_GROUP' => $group_type == GROUP_SPECIAL ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'GROUP_NAME' => $group_type == GROUP_SPECIAL ? $user->lang['G_' . $group_name] : $group_name, 'GROUP_INTERNAL_NAME' => $group_name, 'GROUP_DESC' => $group_desc_data['text'], 'GROUP_RECEIVE_PM' => isset($group_row['group_receive_pm']) && $group_row['group_receive_pm'] ? ' checked="checked"' : '', 'GROUP_LEGEND' => isset($group_row['group_legend']) && $group_row['group_legend'] ? ' checked="checked"' : '', 'GROUP_MESSAGE_LIMIT' => isset($group_row['group_message_limit']) ? $group_row['group_message_limit'] : 0, 'GROUP_COLOUR' => isset($group_row['group_colour']) ? $group_row['group_colour'] : '', 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'], 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'], 'S_DESC_SMILIES_CHECKED' => $group_desc_data['allow_smilies'], 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(0), 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'GROUP_AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', 'GROUP_AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, 'GROUP_TYPE_CLOSED' => GROUP_CLOSED, 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN, 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL, 'GROUP_FREE' => $type_free, 'GROUP_OPEN' => $type_open, 'GROUP_CLOSED' => $type_closed, 'GROUP_HIDDEN' => $type_hidden, 'U_BACK' => $u_back, 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&amp;name=group_colour'), 'UA_SWATCH' => append_sid("{$phpbb_admin_path}swatch.{$phpEx}", 'form=settings&name=group_colour', false), 'U_ACTION' => "{$this->u_action}&amp;action={$action}&amp;g={$group_id}", 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                return;
                break;
            case 'list':
                if (!$group_id) {
                    trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action));
                }
                $this->page_title = 'GROUP_MEMBERS';
                // Total number of group leaders
                $sql = 'SELECT COUNT(user_id) AS total_leaders 
					FROM ' . USER_GROUP_TABLE . " \n\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\tAND group_leader = 1";
                $result = $db->sql_query($sql);
                $total_leaders = (int) $db->sql_fetchfield('total_leaders');
                $db->sql_freeresult($result);
                // Total number of group members (non-leaders)
                $sql = 'SELECT COUNT(user_id) AS total_members 
					FROM ' . USER_GROUP_TABLE . " \n\t\t\t\t\tWHERE group_id = {$group_id} \n\t\t\t\t\t\tAND group_leader <> 1";
                $result = $db->sql_query($sql);
                $total_members = (int) $db->sql_fetchfield('total_members');
                $db->sql_freeresult($result);
                // Grab the members
                $sql = 'SELECT u.user_id, u.username, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending 
					FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug \n\t\t\t\t\tWHERE ug.group_id = {$group_id} \n\t\t\t\t\t\tAND u.user_id = ug.user_id \n\t\t\t\t\tORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username";
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
                $leader = $member = 0;
                $group_data = array('leader' => array(), 'member' => array());
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_leader'] ? 'leader' : 'member';
                    $group_data[$type][${$type}]['user_id'] = $row['user_id'];
                    $group_data[$type][${$type}]['group_id'] = $row['group_id'];
                    $group_data[$type][${$type}]['username'] = $row['username'];
                    $group_data[$type][${$type}]['user_regdate'] = $row['user_regdate'];
                    $group_data[$type][${$type}]['user_posts'] = $row['user_posts'];
                    $group_data[$type][${$type}]['user_pending'] = $row['user_pending'] ? 1 : 0;
                    ${$type}++;
                }
                $db->sql_freeresult($result);
                $s_action_options = '';
                $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
                foreach ($options as $option => $lang) {
                    $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
                }
                $template->assign_vars(array('S_LIST' => true, 'S_GROUP_SPECIAL' => $group_row['group_type'] == GROUP_SPECIAL ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;action={$action}&amp;g={$group_id}", $total_members, $config['topics_per_page'], $start, true), 'U_ACTION' => $this->u_action . "&amp;g={$group_id}", 'U_BACK' => $this->u_action, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=list&amp;field=usernames')));
                foreach ($group_data['leader'] as $row) {
                    $template->assign_block_vars('leader', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;action=edit&amp;u={$row['user_id']}"), 'USERNAME' => $row['username'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                }
                $pending = false;
                foreach ($group_data['member'] as $row) {
                    if ($row['user_pending'] && !$pending) {
                        $template->assign_block_vars('member', array('S_PENDING' => true));
                        $pending = true;
                    }
                    $template->assign_block_vars('member', array('U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;action=edit&amp;u={$row['user_id']}"), 'USERNAME' => $row['username'], 'S_GROUP_DEFAULT' => $row['group_id'] == $group_id ? true : false, 'JOINED' => $row['user_regdate'] ? $user->format_date($row['user_regdate']) : ' - ', 'USER_POSTS' => $row['user_posts'], 'USER_ID' => $row['user_id']));
                }
                return;
                break;
        }
        $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_GROUP_ADD' => $auth->acl_get('a_groupadd') ? true : false));
        $sql = 'SELECT g.group_id, g.group_name, g.group_type, COUNT(ug.user_id) AS total_members 
			FROM ' . GROUPS_TABLE . ' g
			LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (g.group_id = ug.group_id)
			GROUP BY g.group_id, g.group_name, g.group_type
			ORDER BY g.group_type ASC, g.group_name';
        $result = $db->sql_query($sql);
        $special = $normal = 0;
        $group_ary = array();
        while ($row = $db->sql_fetchrow($result)) {
            $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : 'normal';
            $group_ary[$type][${$type}]['group_id'] = $row['group_id'];
            $group_ary[$type][${$type}]['group_name'] = $row['group_name'];
            $group_ary[$type][${$type}]['group_type'] = $row['group_type'];
            $group_ary[$type][${$type}]['total_members'] = $row['total_members'];
            ${$type}++;
        }
        $db->sql_freeresult($result);
        ksort($group_ary);
        $special_toggle = false;
        foreach ($group_ary as $type => $row_ary) {
            if ($type == 'special') {
                $template->assign_block_vars('groups', array('S_SPECIAL' => true));
            }
            foreach ($row_ary as $row) {
                $group_id = $row['group_id'];
                $group_name = !empty($user->lang['G_' . $row['group_name']]) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
                $template->assign_block_vars('groups', array('U_LIST' => "{$this->u_action}&amp;action=list&amp;g={$group_id}", 'U_DEFAULT' => "{$this->u_action}&amp;action=default&amp;g={$group_id}", 'U_EDIT' => "{$this->u_action}&amp;action=edit&amp;g={$group_id}", 'U_DELETE' => $auth->acl_get('a_groupdel') ? "{$this->u_action}&amp;action=delete&amp;g={$group_id}" : '', 'S_GROUP_SPECIAL' => $row['group_type'] == GROUP_SPECIAL ? true : false, 'GROUP_NAME' => $group_name, 'TOTAL_MEMBERS' => $row['total_members']));
            }
        }
    }
    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');
    }
                    $error[] = 'BAD_AVATAR';
                } else {
                    $type = AVATAR_GALLERY;
                    $filename = $gallery_avatar;
                    list($width, $height) = getimagesize($_CORE_CONFIG['global']['path_avatar_gallery'] . '/' . $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'];
                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) {
                    $filename = '';
                    $type = $width = $height = 0;
                } else {
                    $error[] = 'IM_LOST';
                }
            }
            if (empty($error)) {
                $sql_ary = array('user_avatar' => (string) $filename, 'user_avatar_type' => (int) $type, 'user_avatar_width' => (int) $width, 'user_avatar_height' => (int) $height);
                $sql = 'UPDATE ' . CORE_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) {
示例#8
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
        $user->add_lang('posting');
        $preview = !empty($_POST['preview']) ? true : false;
        $submit = !empty($_POST['submit']) ? true : false;
        $delete = !empty($_POST['delete']) ? true : false;
        $error = $data = array();
        $s_hidden_fields = '';
        switch ($mode) {
            case 'reg_details':
                if ($submit) {
                    $var_ary = array('username' => $user->data['username'], 'email' => $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('password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'new_password' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'cur_password' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('email', $data['email'])), 'email_confirm' => array('string', true, 6, 60));
                    if ($auth->acl_get('u_chgname') && $config['allow_namechange']) {
                        $var_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $data['username']));
                    }
                    $error = validate_data($data, $var_ary);
                    extract($data);
                    unset($data);
                    if ($auth->acl_get('u_chgpasswd') && $new_password && $password_confirm != $new_password) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if (($new_password || $auth->acl_get('u_chgemail') && $email != $user->data['user_email'] || $username != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) && md5($cur_password) != $user->data['user_password']) {
                        $error[] = 'CUR_PASSWORD_ERROR';
                    }
                    if ($auth->acl_get('u_chgemail') && $email != $user->data['user_email'] && $email_confirm != $email) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $username : $user->data['username'], 'user_email' => $auth->acl_get('u_chgemail') ? $email : $user->data['user_email'], 'user_email_hash' => $auth->acl_get('u_chgemail') ? crc32(strtolower($email)) . strlen($email) : $user->data['user_email_hash'], 'user_password' => $auth->acl_get('u_chgpasswd') && $new_password ? md5($new_password) : $user->data['user_password'], 'user_passchg' => $auth->acl_get('u_chgpasswd') && $new_password ? time() : 0);
                        if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $username != $user->data['username']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $username);
                        }
                        if ($auth->acl_get('u_chgpasswd') && $new_password && md5($new_password) != $user->data['user_password']) {
                            $user->reset_login_keys();
                            add_log('user', $user->data['user_id'], 'LOG_USER_NEW_PASSWORD', $username);
                        }
                        if ($auth->acl_get('u_chgemail') && $email != $user->data['user_email']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_EMAIL', $username, $user->data['user_email'], $email);
                        }
                        if ($config['email_enable'] && $email != $user->data['user_email'] && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) {
                            include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                            $server_url = generate_board_url();
                            $user_actkey = gen_rand_string(10);
                            $key_len = 54 - strlen($server_url);
                            $key_len = $key_len > 6 ? $key_len : 6;
                            $user_actkey = substr($user_actkey, 0, $key_len);
                            $messenger = new messenger();
                            $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive' : 'user_activate';
                            $messenger->template($template_file, $user->data['user_lang']);
                            $messenger->replyto($config['board_contact']);
                            $messenger->to($email, $username);
                            $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                            $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                            $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                            $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                            $messenger->assign_vars(array('SITENAME' => $config['sitename'], 'USERNAME' => html_entity_decode($username), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}"));
                            $messenger->send(NOTIFY_EMAIL);
                            if ($config['require_activation'] == USER_ACTIVATION_ADMIN) {
                                // Grab an array of user_id's with a_user permissions
                                $admin_ary = $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 = $db->sql_query($sql);
                                while ($row = $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' => html_entity_decode($username), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user->data['user_id']}&k={$user_actkey}"));
                                    $messenger->send($row['user_notify_type']);
                                }
                                $db->sql_freeresult($result);
                            }
                            $messenger->save_queue();
                            $sql_ary += array('user_type' => USER_INACTIVE, 'user_actkey' => $user_actkey);
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                        }
                        // Need to update config, forum, topic, posting, messages, etc.
                        if ($username != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) {
                            user_update_name($user->data['username'], $username);
                        }
                        meta_refresh(3, $this->u_action);
                        $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => isset($username) ? $username : $user->data['username'], 'EMAIL' => isset($email) ? $email : $user->data['user_email'], 'PASSWORD_CONFIRM' => isset($password_confirm) ? $password_confirm : '', 'NEW_PASSWORD' => isset($new_password) ? $new_password : '', 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$user_char_ary[str_replace('\\\\', '\\', $config['allow_name_chars'])] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang['CHANGE_PASSWORD_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FORCE_PASSWORD' => $config['chg_passforce'] && $user->data['user_passchg'] < time() - $config['chg_passforce'] ? true : false, 'S_CHANGE_USERNAME' => $config['allow_namechange'] && $auth->acl_get('u_chgname') ? true : false, 'S_CHANGE_EMAIL' => $auth->acl_get('u_chgemail') ? true : false, 'S_CHANGE_PASSWORD' => $auth->acl_get('u_chgpasswd') ? true : false));
                break;
            case 'profile_info':
                include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                if ($submit) {
                    $var_ary = array('icq' => (string) '', 'aim' => (string) '', 'msn' => (string) '', 'yim' => (string) '', 'jabber' => (string) '', 'website' => (string) '', 'location' => (string) '', 'occupation' => (string) '', 'interests' => (string) '', 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = in_array($var, array('location', 'occupation', 'interests')) ? request_var($var, $default, true) : request_var($var, $default);
                    }
                    $var_ary = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 17), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('match', true, '#^[a-z0-9\\.\\-_\\+]+?@(.*?\\.)*?[a-z0-9\\-_]+?\\.[a-z]{2,4}(/.*)?$#i')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 255), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())));
                    $error = validate_data($data, $var_ary);
                    extract($data);
                    unset($data);
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user->get_iso_lang_id(), $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!sizeof($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' => sprintf('%2d-%2d-%4d', $bday_day, $bday_month, $bday_year));
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user->data['user_id'];
                        $db->sql_query($sql);
                        // Update Custom Fields
                        if (sizeof($cp_data)) {
                            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . '
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                            if (!$db->sql_affectedrows()) {
                                $cp_data['user_id'] = (int) $user->data['user_id'];
                                $db->return_on_error = true;
                                $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
                                $db->sql_query($sql);
                                $db->return_on_error = false;
                            }
                        }
                        meta_refresh(3, $this->u_action);
                        $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                        trigger_error($message);
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!isset($bday_day)) {
                    if ($user->data['user_birthday']) {
                        list($bday_day, $bday_month, $bday_year) = explode('-', $user->data['user_birthday']);
                    } else {
                        $bday_day = $bday_month = $bday_year = 0;
                    }
                }
                $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 = '';
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$bday_year ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i < $now['year']; $i++) {
                    $selected = $i == $bday_year ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'ICQ' => isset($icq) ? $icq : $user->data['user_icq'], 'YIM' => isset($yim) ? $yim : $user->data['user_yim'], 'AIM' => isset($aim) ? $aim : $user->data['user_aim'], 'MSN' => isset($msn) ? $msn : $user->data['user_msnm'], 'JABBER' => isset($jabber) ? $jabber : $user->data['user_jabber'], 'WEBSITE' => isset($website) ? $website : $user->data['user_website'], 'LOCATION' => isset($location) ? $location : $user->data['user_from'], 'OCCUPATION' => isset($occupation) ? $occupation : $user->data['user_occ'], 'INTERESTS' => isset($interests) ? $interests : $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));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user->data['user_id']);
                $cp->generate_profile_fields('profile', $user->get_iso_lang_id());
                break;
            case 'signature':
                if (!$auth->acl_get('u_sig')) {
                    trigger_error('NO_AUTH_SIGNATURE');
                }
                include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('enable_bbcode', $user->optionget('bbcode')) : false;
                $enable_smilies = $config['allow_sig_smilies'] ? request_var('enable_smilies', $user->optionget('smilies')) : false;
                $enable_urls = request_var('enable_urls', true);
                $signature = request_var('signature', (string) $user->data['user_sig'], true);
                if ($submit || $preview) {
                    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    if (!sizeof($error)) {
                        $message_parser = new parse_message($signature);
                        // Allowing Quote BBCode
                        $message_parser->parse($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);
                            $sql = 'UPDATE ' . USERS_TABLE . ' 
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                            $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                            trigger_error($message);
                        }
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user->data['user_sig_bbcode_uid']);
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? 'checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? 'checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false));
                // Build custom bbcodes array
                $sql = 'SELECT bbcode_id, bbcode_tag 
					FROM ' . BBCODES_TABLE . '
					WHERE display_on_posting = 1';
                $result = $db->sql_query($sql);
                $i = 0;
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('custom_tags', array('BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'", 'BBCODE_ID' => 22 + $i * 2, 'BBCODE_TAG' => $row['bbcode_tag']));
                    $i++;
                }
                $db->sql_freeresult($result);
                break;
            case 'avatar':
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                $delete = isset($_POST['delete']) ? true : false;
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                // Can we upload?
                $can_upload = $config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
                if ($submit) {
                    $var_ary = array('uploadurl' => (string) '', 'remotelink' => (string) '', 'width' => (string) '', 'height' => (string) '');
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $data['user_id'] = $user->data['user_id'];
                        if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) {
                            list($type, $filename, $width, $height) = avatar_upload($data, $error);
                        } else {
                            if ($data['remotelink'] && $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote']) {
                                list($type, $filename, $width, $height) = avatar_remote($data, $error);
                            } else {
                                if ($avatar_select && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) {
                                    $type = AVATAR_GALLERY;
                                    $filename = $avatar_select;
                                    // check avatar gallery
                                    if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                        $filename = '';
                                        $type = $width = $height = 0;
                                    } else {
                                        list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $filename);
                                        $filename = $category . '/' . $filename;
                                    }
                                } else {
                                    if ($delete && $auth->acl_get('u_chgavatar')) {
                                        $filename = '';
                                        $type = $width = $height = 0;
                                    } else {
                                        $data = array();
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        // Do we actually have any data to update?
                        if (sizeof($data)) {
                            $sql_ary = array('user_avatar' => $filename, 'user_avatar_type' => $type, 'user_avatar_width' => $width, 'user_avatar_height' => $height);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user->data['user_id'];
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user->data['user_avatar'] && $filename != $user->data['user_avatar'] && $user->data['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user->data['user_avatar']);
                            }
                        }
                        meta_refresh(3, $this->u_action);
                        $message = $user->lang['PROFILE_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
                        trigger_error($message);
                    }
                    extract($data);
                    unset($data);
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                // Generate users avatar
                $avatar_img = '';
                if ($user->data['user_avatar']) {
                    switch ($user->data['user_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $user->data['user_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $user->data['user_avatar_width'] . '" height="' . $user->data['user_avatar_height'] . '" alt="" />';
                }
                $template->assign_vars(array('ERROR' => sizeof($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($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                if ($display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) {
                    avatar_gallery($category, $avatar_select, 4);
                } else {
                    $template->assign_vars(array('AVATAR' => $avatar_img, 'AVATAR_SIZE' => $config['avatar_filesize'], 'WIDTH' => isset($width) ? $width : $user->data['user_avatar_width'], 'HEIGHT' => isset($height) ? $height : $user->data['user_avatar_height'], 'S_UPLOAD_AVATAR_FILE' => $can_upload, 'S_UPLOAD_AVATAR_URL' => $can_upload, 'S_LINK_AVATAR' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote'] ? true : false, 'S_GALLERY_AVATAR' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_local'] ? true : false));
                }
                break;
        }
        $template->assign_vars(array('L_TITLE' => $user->lang['UCP_PROFILE_' . strtoupper($mode)], 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => $this->u_action));
        // Set desired template
        $this->tpl_name = 'ucp_profile_' . $mode;
        $this->page_title = 'UCP_PROFILE_' . strtoupper($mode);
    }
示例#9
0
function tt_copy_avatar($uid, $avatar_url)
{
    global $config, $phpbb_root_path, $db, $user, $phpEx;
    $can_upload = $config['allow_avatar_remote'];
    if ($can_upload && !empty($avatar_url)) {
        $avatar['user_id'] = $uid;
        $avatar['uploadurl'] = '';
        $avatar['remotelink'] = $avatar_url;
        $avatar['width'] = $config['avatar_max_width'];
        $avatar['height'] = $config['avatar_max_height'];
        $error = array();
        $upload_response = avatar_remote($avatar, $error);
        if (empty($error)) {
            list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = $upload_response;
            $sql = 'UPDATE ' . USERS_TABLE . '
			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
			WHERE user_id = ' . $uid;
            $db->sql_query($sql);
        }
    }
}
    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) {
                    $password = get_variable('new_password', 'POST', false);
                    $cur_password = get_variable('cur_password', 'POST', false);
                    if (!$cur_password || encode_password($cur_password, $_CLASS['core_user']->data['user_password_encoding']) !== $_CLASS['core_user']->data['user_password']) {
                        $error[] = $_CLASS['core_user']->get_lang('CURRENT_PASSWORD_INVALID');
                    }
                    if (!$password || $password !== get_variable('password_confirm', 'POST', '')) {
                        $error[] = $_CLASS['core_user']->get_lang('PASSWORD_MISMATCH');
                    }
                    if (empty($error) && $password === $cur_password) {
                        $error[] = $_CLASS['core_user']->get_lang('PASSWORD_SAME');
                    }
                    if (empty($error)) {
                        $array = array('user_password' => encode_password($password, $_CLASS['core_user']->data['user_password_encoding']));
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $array) . ' 
							WHERE user_id = ' . $_CLASS['core_user']->data['user_id'];
                        $_CLASS['core_db']->sql_query($sql);
                    }
                }
                $_CLASS['core_template']->assign_array(array('ERROR' => empty($error) ? '' : implode('<br />', $error), 'USERNAME' => $_CLASS['core_user']->data['username'], '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' => '', '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' => false, 'S_CHANGE_USERNAME' => false, 'S_CHANGE_EMAIL' => 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 = true ? !isset($_POST['disable_html']) : false;
                $enable_bbcode = true ? !isset($_POST['disable_bbcode']) : false;
                $enable_smilies = true ? !isset($_POST['disable_smilies']) : false;
                $enable_urls = !isset($_POST['disable_magic_url']);
                $signature = get_variable('signature', 'POST', $_CLASS['core_user']->data['user_sig']);
                $signature_preview = '';
                $sql_array = false;
                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 (!empty($message_parser->warn_msg)) {
                            $error[] = implode('<br />', $message_parser->warn_msg);
                        }
                    }
                    if (empty($error) && $submit) {
                        if ($signature && !empty($message_parser->message)) {
                            $sql_array = 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_array = array('user_sig' => (string) '', 'user_sig_bbcode_uid' => (string) '', 'user_sig_bbcode_bitfield' => (int) 0);
                        }
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $_CLASS['core_db']->sql_build_array('UPDATE', $sql_array) . ' 
							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);
                    }
                }
                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);
                }
                if ($signature) {
                    decode_message($signature, $_CLASS['core_user']->data['user_sig_bbcode_uid']);
                }
                $_CLASS['core_template']->assign_array(array('ERROR' => empty($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' => true ? $_CLASS['core_user']->get_lang('HTML_IS_ON') : $_CLASS['core_user']->get_lang('HTML_IS_OFF'), 'BBCODE_STATUS' => true ? sprintf($_CLASS['core_user']->get_lang('BBCODE_IS_ON'), '<a href="' . generate_link('Forums&amp;file=faq&amp;mode=bbcode') . '" target="_phpbbcode">', '</a>') : sprintf($_CLASS['core_user']->get_lang('BBCODE_IS_OFF'), '<a href="' . generate_link('Forums&amp;file=faq&amp;mode=bbcode') . '" target="_phpbbcode">', '</a>'), 'SMILIES_STATUS' => true ? $_CLASS['core_user']->get_lang('SMILIES_ARE_ON') : $_CLASS['core_user']->get_lang('SMILIES_ARE_OFF'), 'IMG_STATUS' => true ? $_CLASS['core_user']->get_lang('IMAGES_ARE_ON') : $_CLASS['core_user']->get_lang('IMAGES_ARE_OFF'), 'FLASH_STATUS' => true ? $_CLASS['core_user']->get_lang('FLASH_IS_ON') : $_CLASS['core_user']->get_lang('FLASH_IS_OFF'), 'L_SIGNATURE_EXPLAIN' => sprintf($_CLASS['core_user']->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_HTML_ALLOWED' => true, 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true));
                break;
            case 'avatar':
                $display_gallery = isset($_POST['display_gallery']);
                $folder = isset($_POST['category']) ? str_replace(array('../', '..\\', './', '.\\'), '', $_POST['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'];
                        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) {
                            $filename = '';
                            $type = $width = $height = 0;
                        } else {
                            $error[] = 'IM_LOST';
                        }
                    }
                    if (empty($error)) {
                        $sql_ary = array('user_avatar' => (string) $filename, 'user_avatar_type' => (int) $type, 'user_avatar_width' => (int) $width, 'user_avatar_height' => (int) $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(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(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(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');
    }