Exemplo n.º 1
4
 /**
  * Show bbcodes and smilies in the quickreply
  * Template data for Ajax submit
  *
  * @param object $event The event object
  * @return null
  * @access public
  */
 public function viewtopic_modify_data($event)
 {
     $forum_id = $event['forum_id'];
     $topic_data = $event['topic_data'];
     $post_list = $event['post_list'];
     $topic_id = $topic_data['topic_id'];
     $s_quick_reply = false;
     if (($this->user->data['is_registered'] || $this->config['qr_allow_for_guests']) && $this->config['allow_quick_reply'] && $topic_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY && $this->auth->acl_get('f_reply', $forum_id)) {
         // Quick reply enabled forum
         $s_quick_reply = $topic_data['forum_status'] == ITEM_UNLOCKED && $topic_data['topic_status'] == ITEM_UNLOCKED || $this->auth->acl_get('m_edit', $forum_id) ? true : false;
     }
     if (!$this->user->data['is_registered'] && $s_quick_reply) {
         add_form_key('posting');
         $s_attach_sig = $this->config['allow_sig'] && $this->user->optionget('attachsig') && $this->auth->acl_get('f_sigs', $forum_id) && $this->auth->acl_get('u_sig');
         $s_smilies = $this->config['allow_smilies'] && $this->user->optionget('smilies') && $this->auth->acl_get('f_smilies', $forum_id);
         $s_bbcode = $this->config['allow_bbcode'] && $this->user->optionget('bbcode') && $this->auth->acl_get('f_bbcode', $forum_id);
         $s_notify = false;
         $qr_hidden_fields = array('topic_cur_post_id' => (int) $topic_data['topic_last_post_id'], 'lastclick' => (int) time(), 'topic_id' => (int) $topic_data['topic_id'], 'forum_id' => (int) $forum_id);
         // Originally we use checkboxes and check with isset(), so we only provide them if they would be checked
         !$s_bbcode ? $qr_hidden_fields['disable_bbcode'] = 1 : true;
         !$s_smilies ? $qr_hidden_fields['disable_smilies'] = 1 : true;
         !$this->config['allow_post_links'] ? $qr_hidden_fields['disable_magic_url'] = 1 : true;
         $s_attach_sig ? $qr_hidden_fields['attach_sig'] = 1 : true;
         $s_notify ? $qr_hidden_fields['notify'] = 1 : true;
         $topic_data['topic_status'] == ITEM_LOCKED ? $qr_hidden_fields['lock_topic'] = 1 : true;
         $this->template->assign_vars(array('S_QUICK_REPLY' => true, 'U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}"), 'QR_HIDDEN_FIELDS' => build_hidden_fields($qr_hidden_fields), 'USERNAME' => $this->request->variable('username', '', true)));
         if ($this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
         }
         if ($this->config['enable_post_confirm'] && (isset($captcha) && $captcha->is_solved() === false)) {
             $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template()));
         }
         // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
         if (isset($captcha) && $captcha->is_solved() !== false) {
             $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
         }
     }
     // Ajaxify viewtopic data
     if ($this->request->is_ajax() && $this->request->is_set('qr_request')) {
         if (!$this->user->data['is_registered'] && $this->config['enable_post_confirm']) {
             $captcha = $this->captcha->get_instance($this->config['captcha_plugin']);
             $captcha->init(CONFIRM_POST);
             // Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
             if (isset($captcha) && $captcha->is_solved() !== false) {
                 $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields($captcha->get_hidden_fields()));
             }
         }
         // Fix issues if the inserted post is not the first.
         if ($this->qr_insert && !$this->qr_first) {
             $this->template->alter_block_array('postrow', array('S_FIRST_ROW' => false), false, 'change');
         }
         $page_title = $event['page_title'];
         $this->template->assign_vars(array('S_QUICKREPLY_REQUEST' => true, 'S_QR_NO_FIRST_POST' => $this->qr_insert, 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote']));
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         // Output the page
         page_header($page_title, false, $forum_id);
         page_footer(false, false, false);
         $json_response = new \phpbb\json_response();
         $json_response->send(array('success' => true, 'result' => $this->template->assign_display('@tatiana5_quickreply/quickreply_template.html', '', true), 'insert' => $this->qr_insert));
     }
     if ($s_quick_reply) {
         include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
         // HTML, BBCode, Smilies, Images and Flash status
         $bbcode_status = $this->config['allow_bbcode'] && $this->config['qr_bbcode'] && $this->auth->acl_get('f_bbcode', $forum_id) ? true : false;
         $smilies_status = $this->config['allow_smilies'] && $this->config['qr_smilies'] && $this->auth->acl_get('f_smilies', $forum_id) ? true : false;
         $img_status = $bbcode_status && $this->auth->acl_get('f_img', $forum_id) ? true : false;
         $url_status = $this->config['allow_post_links'] ? true : false;
         $flash_status = $bbcode_status && $this->auth->acl_get('f_flash', $forum_id) && $this->config['allow_post_flash'] ? true : false;
         $quote_status = true;
         // Build custom bbcodes array
         if ($bbcode_status) {
             display_custom_bbcodes();
         }
         // Generate smiley listing
         if ($smilies_status) {
             generate_smilies('inline', $forum_id);
         }
         // Show attachment box for adding attachments if true
         $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$this->config['allow_attachments'] || !$this->auth->acl_get('u_attach') || !$this->auth->acl_get('f_attach', $forum_id) ? '' : '" enctype="multipart/form-data';
         $allowed = $this->auth->acl_get('f_attach', $forum_id) && $this->auth->acl_get('u_attach') && $this->config['allow_attachments'] && $form_enctype;
         $attachment_data = false;
         if ($bbcode_status || $smilies_status || $this->config['qr_attach'] && $allowed) {
             $this->user->add_lang('posting');
         }
         if ($this->config['qr_attach'] && $allowed) {
             $this->template->assign_vars(array('U_QR_ACTION' => append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}") . $form_enctype));
             include_once $this->phpbb_root_path . 'includes/message_parser.' . $this->php_ext;
             $message_parser = new \parse_message();
             $message_parser->set_plupload($this->plupload);
             $message_parser->set_mimetype_guesser($this->mimetype_guesser);
             $message_parser->get_submitted_attachment_data($this->user->data['user_id']);
             $attachment_data = $message_parser->attachment_data;
             $filename_data = $message_parser->filename_data;
             posting_gen_inline_attachments($attachment_data);
             $max_files = $this->auth->acl_get('a_') || $this->auth->acl_get('m_', $forum_id) ? 0 : (int) $this->config['max_attachments'];
             $topic_id = $topic_data['topic_id'];
             $s_action = append_sid("{$this->phpbb_root_path}posting.{$this->php_ext}", "mode=reply&f={$forum_id}&t={$topic_id}");
             $this->plupload->configure($this->cache, $this->template, $s_action, $forum_id, $max_files);
             posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
         }
         $this->template->append_var('QR_HIDDEN_FIELDS', build_hidden_fields(array('qr' => 1, 'qr_cur_post_id' => (int) max($post_list))));
         if ($this->phpbb_extension_manager->is_enabled('rxu/PostsMerging') && $this->user->data['is_registered'] && $this->config['merge_interval']) {
             // Always show the checkbox if PostsMerging extension is installed.
             $this->user->add_lang_ext('rxu/PostsMerging', 'posts_merging');
             $this->template->assign_var('POSTS_MERGING_OPTION', true);
         }
         $this->template->assign_vars(array('S_QR_COLOUR_NICKNAME' => $this->config['qr_color_nickname'], 'S_QR_NOT_CHANGE_SUBJECT' => $this->auth->acl_get('f_qr_change_subject', $forum_id) ? false : true, 'S_QR_COMMA_ENABLE' => $this->config['qr_comma'], 'S_QR_QUICKNICK_ENABLE' => $this->config['qr_quicknick'], 'S_QR_QUICKNICK_REF' => $this->config['qr_quicknick_ref'], 'S_QR_QUICKNICK_PM' => $this->config['qr_quicknick_pm'], 'S_QR_QUICKQUOTE_ENABLE' => $this->config['qr_quickquote'], 'S_QR_QUICKQUOTE_LINK' => $this->config['qr_quickquote_link'], 'S_QR_FULL_QUOTE' => $this->config['qr_full_quote'], 'S_QR_CE_ENABLE' => $this->config['qr_ctrlenter'], 'QR_SOURCE_POST' => $this->config['qr_source_post'], 'S_DISPLAY_USERNAME' => !$this->user->data['is_registered'], 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'MESSAGE' => $this->request->variable('message', '', true), 'READ_POST_IMG' => $this->user->img('icon_post_target', 'POST'), 'S_QR_CAPS_ENABLE' => $this->config['qr_capslock_transfer'], 'S_QR_SHOW_BUTTON_TRANSLIT' => $this->config['qr_show_button_translit'], 'L_FULL_EDITOR' => $this->config['qr_ajax_submit'] ? $this->user->lang['PREVIEW'] : $this->user->lang['FULL_EDITOR'], 'S_QR_AJAX_SUBMIT' => $this->config['qr_ajax_submit'], 'S_QR_AJAX_PAGINATION' => $this->config['qr_ajax_pagination'] && $this->user->data['ajax_pagination'], 'S_QR_ENABLE_SCROLL' => $this->user->data['qr_enable_scroll'], 'S_QR_SCROLL_INTERVAL' => $this->config['qr_scroll_time'], 'S_QR_SOFT_SCROLL' => $this->config['qr_scroll_time'] && $this->user->data['qr_soft_scroll'], 'S_QR_ALLOWED_GUEST' => $this->config['qr_allow_for_guests'] && $this->user->data['user_id'] == ANONYMOUS, 'S_ABBC3_INSTALLED' => $this->phpbb_extension_manager->is_enabled('vse/abbc3'), 'S_QR_SHOW_ATTACH_BOX' => $this->config['qr_attach'] && $allowed, 'S_ATTACH_DATA' => $attachment_data ? json_encode($attachment_data) : '[]'));
         $add_re = $this->config['qr_enable_re'] ? 'Re: ' : '';
         $this->template->assign_var('SUBJECT', $this->request->variable('subject', $add_re . censor_text($topic_data['topic_title']), true));
     }
     $this->template->assign_vars(array('QR_HIDE_POSTS_SUBJECT' => $this->config['qr_show_subjects'] ? false : true));
 }
Exemplo n.º 2
0
 /**
  * Display the edit form
  *
  * @param bool $preview
  */
 protected function display_edit_form($preview = false)
 {
     generate_smilies('inline', 0);
     display_custom_bbcodes();
     add_form_key('article');
     $this->template->assign_vars(array('S_PREVIEW' => $preview, 'TITLE' => $this->data['article_title'], 'MESSAGE' => $preview ? $this->data['article_text'] : $this->message_parser->message, 'PREVIEW_MESSAGE' => $this->message_parser->message, 'SOURCES' => $this->data['article_sources'], 'S_BBCODE_ALLOWED' => $this->option['bbcode'], 'S_LINKS_ALLOWED' => $this->option['url'], 'S_BBCODE_IMG' => $this->option['img'], 'S_BBCODE_FLASH' => $this->option['flash'], 'S_BBCODE_QUOTE' => $this->option['quote'], 'BBCODE_STATUS' => $this->option['bbcode'] ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $this->option['img'] ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $this->option['flash'] ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $this->option['smilies'] ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $this->option['bbcode'] && $this->option['url'] ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'EDIT_REASON' => $this->data['article_edit_reason'], 'TOPIC_ID' => (int) $this->data['article_topic_id'], 'S_AUTH_ACTIVATE' => $this->auth->acl_get('u_wiki_set_active'), 'S_AUTH_EDIT_TOPIC' => $this->auth->acl_get('u_wiki_edit_topic'), 'S_AUTH_REDIRECT' => $this->auth->acl_get('u_wiki_set_redirect'), 'S_AUTH_STICKY' => $this->auth->acl_get('u_wiki_set_sticky'), 'S_ACTIVE' => $preview ? $this->data['article_approved'] : 1, 'S_STICKY' => $this->data['article_sticky'], 'ARTICLE_REDIRECT' => $this->data['article_redirect'], 'ARTICLE_DESCRIPTION' => $this->data['article_description']));
 }
Exemplo n.º 3
0
 public function main($id, $mode)
 {
     global $user, $request, $template;
     global $config, $phpbb_root_path, $phpEx, $phpbb_container;
     $user->add_lang(array('acp/board', 'posting'));
     $this->tpl_name = 'acp_contact';
     $this->page_title = 'ACP_CONTACT_SETTINGS';
     $form_name = 'acp_contact';
     add_form_key($form_name);
     $error = '';
     if (!function_exists('display_custom_bbcodes')) {
         include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
     }
     if (!class_exists('parse_message')) {
         include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
     }
     /* @var $config_text \phpbb\config\db_text */
     $config_text = $phpbb_container->get('config_text');
     $contact_admin_data = $config_text->get_array(array('contact_admin_info', 'contact_admin_info_uid', 'contact_admin_info_bitfield', 'contact_admin_info_flags'));
     $contact_admin_info = $contact_admin_data['contact_admin_info'];
     $contact_admin_info_uid = $contact_admin_data['contact_admin_info_uid'];
     $contact_admin_info_bitfield = $contact_admin_data['contact_admin_info_bitfield'];
     $contact_admin_info_flags = $contact_admin_data['contact_admin_info_flags'];
     if ($request->is_set_post('submit') || $request->is_set_post('preview')) {
         if (!check_form_key($form_name)) {
             $error = $user->lang('FORM_INVALID');
         }
         $contact_admin_info = $request->variable('contact_admin_info', '', true);
         generate_text_for_storage($contact_admin_info, $contact_admin_info_uid, $contact_admin_info_bitfield, $contact_admin_info_flags, !$request->variable('disable_bbcode', false), !$request->variable('disable_magic_url', false), !$request->variable('disable_smilies', false));
         if (empty($error) && $request->is_set_post('submit')) {
             $config->set('contact_admin_form_enable', $request->variable('contact_admin_form_enable', false));
             $config_text->set_array(array('contact_admin_info' => $contact_admin_info, 'contact_admin_info_uid' => $contact_admin_info_uid, 'contact_admin_info_bitfield' => $contact_admin_info_bitfield, 'contact_admin_info_flags' => $contact_admin_info_flags));
             trigger_error($user->lang['CONTACT_US_INFO_UPDATED'] . adm_back_link($this->u_action));
         }
     }
     $contact_admin_info_preview = '';
     if ($request->is_set_post('preview')) {
         $contact_admin_info_preview = generate_text_for_display($contact_admin_info, $contact_admin_info_uid, $contact_admin_info_bitfield, $contact_admin_info_flags);
     }
     $contact_admin_edit = generate_text_for_edit($contact_admin_info, $contact_admin_info_uid, $contact_admin_info_flags);
     /** @var \phpbb\controller\helper $controller_helper */
     $controller_helper = $phpbb_container->get('controller.helper');
     $template->assign_vars(array('ERRORS' => $error, 'CONTACT_ENABLED' => $config['contact_admin_form_enable'], 'CONTACT_US_INFO' => $contact_admin_edit['text'], 'CONTACT_US_INFO_PREVIEW' => $contact_admin_info_preview, 'S_BBCODE_DISABLE_CHECKED' => !$contact_admin_edit['allow_bbcode'], 'S_SMILIES_DISABLE_CHECKED' => !$contact_admin_edit['allow_smilies'], 'S_MAGIC_URL_DISABLE_CHECKED' => !$contact_admin_edit['allow_urls'], 'BBCODE_STATUS' => $user->lang('BBCODE_IS_ON', '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'), 'SMILIES_STATUS' => $user->lang['SMILIES_ARE_ON'], 'IMG_STATUS' => $user->lang['IMAGES_ARE_ON'], 'FLASH_STATUS' => $user->lang['FLASH_IS_ON'], 'URL_STATUS' => $user->lang['URL_IS_ON'], 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true));
     // Assigning custom bbcodes
     display_custom_bbcodes();
 }
Exemplo n.º 4
0
 /**
  * Controller for /post
  *
  * @throws http_exception
  * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
  */
 public function post()
 {
     if (!$this->is_available()) {
         throw new http_exception(404, 'IDEAS_NOT_AVAILABLE');
     }
     if ($this->user->data['user_id'] == ANONYMOUS) {
         throw new http_exception(404, 'LOGGED_OUT');
     }
     $this->language->add_lang('posting');
     if (!function_exists('submit_post')) {
         include $this->root_path . 'includes/functions_posting.' . $this->php_ext;
     }
     if (!function_exists('display_custom_bbcodes')) {
         include $this->root_path . 'includes/functions_display.' . $this->php_ext;
     }
     $mode = $this->request->variable('mode', '');
     $title = $this->request->variable('title', '', true);
     $message = $this->request->variable('message', '', true);
     if ($mode === 'submit') {
         $submit = $this->ideas->submit($title, $message, $this->user->data['user_id']);
         if (is_array($submit)) {
             $this->template->assign_vars(array('ERROR' => implode('<br />', $submit), 'MESSAGE' => $message));
         } else {
             return new RedirectResponse($this->helper->route('phpbb_ideas_idea_controller', array('idea_id' => $submit)));
         }
     }
     display_custom_bbcodes();
     generate_smilies('inline', 0);
     // BBCode, Smilies, Images URL, and Flash statuses
     $bbcode_status = (bool) $this->config['allow_bbcode'] && $this->auth->acl_get('f_bbcode', $this->config['ideas_forum_id']);
     $smilies_status = (bool) $this->config['allow_smilies'] && $this->auth->acl_get('f_smilies', $this->config['ideas_forum_id']);
     $img_status = (bool) $bbcode_status && $this->auth->acl_get('f_img', $this->config['ideas_forum_id']);
     $url_status = (bool) $this->config['allow_post_links'];
     $flash_status = (bool) $bbcode_status && $this->auth->acl_get('f_flash', $this->config['ideas_forum_id']) && $this->config['allow_post_flash'];
     $this->template->assign_vars(array('TITLE' => $title, 'S_POST_ACTION' => $this->helper->route('phpbb_ideas_post_controller', array('mode' => 'submit')), 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => true, 'BBCODE_STATUS' => $this->language->lang($bbcode_status ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF', '<a href="' . $this->helper->route('phpbb_help_bbcode_controller') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $this->language->lang('IMAGES_ARE_ON') : $this->language->lang('IMAGES_ARE_OFF'), 'FLASH_STATUS' => $flash_status ? $this->language->lang('FLASH_IS_ON') : $this->language->lang('FLASH_IS_OFF'), 'URL_STATUS' => $bbcode_status && $url_status ? $this->language->lang('URL_IS_ON') : $this->language->lang('URL_IS_OFF'), 'SMILIES_STATUS' => $smilies_status ? $this->language->lang('SMILIES_ARE_ON') : $this->language->lang('SMILIES_ARE_OFF')));
     // Assign breadcrumb template vars
     $this->template->assign_block_vars_array('navlinks', array(array('U_VIEW_FORUM' => $this->helper->route('phpbb_ideas_index_controller'), 'FORUM_NAME' => $this->language->lang('IDEAS')), array('U_VIEW_FORUM' => $this->helper->route('phpbb_ideas_post_controller'), 'FORUM_NAME' => $this->language->lang('NEW_IDEA'))));
     return $this->helper->render('idea_new.html', $this->language->lang('NEW_IDEA'));
 }
Exemplo n.º 5
0
    public function handle_video()
    {
        if (!$this->auth->acl_get('u_video_view_full')) {
            trigger_error($this->user->lang['UNAUTHED']);
        }
        // Initial var setup
        $video_id = $this->request->variable('id', 0);
        $video_url = $this->request->variable('video_url', '', true);
        $video_title = $this->request->variable('video_title', '', true);
        $video_cat_id = $this->request->variable('cid', 0);
        $video_cat_ids = $this->request->variable('id', 0);
        $username = $this->request->variable('username', '', true);
        $user_id = $this->request->variable('user_id', 0);
        $youtube_id = $this->request->variable('youtube_id', '', true);
        $create_time = $this->request->variable('create_time', '');
        $video_views = $this->request->variable('video_views', 0);
        $sql_start = $this->request->variable('start', 0);
        $sql_limit = $this->request->variable('limit', 10);
        $sql_limits = $this->request->variable('limit', $this->config['comments_per_page']);
        //comments
        // Comments
        $cmnt_id = $this->request->variable('cmntid', 0);
        $cmnt_video_id = $this->request->variable('v', 0);
        $cmnt_text = utf8_normalize_nfc($this->request->variable('cmnt_text', '', true));
        $mode = $this->request->variable('mode', '');
        $submit = isset($_POST['submit']) ? true : false;
        // Determine board url - we may need it later
        $board_url = generate_board_url() . '/';
        $web_path = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH ? $board_url : $this->phpbb_root_path;
        if (!$this->config['google_api_key']) {
            if ($this->auth->acl_get('a_')) {
                trigger_error($this->user->lang['NO_KEY_ADMIN']);
            } else {
                trigger_error($this->user->lang['NO_KEY_USER']);
            }
        }
        /**
         * Get youtube video ID from URL
         * From: http://halgatewood.com/php-get-the-youtube-video-id-from-a-youtube-url/
         */
        function getYouTubeIdFromURL($url)
        {
            $pattern = '/(?:youtube\\.com\\/(?:[^\\/]+\\/.+\\/|(?:v|e(?:mbed)?)\\/|.*[?&]v=)|youtu\\.be\\/)([^"&?\\/ ]{11})/i';
            preg_match($pattern, $url, $matches);
            return isset($matches[1]) ? $matches[1] : false;
        }
        $youtube_id = getYouTubeIdFromURL($video_url);
        $jsonURL = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id={$youtube_id}&key={$this->config['google_api_key']}&type=video&part=snippet");
        $json = json_decode($jsonURL);
        if (isset($json->items[0]->snippet)) {
            $video_title = $json->items[0]->snippet->title;
        }
        $sql_ary = array('video_id' => $video_id, 'video_url' => $video_url, 'video_title' => $video_title, 'video_cat_id' => $video_cat_id, 'username' => $username, 'user_id' => $user_id, 'youtube_id' => $youtube_id, 'create_time' => (int) time(), 'video_views' => $video_views);
        $error = $row = array();
        $current_time = time();
        $this->template->assign_vars(array('S_NEW_VIDEO' => $this->auth->acl_get('u_video_post') ? true : false, 'SCRIPT_NAME' => 'video', 'U_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller')));
        $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_INDEX'], 'U_VIEW_FORUM' => $this->helper->route('dmzx_youtubegallery_controller')));
        switch ($mode) {
            case 'submit':
                // User is a bot?!
                if ($this->user->data['is_bot']) {
                    redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"));
                }
                $redirect_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                // Is a guest?!
                if ($this->user->data['user_id'] == ANONYMOUS) {
                    login_box($redirect_url);
                }
                // Can post?!
                if (!$this->auth->acl_get('u_video_post')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $l_title = $this->user->lang['VIDEO_SUBMIT'];
                $template_html = 'video_editor.html';
                $s_action = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                $s_hidden_fields = '';
                $form_enctype = '';
                add_form_key('postform');
                // List of categories
                $sql = 'SELECT *
					FROM ' . $this->video_cat_table . '
					ORDER BY video_cat_id DESC';
                $result = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('cat', array('VIDEO_CAT_ID' => censor_text($row['video_cat_id']), 'VIDEO_CAT_TITLE' => censor_text($row['video_cat_title'])));
                }
                // Start assigning vars for main posting page ...
                $this->template->assign_vars(array('S_USER_ID' => $this->user->data['user_id'], 'S_USERNAME' => $this->user->data['username'], 'S_FORM_ENCTYPE' => $form_enctype, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'ERROR' => sizeof($error) ? implode('<br />', $error) : ''));
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_SUBMIT']));
                add_form_key('postform');
                if ($submit) {
                    if (!check_form_key('postform')) {
                        trigger_error('FORM_INVALID');
                    }
                }
                switch ($submit) {
                    case 'add':
                        if ($video_url == '') {
                            $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit'));
                            $message = $this->user->lang['NEED_VIDEO_URL'];
                            meta_refresh(3, $meta_info);
                            $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                            trigger_error($message);
                        } else {
                            $this->db->sql_query('INSERT INTO ' . $this->video_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary));
                            $u_action = $this->helper->route('dmzx_youtubegallery_controller');
                            $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                            $message = $this->user->lang['VIDEO_CREATED'];
                            meta_refresh(3, $meta_info);
                            $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                            trigger_error($message);
                        }
                        break;
                }
                break;
            case 'comment':
                $l_title = $this->user->lang['VIDEO_CMNT_SUBMIT'];
                $template_html = '@dmzx_youtubegallery/video_cmnt_editor.html';
                if (!$this->config['enable_comments']) {
                    trigger_error($this->user->lang['COMMENTS_DISABLED']);
                }
                // User is a bot?!
                if ($this->user->data['is_bot']) {
                    redirect(append_sid("{$this->phpbb_root_path}index.{$this->phpEx}"));
                }
                // Can post?!
                if (!$this->auth->acl_get('u_video_comment')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $redirect_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                // Is a guest?!
                if ($this->user->data['user_id'] == ANONYMOUS) {
                    login_box($redirect_url);
                }
                if (!function_exists('generate_smilies')) {
                    include $this->phpbb_root_path . 'includes/functions_posting.' . $this->phpEx;
                }
                if (!function_exists('display_custom_bbcodes')) {
                    include $this->phpbb_root_path . 'includes/functions_display.' . $this->phpEx;
                }
                //Settings for comments
                $this->user->setup('posting');
                display_custom_bbcodes();
                generate_smilies('inline', 0);
                $bbcode_status = $this->config['allow_bbcode'] ? true : false;
                $smilies_status = $this->config['allow_smilies'] ? true : false;
                $img_status = $bbcode_status ? true : false;
                $url_status = $this->config['allow_post_links'] ? true : false;
                $flash_status = $bbcode_status && $this->config['allow_post_flash'] ? true : false;
                $quote_status = true;
                $video_id = $this->request->variable('v', 0);
                $uid = $bitfield = $options = '';
                $allow_bbcode = $allow_urls = $allow_smilies = true;
                $s_action = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                $s_hidden_fields = '';
                $form_enctype = '';
                add_form_key('postform');
                // Start assigning vars for main posting page ...
                $this->template->assign_vars(array('VIDEO_ID' => (int) $video_id, 'S_FORM_ENCTYPE' => $form_enctype, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_QUOTE' => $quote_status));
                if (isset($_POST['submit'])) {
                    if (!check_form_key('postform')) {
                        trigger_error('FORM_INVALID');
                    }
                    $video_id = $this->request->variable('v', 0);
                    // Get video to redirect :D
                    $message = $this->request->variable('cmnt_text', '', true);
                    generate_text_for_storage($message, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
                    $data = array('cmnt_video_id' => $this->request->variable('cmnt_video_id', 0), 'cmnt_poster_id' => $this->user->data['user_id'], 'cmnt_text' => $message, 'create_time' => time(), 'bbcode_uid' => $uid, 'bbcode_bitfield' => $bitfield, 'bbcode_options' => $options);
                    if ($message == '') {
                        $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => (int) $video_id));
                        $message = $this->user->lang['NEED_VIDEO_MESSAGE'];
                        meta_refresh(3, $meta_info);
                        $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                        trigger_error($message);
                    } else {
                        $this->db->sql_query('INSERT INTO ' . $this->video_cmnts_table . ' ' . $this->db->sql_build_array('INSERT', $data));
                        $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                        $message = $this->user->lang['COMMENT_CREATED'];
                        meta_refresh(3, $meta_info);
                        $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                        trigger_error($message);
                    }
                }
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->user->lang['VIDEO_CMNT_SUBMIT']));
                break;
            case 'delcmnt':
                if (!$this->auth->acl_get('u_video_comment_delete')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $video_id = $this->request->variable('v', 0);
                // Get video to redirect :D
                if (confirm_box(true)) {
                    $sql = 'DELETE FROM ' . $this->video_cmnts_table . '
						WHERE cmnt_id = ' . (int) $cmnt_id;
                    $this->db->sql_query($sql);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                    $message = $this->user->lang['COMMENT_DELETED_SUCCESS'];
                    meta_refresh(1, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                } else {
                    $s_hidden_fields = build_hidden_fields(array('id' => $cmnt_id, 'mode' => 'delcmnt'));
                    confirm_box(false, $this->user->lang['DELETE_COMMENT_CONFIRM'], $s_hidden_fields);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => (int) $video_id));
                    meta_refresh(1, $meta_info);
                }
                break;
            case 'delete':
                if (!$this->auth->acl_get('u_video_delete')) {
                    trigger_error($this->user->lang['UNAUTHED']);
                }
                $l_title = $this->user->lang['DELETE_VIDEO'];
                if (confirm_box(true)) {
                    $sql = 'DELETE FROM ' . $this->video_table . '
						WHERE video_id = ' . $video_id;
                    $this->db->sql_query($sql);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                    $message = $this->user->lang['VIDEO_DELETED'];
                    meta_refresh(3, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                } else {
                    $s_hidden_fields = build_hidden_fields(array('mode' => 'delete', 'submit' => true, 'video_id' => $video_id));
                    confirm_box(false, $this->user->lang['DELETE_VIDEO'], $s_hidden_fields);
                    $meta_info = $this->helper->route('dmzx_youtubegallery_controller');
                    $message = $this->user->lang['RETURN_TO_VIDEO_INDEX'];
                    meta_refresh(3, $meta_info);
                    $message .= '<br /><br />' . sprintf($this->user->lang['PAGE_RETURN'], '<a href="' . $meta_info . '">', '</a>');
                    trigger_error($message);
                }
                break;
            case 'view':
                if (!$this->auth->acl_get('u_video_view')) {
                    trigger_error($this->user->lang['VIDEO_UNAUTHED']);
                }
                // Update video view... but only for humans
                if (isset($this->user->data['session_page']) && !$this->user->data['is_bot']) {
                    $sql = 'UPDATE ' . $this->video_table . '
					SET video_views = video_views + 1
					WHERE video_id = ' . $video_id;
                    $this->db->sql_query($sql);
                }
                $sql_ary = array('SELECT' => 'v.*, u.*', 'FROM' => array($this->video_table => 'v', USERS_TABLE => 'u'), 'WHERE' => 'v.video_id = ' . (int) $video_id . ' and u.user_id = v.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $page_title = $row['video_title'];
                $user_id = $row['user_id'];
                $flash_status = $this->config['allow_post_flash'] ? true : false;
                $delete_allowed = ($this->auth->acl_get('a_') or $this->auth->acl_get('m_') || $this->user->data['is_registered'] && $this->user->data['user_id'] == $row['user_id'] && $this->auth->acl_get('u_video_delete'));
                $this->template->assign_vars(array('VIDEO_ID' => censor_text($row['video_id']), 'VIDEO_TITLE' => censor_text($row['video_title']), 'VIDEO_VIEWS' => $row['video_views'], 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'YOUTUBE_ID' => censor_text($row['youtube_id']), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'YOUTUBE_VIDEO' => 'http://www.youtube.com/watch?v=' . $row['youtube_id'], 'VIDEO_LINK' => generate_board_url() . $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'VIDEO_LINK_FLASH' => 'http://www.youtube.com/v/' . $row['youtube_id'], 'U_USER_VIDEOS' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $this->user->data['user_id'])), 'U_DELETE' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'delete', 'id' => $row['video_id'])), 'DELETE_ALLOW' => $delete_allowed, 'S_BBCODE_FLASH' => $flash_status, 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'S_VIDEO_WIDTH' => $this->config['video_width'], 'S_VIDEO_HEIGHT' => $this->config['video_height'], 'U_POST_COMMENT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'comment', 'v' => $row['video_id'])), 'S_ENABLE_COMMENTS' => $this->config['enable_comments'], 'S_POST_COMMENT' => $this->auth->acl_get('u_video_comment')));
                // Comments
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $video_id));
                $sql_ary = array('SELECT' => 'v.*, cmnt.*, u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cmnts_table => 'cmnt', USERS_TABLE => 'u'), 'WHERE' => 'v.video_id = ' . (int) $video_id . '
						AND cmnt.cmnt_video_id = v.video_id
						AND u.user_id = cmnt.cmnt_poster_id', 'ORDER_BY' => 'cmnt.cmnt_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limits, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $delete_cmnt_allowed = ($this->auth->acl_get('a_') or $this->auth->acl_get('m_') || $this->user->data['is_registered'] && $this->user->data['user_id'] == $row['user_id'] && $this->auth->acl_get('u_video_comment_delete'));
                    $text = generate_text_for_display($row['cmnt_text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
                    $this->template->assign_block_vars('commentrow', array('COMMENT_ID' => $row['cmnt_id'], 'COMMENT_TEXT' => $text, 'COMMENT_TIME' => $this->user->format_date($row['create_time']), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_DELETE_ALLOWED' => $delete_cmnt_allowed, 'U_DELETE' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'delcmnt', 'cmntid' => (int) $row['cmnt_id'], 'v' => (int) $row['cmnt_video_id']))));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as comment_count
				FROM ' . $this->video_cmnts_table . '
				WHERE cmnt_video_id = ' . (int) $video_id;
                $result = $this->db->sql_query($sql);
                $videorow['comment_count'] = $this->db->sql_fetchfield('comment_count');
                $this->db->sql_freeresult($result);
                //Start pagination
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['comment_count'], $sql_limits, $sql_start);
                $this->template->assign_vars(array('TOTAL_COMMENTS' => $videorow['comment_count'] == 1 ? $this->user->lang['LIST_COMMENT'] : sprintf($this->user->lang['LIST_COMMENTS'], $videorow['comment_count'])));
                //End pagination
                // Count the videos user video ...
                $sql = 'SELECT COUNT(video_id) AS total_videos
				FROM ' . $this->video_table . '
				WHERE user_id = ' . (int) $user_id;
                $result = $this->db->sql_query($sql);
                $total_videos = (int) $this->db->sql_fetchfield('total_videos');
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $total_videos));
                // Count the video comments ...
                $sql_cmnts = 'SELECT COUNT(cmnt_id) AS total_comments
				FROM ' . $this->video_cmnts_table . '
				WHERE cmnt_video_id = ' . (int) $video_id;
                $result = $this->db->sql_query($sql_cmnts);
                $total_comments = (int) $this->db->sql_fetchfield('total_comments');
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('TOTAL_COMMENTS_TITLE' => $total_comments));
                $l_title = $page_title;
                $template_html = 'video_view.html';
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $page_title));
                break;
            case 'cat':
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $video_cat_ids));
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'v.video_cat_id = ' . $video_cat_ids . '
					AND ct.video_cat_id = ' . $video_cat_ids . '
					AND v.user_id = u.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_VIDEO_THUMBNAIL' => 'http://img.youtube.com/vi/' . censor_text($row['youtube_id']) . '/default.jpg'));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table . '
				WHERE video_cat_id = ' . (int) $video_cat_ids;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                $sql = 'SELECT *
				FROM ' . $this->video_cat_table . '
				WHERE video_cat_id = ' . (int) $video_cat_ids;
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('CAT_NAME' => $row['video_cat_title']));
                $l_title = $row['video_cat_title'];
                $template_html = 'video_cat.html';
                $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $row['video_cat_title']));
                break;
            case 'user_videos':
                $this->template->assign_vars(array('S_SEARCH_USER_VIDEO' => true));
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $user_id));
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'u.user_id = v.user_id
					AND ct.video_cat_id = v.video_cat_id
					AND u.user_id = ' . $user_id, 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'S_VIDEO_THUMBNAIL' => 'http://img.youtube.com/vi/' . censor_text($row['youtube_id']) . '/default.jpg'));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table . '
				WHERE user_id = ' . $user_id;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                $l_title = $this->user->lang['USER_VIDEOS'];
                $template_html = 'video_search.html';
                break;
            default:
                //Listing categories
                $sql = 'SELECT *
				FROM ' . $this->video_cat_table . "\n\t\t\t\tORDER BY video_cat_id";
                $res = $this->db->sql_query($sql);
                while ($row = $this->db->sql_fetchrow($res)) {
                    $this->template->assign_block_vars('videocat', array('VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id']))));
                }
                // Count the videos ...
                $sql = 'SELECT COUNT(video_id) AS total_videos
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $total_videos = (int) $this->db->sql_fetchfield('total_videos');
                $this->db->sql_freeresult($result);
                // Count the videos categories ...
                $sql = 'SELECT COUNT(video_cat_id) AS total_categories
				FROM ' . $this->video_cat_table . '';
                $result = $this->db->sql_query($sql);
                $total_categories = (int) $this->db->sql_fetchfield('total_categories');
                $this->db->sql_freeresult($result);
                // Count the videos views ...
                $sql = 'SELECT SUM(video_views) AS total_views
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $total_views = (int) $this->db->sql_fetchfield('total_views');
                $this->db->sql_freeresult($result);
                $total_videos;
                // Count the videos comments ...
                $sql = 'SELECT COUNT(cmnt_id) AS total_comments
				FROM ' . $this->video_cmnts_table;
                $result = $this->db->sql_query($sql);
                $total_comments = (int) $this->db->sql_fetchfield('total_comments');
                $this->db->sql_freeresult($result);
                $l_title = $this->user->lang['VIDEO_INDEX'];
                $template_html = 'video_body.html';
                $l_total_video_s = $total_videos == 0 ? 'TOTAL_VIDEO_ZERO' : 'TOTAL_VIDEOS_OTHER';
                $l_total_category_s = $total_categories == 0 ? 'TOTAL_CATEGORY_ZERO' : 'TOTAL_CATEGORIES_OTHER';
                $l_total_view_s = $total_views == 0 ? 'TOTAL_VIEW_ZERO' : 'TOTAL_VIEWS_OTHER';
                $l_total_comment_s = $total_comments == 0 ? 'TOTAL_COMMENT_ZERO' : 'TOTAL_COMMENTS_OTHER';
                $this->template->assign_vars(array('U_VIDEO_SUBMIT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'submit')), 'VIDEOSUBMIT' => $this->auth->acl_get('u_video_post'), 'U_MY_VIDEOS' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'user_videos', 'user_id' => $this->user->data['user_id'])), 'BUTTON_VIDEO_NEW' => "{$web_path}styles/" . $this->user->lang_name . '/button_video_new.gif', 'TOTAL_VIDEOS_INDEX' => sprintf($this->user->lang[$l_total_video_s], $total_videos), 'TOTAL_CATEGORIES' => sprintf($this->user->lang[$l_total_category_s], $total_categories), 'TOTAL_VIEWS' => sprintf($this->user->lang[$l_total_view_s], $total_views), 'TOTAL_COMMENTS' => sprintf($this->user->lang[$l_total_comment_s], $total_comments)));
                $sql_limit = $sql_limit > 10 ? 10 : $sql_limit;
                $pagination_url = $this->helper->route('dmzx_youtubegallery_controller');
                $sql_ary = array('SELECT' => 'v.*,
				ct.video_cat_title,ct.video_cat_id,
				u.username,u.user_colour,u.user_id', 'FROM' => array($this->video_table => 'v', $this->video_cat_table => 'ct', USERS_TABLE => 'u'), 'WHERE' => 'ct.video_cat_id = v.video_cat_id AND u.user_id = v.user_id', 'ORDER_BY' => 'v.video_id DESC');
                $sql = $this->db->sql_build_query('SELECT', $sql_ary);
                $result = $this->db->sql_query_limit($sql, $sql_limit, $sql_start);
                while ($row = $this->db->sql_fetchrow($result)) {
                    $this->template->assign_block_vars('video', array('VIDEO_TITLE' => $row['video_title'], 'VIDEO_CAT_ID' => $row['video_cat_id'], 'VIDEO_CAT_TITLE' => $row['video_cat_title'], 'VIDEO_VIEWS' => $row['video_views'], 'U_CAT' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'cat', 'id' => $row['video_cat_id'])), 'VIDEO_TIME' => $this->user->format_date($row['create_time']), 'VIDEO_ID' => censor_text($row['video_id']), 'U_VIEW_VIDEO' => $this->helper->route('dmzx_youtubegallery_controller', array('mode' => 'view', 'id' => $row['video_id'])), 'U_POSTER' => append_sid("{$this->phpbb_root_path}memberlist.{$this->phpEx}", array('mode' => 'viewprofile', 'u' => $row['user_id'])), 'USERNAME' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'YOUTUBE_ID' => censor_text($row['youtube_id'])));
                }
                $this->db->sql_freeresult($result);
                // We need another query for the video count
                $sql = 'SELECT COUNT(*) as video_count
				FROM ' . $this->video_table;
                $result = $this->db->sql_query($sql);
                $videorow['video_count'] = $this->db->sql_fetchfield('video_count');
                $this->db->sql_freeresult($result);
                $start = $this->request->variable('start', 0);
                $this->pagination->generate_template_pagination($pagination_url, 'pagination', 'start', $videorow['video_count'], $sql_limit, $sql_start);
                $this->template->assign_vars(array('TOTAL_VIDEOS' => $videorow['video_count'] == 1 ? $this->user->lang['LIST_VIDEO'] : sprintf($this->user->lang['LIST_VIDEOS'], $videorow['video_count'])));
                break;
        }
        if (!$row) {
            $this->template->assign_vars(array('NO_ENTRY' => $this->user->lang['NO_VIDEOS']));
        }
        // Output page
        page_header($l_title, false);
        $this->template->set_filenames(array('body' => $template_html));
        make_jumpbox(append_sid("{$this->phpbb_root_path}viewforum.{$this->phpEx}"));
        page_footer();
    }
/**
* Handle basic posting setup and some basic checks
*/
function handle_basic_posting_data($check = false, $page = 'blog', $mode = 'add')
{
    global $auth, $blog_attachment, $blog_id, $config, $db, $template, $user, $phpbb_root_path, $phpEx, $category_ary;
    $submit = isset($_POST['submit']) ? true : false;
    $preview = isset($_POST['preview']) ? true : false;
    $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || isset($_POST['cancel_unglobalise']) ? true : false;
    $submitted = $submit || $preview || $refresh ? true : false;
    // shortcut for any of the 3 above
    if ($check) {
        $error = array();
        // check the captcha
        if ($mode == 'add') {
            if (!handle_captcha('check')) {
                $error[] = $user->lang['CONFIRM_CODE_WRONG'];
            }
        }
        // check the form key
        if (!check_form_key('postform')) {
            $error[] = $user->lang['FORM_INVALID'];
        }
        return $error;
    } else {
        $above_subject = $above_message = $above_submit = $panel_data = '';
        $panels = array('options-panel' => $user->lang['OPTIONS']);
        if ($page == 'blog') {
            $category_list = make_category_select($category_ary);
            if ($category_list) {
                $panels['categories-panel'] = $user->lang['CATEGORIES'];
            }
            $panels['poll-panel'] = $user->lang['ADD_POLL'];
            if ($user->data['is_registered']) {
                // Build permissions box
                permission_settings_builder(true, $mode);
                $panels['permissions-panel'] = $user->lang['PERMISSIONS'];
            }
            // Some variables
            $template->assign_vars(array('CATEGORY_LIST' => $category_list, 'S_CAT_0_SELECTED' => is_array($category_ary) && in_array(0, $category_ary), 'S_SHOW_POLL_BOX' => true));
        }
        if ($mode == 'add') {
            // setup the captcha
            handle_captcha('build');
        }
        // Subscriptions
        if ($config['user_blog_subscription_enabled'] && $user->data['is_registered']) {
            $panels['subscriptions-panel'] = $user->lang['SUBSCRIPTION'];
            $subscription_types = get_blog_subscription_types();
            $subscribed = array();
            if ($page == 'blog' && $mode == 'add' && !$submitted) {
                // check default subscription settings from user_settings
                global $user_settings;
                get_user_settings($user->data['user_id']);
                if (isset($user_settings[$user->data['user_id']])) {
                    foreach ($subscription_types as $type => $name) {
                        // Bitwise check
                        if ($user_settings[$user->data['user_id']]['blog_subscription_default'] & $type) {
                            $subscribed[$type] = true;
                        }
                    }
                }
            } else {
                if (!$submitted) {
                    // check set subscription settings
                    $sql = 'SELECT * FROM ' . BLOGS_SUBSCRIPTION_TABLE . '
					WHERE sub_user_id = ' . $user->data['user_id'] . '
						AND blog_id = ' . intval($blog_id);
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $subscribed[$row['sub_type']] = true;
                    }
                }
            }
            foreach ($subscription_types as $type => $name) {
                $template->assign_block_vars('subscriptions', array('TYPE' => 'subscription_' . $type, 'NAME' => isset($user->lang[$name]) ? $user->lang[$name] : $name, 'S_CHECKED' => $submitted && request_var('subscription_' . $type, false) || isset($subscribed[$type]) ? true : false));
            }
        }
        // Attachments
        $attachment_data = $blog_attachment->attachment_data;
        $filename_data = $blog_attachment->filename_data;
        $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') ? '' : ' enctype="multipart/form-data"';
        posting_gen_inline_attachments($attachment_data);
        if ($auth->acl_get('u_blogattach') && $config['allow_attachments'] && $form_enctype) {
            $allowed_extensions = $blog_attachment->obtain_blog_attach_extensions();
            if (sizeof($allowed_extensions['_allowed_'])) {
                $blog_attachment->posting_gen_attachment_entry($attachment_data, $filename_data);
                $panels['attach-panel'] = $user->lang['ADD_ATTACHMENT'];
            }
        }
        // Add the forum key
        add_form_key('postform');
        // Generate smiley listing
        generate_smilies('inline', false);
        // Build custom bbcodes array
        display_custom_bbcodes();
        $temp = compact('page', 'mode', 'panels', 'panel_data', 'above_subject', 'above_message', 'above_submit');
        blog_plugins::plugin_do_ref('function_handle_basic_posting_data', $temp);
        extract($temp);
        $template->assign_vars(array('EXTRA_ABOVE_SUBJECT' => $above_subject, 'EXTRA_ABOVE_MESSAGE' => $above_message, 'EXTRA_ABOVE_SUBMIT' => $above_submit, 'EXTRA_PANELS' => $panel_data, 'JS_PANELS_LIST' => "'" . implode("', '", array_keys($panels)) . "'", 'UA_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=popup", false), 'S_BLOG' => $page == 'blog' ? true : false, 'S_REPLY' => $page == 'reply' ? true : false, 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']) ? true : false, 'S_FORM_ENCTYPE' => $form_enctype));
        foreach ($panels as $name => $title) {
            $template->assign_vars(array('S_' . strtoupper(str_replace('-', '_', $name)) => true));
            $template->assign_block_vars('panel_list', array('NAME' => $name, 'TITLE' => $title));
        }
    }
}
Exemplo n.º 7
0
$s_hidden_fields = $mode == 'reply' || $mode == 'quote' ? '<input type="hidden" name="topic_cur_post_id" value="' . $post_data['topic_last_post_id'] . '" />' : '';
$s_hidden_fields .= '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
$s_hidden_fields .= $draft_id || isset($_REQUEST['draft_loaded']) ? '<input type="hidden" name="draft_loaded" value="' . request_var('draft_loaded', $draft_id) . '" />' : '';
if ($mode == 'edit') {
    $s_hidden_fields .= build_hidden_fields(array('edit_post_message_checksum' => $post_data['post_checksum'], 'edit_post_subject_checksum' => $post_data['post_subject_md5']));
}
// Add the confirm id/code pair to the hidden fields, else an error is displayed on next submit/preview
if (isset($captcha) && $captcha->is_solved() !== false) {
    $s_hidden_fields .= build_hidden_fields($captcha->get_hidden_fields());
}
$form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_attachments'] || !$auth->acl_get('u_attach') || !$auth->acl_get('f_attach', $forum_id) ? '' : ' enctype="multipart/form-data"';
add_form_key('posting');
// Start assigning vars for main posting page ...
$template->assign_vars(array('L_POST_A' => $page_title, 'L_ICON' => $mode == 'reply' || $mode == 'quote' || $mode == 'edit' && $post_id != $post_data['topic_first_post_id'] ? $user->lang['POST_ICON'] : $user->lang['TOPIC_ICON'], 'L_MESSAGE_BODY_EXPLAIN' => intval($config['max_post_chars']) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '', 'FORUM_NAME' => $post_data['forum_name'], 'FORUM_DESC' => $post_data['forum_desc'] ? generate_text_for_display($post_data['forum_desc'], $post_data['forum_desc_uid'], $post_data['forum_desc_bitfield'], $post_data['forum_desc_options']) : '', 'TOPIC_TITLE' => censor_text($post_data['topic_title']), 'MODERATORS' => sizeof($moderators) ? implode(', ', $moderators[$forum_id]) : '', 'USERNAME' => !$preview && $mode != 'quote' || $preview ? $post_data['username'] : '', 'SUBJECT' => $post_data['post_subject'], 'MESSAGE' => $post_data['post_text'], 'BBCODE_STATUS' => $bbcode_status ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $bbcode_status && $url_status ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'], 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['POST']), 'POST_DATE' => $post_data['post_time'] ? $user->format_date($post_data['post_time']) : '', 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'TOPIC_TIME_LIMIT' => (int) $post_data['topic_time_limit'], 'EDIT_REASON' => $post_data['post_edit_reason'], 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$forum_id}"), 'U_VIEW_TOPIC' => $mode != 'post' ? append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$forum_id}&amp;t={$topic_id}") : '', 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.{$phpEx}", "f={$forum_id}&amp;mode=popup"), 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.{$phpEx}", "f={$forum_id}&amp;mode=popup")), 'S_PRIVMSGS' => false, 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']) ? true : false, 'S_EDIT_POST' => $mode == 'edit' ? true : false, 'S_EDIT_REASON' => $mode == 'edit' && $auth->acl_get('m_edit', $forum_id) ? true : false, 'S_DISPLAY_USERNAME' => !$user->data['is_registered'] || $mode == 'edit' && $post_data['poster_id'] == ANONYMOUS ? true : false, 'S_SHOW_TOPIC_ICONS' => $s_topic_icons, 'S_DELETE_ALLOWED' => $mode == 'edit' && ($post_id == $post_data['topic_last_post_id'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) && !$post_data['post_edit_locked'] && ($post_data['post_time'] > time() - $config['delete_time'] * 60 || !$config['delete_time']) || $auth->acl_get('m_delete', $forum_id)) ? true : false, 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_BBCODE_CHECKED' => $bbcode_checked ? ' checked="checked"' : '', 'S_SMILIES_ALLOWED' => $smilies_status, 'S_SMILIES_CHECKED' => $smilies_checked ? ' checked="checked"' : '', 'S_SIG_ALLOWED' => $auth->acl_get('f_sigs', $forum_id) && $config['allow_sig'] && $user->data['is_registered'] ? true : false, 'S_SIGNATURE_CHECKED' => $sig_checked ? ' checked="checked"' : '', 'S_NOTIFY_ALLOWED' => !$user->data['is_registered'] || $mode == 'edit' && $user->data['user_id'] != $post_data['poster_id'] || !$config['allow_topic_notify'] || !$config['email_enable'] ? false : true, 'S_NOTIFY_CHECKED' => $notify_checked ? ' checked="checked"' : '', 'S_LOCK_TOPIC_ALLOWED' => ($mode == 'edit' || $mode == 'reply' || $mode == 'quote') && ($auth->acl_get('m_lock', $forum_id) || $auth->acl_get('f_user_lock', $forum_id) && $user->data['is_registered'] && !empty($post_data['topic_poster']) && $user->data['user_id'] == $post_data['topic_poster'] && $post_data['topic_status'] == ITEM_UNLOCKED) ? true : false, 'S_LOCK_TOPIC_CHECKED' => $lock_topic_checked ? ' checked="checked"' : '', 'S_LOCK_POST_ALLOWED' => $mode == 'edit' && $auth->acl_get('m_edit', $forum_id) ? true : false, 'S_LOCK_POST_CHECKED' => $lock_post_checked ? ' checked="checked"' : '', 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => $urls_checked ? ' checked="checked"' : '', 'S_TYPE_TOGGLE' => $topic_type_toggle, 'S_SAVE_ALLOWED' => $auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $mode != 'edit' ? true : false, 'S_HAS_DRAFTS' => $auth->acl_get('u_savedrafts') && $user->data['is_registered'] && $post_data['drafts'] ? true : false, 'S_FORM_ENCTYPE' => $form_enctype, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields));
// Build custom bbcodes array
display_custom_bbcodes();
// Poll entry
if (($mode == 'post' || $mode == 'edit' && $post_id == $post_data['topic_first_post_id']) && $auth->acl_get('f_poll', $forum_id)) {
    $template->assign_vars(array('S_SHOW_POLL_BOX' => true, 'S_POLL_VOTE_CHANGE' => $auth->acl_get('f_votechg', $forum_id) && $auth->acl_get('f_vote', $forum_id), 'S_POLL_DELETE' => $mode == 'edit' && sizeof($post_data['poll_options']) && (!$post_data['poll_last_vote'] && $post_data['poster_id'] == $user->data['user_id'] && $auth->acl_get('f_delete', $forum_id) || $auth->acl_get('m_delete', $forum_id)), 'S_POLL_DELETE_CHECKED' => !empty($poll_delete) ? true : false, 'L_POLL_OPTIONS_EXPLAIN' => sprintf($user->lang['POLL_OPTIONS_' . ($mode == 'edit' ? 'EDIT_' : '') . 'EXPLAIN'], $config['max_poll_options']), 'VOTE_CHANGE_CHECKED' => !empty($post_data['poll_vote_change']) ? ' checked="checked"' : '', 'POLL_TITLE' => isset($post_data['poll_title']) ? $post_data['poll_title'] : '', 'POLL_OPTIONS' => !empty($post_data['poll_options']) ? implode("\n", $post_data['poll_options']) : '', 'POLL_MAX_OPTIONS' => isset($post_data['poll_max_options']) ? (int) $post_data['poll_max_options'] : 1, 'POLL_LENGTH' => $post_data['poll_length']));
}
// Show attachment box for adding attachments if true
$allowed = $auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && $config['allow_attachments'] && $form_enctype;
// Attachment entry
posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
// Output page ...
page_header($page_title, false);
$template->set_filenames(array('body' => 'posting_body.html'));
make_jumpbox(append_sid("{$phpbb_root_path}viewforum.{$phpEx}"));
// Topic review
if ($mode == 'reply' || $mode == 'quote') {
    if (topic_review($topic_id, $forum_id)) {
    public function main($id, $mode)
    {
        global $cache, $config, $db, $phpbb_log, $request, $template, $user, $phpbb_root_path, $phpEx, $phpbb_container;
        $this->cache = $cache;
        $this->config = $config;
        $this->config_text = $phpbb_container->get('config_text');
        $this->db = $db;
        $this->log = $phpbb_log;
        $this->request = $request;
        $this->template = $template;
        $this->user = $user;
        $this->phpbb_root_path = $phpbb_root_path;
        $this->php_ext = $phpEx;
        // Add the posting lang file needed by BBCodes
        $this->user->add_lang(array('posting'));
        // Add the board announcements ACP lang file
        $this->user->add_lang_ext('phpbb/boardannouncements', 'boardannouncements_acp');
        // Load a template from adm/style for our ACP page
        $this->tpl_name = 'board_announcements';
        // Set the page title for our ACP page
        $this->page_title = 'ACP_BOARD_ANNOUNCEMENTS_SETTINGS';
        // Define the name of the form for use as a form key
        $form_name = 'acp_board_announcements';
        add_form_key($form_name);
        // Set an empty error string
        $error = '';
        // Include files needed for displaying BBCodes
        if (!function_exists('display_custom_bbcodes')) {
            include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        }
        // Get all board announcement data from the config_text table in the database
        $data = $this->config_text->get_array(array('announcement_text', 'announcement_uid', 'announcement_bitfield', 'announcement_options', 'announcement_bgcolor'));
        // If form is submitted or previewed
        if ($this->request->is_set_post('submit') || $this->request->is_set_post('preview')) {
            // Test if form key is valid
            if (!check_form_key($form_name)) {
                $error = $this->user->lang('FORM_INVALID');
            }
            // Get new announcement text and bgcolor values from the form
            $data['announcement_text'] = $this->request->variable('board_announcements_text', '', true);
            $data['announcement_bgcolor'] = $this->request->variable('board_announcements_bgcolor', '', true);
            // Get config options from the form
            $enable_announcements = $this->request->variable('board_announcements_enable', false);
            $allow_guests = $this->request->variable('board_announcements_guests', false);
            $dismiss_announcements = $this->request->variable('board_announcements_dismiss', false);
            // Prepare announcement text for storage
            generate_text_for_storage($data['announcement_text'], $data['announcement_uid'], $data['announcement_bitfield'], $data['announcement_options'], !$this->request->variable('disable_bbcode', false), !$this->request->variable('disable_magic_url', false), !$this->request->variable('disable_smilies', false));
            // Store the announcement text and settings if submitted with no errors
            if (empty($error) && $this->request->is_set_post('submit')) {
                // Store the config enable/disable state
                $this->config->set('board_announcements_enable', $enable_announcements);
                $this->config->set('board_announcements_guests', $allow_guests);
                $this->config->set('board_announcements_dismiss', $dismiss_announcements);
                // Store the announcement settings to the config_table in the database
                $this->config_text->set_array(array('announcement_text' => $data['announcement_text'], 'announcement_uid' => $data['announcement_uid'], 'announcement_bitfield' => $data['announcement_bitfield'], 'announcement_options' => $data['announcement_options'], 'announcement_bgcolor' => $data['announcement_bgcolor'], 'announcement_timestamp' => time()));
                // Set the board_announcements_status for all normal users
                // to 1 when an announcement is created, or 0 when announcement is empty
                $announcement_status = !empty($data['announcement_text']) ? 1 : 0;
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET board_announcements_status = ' . $announcement_status . '
					WHERE user_type <> ' . USER_IGNORE;
                $this->db->sql_query($sql);
                // Set the board_announcement status for guests if they are allowed
                // We do this separately for guests to make sure it is always set to
                // the correct value every time.
                $sql = 'UPDATE ' . USERS_TABLE . '
					SET board_announcements_status = ' . ($allow_guests && $announcement_status ? 1 : 0) . '
					WHERE user_id = ' . ANONYMOUS;
                $this->db->sql_query($sql);
                // Log the announcement update
                $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'BOARD_ANNOUNCEMENTS_UPDATED_LOG');
                // Destroy any cached board announcement data
                $this->cache->destroy('_board_announcement_data');
                // Output message to user for the announcement update
                trigger_error($this->user->lang('BOARD_ANNOUNCEMENTS_UPDATED') . adm_back_link($this->u_action));
            }
        }
        // Prepare a fresh announcement preview
        $announcement_text_preview = '';
        if ($this->request->is_set_post('preview')) {
            $announcement_text_preview = generate_text_for_display($data['announcement_text'], $data['announcement_uid'], $data['announcement_bitfield'], $data['announcement_options']);
        }
        // prepare the announcement text for editing inside the textbox
        $announcement_text_edit = generate_text_for_edit($data['announcement_text'], $data['announcement_uid'], $data['announcement_options']);
        // Output data to the template
        $this->template->assign_vars(array('ERRORS' => $error, 'BOARD_ANNOUNCEMENTS_ENABLED' => isset($enable_announcements) ? $enable_announcements : $this->config['board_announcements_enable'], 'BOARD_ANNOUNCEMENTS_GUESTS' => isset($allow_guests) ? $allow_guests : $this->config['board_announcements_guests'], 'BOARD_ANNOUNCEMENTS_DISMISS' => isset($dismiss_announcements) ? $dismiss_announcements : $this->config['board_announcements_dismiss'], 'BOARD_ANNOUNCEMENTS_TEXT' => $announcement_text_edit['text'], 'BOARD_ANNOUNCEMENTS_PREVIEW' => $announcement_text_preview, 'BOARD_ANNOUNCEMENTS_BGCOLOR' => $data['announcement_bgcolor'], 'S_BBCODE_DISABLE_CHECKED' => !$announcement_text_edit['allow_bbcode'], 'S_SMILIES_DISABLE_CHECKED' => !$announcement_text_edit['allow_smilies'], 'S_MAGIC_URL_DISABLE_CHECKED' => !$announcement_text_edit['allow_urls'], 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'), 'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'), 'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'), 'URL_STATUS' => $this->user->lang('URL_IS_ON'), 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, 'S_BOARD_ANNOUNCEMENTS' => true, 'U_ACTION' => $this->u_action));
        // Build custom bbcodes array
        display_custom_bbcodes();
    }
Exemplo n.º 9
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);

		$error		= array();
		$username	= utf8_normalize_nfc(request_var('username', '', true));
		$user_id	= request_var('u', 0);
		$action		= request_var('action', '');

		$submit		= (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;

		$form_name = 'acp_users';
		add_form_key($form_name);

		// Whois (special case)
		if ($action == 'whois')
		{
			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

			$this->page_title = 'WHOIS';
			$this->tpl_name = 'simple_body';

			$user_ip = request_var('user_ip', '');
			$domain = gethostbyaddr($user_ip);
			$ipwhois = user_ipwhois($user_ip);

			$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&amp;select_single=true'),
			));

			return;
		}

		if (!$user_id)
		{
			$sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "
				WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($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), E_USER_WARNING);
			}
		}

		// 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), E_USER_WARNING);
		}

		// Generate overall "header" for user admin
		$s_form_options = '';

		// Build modes dropdown list
		$sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "
			WHERE module_basename = 'users'
				AND module_enabled = 1
				AND module_class = 'acp'
			ORDER BY left_id, module_mode";
		$result = $db->sql_query($sql);

		$dropdown_modes = array();
		while ($row = $db->sql_fetchrow($result))
		{
			if (!$this->p_master->module_auth($row['module_auth']))
			{
				continue;
			}

			$dropdown_modes[$row['module_mode']] = true;
		}
		$db->sql_freeresult($result);

		foreach ($dropdown_modes as $module_mode => $null)
		{
			$selected = ($mode == $module_mode) ? ' selected="selected"' : '';
			$s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</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,
			'MANAGED_USERNAME'	=> $user_row['username'])
		);

		// 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), E_USER_WARNING);
		}

		switch ($mode)
		{
			case 'overview':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$user->add_lang('acp/ban');

				$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_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}

						// 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), E_USER_WARNING);
						}

						if ($user_id == $user->data['user_id'])
						{
							trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}

						if (confirm_box(true))
						{
							user_delete($delete_type, $user_id, $user_row['username']);

							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':

							if ($user_id == $user->data['user_id'])
							{
								trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$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 . "
										WHERE 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;
							}

							$ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
							$ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));

							// Log not used at the moment, we simply utilize the ban function.
							$result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);

							trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;

						case 'reactivate':

							if ($user_id == $user->data['user_id'])
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_IGNORE)
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							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);
								$email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';

								if ($user_row['user_type'] == USER_NORMAL)
								{
									user_active_flip('deactivate', $user_id, INACTIVE_REMIND);

									$sql = 'UPDATE ' . USERS_TABLE . "
										SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
										WHERE user_id = $user_id";
									$db->sql_query($sql);
								}
								else
								{
									// Grabbing the last confirm key - we only send a reminder
									$sql = 'SELECT user_actkey
										FROM ' . USERS_TABLE . '
										WHERE user_id = ' . $user_id;
									$result = $db->sql_query($sql);
									$user_actkey = (string) $db->sql_fetchfield('user_actkey');
									$db->sql_freeresult($result);
								}

								$messenger = new messenger(false);

								$messenger->template($email_template, $user_row['user_lang']);

								$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(
									'WELCOME_MSG'	=> htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
									'USERNAME'		=> htmlspecialchars_decode($user_row['username']),
									'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':

							if ($user_id == $user->data['user_id'])
							{
								// It is only deactivation since the user is already activated (else he would not have reached this page)
								trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_IGNORE)
							{
								trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							user_active_flip('flip', $user_id);

							$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('admin', $log, $user_row['username']);
							add_log('user', $user_id, $log . '_USER');

							trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;

						case 'delsig':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$sql_ary = array(
								'user_sig'					=> '',
								'user_sig_bbcode_uid'		=> '',
								'user_sig_bbcode_bitfield'	=> ''
							);

							$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
								WHERE 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':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$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) . "
								WHERE 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', $user_row);
							}

							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))
							{
								// 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':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$user->add_lang('acp/forums');

							$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;
							}

							// Is the new forum postable to?
							$sql = 'SELECT forum_name, forum_type
								FROM ' . FORUMS_TABLE . "
								WHERE forum_id = $new_forum_id";
							$result = $db->sql_query($sql);
							$forum_info = $db->sql_fetchrow($result);
							$db->sql_freeresult($result);

							if (!$forum_info)
							{
								trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($forum_info['forum_type'] != FORUM_POST)
							{
								trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							// 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 . "
								WHERE poster_id = $user_id
									AND forum_id <> $new_forum_id
								GROUP 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, topic_attachment
									FROM ' . TOPICS_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', 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['topic_attachment']) ? 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 . "
										SET forum_id = $new_forum_id, topic_id = $new_topic_id
										WHERE topic_id = $topic_id
											AND poster_id = $user_id";
									$db->sql_query($sql);

									if ($post_ary['attach'])
									{
										$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
											SET topic_id = $new_topic_id
											WHERE topic_id = $topic_id
												AND 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, false, true);
							}


							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;
					}

					// Handle registration info updates
					$data = array(
						'username'			=> utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
						'user_founder'		=> request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
						'email'				=> strtolower(request_var('user_email', $user_row['user_email'])),
						'email_confirm'		=> strtolower(request_var('email_confirm', '')),
						'new_password'		=> request_var('new_password', '', true),
						'password_confirm'	=> request_var('password_confirm', '', true),
					);

					// Validation data - we do not check the password complexity setting here
					$check_ary = array(
						'new_password'		=> array(
							array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
							array('password')),
						'password_confirm'	=> array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
					);

					// Check username if altered
					if ($data['username'] != $user_row['username'])
					{
						$check_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['email'] != $user_row['user_email'])
					{
						$check_ary += array(
							'email'				=> array(
								array('string', false, 6, 60),
								array('email', $user_row['user_email'])
							),
							'email_confirm'		=> array('string', true, 6, 60)
						);
					}

					$error = validate_data($data, $check_ary);

					if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
					{
						$error[] = 'NEW_PASSWORD_ERROR';
					}

					if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
					{
						$error[] = 'NEW_EMAIL_ERROR';
					}

					if (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					// Which updates do we need to do?
					$update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
					$update_password = ($data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password'])) ? true : false;
					$update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;

					if (!sizeof($error))
					{
						$sql_ary = array();

						if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
						{
							// Only allow founders updating the founder status...
							if ($user->data['user_type'] == USER_FOUNDER)
							{
								// Setting a normal member to be a founder
								if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
								{
									// Make sure the user is not setting an Inactive or ignored user to be a founder
									if ($user_row['user_type'] == USER_IGNORE)
									{
										trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}

									if ($user_row['user_type'] == USER_INACTIVE)
									{
										trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}

									$sql_ary['user_type'] = USER_FOUNDER;
								}
								else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
								{
									// Check if at least one founder is present
									$sql = 'SELECT user_id
										FROM ' . USERS_TABLE . '
										WHERE user_type = ' . USER_FOUNDER . '
											AND user_id <> ' . $user_id;
									$result = $db->sql_query_limit($sql, 1);
									$row = $db->sql_fetchrow($result);
									$db->sql_freeresult($result);

									if ($row)
									{
										$sql_ary['user_type'] = USER_NORMAL;
									}
									else
									{
										trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}
								}
							}
						}

						if ($update_username !== false)
						{
							$sql_ary['username'] = $update_username;
							$sql_ary['username_clean'] = utf8_clean_string($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($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'		=> phpbb_hash($data['new_password']),
								'user_passchg'		=> time(),
								'user_pass_convert'	=> 0,
							);

							$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);
						}

						if ($update_username)
						{
							user_update_name($user_row['username'], $update_username);
						}

						// Let the users permissions being updated
						$auth->acl_clear_prefetch($user_id);

						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);
				}

				if ($user_id == $user->data['user_id'])
				{
					$quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
				}
				else
				{
					$quick_tool_ary = array();

					if ($user_row['user_type'] != USER_FOUNDER)
					{
						$quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
					}

					if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
					{
						$quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
					}
					
					$quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
					
					if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
					{
						$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>';
				}

				if ($config['load_onlinetrack'])
				{
					$sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
						FROM ' . SESSIONS_TABLE . "
						WHERE session_user_id = $user_id";
					$result = $db->sql_query($sql);
					$row = $db->sql_fetchrow($result);
					$db->sql_freeresult($result);

					$user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
					$user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
					unset($row);
				}

				$last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];

				$inactive_reason = '';
				if ($user_row['user_type'] == USER_INACTIVE)
				{
					$inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];

					switch ($user_row['user_inactive_reason'])
					{
						case INACTIVE_REGISTER:
							$inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
						break;

						case INACTIVE_PROFILE:
							$inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
						break;

						case INACTIVE_MANUAL:
							$inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
						break;

						case INACTIVE_REMIND:
							$inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
						break;
					}
				}

				$template->assign_vars(array(
					'L_NAME_CHARS_EXPLAIN'		=> sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
					'L_CHANGE_PASSWORD_EXPLAIN'	=> sprintf($user->lang[$config['pass_complex'] . '_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,
					'S_OWN_ACCOUNT'		=> ($user_id == $user->data['user_id']) ? true : false,
					'S_USER_INACTIVE'	=> ($user_row['user_type'] == USER_INACTIVE) ? true : false,

					'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'	=> ($last_visit) ? $user->format_date($last_visit) : ' - ',
					'USER_EMAIL'		=> $user_row['user_email'],
					'USER_WARNINGS'		=> $user_row['user_warnings'],
					'USER_POSTS'		=> $user_row['user_posts'],
					'USER_INACTIVE_REASON'	=> $inactive_reason,
				));

			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	= utf8_normalize_nfc(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'))
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					$where_sql = '';
					if ($deletemark && $marked)
					{
						$sql_in = array();
						foreach ($marked as $mark)
						{
							$sql_in[] = $mark;
						}
						$where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
						unset($sql_in);
					}

					if ($where_sql || $deleteall)
					{
						$sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "
							$where_sql";
						$db->sql_query($sql);

						add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
					}
				}

				if ($submit && $message)
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
					add_log('mod', 0, 0, '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' => 'u.username_clean', '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_full'],
						'IP'			=> $row['ip'],
						'DATE'			=> $user->format_date($row['time']),
						'ACTION'		=> nl2br($row['action']),
						'ID'			=> $row['id'])
					);
				}

			break;

			case 'profile':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);

				$cp = new custom_profile();

				$cp_data = $cp_error = array();

				$sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "
					WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
				$result = $db->sql_query($sql);
				$row = $db->sql_fetchrow($result);
				$db->sql_freeresult($result);

				$user_row['iso_lang_id'] = $row['lang_id'];

				$data = array(
					'icq'			=> request_var('icq', $user_row['user_icq']),
					'aim'			=> request_var('aim', $user_row['user_aim']),
					'msn'			=> request_var('msn', $user_row['user_msnm']),
					'yim'			=> request_var('yim', $user_row['user_yim']),
					'jabber'		=> utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
					'website'		=> request_var('website', $user_row['user_website']),
					'location'		=> utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
					'occupation'	=> utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
					'interests'		=> utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
					'bday_day'		=> 0,
					'bday_month'	=> 0,
					'bday_year'		=> 0,
				);

				if ($user_row['user_birthday'])
				{
					list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
				}

				$data['bday_day'] = request_var('bday_day', $data['bday_day']);
				$data['bday_month'] = request_var('bday_month', $data['bday_month']);
				$data['bday_year'] = request_var('bday_year', $data['bday_year']);

				if ($submit)
				{
					$error = validate_data($data, array(
						'icq'			=> array(
							array('string', true, 3, 15),
							array('match', true, '#^[0-9]+$#i')),
						'aim'			=> array('string', true, 3, 255),
						'msn'			=> array('string', true, 5, 255),
						'jabber'		=> array(
							array('string', true, 5, 255),
							array('jabber')),
						'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())),
					));

					// 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 (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					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) . "
							WHERE user_id = $user_id";
						$db->sql_query($sql);

						// Update Custom Fields
						if (sizeof($cp_data))
						{
							switch ($db->sql_layer)
							{
								case 'oracle':
								case 'firebird':
								case 'postgres':
									$right_delim = $left_delim = '"';
								break;

								case 'sqlite':
								case 'mssql':
								case 'mssql_odbc':
									$right_delim = ']';
									$left_delim = '[';
								break;

								case 'mysql':
								case 'mysql4':
								case 'mysqli':
									$right_delim = $left_delim = '`';
								break;
							}

							foreach ($cp_data as $key => $value)
							{
								$cp_data[$left_delim . $key . $right_delim] = $value;
								unset($cp_data[$key]);
							}

							$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "
								WHERE user_id = $user_id";
							$db->sql_query($sql);

							if (!$db->sql_affectedrows())
							{
								$cp_data['user_id'] = (int) $user_id;

								$db->sql_return_on_error(true);

								$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
								$db->sql_query($sql);

								$db->sql_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);
				}

				$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'			=> $data['icq'],
					'YIM'			=> $data['yim'],
					'AIM'			=> $data['aim'],
					'MSN'			=> $data['msn'],
					'JABBER'		=> $data['jabber'],
					'WEBSITE'		=> $data['website'],
					'LOCATION'		=> $data['location'],
					'OCCUPATION'	=> $data['occupation'],
					'INTERESTS'		=> $data['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':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$data = array(
					'dateformat'		=> utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
					'lang'				=> basename(request_var('lang', $user_row['user_lang'])),
					'tz'				=> request_var('tz', (float) $user_row['user_timezone']),
					'style'				=> request_var('style', $user_row['user_style']),
					'dst'				=> request_var('dst', $user_row['user_dst']),
					'viewemail'			=> request_var('viewemail', $user_row['user_allow_viewemail']),
					'massemail'			=> request_var('massemail', $user_row['user_allow_massemail']),
					'hideonline'		=> request_var('hideonline', !$user_row['user_allow_viewonline']),
					'notifymethod'		=> request_var('notifymethod', $user_row['user_notify_type']),
					'notifypm'			=> request_var('notifypm', $user_row['user_notify_pm']),
					'popuppm'			=> request_var('popuppm', $this->optionget($user_row, 'popuppm')),
					'allowpm'			=> request_var('allowpm', $user_row['user_allow_pm']),

					'topic_sk'			=> request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
					'topic_sd'			=> request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
					'topic_st'			=> request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),

					'post_sk'			=> request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
					'post_sd'			=> request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
					'post_st'			=> request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),

					'view_images'		=> request_var('view_images', $this->optionget($user_row, 'viewimg')),
					'view_flash'		=> request_var('view_flash', $this->optionget($user_row, 'viewflash')),
					'view_smilies'		=> request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
					'view_sigs'			=> request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
					'view_avatars'		=> request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
					'view_wordcensor'	=> request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),

					'bbcode'	=> request_var('bbcode', $this->optionget($user_row, 'bbcode')),
					'smilies'	=> request_var('smilies', $this->optionget($user_row, 'smilies')),
					'sig'		=> request_var('sig', $this->optionget($user_row, 'attachsig')),
					'notify'	=> request_var('notify', $user_row['user_notify']),
				);

				if ($submit)
				{
					$error = validate_data($data, array(
						'dateformat'	=> array('string', false, 1, 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),
					));

					if (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					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) . "
							WHERE 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);
				}

				$dateformat_options = '';
				foreach ($user->lang['dateformats'] as $format => $null)
				{
					$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
					$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
					$dateformat_options .= '</option>';
				}

				$s_custom = false;

				$dateformat_options .= '<option value="custom"';
				if (!in_array($data['dateformat'], array_keys($user->lang['dateformats'])))
				{
					$dateformat_options .= ' selected="selected"';
					$s_custom = true;
				}
				$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';

				$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 = ($data[$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 = ($data[$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 = ($data[$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_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
					
					'VIEW_EMAIL'		=> $data['viewemail'],
					'MASS_EMAIL'		=> $data['massemail'],
					'ALLOW_PM'			=> $data['allowpm'],
					'HIDE_ONLINE'		=> $data['hideonline'],
					'NOTIFY_EMAIL'		=> ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
					'NOTIFY_IM'			=> ($data['notifymethod'] == NOTIFY_IM) ? true : false,
					'NOTIFY_BOTH'		=> ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
					'NOTIFY_PM'			=> $data['notifypm'],
					'POPUP_PM'			=> $data['popuppm'],
					'DST'				=> $data['dst'],
					'BBCODE'			=> $data['bbcode'],
					'SMILIES'			=> $data['smilies'],
					'ATTACH_SIG'		=> $data['sig'],
					'NOTIFY'			=> $data['notify'],
					'VIEW_IMAGES'		=> $data['view_images'],
					'VIEW_FLASH'		=> $data['view_flash'],
					'VIEW_SMILIES'		=> $data['view_smilies'],
					'VIEW_SIGS'			=> $data['view_sigs'],
					'VIEW_AVATARS'		=> $data['view_avatars'],
					'VIEW_WORDCENSOR'	=> $data['view_wordcensor'],
					
					'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'			=> $data['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($data['lang']),
					'S_STYLE_OPTIONS'	=> style_select($data['style']),
					'S_TZ_OPTIONS'		=> tz_select($data['tz'], true),
					)
				);

			break;

			case 'avatar':

				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;

				if ($submit)
				{

					if (!check_form_key($form_name))
					{
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					if (avatar_process_user($error, $user_row))
					{
						trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['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
				$avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';

				$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
				$avatar_select = basename(request_var('avatar_select', ''));
				$category = basename(request_var('category', ''));

				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)
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					$rank_id = request_var('user_rank', 0);

					$sql = 'UPDATE ' . USERS_TABLE . "
						SET user_rank = $rank_id
						WHERE 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);
				include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);

				$enable_bbcode	= ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', !$user->optionget('bbcode'))) ? false : true) : false;
				$enable_smilies	= ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', !$user->optionget('smilies'))) ? false : true) : false;
				$enable_urls	= ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
				$signature		= utf8_normalize_nfc(request_var('signature', (string) $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, $config['allow_sig_links'], true, 'sig');
						
					if (sizeof($message_parser->warn_msg))
					{
						$error[] = implode('<br />', $message_parser->warn_msg);
					}

					if (!check_form_key($form_name))
					{
						$error = 'FORM_INVALID';
					}

					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'	=> (string) $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') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</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'],
					'URL_STATUS'			=> ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_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,
					'S_LINKS_ALLOWED'		=> ($config['allow_sig_links']) ? true : false)
				);

				// Assigning custom bbcodes
				display_custom_bbcodes();

			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))
				{
					$sql = 'SELECT attach_id
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE poster_id = ' . $user_id . '
							AND is_orphan = 0
							AND ' . $db->sql_in_set('attach_id', $marked);
					$result = $db->sql_query($sql);

					$marked = array();
					while ($row = $db->sql_fetchrow($result))
					{
						$marked[] = $row['attach_id'];
					}
					$db->sql_freeresult($result);
				}

				if ($deletemark && sizeof($marked))
				{
					if (confirm_box(true))
					{
						$sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $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);

						$message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];

						add_log('admin', 'LOG_ATTACHMENTS_DELETED', 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,
							'delmarked'		=> 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>';
				}

				if (!isset($sk_sql[$sort_key]))
				{
					$sort_key = 'a';
				}

				$order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');

				$sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "
					WHERE poster_id = $user_id
						AND is_orphan = 0";
				$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 . "
						AND a.is_orphan = 0
					ORDER 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']}") . '#p' . $row['post_msg_id'];
					}

					$template->assign_block_vars('attach', array(
						'REAL_FILENAME'		=> $row['real_filename'],
						'COMMENT'			=> nl2br($row['attach_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/file.$phpEx", 'mode=view&amp;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;u=$user_id&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start, true))
				);

			break;
		
			case 'groups':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$user->add_lang(array('groups', 'acp/groups'));
				$group_id = request_var('g', 0);
				
				if ($group_id)
				{
					// Check the founder only entry for this group to make sure everything is well
					$sql = 'SELECT group_founder_manage
						FROM ' . GROUPS_TABLE . '
						WHERE group_id = ' . $group_id;
					$result = $db->sql_query($sql);
					$founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
					$db->sql_freeresult($result);
					
					if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
					{
						trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}
				}
				else
				{
					$founder_manage = 0;
				}
				
				switch ($action)
				{
					case 'demote':
					case 'promote':
					case 'default':
						if (!$group_id)
						{
							trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}
						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), E_USER_WARNING);
							}

							if ($error = group_user_del($group_id, $user_id))
							{
								trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}
						
							$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 (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					if (!$group_id)
					{
						trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					// 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), E_USER_WARNING);
					}

					$error = array();
				}


				$sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
					WHERE ug.user_id = $user_id
						AND g.group_id = ug.group_id
					ORDER 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, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
					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_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
					{
						continue;
					}

					// Do not display those groups not allowed to be managed
					if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
					{
						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');
				add_permission_language();

				$forum_id = request_var('f', 0);

				// Global Permissions
				if (!$forum_id)
				{
					// Select auth options
					$sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . '
						WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
							AND is_global = 1
						ORDER BY auth_option';
					$result = $db->sql_query($sql);

					$hold_ary = array();
					
					while ($row = $db->sql_fetchrow($result))
					{
						$hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
					}
					$db->sql_freeresult($result);

					unset($hold_ary);
				}
				else
				{
					$sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . "
						WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
							AND is_local = 1
						ORDER 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, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
					}
					$db->sql_freeresult($result);
				}

				$s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
				$s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);

				$template->assign_vars(array(
					'S_PERMISSIONS'				=> true,

					'S_GLOBAL'					=> (!$forum_id) ? true : false,
					'S_FORUM_OPTIONS'			=> $s_forum_options,

					'U_ACTION'					=> $this->u_action . '&amp;u=' . $user_id,
					'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) : '')
		);
	}
Exemplo n.º 10
0
    /**
     * Edit an article
     *
     * @param	string	$article	URL of the article
     * @return	object
     */
    public function edit_article($article)
    {
        // If no auth to edit display error message
        if (!$this->auth->acl_get('u_wiki_edit')) {
            trigger_error('NO_ARTICLE');
        }
        $this->user->add_lang('posting');
        $preview = $this->request->is_set_post('preview');
        $submit = $this->request->is_set_post('submit');
        $error = array();
        if ($preview || $submit) {
            $title = $this->request->variable('title', '', true);
            $message = $this->request->variable('message', '', true);
            $edit_reason = $this->request->variable('edit_reason', '', true);
            $topic_id = $this->request->variable('topic_id', '', true);
            $message_length = utf8_strlen($message);
            if (utf8_clean_string($title) === '') {
                $error[] = $this->user->lang['EMPTY_SUBJECT'];
            }
            if (utf8_clean_string($message) === '') {
                $error[] = $this->user->lang['TOO_FEW_CHARS'];
            }
            // Maximum message length check. 0 disables this check completely.
            if ((int) $this->config['max_post_chars'] > 0 && $message_length > (int) $this->config['max_post_chars']) {
                $error[] = $this->user->lang('CHARS_POST_CONTAINS', $message_length) . '<br />' . $this->user->lang('TOO_MANY_CHARS_LIMIT', (int) $this->config['max_post_chars']);
            }
            // Minimum message length check
            if (!$message_length || $message_length < (int) $this->config['min_post_chars']) {
                $error[] = !$message_length ? $this->user->lang['TOO_FEW_CHARS'] : $this->user->lang('CHARS_POST_CONTAINS', $message_length) . '<br />' . $this->user->lang('TOO_FEW_CHARS_LIMIT', (int) $this->config['min_post_chars']);
            }
        }
        if (sizeof($error)) {
            $this->template->assign_vars(array('ERROR' => implode('<br />', $error), 'TITLE' => $title, 'MESSAGE' => $message));
        } else {
            if ($preview) {
                $preview_text = $message;
                $uid = $bitfield = $options = '';
                generate_smilies('inline', 0);
                display_custom_bbcodes();
                add_form_key('article');
                $allowed_bbcode = $allowed_smilies = $allowed_urls = true;
                generate_text_for_storage($preview_text, $uid, $bitfield, $options, true, true, true);
                $preview_text = generate_text_for_display($preview_text, $uid, $bitfield, $options);
                $this->template->assign_vars(array('S_PREVIEW' => true, 'S_BBCODE_ALLOWED' => 1, 'TITLE' => $title, 'PREVIEW_MESSAGE' => $preview_text, 'MESSAGE' => $message, 'EDIT_REASON' => $edit_reason, 'TOPIC_ID' => $topic_id));
            } else {
                if ($submit) {
                    generate_text_for_storage($message, $uid, $bitfield, $options, true, true, true);
                    $sql_data = array('article_title' => $title, 'article_url' => $article, 'article_text' => $message, 'bbcode_uid' => $uid, 'bbcode_bitfield' => $bitfield, 'article_approved' => 1, 'article_user_id' => $this->user->data['user_id'], 'article_last_edit' => time(), 'article_edit_reason' => $edit_reason, 'article_topic_id' => (int) $topic_id);
                    $sql = 'INSERT INTO ' . $this->table_article . '
				' . $this->db->sql_build_array('INSERT', $sql_data);
                    $this->db->sql_query($sql);
                    $back_url = empty($article) ? $this->helper->route('tas2580_wiki_index', array()) : $this->helper->route('tas2580_wiki_article', array('article' => $article));
                    trigger_error($this->user->lang['EDIT_ARTICLE_SUCCESS'] . '<br /><br /><a href="' . $back_url . '">' . $this->user->lang['BACK_TO_ARTICLE'] . '</a>');
                } else {
                    $sql = 'SELECT *
				FROM ' . $this->table_article . '
					WHERE article_url = "' . $this->db->sql_escape($article) . '"
				ORDER BY article_last_edit DESC';
                    $result = $this->db->sql_query_limit($sql, 1);
                    $this->data = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    generate_smilies('inline', 0);
                    display_custom_bbcodes();
                    add_form_key('article');
                    $message = generate_text_for_edit($this->data['article_text'], $this->data['bbcode_uid'], 3);
                    $this->template->assign_vars(array('TITLE' => $this->data['article_title'], 'MESSAGE' => $message['text'], 'S_BBCODE_ALLOWED' => 1, 'TOPIC_ID' => $this->data['article_topic_id']));
                    if (!empty($article)) {
                        $this->template->assign_block_vars('navlinks', array('FORUM_NAME' => $this->data['article_title'], 'U_VIEW_FORUM' => $this->helper->route('tas2580_wiki_article', array('article' => $article))));
                    }
                }
            }
        }
        return $this->helper->render('article_edit.html', $this->user->lang['EDIT_WIKI']);
    }
Exemplo n.º 11
0
    /**
     * Image Controller
     *	Route: gallery/image_id/{image_id}
     *
     * @param int	$image_id	Image ID
     * @return Symfony\Component\HttpFoundation\Response A Symfony Response object
     */
    public function base($image_id, $page = 0)
    {
        $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
        try {
            $sql = 'SELECT *
			FROM ' . $this->table_images . '
			WHERE image_id = ' . (int) $image_id;
            $result = $this->db->sql_query($sql);
            $this->data = $this->db->sql_fetchrow($result);
            $this->db->sql_freeresult($result);
            if (!$this->data) {
                // Image does not exist
                throw new \OutOfBoundsException('INVALID_IMAGE');
            }
            $this->loader->load($this->data['image_album_id']);
        } catch (\Exception $e) {
            return $this->error($e->getMessage(), 404);
        }
        $album_id = (int) $this->data['image_album_id'];
        $album_data = $this->loader->get($album_id);
        $this->check_permissions($album_id, $album_data['album_user_id'], $this->data['image_status'], $album_data['album_auth_access']);
        $this->display->generate_navigation($album_data);
        if (!$this->user->data['is_bot'] && isset($this->user->data['session_page']) && (strpos($this->user->data['session_page'], '&image_id=' . $image_id) === false || isset($this->user->data['session_created']))) {
            $sql = 'UPDATE ' . $this->table_images . '
				SET image_view_count = image_view_count + 1
				WHERE image_id = ' . $image_id;
            $this->db->sql_query($sql);
        }
        // Do stuff here
        $page_title = $this->data['image_name'];
        if ($page > 1) {
            $page_title .= ' - ' . $this->user->lang('PAGE_TITLE_NUMBER', $page);
        }
        $s_allowed_delete = $s_allowed_edit = $s_allowed_status = false;
        if (($this->gallery_auth->acl_check('m_', $album_id, $album_data['album_user_id']) || $this->data['image_user_id'] == $this->user->data['user_id']) && $this->user->data['user_id'] != ANONYMOUS) {
            //$s_user_allowed = (($this->data['image_user_id'] == $this->user->data['user_id']) && ($album_data['album_status'] != phpbb_ext_gallery_core_album::STATUS_LOCKED));
            $s_user_allowed = $this->data['image_user_id'] == $this->user->data['user_id'] && $album_data['album_status'] != 1;
            $s_allowed_delete = $this->gallery_auth->acl_check('i_delete', $album_id, $album_data['album_user_id']) && $s_user_allowed || $this->gallery_auth->acl_check('m_delete', $album_id, $album_data['album_user_id']);
            $s_allowed_edit = $this->gallery_auth->acl_check('i_edit', $album_id, $album_data['album_user_id']) && $s_user_allowed || $this->gallery_auth->acl_check('m_edit', $album_id, $album_data['album_user_id']);
            $s_quick_mod = $s_allowed_delete || $s_allowed_edit || $this->gallery_auth->acl_check('m_status', $album_id, $album_data['album_user_id']) || $this->gallery_auth->acl_check('m_move', $album_id, $album_data['album_user_id']);
            $this->user->add_lang_ext('phpbbgallery/core', 'gallery_mcp');
            $this->template->assign_vars(array('S_MOD_ACTION' => $this->helper->route('phpbbgallery_moderate_image', array('image_id' => $image_id)), 'S_QUICK_MOD' => $s_quick_mod, 'S_QM_MOVE' => $this->gallery_auth->acl_check('m_move', $album_id, $album_data['album_user_id']), 'S_QM_EDIT' => $s_allowed_edit, 'S_QM_DELETE' => $s_allowed_delete, 'S_QM_REPORT' => $this->gallery_auth->acl_check('m_report', $album_id, $album_data['album_user_id']), 'S_QM_STATUS' => $this->gallery_auth->acl_check('m_status', $album_id, $album_data['album_user_id']), 'S_IMAGE_REPORTED' => $this->data['image_reported'] ? true : false, 'U_IMAGE_REPORTED' => $this->data['image_reported'] ? $this->helper->route('phpbbgallery_moderate_image', array('image_id' => $image_id)) : '', 'S_STATUS_APPROVED' => $this->data['image_status'] == \phpbbgallery\core\image\image::STATUS_APPROVED, 'S_STATUS_UNAPPROVED' => $this->data['image_status'] == \phpbbgallery\core\image\image::STATUS_UNAPPROVED, 'S_STATUS_LOCKED' => $this->data['image_status'] == \phpbbgallery\core\image\image::STATUS_LOCKED));
        }
        $image_desc = generate_text_for_display($this->data['image_desc'], $this->data['image_desc_uid'], $this->data['image_desc_bitfield'], 7);
        // Let's see if we can get next end prev
        $sort_key = $this->request->variable('sk', $album_data['album_sort_key'] ? $album_data['album_sort_key'] : $this->config['phpbb_gallery_default_sort_key']);
        $sort_dir = $this->request->variable('sd', $album_data['album_sort_dir'] ? $album_data['album_sort_dir'] : $this->config['phpbb_gallery_default_sort_dir']);
        if (in_array($sort_key, array('r', 'ra'))) {
            $sql_help_sort = ', image_id ' . ($sort_dir == 'd' ? 'ASC' : 'DESC');
        } else {
            $sql_help_sort = ', image_id ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        }
        $limit_days = array();
        $sort_by_text = array('t' => $this->user->lang['TIME'], 'n' => $this->user->lang['IMAGE_NAME'], 'vc' => $this->user->lang['GALLERY_VIEWS'], 'u' => $this->user->lang['SORT_USERNAME']);
        $sort_by_sql = array('t' => 'image_time', 'n' => 'image_name_clean', 'vc' => 'image_view_count', 'u' => 'image_username_clean');
        if ($this->config['phpbb_gallery_allow_rates']) {
            $sort_by_text['ra'] = $this->user->lang['RATING'];
            $sort_by_sql['ra'] = 'image_rate_points';
            $sort_by_text['r'] = $this->user->lang['RATES_COUNT'];
            $sort_by_sql['r'] = 'image_rates';
        }
        if ($this->config['phpbb_gallery_allow_comments']) {
            $sort_by_text['c'] = $this->user->lang['COMMENTS'];
            $sort_by_sql['c'] = 'image_comments';
            $sort_by_text['lc'] = $this->user->lang['NEW_COMMENT'];
            $sort_by_sql['lc'] = 'image_last_comment';
        }
        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);
        $sql_sort_order = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        $sql_sort_order .= $sql_help_sort;
        // Let's see if there is prieveus image
        $sql = 'SELECT *
			FROM ' . $this->table_images . '
			WHERE image_album_id = ' . (int) $album_id . "\n\t\t\t\tAND image_status <> 3\n\t\t\tORDER BY {$sql_sort_order}" . $sql_help_sort;
        $result = $this->db->sql_query($sql);
        $images_array = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $images_array[] = $row;
        }
        $cur = 0;
        foreach ($images_array as $id => $var) {
            if ($var['image_id'] == $image_id) {
                $cur = $id;
            }
        }
        $next = $prev = false;
        if (count($images_array) > $cur + 1) {
            $next = array('image_id' => $images_array[$cur + 1]['image_id'], 'image_name' => $images_array[$cur + 1]['image_name']);
        }
        if ($cur > 0) {
            $prev = array('image_id' => $images_array[$cur - 1]['image_id'], 'image_name' => $images_array[$cur - 1]['image_name']);
        }
        $this->db->sql_freeresult($result);
        $this->template->assign_vars(array('UC_NEXT_IMAGE' => $next ? $this->gallery_config->get('disp_nextprev_thumbnail') ? '<a href="' . $this->helper->route('phpbbgallery_image', array('image_id' => $next['image_id'])) . '"><img style="max-width: 70px; max-height: 70px;" src="' . $this->helper->route('phpbbgallery_image_file_mini', array('image_id' => $next['image_id'])) . '" alt="' . $next['image_name'] . '"></a>' : '<a href="' . $this->helper->route('phpbbgallery_image', array('image_id' => $next['image_id'])) . '">' . $next['image_name'] . ' &raquo;&raquo; </a>' : '', 'UC_PREV_IMAGE' => $prev ? $this->gallery_config->get('disp_nextprev_thumbnail') ? '<a href="' . $this->helper->route('phpbbgallery_image', array('image_id' => $prev['image_id'])) . '"><img style="max-width: 70px; max-height: 70px;" src="' . $this->helper->route('phpbbgallery_image_file_mini', array('image_id' => $prev['image_id'])) . '" alt="' . $prev['image_name'] . '"></a>' : '<a href="' . $this->helper->route('phpbbgallery_image', array('image_id' => $prev['image_id'])) . '">&laquo;&laquo; ' . $prev['image_name'] . '</a>' : '', 'U_VIEW_ALBUM' => $this->helper->route('phpbbgallery_album', array('album_id' => $album_id)), 'UC_IMAGE' => $this->helper->route('phpbbgallery_image_file_medium', array('image_id' => $image_id)), 'U_DELETE' => $s_allowed_delete ? $this->helper->route('phpbbgallery_image_delete', array('image_id' => $image_id)) : '', 'U_EDIT' => $s_allowed_edit ? $this->helper->route('phpbbgallery_image_edit', array('image_id' => $image_id)) : '', 'U_REPORT' => $this->gallery_auth->acl_check('i_report', $album_id, $album_data['album_user_id']) && $this->data['image_user_id'] != $this->user->data['user_id'] ? $this->helper->route('phpbbgallery_image_report', array('image_id' => $image_id)) : '', 'U_STATUS' => $s_allowed_status ? $this->helper->route('phpbbgallery_moderate_image', array('image_id' => $image_id)) : '', 'CONTEST_RANK' => $this->data['image_contest_rank'] ? $this->user->lang('CONTEST_RESULT_' . $this->data['image_contest_rank']) : '', 'IMAGE_NAME' => $this->data['image_name'], 'IMAGE_DESC' => $image_desc, 'IMAGE_BBCODE' => $this->config['allow_bbcode'] ? '[image]' . $image_id . '[/image]' : '', 'IMAGE_IMGURL_BBCODE' => $this->config['phpbb_gallery_disp_image_url'] ? '[url=' . $this->url->get_uri($this->helper->route('phpbbgallery_image', array('image_id' => $image_id))) . '][img]' . $this->url->get_uri($this->helper->route('phpbbgallery_image_file_mini', array('image_id' => $image_id))) . '[/img][/url]' : '', 'IMAGE_URL' => $this->config['phpbb_gallery_disp_image_url'] ? $this->url->get_uri($this->helper->route('phpbbgallery_image', array('image_id' => $image_id))) : '', 'IMAGE_TIME' => $this->user->format_date($this->data['image_time']), 'IMAGE_VIEW' => $this->data['image_view_count'], 'POSTER_IP' => $this->auth->acl_get('a_') ? $this->data['image_user_ip'] : '', 'U_POSTER_WHOIS' => $this->auth->acl_get('a_') ? append_sid('mcp', 'mode=whois&amp;ip=' . $this->data['image_user_ip']) : '', 'S_ALBUM_ACTION' => $this->helper->route('phpbbgallery_image', array('image_id' => $image_id)), 'U_RETURN_LINK' => $this->helper->route('phpbbgallery_album', array('album_id' => $album_id)), 'S_RETURN_LINK' => $this->user->lang('RETURN_TO', $album_data['album_name'])));
        switch ($this->gallery_config->get('link_imagepage')) {
            case 'image':
                $this->template->assign_vars(array('UC_IMAGE_ACTION' => $this->helper->route('phpbbgallery_image_file_source', array('image_id' => $image_id))));
                break;
            case 'next':
                if ($next) {
                    $this->template->assign_vars(array('UC_IMAGE_ACTION' => $this->helper->route('phpbbgallery_image', array('image_id' => $next['image_id']))));
                }
                break;
        }
        $image_data = $this->data;
        /**
         * Event view image
         *
         * @event phpbbgallery.core.viewimage
         * @var	int		image_id		id of the image we are viewing
         * @var	array	image_data		All the data related to the image
         * @var	array	album_data		All the data related to the album image is part of
         * @var	string	page_title		Page title
         * @since 1.2.0
         */
        $vars = array('image_id', 'image_data', 'album_data', 'page_title');
        extract($this->dispatcher->trigger_event('phpbbgallery.core.viewimage', compact($vars)));
        $this->data = $image_data;
        $user_id = $this->data['image_user_id'];
        $sql = $this->db->sql_build_query('SELECT', array('SELECT' => 'u.*, gu.personal_album_id, gu.user_images', 'FROM' => array(USERS_TABLE => 'u'), 'LEFT_JOIN' => array(array('FROM' => array($this->table_users => 'gu'), 'ON' => 'gu.user_id = u.user_id')), 'WHERE' => 'u.user_id = ' . $this->data['image_user_id']));
        $result = $this->db->sql_query($sql);
        $user_cache = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            \phpbbgallery\core\user::add_user_to_cache($user_cache, $row);
        }
        $this->db->sql_freeresult($result);
        $user_cache[$user_id]['username'] = $this->data['image_username'] ? $this->data['image_username'] : $this->user->lang['GUEST'];
        $this->template->assign_vars(array('POSTER_FULL' => get_username_string('full', $user_id, $user_cache[$user_id]['username'], $user_cache[$user_id]['user_colour']), 'POSTER_COLOUR' => get_username_string('colour', $user_id, $user_cache[$user_id]['username'], $user_cache[$user_id]['user_colour']), 'POSTER_USERNAME' => get_username_string('username', $user_id, $user_cache[$user_id]['username'], $user_cache[$user_id]['user_colour']), 'U_POSTER' => get_username_string('profile', $user_id, $user_cache[$user_id]['username'], $user_cache[$user_id]['user_colour']), 'POSTER_SIGNATURE' => $user_cache[$user_id]['sig'], 'POSTER_RANK_TITLE' => $user_cache[$user_id]['rank_title'], 'POSTER_RANK_IMG' => $user_cache[$user_id]['rank_image'], 'POSTER_RANK_IMG_SRC' => $user_cache[$user_id]['rank_image_src'], 'POSTER_JOINED' => $user_cache[$user_id]['joined'], 'POSTER_POSTS' => $user_cache[$user_id]['posts'], 'POSTER_AVATAR' => $user_cache[$user_id]['avatar'], 'POSTER_WARNINGS' => $user_cache[$user_id]['warnings'], 'POSTER_AGE' => $user_cache[$user_id]['age'], 'POSTER_ONLINE_IMG' => $user_id == ANONYMOUS || !$this->config['load_onlinetrack'] ? '' : ($user_cache[$user_id]['online'] ? $this->user->img('icon_user_online', 'ONLINE') : $this->user->img('icon_user_offline', 'OFFLINE')), 'S_POSTER_ONLINE' => $user_id == ANONYMOUS || !$this->config['load_onlinetrack'] ? false : ($user_cache[$user_id]['online'] ? true : false), 'U_POSTER_PROFILE' => $user_cache[$user_id]['profile'], 'U_POSTER_SEARCH' => $user_cache[$user_id]['search'], 'U_POSTER_PM' => $user_id != ANONYMOUS && $this->config['allow_privmsg'] && $this->auth->acl_get('u_sendpm') && ($user_cache[$user_id]['allow_pm'] || $this->auth->acl_gets('a_', 'm_')) ? append_sid('./ucp.php', 'i=pm&amp;mode=compose&amp;u=' . $user_id) : '', 'U_POSTER_EMAIL' => $this->auth->acl_gets('a_') || !$this->config['board_hide_emails'] ? $user_cache[$user_id]['email'] : false, 'U_POSTER_JABBER' => $user_cache[$user_id]['jabber'], 'U_POSTER_GALLERY' => $user_cache[$user_id]['gallery_album'], 'POSTER_GALLERY_IMAGES' => $user_cache[$user_id]['gallery_images'], 'U_POSTER_GALLERY_SEARCH' => $user_cache[$user_id]['gallery_search']));
        // Add ratings
        if ($this->gallery_config->get('allow_rates')) {
            $rating = new \phpbbgallery\core\rating($image_id, $image_data, $album_data);
            $user_rating = $rating->get_user_rating($this->user->data['user_id']);
            // Check: User didn't rate yet, has permissions, it's not the users own image and the user is logged in
            if (!$user_rating && $rating->is_allowed()) {
                $rating->display_box();
            }
            $this->template->assign_vars(array('IMAGE_RATING' => $rating->get_image_rating($user_rating), 'S_ALLOWED_TO_RATE' => !$user_rating && $rating->is_allowed(), 'S_VIEW_RATE' => $this->gallery_auth->acl_check('i_rate', $album_id, $album_data['album_user_id']) ? true : false, 'S_RATE_ACTION' => $this->helper->route('phpbbgallery_image_rate', array('image_id' => $image_id))));
            unset($rating);
        }
        /**
         * Posting comment
         */
        $comments_disabled = !$this->gallery_config->get('allow_comments') || $this->gallery_config->get('comment_user_control') && !$image_data['image_allow_comments'];
        if (!$comments_disabled && $this->gallery_auth->acl_check('c_post', $album_id, $album_data['album_user_id']) && $album_data['album_status'] != $this->album->get_status_locked() && ($image_data['image_status'] != $this->image->get_status_locked() || $this->gallery_auth->acl_check('m_status', $album_id, $album_data['album_user_id']))) {
            add_form_key('gallery');
            $this->user->add_lang('posting');
            $this->url->_include('functions_posting', 'phpbb');
            $bbcode_status = $this->config['allow_bbcode'] ? true : false;
            $smilies_status = $this->config['allow_smilies'] ? true : false;
            $img_status = $bbcode_status ? true : false;
            $url_status = $this->config['allow_post_links'] ? true : false;
            $flash_status = false;
            $quote_status = true;
            include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
            // Build custom bbcodes array
            display_custom_bbcodes();
            // Build smilies array
            generate_smilies('inline', 0);
            //$s_hide_comment_input = (time() < ($album_data['contest_start'] + $album_data['contest_end'])) ? true : false;
            $s_hide_comment_input = false;
            $this->template->assign_vars(array('S_ALLOWED_TO_COMMENT' => true, 'S_HIDE_COMMENT_INPUT' => $s_hide_comment_input, 'BBCODE_STATUS' => $bbcode_status ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . $this->url->append_sid('phpbb', 'faq', 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . $this->url->append_sid('phpbb', 'faq', 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $bbcode_status && $url_status ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'S_SIGNATURE_CHECKED' => $this->user->optionget('attachsig') ? ' checked="checked"' : '', 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_LINKS_ALLOWED' => $url_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'L_COMMENT_LENGTH' => sprintf($this->user->lang['COMMENT_LENGTH'], $this->gallery_config->get('comment_length'))));
            if ($this->misc->display_captcha('comment')) {
                global $phpbb_container;
                $captcha = $phpbb_container->get('captcha.factory')->get_instance($this->config['captcha_plugin']);
                $captcha->init(CONFIRM_POST);
                $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $captcha->get_template()));
            }
            // Different link, when we rate and dont comment
            if (!$s_hide_comment_input) {
                //$this->template->assign_var('S_COMMENT_ACTION', append_sid($this->url->path('full') . 'comment/' . $image_id . '/add/0'));
                $this->template->assign_var('S_COMMENT_ACTION', $this->helper->route('phpbbgallery_comment_add', array('image_id' => $image_id, 'comment_id' => 0)));
            }
        } else {
            if ($this->gallery_config->get('comment_user_control') && !$image_data['image_allow_comments']) {
                $this->template->assign_var('S_COMMENTS_DISABLED', true);
            }
        }
        /**
         * Listing comment
         */
        if ($this->gallery_config->get('allow_comments') && $this->gallery_auth->acl_check('c_read', $album_id, $album_data['album_user_id'])) {
            $this->display_comments($image_id, $this->data, $album_id, $album_data, ($page - 1) * $this->gallery_config->get('items_per_page'), $this->gallery_config->get('items_per_page'));
        }
        return $this->helper->render('gallery/viewimage_body.html', $page_title);
    }
Exemplo n.º 12
0
 public function index()
 {
     // sets a few variables before the actions
     $this->mode = $this->request->variable('mode', 'default');
     $this->last_id = $this->request->variable('last_id', 0);
     $this->last_time = $this->request->variable('last_time', 0);
     $this->post_time = $this->request->variable('last_post', 0);
     $this->read_interval = $this->request->variable('read_interval', 5000);
     // Grabs the right Action depending on ajax requested mode
     if ($this->mode === 'default') {
         $this->defaultAction();
     } else {
         if ($this->mode === 'read') {
             $this->readAction();
         } else {
             if ($this->mode === 'smilies') {
                 $this->smiliesAction();
             } else {
                 if ($this->mode === 'delete') {
                     $this->delAction();
                 }
             }
         }
     }
     // Sets a few variables
     $bbcode_status = $this->config['allow_bbcode'] && $this->config['auth_bbcode_pm'] && $this->auth->acl_get('u_ajaxchat_bbcode') ? true : false;
     $smilies_status = $this->config['allow_smilies'] && $this->config['auth_smilies_pm'] && $this->auth->acl_get('u_pm_smilies') ? true : false;
     $img_status = $this->config['auth_img_pm'] && $this->auth->acl_get('u_pm_img') ? true : false;
     $flash_status = $this->config['auth_flash_pm'] && $this->auth->acl_get('u_pm_flash') ? true : false;
     $url_status = $this->config['allow_post_links'] ? true : false;
     $quote_status = true;
     $this->mode = strtoupper($this->mode);
     $sql = 'SELECT `user_lastpost` FROM ' . CHAT_SESSIONS_TABLE . " WHERE user_id = {$this->user->data['user_id']}";
     $result = $this->db->sql_query($sql);
     $row = $this->db->sql_fetchrow($result);
     $this->db->sql_freeresult($result);
     if ($this->get_status($row['user_lastpost']) === 'online') {
         $refresh = $this->config['refresh_online_chat'];
     } else {
         if ($this->user->data['user_id'] === ANONYMOUS || $this->get_status($row['user_lastpost']) === 'offline') {
             $refresh = $this->config['refresh_offline_chat'];
         } else {
             $refresh = $this->config['refresh_offline_chat'];
         }
     }
     if ($this->user->data['user_id'] === ANONYMOUS || $row['user_lastpost'] === null) {
         $last_post = 0;
     } else {
         $last_post = $row['user_lastpost'];
     }
     $details = base64_decode('Jm5ic3A7PGEgaHJlZj0iaHR0cDovL3d3dy5saXZlbWVtYmVyc29ubHkuY29tIiBzdHlsZT0iZm9udC13ZWlnaHQ6IGJvbGQ7Ij5BSkFYJm5ic3A7Q2hhdCZuYnNwOyZjb3B5OyZuYnNwOzIwMTU8L2E+Jm5ic3A7PHN0cm9uZz5MaXZlJm5ic3A7TWVtYmVycyZuYnNwO09ubHk8L3N0cm9uZz4=');
     //Assign the features template variable
     $this->template->assign_vars(['BBCODE_STATUS' => $bbcode_status ? sprintf($this->user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>') : sprintf($this->user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $url_status ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'S_LINKS_ALLOWED' => $url_status, 'S_COMPOSE_PM' => true, 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_SMILIES_ALLOWED' => $smilies_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status, 'S_BBCODE_URL' => $url_status, 'L_DETAILS' => $details, 'REFRESH_TIME' => $refresh, 'LAST_ID' => $this->last_id, 'LAST_POST' => $last_post, 'TIME' => time(), 'L_VERSION' => '3.0.9-BETA', 'STYLE_PATH' => generate_board_url() . '/styles/' . $this->user->style['style_path'], 'EXT_STYLE_PATH' => '' . $this->ext_path_web . 'styles/', 'FILENAME' => $this->helper->route('spaceace_ajaxchat_chat'), 'S_ARCHIVE' => !$this->get ? true : false, 'S_GET_CHAT' => $this->get ? true : false, 'S_' . $this->mode => true]);
     // Generate smiley listing
     \generate_smilies('inline', 0);
     // Build custom bbcodes array
     \display_custom_bbcodes();
     $this->whois_online();
     return $this->helper->render('chat_body.html', $this->user->lang['CHAT_ARCHIVE_EXPLAIN']);
 }
Exemplo n.º 13
0
 /**
  * Process page data to be added or edited
  *
  * @param object $entity The page entity object
  * @return null
  * @access protected
  */
 protected function add_edit_page_data($entity)
 {
     // Create an array to collect errors that will be output to the user
     $errors = array();
     // Is the form submitted
     $submit = $this->request->is_set_post('submit');
     // Load posting language file for the BBCode editor
     $this->user->add_lang('posting');
     // Add form key for form validation checks
     add_form_key('add_edit_page');
     // Collect form data
     $data = array('page_title' => $this->request->variable('page_title', '', true), 'page_route' => $this->request->variable('page_route', ''), 'page_description' => $this->request->variable('page_description', '', true), 'page_content' => $this->request->variable('page_content', '', true), 'bbcode' => $this->request->variable('parse_bbcode', false), 'magic_url' => $this->request->variable('parse_magic_url', false), 'smilies' => $this->request->variable('parse_smilies', false), 'html' => $this->request->variable('parse_html', false), 'page_template' => $this->request->variable('page_template', ''), 'page_links' => $this->request->variable('page_links', array(0)), 'page_order' => $this->request->variable('page_order', 0), 'page_display' => $this->request->variable('page_display', 0), 'page_display_to_guests' => $this->request->variable('page_guest_display', 0));
     // Grab the form data's message parsing options (possible values: 1 or 0)
     // If submit use the data from the form
     // If page edit use data stored in the entity
     // If page add use default values
     $content_parse_options = array('bbcode' => $submit ? $data['bbcode'] : ($entity->get_id() ? $entity->content_bbcode_enabled() : 1), 'magic_url' => $submit ? $data['magic_url'] : ($entity->get_id() ? $entity->content_magic_url_enabled() : 1), 'smilies' => $submit ? $data['smilies'] : ($entity->get_id() ? $entity->content_smilies_enabled() : 1), 'html' => $submit ? $data['html'] : ($entity->get_id() ? $entity->content_html_enabled() : 0));
     // Set the content parse options in the entity
     foreach ($content_parse_options as $function => $enabled) {
         call_user_func(array($entity, ($enabled ? 'content_enable_' : 'content_disable_') . $function));
     }
     // Purge temporary variable
     unset($content_parse_options);
     // If the form has been submitted, set all data and save it
     if ($submit) {
         // Test if the form is valid
         // Use -1 to allow unlimited time to submit form
         if (!check_form_key('add_edit_page', -1)) {
             $errors[] = $this->user->lang('FORM_INVALID');
         }
         // Map the form's page data fields to setters
         $map_fields = array('set_title' => $data['page_title'], 'set_route' => $data['page_route'], 'set_description' => $data['page_description'], 'set_content' => $data['page_content'], 'set_template' => $data['page_template'], 'set_order' => $data['page_order'], 'set_page_display' => $data['page_display'], 'set_page_display_to_guests' => $data['page_display_to_guests']);
         // Set the mapped page data in the entity
         foreach ($map_fields as $entity_function => $page_data) {
             try {
                 // Calling the $entity_function on the entity and passing it $page_data
                 call_user_func_array(array($entity, $entity_function), array($page_data));
             } catch (\phpbb\pages\exception\base $e) {
                 // Catch exceptions and add them to errors array
                 $errors[] = $e->get_message($this->user);
             }
         }
         // Purge temporary variable
         unset($map_fields);
         // Insert or update page
         if (empty($errors)) {
             if ($entity->get_id()) {
                 // Save the edited page entity to the database
                 $entity->save();
                 // Save the page link location data
                 $this->page_operator->insert_page_links($entity->get_id(), $data['page_links']);
                 // Log the action
                 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PAGES_EDITED_LOG', time(), array($entity->get_title()));
                 // Show user confirmation of the saved page and provide link back to the previous screen
                 trigger_error($this->user->lang('ACP_PAGES_EDIT_SUCCESS') . adm_back_link($this->u_action));
             } else {
                 // Add the new page entity to the database
                 /* @var $entity \phpbb\pages\entity\page */
                 $entity = $this->page_operator->add_page($entity);
                 // Save the page link location data (now that we can access the new id)
                 $this->page_operator->insert_page_links($entity->get_id(), $data['page_links']);
                 // Log the action
                 $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'ACP_PAGES_ADDED_LOG', time(), array($entity->get_title()));
                 // Show user confirmation of the added page and provide link back to the previous screen
                 trigger_error($this->user->lang('ACP_PAGES_ADD_SUCCESS') . adm_back_link($this->u_action));
             }
         }
     }
     /**
      * Event to add to Pages ACP add/edit pages
      *
      * @event phpbb.pages.acp_add_edit_page
      * @since 1.0.0-RC1
      */
     $this->dispatcher->dispatch('phpbb.pages.acp_add_edit_page');
     // Set template vars for Page Template select menu
     $this->create_page_template_options($entity->get_template());
     // Set template vars for Page Link Locations select menu
     $this->create_page_link_options($entity->get_id(), $data['page_links']);
     // Set output vars for display in the template
     $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'PAGES_TITLE' => $entity->get_title(), 'PAGES_ROUTE' => $entity->get_route(), 'PAGES_CONTENT' => $entity->get_content_for_edit(), 'PAGES_DESCRIPTION' => $entity->get_description(), 'PAGES_ORDER' => $entity->get_order(), 'S_PAGES_DISPLAY' => $entity->get_page_display(), 'S_PAGES_GUEST_DISPLAY' => $entity->get_page_display_to_guests(), 'S_PARSE_BBCODE_CHECKED' => $entity->content_bbcode_enabled(), 'S_PARSE_SMILIES_CHECKED' => $entity->content_smilies_enabled(), 'S_PARSE_MAGIC_URL_CHECKED' => $entity->content_magic_url_enabled(), 'S_PARSE_HTML_CHECKED' => $entity->content_html_enabled(), 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'), 'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'), 'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'), 'URL_STATUS' => $this->user->lang('URL_IS_ON'), 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, 'U_BACK' => $this->u_action));
     // Build custom bbcodes array
     include_once $this->root_path . 'includes/functions_display.' . $this->php_ext;
     display_custom_bbcodes();
 }
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache;
        global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
        include $phpbb_root_path . CL_DIRECTORY . '/includes/functions_buysell.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
        switch ($mode) {
            case 'index':
                $this->page_title = 'ACP_CLASSIFIEDS';
                $this->tpl_name = 'acp_classifieds';
                $submit = isset($_POST['submit']) ? true : false;
                if ($submit) {
                    set_config('enable_classifieds', request_var('enable_classifieds', 0));
                    set_config('disable_message', utf8_normalize_nfc(request_var('disable_message', '', true)));
                    set_config('number_expire', request_var('number_expire', 0));
                    set_config('allow_users_set_expiration', request_var('allow_users_set_expiration', 0));
                    set_config('min_expiration_by_user', request_var('min_expiration_by_user', 0));
                    set_config('max_expiration_by_user', request_var('max_expiration_by_user', 0));
                    set_config('allow_comments', request_var('allow_comments', 0));
                    set_config('enable_watch_cat', request_var('enable_watch_cat', 0));
                    set_config('allow_classifieds_feeds', request_var('allow_classifieds_feeds', 0));
                    set_config('number_ad_feeds', request_var('number_ad_feeds', 0));
                    set_config('allow_upload', request_var('allow_upload', 0));
                    set_config('max_img_size', request_var('max_img_size', 0) * 1024);
                    set_config('required_posts_to_create', request_var('required_posts_to_create', 0));
                    set_config('required_posts_to_view', request_var('required_posts_to_view', 0));
                    set_config('mandatory_phone', request_var('mandatory_phone', 0));
                    set_config('sold_color', request_var('sold_color', ''));
                    set_config('closed_color', request_var('closed_color', ''));
                    set_config('number_ads', request_var('number_ads', 0));
                    set_config('allow_addthis_button', request_var('allow_addthis_button', ''));
                    set_config('email_ad', request_var('email_ad', 0));
                    set_config('email_expire', request_var('email_expire', 0));
                    set_config('max_images_per_ad', request_var('max_images_per_ad', 0));
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                }
                $template->assign_vars(array('U_ACTION' => $this->u_action, 'ENABLE_CLASSIFIEDS' => $config['enable_classifieds'], 'DISABLE_MESSAGE' => $config['disable_message'], 'ALLOW_ADDTHIS_BUTTON' => $config['allow_addthis_button'], 'MANDATORY_PHONE' => $config['mandatory_phone'], 'NUMBER_ADS' => $config['number_ads'], 'NUMBER_EXPIRE' => $config['number_expire'], 'ALLOW_USERS_SET_EXPIRATION' => $config['allow_users_set_expiration'], 'MIN_EXPIRATION_BY_USER' => $config['min_expiration_by_user'], 'MAX_EXPIRATION_BY_USER' => $config['max_expiration_by_user'], 'EMAIL_AD' => $config['email_ad'], 'EMAIL_EXPIRE' => $config['email_expire'], 'CLOSED_COLOR' => $config['closed_color'], 'SOLD_COLOR' => $config['sold_color'], 'ALLOW_COMMENTS' => $config['allow_comments'], 'ENABLE_WATCH_CAT' => $config['enable_watch_cat'], 'ALLOW_CLASSIFIEDS_FEEDS' => $config['allow_classifieds_feeds'], 'NUMBER_AD_FEEDS' => $config['number_ad_feeds'], 'ALLOW_UPLOAD' => $config['allow_upload'], 'MAX_IMG_SIZE' => $config['max_img_size'] / 1024, 'REQUIRED_POSTS_TO_CREATE' => $config['required_posts_to_create'], 'REQUIRED_POSTS_TO_VIEW' => $config['required_posts_to_view'], 'MAX_IMAGES_PER_AD' => $config['max_images_per_ad']));
                break;
            case 'blocks':
                $this->page_title = 'ACP_CLASSIFIEDS_BLOCKS_TITLE';
                $this->tpl_name = 'acp_classifieds_blocks';
                $submit = isset($_POST['submit']) ? true : false;
                if ($submit) {
                    set_config('display_ads_on_index', request_var('display_ads_on_index', 0));
                    set_config('recent_ads_place', request_var('recent_ads_place', 0));
                    set_config('ad_num_display_on_index', request_var('ad_num_display_on_index', 0));
                    set_config('display_rand_ads_on_index', request_var('display_rand_ads_on_index', 0));
                    set_config('rand_ads_place', request_var('rand_ads_place', 0));
                    set_config('rand_ad_num_display_on_index', request_var('rand_ad_num_display_on_index', 0));
                    set_config('display_rand_miniblock', request_var('display_rand_miniblock', 0));
                    set_config('rand_miniblock_place', request_var('rand_miniblock_place', 0));
                    set_config('rand_miniblock_num_ads', request_var('rand_miniblock_num_ads', 0));
                    set_config('display_advertisers_ads', request_var('display_advertisers_ads', 0));
                    set_config('advertisers_block_place', request_var('advertisers_block_place', 0));
                    set_config('advertisers_ads_num', request_var('advertisers_ads_num', 0));
                    set_config('display_hot_ads', request_var('display_hot_ads', 0));
                    set_config('hot_block_place', request_var('hot_block_place', 0));
                    set_config('hot_ads_num', request_var('hot_ads_num', 0));
                    set_config('display_profile_last_ads', request_var('display_profile_last_ads', 0));
                    set_config('profile_num_last_ads', request_var('profile_num_last_ads', 0));
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                }
                $template->assign_vars(array('U_ACTION' => $this->u_action, 'DISPLAY_ADS_ON_INDEX' => $config['display_ads_on_index'], 'RECENT_ADS_PLACE' => $config['recent_ads_place'], 'AD_NUM_DISPLAY_ON_INDEX' => $config['ad_num_display_on_index'], 'DISPLAY_RAND_ADS_ON_INDEX' => $config['display_rand_ads_on_index'], 'RAND_ADS_PLACE' => $config['rand_ads_place'], 'RAND_AD_NUM_DISPLAY_ON_INDEX' => $config['rand_ad_num_display_on_index'], 'DISPLAY_RAND_MINIBLOCK' => $config['display_rand_miniblock'], 'RAND_MINIBLOCK_PLACE' => $config['rand_miniblock_place'], 'RAND_MINIBLOCK_NUM_ADS' => $config['rand_miniblock_num_ads'], 'DISPLAY_ADVERTISERS_ADS' => $config['display_advertisers_ads'], 'ADVERTISERS_BLOCK_PLACE' => $config['advertisers_block_place'], 'ADVERTISERS_ADS_NUM' => $config['advertisers_ads_num'], 'DISPLAY_HOT_ADS' => $config['display_hot_ads'], 'HOT_BLOCK_PLACE' => $config['hot_block_place'], 'HOT_ADS_NUM' => $config['hot_ads_num'], 'DISPLAY_PROFILE_LAST_ADS' => $config['display_profile_last_ads'], 'PROFILE_LAST_ADS_NUM' => $config['profile_num_last_ads']));
                break;
            case 'manage':
                $this->page_title = 'ACP_CLASSIFIEDS_MANAGE_TITLE';
                $this->tpl_name = 'acp_classifieds_manage';
                $action = request_var('action', '');
                $status = request_var('status', '');
                $id = request_var('id', 0);
                $ad_id = request_var('ad_id', 0);
                $profile_user = request_var('u', 0);
                $add_days = request_var('add_days', '');
                $limit = 20;
                $start = request_var('start', 0);
                switch ($action) {
                    case "delete":
                        if (confirm_box(true)) {
                            $sql = 'DELETE FROM ' . CLASSIFIEDS_TABLE . '
							 				  WHERE ad_id = ' . $ad_id;
                            $db->sql_query($sql);
                            // select images from deleted ad
                            $sql = 'SELECT *
												FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
												  WHERE ad_id = ' . $ad_id;
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // remove images from FTP and DB
                                @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row['image_name']);
                                $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $ad_id . '
														AND image_name = "' . $row['image_name'] . '"';
                                $result2 = $db->sql_query($sql);
                            }
                            redirect(append_sid("{$this->u_action}", "status=active"));
                        } else {
                            confirm_box(false, $user->lang['DELETE_CONFIRM']);
                            redirect(append_sid("{$this->u_action}", "status=active"));
                        }
                        break;
                    case "add_days":
                        if (confirm_box(true)) {
                            $days = '+' . $add_days . 'days';
                            $now = time();
                            $expire = strtotime($days, $now);
                            $sql_ary = array('ad_expire' => $expire, 'ad_date' => $now, 'expire_email' => 0);
                            $sql = 'UPDATE ' . CLASSIFIEDS_TABLE . '
												SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
												  WHERE ad_id = ' . $ad_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}", "status=expired"));
                        } else {
                            confirm_box(false, $user->lang['EXTEND_CONFIRM'], build_hidden_fields(array('add_days' => $add_days)));
                            redirect(append_sid("{$this->u_action}", "status=expired"));
                        }
                        break;
                }
                if ($status != '') {
                    $pagination_url = $status == 'viewuser' ? $this->u_action . "&amp;status={$status}&amp;u={$profile_user}" : $this->u_action . "&amp;status={$status}";
                } else {
                    $pagination_url = $this->u_action;
                }
                $template->assign_vars(array('STATUS' => $status, 'VIEW_ALL_ACTIVE' => append_sid("{$this->u_action}", "status=active"), 'VIEW_ALL_CLOSED' => append_sid("{$this->u_action}", "status=closed"), 'VIEW_ALL_SOLD' => append_sid("{$this->u_action}", "status=sold"), 'VIEW_ALL_EXPIRED' => append_sid("{$this->u_action}", "status=expired")));
                if (!empty($status)) {
                    $ad_ary = array('SELECT' => 'a.* , u.user_id, u.username, u.user_colour', 'FROM' => array(CLASSIFIEDS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(USERS_TABLE => 'u'), 'ON' => 'u.user_id = a.ad_poster_id')), 'WHERE' => 'a.ad_status = ' . ACTIVE . ' AND a.ad_expire > ' . time(), 'ORDER_BY' => 'a.ad_date DESC');
                    switch ($status) {
                        case "active":
                            $ad_ary['WHERE'] = 'a.ad_status = ' . ACTIVE . ' AND a.ad_expire > ' . time();
                            break;
                        case "closed":
                            $ad_ary['WHERE'] = 'a.ad_status = ' . CLOSED . ' AND a.ad_expire > ' . time();
                            break;
                        case "sold":
                            $ad_ary['WHERE'] = 'a.ad_status = ' . SOLD . ' AND a.ad_expire > ' . time();
                            break;
                        case "expired":
                            $ad_ary['WHERE'] = 'a.ad_expire <' . time();
                            break;
                        case "viewuser":
                            $ad_ary['WHERE'] = 'a.ad_poster_id = "' . $profile_user . '"';
                            break;
                    }
                    $sql = $db->sql_build_query('SELECT', $ad_ary);
                    $result = $db->sql_query_limit($sql, $limit, $start);
                    $username = '';
                    while ($row = $db->sql_fetchrow($result)) {
                        $template->assign_block_vars('ad', array('AD_ID' => $row['ad_id'], 'AD_TITLE' => $row['ad_title'], 'AD_LINK' => append_sid("{$phpbb_root_path}" . CL_DIRECTORY . "/single_ad.{$phpEx}", "ad_id={$row['ad_id']}"), 'AD_DATE' => $user->format_date($row['ad_date']), 'AD_CATEGORY' => get_ad_category($row['cat_id']), 'AD_POSTER' => $row['username'], 'AD_POSTER_COLOR' => $row['user_colour'], 'AD_STATUS' => $row['ad_status'], 'DELETE_LINK' => $this->u_action . '&amp;action=delete&amp;ad_id= ' . $row['ad_id'], 'AD_EXPIRE' => $user->format_date($row['ad_expire']), 'EXPIRE' => $row['ad_expire'], 'EDIT_EXPIRE' => $this->u_action . '&amp;action=add_days&amp;ad_id=' . $row['ad_id']));
                        $username = $row['username'];
                    }
                    $ad_ary['SELECT'] = 'COUNT(a.ad_id) as total_ads';
                    $sql = $db->sql_build_query('SELECT', $ad_ary);
                    $result = $db->sql_query($sql);
                    $total_ads = $db->sql_fetchfield('total_ads');
                    $db->sql_freeresult($result);
                    $template->assign_vars(array('USERS_ADS' => $username . '\'s ' . $user->lang['ADS'], 'PAGINATION' => generate_pagination($pagination_url, $total_ads, $limit, $start), 'PAGE_NUMBER' => on_page($total_ads, $limit, $start), 'TOTAL_ADS' => sprintf($user->lang['TOTAL_ADS'], $total_ads)));
                }
                break;
            case 'purge':
                $this->page_title = 'ACP_CLASSIFIEDS_PURGE_TITLE';
                $this->tpl_name = 'acp_classifieds_purge';
                if ((int) $user->data['user_type'] !== USER_FOUNDER) {
                    trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                $action = request_var('action', '');
                switch ($action) {
                    case 'purge_expired_sold_closed':
                        if (!confirm_box(true)) {
                            $confirm = true;
                            $confirm_lang = 'PURGE_EXPIRED_SOLD_CLOSED_ADS_CONFIRM';
                            if ($confirm) {
                                confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                            }
                        } else {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ad_expire < " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND ad_status != 0";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ad_expire < " . time() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND ad_status != 0";
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        }
                        break;
                    case 'purge_closed':
                        if (!confirm_box(true)) {
                            $confirm = true;
                            $confirm_lang = 'PURGE_CLOSED_ADS_CONFIRM';
                            if ($confirm) {
                                confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                            }
                        } else {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n            \t\t\t\t\t\tWHERE ad_status = 2";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ad_status = 2";
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        }
                        break;
                    case 'purge_sold':
                        if (!confirm_box(true)) {
                            $confirm = true;
                            $confirm_lang = 'PURGE_SOLD_ADS_CONFIRM';
                            if ($confirm) {
                                confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                            }
                        } else {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n            \t\t\t\t\t\tWHERE ad_status = 1";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ad_status = 1";
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        }
                        break;
                    case 'purge_expired':
                        if (!confirm_box(true)) {
                            $confirm = true;
                            $confirm_lang = 'PURGE_EXPIRED_ADS_CONFIRM';
                            if ($confirm) {
                                confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                            }
                        } else {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t  WHERE ad_expire < " . time();
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tad_expire < " . time();
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        }
                        break;
                    case 'purge_active':
                        if (!confirm_box(true)) {
                            $confirm = true;
                            $confirm_lang = 'PURGE_ACTIVE_ADS_CONFIRM';
                            if ($confirm) {
                                confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                            }
                        } else {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n            \t\t\t\t\t\tWHERE ad_status = 0\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND ad_expire > " . time();
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE ad_status = 0\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND ad_expire > " . time();
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        }
                        break;
                }
                $template->assign_vars(array('U_PURGE_EXPIRED_SOLD_CLOSED' => $this->u_action . '&amp;action=purge_expired_sold_closed', 'U_PURGE_CLOSED' => $this->u_action . '&amp;action=purge_closed', 'U_PURGE_SOLD' => $this->u_action . '&amp;action=purge_sold', 'U_PURGE_EXPIRED' => $this->u_action . '&amp;action=purge_expired', 'U_PURGE_ACTIVE' => $this->u_action . '&amp;action=purge_active', 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
                break;
            case 'cats':
                $this->page_title = 'ACP_CLASSIFIEDS_CATS_TITLE';
                $this->tpl_name = 'acp_classifieds_cats';
                $action = request_var('action', '');
                $id = request_var('id', 0);
                $name = request_var('name', '', true);
                $delete_cat = request_var('delete_cat', '');
                $delete_parent = request_var('delete_parent', '');
                $sql_ary = array('name' => $name, 'parent' => request_var('parent', 0), 'parent_id' => request_var('parent_id', 0));
                switch ($action) {
                    case 'move_up':
                    case 'move_down':
                        if (!$id) {
                            trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT *
										FROM ' . CLASSIFIEDS_CATEGORY_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE id = {$id}";
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$row) {
                            trigger_error($user->lang['NO_CATEGORY'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $move_category_name = move_category_by($row, $action);
                        if ($move_category_name !== false) {
                            $cache->destroy('sql', CLASSIFIEDS_CATEGORY_TABLE);
                        }
                        break;
                    case "newcat":
                        $sql = 'SELECT MAX(right_id) AS right_id
											FROM ' . CLASSIFIEDS_CATEGORY_TABLE;
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        $sql_ary['left_id'] = $row['right_id'] + 1;
                        $sql_ary['right_id'] = $row['right_id'] + 2;
                        $sql = 'INSERT INTO ' . CLASSIFIEDS_CATEGORY_TABLE . $db->sql_build_array('INSERT', $sql_ary);
                        $db->sql_query($sql);
                        break;
                    case "editcat":
                        $sql = 'UPDATE ' . CLASSIFIEDS_CATEGORY_TABLE . '
											SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
											WHERE id = ' . $id;
                        $db->sql_query($sql);
                        break;
                    case "purgecat":
                        if (confirm_box(true)) {
                            // select ad_id of all ads, which will be purged
                            $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE cat_id = " . $id;
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                // select images from deleted ad
                                $sql = 'SELECT ad_id, image_name
													FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
													WHERE ad_id = ' . $row['ad_id'];
                                $result2 = $db->sql_query($sql);
                                while ($row2 = $db->sql_fetchrow($result2)) {
                                    // remove images from FTP and DB
                                    @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                    $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row2['ad_id'] . '
																AND image_name = "' . $row2['image_name'] . '"';
                                    $result3 = $db->sql_query($sql);
                                }
                            }
                            $sql = "DELETE FROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE cat_id = " . $id;
                            $result = $db->sql_query($sql);
                            trigger_error($user->lang['PURGED_SUCCESFULLY'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['PURGE_CAT_CONFIRM']);
                        }
                        break;
                    case "deletecat":
                        if (confirm_box(true)) {
                            if ($delete_parent == '') {
                                // Now if there are ads under the deleted category they need to be moved to another category or deleted
                                if (empty($delete_cat) || $delete_cat == '0') {
                                    // select ad_id of all ads, which will be purged
                                    $sql = "SELECT ad_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . CLASSIFIEDS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE cat_id = " . $id;
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        // select images from deleted ad
                                        $sql = 'SELECT ad_id, image_name
															FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
															WHERE ad_id = ' . $row['ad_id'];
                                        $result2 = $db->sql_query($sql);
                                        while ($row2 = $db->sql_fetchrow($result2)) {
                                            // remove images from FTP and DB
                                            @unlink("{$phpbb_root_path}" . CL_DIRECTORY . "/images/" . $row2['image_name']);
                                            $sql = 'DELETE FROM  ' . CLASSIFIEDS_IMAGES_TABLE . '
																	WHERE ad_id = ' . $row2['ad_id'] . '
																		AND image_name = "' . $row2['image_name'] . '"';
                                            $result3 = $db->sql_query($sql);
                                        }
                                    }
                                    $sql = 'DELETE FROM ' . CLASSIFIEDS_TABLE . '
														WHERE cat_id = ' . $id;
                                    $db->sql_query($sql);
                                } else {
                                    $sql = 'UPDATE ' . CLASSIFIEDS_TABLE . '
														SET cat_id = ' . $delete_cat . '
														WHERE cat_id= ' . $id;
                                    $db->sql_query($sql);
                                }
                            } else {
                                $sql = 'UPDATE ' . CLASSIFIEDS_CATEGORY_TABLE . '
													SET parent_id = 0
													WHERE parent_id = ' . $id;
                                $db->sql_query($sql);
                            }
                            $sql = 'DELETE FROM ' . CLASSIFIEDS_CATEGORY_TABLE . '
												WHERE id = ' . $id;
                            $db->sql_query($sql);
                        } else {
                            confirm_box(false, $user->lang['DELETE_CAT_CONFIRM'], build_hidden_fields(array('delete_cat' => $delete_cat)));
                        }
                        break;
                }
                $sql = 'SELECT *
								FROM ' . CLASSIFIEDS_CATEGORY_TABLE . '
									ORDER BY left_id ASC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $url = $this->u_action . "&amp;id={$row['id']}";
                    $template->assign_block_vars('cat', array('NAME' => $row['name'], 'ID' => $row['id'], 'EDIT_CAT' => $this->u_action . '&amp;action=editcat&amp;id=' . $row['id'], 'PURGE_CAT' => $this->u_action . '&amp;action=purgecat&amp;id=' . $row['id'], 'DELETE_PARENT_CAT' => $this->u_action . '&amp;action=deletecat&amp;id=' . $row['id'] . '&amp;delete_parent=1', 'DELETE_CAT' => $this->u_action . '&amp;action=deletecat&amp;id=' . $row['id'] . '&amp;delete_cat=' . $delete_cat, 'U_MOVE_UP' => $url . '&amp;action=move_up', 'U_MOVE_DOWN' => $url . '&amp;action=move_down', 'PARENT' => $row['parent'], 'PARENT_ID' => $row['parent_id'], 'PARENT_CAT' => get_category_parent($row['parent_id'])));
                }
                $template->assign_vars(array('U_NEW_CAT' => $this->u_action . '&amp;action=newcat'));
                break;
            case 'rules':
                $this->page_title = 'ACP_CLASSIFIEDS_RULES_TITLE';
                $this->tpl_name = 'acp_classifieds_rules';
                $user->add_lang('posting');
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                $rules = request_var('rules', '');
                $template->assign_vars(array('RULES' => $rules, 'GENERAL_RULES' => append_sid($this->u_action, "rules=general"), 'BUYER_RULES' => append_sid($this->u_action, "rules=buyer"), 'SELLER_RULES' => append_sid($this->u_action, "rules=seller")));
                if (!empty($rules)) {
                    if ($rules == 'general') {
                        $id = 1;
                    } elseif ($rules == 'buyer') {
                        $id = 2;
                    } elseif ($rules == 'seller') {
                        $id = 3;
                    }
                    // select rules data
                    $sql = 'SELECT *
                    FROM ' . CLASSIFIEDS_RULES_TABLE . '
                      WHERE rules_id = ' . $id . '
										    ORDER BY rules_id ASC';
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $template->assign_vars(array('RULES_ID' => $row['rules_id'], 'RULES_TITLE' => $row['rules_title'], 'RULES_TEXT' => $row['rules_text'], 'DISPLAY_RULES' => $row['display_rules'], 'MUST_AGREE' => $row['must_agree'], 'DISPLAY_AS_LINK' => $row['display_as_link'], 'L_ACP_CLASSIFIEDS_RULES' => $user->lang('ACP_CLASSIFIEDS_RULES' . $id), 'L_RULES_TITLE' => $user->lang('RULES_TITLE' . $id), 'L_RULES_DISPLAY' => $user->lang('RULES_DISPLAY' . $id), 'L_MUST_AGREE' => $user->lang('MUST_AGREE' . $id), 'L_MUST_AGREE_EXPLAIN' => $user->lang('MUST_AGREE_EXPLAIN' . $id), 'L_DISPLAY_AS_LINK' => $user->lang('DISPLAY_AS_LINK' . $id), 'L_DISPLAY_AS_LINK_EXPLAIN' => $user->lang('DISPLAY_AS_LINK_EXPLAIN' . $id)));
                    $db->sql_freeresult($result);
                    display_custom_bbcodes();
                    $submit = isset($_POST['submit']) ? true : false;
                    $preview = isset($_POST['preview']) ? true : false;
                    if ($submit) {
                        $rules_id = request_var('rules_id', 0);
                        $rules_title = utf8_normalize_nfc(request_var('rules_title', '', true));
                        $display_rules = request_var('display_rules', 0);
                        $must_agree = request_var('must_agree', 0);
                        $rules_text = utf8_normalize_nfc(request_var('rules_text', '', true));
                        $display_as_link = request_var('display_as_link', 0);
                        $sql_ary = array('rules_id' => $rules_id, 'rules_title' => $rules_title, 'display_rules' => $display_rules, 'must_agree' => $must_agree, 'rules_text' => $rules_text, 'display_as_link' => $display_as_link);
                        $sql = 'UPDATE ' . CLASSIFIEDS_RULES_TABLE . '
											SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
											WHERE rules_id = ' . $rules_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action . '&amp;rules=' . $rules));
                    }
                    if ($preview == true) {
                        $rules_text = utf8_normalize_nfc(request_var('rules_text', '', true));
                        $rules_text2 = $rules_text;
                        $uid = $bitfield = $options = '';
                        $allow_bbcode = $allow_smilies = $allow_urls = true;
                        generate_text_for_storage($rules_text, $uid, $bitfield, $options, $allow_bbcode, $allow_urls, $allow_smilies);
                        $preview_text = generate_text_for_display($rules_text, $uid, $bitfield, $options);
                        $template->assign_vars(array('RULES_TEXT' => $rules_text2));
                    }
                    $template->assign_vars(array('U_ACTION' => $this->u_action . '&amp;rules=' . $rules, 'S_BBCODE_ALLOWED' => true, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_IMG' => true, 'S_LINKS_ALLOWED' => true, 'S_BBCODE_FLASH' => false, 'PREVIEW_TEXT' => $preview ? $preview_text : '', 'S_PREVIEW' => $preview));
                }
                break;
            case 'prefixes':
                $this->page_title = 'ACP_CLASSIFIEDS_PREFIXES_TITLE';
                $this->tpl_name = 'acp_classifieds_prefixes';
                $action = request_var('action', '');
                $prefix_id = request_var('prefix_id', '');
                $prefix_short = request_var('prefix_short', '');
                $prefix_name = request_var('prefix_name', '', true);
                $prefix_color = request_var('prefix_color', '');
                switch ($action) {
                    case "delete_prefix":
                        if (confirm_box(true)) {
                            $sql = 'DELETE FROM ' . CLASSIFIEDS_PREFIXES_TABLE . '
							 				WHERE prefix_id = ' . $prefix_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['DELETE_PREFIX_CONFIRM']);
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                    case "add_prefix":
                        $sql = 'INSERT INTO ' . CLASSIFIEDS_PREFIXES_TABLE . ' (prefix_short, prefix_name, prefix_color)
                      VALUES ("' . $prefix_short . '", "' . $prefix_name . '", "' . $prefix_color . '")';
                        $db->sql_query($sql);
                        redirect(append_sid("{$this->u_action}"));
                        break;
                    case "edit_prefix":
                        if (confirm_box(true)) {
                            $sql_ary = array('prefix_name' => $prefix_name, 'prefix_short' => $prefix_short, 'prefix_color' => $prefix_color);
                            $sql = 'UPDATE ' . CLASSIFIEDS_PREFIXES_TABLE . '
  											SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
                          WHERE prefix_id = ' . $prefix_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['EDIT_PREFIX_CONFIRM'], build_hidden_fields(array('prefix_name' => $prefix_name, 'prefix_short' => $prefix_short, 'prefix_color' => $prefix_color)));
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                }
                $submit = isset($_POST['submit']) ? true : false;
                if ($submit) {
                    set_config('mandatory_ad_prefix', request_var('mandatory_ad_prefix', 0));
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                }
                $sql = 'SELECT *
                  FROM ' . CLASSIFIEDS_PREFIXES_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('prefixes', array('ID' => $row['prefix_id'], 'NAME' => $row['prefix_name'], 'SHORT' => $row['prefix_short'], 'COLOR' => $row['prefix_color'], 'L_SEARCH_PREFIX' => sprintf($user->lang['SEARCH_PREFIX'], $row['prefix_short']), 'U_SEARCH' => append_sid("{$phpbb_root_path}" . CL_DIRECTORY . "/index.{$phpEx}", "mode=search&amp;sprefix={$row['prefix_id']}"), 'U_DELETE' => $this->u_action . '&amp;action=delete_prefix&amp;prefix_id= ' . $row['prefix_id'], 'U_EDIT' => $this->u_action . '&amp;action=edit_prefix&amp;prefix_id=' . $row['prefix_id']));
                }
                $template->assign_vars(array('U_ADD_PREFIX' => $this->u_action . '&amp;action=add_prefix', 'U_ACTION' => $this->u_action, 'MANDATORY_AD_PREFIX' => $config['mandatory_ad_prefix']));
                break;
            case 'locations':
                $this->page_title = 'ACP_CLASSIFIEDS_LOCATIONS_TITLE';
                $this->tpl_name = 'acp_classifieds_locations';
                $action = request_var('action', '');
                $location_id = request_var('location_id', '');
                $location_name = utf8_normalize_nfc(request_var('location_name', '', true));
                switch ($action) {
                    case "delete_location":
                        if (confirm_box(true)) {
                            $sql = 'DELETE FROM ' . CLASSIFIEDS_LOCATIONS_TABLE . '
							 				WHERE location_id = ' . $location_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['DELETE_LOCATION_CONFIRM']);
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                    case "add_location":
                        $location_list = explode("\n", $location_name);
                        if (empty($location_name)) {
                            trigger_error($user->lang['NO_LOCATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        } else {
                            $sql_ary = array();
                            foreach ($location_list as $location_entry) {
                                $sql_ary[] = array('location_name' => (string) $location_entry);
                            }
                            $db->sql_multi_insert(CLASSIFIEDS_LOCATIONS_TABLE, $sql_ary);
                        }
                        redirect(append_sid("{$this->u_action}"));
                        break;
                    case "edit_location":
                        if (confirm_box(true)) {
                            $sql_ary = array('location_name' => $location_name);
                            $sql = 'UPDATE ' . CLASSIFIEDS_LOCATIONS_TABLE . '
  											SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
                          WHERE location_id = ' . $location_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['EDIT_LOCATION_CONFIRM'], build_hidden_fields(array('location_name' => $location_name)));
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                }
                $submit = isset($_POST['submit']) ? true : false;
                if ($submit) {
                    set_config('mandatory_ad_location', request_var('mandatory_ad_location', 0));
                    set_config('fill_location_to_trade', request_var('fill_location_to_trade', 0));
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                }
                $sql = 'SELECT *
                  FROM ' . CLASSIFIEDS_LOCATIONS_TABLE . '
                    ORDER BY location_name ASC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('locations', array('ID' => $row['location_id'], 'NAME' => $row['location_name'], 'L_SEARCH_LOCATION' => sprintf($user->lang['SEARCH_LOCATION'], $row['location_name']), 'U_SEARCH' => append_sid("{$phpbb_root_path}" . CL_DIRECTORY . "/index.{$phpEx}", "mode=search&amp;slocation={$row['location_id']}"), 'U_DELETE' => $this->u_action . '&amp;action=delete_location&amp;location_id= ' . $row['location_id'], 'U_EDIT' => $this->u_action . '&amp;action=edit_location&amp;location_id=' . $row['location_id']));
                }
                $template->assign_vars(array('U_ADD_LOCATION' => $this->u_action . '&amp;action=add_location', 'U_ACTION' => $this->u_action, 'MANDATORY_AD_LOCATION' => $config['mandatory_ad_location'], 'FILL_LOCATION_TO_TRADE' => $config['fill_location_to_trade']));
                break;
            case 'currency':
                $this->page_title = 'ACP_CLASSIFIEDS_CURRENCY_TITLE';
                $this->tpl_name = 'acp_classifieds_currency';
                $action = request_var('action', '');
                $currency_id = request_var('currency_id', '');
                $currency_short = request_var('short', '', true);
                $currency_name = request_var('name', '', true);
                switch ($action) {
                    case "delete_currency":
                        if (confirm_box(true)) {
                            $sql = 'DELETE FROM ' . CLASSIFIEDS_CURRENCY_TABLE . '
							 				WHERE id = ' . $currency_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['DELETE_CURRENCY_CONFIRM']);
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                    case "add_currency":
                        $sql = 'INSERT INTO ' . CLASSIFIEDS_CURRENCY_TABLE . ' (short, name)
                      VALUES ("' . $currency_short . '", "' . $currency_name . '")';
                        $db->sql_query($sql);
                        redirect(append_sid("{$this->u_action}"));
                        break;
                    case "edit_currency":
                        if (confirm_box(true)) {
                            $sql_ary = array('name' => $currency_name, 'short' => $currency_short);
                            $sql = 'UPDATE ' . CLASSIFIEDS_CURRENCY_TABLE . '
  											SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
                          WHERE id = ' . $currency_id;
                            $db->sql_query($sql);
                            redirect(append_sid("{$this->u_action}"));
                        } else {
                            confirm_box(false, $user->lang['EDIT_CURRENCY_CONFIRM'], build_hidden_fields(array('name' => $currency_name, 'short' => $currency_short)));
                            redirect(append_sid("{$this->u_action}"));
                        }
                        break;
                }
                $submit = isset($_POST['submit']) ? true : false;
                if ($submit) {
                    set_config('default_currency', request_var('default_currency', ''));
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                }
                $sql = 'SELECT *
                  FROM ' . CLASSIFIEDS_CURRENCY_TABLE;
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('currency', array('ID' => $row['id'], 'NAME' => $row['name'], 'SHORT' => $row['short'], 'U_DELETE' => $this->u_action . '&amp;action=delete_currency&amp;currency_id= ' . $row['id'], 'U_EDIT' => $this->u_action . '&amp;action=edit_currency&amp;currency_id=' . $row['id']));
                }
                $template->assign_vars(array('U_ADD_CURRENCY' => $this->u_action . '&amp;action=add_currency', 'U_ACTION' => $this->u_action, 'DEFAULT_CURRENCY' => $config['default_currency']));
                break;
        }
    }
Exemplo n.º 15
0
 /**
  * Assigns BBCodes and smilies to the template
  */
 protected function assign_bbcodes_smilies()
 {
     // Display custom bbcodes
     if ($this->config['allow_bbcode'] && $this->auth->acl_get('u_mchat_bbcode')) {
         $default_bbcodes = array('B', 'I', 'U', 'QUOTE', 'CODE', 'LIST', 'IMG', 'URL', 'SIZE', 'COLOR', 'EMAIL', 'FLASH');
         // Let's remove the default bbcodes
         $disallowed_bbcode_array = explode('|', strtoupper($this->config['mchat_bbcode_disallowed']));
         foreach ($default_bbcodes as $default_bbcode) {
             if (!in_array($default_bbcode, $disallowed_bbcode_array)) {
                 $this->template->assign_vars(array('S_MCHAT_BBCODE_' . $default_bbcode => true));
             }
         }
         if (!function_exists('display_custom_bbcodes')) {
             include $this->root_path . 'includes/functions_display.' . $this->php_ext;
         }
         display_custom_bbcodes();
     }
     // Smile row
     if ($this->config['allow_smilies'] && $this->auth->acl_get('u_mchat_smilies')) {
         if (!function_exists('generate_smilies')) {
             include $this->root_path . 'includes/functions_posting.' . $this->php_ext;
         }
         generate_smilies('inline', 0);
     }
 }
Exemplo n.º 16
0
    public function medals_system()
    {
        if (!$this->config['medals_active']) {
            $url = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext);
            $message = "This mod is not active. <br /><br />Click <a href=\"{$url}\">here</a> to return to the index.<br />";
            trigger_error($message);
        }
        // Gather post and get variables
        $mode = $this->request->variable('m', '');
        $from = $this->request->variable('f', '');
        $user_id = $this->request->variable('u', 0);
        $usernames = $this->request->variable('add', '', true);
        $medal_id = $this->request->variable('mid', 0);
        $med_id = $this->request->variable('med', 0);
        $submit = $this->request->is_set_post('submit');
        $catchoice = $this->request->variable('cat', $this->getfirstcat());
        // Dynamic Medal Image creation
        if ($mode == "mi") {
            $medal = $this->request->variable('med', '');
            $device = $this->request->variable('d', '');
            $this->dynamic->create_dynamic_image($medal, $device);
            exit;
        }
        $phpbb_root_path = $this->phpbb_root_path;
        $phpEx = $this->php_ext;
        $medals_path = generate_board_url() . '/images/medals';
        include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
        $this->config['points_enable'] = isset($this->config['points_enable']) ? $this->config['points_enable'] : 0;
        $medals = array();
        $sql = "SELECT *\n\t\t\tFROM " . $this->tb_medal . "\n\t\t\tORDER BY order_id ASC";
        $result = $this->db->sql_query($sql);
        while ($row = $this->db->sql_fetchrow($result)) {
            $medals[$row['id']] = array('name' => $row['name'], 'image' => $medals_path . '/' . $row['image'], 'device' => $medals_path . '/devices/' . $row['device'], 'dynamic' => $row['dynamic'], 'parent' => $row['parent'], 'id' => $row['id'], 'number' => $row['number'], 'nominated' => $row['nominated'], 'order_id' => $row['order_id'], 'description' => $row['description'], 'points' => $row['points']);
        }
        $this->db->sql_freeresult($result);
        $sql = "SELECT *\n\t\t\tFROM " . $this->tb_medals_cats . "\n\t\t\tORDER BY order_id ASC";
        $result = $this->db->sql_query($sql);
        $cats = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $cats[$row['id']] = array('name' => $row['name'], 'id' => $row['id'], 'order_id' => $row['order_id']);
            $this->template->assign_block_vars('catlinkrow', array('U_CATPAGE' => $this->helper->route('bb3mobi_medals_controller', array('cat' => $row['id'])), 'MEDAL_CAT' => $row['name']));
        }
        $this->db->sql_freeresult($result);
        generate_smilies('inline', 0);
        $this->template->assign_vars(array('S_CAN_AWARD_MEDALS' => $this->user->data['user_type'] == USER_FOUNDER || $this->auth->acl_get('u_award_medals') ? true : false, 'S_CAN_NOMINATE_MEDALS' => $this->auth->acl_get('u_nominate_medals') && $user_id != $this->user->data['user_id'] ? true : false, 'U_NOMINATE_PANEL' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'nominate', 'u' => $user_id)), 'U_AWARD_PANEL' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'award', 'u' => $user_id)), 'U_VALIDATE_PANEL' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'validate', 'u' => $user_id)), 'U_AWARDED_PANEL' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'awarded', 'u' => $user_id))));
        switch ($mode) {
            case 'nominate':
                if ($this->user->data['user_id'] == ANONYMOUS || !$this->auth->acl_get('u_nominate_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if ($user_id == 0 || $user_id == ANONYMOUS) {
                    trigger_error('NO_USER_ID');
                }
                if ($user_id == $this->user->data['user_id']) {
                    trigger_error('NOT_SELF');
                }
                $sql = "SELECT *\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\tORDER BY medal_id AND nominated";
                $result = $this->db->sql_query($sql);
                $my_medals = array();
                while ($row = $this->db->sql_fetchrow($result)) {
                    $awarded_by_me = isset($my_medals[$row['medal_id']]['awarded_by_me']) && $row['nominated'] == 1 ? $my_medals[$row['medal_id']]['awarded_by_me'] : 0;
                    $row['awarded_by_me'] = $this->user->data['user_id'] == $row['awarder_id'] && $awarded_by_me == 0 && $row['nominated'] == 1 ? 1 : $awarded_by_me;
                    $my_medals[$row['medal_id']] = $row;
                }
                $this->db->sql_freeresult($result);
                $sql = "SELECT user_id, username, user_colour\n\t\t\t\t\tFROM " . USERS_TABLE . "\n\t\t\t\t\tWHERE user_id = {$user_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['username']);
                $medals_options = '<option value=""></option>';
                $temp_string = '';
                $i = 0;
                foreach ($cats as $key => $value) {
                    $at_least_one = false;
                    foreach ($medals as $key2 => $value2) {
                        if ($value2['parent'] == $value['id']) {
                            $can_award = false;
                            $my_medals[$value2['id']]['awarded_by_me'] = isset($my_medals[$value2['id']]['awarded_by_me']) ? $my_medals[$value2['id']]['awarded_by_me'] : 0;
                            if ($value2['nominated'] == 1 && $my_medals[$value2['id']]['awarded_by_me'] == 0) {
                                $temp_string .= '<option value="' . $value2['id'] . '">&bull;&nbsp;' . $value2['name'] . '</option>';
                                $at_least_one = true;
                            }
                        }
                    }
                    if ($at_least_one) {
                        $medals_options .= '<option value="">' . $value['name'] . '</option>';
                        $medals_options .= $temp_string;
                        $at_least_one = false;
                        $temp_string = '';
                        $i++;
                    }
                }
                if ($i == 0) {
                    trigger_error(sprintf($this->user->lang['NO_MEDALS_TO_NOMINATE'], append_sid('memberlist.php?mode=viewprofile&u=' . $user_id)));
                }
                $medals_arr = 'var medals = new Array();';
                $medals_desc_arr = 'var medals_desc = new Array();';
                foreach ($medals as $key => $value) {
                    $medals_arr .= 'medals[' . $value['id'] . '] = "' . $value['image'] . '";';
                    $medals_desc_arr .= 'medals_desc[' . $value['id'] . '] = "' . $value['description'] . '";';
                }
                $medals_arr .= "\n" . $medals_desc_arr . "\n";
                $bbcode_status = $this->config['allow_bbcode'] ? true : false;
                $smilies_status = $bbcode_status && $this->config['allow_smilies'] ? true : false;
                $img_status = $bbcode_status ? true : false;
                $url_status = $bbcode_status && $this->config['allow_post_links'] ? true : false;
                $flash_status = $bbcode_status ? true : false;
                $quote_status = $bbcode_status ? true : false;
                display_custom_bbcodes();
                $this->template->assign_vars(array('USERNAME' => $username, 'MEDALS' => $medals_options, 'JS' => $medals_arr, 'U_MEDALS_ACTION' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'submit_nomination', 'u' => $user_id)), 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status));
                page_header($this->user->lang['NOMINATE']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medalcp_nominate.html'));
                page_footer();
                break;
            case 'submit_nomination':
                if ($this->user->data['user_id'] == ANONYMOUS || !$this->auth->acl_get('u_nominate_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                $medal_id = $this->request->variable('medal', 0);
                if (!$medal_id) {
                    $redirect = $this->helper->route('bb3mobi_medals_controller', array('m' => 'nominate', 'u' => $user_id));
                    meta_refresh(3, $redirect);
                    trigger_error('NO_MEDAL_ID');
                }
                include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
                $this->user->add_lang('ucp');
                $message = utf8_normalize_nfc($this->request->variable('message', '', true));
                if (!strlen($message)) {
                    $return_to = $this->helper->route('bb3mobi_medals_controller', array('m' => 'nominate', 'u' => $user_id));
                    trigger_error(sprintf($this->user->lang['NO_MEDAL_MSG'], $return_to));
                }
                $sql = "SELECT *\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE user_id = {$user_id} \n\t\t\t\t\t\tAND medal_id = {$medal_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                if (!$medals[$medal_id]['number'] > 1 && !empty($row)) {
                    trigger_error(sprintf($this->user->lang['CANNOT_AWARD_MULTIPLE'], append_sid('memberlist.php?mode=viewprofile&u=' . $user_id)));
                }
                generate_text_for_storage($message, $this->uid, $this->bitfield, $this->m_flags, $this->allow_bbcode, $this->allow_urls, $this->allow_smilies);
                $sql_ary = array('medal_id' => $medal_id, 'user_id' => $user_id, 'awarder_id' => $this->user->data['user_id'], 'awarder_un' => $this->user->data['username'], 'awarder_color' => $this->user->data['user_colour'], 'nominated' => 1, 'nominated_reason' => $message, 'time' => time(), 'bbuid' => $this->uid, 'bitfield' => $this->bitfield);
                $sql = 'INSERT INTO ' . $this->tb_medals_awarded . ' ' . $this->db->sql_build_array('INSERT', $sql_ary);
                $this->db->sql_query($sql);
                $redirect = append_sid('memberlist.php?mode=viewprofile&u=' . $user_id);
                meta_refresh(3, $redirect);
                trigger_error(sprintf($this->user->lang['MEDAL_NOMINATE_GOOD']));
                break;
            case 'award':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if ($user_id == 0 || $user_id == ANONYMOUS) {
                    trigger_error('NO_USER_ID');
                }
                $sql = "SELECT *\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\tORDER BY medal_id AND nominated";
                $result = $this->db->sql_query($sql);
                $my_medals = array();
                while ($row = $this->db->sql_fetchrow($result)) {
                    if (isset($my_medals[$row['medal_id']]['count'])) {
                        $row['count'] = $my_medals[$row['medal_id']]['count'] + '1';
                    } else {
                        $row['count'] = '1';
                    }
                    $my_medals[$row['medal_id']] = $row;
                }
                $this->db->sql_freeresult($result);
                $sql = "SELECT user_id, username, user_colour\n\t\t\t\t\tFROM " . USERS_TABLE . "\n\t\t\t\t\tWHERE user_id = {$user_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['username']);
                $medals_options = '<option value=""></option>';
                $temp_string = '';
                $no_medals = true;
                foreach ($cats as $key => $value) {
                    $at_least_one = false;
                    foreach ($medals as $key2 => $value2) {
                        if ($value2['parent'] == $value['id']) {
                            $can_award = false;
                            $my_medals[$value2['id']]['count'] = isset($my_medals[$value2['id']]['count']) ? $my_medals[$value2['id']]['count'] : 0;
                            if ($my_medals[$value2['id']]['count'] < $value2['number'] || $medal_id == $value2['id']) {
                                $my_medals[$value2['id']]['nominated'] = isset($my_medals[$value2['id']]['nominated']) ? $my_medals[$value2['id']]['nominated'] : 0;
                                if (isset($my_medals[$value2['id']]) && $my_medals[$value2['id']]['nominated'] == 1) {
                                    $value2['name'] .= ' ' . sprintf($this->user->lang['NOMINATED_BY'], $my_medals[$value2['id']]['awarder_un']);
                                } else {
                                    if ($value2['nominated']) {
                                        $value2['name'] .= ' ' . $this->user->lang['NOMINATABLE'];
                                    }
                                }
                                if ($medal_id == $value2['id']) {
                                    $temp_string .= '<option value="' . $value2['id'] . '" selected="selected">&bull;&nbsp;' . $value2['name'] . '</option>';
                                    $sql = "SELECT *\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\t\t\t\t\t\tWHERE id = {$med_id}";
                                    $result = $this->db->sql_query($sql);
                                    $row = $this->db->sql_fetchrow($result);
                                    $this->db->sql_freeresult($result);
                                    $message = generate_text_for_edit($row['nominated_reason'], $row['bbuid'], $this->m_flags);
                                    $medal_edit = "&med={$med_id}";
                                } else {
                                    $temp_string .= '<option value="' . $value2['id'] . '">&bull;&nbsp;' . $value2['name'] . '</option>';
                                }
                                $at_least_one = true;
                            }
                        }
                    }
                    if ($at_least_one) {
                        $medals_options .= '<option value="">' . $value['name'] . '</option>';
                        $medals_options .= $temp_string;
                        $at_least_one = false;
                        $temp_string = '';
                        $no_medals = false;
                    }
                }
                $medals_arr = 'var medals = new Array();';
                $medals_desc_arr = 'var medals_desc = new Array();';
                foreach ($medals as $key => $value) {
                    $medals_arr .= 'medals[' . $value['id'] . '] = "' . $value['image'] . '";';
                    $medals_desc_arr .= 'medals_desc[' . $value['id'] . '] = "' . $value['description'] . '";';
                }
                $medals_arr .= "\n" . $medals_desc_arr . "\n";
                if ($no_medals) {
                    $medals_options = '<option value="">' . $this->user->lang['NO_MEDALS'] . '</option>';
                }
                $bbcode_status = $this->config['allow_bbcode'] ? true : false;
                $smilies_status = $bbcode_status && $this->config['allow_smilies'] ? true : false;
                $img_status = $bbcode_status ? true : false;
                $url_status = $bbcode_status && $this->config['allow_post_links'] ? true : false;
                $flash_status = $bbcode_status ? true : false;
                $quote_status = $bbcode_status ? true : false;
                display_custom_bbcodes();
                $message = isset($message['text']) ? $message['text'] : '';
                $medal_action = $this->helper->route('bb3mobi_medals_controller', array('m' => 'submit', 'u' => $user_id));
                $this->template->assign_vars(array('USERNAME' => $username, 'MEDALS' => $medals_options, 'JS' => $medals_arr, 'U_MEDALS_ACTION' => isset($medal_edit) ? $medal_action . $medal_edit : $medal_action, 'MESSAGE' => $message, 'S_BBCODE_ALLOWED' => $bbcode_status, 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_URL' => $url_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => $quote_status));
                page_header($this->user->lang['AWARD_MEDAL']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medalcp_award_user.html'));
                page_footer();
                break;
            case 'awarded':
                $sql = "SELECT user_id, username, user_colour\n\t\t\t\t\tFROM " . USERS_TABLE . "\n\t\t\t\t\tWHERE user_id = {$user_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['username']);
                $sql3 = "SELECT *\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\t\tAND nominated <> 1";
                $result3 = $this->db->sql_query($sql3);
                $s_medals = false;
                $users_medals = array();
                while ($row3 = $this->db->sql_fetchrow($result3)) {
                    $awarder_name = get_username_string('full', $row3['awarder_id'], $row3['awarder_un'], $row3['awarder_color'], $row3['awarder_un']);
                    $nom_message = sprintf($this->user->lang['NOMINATE_MESSAGE'], $awarder_name, $medals[$row3['medal_id']]['name']);
                    // Parse the message and subject
                    $reason = generate_text_for_display($row3['nominated_reason'], $row3['bbuid'], $row3['bitfield'], $this->m_flags);
                    $message = $this->user->lang['AWARDED_BY'] . ' ' . $awarder_name . ' ' . $this->user->format_date($row3['time']) . '<br \\>' . $reason;
                    $this_cat = $cats[$medals[$row3['medal_id']]['parent']];
                    $users_medals[$this_cat['order_id']]['name'] = $this_cat['name'];
                    $users_medals[$this_cat['order_id']][$medals[$row3['medal_id']]['order_id']][] = array('MEDAL_NAME' => $medals[$row3['medal_id']]['name'], 'MEDAL_IMAGE' => '<img src="' . $medals[$row3['medal_id']]['image'] . '" title="' . $medals[$row3['medal_id']]['name'] . '" alt="' . $medals[$row3['medal_id']]['name'] . '" />', 'MEDAL_REASON' => $message, 'ID' => $row3['id']);
                    $s_medals = true;
                }
                $this->db->sql_freeresult($result3);
                $my_medals_arr = array();
                ksort($users_medals);
                foreach ($users_medals as $key => $value) {
                    ksort($value);
                    foreach ($value as $key2 => $value2) {
                        if ($key2 != 'name') {
                            foreach ($value2 as $key3 => $value3) {
                                $my_medals_arr[] = array($value3, false);
                            }
                        } else {
                            $my_medals_arr[] = array($value2, true);
                        }
                    }
                }
                foreach ($my_medals_arr as $key => $value) {
                    if ($value[1]) {
                        $this->template->assign_block_vars('medals', array('MEDAL_NAME' => $value[0], 'IS_CAT' => true));
                    } else {
                        $u_delete = $this->helper->route('bb3mobi_medals_controller', array('m' => 'delete', 'u' => $user_id, 'med' => $value[0]['ID']));
                        $this->template->assign_block_vars('medals', array('MEDAL_NAME' => $value[0]['MEDAL_NAME'], 'MEDAL_IMAGE' => $value[0]['MEDAL_IMAGE'], 'MEDAL_REASON' => $value[0]['MEDAL_REASON'], 'U_DELETE' => $u_delete, 'IS_CAT' => false));
                    }
                }
                $this->template->assign_vars(array('USERNAME' => $username, 'U_MEDALS_ACTION' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'submit', 'u' => $user_id))));
                page_header($this->user->lang['AWARDED_MEDAL_TO']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medalcp_awarded_user.html'));
                page_footer();
                break;
            case 'submit':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if (!$medal_id) {
                    $redirect = $this->helper->route('bb3mobi_medals_controller', array('m' => 'award', 'u' => $user_id));
                    meta_refresh(3, $redirect);
                    trigger_error('NO_MEDAL_ID');
                }
                include_once $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
                $message = utf8_normalize_nfc($this->request->variable('message', '', true));
                if (!strlen($message)) {
                    $return_to = $this->helper->route('bb3mobi_medals_controller', array('m' => 'award', 'u' => $user_id));
                    trigger_error(sprintf($this->user->lang['NO_MEDAL_MSG'], $return_to));
                }
                $username = array();
                if (sizeof($user_id) > 1) {
                    foreach ($this->uid as $user_id) {
                        // Change usernames to ids
                        $sql = "SELECT user_id\n\t\t\t\t\t\t\tFROM " . USERS_TABLE . "\n\t\t\t\t\t\t\tWHERE username = {$this->uid}";
                        $result = $this->db->sql_query($sql);
                        $row = $this->db->sql_fetchrow($result);
                        $this->db->sql_freeresult($result);
                        $username[] = $row['user_id'];
                    }
                } else {
                    $username[] = $user_id;
                }
                foreach ($username as $user_id) {
                    $sql = "SELECT count(*) as count\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE medal_id = {$medal_id}\n\t\t\t\t\t\t\tAND user_id = {$user_id}\n\t\t\t\t\t\t\tAND nominated = 0";
                    $result = $this->db->sql_query($sql);
                    $row = $this->db->sql_fetchrow($result);
                    $this->db->sql_freeresult($result);
                    if ($row['count'] >= $medals[$medal_id]['number']) {
                        trigger_error(sprintf($this->user->lang['CANNOT_AWARD_MULTIPLE'], append_sid('memberlist.php?mode=viewprofile&u=' . $user_id)));
                    }
                    // Call award_medal function
                    if (isset($med_id)) {
                        $this->award_medal($medals, $medal_id, $user_id, $message, time(), $medals[$medal_id]['points'], $med_id);
                    } else {
                        $this->award_medal($medals, $medal_id, $user_id, $message, time(), $medals[$medal_id]['points']);
                    }
                }
                $redirect = append_sid('memberlist.php?mode=viewprofile&u=' . $user_id);
                meta_refresh(3, $redirect);
                trigger_error(sprintf($this->user->lang['MEDAL_AWARD_GOOD']));
                break;
            case 'delete':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if (!$med_id) {
                    trigger_error('NO_MEDAL_ID');
                }
                if (confirm_box(true)) {
                    if ($this->config['points_enable'] == 1) {
                        $sql = "SELECT points\n\t\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\t\tWHERE id = {$med_id}\n\t\t\t\t\t\t\tLIMIT 1";
                        $result = $this->db->sql_query($sql);
                        $row = $this->db->sql_fetchrow($result);
                        $this->db->sql_freeresult($result);
                        $sql = "UPDATE " . USERS_TABLE . " \n\t\t\t\t\t\t\tSET medal_user_points = user_points - " . $row['points'] . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $this->db->sql_query($sql);
                    }
                    $sql = "DELETE FROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE id = {$med_id}\n\t\t\t\t\t\tLIMIT 1";
                    $this->db->sql_query($sql);
                    $redirect = $this->helper->route('bb3mobi_medals_controller', array('m' => 'awarded', 'u' => $user_id));
                    meta_refresh(3, $redirect);
                    trigger_error(sprintf($this->user->lang['MEDAL_REMOVE_GOOD']));
                } else {
                    confirm_box(false, $this->user->lang['MEDAL_REMOVE_CONFIRM'], build_hidden_fields(array('action' => 'delete')));
                    $redirect = $this->helper->route('bb3mobi_medals_controller', array('m' => 'awarded', 'u' => $user_id));
                    meta_refresh(1, $redirect);
                    trigger_error(sprintf($this->user->lang['MEDAL_REMOVE_NO']));
                }
                break;
            case 'approve':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if (!$med_id) {
                    trigger_error('NO_MEDAL_ID');
                }
                $sql = "SELECT count(*) as count\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE medal_id = {$medal_id}\n\t\t\t\t\t\t  AND user_id = {$user_id}\n\t\t\t\t\t\t  AND nominated = 0";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                if ($row['count'] >= $medals[$medal_id]['number']) {
                    $redirect = append_sid('memberlist.php?mode=viewprofile&u=' . $user_id);
                    meta_refresh(3, $redirect);
                    trigger_error(sprintf($this->user->lang['CANNOT_AWARD_MULTIPLE']));
                }
                $sql = "SELECT *\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE id = {$med_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $message = generate_text_for_edit($row['nominated_reason'], $row['bbuid'], $this->m_flags);
                $this->award_medal($medals, $row['medal_id'], $row['user_id'], $message['text'], $row['time'], $medals[$medal_id]['points'], $row['id']);
                $redirect = $this->helper->route('bb3mobi_medals_controller', array('m' => 'validate', 'u' => $user_id));
                meta_refresh(3, $redirect);
                trigger_error(sprintf($this->user->lang['MEDAL_AWARD_GOOD']));
                break;
            case 'validate':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                $sql = 'SELECT user_id, username, user_colour
						FROM ' . USERS_TABLE . "\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                $result = $this->db->sql_query($sql);
                $row = $this->db->sql_fetchrow($result);
                $this->db->sql_freeresult($result);
                $username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], $row['username']);
                $sql = "SELECT ma.*, m.name\n\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . " as ma, " . $this->tb_medal . " as m\n\t\t\t\t\t\tWHERE ma.user_id = {$user_id}\n\t\t\t\t\t\t  AND ma.medal_id = m.id\n\t\t\t\t\t\t  AND ma.nominated <> 0";
                $result = $this->db->sql_query($sql);
                $i = 0;
                while ($row = $this->db->sql_fetchrow($result)) {
                    $awarder_name = get_username_string('full', $row['awarder_id'], $row['awarder_un'], $row['awarder_color'], $row['awarder_un']);
                    $nom_message = sprintf($this->user->lang['NOMINATE_MESSAGE'], $awarder_name, $row['name']);
                    // Parse the message and subject
                    $message = generate_text_for_display($row['nominated_reason'], $row['bbuid'], $row['bitfield'], $this->m_flags);
                    $message = $nom_message . $message;
                    $message = censor_text($message);
                    $message = str_replace("\n", '<br />', $message);
                    $this->uid = $row['bbuid'];
                    $this->bitfield = $row['bitfield'];
                    $u_delete = $this->helper->route('bb3mobi_medals_controller', array('m' => 'delete', 'med' => $row['id'], 'u' => $user_id));
                    $u_approve = $this->helper->route('bb3mobi_medals_controller', array('m' => 'approve', 'med' => $row['id'], 'mid' => $row['medal_id'], 'u' => $user_id));
                    $u_m_edit = $this->helper->route('bb3mobi_medals_controller', array('m' => 'award', 'med' => $row['id'], 'mid' => $row['medal_id'], 'u' => $user_id));
                    $this->template->assign_block_vars('nominations', array('USERNAME' => $awarder_name, 'REASON' => $message, 'U_DELETE' => $u_delete, 'U_APPROVE' => $u_approve, 'U_MEDAL_EDIT' => $u_m_edit));
                    $i++;
                }
                $this->db->sql_freeresult($result);
                $this->template->assign_vars(array('U_MEDALS_ACTION' => $this->helper->route('bb3mobi_medals_controller', array('m' => 'submit', 'u' => $user_id)), 'NOMINATE_MEDAL' => sprintf($this->user->lang['NOMINATE_USER_LOG'], $username), 'S_ROW_COUNT' => $i));
                page_header($this->user->lang['NOMINATE_MEDAL']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medalcp_nominate_user.html'));
                page_footer();
                break;
            case 'mnd':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if (!$med_id) {
                    trigger_error('NO_MEDAL_ID');
                }
                $sql = "DELETE FROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\tWHERE medal_id = {$med_id}\n\t\t\t\t\t\t\tAND nominated = 1";
                $this->db->sql_query($sql);
                trigger_error(sprintf($this->user->lang['NOMINATIONS_REMOVE_GOOD'], $this->helper->route('bb3mobi_medals_controller')));
                // No break;
            // No break;
            case 'mn':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                $sql = "SELECT u.username, u.user_colour, ma.*\n\t\t\t\t\t\tFROM " . USERS_TABLE . " u, " . $this->tb_medals_awarded . " ma\n\t\t\t\t\t\tWHERE u.user_id = ma.user_id\n\t\t\t\t\t\t\tAND ma.nominated = 1\n\t\t\t\t\t\t\tAND ma.medal_id = {$med_id}\n\t\t\t\t\t\tORDER BY u.username_clean";
                $result = $this->db->sql_query($sql);
                $users_medals = array();
                $i = 1;
                while ($row = $this->db->sql_fetchrow($result)) {
                    $awarder_name = get_username_string('full', $row['awarder_id'], $row['awarder_un'], $row['awarder_color'], $row['awarder_un']);
                    $users_medals[$i] = array('id' => $row['id'], 'username' => $row['username'], 'user_colour' => $row['user_colour'], 'user_id' => $row['user_id'], 'reason' => $this->user->lang['MEDAL_NOM_BY'] . ' : ' . $awarder_name . '<br />' . $row['nominated_reason'], 'bbuid' => $row['bbuid'], 'bitfield' => $row['bitfield']);
                    $i++;
                }
                $this->db->sql_freeresult($result);
                foreach ($users_medals as $key => $value) {
                    $awarded = get_username_string('full', $value['user_id'], $value['username'], $value['user_colour']);
                    $this->template->assign_block_vars('nominatedrow', array('NOMINATED' => $awarded, 'REASON' => generate_text_for_display($value['reason'], $value['bbuid'], $value['bitfield'], $this->m_flags), 'U_MCP' => "?m=approve&med={$value['id']}&mid={$med_id}&u={$value['user_id']}", 'U_USER_DELETE' => "?m=delete&med={$value['id']}&u={$value['user_id']}"));
                    $nominated_users[$value['user_id']]['user'] = $awarded;
                    $nominated_users[$value['user_id']]['count'] = isset($nominated_users[$value['user_id']]['count']) ? $nominated_users[$value['user_id']]['count'] + '1' : 1;
                }
                if (isset($nominated_users)) {
                    $i = 0;
                    $nom_users = '';
                    foreach ($nominated_users as $key => $value) {
                        if ($i > 0) {
                            $nom_users .= ", ";
                        }
                        $nom_users .= "{$value['user']} ({$value['count']})";
                        $i++;
                    }
                }
                $this->template->assign_vars(array('S_MEDAL_NOM' => true, 'MEDAL_NAME' => $medals[$med_id]['name'], 'MEDAL_DESC' => $medals[$med_id]['description'], 'MEDAL_IMG' => '<img src="' . $medals[$med_id]['image'] . '">', 'MEDAL_AWARDED' => isset($awarded_users) ? $awarded_users : $this->user->lang['NO_MEDALS_ISSUED'], 'NOMINATED_USERS' => isset($nom_users) ? $nom_users : $this->user->lang['NO_MEDALS_NOMINATED'], 'S_DELETE_ALL' => isset($nom_users) ? true : false, 'U_MEDALS_ACTION' => "?m={$mode}d&med={$med_id}", 'U_FIND_USERNAME' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx, 'mode=searchuser&amp;form=post&amp;field=add')));
                page_header($this->user->lang['MEDALS_VIEW']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medals.html'));
                page_footer();
                break;
            case 'ma':
                if ($this->user->data['user_type'] != USER_FOUNDER && !$this->auth->acl_get('u_award_medals')) {
                    trigger_error($this->user->lang['NO_GOOD_PERMS']);
                }
                if ($submit) {
                    if (!$med_id) {
                        trigger_error('NO_MEDAL_ID');
                    }
                    $message = utf8_normalize_nfc($this->request->variable('message', '', true));
                    if (!strlen($message)) {
                        $return_to = $this->helper->route('bb3mobi_medals_controller', array('mode' => $mode, 'med' => $med_id));
                        trigger_error(sprintf($this->user->lang['NO_MEDAL_MSG'], $return_to));
                    }
                    $usernames = explode("\n", $usernames);
                    foreach ($usernames as $value) {
                        $username[] = $this->db->sql_escape(utf8_clean_string($value));
                    }
                    $award_user = $not_award_user = $awarded_user = $no_such_user = array();
                    // Change usernames to ids
                    $sql = 'SELECT user_id, username, username_clean
							FROM ' . USERS_TABLE . '
							WHERE ' . $this->db->sql_in_set('username_clean', $username);
                    $result = $this->db->sql_query($sql);
                    while ($row = $this->db->sql_fetchrow($result)) {
                        $sql = "SELECT count(*) as number\n\t\t\t\t\t\t\t\tFROM " . $this->tb_medals_awarded . "\n\t\t\t\t\t\t\t\tWHERE medal_id = {$med_id}\n\t\t\t\t\t\t\t\t\tAND user_id = {$row['user_id']}";
                        $result2 = $this->db->sql_query($sql);
                        $row2 = $this->db->sql_fetchrow($result2);
                        $this->db->sql_freeresult($result2);
                        if ($row2['number'] < $medals[$med_id]['number']) {
                            $award_user[] = $row['user_id'];
                            $awarded_user[] = $row['username_clean'];
                        }
                    }
                    $this->db->sql_freeresult($result);
                    $not_award_user = array_diff($username, $awarded_user);
                    // Call award_medal function
                    $time = time();
                    if (sizeof($award_user)) {
                        foreach ($award_user as $uid) {
                            $this->award_medal($medals, $med_id, $uid, $message, $time, $medals[$med_id]['points']);
                        }
                    }
                    if (sizeof($not_award_user)) {
                        $redirect = $this->helper->route('bb3mobi_medals_controller', array('mode' => $mode, 'med' => $med_id));
                        meta_refresh(3, $redirect);
                        trigger_error(sprintf($this->user->lang['NO_USER_SELECTED'], implode(", ", $not_award_user)));
                    } else {
                        $redirect = $this->helper->route('bb3mobi_medals_controller', array('mode' => $mode, 'med' => $med_id));
                        meta_refresh(3, $redirect);
                        trigger_error($this->user->lang['MEDAL_AWARD_GOOD']);
                    }
                }
                $sql = "SELECT u.username, u.user_colour, ma.user_id\n\t\t\t\t\t\tFROM " . USERS_TABLE . " u, " . $this->tb_medals_awarded . " ma\n\t\t\t\t\t\tWHERE u.user_id = ma.user_id\n\t\t\t\t\t\t\tAND ma.nominated = 0\n\t\t\t\t\t\t\tAND ma.medal_id = {$med_id}\n\t\t\t\t\t\tGROUP BY ma.user_id, u.username, ma.medal_id\n\t\t\t\t\t\tORDER BY u.username";
                $result = $this->db->sql_query($sql);
                $users_medals = array();
                $i = 1;
                while ($row = $this->db->sql_fetchrow($result)) {
                    $users_medals[$i] = array('username' => $row['username'], 'user_colour' => $row['user_colour'], 'user_id' => $row['user_id']);
                    $i++;
                }
                $this->db->sql_freeresult($result);
                foreach ($users_medals as $key => $value) {
                    $awarded = get_username_string('full', $value['user_id'], $value['username'], $value['user_colour']);
                    $awarded_users = isset($awarded_users) ? $awarded_users . ', ' . $awarded : $awarded;
                }
                $this->template->assign_vars(array('S_MEDAL_AWARD' => true, 'MEDAL_NAME' => $medals[$med_id]['name'], 'MEDAL_DESC' => $medals[$med_id]['description'], 'MEDAL_IMG' => '<img src="' . $medals[$med_id]['image'] . '">', 'MEDAL_AWARDED' => isset($awarded_users) ? $awarded_users : $this->user->lang['NO_MEDALS_ISSUED'], 'U_MEDALS_ACTION' => "?m={$mode}&med={$med_id}", 'U_FIND_USERNAME' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx, 'mode=searchuser&amp;form=post&amp;field=add')));
                page_header($this->user->lang['MEDALS_VIEW']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medals.html'));
                page_footer();
                break;
            default:
                $sql = "SELECT u.username, u.user_colour, ma.user_id, ma.medal_id, ma.nominated\n\t\t\t\t\t\tFROM " . USERS_TABLE . " u, " . $this->tb_medals_awarded . " ma\n\t\t\t\t\t\tWHERE u.user_id = ma.user_id\n\t\t\t\t\t\tGROUP BY ma.nominated, ma.user_id, u.username, ma.medal_id\n\t\t\t\t\t\tORDER BY u.username_clean";
                $result = $this->db->sql_query($sql);
                $users_medals = array();
                $i = 1;
                while ($row = $this->db->sql_fetchrow($result)) {
                    $users_medals[$i] = array('username' => $row['username'], 'user_colour' => $row['user_colour'], 'medal_id' => $row['medal_id'], 'user_id' => $row['user_id'], 'nominated' => $row['nominated']);
                    $i++;
                }
                $this->db->sql_freeresult($result);
                $at_least_one_awarded = false;
                foreach ($cats as $key => $value) {
                    $at_least_one = true;
                    foreach ($medals as $key2 => $value2) {
                        if ($value2['parent'] == $value['id']) {
                            if ($at_least_one) {
                                $at_least_one_awarded = true;
                                $this->template->assign_block_vars('medalrow', array('IS_CAT' => 1, 'MEDAL_CAT' => $value['name']));
                                $at_least_one = false;
                            }
                            $awarded_users = '';
                            $nominations = 0;
                            foreach ($users_medals as $key3 => $value3) {
                                if ($value3['medal_id'] == $value2['id'] && $value3['nominated'] == 0) {
                                    $awarded = get_username_string('full', $value3['user_id'], $value3['username'], $value3['user_colour']);
                                    $awarded_users = $awarded_users ? $awarded_users . ', ' . $awarded : $awarded;
                                } else {
                                    if ($value3['medal_id'] == $value2['id'] && $value3['nominated'] == 1) {
                                        $nominations++;
                                    }
                                }
                            }
                            $u_medal_award = $this->helper->route('bb3mobi_medals_controller', array('m' => 'ma', 'med' => $value2['id']));
                            $u_medal_ncp = $this->helper->route('bb3mobi_medals_controller', array('m' => 'mn', 'med' => $value2['id']));
                            $this->template->assign_block_vars('medalrow', array('MEDAL_NAME' => $value2['name'], 'U_MEDAL_AWARD_PANEL' => $u_medal_award, 'MEDAL_IMG' => '<img src="' . $value2['image'] . '">', 'MEDAL_DESC' => $value2['description'], 'MEDAL_AWARDED' => $awarded_users ? $awarded_users : $this->user->lang['NO_MEDALS_ISSUED'], 'NOMINATIONS' => $nominations > 0 ? true : false, 'U_MEDAL_NCP' => $u_medal_ncp, 'MEDAL_DESC' => $value2['description']));
                        }
                    }
                }
                $this->template->assign_vars(array('S_MEDAL_VIEW' => true, 'NO_MEDAL' => $at_least_one_awarded ? 0 : 1));
                page_header($this->user->lang['MEDALS_VIEW']);
                $this->template->set_filenames(array('body' => '@bb3mobi_medals/medals.html'));
                page_footer();
                break;
        }
    }
Exemplo n.º 17
0
 /**
  * Process rule data to be added or edited
  *
  * @param object $entity The rule entity object
  * @param array $data The form data to be processed
  * @return null
  * @access protected
  */
 protected function add_edit_rule_data($entity, $data)
 {
     // Get form's POST actions (submit or preview)
     $submit = $this->request->is_set_post('submit');
     $preview = $this->request->is_set_post('preview');
     // Load posting language file for the BBCode editor
     $this->user->add_lang('posting');
     // Create an array to collect errors that will be output to the user
     $errors = array();
     // Grab the form data's message parsing options (possible values: 1 or 0)
     $message_parse_options = array('bbcode' => $submit || $preview ? $data['bbcode'] : $entity->message_bbcode_enabled(), 'magic_url' => $submit || $preview ? $data['magic_url'] : $entity->message_magic_url_enabled(), 'smilies' => $submit || $preview ? $data['smilies'] : $entity->message_smilies_enabled());
     // Set the message parse options in the entity
     foreach ($message_parse_options as $function => $enabled) {
         call_user_func(array($entity, ($enabled ? 'message_enable_' : 'message_disable_') . $function));
     }
     unset($message_parse_options);
     // Grab the form's rule data fields
     $rule_fields = array('title' => $data['rule_title'], 'anchor' => $data['rule_anchor'], 'message' => $data['rule_message']);
     // Set the rule's data in the entity
     foreach ($rule_fields as $entity_function => $rule_data) {
         try {
             // Calling the set_$entity_function on the entity and passing it $rule_data
             call_user_func_array(array($entity, 'set_' . $entity_function), array($rule_data));
         } catch (\phpbb\boardrules\exception\base $e) {
             // Catch exceptions and add them to errors array
             $errors[] = $e->get_message($this->user);
         }
     }
     unset($rule_fields);
     // If the form has been submitted or previewed
     if ($submit || $preview) {
         // Test if the form is valid
         if (!check_form_key('add_edit_rule')) {
             $errors[] = $this->user->lang('FORM_INVALID');
         }
         // Do not allow an empty rule title
         if ($entity->get_title() == '') {
             $errors[] = $this->user->lang('ACP_RULE_TITLE_EMPTY');
         }
     }
     // Preview
     if ($preview && empty($errors)) {
         // Set output vars for display in the template
         $this->template->assign_vars(array('S_PREVIEW' => $preview, 'RULE_TITLE_PREVIEW' => $entity->get_title(), 'RULE_MESSAGE_PREVIEW' => $entity->get_message_for_display()));
     }
     // Insert or update rule
     if ($submit && empty($errors) && !$preview) {
         if ($entity->get_id()) {
             // Save the edited rule entity to the database
             $entity->save();
             // Change rule parent
             if (isset($data['rule_parent_id']) && $data['rule_parent_id'] != $entity->get_parent_id()) {
                 $this->rule_operator->change_parent($entity->get_id(), $data['rule_parent_id']);
             }
             // Show user confirmation of the saved rule and provide link back to the previous page
             trigger_error($this->user->lang('ACP_RULE_EDITED') . adm_back_link("{$this->u_action}&amp;language={$entity->get_language()}&amp;parent_id={$entity->get_parent_id()}"));
         } else {
             // Add a new rule entity to the database
             $this->rule_operator->add_rule($entity, $data['rule_language'], $data['rule_parent_id']);
             // Show user confirmation of the added rule and provide link back to the previous page
             trigger_error($this->user->lang('ACP_RULE_ADDED') . adm_back_link("{$this->u_action}&amp;language={$data['rule_language']}&amp;parent_id={$data['rule_parent_id']}"));
         }
     }
     // Set output vars for display in the template
     $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'RULE_TITLE' => $entity->get_title(), 'RULE_ANCHOR' => $entity->get_anchor(), 'RULE_MESSAGE' => $entity->get_message_for_edit(), 'S_BBCODE_DISABLE_CHECKED' => !$entity->message_bbcode_enabled(), 'S_SMILIES_DISABLE_CHECKED' => !$entity->message_smilies_enabled(), 'S_MAGIC_URL_DISABLE_CHECKED' => !$entity->message_magic_url_enabled(), 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $this->user->lang('SMILIES_ARE_ON'), 'IMG_STATUS' => $this->user->lang('IMAGES_ARE_ON'), 'FLASH_STATUS' => $this->user->lang('FLASH_IS_ON'), 'URL_STATUS' => $this->user->lang('URL_IS_ON'), 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true));
     // Build custom bbcodes array
     include_once $this->root_path . 'includes/functions_display.' . $this->php_ext;
     display_custom_bbcodes();
 }
Exemplo n.º 18
0
 /**
  * Populate form when an error occurred
  *
  * @param	int		$link_id		The link ID
  * @param	string	$mode			add|edit
  * @return	null
  */
 private function _populate_form($link_id, $mode)
 {
     if (!$this->user->data['is_registered'] && $this->config['dir_visual_confirm'] && $mode != 'edit') {
         $this->s_hidden_fields = array_merge($this->s_hidden_fields, $this->captcha->get_hidden_fields());
         $this->template->assign_vars(array('S_CONFIRM_CODE' => true, 'CAPTCHA_TEMPLATE' => $this->captcha->get_template()));
     }
     if (!function_exists('generate_smilies')) {
         include $this->root_path . 'includes/functions_posting.' . $this->php_ext;
     }
     if (!function_exists('display_custom_bbcodes')) {
         include $this->root_path . 'includes/functions_display.' . $this->php_ext;
     }
     generate_smilies('inline', 0);
     display_custom_bbcodes();
     add_form_key('dir_form_comment');
     $this->template->assign_vars(array('S_AUTH_COMM' => $this->auth->acl_get('u_comment_dir'), 'BBCODE_STATUS' => $this->config['dir_allow_bbcode'] ? $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid($this->root_path . "faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>') : $this->user->lang('BBCODE_IS_OFF', '<a href="' . append_sid($this->root_path . "faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $this->config['dir_allow_bbcode'] ? $this->user->lang['IMAGES_ARE_ON'] : $this->user->lang['IMAGES_ARE_OFF'], 'SMILIES_STATUS' => $this->config['dir_allow_smilies'] ? $this->user->lang['SMILIES_ARE_ON'] : $this->user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $this->config['dir_allow_links'] ? $this->user->lang['URL_IS_ON'] : $this->user->lang['URL_IS_OFF'], 'FLASH_STATUS' => $this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash'] ? $this->user->lang['FLASH_IS_ON'] : $this->user->lang['FLASH_IS_OFF'], 'L_DIR_REPLY_EXP' => $this->user->lang('DIR_REPLY_EXP', $this->config['dir_length_comments']), 'S_COMMENT' => isset($this->s_comment) ? $this->s_comment : '', 'S_BBCODE_ALLOWED' => (bool) $this->config['dir_allow_bbcode'], 'S_BBCODE_IMG' => (bool) $this->config['dir_allow_bbcode'], 'S_BBCODE_FLASH' => $this->config['dir_allow_bbcode'] && $this->config['dir_allow_flash'] ? true : false, 'S_BBCODE_QUOTE' => true, 'S_LINKS_ALLOWED' => (bool) $this->config['dir_allow_links'], 'S_SMILIES_ALLOWED' => (bool) $this->config['dir_allow_smilies'], 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields), 'S_BUTTON_NAME' => $mode == 'edit' ? 'update_comment' : 'submit_comment', 'S_POST_ACTION' => $mode == 'edit' ? '' : $this->helper->route('ernadoo_phpbbdirectory_comment_new_controller', array('link_id' => (int) $link_id))));
 }
Exemplo n.º 19
0
    function comment_edit($blog_id, $comment_id)
    {
        // Grab comment details
        $sql = 'SELECT c.*, b.blog_subject
				FROM ' . $this->ub_comments_table . ' c
				LEFT JOIN ' . $this->ub_blogs_table . ' b
					ON c.blog_id = b.blog_id
				WHERE c.comment_id = ' . (int) $comment_id . '
					AND c.blog_id = ' . (int) $blog_id;
        $result = $this->db->sql_query($sql);
        $comment = $this->db->sql_fetchrow($result);
        $this->db->sql_freeresult($result);
        if (!$comment) {
            trigger_error($this->user->lang['BLOG_COMMENT_NOT_EXIST'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_blog_display', ['blog_id' => (int) $blog_id]) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>');
        }
        // Check if authorised to edit this comment
        if (!$this->auth->acl_gets('u_blog_comment_edit', 'm_blog_comment_edit')) {
            trigger_error($this->user->lang['AUTH_COMMENT_EDIT'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_blog_display', ['blog_id' => (int) $blog_id]) . '">&laquo; ' . $this->user->lang['BLOG_BACK'] . '</a>');
        }
        if ($this->auth->acl_get('u_blog_edit') && $comment['poster_id'] != $this->user->data['user_id'] && !$this->auth->acl_get('m_blog_comment_edit')) {
            trigger_error($this->user->lang['AUTH_COMMENT_EDIT_ELSE'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_blog_display', ['blog_id' => (int) $blog_id]) . '">&laquo; ' . $this->user->lang['BLOG_BACK'] . '</a>');
        }
        if (!function_exists('generate_smilies')) {
            include $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
        }
        if (!function_exists('display_custom_bbcodes')) {
            include $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
        }
        // Add lang file
        $this->user->add_lang('posting');
        display_custom_bbcodes();
        generate_smilies('inline', 0);
        // Generate text for editing
        decode_message($comment['comment_text'], $comment['bbcode_uid']);
        $this->template->assign_vars(['MESSAGE' => $comment['comment_text'], 'S_FORM_ENCTYPE' => '', 'S_BBCODE_ALLOWED' => $this->config['allow_bbcode'] ? true : false, 'S_SMILIES_STATUS' => $this->config['allow_smilies'] ? true : false]);
        add_form_key('edit_comment');
        if ($this->request->is_set_post('submit')) {
            if (!check_form_key('edit_comment')) {
                // Invalid form key
                trigger_error($this->user->lang['FORM_INVALID'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_comment', ['blog_id' => (int) $blog_id, 'comment_id' => (int) $comment_id, 'action' => 'edit']) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>');
            } else {
                if ($this->request->variable('comment_text', '', true) == '') {
                    // Empty comment message
                    trigger_error($this->user->lang['BLOG_COMMENT_EMPTY'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_comment', ['blog_id' => (int) $blog_id, 'comment_id' => (int) $comment_id, 'action' => 'edit']) . '">&laquo; ' . $this->user->lang['BACK_TO_PREV'] . '</a>');
                } else {
                    // Generate text for storage
                    $comment_text = $this->request->variable('comment_text', '', true);
                    $uid = $bitfield = $options = '';
                    $allow_bbcode = $this->config['allow_bbcode'];
                    $allow_smilies = $this->config['allow_smilies'];
                    $allow_urls = $this->config['allow_post_links'];
                    generate_text_for_storage($comment_text, $uid, $bitfield, $options, $allow_bbcode, $allow_smilies, $allow_urls);
                    $comment_row = ['comment_text' => $comment_text, 'bbcode_uid' => $uid, 'bbcode_bitfield' => $bitfield, 'bbcode_options' => $options];
                    // Update the blog
                    $sql = 'UPDATE ' . $this->ub_comments_table . ' SET ' . $this->db->sql_build_array('UPDATE', $comment_row) . ' WHERE comment_id = ' . (int) $comment_id;
                    $this->db->sql_query($sql);
                    // Add it to the log
                    $this->log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_COMMENT_EDITED', false, array($comment_id));
                    // Send success message
                    trigger_error($this->user->lang['BLOG_COMMENT_EDITED'] . '<br><br><a href="' . $this->helper->route('posey_ultimateblog_blog_display', ['blog_id' => (int) $blog_id]) . '#c' . (int) $comment_id . '">' . $this->user->lang['BLOG_COMMENT_VIEW'] . ' &raquo;</a>');
                }
            }
        }
        // Assign breadcrumb template vars
        $navlinks_array = [['U_VIEW_FORUM' => $this->helper->route('posey_ultimateblog_blog'), 'FORUM_NAME' => $this->user->lang('BLOG')], ['U_VIEW_FORUM' => $this->helper->route('posey_ultimateblog_blog_display', ['blog_id' => (int) $blog_id]), 'FORUM_NAME' => $comment['blog_subject']]];
        foreach ($navlinks_array as $name) {
            $this->template->assign_block_vars('navlinks', ['FORUM_NAME' => $name['FORUM_NAME'], 'U_VIEW_FORUM' => $name['U_VIEW_FORUM']]);
        }
    }
Exemplo n.º 20
0
 public function rate($image_id)
 {
     $this->user->add_lang_ext('phpbbgallery/core', array('gallery'));
     add_form_key('gallery');
     $submit = $this->request->variable('submit', false);
     $error = $message = '';
     // load Image Data
     $image_data = $this->image->get_image_data($image_id);
     $album_id = (int) $image_data['image_album_id'];
     $album_data = $this->loader->get($album_id);
     $this->display->generate_navigation($album_data);
     $page_title = $image_data['image_name'];
     $image_backlink = $this->helper->route('phpbbgallery_image', array('image_id' => $image_id));
     $album_backlink = $this->helper->route('phpbbgallery_album', array('album_id' => $album_id));
     $image_loginlink = $this->url->append_sid('relative', 'image_page', "album_id={$album_id}&amp;image_id={$image_id}");
     $this->gallery_auth->load_user_premissions($this->user->data['user_id']);
     $rating = new \phpbbgallery\core\rating($image_id, $image_data, $album_data);
     if (!($this->gallery_config->get('allow_rates') && $rating->is_able())) {
         // The user is unable to rate.
         $this->misc->not_authorised($image_backlink, $image_loginlink);
     }
     $this->user->add_lang('posting');
     include_once $this->phpbb_root_path . 'includes/functions_posting.' . $this->php_ext;
     $bbcode_status = $this->config['allow_bbcode'] ? true : false;
     $smilies_status = $this->config['allow_smilies'] ? true : false;
     $img_status = $bbcode_status ? true : false;
     $url_status = $this->config['allow_post_links'] ? true : false;
     $flash_status = false;
     $quote_status = true;
     include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
     // Build custom bbcodes array
     display_custom_bbcodes();
     // Build smilies array
     generate_smilies('inline', 0);
     /**
      * Rating-System: now you can comment and rate in one form
      */
     $s_user_rated = false;
     if ($this->gallery_config->get('allow_rates')) {
         $user_rating = $rating->get_user_rating($this->user->data['user_id']);
         // Check: User didn't rate yet, has permissions, it's not the users own image and the user is logged in
         if (!$user_rating && $rating->is_allowed()) {
             $rating->display_box();
             // User just rated the image, so we store it
             $rate_point = $this->request->variable('rating', 0);
             if ($rating->rating_enabled && $rate_point > 0) {
                 $rating->submit_rating();
                 $s_user_rated = true;
                 $message .= $this->user->lang['RATING_SUCCESSFUL'] . '<br />';
             }
             $this->template->assign_vars(array('S_ALLOWED_TO_RATE' => $rating->is_allowed()));
         }
     }
     $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_IMAGE'], '<a href="' . $image_backlink . '">', '</a>');
     $message .= '<br />' . sprintf($this->user->lang['CLICK_RETURN_ALBUM'], '<a href="' . $album_backlink . '">', '</a>');
     $this->url->meta_refresh(3, $image_backlink);
     trigger_error($message);
     return $this->helper->render('gallery/comment_body.html', $page_title);
 }
Exemplo n.º 21
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':
                $data = array('username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'email' => strtolower(request_var('email', $user->data['user_email'])), 'email_confirm' => strtolower(request_var('email_confirm', '')), 'new_password' => request_var('new_password', '', true), 'cur_password' => request_var('cur_password', '', true), 'password_confirm' => request_var('password_confirm', '', true));
                add_form_key('ucp_reg_details');
                if ($submit) {
                    // Do not check cur_password, it is the old one.
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('email')), 'email_confirm' => array('string', true, 6, 60));
                    if ($auth->acl_get('u_chgname') && $config['allow_namechange']) {
                        $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username'));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email'] && $data['email_confirm'] != $data['email']) {
                        $error[] = $data['email_confirm'] ? 'NEW_EMAIL_ERROR' : 'NEW_EMAIL_CONFIRM_EMPTY';
                    }
                    if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = $data['password_confirm'] ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY';
                    }
                    // Only check the new password against the previous password if there have been no errors
                    if (!sizeof($error) && $auth->acl_get('u_chgpasswd') && $data['new_password'] && phpbb_check_hash($data['new_password'], $user->data['user_password'])) {
                        $error[] = 'SAME_PASSWORD_ERROR';
                    }
                    if (!phpbb_check_hash($data['cur_password'], $user->data['user_password'])) {
                        $error[] = $data['cur_password'] ? 'CUR_PASSWORD_ERROR' : 'CUR_PASSWORD_EMPTY';
                    }
                    if (!check_form_key('ucp_reg_details')) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $data['username'] : $user->data['username'], 'username_clean' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? utf8_clean_string($data['username']) : $user->data['username_clean'], 'user_email' => $auth->acl_get('u_chgemail') ? $data['email'] : $user->data['user_email'], 'user_email_hash' => $auth->acl_get('u_chgemail') ? phpbb_email_hash($data['email']) : $user->data['user_email_hash'], 'user_password' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? phpbb_hash($data['new_password']) : $user->data['user_password'], 'user_passchg' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? time() : 0);
                        if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $data['username']);
                        }
                        if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && !phpbb_check_hash($data['new_password'], $user->data['user_password'])) {
                            $user->reset_login_keys();
                            add_log('user', $user->data['user_id'], 'LOG_USER_NEW_PASSWORD', $data['username']);
                        }
                        if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email']) {
                            add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_EMAIL', $data['username'], $user->data['user_email'], $data['email']);
                        }
                        $message = 'PROFILE_UPDATED';
                        if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) {
                            $message = $config['require_activation'] == USER_ACTIVATION_SELF ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN';
                            include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                            $server_url = generate_board_url();
                            $user_actkey = gen_rand_string(mt_rand(6, 10));
                            $messenger = new messenger(false);
                            $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive' : 'user_activate';
                            $messenger->template($template_file, $user->data['user_lang']);
                            $messenger->to($data['email'], $data['username']);
                            $messenger->anti_abuse_headers($config, $user);
                            $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), '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 ... these users can activate a user
                                $admin_ary = $auth->acl_get_list(false, 'a_user', false);
                                $admin_ary = !empty($admin_ary[0]['a_user']) ? $admin_ary[0]['a_user'] : array();
                                // Also include founders
                                $where_sql = ' WHERE user_type = ' . USER_FOUNDER;
                                if (sizeof($admin_ary)) {
                                    $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
                                }
                                $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
									FROM ' . USERS_TABLE . ' ' . $where_sql;
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    $messenger->template('admin_activate', $row['user_lang']);
                                    $messenger->to($row['user_email'], $row['username']);
                                    $messenger->im($row['user_jabber'], $row['username']);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_USER_DETAILS' => "{$server_url}/memberlist.{$phpEx}?mode=viewprofile&u={$user->data['user_id']}", '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);
                            }
                            user_active_flip('deactivate', $user->data['user_id'], INACTIVE_PROFILE);
                            // Because we want the profile to be reactivated we set user_newpasswd to empty (else the reactivation will fail)
                            $sql_ary['user_actkey'] = $user_actkey;
                            $sql_ary['user_newpasswd'] = '';
                        }
                        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 ($data['username'] != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) {
                            user_update_name($user->data['username'], $data['username']);
                        }
                        // Now, we can remove the user completely (kill the session) - NOT BEFORE!!!
                        if (!empty($sql_ary['user_actkey'])) {
                            meta_refresh(5, append_sid($phpbb_root_path . 'index.' . $phpEx));
                            $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($phpbb_root_path . 'index.' . $phpEx) . '">', '</a>');
                            // Because the user gets deactivated we log him out too, killing his session
                            $user->session_kill();
                        } else {
                            meta_refresh(3, $this->u_action);
                            $message = $user->lang[$message] . '<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);
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], 'EMAIL' => $data['email'], 'PASSWORD_CONFIRM' => $data['password_confirm'], 'NEW_PASSWORD' => $data['new_password'], 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FORCE_PASSWORD' => $auth->acl_get('u_chgpasswd') && $config['chg_passforce'] && $user->data['user_passchg'] < time() - $config['chg_passforce'] * 86400 ? 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();
                $data = array('icq' => request_var('icq', $user->data['user_icq']), 'aim' => request_var('aim', $user->data['user_aim']), 'msn' => request_var('msn', $user->data['user_msnm']), 'yim' => request_var('yim', $user->data['user_yim']), 'jabber' => utf8_normalize_nfc(request_var('jabber', $user->data['user_jabber'], true)), 'website' => request_var('website', $user->data['user_website']), 'location' => utf8_normalize_nfc(request_var('location', $user->data['user_from'], true)), 'occupation' => utf8_normalize_nfc(request_var('occupation', $user->data['user_occ'], true)), 'interests' => utf8_normalize_nfc(request_var('interests', $user->data['user_interests'], true)));
                if ($config['allow_birthdays']) {
                    $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    if ($user->data['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']);
                    }
                    $data['bday_day'] = request_var('bday_day', $data['bday_day']);
                    $data['bday_month'] = request_var('bday_month', $data['bday_month']);
                    $data['bday_year'] = request_var('bday_year', $data['bday_year']);
                    $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                }
                add_form_key('ucp_profile_info');
                if ($submit) {
                    $validate_array = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 255), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('jabber')), '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, 100), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500));
                    if ($config['allow_birthdays']) {
                        $validate_array = array_merge($validate_array, array('bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time()) + 50), 'user_birthday' => array('date', true)));
                    }
                    $error = validate_data($data, $validate_array);
                    // 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 (!check_form_key('ucp_profile_info')) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $data['notify'] = $user->data['user_notify_type'];
                        if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) {
                            // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
                            // Disable notify by Jabber now for this user.
                            $data['notify'] = NOTIFY_EMAIL;
                        }
                        $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_notify_type' => $data['notify']);
                        if ($config['allow_birthdays']) {
                            $sql_ary['user_birthday'] = $data['user_birthday'];
                        }
                        $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
                        $cp->update_profile_field_data($user->data['user_id'], $cp_data);
                        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 ($config['allow_birthdays']) {
                    $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('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_BIRTHDAYS_ENABLED' => true));
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'ICQ' => $data['icq'], 'YIM' => $data['yim'], 'AIM' => $data['aim'], 'MSN' => $data['msn'], 'JABBER' => $data['jabber'], 'WEBSITE' => $data['website'], 'LOCATION' => $data['location'], 'OCCUPATION' => $data['occupation'], 'INTERESTS' => $data['interests']));
                // 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;
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? (bool) $user->optionget('sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? (bool) $user->optionget('sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? (bool) $user->optionget('sig_links') : false;
                $signature = utf8_normalize_nfc(request_var('signature', (string) $user->data['user_sig'], true));
                add_form_key('ucp_sig');
                if ($submit || $preview) {
                    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('disable_bbcode', false) ? false : true : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? request_var('disable_smilies', false) ? false : true : false;
                    $enable_urls = $config['allow_sig_links'] ? request_var('disable_magic_url', false) ? false : true : false;
                    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, $config['allow_sig_links'], true, 'sig');
                        if (sizeof($message_parser->warn_msg)) {
                            $error[] = implode('<br />', $message_parser->warn_msg);
                        }
                        if (!check_form_key('ucp_sig')) {
                            $error[] = 'FORM_INVALID';
                        }
                        if (!sizeof($error) && $submit) {
                            $user->optionset('sig_bbcode', $enable_bbcode);
                            $user->optionset('sig_smilies', $enable_smilies);
                            $user->optionset('sig_links', $enable_urls);
                            $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_options' => $user->data['user_options'], 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => $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') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</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'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_sig_font_size'], '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, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                // Build custom bbcodes array
                display_custom_bbcodes();
                break;
            case 'avatar':
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $display_gallery = request_var('display_gallery', '0');
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $auth->acl_get('u_chgavatar') && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
                add_form_key('ucp_avatar');
                if ($submit) {
                    if (check_form_key('ucp_avatar')) {
                        if (avatar_process_user($error, false, $can_upload)) {
                            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);
                        }
                    } else {
                        $error[] = 'FORM_INVALID';
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!$config['allow_avatar'] && $user->data['user_avatar_type']) {
                    $error[] = $user->lang['AVATAR_NOT_ALLOWED'];
                } else {
                    if ($user->data['user_avatar_type'] == AVATAR_UPLOAD && !$config['allow_avatar_upload'] || $user->data['user_avatar_type'] == AVATAR_REMOTE && !$config['allow_avatar_remote'] || $user->data['user_avatar_type'] == AVATAR_GALLERY && !$config['allow_avatar_local']) {
                        $error[] = $user->lang['AVATAR_TYPE_NOT_ALLOWED'];
                    }
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'AVATAR' => get_user_avatar($user->data['user_avatar'], $user->data['user_avatar_type'], $user->data['user_avatar_width'], $user->data['user_avatar_height'], 'USER_AVATAR', true), 'AVATAR_SIZE' => $config['avatar_filesize'], 'U_GALLERY' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=profile&amp;mode=avatar&amp;display_gallery=1'), 'S_FORM_ENCTYPE' => $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) ? ' enctype="multipart/form-data"' : '', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024)));
                if ($config['allow_avatar'] && $display_gallery && $auth->acl_get('u_chgavatar') && $config['allow_avatar_local']) {
                    avatar_gallery($category, $avatar_select, 4);
                } else {
                    if ($config['allow_avatar']) {
                        $avatars_enabled = $can_upload && ($config['allow_avatar_upload'] || $config['allow_avatar_remote_upload']) || $auth->acl_get('u_chgavatar') && ($config['allow_avatar_local'] || $config['allow_avatar_remote']) ? true : false;
                        $template->assign_vars(array('AVATAR_WIDTH' => request_var('width', $user->data['user_avatar_width']), 'AVATAR_HEIGHT' => request_var('height', $user->data['user_avatar_height']), 'S_AVATARS_ENABLED' => $avatars_enabled, 'S_UPLOAD_AVATAR_FILE' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_UPLOAD_AVATAR_URL' => $can_upload && $config['allow_avatar_remote_upload'] ? true : false, 'S_LINK_AVATAR' => $auth->acl_get('u_chgavatar') && $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $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);
    }
Exemplo n.º 22
0
/**
* Compose private message
* Called from ucp_pm with mode == 'compose'
*/
function compose_pm($id, $mode, $action, $user_folders = array())
{
    global $template, $db, $auth, $user, $cache;
    global $phpbb_root_path, $phpEx, $config;
    global $request, $phpbb_dispatcher, $phpbb_container;
    // Damn php and globals - i know, this is horrible
    // Needed for handle_message_list_actions()
    global $refresh, $submit, $preview;
    include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
    include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
    include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
    if (!$action) {
        $action = 'post';
    }
    add_form_key('ucp_pm_compose');
    // Grab only parameters needed here
    $to_user_id = request_var('u', 0);
    $to_group_id = request_var('g', 0);
    $msg_id = request_var('p', 0);
    $draft_id = request_var('d', 0);
    $lastclick = request_var('lastclick', 0);
    // Reply to all triggered (quote/reply)
    $reply_to_all = request_var('reply_to_all', 0);
    $address_list = $request->variable('address_list', array('' => array(0 => '')));
    $submit = isset($_POST['post']) ? true : false;
    $preview = isset($_POST['preview']) ? true : false;
    $save = isset($_POST['save']) ? true : false;
    $load = isset($_POST['load']) ? true : false;
    $cancel = isset($_POST['cancel']) && !isset($_POST['save']) ? true : false;
    $delete = isset($_POST['delete']) ? true : false;
    $remove_u = isset($_REQUEST['remove_u']) ? true : false;
    $remove_g = isset($_REQUEST['remove_g']) ? true : false;
    $add_to = isset($_REQUEST['add_to']) ? true : false;
    $add_bcc = isset($_REQUEST['add_bcc']) ? true : false;
    $refresh = isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load || $remove_u || $remove_g || $add_to || $add_bcc;
    $action = $delete && !$preview && !$refresh && $submit ? 'delete' : $action;
    $select_single = $config['allow_mass_pm'] && $auth->acl_get('u_masspm') ? false : true;
    $error = array();
    $current_time = time();
    // Was cancel pressed? If so then redirect to the appropriate page
    if ($cancel || $current_time - $lastclick < 2 && $submit) {
        if ($msg_id) {
            redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
        }
        redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm'));
    }
    // Since viewtopic.php language entries are used in several modes,
    // we include the language file here
    $user->add_lang('viewtopic');
    /**
     * Modify the default vars before composing a PM
     *
     * @event core.ucp_pm_compose_modify_data
     * @var	int		msg_id					post_id in the page request
     * @var	int		to_user_id				The id of whom the message is to
     * @var	int		to_group_id				The id of the group the message is to
     * @var	bool	submit					Whether the form has been submitted
     * @var	bool	preview					Whether the user is previewing the PM or not
     * @var	string	action					One of: post, reply, quote, forward, quotepost, edit, delete, smilies
     * @var	bool	delete					Whether the user is deleting the PM
     * @var	int		reply_to_all			Value of reply_to_all request variable.
     * @since 3.1.4-RC1
     */
    $vars = array('msg_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all');
    extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_modify_data', compact($vars)));
    // Output PM_TO box if message composing
    if ($action != 'edit') {
        // Add groups to PM box
        if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm_group')) {
            $sql = 'SELECT g.group_id, g.group_name, g.group_type
				FROM ' . GROUPS_TABLE . ' g';
            if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) {
                $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
            }
            $sql .= $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? ' WHERE ' : ' AND ';
            $sql .= 'g.group_receive_pm = 1
				ORDER BY g.group_type DESC, g.group_name ASC';
            $result = $db->sql_query($sql);
            $group_options = '';
            while ($row = $db->sql_fetchrow($result)) {
                $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);
        }
        $template->assign_vars(array('S_SHOW_PM_BOX' => true, 'S_ALLOW_MASS_PM' => $config['allow_mass_pm'] && $auth->acl_get('u_masspm') ? true : false, 'S_GROUP_OPTIONS' => $config['allow_mass_pm'] && $auth->acl_get('u_masspm_group') ? $group_options : '', 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", "mode=searchuser&amp;form=postform&amp;field=username_list&amp;select_single={$select_single}")));
    }
    $sql = '';
    $folder_id = 0;
    // What is all this following SQL for? Well, we need to know
    // some basic information in all cases before we do anything.
    switch ($action) {
        case 'post':
            if (!$auth->acl_get('u_sendpm')) {
                trigger_error('NO_AUTH_SEND_MESSAGE');
            }
            break;
        case 'reply':
        case 'quote':
        case 'forward':
        case 'quotepost':
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            if (!$auth->acl_get('u_sendpm')) {
                trigger_error('NO_AUTH_SEND_MESSAGE');
            }
            if ($action == 'quotepost') {
                $sql = 'SELECT p.post_id as msg_id, p.forum_id, p.post_text as message_text, p.poster_id as author_id, p.post_time as message_time, p.bbcode_bitfield, p.bbcode_uid, p.enable_sig, p.enable_smilies, p.enable_magic_url, t.topic_title as message_subject, u.username as quote_username
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u\n\t\t\t\t\tWHERE p.post_id = {$msg_id}\n\t\t\t\t\t\tAND t.topic_id = p.topic_id\n\t\t\t\t\t\tAND u.user_id = p.poster_id";
            } else {
                $sql = 'SELECT t.folder_id, p.*, u.username as quote_username
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
					WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\tAND p.author_id = u.user_id\n\t\t\t\t\t\tAND t.msg_id = p.msg_id\n\t\t\t\t\t\tAND p.msg_id = {$msg_id}";
            }
            break;
        case 'edit':
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            // check for outbox (not read) status, we do not allow editing if one user already having the message
            $sql = 'SELECT p.*, t.folder_id
				FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
				WHERE t.user_id = ' . $user->data['user_id'] . '
					AND t.folder_id = ' . PRIVMSGS_OUTBOX . "\n\t\t\t\t\tAND t.msg_id = {$msg_id}\n\t\t\t\t\tAND t.msg_id = p.msg_id";
            break;
        case 'delete':
            if (!$auth->acl_get('u_pm_delete')) {
                trigger_error('NO_AUTH_DELETE_MESSAGE');
            }
            if (!$msg_id) {
                trigger_error('NO_MESSAGE');
            }
            $sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
				FROM ' . PRIVMSGS_TO_TABLE . '
				WHERE user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\tAND msg_id = {$msg_id}";
            break;
        case 'smilies':
            generate_smilies('window', 0);
            break;
        default:
            trigger_error('NO_ACTION_MODE', E_USER_ERROR);
            break;
    }
    if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward'))) {
        trigger_error('NO_AUTH_FORWARD_MESSAGE');
    }
    if ($action == 'edit' && !$auth->acl_get('u_pm_edit')) {
        trigger_error('NO_AUTH_EDIT_MESSAGE');
    }
    if ($sql) {
        /**
         * Alter sql query to get message for user to write the PM
         *
         * @event core.ucp_pm_compose_compose_pm_basic_info_query_before
         * @var	string	sql						String with the query to be executed
         * @var	array	forum_list				List of forums that contain the posts
         * @var	int		visibility_const		Integer with one of the possible ITEM_* constant values
         * @var	int		msg_id					topic_id in the page request
         * @var	int		to_user_id				The id of whom the message is to
         * @var	int		to_group_id				The id of the group whom the message is to
         * @var	bool	submit					Whether the user is sending the PM or not
         * @var	bool	preview					Whether the user is previewing the PM or not
         * @var	string	action					One of: post, reply, quote, forward, quotepost, edit, delete, smilies
         * @var	bool	delete					Whether the user is deleting the PM
         * @var	int		reply_to_all			Value of reply_to_all request variable.
         * @var	string	limit_time_sql			String with the SQL code to limit the time interval of the post (Note: May be empty string)
         * @var	string	sort_order_sql			String with the ORDER BY SQL code used in this query
         * @since 3.1.0-RC5
         */
        $vars = array('sql', 'forum_list', 'visibility_const', 'msg_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all', 'limit_time_sql', 'sort_order_sql');
        extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_compose_pm_basic_info_query_before', compact($vars)));
        $result = $db->sql_query($sql);
        $post = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$post) {
            // If editing it could be the recipient already read the message...
            if ($action == 'edit') {
                $sql = 'SELECT p.*, t.folder_id
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
					WHERE t.user_id = ' . $user->data['user_id'] . "\n\t\t\t\t\t\tAND t.msg_id = {$msg_id}\n\t\t\t\t\t\tAND t.msg_id = p.msg_id";
                $result = $db->sql_query($sql);
                $post = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if ($post) {
                    trigger_error('NO_EDIT_READ_MESSAGE');
                }
            }
            trigger_error('NO_MESSAGE');
        }
        if ($action == 'quotepost') {
            if ($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id']) || !$post['forum_id'] && !$auth->acl_getf_global('f_read')) {
                trigger_error('NOT_AUTHORISED');
            }
            /**
             * Get the result of querying for the post to be quoted in the pm message
             *
             * @event core.ucp_pm_compose_quotepost_query_after
             * @var	string	sql					The original SQL used in the query
             * @var	array	post				Associative array with the data of the quoted post
             * @var	array	msg_id				The post_id that was searched to get the message for quoting
             * @var	int		visibility_const	Visibility of the quoted post (one of the possible ITEM_* constant values)
             * @var	int		topic_id			Topic ID of the quoted post
             * @var	int		to_user_id			Users the message is sent to
             * @var	int		to_group_id			Groups the message is sent to
             * @var	bool	submit				Whether the user is sending the PM or not
             * @var	bool	preview				Whether the user is previewing the PM or not
             * @var	string	action				One of: post, reply, quote, forward, quotepost, edit, delete, smilies
             * @var	bool	delete				If deleting message
             * @var	int		reply_to_all		Value of reply_to_all request variable.
             * @since 3.1.0-RC5
             */
            $vars = array('sql', 'post', 'msg_id', 'visibility_const', 'topic_id', 'to_user_id', 'to_group_id', 'submit', 'preview', 'action', 'delete', 'reply_to_all');
            extract($phpbb_dispatcher->trigger_event('core.ucp_pm_compose_quotepost_query_after', compact($vars)));
            // Passworded forum?
            if ($post['forum_id']) {
                $sql = 'SELECT forum_id, forum_name, forum_password
					FROM ' . FORUMS_TABLE . '
					WHERE forum_id = ' . (int) $post['forum_id'];
                $result = $db->sql_query($sql);
                $forum_data = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!empty($forum_data['forum_password'])) {
                    login_forum_box($forum_data);
                }
            }
        }
        $msg_id = (int) $post['msg_id'];
        $folder_id = isset($post['folder_id']) ? $post['folder_id'] : 0;
        $message_text = isset($post['message_text']) ? $post['message_text'] : '';
        if ((!$post['author_id'] || $post['author_id'] == ANONYMOUS && $action != 'delete') && $msg_id) {
            trigger_error('NO_AUTHOR');
        }
        if ($action == 'quotepost') {
            // Decode text for message display
            decode_message($message_text, $post['bbcode_uid']);
        }
        if ($action != 'delete') {
            $enable_urls = $post['enable_magic_url'];
            $enable_sig = isset($post['enable_sig']) ? $post['enable_sig'] : 0;
            $message_attachment = isset($post['message_attachment']) ? $post['message_attachment'] : 0;
            $message_subject = $post['message_subject'];
            $message_time = $post['message_time'];
            $bbcode_uid = $post['bbcode_uid'];
            $quote_username = isset($post['quote_username']) ? $post['quote_username'] : '';
            $icon_id = isset($post['icon_id']) ? $post['icon_id'] : 0;
            if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview) {
                // Add the original author as the recipient if quoting a post or only replying and not having checked "reply to all"
                if ($action == 'quotepost' || !$reply_to_all) {
                    $address_list = array('u' => array($post['author_id'] => 'to'));
                } else {
                    // We try to include every previously listed member from the TO Header - Reply to all
                    $address_list = rebuild_header(array('to' => $post['to_address']));
                    // Add the author (if he is already listed then this is no shame (it will be overwritten))
                    $address_list['u'][$post['author_id']] = 'to';
                    // Now, make sure the user itself is not listed. ;)
                    if (isset($address_list['u'][$user->data['user_id']])) {
                        unset($address_list['u'][$user->data['user_id']]);
                    }
                }
            } else {
                if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview) {
                    // Rebuild TO and BCC Header
                    $address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
                }
            }
            if ($action == 'quotepost') {
                $check_value = 0;
            } else {
                $check_value = ($post['enable_bbcode'] + 1 << 8) + ($post['enable_smilies'] + 1 << 4) + ($enable_urls + 1 << 2) + ($post['enable_sig'] + 1 << 1);
            }
        }
    } else {
        $message_attachment = 0;
        $message_text = $message_subject = '';
        if ($to_user_id && $to_user_id != ANONYMOUS && $action == 'post') {
            $address_list['u'][$to_user_id] = 'to';
        } else {
            if ($to_group_id && $action == 'post') {
                $address_list['g'][$to_group_id] = 'to';
            }
        }
        $check_value = 0;
    }
    if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group'))) {
        trigger_error('NO_AUTH_GROUP_MESSAGE');
    }
    if ($action == 'edit' && !$refresh && !$preview && !$submit) {
        if (!($message_time > time() - $config['pm_edit_time'] * 60 || !$config['pm_edit_time'])) {
            trigger_error('CANNOT_EDIT_MESSAGE_TIME');
        }
    }
    if ($action == 'post') {
        $template->assign_var('S_NEW_MESSAGE', true);
    }
    if (!isset($icon_id)) {
        $icon_id = 0;
    }
    $message_parser = new parse_message();
    $plupload = $phpbb_container->get('plupload');
    $message_parser->set_plupload($plupload);
    $message_parser->message = $action == 'reply' ? '' : $message_text;
    unset($message_text);
    $s_action = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;action={$action}", true, $user->session_id);
    $s_action .= ($folder_id ? "&amp;f={$folder_id}" : '') . ($msg_id ? "&amp;p={$msg_id}" : '');
    // Delete triggered ?
    if ($action == 'delete') {
        // Folder id has been determined by the SQL Statement
        // $folder_id = request_var('f', PRIVMSGS_NO_BOX);
        // Do we need to confirm ?
        if (confirm_box(true)) {
            delete_pm($user->data['user_id'], $msg_id, $folder_id);
            // jump to next message in "history"? nope, not for the moment. But able to be included later.
            $meta_info = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;folder={$folder_id}");
            $message = $user->lang['MESSAGE_DELETED'];
            meta_refresh(3, $meta_info);
            $message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
            trigger_error($message);
        } else {
            $s_hidden_fields = array('p' => $msg_id, 'f' => $folder_id, 'action' => 'delete');
            // "{$phpbb_root_path}ucp.$phpEx?i=pm&amp;mode=compose"
            confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
        }
        redirect(append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
    }
    // Get maximum number of allowed recipients
    $sql = 'SELECT MAX(g.group_max_recipients) as max_recipients
		FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
		WHERE ug.user_id = ' . $user->data['user_id'] . '
			AND ug.user_pending = 0
			AND ug.group_id = g.group_id';
    $result = $db->sql_query($sql);
    $max_recipients = (int) $db->sql_fetchfield('max_recipients');
    $db->sql_freeresult($result);
    $max_recipients = !$max_recipients ? $config['pm_max_recipients'] : $max_recipients;
    // If this is a quote/reply "to all"... we may increase the max_recpients to the number of original recipients
    if (($action == 'reply' || $action == 'quote') && $max_recipients && $reply_to_all) {
        // We try to include every previously listed member from the TO Header
        $list = rebuild_header(array('to' => $post['to_address']));
        // Can be an empty array too ;)
        $list = !empty($list['u']) ? $list['u'] : array();
        $list[$post['author_id']] = 'to';
        if (isset($list[$user->data['user_id']])) {
            unset($list[$user->data['user_id']]);
        }
        $max_recipients = $max_recipients < sizeof($list) ? sizeof($list) : $max_recipients;
        unset($list);
    }
    // Handle User/Group adding/removing
    handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);
    // Check mass pm to group permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm_group')) && !empty($address_list['g'])) {
        $address_list = array();
        $error[] = $user->lang['NO_AUTH_GROUP_MESSAGE'];
    }
    // Check mass pm to users permission
    if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1) {
        $address_list = get_recipients($address_list, 1);
        $error[] = $user->lang('TOO_MANY_RECIPIENTS', 1);
    }
    // Check for too many recipients
    if (!empty($address_list['u']) && $max_recipients && sizeof($address_list['u']) > $max_recipients) {
        $address_list = get_recipients($address_list, $max_recipients);
        $error[] = $user->lang('TOO_MANY_RECIPIENTS', $max_recipients);
    }
    // Always check if the submitted attachment data is valid and belongs to the user.
    // Further down (especially in submit_post()) we do not check this again.
    $message_parser->get_submitted_attachment_data();
    if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit') {
        // Do not change to SELECT *
        $sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename, filesize
			FROM ' . ATTACHMENTS_TABLE . "\n\t\t\tWHERE post_msg_id = {$msg_id}\n\t\t\t\tAND in_message = 1\n\t\t\t\tAND is_orphan = 0\n\t\t\tORDER BY filetime DESC";
        $result = $db->sql_query($sql);
        $message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
        $db->sql_freeresult($result);
    }
    if (!in_array($action, array('quote', 'edit', 'delete', 'forward'))) {
        $enable_sig = $config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig');
        $enable_smilies = $config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies');
        $enable_bbcode = $config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode');
        $enable_urls = true;
    }
    $enable_magic_url = $drafts = false;
    // User own some drafts?
    if ($auth->acl_get('u_savedrafts') && $action != 'delete') {
        $sql = 'SELECT draft_id
			FROM ' . DRAFTS_TABLE . '
			WHERE forum_id = 0
				AND topic_id = 0
				AND user_id = ' . $user->data['user_id'] . ($draft_id ? " AND draft_id <> {$draft_id}" : '');
        $result = $db->sql_query_limit($sql, 1);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if ($row) {
            $drafts = true;
        }
    }
    if ($action == 'edit') {
        $message_parser->bbcode_uid = $bbcode_uid;
    }
    $bbcode_status = $config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode') ? true : false;
    $smilies_status = $config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies') ? true : false;
    $img_status = $config['auth_img_pm'] && $auth->acl_get('u_pm_img') ? true : false;
    $flash_status = $config['auth_flash_pm'] && $auth->acl_get('u_pm_flash') ? true : false;
    $url_status = $config['allow_post_links'] ? true : false;
    // Save Draft
    if ($save && $auth->acl_get('u_savedrafts')) {
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
        $subject = !$subject && $action != 'post' ? $user->lang['NEW_MESSAGE'] : $subject;
        $message = utf8_normalize_nfc(request_var('message', '', true));
        if ($subject && $message) {
            if (confirm_box(true)) {
                $sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array('user_id' => $user->data['user_id'], 'topic_id' => 0, 'forum_id' => 0, 'save_time' => $current_time, 'draft_subject' => $subject, 'draft_message' => $message));
                $db->sql_query($sql);
                $redirect_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;mode={$mode}");
                meta_refresh(3, $redirect_url);
                $message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');
                trigger_error($message);
            } else {
                $s_hidden_fields = build_hidden_fields(array('mode' => $mode, 'action' => $action, 'save' => true, 'subject' => $subject, 'message' => $message, 'u' => $to_user_id, 'g' => $to_group_id, 'p' => $msg_id));
                $s_hidden_fields .= build_address_field($address_list);
                confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
            }
        } else {
            if (utf8_clean_string($subject) === '') {
                $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
            }
            if (utf8_clean_string($message) === '') {
                $error[] = $user->lang['TOO_FEW_CHARS'];
            }
        }
        unset($subject, $message);
    }
    // Load Draft
    if ($draft_id && $auth->acl_get('u_savedrafts')) {
        $sql = 'SELECT draft_subject, draft_message
			FROM ' . DRAFTS_TABLE . "\n\t\t\tWHERE draft_id = {$draft_id}\n\t\t\t\tAND topic_id = 0\n\t\t\t\tAND forum_id = 0\n\t\t\t\tAND user_id = " . $user->data['user_id'];
        $result = $db->sql_query_limit($sql, 1);
        if ($row = $db->sql_fetchrow($result)) {
            $message_parser->message = $row['draft_message'];
            $message_subject = $row['draft_subject'];
            $template->assign_var('S_DRAFT_LOADED', true);
        } else {
            $draft_id = 0;
        }
        $db->sql_freeresult($result);
    }
    // Load Drafts
    if ($load && $drafts) {
        load_drafts(0, 0, $id, $action, $msg_id);
    }
    if ($submit || $preview || $refresh) {
        if (($submit || $preview) && !check_form_key('ucp_pm_compose')) {
            $error[] = $user->lang['FORM_INVALID'];
        }
        $subject = utf8_normalize_nfc(request_var('subject', '', true));
        $message_parser->message = utf8_normalize_nfc(request_var('message', '', true));
        $icon_id = request_var('icon', 0);
        $enable_bbcode = !$bbcode_status || isset($_POST['disable_bbcode']) ? false : true;
        $enable_smilies = !$smilies_status || isset($_POST['disable_smilies']) ? false : true;
        $enable_urls = isset($_POST['disable_magic_url']) ? 0 : 1;
        $enable_sig = !$config['allow_sig'] || !$config['allow_sig_pm'] ? false : (isset($_POST['attach_sig']) ? true : false);
        if ($submit) {
            $status_switch = ($enable_bbcode + 1 << 8) + ($enable_smilies + 1 << 4) + ($enable_urls + 1 << 2) + ($enable_sig + 1 << 1);
            $status_switch = $status_switch != $check_value;
        } else {
            $status_switch = 1;
        }
        // Parse Attachments - before checksum is calculated
        $message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);
        if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc)) {
            $error[] = implode('<br />', $message_parser->warn_msg);
            $message_parser->warn_msg = array();
        }
        // Parse message
        $message_parser->parse($enable_bbcode, $config['allow_post_links'] ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);
        // On a refresh we do not care about message parsing errors
        if (sizeof($message_parser->warn_msg) && !$refresh) {
            $error[] = implode('<br />', $message_parser->warn_msg);
        }
        if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood')) {
            // Flood check
            $last_post_time = $user->data['user_lastpost_time'];
            if ($last_post_time) {
                if ($last_post_time && $current_time - $last_post_time < intval($config['flood_interval'])) {
                    $error[] = $user->lang['FLOOD_ERROR'];
                }
            }
        }
        // Subject defined
        if ($submit) {
            if (utf8_clean_string($subject) === '') {
                $error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
            }
            if (!sizeof($address_list)) {
                $error[] = $user->lang['NO_RECIPIENT'];
            }
        }
        // Store message, sync counters
        if (!sizeof($error) && $submit) {
            $pm_data = array('msg_id' => (int) $msg_id, 'from_user_id' => $user->data['user_id'], 'from_user_ip' => $user->ip, 'from_username' => $user->data['username'], 'reply_from_root_level' => isset($post['root_level']) ? (int) $post['root_level'] : 0, 'reply_from_msg_id' => (int) $msg_id, 'icon_id' => (int) $icon_id, 'enable_sig' => (bool) $enable_sig, 'enable_bbcode' => (bool) $enable_bbcode, 'enable_smilies' => (bool) $enable_smilies, 'enable_urls' => (bool) $enable_urls, 'bbcode_bitfield' => $message_parser->bbcode_bitfield, 'bbcode_uid' => $message_parser->bbcode_uid, 'message' => $message_parser->message, 'attachment_data' => $message_parser->attachment_data, 'filename_data' => $message_parser->filename_data, 'address_list' => $address_list);
            // ((!$message_subject) ? $subject : $message_subject)
            $msg_id = submit_pm($action, $subject, $pm_data);
            $return_message_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;mode=view&amp;p=' . $msg_id);
            $inbox_folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=inbox');
            $outbox_folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=outbox');
            $folder_url = '';
            if ($folder_id > 0 && isset($user_folders[$folder_id])) {
                $folder_url = append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'i=pm&amp;folder=' . $folder_id);
            }
            $return_box_url = $action === 'post' || $action === 'edit' ? $outbox_folder_url : $inbox_folder_url;
            $return_box_lang = $action === 'post' || $action === 'edit' ? 'PM_OUTBOX' : 'PM_INBOX';
            $save_message = $action === 'edit' ? $user->lang['MESSAGE_EDITED'] : $user->lang['MESSAGE_STORED'];
            $message = $save_message . '<br /><br />' . $user->lang('VIEW_PRIVATE_MESSAGE', '<a href="' . $return_message_url . '">', '</a>');
            $last_click_type = 'CLICK_RETURN_FOLDER';
            if ($folder_url) {
                $message .= '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $folder_url . '">', '</a>', $user_folders[$folder_id]['folder_name']);
                $last_click_type = 'CLICK_GOTO_FOLDER';
            }
            $message .= '<br /><br />' . sprintf($user->lang[$last_click_type], '<a href="' . $return_box_url . '">', '</a>', $user->lang[$return_box_lang]);
            meta_refresh(3, $return_message_url);
            trigger_error($message);
        }
        $message_subject = $subject;
    }
    // Preview
    if (!sizeof($error) && $preview) {
        $preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
        $preview_signature = $user->data['user_sig'];
        $preview_signature_uid = $user->data['user_sig_bbcode_uid'];
        $preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];
        // Signature
        if ($enable_sig && $config['allow_sig'] && $preview_signature) {
            $parse_sig = new parse_message($preview_signature);
            $parse_sig->bbcode_uid = $preview_signature_uid;
            $parse_sig->bbcode_bitfield = $preview_signature_bitfield;
            $parse_sig->format_display($config['allow_sig_bbcode'], $config['allow_sig_links'], $config['allow_sig_smilies']);
            $preview_signature = $parse_sig->message;
            unset($parse_sig);
        } else {
            $preview_signature = '';
        }
        // Attachment Preview
        if (sizeof($message_parser->attachment_data)) {
            $template->assign_var('S_HAS_ATTACHMENTS', true);
            $update_count = array();
            $attachment_data = $message_parser->attachment_data;
            parse_attachments(false, $preview_message, $attachment_data, $update_count, true);
            foreach ($attachment_data as $i => $attachment) {
                $template->assign_block_vars('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
            }
            unset($attachment_data);
        }
        $preview_subject = censor_text($subject);
        if (!sizeof($error)) {
            $template->assign_vars(array('PREVIEW_SUBJECT' => $preview_subject, 'PREVIEW_MESSAGE' => $preview_message, 'PREVIEW_SIGNATURE' => $preview_signature, 'S_DISPLAY_PREVIEW' => true));
        }
        unset($message_text);
    }
    // Decode text for message display
    $bbcode_uid = ($action == 'quote' || $action == 'forward') && !$preview && !$refresh && (!sizeof($error) || sizeof($error) && !$submit) ? $bbcode_uid : $message_parser->bbcode_uid;
    $message_parser->decode_message($bbcode_uid);
    if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit) {
        if ($action == 'quotepost') {
            $post_id = request_var('p', 0);
            if ($config['allow_post_links']) {
                $message_link = "[url=" . generate_board_url() . "/viewtopic.{$phpEx}?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}{$user->lang['COLON']} {$message_subject}[/url]\n\n";
            } else {
                $message_link = $user->lang['SUBJECT'] . $user->lang['COLON'] . ' ' . $message_subject . " (" . generate_board_url() . "/viewtopic.{$phpEx}?p={$post_id}#p{$post_id})\n\n";
            }
        } else {
            $message_link = '';
        }
        $message_parser->message = $message_link . '[quote=&quot;' . $quote_username . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
    }
    if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh) {
        $message_subject = (!preg_match('/^Re:/', $message_subject) ? 'Re: ' : '') . censor_text($message_subject);
    }
    if ($action == 'forward' && !$preview && !$refresh && !$submit) {
        $fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);
        if ($config['allow_post_links']) {
            $quote_username_text = '[url=' . generate_board_url() . "/memberlist.{$phpEx}?mode=viewprofile&amp;u={$post['author_id']}]{$quote_username}[/url]";
        } else {
            $quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.{$phpEx}?mode=viewprofile&amp;u={$post['author_id']})";
        }
        $forward_text = array();
        $forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
        $forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
        $forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time, false, true));
        $forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
        $forward_text[] = sprintf($user->lang['FWD_TO'], implode($user->lang['COMMA_SEPARATOR'], $fwd_to_field['to']));
        $message_parser->message = implode("\n", $forward_text) . "\n\n[quote=&quot;{$quote_username}&quot;]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
        $message_subject = (!preg_match('/^Fwd:/', $message_subject) ? 'Fwd: ' : '') . censor_text($message_subject);
    }
    $attachment_data = $message_parser->attachment_data;
    $filename_data = $message_parser->filename_data;
    $message_text = $message_parser->message;
    // MAIN PM PAGE BEGINS HERE
    // Generate smiley listing
    generate_smilies('inline', 0);
    // Generate PM Icons
    $s_pm_icons = false;
    if ($config['enable_pm_icons']) {
        $s_pm_icons = posting_gen_topic_icons($action, $icon_id);
    }
    // Generate inline attachment select box
    posting_gen_inline_attachments($attachment_data);
    // Build address list for display
    // array('u' => array($author_id => 'to'));
    if (sizeof($address_list)) {
        // Get Usernames and Group Names
        $result = array();
        if (!empty($address_list['u'])) {
            $sql = 'SELECT user_id as id, username as name, user_colour as colour
				FROM ' . USERS_TABLE . '
				WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
				ORDER BY username_clean ASC';
            $result['u'] = $db->sql_query($sql);
        }
        if (!empty($address_list['g'])) {
            $sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
				FROM ' . GROUPS_TABLE . ' g';
            if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) {
                $sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
            }
            $sql .= $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel') ? ' WHERE ' : ' AND ';
            $sql .= 'g.group_receive_pm = 1
				AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
				ORDER BY g.group_name ASC';
            $result['g'] = $db->sql_query($sql);
        }
        $u = $g = array();
        $_types = array('u', 'g');
        foreach ($_types as $type) {
            if (isset($result[$type]) && $result[$type]) {
                while ($row = $db->sql_fetchrow($result[$type])) {
                    if ($type == 'g') {
                        $row['name'] = $row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['name']] : $row['name'];
                    }
                    ${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
                }
                $db->sql_freeresult($result[$type]);
            }
        }
        // Now Build the address list
        $plain_address_field = '';
        foreach ($address_list as $type => $adr_ary) {
            foreach ($adr_ary as $id => $field) {
                if (!isset(${$type}[$id])) {
                    unset($address_list[$type][$id]);
                    continue;
                }
                $field = $field == 'to' ? 'to' : 'bcc';
                $type = $type == 'u' ? 'u' : 'g';
                $id = (int) $id;
                $tpl_ary = array('IS_GROUP' => $type == 'g' ? true : false, 'IS_USER' => $type == 'u' ? true : false, 'UG_ID' => $id, 'NAME' => ${$type}[$id]['name'], 'COLOUR' => ${$type}[$id]['colour'] ? '#' . ${$type}[$id]['colour'] : '', 'TYPE' => $type);
                if ($type == 'u') {
                    $tpl_ary = array_merge($tpl_ary, array('U_VIEW' => get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']), 'NAME_FULL' => get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour'])));
                } else {
                    $tpl_ary = array_merge($tpl_ary, array('U_VIEW' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=group&amp;g=' . $id)));
                }
                $template->assign_block_vars($field . '_recipient', $tpl_ary);
            }
        }
    }
    // Build hidden address list
    $s_hidden_address_field = build_address_field($address_list);
    $bbcode_checked = isset($enable_bbcode) ? !$enable_bbcode : ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') ? !$user->optionget('bbcode') : 1);
    $smilies_checked = isset($enable_smilies) ? !$enable_smilies : ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') ? !$user->optionget('smilies') : 1);
    $urls_checked = isset($enable_urls) ? !$enable_urls : 0;
    $sig_checked = $enable_sig;
    switch ($action) {
        case 'post':
            $page_title = $user->lang['POST_NEW_PM'];
            break;
        case 'quote':
            $page_title = $user->lang['POST_QUOTE_PM'];
            break;
        case 'quotepost':
            $page_title = $user->lang['POST_PM_POST'];
            break;
        case 'reply':
            $page_title = $user->lang['POST_REPLY_PM'];
            break;
        case 'edit':
            $page_title = $user->lang['POST_EDIT_PM'];
            break;
        case 'forward':
            $page_title = $user->lang['POST_FORWARD_PM'];
            break;
        default:
            trigger_error('NO_ACTION_MODE', E_USER_ERROR);
            break;
    }
    $s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
    $s_hidden_fields .= isset($check_value) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
    $s_hidden_fields .= $draft_id || isset($_REQUEST['draft_loaded']) ? '<input type="hidden" name="draft_loaded" value="' . (isset($_REQUEST['draft_loaded']) ? $request->variable('draft_loaded', 0) : $draft_id) . '" />' : '';
    $form_enctype = @ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !$config['allow_pm_attach'] || !$auth->acl_get('u_pm_attach') ? '' : ' enctype="multipart/form-data"';
    // Start assigning vars for main posting page ...
    $template->assign_vars(array('L_POST_A' => $page_title, 'L_ICON' => $user->lang['PM_ICON'], 'L_MESSAGE_BODY_EXPLAIN' => $user->lang('MESSAGE_BODY_EXPLAIN', (int) $config['max_post_chars']), 'SUBJECT' => isset($message_subject) ? $message_subject : '', 'MESSAGE' => $message_text, 'BBCODE_STATUS' => $bbcode_status ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '">', '</a>'), 'IMG_STATUS' => $img_status ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $flash_status ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'SMILIES_STATUS' => $smilies_status ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'URL_STATUS' => $url_status ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_post_font_size'], 'MINI_POST_IMG' => $user->img('icon_post_target', $user->lang['PM']), 'ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'MAX_RECIPIENTS' => $config['allow_mass_pm'] && ($auth->acl_get('u_masspm') || $auth->acl_get('u_masspm_group')) ? $max_recipients : 0, 'S_COMPOSE_PM' => true, 'S_EDIT_POST' => $action == 'edit', 'S_SHOW_PM_ICONS' => $s_pm_icons, 'S_BBCODE_ALLOWED' => $bbcode_status ? 1 : 0, 'S_BBCODE_CHECKED' => $bbcode_checked ? ' checked="checked"' : '', 'S_SMILIES_ALLOWED' => $smilies_status, 'S_SMILIES_CHECKED' => $smilies_checked ? ' checked="checked"' : '', 'S_SIG_ALLOWED' => $config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig'), 'S_SIGNATURE_CHECKED' => $sig_checked ? ' checked="checked"' : '', 'S_LINKS_ALLOWED' => $url_status, 'S_MAGIC_URL_CHECKED' => $urls_checked ? ' checked="checked"' : '', 'S_SAVE_ALLOWED' => $auth->acl_get('u_savedrafts') && $action != 'edit' ? true : false, 'S_HAS_DRAFTS' => $auth->acl_get('u_savedrafts') && $drafts, 'S_FORM_ENCTYPE' => $form_enctype, 'S_ATTACH_DATA' => json_encode($message_parser->attachment_data), 'S_BBCODE_IMG' => $img_status, 'S_BBCODE_FLASH' => $flash_status, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_URL' => $url_status, 'S_POST_ACTION' => $s_action, 'S_HIDDEN_ADDRESS_FIELD' => $s_hidden_address_field, 'S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_CLOSE_PROGRESS_WINDOW' => isset($_POST['add_file']), 'U_PROGRESS_BAR' => append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=0&amp;mode=popup'), 'UA_PROGRESS_BAR' => addslashes(append_sid("{$phpbb_root_path}posting.{$phpEx}", 'f=0&amp;mode=popup'))));
    // Build custom bbcodes array
    display_custom_bbcodes();
    // Show attachment box for adding attachments if true
    $allowed = $auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype;
    if ($allowed) {
        $max_files = $auth->acl_gets('a_', 'm_') ? 0 : (int) $config['max_attachments_pm'];
        $plupload->configure($cache, $template, $s_action, false, $max_files);
    }
    // Attachment entry
    posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
    // Message History
    if ($action == 'reply' || $action == 'quote' || $action == 'forward') {
        if (message_history($msg_id, $user->data['user_id'], $post, array(), true)) {
            $template->assign_var('S_DISPLAY_HISTORY', true);
        }
    }
}
Exemplo n.º 23
0
    function main($id, $mode)
    {
        global $cache, $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
        global $request, $phpbb_container, $phpbb_log, $phpbb_dispatcher;
        $user->add_lang('posting');
        $submit = $request->variable('submit', false, false, \phpbb\request\request_interface::POST);
        $delete = $request->variable('delete', false, false, \phpbb\request\request_interface::POST);
        $error = $data = array();
        $s_hidden_fields = '';
        switch ($mode) {
            case 'reg_details':
                $data = array('username' => $request->variable('username', $user->data['username'], true), 'email' => strtolower($request->variable('email', $user->data['user_email'])), 'new_password' => $request->variable('new_password', '', true), 'cur_password' => $request->variable('cur_password', '', true), 'password_confirm' => $request->variable('password_confirm', '', true));
                /**
                 * Modify user registration data on editing account settings in UCP
                 *
                 * @event core.ucp_profile_reg_details_data
                 * @var	array	data		Array with current or updated user registration data
                 * @var	bool	submit		Flag indicating if submit button has been pressed
                 * @since 3.1.4-RC1
                 */
                $vars = array('data', 'submit');
                extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_data', compact($vars)));
                add_form_key('ucp_reg_details');
                if ($submit) {
                    // Do not check cur_password, it is the old one.
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'email' => array(array('string', false, 6, 60), array('user_email')));
                    if ($auth->acl_get('u_chgname') && $config['allow_namechange']) {
                        $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username'));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = $data['password_confirm'] ? 'NEW_PASSWORD_ERROR' : 'NEW_PASSWORD_CONFIRM_EMPTY';
                    }
                    // Instantiate passwords manager
                    /* @var $passwords_manager \phpbb\passwords\manager */
                    $passwords_manager = $phpbb_container->get('passwords.manager');
                    // Only check the new password against the previous password if there have been no errors
                    if (!sizeof($error) && $auth->acl_get('u_chgpasswd') && $data['new_password'] && $passwords_manager->check($data['new_password'], $user->data['user_password'])) {
                        $error[] = 'SAME_PASSWORD_ERROR';
                    }
                    if (!$passwords_manager->check($data['cur_password'], $user->data['user_password'])) {
                        $error[] = $data['cur_password'] ? 'CUR_PASSWORD_ERROR' : 'CUR_PASSWORD_EMPTY';
                    }
                    if (!check_form_key('ucp_reg_details')) {
                        $error[] = 'FORM_INVALID';
                    }
                    /**
                     * Validate user data on editing registration data in UCP
                     *
                     * @event core.ucp_profile_reg_details_validate
                     * @var	array	data			Array with user profile data
                     * @var	bool	submit			Flag indicating if submit button has been pressed
                     * @var array	error			Array of any generated errors
                     * @since 3.1.4-RC1
                     */
                    $vars = array('data', 'submit', 'error');
                    extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_validate', compact($vars)));
                    if (!sizeof($error)) {
                        $sql_ary = array('username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $data['username'] : $user->data['username'], 'username_clean' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? utf8_clean_string($data['username']) : $user->data['username_clean'], 'user_email' => $auth->acl_get('u_chgemail') ? $data['email'] : $user->data['user_email'], 'user_email_hash' => $auth->acl_get('u_chgemail') ? phpbb_email_hash($data['email']) : $user->data['user_email_hash'], 'user_password' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? $passwords_manager->hash($data['new_password']) : $user->data['user_password'], 'user_passchg' => $auth->acl_get('u_chgpasswd') && $data['new_password'] ? time() : 0);
                        if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) {
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array('reportee_id' => $user->data['user_id'], $user->data['username'], $data['username']));
                        }
                        if ($auth->acl_get('u_chgpasswd') && $data['new_password'] && !$passwords_manager->check($data['new_password'], $user->data['user_password'])) {
                            $user->reset_login_keys();
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array('reportee_id' => $user->data['user_id'], $user->data['username']));
                        }
                        if ($auth->acl_get('u_chgemail') && $data['email'] != $user->data['user_email']) {
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array('reportee_id' => $user->data['user_id'], $user->data['username'], $data['user_email'], $data['email']));
                        }
                        $message = 'PROFILE_UPDATED';
                        if ($auth->acl_get('u_chgemail') && $config['email_enable'] && $data['email'] != $user->data['user_email'] && $user->data['user_type'] != USER_FOUNDER && ($config['require_activation'] == USER_ACTIVATION_SELF || $config['require_activation'] == USER_ACTIVATION_ADMIN)) {
                            $message = $config['require_activation'] == USER_ACTIVATION_SELF ? 'ACCOUNT_EMAIL_CHANGED' : 'ACCOUNT_EMAIL_CHANGED_ADMIN';
                            include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                            $server_url = generate_board_url();
                            $user_actkey = gen_rand_string(mt_rand(6, 10));
                            $messenger = new messenger(false);
                            $template_file = $config['require_activation'] == USER_ACTIVATION_ADMIN ? 'user_activate_inactive' : 'user_activate';
                            $messenger->template($template_file, $user->data['user_lang']);
                            $messenger->to($data['email'], $data['username']);
                            $messenger->anti_abuse_headers($config, $user);
                            $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), '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 ... these users can activate a user
                                $admin_ary = $auth->acl_get_list(false, 'a_user', false);
                                $admin_ary = !empty($admin_ary[0]['a_user']) ? $admin_ary[0]['a_user'] : array();
                                // Also include founders
                                $where_sql = ' WHERE user_type = ' . USER_FOUNDER;
                                if (sizeof($admin_ary)) {
                                    $where_sql .= ' OR ' . $db->sql_in_set('user_id', $admin_ary);
                                }
                                $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type
									FROM ' . USERS_TABLE . ' ' . $where_sql;
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    $messenger->template('admin_activate', $row['user_lang']);
                                    $messenger->set_addresses($row);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($data['username']), 'U_USER_DETAILS' => "{$server_url}/memberlist.{$phpEx}?mode=viewprofile&u={$user->data['user_id']}", '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);
                            }
                            user_active_flip('deactivate', $user->data['user_id'], INACTIVE_PROFILE);
                            // Because we want the profile to be reactivated we set user_newpasswd to empty (else the reactivation will fail)
                            $sql_ary['user_actkey'] = $user_actkey;
                            $sql_ary['user_newpasswd'] = '';
                        }
                        /**
                         * Modify user registration data before submitting it to the database
                         *
                         * @event core.ucp_profile_reg_details_sql_ary
                         * @var	array	data		Array with current or updated user registration data
                         * @var	array	sql_ary		Array with user registration data to submit to the database
                         * @since 3.1.4-RC1
                         */
                        $vars = array('data', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.ucp_profile_reg_details_sql_ary', compact($vars)));
                        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 ($data['username'] != $user->data['username'] && $auth->acl_get('u_chgname') && $config['allow_namechange']) {
                            user_update_name($user->data['username'], $data['username']);
                        }
                        // Now, we can remove the user completely (kill the session) - NOT BEFORE!!!
                        if (!empty($sql_ary['user_actkey'])) {
                            meta_refresh(5, append_sid($phpbb_root_path . 'index.' . $phpEx));
                            $message = $user->lang[$message] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid($phpbb_root_path . 'index.' . $phpEx) . '">', '</a>');
                            // Because the user gets deactivated we log him out too, killing his session
                            $user->session_kill();
                        } else {
                            meta_refresh(3, $this->u_action);
                            $message = $user->lang[$message] . '<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 = array_map(array($user, 'lang'), $error);
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], 'EMAIL' => $data['email'], 'PASSWORD_CONFIRM' => $data['password_confirm'], 'NEW_PASSWORD' => $data['new_password'], 'CUR_PASSWORD' => '', 'L_USERNAME_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'S_FORCE_PASSWORD' => $auth->acl_get('u_chgpasswd') && $config['chg_passforce'] && $user->data['user_passchg'] < time() - $config['chg_passforce'] * 86400 ? 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':
                // Do not display profile information panel if not authed to do so
                if (!$auth->acl_get('u_chgprofileinfo')) {
                    trigger_error('NO_AUTH_PROFILEINFO');
                }
                /* @var $cp \phpbb\profilefields\manager */
                $cp = $phpbb_container->get('profilefields.manager');
                $cp_data = $cp_error = array();
                $data = array('jabber' => $request->variable('jabber', $user->data['user_jabber'], true));
                if ($config['allow_birthdays']) {
                    $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    if ($user->data['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user->data['user_birthday']);
                    }
                    $data['bday_day'] = $request->variable('bday_day', $data['bday_day']);
                    $data['bday_month'] = $request->variable('bday_month', $data['bday_month']);
                    $data['bday_year'] = $request->variable('bday_year', $data['bday_year']);
                    $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                }
                /**
                 * Modify user data on editing profile in UCP
                 *
                 * @event core.ucp_profile_modify_profile_info
                 * @var	array	data		Array with user profile data
                 * @var	bool	submit		Flag indicating if submit button has been pressed
                 * @since 3.1.4-RC1
                 */
                $vars = array('data', 'submit');
                extract($phpbb_dispatcher->trigger_event('core.ucp_profile_modify_profile_info', compact($vars)));
                add_form_key('ucp_profile_info');
                if ($submit) {
                    $validate_array = array('jabber' => array(array('string', true, 5, 255), array('jabber')));
                    if ($config['allow_birthdays']) {
                        $validate_array = array_merge($validate_array, array('bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time()) + 50), 'user_birthday' => array('date', true)));
                    }
                    $error = validate_data($data, $validate_array);
                    // 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 (!check_form_key('ucp_profile_info')) {
                        $error[] = 'FORM_INVALID';
                    }
                    /**
                     * Validate user data on editing profile in UCP
                     *
                     * @event core.ucp_profile_validate_profile_info
                     * @var	array	data			Array with user profile data
                     * @var	bool	submit			Flag indicating if submit button has been pressed
                     * @var array	error			Array of any generated errors
                     * @since 3.1.4-RC1
                     */
                    $vars = array('data', 'submit', 'error');
                    extract($phpbb_dispatcher->trigger_event('core.ucp_profile_validate_profile_info', compact($vars)));
                    if (!sizeof($error)) {
                        $data['notify'] = $user->data['user_notify_type'];
                        if ($data['notify'] == NOTIFY_IM && (!$config['jab_enable'] || !$data['jabber'] || !@extension_loaded('xml'))) {
                            // User has not filled in a jabber address (Or one of the modules is disabled or jabber is disabled)
                            // Disable notify by Jabber now for this user.
                            $data['notify'] = NOTIFY_EMAIL;
                        }
                        $sql_ary = array('user_jabber' => $data['jabber'], 'user_notify_type' => $data['notify']);
                        if ($config['allow_birthdays']) {
                            $sql_ary['user_birthday'] = $data['user_birthday'];
                        }
                        /**
                         * Modify profile data in UCP before submitting to the database
                         *
                         * @event core.ucp_profile_info_modify_sql_ary
                         * @var	array	cp_data		Array with the user custom profile fields data
                         * @var	array	data		Array with user profile data
                         * @var  array	sql_ary		user options data we update
                         * @since 3.1.4-RC1
                         */
                        $vars = array('cp_data', 'data', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.ucp_profile_info_modify_sql_ary', compact($vars)));
                        $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
                        $cp->update_profile_field_data($user->data['user_id'], $cp_data);
                        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 = array_map(array($user, 'lang'), $error);
                }
                if ($config['allow_birthdays']) {
                    $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('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_BIRTHDAYS_ENABLED' => true));
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'S_JABBER_ENABLED' => $config['jab_enable'], 'JABBER' => $data['jabber']));
                // 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;
                include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? $user->optionget('sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? $user->optionget('sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? $user->optionget('sig_links') : false;
                $decoded_message = generate_text_for_edit($user->data['user_sig'], $user->data['user_sig_bbcode_uid'], $user->data['user_sig_bbcode_bitfield']);
                $signature = $request->variable('signature', $decoded_message['text'], true);
                $signature_preview = '';
                if ($submit || $request->is_set_post('preview')) {
                    $enable_bbcode = $config['allow_sig_bbcode'] ? !$request->variable('disable_bbcode', false) : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? !$request->variable('disable_smilies', false) : false;
                    $enable_urls = $config['allow_sig_links'] ? !$request->variable('disable_magic_url', false) : false;
                    if (!check_form_key('ucp_sig')) {
                        $error[] = 'FORM_INVALID';
                    }
                }
                $bbcode_uid = $bbcode_bitfield = $bbcode_flags = '';
                $warn_msg = generate_text_for_storage($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags, $enable_bbcode, $enable_urls, $enable_smilies);
                if (sizeof($warn_msg)) {
                    $error += $warn_msg;
                }
                if (!$submit) {
                    // Parse it for displaying
                    $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags);
                } else {
                    if (!sizeof($error)) {
                        $user->optionset('sig_bbcode', $enable_bbcode);
                        $user->optionset('sig_smilies', $enable_smilies);
                        $user->optionset('sig_links', $enable_urls);
                        $sql_ary = array('user_sig' => $signature, 'user_options' => $user->data['user_options'], 'user_sig_bbcode_uid' => $bbcode_uid, 'user_sig_bbcode_bitfield' => $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 = array_map(array($user, 'lang'), $error);
                $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_bitfield);
                /** @var \phpbb\controller\helper $controller_helper */
                $controller_helper = $phpbb_container->get('controller.helper');
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'SIGNATURE' => $decoded_message['text'], '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' => $user->lang($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF', '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</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'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'MAX_FONT_SIZE' => (int) $config['max_sig_font_size'], 'L_SIGNATURE_EXPLAIN' => $user->lang('SIGNATURE_EXPLAIN', (int) $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, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                add_form_key('ucp_sig');
                // Build custom bbcodes array
                display_custom_bbcodes();
                // Generate smiley listing
                generate_smilies('inline', 0);
                break;
            case 'avatar':
                add_form_key('ucp_avatar');
                $avatars_enabled = false;
                if ($config['allow_avatar'] && $auth->acl_get('u_chgavatar')) {
                    /* @var $phpbb_avatar_manager \phpbb\avatar\manager */
                    $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                    $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
                    // This is normalised data, without the user_ prefix
                    $avatar_data = \phpbb\avatar\manager::clean_row($user->data, 'user');
                    if ($submit) {
                        if (check_form_key('ucp_avatar')) {
                            $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', ''));
                            if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) {
                                $driver = $phpbb_avatar_manager->get_driver($driver_name);
                                $result = $driver->process_form($request, $template, $user, $avatar_data, $error);
                                if ($result && empty($error)) {
                                    // Success! Lets save the result in the database
                                    $result = array('user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height']);
                                    $sql = 'UPDATE ' . USERS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $result) . '
										WHERE user_id = ' . (int) $user->data['user_id'];
                                    $db->sql_query($sql);
                                    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);
                                }
                            }
                        } else {
                            $error[] = 'FORM_INVALID';
                        }
                    }
                    // Handle deletion of avatars
                    if ($request->is_set_post('avatar_delete')) {
                        if (!confirm_box(true)) {
                            confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array('avatar_delete' => true, 'i' => $id, 'mode' => $mode)));
                        } else {
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_');
                            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);
                        }
                    }
                    $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user->data['user_avatar_type']));
                    foreach ($avatar_drivers as $current_driver) {
                        $driver = $phpbb_avatar_manager->get_driver($current_driver);
                        $avatars_enabled = true;
                        $template->set_filenames(array('avatar' => $driver->get_template_name()));
                        if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) {
                            $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver);
                            $driver_upper = strtoupper($driver_name);
                            $template->assign_block_vars('avatar_drivers', array('L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar')));
                        }
                    }
                    // Replace "error" strings with their real, localised form
                    $error = $phpbb_avatar_manager->localize_errors($user, $error);
                }
                $avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true);
                $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'AVATAR' => $avatar, 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => phpbb_avatar_explanation_string(), 'S_AVATARS_ENABLED' => $config['allow_avatar'] && $avatars_enabled));
                break;
            case 'autologin_keys':
                add_form_key('ucp_autologin_keys');
                if ($submit) {
                    $keys = $request->variable('keys', array(''));
                    if (!check_form_key('ucp_autologin_keys')) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        if (!empty($keys)) {
                            foreach ($keys as $key => $id) {
                                $keys[$key] = $db->sql_like_expression($id . $db->get_any_char());
                            }
                            $sql_where = '(key_id ' . implode(' OR key_id ', $keys) . ')';
                            $sql = 'DELETE FROM ' . SESSIONS_KEYS_TABLE . '
								WHERE user_id = ' . (int) $user->data['user_id'] . '
								AND ' . $sql_where;
                            $db->sql_query($sql);
                            meta_refresh(3, $this->u_action);
                            $message = $user->lang['AUTOLOGIN_SESSION_KEYS_DELETED'] . '<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 = array_map(array($user, 'lang'), $error);
                }
                $sql = 'SELECT key_id, last_ip, last_login
					FROM ' . SESSIONS_KEYS_TABLE . '
					WHERE user_id = ' . (int) $user->data['user_id'] . '
					ORDER BY last_login ASC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('sessions', array('KEY' => substr($row['key_id'], 0, 8), 'IP' => $row['last_ip'], 'LOGIN_TIME' => $user->format_date($row['last_login'])));
                }
                $db->sql_freeresult($result);
                break;
        }
        $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', '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);
    }
Exemplo n.º 24
0
/**
* Compose private message
* Called from ucp_pm with mode == 'compose'
*/
function compose_pm($id, $mode, $action)
{
	global $template, $db, $auth, $user;
	global $phpbb_root_path, $phpEx, $config;

	include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
	include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
	include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

	if (!$action)
	{
		$action = 'post';
	}
	add_form_key('ucp_pm_compose');

	// Grab only parameters needed here
	$to_user_id		= request_var('u', 0);
	$to_group_id	= request_var('g', 0);
	$msg_id			= request_var('p', 0);
	$draft_id		= request_var('d', 0);
	$lastclick		= request_var('lastclick', 0);

	// Do NOT use request_var or specialchars here
	$address_list	= isset($_REQUEST['address_list']) ? $_REQUEST['address_list'] : array();

	$submit		= (isset($_POST['post'])) ? true : false;
	$preview	= (isset($_POST['preview'])) ? true : false;
	$save		= (isset($_POST['save'])) ? true : false;
	$load		= (isset($_POST['load'])) ? true : false;
	$cancel		= (isset($_POST['cancel']) && !isset($_POST['save'])) ? true : false;
	$delete		= (isset($_POST['delete'])) ? true : false;

	$remove_u	= (isset($_REQUEST['remove_u'])) ? true : false;
	$remove_g	= (isset($_REQUEST['remove_g'])) ? true : false;
	$add_to		= (isset($_REQUEST['add_to'])) ? true : false;
	$add_bcc	= (isset($_REQUEST['add_bcc'])) ? true : false;

	$refresh	= isset($_POST['add_file']) || isset($_POST['delete_file']) || $save || $load
		|| $remove_u || $remove_g || $add_to || $add_bcc;

	$action		= ($delete && !$preview && !$refresh && $submit) ? 'delete' : $action;
	$select_single = ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? false : true;

	$error = array();
	$current_time = time();

	// Was cancel pressed? If so then redirect to the appropriate page
	if ($cancel || ($current_time - $lastclick < 2 && $submit))
	{
		if ($msg_id)
		{
			redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
		}
		redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm'));
	}

	// Output PM_TO box if message composing
	if ($action != 'edit')
	{
		if ($config['allow_mass_pm'] && $auth->acl_get('u_masspm'))
		{
			$sql = 'SELECT g.group_id, g.group_name, g.group_type
				FROM ' . GROUPS_TABLE . ' g';

			if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
			{
				$sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
			}

			$sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';

			$sql .= 'g.group_receive_pm = 1
				ORDER BY g.group_type DESC, g.group_name ASC';
			$result = $db->sql_query($sql);

			$group_options = '';
			while ($row = $db->sql_fetchrow($result))
			{
				$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);
		}

		$template->assign_vars(array(
			'S_SHOW_PM_BOX'		=> true,
			'S_ALLOW_MASS_PM'	=> ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? true : false,
			'S_GROUP_OPTIONS'	=> ($config['allow_mass_pm'] && $auth->acl_get('u_masspm')) ? $group_options : '',
			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=searchuser&amp;form=postform&amp;field=username_list&amp;select_single=$select_single"),
		));
	}

	$sql = '';

	// What is all this following SQL for? Well, we need to know
	// some basic information in all cases before we do anything.
	switch ($action)
	{
		case 'post':
			if (!$auth->acl_get('u_sendpm'))
			{
				trigger_error('NO_AUTH_SEND_MESSAGE');
			}
		break;

		case 'reply':
		case 'quote':
		case 'forward':
		case 'quotepost':
			if (!$msg_id)
			{
				trigger_error('NO_MESSAGE');
			}

			if (!$auth->acl_get('u_sendpm'))
			{
				trigger_error('NO_AUTH_SEND_MESSAGE');
			}

			if ($action == 'quotepost')
			{
				$sql = 'SELECT p.post_id as msg_id, p.forum_id, p.post_text as message_text, p.poster_id as author_id, p.post_time as message_time, p.bbcode_bitfield, p.bbcode_uid, p.enable_sig, p.enable_smilies, p.enable_magic_url, t.topic_title as message_subject, u.username as quote_username
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . " u
					WHERE p.post_id = $msg_id
						AND t.topic_id = p.topic_id
						AND u.user_id = p.poster_id";
			}
			else
			{
				$sql = 'SELECT t.folder_id, p.*, u.username as quote_username
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
					WHERE t.user_id = ' . $user->data['user_id'] . "
						AND p.author_id = u.user_id
						AND t.msg_id = p.msg_id
						AND p.msg_id = $msg_id";
			}
		break;

		case 'edit':
			if (!$msg_id)
			{
				trigger_error('NO_MESSAGE');
			}

			// check for outbox (not read) status, we do not allow editing if one user already having the message
			$sql = 'SELECT p.*, t.folder_id
				FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
				WHERE t.user_id = ' . $user->data['user_id'] . '
					AND t.folder_id = ' . PRIVMSGS_OUTBOX . "
					AND t.msg_id = $msg_id
					AND t.msg_id = p.msg_id";
		break;

		case 'delete':
			if (!$auth->acl_get('u_pm_delete'))
			{
				trigger_error('NO_AUTH_DELETE_MESSAGE');
			}

			if (!$msg_id)
			{
				trigger_error('NO_MESSAGE');
			}

			$sql = 'SELECT msg_id, pm_unread, pm_new, author_id, folder_id
				FROM ' . PRIVMSGS_TO_TABLE . '
				WHERE user_id = ' . $user->data['user_id'] . "
					AND msg_id = $msg_id";
		break;

		case 'smilies':
			generate_smilies('window', 0);
		break;

		default:
			trigger_error('NO_ACTION_MODE', E_USER_ERROR);
		break;
	}

	if ($action == 'forward' && (!$config['forward_pm'] || !$auth->acl_get('u_pm_forward')))
	{
		trigger_error('NO_AUTH_FORWARD_MESSAGE');
	}

	if ($action == 'edit' && !$auth->acl_get('u_pm_edit'))
	{
		trigger_error('NO_AUTH_EDIT_MESSAGE');
	}

	if ($sql)
	{
		$result = $db->sql_query($sql);
		$post = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		if (!$post)
		{
			// If editing it could be the recipient already read the message...
			if ($action == 'edit')
			{
				$sql = 'SELECT p.*, t.folder_id
					FROM ' . PRIVMSGS_TO_TABLE . ' t, ' . PRIVMSGS_TABLE . ' p
					WHERE t.user_id = ' . $user->data['user_id'] . "
						AND t.msg_id = $msg_id
						AND t.msg_id = p.msg_id";
				$result = $db->sql_query($sql);
				$post = $db->sql_fetchrow($result);
				$db->sql_freeresult($result);

				if ($post)
				{
					trigger_error('NO_EDIT_READ_MESSAGE');
				}
			}

			trigger_error('NO_MESSAGE');
		}

		if ($action == 'quotepost')
		{
			if (($post['forum_id'] && !$auth->acl_get('f_read', $post['forum_id'])) || (!$post['forum_id'] && !$auth->acl_getf_global('f_read')))
			{
				trigger_error('NOT_AUTHORISED');
			}
		}

		$msg_id			= (int) $post['msg_id'];
		$folder_id		= (isset($post['folder_id'])) ? $post['folder_id'] : 0;
		$message_text	= (isset($post['message_text'])) ? $post['message_text'] : '';

		if ((!$post['author_id'] || ($post['author_id'] == ANONYMOUS && $action != 'delete')) && $msg_id)
		{
			trigger_error('NO_AUTHOR');
		}

		if ($action == 'quotepost')
		{
			// Decode text for message display
			decode_message($message_text, $post['bbcode_uid']);
		}

		if ($action != 'delete')
		{
			$enable_urls = $post['enable_magic_url'];
			$enable_sig = (isset($post['enable_sig'])) ? $post['enable_sig'] : 0;

			$message_attachment = (isset($post['message_attachment'])) ? $post['message_attachment'] : 0;
			$message_subject = $post['message_subject'];
			$message_time = $post['message_time'];
			$bbcode_uid = $post['bbcode_uid'];

			$quote_username = (isset($post['quote_username'])) ? $post['quote_username'] : '';
			$icon_id = (isset($post['icon_id'])) ? $post['icon_id'] : 0;

			if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !sizeof($address_list) && !$refresh && !$submit && !$preview)
			{
				$address_list = array('u' => array($post['author_id'] => 'to'));
			}
			else if ($action == 'edit' && !sizeof($address_list) && !$refresh && !$submit && !$preview)
			{
				// Rebuild TO and BCC Header
				$address_list = rebuild_header(array('to' => $post['to_address'], 'bcc' => $post['bcc_address']));
			}

			if ($action == 'quotepost')
			{
				$check_value = 0;
			}
			else
			{
				$check_value = (($post['enable_bbcode']+1) << 8) + (($post['enable_smilies']+1) << 4) + (($enable_urls+1) << 2) + (($post['enable_sig']+1) << 1);
			}
		}
	}
	else
	{
		$message_attachment = 0;
		$message_text = $message_subject = '';

		if ($to_user_id && $action == 'post')
		{
			$address_list['u'][$to_user_id] = 'to';
		}
		else if ($to_group_id && $action == 'post')
		{
			$address_list['g'][$to_group_id] = 'to';
		}
		$check_value = 0;
	}

	if (($to_group_id || isset($address_list['g'])) && (!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')))
	{
		trigger_error('NO_AUTH_GROUP_MESSAGE');
	}

	if ($action == 'edit' && !$refresh && !$preview && !$submit)
	{
		if (!($message_time > time() - ($config['pm_edit_time'] * 60) || !$config['pm_edit_time']))
		{
			trigger_error('CANNOT_EDIT_MESSAGE_TIME');
		}
	}

	if ($action == 'post')
	{
		$template->assign_var('S_NEW_MESSAGE', true);
	}

	if (!isset($icon_id))
	{
		$icon_id = 0;
	}

	$message_parser = new parse_message();

	$message_parser->message = ($action == 'reply') ? '' : $message_text;
	unset($message_text);

	$s_action = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=$id&amp;mode=$mode&amp;action=$action", true, $user->session_id);
	$s_action .= ($msg_id) ? "&amp;p=$msg_id" : '';

	// Delete triggered ?
	if ($action == 'delete')
	{
		// Folder id has been determined by the SQL Statement
		// $folder_id = request_var('f', PRIVMSGS_NO_BOX);

		// Do we need to confirm ?
		if (confirm_box(true))
		{
			delete_pm($user->data['user_id'], $msg_id, $folder_id);

			// jump to next message in "history"? nope, not for the moment. But able to be included later.
			$meta_info = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;folder=$folder_id");
			$message = $user->lang['MESSAGE_DELETED'];

			meta_refresh(3, $meta_info);
			$message .= '<br /><br />' . sprintf($user->lang['RETURN_FOLDER'], '<a href="' . $meta_info . '">', '</a>');
			trigger_error($message);
		}
		else
		{
			$s_hidden_fields = array(
				'p'			=> $msg_id,
				'f'			=> $folder_id,
				'action'	=> 'delete'
			);

			// "{$phpbb_root_path}ucp.$phpEx?i=pm&amp;mode=compose"
			confirm_box(false, 'DELETE_MESSAGE', build_hidden_fields($s_hidden_fields));
		}

		redirect(append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;action=view_message&amp;p=' . $msg_id));
	}

	// Handle User/Group adding/removing
	handle_message_list_actions($address_list, $error, $remove_u, $remove_g, $add_to, $add_bcc);

	// Check for too many recipients
	if ((!$config['allow_mass_pm'] || !$auth->acl_get('u_masspm')) && num_recipients($address_list) > 1)
	{
		$address_list = get_recipient_pos($address_list, 1);
		$error[] = $user->lang['TOO_MANY_RECIPIENTS'];
	}

	// Always check if the submitted attachment data is valid and belongs to the user.
	// Further down (especially in submit_post()) we do not check this again.
	$message_parser->get_submitted_attachment_data();

	if ($message_attachment && !$submit && !$refresh && !$preview && $action == 'edit')
	{
		// Do not change to SELECT *
		$sql = 'SELECT attach_id, is_orphan, attach_comment, real_filename
			FROM ' . ATTACHMENTS_TABLE . "
			WHERE post_msg_id = $msg_id
				AND in_message = 1
				AND is_orphan = 0
			ORDER BY filetime DESC";
		$result = $db->sql_query($sql);
		$message_parser->attachment_data = array_merge($message_parser->attachment_data, $db->sql_fetchrowset($result));
		$db->sql_freeresult($result);
	}

	if (!in_array($action, array('quote', 'edit', 'delete', 'forward')))
	{
		$enable_sig		= ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig') && $user->optionget('attachsig'));
		$enable_smilies	= ($config['allow_smilies'] && $auth->acl_get('u_pm_smilies') && $user->optionget('smilies'));
		$enable_bbcode	= ($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode') && $user->optionget('bbcode'));
		$enable_urls	= true;
	}

	$enable_magic_url = $drafts = false;

	// User own some drafts?
	if ($auth->acl_get('u_savedrafts') && $action != 'delete')
	{
		$sql = 'SELECT draft_id
			FROM ' . DRAFTS_TABLE . '
			WHERE forum_id = 0
				AND topic_id = 0
				AND user_id = ' . $user->data['user_id'] .
				(($draft_id) ? " AND draft_id <> $draft_id" : '');
		$result = $db->sql_query_limit($sql, 1);
		$row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		if ($row)
		{
			$drafts = true;
		}
	}

	if ($action == 'edit')
	{
		$message_parser->bbcode_uid = $bbcode_uid;
	}

	$bbcode_status	= ($config['allow_bbcode'] && $config['auth_bbcode_pm'] && $auth->acl_get('u_pm_bbcode')) ? true : false;
	$smilies_status	= ($config['allow_smilies'] && $config['auth_smilies_pm'] && $auth->acl_get('u_pm_smilies')) ? true : false;
	$img_status		= ($config['auth_img_pm'] && $auth->acl_get('u_pm_img')) ? true : false;
	$flash_status	= ($config['auth_flash_pm'] && $auth->acl_get('u_pm_flash')) ? true : false;
	$url_status		= ($config['allow_post_links']) ? true : false;

	// Save Draft
	if ($save && $auth->acl_get('u_savedrafts'))
	{
		$subject = utf8_normalize_nfc(request_var('subject', '', true));
		$subject = (!$subject && $action != 'post') ? $user->lang['NEW_MESSAGE'] : $subject;
		$message = utf8_normalize_nfc(request_var('message', '', true));

		if ($subject && $message)
		{
			if (confirm_box(true))
			{
				$sql = 'INSERT INTO ' . DRAFTS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
					'user_id'		=> $user->data['user_id'],
					'topic_id'		=> 0,
					'forum_id'		=> 0,
					'save_time'		=> $current_time,
					'draft_subject'	=> $subject,
					'draft_message'	=> $message)
				);
				$db->sql_query($sql);

				$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;mode=$mode");

				meta_refresh(3, $redirect_url);
				$message = $user->lang['DRAFT_SAVED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $redirect_url . '">', '</a>');

				trigger_error($message);
			}
			else
			{
				$s_hidden_fields = build_hidden_fields(array(
					'mode'		=> $mode,
					'action'	=> $action,
					'save'		=> true,
					'subject'	=> $subject,
					'message'	=> $message,
					'u'			=> $to_user_id,
					'g'			=> $to_group_id,
					'p'			=> $msg_id)
				);

				confirm_box(false, 'SAVE_DRAFT', $s_hidden_fields);
			}
		}
		else
		{
			if (!$subject || !utf8_clean_string($subject))
			{
				$error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
			}

			if (!$message)
			{
				$error[] = $user->lang['TOO_FEW_CHARS'];
			}
		}

		unset($subject, $message);
	}

	// Load Draft
	if ($draft_id && $auth->acl_get('u_savedrafts'))
	{
		$sql = 'SELECT draft_subject, draft_message
			FROM ' . DRAFTS_TABLE . "
			WHERE draft_id = $draft_id
				AND topic_id = 0
				AND forum_id = 0
				AND user_id = " . $user->data['user_id'];
		$result = $db->sql_query_limit($sql, 1);

		if ($row = $db->sql_fetchrow($result))
		{
			$message_parser->message = $row['draft_message'];
			$message_subject = $row['draft_subject'];

			$template->assign_var('S_DRAFT_LOADED', true);
		}
		else
		{
			$draft_id = 0;
		}
		$db->sql_freeresult($result);
	}

	// Load Drafts
	if ($load && $drafts)
	{
		load_drafts(0, 0, $id);
	}

	if ($submit || $preview || $refresh)
	{
		if (!check_form_key('ucp_pm_compose'))
		{
			$error[] = $user->lang['FORM_INVALID'];
		}
		$subject = utf8_normalize_nfc(request_var('subject', '', true));
		$message_parser->message = utf8_normalize_nfc(request_var('message', '', true));

		$icon_id			= request_var('icon', 0);

		$enable_bbcode 		= (!$bbcode_status || isset($_POST['disable_bbcode'])) ? false : true;
		$enable_smilies		= (!$smilies_status || isset($_POST['disable_smilies'])) ? false : true;
		$enable_urls 		= (isset($_POST['disable_magic_url'])) ? 0 : 1;
		$enable_sig			= (!$config['allow_sig'] ||!$config['allow_sig_pm']) ? false : ((isset($_POST['attach_sig'])) ? true : false);

		if ($submit)
		{
			$status_switch	= (($enable_bbcode+1) << 8) + (($enable_smilies+1) << 4) + (($enable_urls+1) << 2) + (($enable_sig+1) << 1);
			$status_switch = ($status_switch != $check_value);
		}
		else
		{
			$status_switch = 1;
		}

		// Parse Attachments - before checksum is calculated
		$message_parser->parse_attachments('fileupload', $action, 0, $submit, $preview, $refresh, true);

		if (sizeof($message_parser->warn_msg) && !($remove_u || $remove_g || $add_to || $add_bcc))
		{
			$error[] = implode('<br />', $message_parser->warn_msg);
			$message_parser->warn_msg = array();
		}

		// Parse message
		$message_parser->parse($enable_bbcode, ($config['allow_post_links']) ? $enable_urls : false, $enable_smilies, $img_status, $flash_status, true, $config['allow_post_links']);

		// On a refresh we do not care about message parsing errors
		if (sizeof($message_parser->warn_msg) && !$refresh)
		{
			$error[] = implode('<br />', $message_parser->warn_msg);
		}

		if ($action != 'edit' && !$preview && !$refresh && $config['flood_interval'] && !$auth->acl_get('u_ignoreflood'))
		{
			// Flood check
			$last_post_time = $user->data['user_lastpost_time'];

			if ($last_post_time)
			{
				if ($last_post_time && ($current_time - $last_post_time) < intval($config['flood_interval']))
				{
					$error[] = $user->lang['FLOOD_ERROR'];
				}
			}
		}

		// Subject defined
		if ($submit)
		{
			if (!$subject || !utf8_clean_string($subject))
			{
				$error[] = $user->lang['EMPTY_MESSAGE_SUBJECT'];
			}

			if (!sizeof($address_list))
			{
				$error[] = $user->lang['NO_RECIPIENT'];
			}
		}

		// Store message, sync counters
		if (!sizeof($error) && $submit)
		{
			$pm_data = array(
				'msg_id'				=> (int) $msg_id,
				'from_user_id'			=> $user->data['user_id'],
				'from_user_ip'			=> $user->ip,
				'from_username'			=> $user->data['username'],
				'reply_from_root_level'	=> (isset($post['root_level'])) ? (int) $post['root_level'] : 0,
				'reply_from_msg_id'		=> (int) $msg_id,
				'icon_id'				=> (int) $icon_id,
				'enable_sig'			=> (bool) $enable_sig,
				'enable_bbcode'			=> (bool) $enable_bbcode,
				'enable_smilies'		=> (bool) $enable_smilies,
				'enable_urls'			=> (bool) $enable_urls,
				'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
				'bbcode_uid'			=> $message_parser->bbcode_uid,
				'message'				=> $message_parser->message,
				'attachment_data'		=> $message_parser->attachment_data,
				'filename_data'			=> $message_parser->filename_data,
				'address_list'			=> $address_list
			);
			unset($message_parser);

			// ((!$message_subject) ? $subject : $message_subject)
			$msg_id = submit_pm($action, $subject, $pm_data);

			$return_message_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;mode=view&amp;p=' . $msg_id);
			$return_folder_url = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&amp;folder=outbox');
			meta_refresh(3, $return_message_url);

			$message = $user->lang['MESSAGE_STORED'] . '<br /><br />' . sprintf($user->lang['VIEW_PRIVATE_MESSAGE'], '<a href="' . $return_message_url . '">', '</a>') . '<br /><br />' . sprintf($user->lang['CLICK_RETURN_FOLDER'], '<a href="' . $return_folder_url . '">', '</a>', $user->lang['PM_OUTBOX']);
			trigger_error($message);
		}

		$message_subject = $subject;
	}

	// Preview
	if (!sizeof($error) && $preview)
	{
		$user->add_lang('viewtopic');
		$preview_message = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);

		$preview_signature = $user->data['user_sig'];
		$preview_signature_uid = $user->data['user_sig_bbcode_uid'];
		$preview_signature_bitfield = $user->data['user_sig_bbcode_bitfield'];

		// Signature
		if ($enable_sig && $config['allow_sig'] && $preview_signature)
		{
			$parse_sig = new parse_message($preview_signature);
			$parse_sig->bbcode_uid = $preview_signature_uid;
			$parse_sig->bbcode_bitfield = $preview_signature_bitfield;

			$parse_sig->format_display($enable_bbcode, $enable_urls, $enable_smilies);
			$preview_signature = $parse_sig->message;
			unset($parse_sig);
		}
		else
		{
			$preview_signature = '';
		}

		// Attachment Preview
		if (sizeof($message_parser->attachment_data))
		{
			$template->assign_var('S_HAS_ATTACHMENTS', true);

			$update_count = array();
			$attachment_data = $message_parser->attachment_data;

			parse_attachments(false, $preview_message, $attachment_data, $update_count, true);

			foreach ($attachment_data as $i => $attachment)
			{
				$template->assign_block_vars('attachment', array(
					'DISPLAY_ATTACHMENT'	=> $attachment)
				);
			}
			unset($attachment_data);
		}

		$preview_subject = censor_text($subject);

		if (!sizeof($error))
		{
			$template->assign_vars(array(
				'PREVIEW_SUBJECT'		=> $preview_subject,
				'PREVIEW_MESSAGE'		=> $preview_message,
				'PREVIEW_SIGNATURE'		=> $preview_signature,

				'S_DISPLAY_PREVIEW'		=> true)
			);
		}
		unset($message_text);
	}

	// Decode text for message display
	$bbcode_uid = (($action == 'quote' || $action == 'forward') && !$preview && !$refresh && !sizeof($error)) ? $bbcode_uid : $message_parser->bbcode_uid;

	$message_parser->decode_message($bbcode_uid);

	if (($action == 'quote' || $action == 'quotepost') && !$preview && !$refresh && !$submit)
	{
		if ($action == 'quotepost')
		{
			$post_id = request_var('p', 0);
			if ($config['allow_post_links'])
			{
				$message_link = "[url=" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id}]{$user->lang['SUBJECT']}: {$message_subject}[/url]\n\n";
			}
			else
			{
				$message_link = $user->lang['SUBJECT'] . ': ' . $message_subject . " (" . generate_board_url() . "/viewtopic.$phpEx?p={$post_id}#p{$post_id})\n\n";
			}
		}
		else
		{
			$message_link = '';
		}
		$message_parser->message = $message_link . '[quote=&quot;' . $quote_username . '&quot;]' . censor_text(trim($message_parser->message)) . "[/quote]\n";
	}

	if (($action == 'reply' || $action == 'quote' || $action == 'quotepost') && !$preview && !$refresh)
	{
		$message_subject = ((!preg_match('/^Re:/', $message_subject)) ? 'Re: ' : '') . censor_text($message_subject);
	}

	if ($action == 'forward' && !$preview && !$refresh && !$submit)
	{
		$fwd_to_field = write_pm_addresses(array('to' => $post['to_address']), 0, true);

		if ($config['allow_post_links'])
		{
			$quote_username_text = '[url=' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&amp;u={$post['author_id']}]{$quote_username}[/url]";
		}
		else
		{
			$quote_username_text = $quote_username . ' (' . generate_board_url() . "/memberlist.$phpEx?mode=viewprofile&amp;u={$post['author_id']})";
		}

		$forward_text = array();
		$forward_text[] = $user->lang['FWD_ORIGINAL_MESSAGE'];
		$forward_text[] = sprintf($user->lang['FWD_SUBJECT'], censor_text($message_subject));
		$forward_text[] = sprintf($user->lang['FWD_DATE'], $user->format_date($message_time));
		$forward_text[] = sprintf($user->lang['FWD_FROM'], $quote_username_text);
		$forward_text[] = sprintf($user->lang['FWD_TO'], implode(', ', $fwd_to_field['to']));

		$message_parser->message = implode("\n", $forward_text) . "\n\n[quote=\"{$quote_username}\"]\n" . censor_text(trim($message_parser->message)) . "\n[/quote]";
		$message_subject = ((!preg_match('/^Fwd:/', $message_subject)) ? 'Fwd: ' : '') . censor_text($message_subject);
	}

	$attachment_data = $message_parser->attachment_data;
	$filename_data = $message_parser->filename_data;
	$message_text = $message_parser->message;
	unset($message_parser);

	// MAIN PM PAGE BEGINS HERE

	// Generate smiley listing
	generate_smilies('inline', 0);

	// Generate PM Icons
	$s_pm_icons = false;
	if ($config['enable_pm_icons'])
	{
		$s_pm_icons = posting_gen_topic_icons($action, $icon_id);
	}

	// Generate inline attachment select box
	posting_gen_inline_attachments($attachment_data);

	// Build address list for display
	// array('u' => array($author_id => 'to'));
	if (sizeof($address_list))
	{
		// Get Usernames and Group Names
		$result = array();
		if (!empty($address_list['u']))
		{
			$sql = 'SELECT user_id as id, username as name, user_colour as colour
				FROM ' . USERS_TABLE . '
				WHERE ' . $db->sql_in_set('user_id', array_map('intval', array_keys($address_list['u']))) . '
				ORDER BY username_clean ASC';
			$result['u'] = $db->sql_query($sql);
		}

		if (!empty($address_list['g']))
		{
			$sql = 'SELECT g.group_id AS id, g.group_name AS name, g.group_colour AS colour, g.group_type
				FROM ' . GROUPS_TABLE . ' g';

			if (!$auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
			{
				$sql .= ' LEFT JOIN ' . USER_GROUP_TABLE . ' ug
					ON (
						g.group_id = ug.group_id
						AND ug.user_id = ' . $user->data['user_id'] . '
						AND ug.user_pending = 0
					)
					WHERE (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')';
			}

			$sql .= ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? ' WHERE ' : ' AND ';

			$sql .= 'g.group_receive_pm = 1
				AND ' . $db->sql_in_set('g.group_id', array_map('intval', array_keys($address_list['g']))) . '
				ORDER BY g.group_name ASC';

			$result['g'] = $db->sql_query($sql);
		}

		$u = $g = array();
		$_types = array('u', 'g');
		foreach ($_types as $type)
		{
			if (isset($result[$type]) && $result[$type])
			{
				while ($row = $db->sql_fetchrow($result[$type]))
				{
					if ($type == 'g')
					{
						$row['name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['name']] : $row['name'];
					}

					${$type}[$row['id']] = array('name' => $row['name'], 'colour' => $row['colour']);
				}
				$db->sql_freeresult($result[$type]);
			}
		}

		// Now Build the address list
		$plain_address_field = '';
		foreach ($address_list as $type => $adr_ary)
		{
			foreach ($adr_ary as $id => $field)
			{
				if (!isset(${$type}[$id]))
				{
					unset($address_list[$type][$id]);
					continue;
				}

				$field = ($field == 'to') ? 'to' : 'bcc';
				$type = ($type == 'u') ? 'u' : 'g';
				$id = (int) $id;

				$tpl_ary = array(
					'IS_GROUP'	=> ($type == 'g') ? true : false,
					'IS_USER'	=> ($type == 'u') ? true : false,
					'UG_ID'		=> $id,
					'NAME'		=> ${$type}[$id]['name'],
					'COLOUR'	=> (${$type}[$id]['colour']) ? '#' . ${$type}[$id]['colour'] : '',
					'TYPE'		=> $type,
				);

				if ($type == 'u')
				{
					$tpl_ary = array_merge($tpl_ary, array(
						'U_VIEW'		=> get_username_string('profile', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
						'NAME_FULL'		=> get_username_string('full', $id, ${$type}[$id]['name'], ${$type}[$id]['colour']),
					));
				}
				else
				{
					$tpl_ary = array_merge($tpl_ary, array(
						'U_VIEW'		=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $id),
					));
				}

				$template->assign_block_vars($field . '_recipient', $tpl_ary);
			}
		}
	}

	// Build hidden address list
	$s_hidden_address_field = '';
	foreach ($address_list as $type => $adr_ary)
	{
		foreach ($adr_ary as $id => $field)
		{
			$s_hidden_address_field .= '<input type="hidden" name="address_list[' . (($type == 'u') ? 'u' : 'g') . '][' . (int) $id . ']" value="' . (($field == 'to') ? 'to' : 'bcc') . '" />';
		}
	}

	$bbcode_checked		= (isset($enable_bbcode)) ? !$enable_bbcode : (($config['allow_bbcode'] && $auth->acl_get('u_pm_bbcode')) ? !$user->optionget('bbcode') : 1);
	$smilies_checked	= (isset($enable_smilies)) ? !$enable_smilies : (($config['allow_smilies'] && $auth->acl_get('u_pm_smilies')) ? !$user->optionget('smilies') : 1);
	$urls_checked		= (isset($enable_urls)) ? !$enable_urls : 0;
	$sig_checked		= $enable_sig;

	switch ($action)
	{
		case 'post':
			$page_title = $user->lang['POST_NEW_PM'];
		break;

		case 'quote':
			$page_title = $user->lang['POST_QUOTE_PM'];
		break;

		case 'quotepost':
			$page_title = $user->lang['POST_PM_POST'];
		break;

		case 'reply':
			$page_title = $user->lang['POST_REPLY_PM'];
		break;

		case 'edit':
			$page_title = $user->lang['POST_EDIT_PM'];
		break;

		case 'forward':
			$page_title = $user->lang['POST_FORWARD_PM'];
		break;

		default:
			trigger_error('NO_ACTION_MODE', E_USER_ERROR);
		break;
	}

	$s_hidden_fields = '<input type="hidden" name="lastclick" value="' . $current_time . '" />';
	$s_hidden_fields .= (isset($check_value)) ? '<input type="hidden" name="status_switch" value="' . $check_value . '" />' : '';
	$s_hidden_fields .= ($draft_id || isset($_REQUEST['draft_loaded'])) ? '<input type="hidden" name="draft_loaded" value="' . ((isset($_REQUEST['draft_loaded'])) ? intval($_REQUEST['draft_loaded']) : $draft_id) . '" />' : '';

	$form_enctype = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || @ini_get('file_uploads') == '0' || !$config['allow_pm_attach'] || !$auth->acl_get('u_pm_attach')) ? '' : ' enctype="multipart/form-data"';

	// Start assigning vars for main posting page ...
	$template->assign_vars(array(
		'L_POST_A'					=> $page_title,
		'L_ICON'					=> $user->lang['PM_ICON'],
		'L_MESSAGE_BODY_EXPLAIN'	=> (intval($config['max_post_chars'])) ? sprintf($user->lang['MESSAGE_BODY_EXPLAIN'], intval($config['max_post_chars'])) : '',

		'SUBJECT'				=> (isset($message_subject)) ? $message_subject : '',
		'MESSAGE'				=> $message_text,
		'BBCODE_STATUS'			=> ($bbcode_status) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
		'IMG_STATUS'			=> ($img_status) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
		'FLASH_STATUS'			=> ($flash_status) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
		'SMILIES_STATUS'		=> ($smilies_status) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
		'URL_STATUS'			=> ($url_status) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],
		'MINI_POST_IMG'			=> $user->img('icon_post_target', $user->lang['PM']),
		'ERROR'					=> (sizeof($error)) ? implode('<br />', $error) : '',

		'S_COMPOSE_PM'			=> true,
		'S_EDIT_POST'			=> ($action == 'edit'),
		'S_SHOW_PM_ICONS'		=> $s_pm_icons,
		'S_BBCODE_ALLOWED'		=> $bbcode_status,
		'S_BBCODE_CHECKED'		=> ($bbcode_checked) ? ' checked="checked"' : '',
		'S_SMILIES_ALLOWED'		=> $smilies_status,
		'S_SMILIES_CHECKED'		=> ($smilies_checked) ? ' checked="checked"' : '',
		'S_SIG_ALLOWED'			=> ($config['allow_sig'] && $config['allow_sig_pm'] && $auth->acl_get('u_sig')),
		'S_SIGNATURE_CHECKED'	=> ($sig_checked) ? ' checked="checked"' : '',
		'S_LINKS_ALLOWED'		=> $url_status,
		'S_MAGIC_URL_CHECKED'	=> ($urls_checked) ? ' checked="checked"' : '',
		'S_SAVE_ALLOWED'		=> ($auth->acl_get('u_savedrafts') && $action != 'edit') ? true : false,
		'S_HAS_DRAFTS'			=> ($auth->acl_get('u_savedrafts') && $drafts),
		'S_FORM_ENCTYPE'		=> $form_enctype,

		'S_BBCODE_IMG'			=> $img_status,
		'S_BBCODE_FLASH'		=> $flash_status,
		'S_BBCODE_QUOTE'		=> true,
		'S_BBCODE_URL'			=> $url_status,

		'S_POST_ACTION'				=> $s_action,
		'S_HIDDEN_ADDRESS_FIELD'	=> $s_hidden_address_field,
		'S_HIDDEN_FIELDS'			=> $s_hidden_fields,

		'S_CLOSE_PROGRESS_WINDOW'	=> isset($_POST['add_file']),
		'U_PROGRESS_BAR'			=> append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&amp;mode=popup'),
		'UA_PROGRESS_BAR'			=> addslashes(append_sid("{$phpbb_root_path}posting.$phpEx", 'f=0&amp;mode=popup')),
	));

	// Build custom bbcodes array
	display_custom_bbcodes();

	// Attachment entry
	if ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype)
	{
		posting_gen_attachment_entry($attachment_data, $filename_data);
	}

	// Message History
	if ($action == 'reply' || $action == 'quote' || $action == 'forward')
	{
		if (message_history($msg_id, $user->data['user_id'], $post, array(), true))
		{
			$template->assign_var('S_DISPLAY_HISTORY', true);
		}
	}
}
Exemplo n.º 25
0
 /**
  * Display the message box
  */
 public function display()
 {
     $for_edit = $this->post_object->generate_text_for_edit();
     // Initialize our post options class
     $post_options = new post_options();
     $post_options->set_auth($this->auth['bbcode'], $this->auth['smilies'], true, true, true);
     $post_options->set_status($for_edit['allow_bbcode'], $for_edit['allow_smilies'], $for_edit['allow_urls']);
     // Setup the attachments!
     $this->setup_attachments();
     if ($this->auth['polls']) {
         $this->posting_panels['poll-panel'] = 'POLL';
     }
     // Add the forum key
     add_form_key($this->settings['form_name']);
     // Generate smiley listing
     if ($post_options->get_status('smilies')) {
         phpbb::_include('functions_posting', 'generate_smilies');
         generate_smilies('inline', false);
     }
     // Build custom bbcodes array
     if ($post_options->get_status('bbcode')) {
         phpbb::_include('functions_display', 'display_custom_bbcodes');
         display_custom_bbcodes();
     }
     // Display the Captcha if required
     if ($this->settings['display_captcha']) {
         phpbb::_include('captcha/captcha_factory', false, 'phpbb_captcha_factory');
         $captcha =& phpbb_captcha_factory::get_instance(phpbb::$config['captcha_plugin']);
         $captcha->init(CONFIRM_POST);
         if ($captcha->validate($this->request_data()) !== false) {
             phpbb::reset_template();
             // Parse the captcha template
             phpbb::$template->set_filenames(array('captcha' => $captcha->get_template()));
             // Correct confirm image link
             phpbb::$template->assign_var('CONFIRM_IMAGE_LINK', phpbb::append_sid('ucp', 'mode=confirm&amp;confirm_id=' . $captcha->confirm_id . '&amp;type=' . $captcha->type));
             phpbb::$template->assign_display('captcha', 'CAPTCHA', false);
             titania::set_custom_template();
         }
         $this->s_hidden_fields = array_merge($this->s_hidden_fields, $captcha->get_hidden_fields());
     }
     $post_options->set_in_template();
     // Save the opened panel to show again
     $default_panel = request_var('open_panel', 'options-panel');
     $default_panel = isset($this->posting_panels[$default_panel]) ? $default_panel : 'options-panel';
     phpbb::$template->assign_vars(array('ACCESS_OPTIONS' => titania_access_select(isset($for_edit['access']) ? $for_edit['access'] : TITANIA_ACCESS_PUBLIC), 'EDIT_REASON' => isset($for_edit['edit_reason']) ? $for_edit['edit_reason'] : '', 'POSTING_FORM_NAME' => $this->settings['form_name'], 'POSTING_TEXT_NAME' => $this->settings['text_name'], 'POSTING_SUBJECT_NAME' => $this->settings['subject_name'], 'POSTING_PANELS_DEFAULT' => $default_panel, 'POSTING_TEXT' => $this->settings['text_default_override'] !== false ? $this->settings['text_default_override'] : $for_edit['text'], 'SUBJECT' => $this->settings['subject_default_override'] !== false ? $this->settings['subject_default_override'] : (isset($for_edit['subject']) ? $for_edit['subject'] : ''), 'S_ENHANCED_EDITOR' => phpbb::$user->data['titania_enhanced_editor'], 'S_DISPLAY_ERROR' => $this->settings['display_error'], 'S_DISPLAY_SUBJECT' => $this->settings['display_subject'], 'S_STICKY_TOPIC_ALLOWED' => $this->auth['sticky_topic'], 'S_STICKY_TOPIC_CHECKED' => isset($for_edit['topic_sticky']) ? $for_edit['topic_sticky'] : false, 'S_LOCK_TOPIC_ALLOWED' => $this->auth['lock_topic'], 'S_LOCK_TOPIC_CHECKED' => isset($for_edit['topic_locked']) ? $for_edit['topic_locked'] : false, 'S_LOCK_POST_ALLOWED' => $this->auth['lock'], 'S_LOCK_POST_CHECKED' => isset($for_edit['locked']) ? $for_edit['locked'] : false, 'S_EDIT_REASON' => $this->settings['display_edit_reason'], 'S_HIDDEN_FIELDS' => build_hidden_fields($this->s_hidden_fields)));
     if ($this->attachments) {
         phpbb::$template->assign_vars(array('UPLOADER' => $this->attachments->parse_uploader($this->settings['attachment_tpl']), 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"'));
     }
     $this->display_panels();
 }
Exemplo n.º 26
0
 function main($id, $mode)
 {
     global $config, $request, $template, $user, $phpbb_container;
     global $phpbb_root_path, $phpEx;
     $config_text = $phpbb_container->get('config_text');
     $this->page_title = 'ACP_POSTS_MERGING';
     $this->tpl_name = 'acp_posts_merging';
     $submit = isset($_POST['submit']) ? true : false;
     $preview = isset($_POST['preview']) ? true : false;
     $form_key = 'config_posts_merging';
     add_form_key($form_key);
     $display_vars = array('title' => 'ACP_POSTS_MERGING', 'vars' => array('legend1' => 'GENERAL_OPTIONS', 'merge_interval' => array('lang' => 'MERGE_INTERVAL', 'validate' => 'int:0', 'type' => 'number:0:9999', 'explain' => true, 'append' => ' ' . $user->lang['HOURS']), 'merge_no_forums' => array('lang' => 'MERGE_NO_FORUMS', 'validate' => 'string', 'type' => 'custom', 'method' => 'select_merge_no_forums', 'explain' => true), 'merge_no_topics' => array('lang' => 'MERGE_NO_TOPICS', 'validate' => 'string', 'type' => 'text:5:255', 'explain' => true), 'legend2' => 'MERGE_SEPARATOR'));
     if (isset($display_vars['lang'])) {
         $user->add_lang($display_vars['lang']);
     }
     $user->add_lang(array('posting'));
     $this->new_config = $config;
     $cfg_array = isset($_REQUEST['config']) ? $request->variable('config', array('' => ''), true) : $this->new_config;
     $cfg_array['merge_no_forums'] = $submit ? implode(',', $request->variable('merge_no_forums', array('' => ''))) : $cfg_array['merge_no_forums'];
     $posts_merging_separator_text = $request->variable('posts_merging_separator_text', '', true);
     $error = array();
     // We validate the complete config if wished
     validate_config_vars($display_vars['vars'], $cfg_array, $error);
     if ($submit && !check_form_key($form_key)) {
         $error[] = $user->lang['FORM_INVALID'];
     }
     // Do not write values if there is an error
     if (sizeof($error)) {
         $submit = false;
     }
     // We go through the display_vars to make sure no one is trying to set variables he/she is not allowed to...
     foreach ($display_vars['vars'] as $config_name => $null) {
         if (!isset($cfg_array[$config_name]) || strpos($config_name, 'legend') !== false) {
             continue;
         }
         $this->new_config[$config_name] = $config_value = $cfg_array[$config_name];
         if ($submit) {
             $config->set($config_name, $config_value);
         }
     }
     if ($submit) {
         $config_text->set('posts_merging_separator_text', $posts_merging_separator_text);
         trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
     }
     // Output relevant page
     foreach ($display_vars['vars'] as $config_key => $vars) {
         if (!is_array($vars) && strpos($config_key, 'legend') === false) {
             continue;
         }
         if (strpos($config_key, 'legend') !== false) {
             $template->assign_block_vars('options', array('S_LEGEND' => true, 'LEGEND' => isset($user->lang[$vars]) ? $user->lang[$vars] : $vars));
             continue;
         }
         $type = explode(':', $vars['type']);
         $l_explain = '';
         if ($vars['explain'] && isset($vars['lang_explain'])) {
             $l_explain = isset($user->lang[$vars['lang_explain']]) ? $user->lang[$vars['lang_explain']] : $vars['lang_explain'];
         } else {
             if ($vars['explain']) {
                 $l_explain = isset($user->lang[$vars['lang'] . '_EXPLAIN']) ? $user->lang[$vars['lang'] . '_EXPLAIN'] : '';
             }
         }
         $content = build_cfg_template($type, $config_key, $this->new_config, $config_key, $vars);
         if (empty($content)) {
             continue;
         }
         $template->assign_block_vars('options', array('KEY' => $config_key, 'TITLE' => isset($user->lang[$vars['lang']]) ? $user->lang[$vars['lang']] : $vars['lang'], 'S_EXPLAIN' => $vars['explain'], 'TITLE_EXPLAIN' => $l_explain, 'CONTENT' => $content));
         unset($display_vars['vars'][$config_key]);
     }
     $posts_merging_separator_text = $posts_merging_separator_text ?: $config_text->get('posts_merging_separator_text');
     include_once $phpbb_root_path . 'includes/functions_display.' . $phpEx;
     /*
      * Constant preview
      */
     include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
     // Prepare message separator
     $user->add_lang_ext('rxu/PostsMerging', 'posts_merging');
     // Calculate the time interval
     $helper = $phpbb_container->get('rxu.PostsMerging.helper');
     $current_time = time();
     $interval = $helper->get_time_interval(strtotime('3 hours 17 minutes 56 seconds'), $current_time);
     $time = array();
     $time[] = $interval->h ? $user->lang('D_HOURS', $interval->h) : null;
     $time[] = $interval->i ? $user->lang('D_MINUTES', $interval->i) : null;
     $time[] = $interval->s ? $user->lang('D_SECONDS', $interval->s) : null;
     // Allow using language variables like {L_LANG_VAR}
     $posts_merging_separator_text_prewiew = preg_replace_callback('/{L_([A-Z0-9_]+)}/', function ($matches) {
         global $user;
         return $user->lang($matches[1]);
     }, $posts_merging_separator_text);
     // Eval linefeeds and generate the separator, time interval included
     $posts_merging_separator_text_prewiew = sprintf(str_replace('\\n', "\n", $posts_merging_separator_text_prewiew), implode(' ', $time));
     $message_parser = new \parse_message($posts_merging_separator_text_prewiew);
     // Allowing Quote BBCode
     $message_parser->parse(true, true, true, true, true, true, true, true);
     // Now parse it for displaying
     $separator_preview = $message_parser->format_display(true, true, true, false);
     unset($message_parser);
     $template->assign_vars(array('SEPARATOR_PREVIEW' => $separator_preview));
     /*
      * Constant preview end
      */
     $template->assign_vars(array('POSTS_MERGING_SEPARATOR_TEXT' => $posts_merging_separator_text, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, 'U_ACTION' => $this->u_action));
     // Assigning custom bbcodes
     display_custom_bbcodes();
 }
Exemplo n.º 27
0
    public function main($id, $mode)
    {
        /** @var \phpbb\request\request $request */
        /** @var \phpbb\log\log $phpbb_log */
        global $config, $db, $user, $template, $request, $phpbb_log;
        global $table_prefix, $phpbb_root_path, $phpEx;
        if (!function_exists('display_custom_bbcodes')) {
            include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
        }
        $user->add_lang('posting');
        $user->add_lang_ext('zoddo/postmodels', 'models_acp');
        // Set up general vars
        $action = $request->variable('action', '');
        $submit = $request->is_set_post('submit');
        $model_id = $request->variable('id', 0);
        $this->tpl_name = 'models_manage';
        $this->page_title = 'ACP_MODELS';
        $form_name = 'acp_models';
        add_form_key($form_name);
        $error = array();
        switch ($action) {
            case 'add':
            case 'edit':
                $model_row = array('model_title' => $request->variable('model_title', '', true), 'model_content' => $request->variable('model_content', '', true), 'model_auth' => $request->variable('model_auth', 0), 'model_pm' => $request->variable('model_pm', 0), 'model_lang' => $request->variable('model_lang', '', true));
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        $error[] = $user->lang['FORM_INVALID'];
                    }
                    // Model specified?
                    if (!$model_row['model_title'] || !$model_row['model_content'] || !$model_row['model_lang']) {
                        $error[] = $user->lang['NO_MODEL_INFO'];
                    }
                    $check_double = $action == 'add' ? true : false;
                    if ($action == 'edit') {
                        $sql = 'SELECT model_title
							FROM ' . $table_prefix . "models\n\t\t\t\t\t\t\tWHERE model_id = " . (int) $model_id;
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if ($row['model_title'] != $model_row['model_title']) {
                            $check_double = true;
                        }
                    }
                    // Check for same model if adding it...
                    if ($check_double) {
                        $sql = 'SELECT model_id
							FROM ' . $table_prefix . "models\n\t\t\t\t\t\t\tWHERE model_title = '" . $db->sql_escape($model_row['model_title']) . "'\n\t\t\t\t\t\t\t\tAND model_lang = '" . $db->sql_escape($model_row['model_lang']) . "'";
                        $result = $db->sql_query($sql);
                        $row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if ($row) {
                            $error[] = $user->lang['MODEL_ALREADY_EXIST'];
                        }
                    }
                    if (!sizeof($error)) {
                        // New model?
                        if ($action == 'add') {
                            $sql_ary = array('model_title' => (string) $model_row['model_title'], 'model_content' => (string) $model_row['model_content'], 'model_auth' => (int) $model_row['model_auth'], 'model_pm' => (int) $model_row['model_pm'], 'model_lang' => (string) $model_row['model_lang']);
                            $db->sql_query('INSERT INTO ' . $table_prefix . 'models ' . $db->sql_build_array('INSERT', $sql_ary));
                            $log = 'ADDED';
                        } else {
                            if ($model_id) {
                                $sql_ary = array('model_title' => (string) $model_row['model_title'], 'model_content' => (string) $model_row['model_content'], 'model_auth' => (int) $model_row['model_auth'], 'model_pm' => (int) $model_row['model_pm'], 'model_lang' => (string) $model_row['model_lang']);
                                $db->sql_query('UPDATE ' . $table_prefix . 'models SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE model_id = ' . (int) $model_id);
                                $log = 'UPDATED';
                            }
                        }
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODEL_' . $log, time(), array($model_row['model_title']));
                        trigger_error($user->lang['MODEL_' . $log] . adm_back_link($this->u_action));
                    }
                } else {
                    if ($model_id) {
                        $sql = 'SELECT *
						FROM ' . $table_prefix . 'models
						WHERE model_id = ' . (int) $model_id;
                        $result = $db->sql_query($sql);
                        $model_row = $db->sql_fetchrow($result);
                        $db->sql_freeresult($result);
                        if (!$model_row) {
                            trigger_error($user->lang['NO_MODEL'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                    }
                }
                $l_title = $action == 'edit' ? 'EDIT' : 'ADD';
                $default_language = $action == 'edit' ? $model_row['model_lang'] : $user->data['user_lang'];
                $s_selected_users = $s_selected_mod = $s_selected_admin = $s_selected_founders = '';
                if ($model_row['model_auth'] == constants::MODEL_USERS) {
                    $s_selected_users = 'selected="selected"';
                } else {
                    if ($model_row['model_auth'] == constants::MODEL_MODERATORS) {
                        $s_selected_mod = 'selected="selected"';
                    } else {
                        if ($model_row['model_auth'] == constants::MODEL_ADMINISTRATORS) {
                            $s_selected_admin = 'selected="selected"';
                        } else {
                            if ($model_row['model_auth'] == constants::MODEL_FOUNDERS) {
                                $s_selected_founders = 'selected="selected"';
                            }
                        }
                    }
                }
                $template->assign_vars(array('L_TITLE' => $user->lang['MODEL_' . $l_title], 'U_ACTION' => $this->u_action . "&amp;id={$model_id}&amp;action={$action}", 'U_BACK' => $this->u_action, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '', 'MODEL_TITLE' => $model_row['model_title'], 'MODEL_CONTENT' => $model_row['model_content'], 'MODEL_PM' => $model_row['model_pm'], 'S_MODEL_LANG' => language_select($default_language), 'S_SELECTED_USERS' => $s_selected_users, 'S_SELECTED_MOD' => $s_selected_mod, 'S_SELECTED_ADMIN' => $s_selected_admin, 'S_SELECTED_FOUNDERS' => $s_selected_founders, 'S_EDIT_MODEL' => true, 'S_ERROR' => sizeof($error) ? true : false, 'S_BBCODE_QUOTE' => true, 'S_BBCODE_IMG' => true, 'S_LINKS_ALLOWED' => $config['allow_post_links'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_post_flash'] ? true : false));
                display_custom_bbcodes();
                return;
                break;
            case 'delete':
                $sql = 'SELECT *
					FROM ' . $table_prefix . 'models
					WHERE model_id = ' . (int) $model_id;
                $result = $db->sql_query($sql);
                $model_row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                if (!$model_row) {
                    trigger_error($user->lang['NO_MODEL'] . adm_back_link($this->u_action), E_USER_WARNING);
                }
                // Let the deletion be confirmed...
                if (confirm_box(true)) {
                    $db->sql_query('DELETE FROM ' . $table_prefix . 'models WHERE model_id = ' . (int) $model_id);
                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_MODEL_REMOVED', time(), array($model_row['model_title']));
                    trigger_error($user->lang['MODEL_REMOVED'] . adm_back_link($this->u_action));
                } else {
                    confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action, 'id' => $model_id)));
                }
                break;
        }
        $sql = "SELECT lang_iso\n\t\t\tFROM " . \LANG_TABLE . "\n\t\t\tORDER BY lang_english_name";
        $result = $db->sql_query($sql, 600);
        $language = array();
        while ($row = $db->sql_fetchrow($result)) {
            $language[] = $row['lang_iso'];
        }
        $db->sql_freeresult($result);
        $sql = "SELECT model_id, model_title, model_auth, model_pm, model_lang\n\t\t\tFROM " . $table_prefix . "models\n\t\t\tORDER BY model_title ASC";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $model_auth = array($user->lang['USERS'], $user->lang['MODERATORS'], $user->lang['ADMINISTRATORS'], $user->lang['FOUNDERS']);
            $no_exist = in_array($row['model_lang'], $language) ? false : true;
            $template->assign_block_vars('models', array('MODEL_TITLE' => $row['model_title'], 'MODEL_AUTH' => $model_auth[$row['model_auth']], 'MODEL_PM' => $row['model_pm'] ? $user->lang['YES'] : $user->lang['NO'], 'MODEL_LANG' => $row['model_lang'], 'MODEL_EXIST' => $no_exist == true ? $user->lang['NO_EXIST'] : '', 'U_EDIT' => $this->u_action . '&amp;action=edit&amp;id=' . $row['model_id'], 'U_DELETE' => $this->u_action . '&amp;action=delete&amp;id=' . $row['model_id']));
        }
        $db->sql_freeresult($result);
    }
Exemplo n.º 28
0
 function main($id, $mode)
 {
     global $auth, $cache, $template, $user, $db, $config, $phpEx, $phpbb_root_path;
     global $blog_plugins, $blog_plugins_path, $user_settings;
     $preview = isset($_POST['preview']) ? true : false;
     $submit = isset($_POST['submit']) ? true : false;
     $error = array();
     $user->add_lang(array('mods/blog/common', 'mods/blog/ucp'));
     include $phpbb_root_path . 'blog/functions.' . $phpEx;
     blog_plugins::plugin_do('ucp_start');
     get_user_settings($user->data['user_id']);
     switch ($mode) {
         case 'ucp_blog_settings':
             $subscription_types = get_blog_subscription_types();
             if ($submit) {
                 $sql_ary = array('instant_redirect' => request_var('instant_redirect', 0), 'blog_subscription_default' => 0, 'blog_style' => $auth->acl_get('u_blog_style') ? request_var('blog_style', '') : '', 'blog_css' => $auth->acl_get('u_blog_css') ? request_var('blog_css', '') : '');
                 if ($config['user_blog_subscription_enabled']) {
                     foreach ($subscription_types as $type => $name) {
                         if (request_var('subscription_' . $type, false)) {
                             $sql_ary['blog_subscription_default'] += $type;
                         }
                     }
                 }
                 update_user_blog_settings($user->data['user_id'], $sql_ary);
             } else {
                 if ($config['user_blog_subscription_enabled']) {
                     $subscribed = array();
                     if (isset($user_settings[$user->data['user_id']])) {
                         foreach ($subscription_types as $type => $name) {
                             // Bitwise check
                             if ($user_settings[$user->data['user_id']]['blog_subscription_default'] & $type) {
                                 $subscribed[$type] = true;
                             }
                         }
                     }
                     foreach ($subscription_types as $type => $name) {
                         $template->assign_block_vars('subscriptions', array('TYPE' => 'subscription_' . $type, 'NAME' => isset($user->lang[$name]) ? $user->lang[$name] : $name, 'S_CHECKED' => isset($subscribed[$type]) ? true : false));
                     }
                 }
                 if ($auth->acl_get('u_blog_style')) {
                     $available_styles = array(array('name' => $user->lang['NONE'], 'value' => 0, 'demo' => $phpbb_root_path . 'images/spacer.gif'));
                     $sql = 'SELECT * FROM ' . STYLES_TABLE . ' s, ' . STYLES_TEMPLATE_TABLE . ' st WHERE style_active = 1 AND s.template_id = st.template_id';
                     $result = $db->sql_query($sql);
                     while ($row = $db->sql_fetchrow($result)) {
                         $demo = $phpbb_root_path . 'images/spacer.gif';
                         if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png')) {
                             $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.png';
                         } else {
                             if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif')) {
                                 $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.gif';
                             } else {
                                 if (@file_exists($phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg')) {
                                     $demo = $phpbb_root_path . 'styles/' . $row['template_path'] . '/template/blog/demo.jpg';
                                 }
                             }
                         }
                         $available_styles[] = array('name' => $row['style_name'], 'value' => $row['style_id'], 'demo' => $demo);
                     }
                     $db->sql_freeresult($result);
                     $dh = @opendir($phpbb_root_path . 'blog/styles/');
                     if ($dh) {
                         while (($file = readdir($dh)) !== false) {
                             if (file_exists($phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx)) {
                                 // Inside of the style.php file, add to the $available_styles array
                                 include $phpbb_root_path . 'blog/styles/' . $file . '/style.' . $phpEx;
                             }
                         }
                         closedir($dh);
                     }
                     foreach ($available_styles as $row) {
                         if (isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] && isset($row['demo']) && $row['demo']) {
                             $default_demo = $row['demo'];
                         }
                         $template->assign_block_vars('blog_styles', array('VALUE' => $row['value'], 'SELECTED' => isset($user_settings[$user->data['user_id']]) && $user_settings[$user->data['user_id']]['blog_style'] == $row['value'] ? true : false, 'NAME' => $row['name'], 'BLOG_CSS' => isset($row['blog_css']) && $row['blog_css'] ? true : false, 'DEMO' => isset($row['demo']) && $row['demo'] ? $row['demo'] : ''));
                     }
                 }
                 $template->assign_vars(array('S_BLOG_INSTANT_REDIRECT' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['instant_redirect'] : 0, 'S_SUBSCRIPTIONS' => $config['user_blog_subscription_enabled'] ? true : false, 'S_BLOG_STYLE' => isset($available_styles) && sizeof($available_styles) > 1 ? true : false, 'S_BLOG_CSS' => $auth->acl_get('u_blog_css') ? true : false, 'DEFAULT_DEMO' => isset($default_demo) ? $default_demo : $phpbb_root_path . 'images/spacer.gif', 'BLOG_CSS' => isset($user_settings[$user->data['user_id']]) ? $user_settings[$user->data['user_id']]['blog_css'] : ''));
             }
             break;
         case 'ucp_blog_permissions':
             if (!$config['user_blog_user_permissions']) {
                 $error[] = $user->lang['USER_PERMISSIONS_DISABLED'];
                 $template->assign_vars(array('PERMISSIONS_DISABLED' => true));
             } else {
                 if ($submit) {
                     $sql_ary = array('perm_guest' => request_var('perm_guest', 1), 'perm_registered' => request_var('perm_registered', 2), 'perm_foe' => request_var('perm_foe', 0), 'perm_friend' => request_var('perm_friend', 2));
                     update_user_blog_settings($user->data['user_id'], $sql_ary, isset($_POST['resync']) ? true : false);
                 } else {
                     permission_settings_builder();
                 }
             }
             break;
         case 'ucp_blog_title_description':
             include $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
             include $phpbb_root_path . 'includes/message_parser.' . $phpEx;
             include $phpbb_root_path . 'blog/includes/functions_posting.' . $phpEx;
             if (!function_exists('display_custom_bbcodes')) {
                 include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
             }
             $user->add_lang('posting');
             $post_options = new post_options();
             $post_options->set_status(true, true, true);
             $post_options->set_in_template();
             if ($submit || $preview) {
                 // see if they tried submitting a message or suject(if they hit preview or submit) put it in an array for consistency with the edit mode
                 $blog_title = utf8_normalize_nfc(request_var('title', '', true));
                 $blog_description = utf8_normalize_nfc(request_var('message', '', true));
                 // set up the message parser to parse BBCode, Smilies, etc
                 $message_parser = new parse_message();
                 $message_parser->message = $blog_description;
                 $message_parser->parse($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, $post_options->img_status, $post_options->flash_status, $post_options->bbcode_status, $post_options->url_status);
             } else {
                 if (isset($user_settings[$user->data['user_id']])) {
                     $blog_title = $user_settings[$user->data['user_id']]['title'];
                     $blog_description = $user_settings[$user->data['user_id']]['description'];
                     decode_message($blog_description, $user_settings[$user->data['user_id']]['description_bbcode_uid']);
                 } else {
                     $blog_title = $blog_description = '';
                 }
             }
             if (!$submit || sizeof($error)) {
                 if ($preview && !sizeof($error)) {
                     $preview_message = $message_parser->format_display($post_options->enable_bbcode, $post_options->enable_magic_url, $post_options->enable_smilies, false);
                     // output some data to the template parser
                     $template->assign_vars(array('S_DISPLAY_PREVIEW' => true, 'PREVIEW_SUBJECT' => censor_text($blog_title), 'PREVIEW_MESSAGE' => $preview_message, 'POST_DATE' => $user->format_date(time())));
                 }
                 // Generate smiley listing
                 generate_smilies('inline', false);
                 // Build custom bbcodes array
                 display_custom_bbcodes();
                 $template->assign_vars(array('S_PREVIEW_BUTTON' => true, 'TITLE' => $blog_title, 'MESSAGE' => $blog_description));
             } else {
                 if ($submit) {
                     $sql_ary = array('user_id' => $user->data['user_id'], 'title' => $blog_title, 'description' => $message_parser->message, 'description_bbcode_bitfield' => $message_parser->bbcode_bitfield, 'description_bbcode_uid' => $message_parser->bbcode_uid);
                     unset($message_parser);
                     update_user_blog_settings($user->data['user_id'], $sql_ary);
                 }
             }
             break;
         default:
             $default = true;
             $temp = compact('mode', 'error', 'default');
             blog_plugins::plugin_do_ref('ucp_default', $temp);
             // make sure you set default to false if you use your own page
             extract($temp);
             if ($default) {
                 trigger_error('NO_MODE');
             }
     }
     blog_plugins::plugin_do('ucp_end');
     if ($submit && !sizeof($error)) {
         //$cache->destroy('_blog_settings_' . $user->data['user_id']);
         meta_refresh(3, $this->u_action);
         $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
         trigger_error($message);
     }
     $template->assign_vars(array('L_TITLE' => $user->lang[strtoupper($mode)], 'L_TITLE_EXPLAIN' => $user->lang[strtoupper($mode) . '_EXPLAIN'], 'ERROR' => sizeof($error) ? implode($error, '<br />') : false, 'MODE' => $mode, 'S_UCP_ACTION' => $this->u_action));
     $this->tpl_name = 'blog/ucp_blog';
     $this->page_title = strtoupper($mode);
 }
Exemplo n.º 29
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        global $phpbb_dispatcher, $request;
        global $phpbb_container, $phpbb_log;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $error = array();
        $username = $request->variable('username', '', true);
        $user_id = $request->variable('u', 0);
        $action = $request->variable('action', '');
        // Get referer to redirect user to the appropriate page after delete action
        $redirect = $request->variable('redirect', '');
        $redirect_tag = "redirect={$redirect}";
        $redirect_url = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$redirect}");
        $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false;
        $form_name = 'acp_users';
        add_form_key($form_name);
        // Whois (special case)
        if ($action == 'whois') {
            if (!function_exists('user_get_id_name')) {
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            }
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = phpbb_ip_normalise($request->variable('user_ip', ''));
            $domain = gethostbyaddr($user_ip);
            $ipwhois = user_ipwhois($user_ip);
            $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&amp;select_single=true')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($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), E_USER_WARNING);
            }
        }
        // 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_limit($sql, 1);
        $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), E_USER_WARNING);
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Build modes dropdown list
        $sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\tAND module_enabled = 1\n\t\t\t\tAND module_class = 'acp'\n\t\t\tORDER BY left_id, module_mode";
        $result = $db->sql_query($sql);
        $dropdown_modes = array();
        while ($row = $db->sql_fetchrow($result)) {
            if (!$this->p_master->module_auth_self($row['module_auth'])) {
                continue;
            }
            $dropdown_modes[$row['module_mode']] = true;
        }
        $db->sql_freeresult($result);
        foreach ($dropdown_modes as $module_mode => $null) {
            $selected = $mode == $module_mode ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => empty($redirect) ? $this->u_action : $redirect_url, '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 . (empty($redirect) ? '' : '&amp;' . $redirect_tag), 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username']));
        // 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), E_USER_WARNING);
        }
        $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode));
        switch ($mode) {
            case 'overview':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang('acp/ban');
                $delete = $request->variable('delete', 0);
                $delete_type = $request->variable('delete_type', '');
                $ip = $request->variable('ip', 'ip');
                /**
                 * Run code at beginning of ACP users overview
                 *
                 * @event core.acp_users_overview_before
                 * @var	array   user_row    Current user data
                 * @var	string  mode        Active module
                 * @var	string  action      Module that should be run
                 * @var	bool    submit      Do we display the form only
                 *                          or did the user press submit
                 * @var	array   error       Array holding error messages
                 * @since 3.1.3-RC1
                 */
                $vars = array('user_row', 'mode', 'action', 'submit', 'error');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_before', compact($vars)));
                if ($submit) {
                    if ($delete) {
                        if (!$auth->acl_get('a_userdel')) {
                            send_status_line(403, 'Forbidden');
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        // 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), E_USER_WARNING);
                        }
                        // Founders can not be deleted.
                        if ($user_row['user_type'] == USER_FOUNDER) {
                            trigger_error($user->lang['CANNOT_REMOVE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($delete_type) {
                            if (confirm_box(true)) {
                                user_delete($delete_type, $user_id, $user_row['username']);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DELETED', false, array($user_row['username']));
                                trigger_error($user->lang['USER_DELETED'] . adm_back_link(empty($redirect) ? $this->u_action : $redirect_url));
                            } else {
                                $delete_confirm_hidden_fields = array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type);
                                // Checks if the redirection page is specified
                                if (!empty($redirect)) {
                                    $delete_confirm_hidden_fields['redirect'] = $redirect;
                                }
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($delete_confirm_hidden_fields));
                            }
                        } else {
                            trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_id == ANONYMOUS) {
                                trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    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';
                                    break;
                            }
                            $ban_reason = $request->variable('ban_reason', $user->lang[$reason], true);
                            $ban_give_reason = $request->variable('ban_give_reason', '', true);
                            // Log not used at the moment, we simply utilize the ban function.
                            $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
                            trigger_error(($result === false ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($config['email_enable']) {
                                if (!class_exists('messenger')) {
                                    include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                }
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(mt_rand(6, 10));
                                $email_template = $user_row['user_type'] == USER_NORMAL ? 'user_reactivate_account' : 'user_resend_inactive';
                                if ($user_row['user_type'] == USER_NORMAL) {
                                    user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
                                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET user_actkey = '" . $db->sql_escape($user_actkey) . "'\n\t\t\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                                    $db->sql_query($sql);
                                } else {
                                    // Grabbing the last confirm key - we only send a reminder
                                    $sql = 'SELECT user_actkey
										FROM ' . USERS_TABLE . '
										WHERE user_id = ' . $user_id;
                                    $result = $db->sql_query($sql);
                                    $user_actkey = (string) $db->sql_fetchfield('user_actkey');
                                    $db->sql_freeresult($result);
                                }
                                $messenger = new messenger(false);
                                $messenger->template($email_template, $user_row['user_lang']);
                                $messenger->set_addresses($user_row);
                                $messenger->anti_abuse_headers($config, $user);
                                $messenger->assign_vars(array('WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 'USERNAME' => htmlspecialchars_decode($user_row['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE', false, array($user_row['username']));
                                $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE_USER', false, array('reportee_id' => $user_id));
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            if ($user_id == $user->data['user_id']) {
                                // It is only deactivation since the user is already activated (else he would not have reached this page)
                                trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            user_active_flip('flip', $user_id);
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                if ($config['require_activation'] == USER_ACTIVATION_ADMIN) {
                                    /* @var $phpbb_notifications \phpbb\notification\manager */
                                    $phpbb_notifications = $phpbb_container->get('notification_manager');
                                    $phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
                                    if (!class_exists('messenger')) {
                                        include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                    }
                                    $messenger = new messenger(false);
                                    $messenger->template('admin_welcome_activated', $user_row['user_lang']);
                                    $messenger->set_addresses($user_row);
                                    $messenger->anti_abuse_headers($config, $user);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user_row['username'])));
                                    $messenger->send(NOTIFY_EMAIL);
                                }
                            }
                            $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';
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log, false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, $log . '_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '');
                            $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);
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // Delete old avatar if present
                            /* @var $phpbb_avatar_manager \phpbb\avatar\manager */
                            $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $phpbb_avatar_manager->clean_row($user_row, 'user'), USERS_TABLE, 'user_');
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR_USER', false, array('reportee_id' => $user_id));
                            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)) {
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_POSTS', false, array($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)) {
                                /** @var \phpbb\attachment\manager $attachment_manager */
                                $attachment_manager = $phpbb_container->get('attachment.manager');
                                $attachment_manager->delete('user', $user_id);
                                unset($attachment_manager);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_ATTACH', false, array($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 'deloutbox':
                            if (confirm_box(true)) {
                                $msg_ids = array();
                                $lang = 'EMPTY';
                                $sql = 'SELECT msg_id
									FROM ' . PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE author_id = {$user_id}\n\t\t\t\t\t\t\t\t\t\tAND folder_id = " . PRIVMSGS_OUTBOX;
                                $result = $db->sql_query($sql);
                                if ($row = $db->sql_fetchrow($result)) {
                                    if (!function_exists('delete_pm')) {
                                        include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
                                    }
                                    do {
                                        $msg_ids[] = (int) $row['msg_id'];
                                    } while ($row = $db->sql_fetchrow($result));
                                    $db->sql_freeresult($result);
                                    delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
                                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_OUTBOX', false, array($user_row['username']));
                                    $lang = 'EMPTIED';
                                }
                                $db->sql_freeresult($result);
                                trigger_error($user->lang['USER_OUTBOX_' . $lang] . 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':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $user->add_lang('acp/forums');
                            $new_forum_id = $request->variable('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;
                            }
                            // Is the new forum postable to?
                            $sql = 'SELECT forum_name, forum_type
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            if (!$forum_info) {
                                trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($forum_info['forum_type'] != FORUM_POST) {
                                trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // 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, post_visibility, 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, post_visibility";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment
									FROM ' . TOPICS_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_REAPPROVE] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) {
                                        $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['topic_attachment'] ? 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_visibility' => ITEM_APPROVED, '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(array_keys($topic_id_ary), $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('topic_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, false, true);
                            }
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS', false, array($user_row['username'], $forum_info['forum_name']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS_USER', false, array('reportee_id' => $user_id, $forum_info['forum_name']));
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'leave_nr':
                            if (confirm_box(true)) {
                                remove_newly_registered($user_id, $user_row);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REMOVED_NR', false, array($user_row['username']));
                                trigger_error($user->lang['USER_LIFTED_NR'] . 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;
                        default:
                            /**
                             * Run custom quicktool code
                             *
                             * @event core.acp_users_overview_run_quicktool
                             * @var	array	user_row	Current user data
                             * @var	string	action		Quick tool that should be run
                             * @since 3.1.0-a1
                             */
                            $vars = array('action', 'user_row');
                            extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars)));
                            break;
                    }
                    // Handle registration info updates
                    $data = array('username' => $request->variable('user', $user_row['username'], true), 'user_founder' => $request->variable('user_founder', $user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'email' => strtolower($request->variable('user_email', $user_row['user_email'])), 'new_password' => $request->variable('new_password', '', true), 'password_confirm' => $request->variable('password_confirm', '', true));
                    // Validation data - we do not check the password complexity setting here
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $check_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['email'] != $user_row['user_email']) {
                        $check_ary += array('email' => array(array('string', false, 6, 60), array('user_email', $user_row['user_email'])));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    // Instantiate passwords manager
                    /* @var $passwords_manager \phpbb\passwords\manager */
                    $passwords_manager = $phpbb_container->get('passwords.manager');
                    // Which updates do we need to do?
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['new_password'] && !$passwords_manager->check($data['new_password'], $user_row['user_password']);
                    $update_email = $data['email'] != $user_row['user_email'] ? $data['email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            // Only allow founders updating the founder status...
                            if ($user->data['user_type'] == USER_FOUNDER) {
                                // Setting a normal member to be a founder
                                if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER) {
                                    // Make sure the user is not setting an Inactive or ignored user to be a founder
                                    if ($user_row['user_type'] == USER_IGNORE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    if ($user_row['user_type'] == USER_INACTIVE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    $sql_ary['user_type'] = USER_FOUNDER;
                                } else {
                                    if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER) {
                                        // Check if at least one founder is present
                                        $sql = 'SELECT user_id
										FROM ' . USERS_TABLE . '
										WHERE user_type = ' . USER_FOUNDER . '
											AND user_id <> ' . $user_id;
                                        $result = $db->sql_query_limit($sql, 1);
                                        $row = $db->sql_fetchrow($result);
                                        $db->sql_freeresult($result);
                                        if ($row) {
                                            $sql_ary['user_type'] = USER_NORMAL;
                                        } else {
                                            trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                        }
                                    }
                                }
                            }
                        }
                        /**
                         * Modify user data before we update it
                         *
                         * @event core.acp_users_overview_modify_data
                         * @var	array	user_row	Current user data
                         * @var	array	data		Submitted user data
                         * @var	array	sql_ary		User data we udpate
                         * @since 3.1.0-a1
                         */
                        $vars = array('user_row', 'data', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars)));
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            $sql_ary['username_clean'] = utf8_clean_string($update_username);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array('reportee_id' => $user_id, $user_row['username'], $update_username));
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => phpbb_email_hash($update_email));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array('reportee_id' => $user_id, $user_row['username'], $user_row['user_email'], $update_email));
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => $passwords_manager->hash($data['new_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array('reportee_id' => $user_id, $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);
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        // Let the users permissions being updated
                        $auth->acl_clear_prefetch($user_id);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_USER_UPDATE', false, array($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 = array_map(array($user, 'lang'), $error);
                }
                if ($user_id == $user->data['user_id']) {
                    $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                } else {
                    $quick_tool_ary = array();
                    if ($user_row['user_type'] != USER_FOUNDER) {
                        $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
                    }
                    if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE) {
                        $quick_tool_ary += array('active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE');
                    }
                    $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE)) {
                        $quick_tool_ary['reactivate'] = 'FORCE';
                    }
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                }
                if ($config['load_onlinetrack']) {
                    $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
						FROM ' . SESSIONS_TABLE . "\n\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    $user_row['session_time'] = isset($row['session_time']) ? $row['session_time'] : 0;
                    $user_row['session_viewonline'] = isset($row['session_viewonline']) ? $row['session_viewonline'] : 0;
                    unset($row);
                }
                /**
                 * Add additional quick tool options and overwrite user data
                 *
                 * @event core.acp_users_display_overview
                 * @var	array	user_row			Array with user data
                 * @var	array	quick_tool_ary		Ouick tool options
                 * @since 3.1.0-a1
                 */
                $vars = array('user_row', 'quick_tool_ary');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
                $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>';
                }
                $last_active = !empty($user_row['session_time']) ? $user_row['session_time'] : $user_row['user_lastvisit'];
                $inactive_reason = '';
                if ($user_row['user_type'] == USER_INACTIVE) {
                    $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
                    switch ($user_row['user_inactive_reason']) {
                        case INACTIVE_REGISTER:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
                            break;
                        case INACTIVE_PROFILE:
                            $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
                            break;
                        case INACTIVE_MANUAL:
                            $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
                            break;
                        case INACTIVE_REMIND:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
                            break;
                    }
                }
                // Posts in Queue
                $sql = 'SELECT COUNT(post_id) as posts_in_queue
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id . '
						AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
                $result = $db->sql_query($sql);
                $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id;
                $result = $db->sql_query_limit($sql, 1);
                $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
                $db->sql_freeresult($result);
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']), '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, 'S_OWN_ACCOUNT' => $user_id == $user->data['user_id'] ? true : false, 'S_USER_INACTIVE' => $user_row['user_type'] == USER_INACTIVE ? true : false, '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_MCP_QUEUE' => $auth->acl_getf_global('m_approve') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue', true, $user->session_id) : '', 'U_SEARCH_USER' => $config['load_search'] && $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$user_row['user_id']}&amp;sr=posts") : '', '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']}&amp;hash=" . generate_link_hash('switchperm')) : '', 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'], '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' => $last_active ? $user->format_date($last_active) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings'], 'USER_POSTS' => $user_row['user_posts'], 'USER_HAS_POSTS' => $user_row['user_has_posts'], 'USER_INACTIVE_REASON' => $inactive_reason));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = $request->variable('mark', array(0));
                $message = $request->variable('message', '', true);
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                // Sort keys
                $sort_days = $request->variable('st', 0);
                $sort_key = $request->variable('sk', 't');
                $sort_dir = $request->variable('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND ' . $db->sql_in_set('log_id', $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\tAND reportee_id = {$user_id}\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($user_row['username']));
                    }
                }
                if ($submit && $message) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array($user_row['username']));
                    $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array('forum_id' => 0, 'topic_id' => 0, $user_row['username']));
                    $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, array('reportee_id' => $user_id, $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' => 'u.username_clean', '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;
                $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_FEEDBACK' => 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_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'warnings':
                $user->add_lang('mcp');
                // Set up general vars
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $confirm = isset($_POST['confirm']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Delete entries if requested and able
                if ($deletemark || $deleteall || $confirm) {
                    if (confirm_box(true)) {
                        $where_sql = '';
                        $deletemark = $request->variable('delmarked', 0);
                        $deleteall = $request->variable('delall', 0);
                        if ($deletemark && $marked) {
                            $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
                        }
                        if ($where_sql || $deleteall) {
                            $sql = 'DELETE FROM ' . WARNINGS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\t\t\t\t{$where_sql}";
                            $db->sql_query($sql);
                            if ($deleteall) {
                                $log_warnings = $deleted_warnings = 0;
                            } else {
                                $num_warnings = (int) $db->sql_affectedrows();
                                $deleted_warnings = ' user_warnings - ' . $num_warnings;
                                $log_warnings = $num_warnings > 2 ? 2 : $num_warnings;
                            }
                            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\tSET user_warnings = {$deleted_warnings}\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            if ($log_warnings) {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED', false, array($user_row['username'], $num_warnings));
                            } else {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED_ALL', false, array($user_row['username']));
                            }
                        }
                    } else {
                        $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'u' => $user_id, 'mark' => $marked);
                        if (isset($_POST['delmarked'])) {
                            $s_hidden_fields['delmarked'] = 1;
                        }
                        if (isset($_POST['delall'])) {
                            $s_hidden_fields['delall'] = 1;
                        }
                        if (isset($_POST['delall']) || isset($_POST['delmarked']) && sizeof($marked)) {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
                        }
                    }
                }
                $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour
					FROM ' . WARNINGS_TABLE . ' w
					LEFT JOIN ' . LOG_TABLE . ' l
						ON (w.log_id = l.log_id)
					LEFT JOIN ' . USERS_TABLE . ' m
						ON (l.user_id = m.user_id)
					WHERE w.user_id = ' . $user_id . '
					ORDER BY w.warning_time DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if (!$row['log_operation']) {
                        // We do not have a log-entry anymore, so there is no data available
                        $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
                    } else {
                        $row['action'] = isset($user->lang[$row['log_operation']]) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
                        if (!empty($row['log_data'])) {
                            $log_data_ary = @unserialize($row['log_data']);
                            $log_data_ary = $log_data_ary === false ? array() : $log_data_ary;
                            if (isset($user->lang[$row['log_operation']])) {
                                // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
                                // It doesn't matter if we add more arguments than placeholders
                                if (substr_count($row['action'], '%') - sizeof($log_data_ary) > 0) {
                                    $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
                                }
                                $row['action'] = vsprintf($row['action'], $log_data_ary);
                                $row['action'] = bbcode_nl2br(censor_text($row['action']));
                            } else {
                                if (!empty($log_data_ary)) {
                                    $row['action'] .= '<br />' . implode('', $log_data_ary);
                                }
                            }
                        }
                    }
                    $template->assign_block_vars('warn', array('ID' => $row['warning_id'], 'USERNAME' => $row['log_operation'] ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-', 'ACTION' => make_clickable($row['action']), 'DATE' => $user->format_date($row['warning_time'])));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_WARNINGS' => true));
                break;
            case 'profile':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                /* @var $cp \phpbb\profilefields\manager */
                $cp = $phpbb_container->get('profilefields.manager');
                $cp_data = $cp_error = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                $data = array('jabber' => $request->variable('jabber', $user_row['user_jabber'], true), 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                if ($user_row['user_birthday']) {
                    list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                }
                $data['bday_day'] = $request->variable('bday_day', $data['bday_day']);
                $data['bday_month'] = $request->variable('bday_month', $data['bday_month']);
                $data['bday_year'] = $request->variable('bday_year', $data['bday_year']);
                $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                /**
                 * Modify user data on editing profile in ACP
                 *
                 * @event core.acp_users_modify_profile
                 * @var	array	data		Array with user profile data
                 * @var	bool	submit		Flag indicating if submit button has been pressed
                 * @var	int		user_id		The user id
                 * @var	array	user_row	Array with the full user data
                 * @since 3.1.4-RC1
                 */
                $vars = array('data', 'submit', 'user_id', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_profile', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('jabber' => array(array('string', true, 5, 255), array('jabber')), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())), 'user_birthday' => array('date', true)));
                    // 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 (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    /**
                     * Validate profile data in ACP before submitting to the database
                     *
                     * @event core.acp_users_profile_validate
                     * @var	bool	submit		Flag indicating if submit button has been pressed
                     * @var	array	data		Array with user profile data
                     * @var	array	error		Array with the form errors
                     * @since 3.1.4-RC1
                     */
                    $vars = array('submit', 'data', 'error');
                    extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_validate', compact($vars)));
                    if (!sizeof($error)) {
                        $sql_ary = array('user_jabber' => $data['jabber'], 'user_birthday' => $data['user_birthday']);
                        /**
                         * Modify profile data in ACP before submitting to the database
                         *
                         * @event core.acp_users_profile_modify_sql_ary
                         * @var	array	cp_data		Array with the user custom profile fields data
                         * @var	array	data		Array with user profile data
                         * @var	int		user_id		The user id
                         * @var	array	user_row	Array with the full user data
                         * @var	array	sql_ary		Array with sql data
                         * @since 3.1.4-RC1
                         */
                        $vars = array('cp_data', 'data', 'user_id', 'user_row', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_modify_sql_ary', compact($vars)));
                        $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
                        $cp->update_profile_field_data($user_id, $cp_data);
                        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 = array_map(array($user, 'lang'), $error);
                }
                $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>";
                }
                $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('JABBER' => $data['jabber'], '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':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $data = array('dateformat' => $request->variable('dateformat', $user_row['user_dateformat'], true), 'lang' => basename($request->variable('lang', $user_row['user_lang'])), 'tz' => $request->variable('tz', $user_row['user_timezone']), 'style' => $request->variable('style', $user_row['user_style']), 'viewemail' => $request->variable('viewemail', $user_row['user_allow_viewemail']), 'massemail' => $request->variable('massemail', $user_row['user_allow_massemail']), 'hideonline' => $request->variable('hideonline', !$user_row['user_allow_viewonline']), 'notifymethod' => $request->variable('notifymethod', $user_row['user_notify_type']), 'notifypm' => $request->variable('notifypm', $user_row['user_notify_pm']), 'allowpm' => $request->variable('allowpm', $user_row['user_allow_pm']), 'topic_sk' => $request->variable('topic_sk', $user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't'), 'topic_sd' => $request->variable('topic_sd', $user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd'), 'topic_st' => $request->variable('topic_st', $user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0), 'post_sk' => $request->variable('post_sk', $user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't'), 'post_sd' => $request->variable('post_sd', $user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'a'), 'post_st' => $request->variable('post_st', $user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0), 'view_images' => $request->variable('view_images', $this->optionget($user_row, 'viewimg')), 'view_flash' => $request->variable('view_flash', $this->optionget($user_row, 'viewflash')), 'view_smilies' => $request->variable('view_smilies', $this->optionget($user_row, 'viewsmilies')), 'view_sigs' => $request->variable('view_sigs', $this->optionget($user_row, 'viewsigs')), 'view_avatars' => $request->variable('view_avatars', $this->optionget($user_row, 'viewavatars')), 'view_wordcensor' => $request->variable('view_wordcensor', $this->optionget($user_row, 'viewcensors')), 'bbcode' => $request->variable('bbcode', $this->optionget($user_row, 'bbcode')), 'smilies' => $request->variable('smilies', $this->optionget($user_row, 'smilies')), 'sig' => $request->variable('sig', $this->optionget($user_row, 'attachsig')), 'notify' => $request->variable('notify', $user_row['user_notify']));
                /**
                 * Modify users preferences data
                 *
                 * @event core.acp_users_prefs_modify_data
                 * @var	array	data			Array with users preferences data
                 * @var	array	user_row		Array with user data
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_data', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('dateformat' => array('string', false, 1, 64), 'lang' => array('match', false, '#^[a-z_\\-]{2,}$#i'), 'tz' => array('timezone'), '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)));
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $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_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']);
                        /**
                         * Modify SQL query before users preferences are updated
                         *
                         * @event core.acp_users_prefs_modify_sql
                         * @var	array	data			Array with users preferences data
                         * @var	array	user_row		Array with user data
                         * @var	array	sql_ary			SQL array with users preferences data to update
                         * @var	array	error			Array with errors data
                         * @since 3.1.0-b3
                         */
                        $vars = array('data', 'user_row', 'sql_ary', 'error');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_sql', compact($vars)));
                        if (!sizeof($error)) {
                            $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);
                            // Check if user has an active session
                            if ($user_row['session_id']) {
                                // We'll update the session if user_allow_viewonline has changed and the user is a bot
                                // Or if it's a regular user and the admin set it to hide the session
                                if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) {
                                    // We also need to check if the user has the permission to cloak.
                                    $user_auth = new \phpbb\auth\auth();
                                    $user_auth->acl($user_row);
                                    $session_sql_ary = array('session_viewonline' => $user_auth->acl_get('u_hideonline') ? $sql_ary['user_allow_viewonline'] : true);
                                    $sql = 'UPDATE ' . SESSIONS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "\n\t\t\t\t\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                                    $db->sql_query($sql);
                                    unset($user_auth);
                                }
                            }
                            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 = array_map(array($user, 'lang'), $error);
                }
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $data['dateformat'] ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!isset($user->lang['dateformats'][$data['dateformat']])) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $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 = $data[$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 = $data[$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 = $data[$sort_option . '_sd'] == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                phpbb_timezone_select($template, $user, $data['tz'], true);
                $user_prefs_data = array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => $data['viewemail'], 'MASS_EMAIL' => $data['massemail'], 'ALLOW_PM' => $data['allowpm'], 'HIDE_ONLINE' => $data['hideonline'], 'NOTIFY_EMAIL' => $data['notifymethod'] == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $data['notifymethod'] == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $data['notifymethod'] == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], 'NOTIFY' => $data['notify'], 'VIEW_IMAGES' => $data['view_images'], 'VIEW_FLASH' => $data['view_flash'], 'VIEW_SMILIES' => $data['view_smilies'], 'VIEW_SIGS' => $data['view_sigs'], 'VIEW_AVATARS' => $data['view_avatars'], 'VIEW_WORDCENSOR' => $data['view_wordcensor'], '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' => $data['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($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']));
                /**
                 * Modify users preferences data before assigning it to the template
                 *
                 * @event core.acp_users_prefs_modify_template_data
                 * @var	array	data				Array with users preferences data
                 * @var	array	user_row			Array with user data
                 * @var	array	user_prefs_data		Array with users preferences data to be assigned to the template
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row', 'user_prefs_data');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_template_data', compact($vars)));
                $template->assign_vars($user_prefs_data);
                break;
            case 'avatar':
                $avatars_enabled = false;
                /** @var \phpbb\avatar\manager $phpbb_avatar_manager */
                $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                if ($config['allow_avatar']) {
                    $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
                    // This is normalised data, without the user_ prefix
                    $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user');
                    if ($submit) {
                        if (check_form_key($form_name)) {
                            $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', ''));
                            if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) {
                                $driver = $phpbb_avatar_manager->get_driver($driver_name);
                                $result = $driver->process_form($request, $template, $user, $avatar_data, $error);
                                if ($result && empty($error)) {
                                    // Success! Lets save the result in the database
                                    $result = array('user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height']);
                                    $sql = 'UPDATE ' . USERS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $result) . '
										WHERE user_id = ' . (int) $user_id;
                                    $db->sql_query($sql);
                                    trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                                }
                            }
                        } else {
                            trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle deletion of avatars
                    if ($request->is_set_post('avatar_delete')) {
                        if (!confirm_box(true)) {
                            confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array('avatar_delete' => true)));
                        } else {
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_');
                            trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                    }
                    $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type']));
                    // Assign min and max values before generating avatar driver html
                    $template->assign_vars(array('AVATAR_MIN_WIDTH' => $config['avatar_min_width'], 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height']));
                    foreach ($avatar_drivers as $current_driver) {
                        $driver = $phpbb_avatar_manager->get_driver($current_driver);
                        $avatars_enabled = true;
                        $template->set_filenames(array('avatar' => $driver->get_acp_template_name()));
                        if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) {
                            $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver);
                            $driver_upper = strtoupper($driver_name);
                            $template->assign_block_vars('avatar_drivers', array('L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar')));
                        }
                    }
                }
                // Avatar manager is not initialized if avatars are disabled
                if (isset($phpbb_avatar_manager)) {
                    // Replace "error" strings with their real, localised form
                    $error = $phpbb_avatar_manager->localize_errors($user, $error);
                }
                $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true);
                $template->assign_vars(array('S_AVATAR' => true, 'ERROR' => !empty($error) ? implode('<br />', $error) : '', 'AVATAR' => empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar, 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), 'S_AVATARS_ENABLED' => $config['allow_avatar'] && $avatars_enabled));
                break;
            case 'rank':
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $rank_id = $request->variable('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':
                if (!function_exists('display_custom_bbcodes')) {
                    include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                }
                $enable_bbcode = $config['allow_sig_bbcode'] ? $this->optionget($user_row, 'sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? $this->optionget($user_row, 'sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? $this->optionget($user_row, 'sig_links') : false;
                $decoded_message = generate_text_for_edit($user_row['user_sig'], $user_row['user_sig_bbcode_uid'], $user_row['user_sig_bbcode_bitfield']);
                $signature = $request->variable('signature', $decoded_message['text'], true);
                $signature_preview = '';
                if ($submit || $request->is_set_post('preview')) {
                    $enable_bbcode = $config['allow_sig_bbcode'] ? !$request->variable('disable_bbcode', false) : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? !$request->variable('disable_smilies', false) : false;
                    $enable_urls = $config['allow_sig_links'] ? !$request->variable('disable_magic_url', false) : false;
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                }
                $bbcode_uid = $bbcode_bitfield = $bbcode_flags = '';
                $warn_msg = generate_text_for_storage($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags, $enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], 'sig');
                if (sizeof($warn_msg)) {
                    $error += $warn_msg;
                }
                if (!$submit) {
                    // Parse it for displaying
                    $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags);
                } else {
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
                        $this->optionset($user_row, 'sig_smilies', $enable_smilies);
                        $this->optionset($user_row, 'sig_links', $enable_urls);
                        $sql_ary = array('user_sig' => $signature, 'user_options' => $user_row['user_options'], 'user_sig_bbcode_uid' => $bbcode_uid, 'user_sig_bbcode_bitfield' => $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 = array_map(array($user, 'lang'), $error);
                if ($request->is_set_post('preview')) {
                    $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_bitfield);
                }
                /** @var \phpbb\controller\helper $controller_helper */
                $controller_helper = $phpbb_container->get('controller.helper');
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $decoded_message['text'], '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' => $user->lang($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF', '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</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'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => $user->lang('SIGNATURE_EXPLAIN', (int) $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, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                // Assigning custom bbcodes
                display_custom_bbcodes();
                break;
            case 'attach':
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Sort keys
                $sort_key = $request->variable('sk', 'a');
                $sort_dir = $request->variable('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    $sql = 'SELECT attach_id
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE poster_id = ' . $user_id . '
							AND is_orphan = 0
							AND ' . $db->sql_in_set('attach_id', $marked);
                    $result = $db->sql_query($sql);
                    $marked = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $marked[] = $row['attach_id'];
                    }
                    $db->sql_freeresult($result);
                }
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $marked);
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        /** @var \phpbb\attachment\manager $attachment_manager */
                        $attachment_manager = $phpbb_container->get('attachment.manager');
                        $attachment_manager->delete('attach', $marked);
                        unset($attachment_manager);
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode($user->lang['COMMA_SEPARATOR'], $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, 'delmarked' => 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>';
                }
                if (!isset($sk_sql[$sort_key])) {
                    $sort_key = 'a';
                }
                $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}\n\t\t\t\t\t\tAND is_orphan = 0";
                $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\t\tAND a.is_orphan = 0\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['topics_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']}") . '#p' . $row['post_msg_id'];
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), '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/file.{$phpEx}", 'mode=view&amp;id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;sk={$sort_key}&amp;sd={$sort_dir}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir));
                break;
            case 'groups':
                if (!function_exists('group_user_attributes')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = $request->variable('g', 0);
                if ($group_id) {
                    // Check the founder only entry for this group to make sure everything is well
                    $sql = 'SELECT group_founder_manage
						FROM ' . GROUPS_TABLE . '
						WHERE group_id = ' . $group_id;
                    $result = $db->sql_query($sql);
                    $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
                    $db->sql_freeresult($result);
                    if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) {
                        trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                }
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        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), E_USER_WARNING);
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $error = array();
                            // The delete action was successful - therefore update the user row...
                            $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_limit($sql, 1);
                            $user_row = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                        } 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;
                    case 'approve':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            group_user_attributes($action, $group_id, $user_id);
                        } 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 (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    // 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), E_USER_WARNING);
                    }
                    $error = array();
                }
                /** @var \phpbb\group\helper $group_helper */
                $group_helper = $phpbb_container->get('group_helper');
                $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, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
					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_enable'] && $row['group_name'] == 'REGISTERED_COPPA') {
                        continue;
                    }
                    // Do not display those groups not allowed to be managed
                    if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage']) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . $group_helper->get_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'], 'U_APPROVE' => $group_type == 'pending' ? $this->u_action . "&amp;action=approve&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_IS_MEMBER' => $group_type != 'pending' ? true : false, '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':
                if (!class_exists('auth_admin')) {
                    include $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                }
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                add_permission_language();
                $forum_id = $request->variable('f', 0);
                // Global Permissions
                if (!$forum_id) {
                    // Select auth options
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . '
						WHERE auth_option ' . $db->sql_like_expression($db->get_any_char() . '_') . '
							AND is_global = 1
						ORDER BY auth_option';
                    $result = $db->sql_query($sql);
                    $hold_ary = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                    }
                    $db->sql_freeresult($result);
                    unset($hold_ary);
                } else {
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\t\tWHERE auth_option " . $db->sql_like_expression($db->get_any_char() . '_') . "\n\t\t\t\t\t\t\tAND is_local = 1\n\t\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, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                    }
                    $db->sql_freeresult($result);
                }
                $s_forum_options = '<option value="0"' . (!$forum_id ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
                $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'S_GLOBAL' => !$forum_id ? true : false, 'S_FORUM_OPTIONS' => $s_forum_options, 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, '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) : ''));
    }
 /**
  * Process donation pages data to be added or edited
  *
  * @param \skouat\ppde\entity\donation_pages $entity The donation pages entity object
  * @param array                              $data   The form data to be processed
  *
  * @return null
  * @access private
  */
 private function add_edit_donation_page_data($entity, $data)
 {
     // Get form's POST actions (submit or preview)
     $this->submit = $this->request->is_set_post('submit');
     $this->preview = $this->request->is_set_post('preview');
     // Load posting language file for the BBCode editor
     $this->user->add_lang('posting');
     // Create an array to collect errors that will be output to the user
     $errors = array();
     $message_parse_options = array_merge($this->get_message_parse_options($entity, $data, 'bbcode'), $this->get_message_parse_options($entity, $data, 'magic_url'), $this->get_message_parse_options($entity, $data, 'smilies'));
     // Set the message parse options in the entity
     foreach ($message_parse_options as $function => $enabled) {
         try {
             call_user_func(array($entity, ($enabled ? 'message_enable_' : 'message_disable_') . $function));
         } catch (\skouat\ppde\exception\base $e) {
             // Catch exceptions and add them to errors array
             $errors[] = $e->get_message($this->user);
         }
     }
     unset($message_parse_options);
     // Set the donation page's data in the entity
     $item_fields = array('lang_id' => $data['page_lang_id'], 'name' => $data['page_title'], 'message' => $data['page_content']);
     $errors = array_merge($errors, $this->set_entity_data($entity, $item_fields));
     // Check some settings before submitting data
     $errors = array_merge($errors, $this->is_invalid_form('add_edit_' . $this->module_name, $this->submit_or_preview($this->submit)), $this->is_empty_data($entity, 'name', '', $this->submit_or_preview($this->submit)), $this->is_empty_data($entity, 'lang_id', 0, $this->submit_or_preview($this->submit)));
     // Grab predefined template vars
     $vars = $entity->get_vars();
     // Assign variables in a template block vars
     $this->assign_preview_template_vars($entity, $errors);
     $this->assign_predefined_block_vars($vars);
     // Submit form data
     $this->submit_data($entity, $errors);
     // Set output vars for display in the template
     $this->template->assign_vars(array('S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'L_DONATION_PAGES_TITLE' => $this->user->lang[strtoupper($entity->get_name())], 'L_DONATION_PAGES_TITLE_EXPLAIN' => $this->user->lang[strtoupper($entity->get_name()) . '_EXPLAIN'], 'DONATION_BODY' => $entity->get_message_for_edit(), 'S_BBCODE_DISABLE_CHECKED' => !$entity->message_bbcode_enabled(), 'S_SMILIES_DISABLE_CHECKED' => !$entity->message_smilies_enabled(), 'S_MAGIC_URL_DISABLE_CHECKED' => !$entity->message_magic_url_enabled(), 'BBCODE_STATUS' => $this->user->lang('BBCODE_IS_ON', '<a href="' . append_sid("{$this->phpbb_root_path}faq.{$this->php_ext}", 'mode=bbcode') . '">', '</a>'), 'SMILIES_STATUS' => $this->user->lang['SMILIES_ARE_ON'], 'IMG_STATUS' => $this->user->lang['IMAGES_ARE_ON'], 'FLASH_STATUS' => $this->user->lang['FLASH_IS_ON'], 'URL_STATUS' => $this->user->lang['URL_IS_ON'], 'S_BBCODE_ALLOWED' => true, 'S_SMILIES_ALLOWED' => true, 'S_BBCODE_IMG' => true, 'S_BBCODE_FLASH' => true, 'S_LINKS_ALLOWED' => true, 'S_HIDDEN_FIELDS' => '<input type="hidden" name="page_title" value="' . $entity->get_name() . '" />'));
     // Assigning custom bbcodes
     include_once $this->phpbb_root_path . 'includes/functions_display.' . $this->php_ext;
     display_custom_bbcodes();
 }