$questionid = $pass_questionid;
// picked up from index.php
//	Get information about this question
global $qa_login_userid, $questionid, $question, $parentquestion, $answers, $commentsfollows, $relatedcount, $relatedquestions, $question, $categories;
$usecaptcha = qa_user_use_captcha('captcha_on_anon_post');
$permiterror = qa_user_permit_error('permit_view_q_page');
//	If we're responding to an HTTP POST, include file that handles all posting/editing/etc... logic
//	This is in a separate file because it's a *lot* of logic, and will slow down ordinary page views
$pageerror = null;
$formtype = null;
$formpostid = null;
$jumptoanchor = null;
$focusonid = null;
if (qa_is_http_post() || strlen($qa_state)) {
    require QA_INCLUDE_DIR . 'qa-page-question-post.php';
    qa_page_q_load_q();
    // reload since we may have changed something
}
$formrequested = isset($formtype);
if (!$formrequested && $question['answerbutton']) {
    $immedoption = qa_opt('show_a_form_immediate');
    if ($immedoption == 'always' || $immedoption == 'if_no_as' && !$question['isbyuser'] && !$question['acount']) {
        $formtype = 'a_add';
    }
    // show answer form by default
}
//	Get information on the users referenced
$usershtml = qa_userids_handles_html(array_merge(array($question), $answers, $commentsfollows, $relatedquestions), true);
//	Prepare content for theme
$qa_content = qa_content_prepare(true, array_keys(qa_category_path($categories, $question['categoryid'])));
$qa_content['main_form_tags'] = 'METHOD="POST" ACTION="' . qa_self_html() . '"';
 function doctype()
 {
     //qa_error_log($this->content);
     if ($this->request == 'admin/permissions' && function_exists('qa_register_plugin_phrases') && qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
         $permits[] = 'expert_question_ask';
         $permits[] = 'expert_question_roles';
         foreach ($permits as $optionname) {
             $value = qa_opt($optionname);
             $optionfield = array('id' => $optionname, 'label' => qa_lang_html('expert_question/' . $optionname) . ':', 'tags' => 'NAME="option_' . $optionname . '" ID="option_' . $optionname . '"', 'error' => qa_html(@$errors[$optionname]));
             $widest = QA_PERMIT_USERS;
             $narrowest = QA_PERMIT_ADMINS;
             $permitoptions = qa_admin_permit_options($widest, $narrowest, !QA_FINAL_EXTERNAL_USERS && qa_opt('confirm_user_emails'));
             if (count($permitoptions) > 1) {
                 qa_optionfield_make_select($optionfield, $permitoptions, $value, $value == QA_PERMIT_CONFIRMED ? QA_PERMIT_USERS : min(array_keys($permitoptions)));
             }
             $this->content['form']['fields'][$optionname] = $optionfield;
             $this->content['form']['fields'][$optionname . '_points'] = array('id' => $optionname . '_points', 'tags' => 'NAME="option_' . $optionname . '_points" ID="option_' . $optionname . '_points"', 'type' => 'number', 'value' => qa_opt($optionname . '_points'), 'prefix' => qa_lang_html('admin/users_must_have') . ' ', 'note' => qa_lang_html('admin/points'));
             $checkboxtodisplay[$optionname . '_points'] = '(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS) . ') ||(option_' . $optionname . '==' . qa_js(QA_PERMIT_POINTS_CONFIRMED) . ')';
         }
         qa_set_display_rules($this->content, $checkboxtodisplay);
     }
     $this->expert_user = $this->is_expert_user();
     if (!$this->expert_user) {
         foreach ($this->content['navigation']['main'] as $key => $nav) {
             if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                 unset($this->content['navigation']['main'][$key]);
             }
         }
     }
     if (qa_clicked('do_expert_answeradd') && ($this->expert_user || $this->content['q_view']['raw']['userid'] === qa_get_logged_in_userid())) {
         global $qa_login_userid, $questionid, $question, $answers, $question, $qa_request;
         $innotify = qa_post_text('notify') ? true : false;
         $inemail = qa_post_text('email');
         qa_get_post_content('editor', 'content', $ineditor, $incontent, $informat, $intext);
         $isduplicate = false;
         foreach ($answers as $answer) {
             if (!$answer['hidden']) {
                 if (implode(' ', qa_string_to_words($answer['content'])) == implode(' ', qa_string_to_words($incontent))) {
                     $isduplicate = true;
                 }
             }
         }
         if (!$isduplicate) {
             if (!isset($qa_login_userid)) {
                 $qa_cookieid = qa_cookie_get_create();
             }
             // create a new cookie if necessary
             $answerid = qa_answer_create($qa_login_userid, qa_get_logged_in_handle(), $qa_cookieid, $incontent, $informat, $intext, $innotify, $inemail, $question);
             qa_report_write_action($qa_login_userid, $qa_cookieid, 'a_post', $questionid, $answerid, null);
             qa_redirect($qa_request, null, null, null, qa_anchor('A', $answerid));
         } else {
             $pageerror = qa_lang_html('question/duplicate_content');
         }
         qa_page_q_load_q();
         // reload since we may have changed something
     }
     if (qa_opt('expert_question_enable')) {
         if ($this->expert_user && qa_opt('expert_question_show_count')) {
             $this->expertcount = qa_db_read_one_value(qa_db_query_sub("SELECT COUNT(postid) FROM ^postmeta, ^posts WHERE ^postmeta.meta_key='is_expert_question' AND ^postmeta.post_id=^posts.postid AND ^posts.acount=0" . (is_array($this->expert_user) ? " AND ^posts.categoryid IN (#)" : " AND \$"), $this->expert_user), true);
             if ($this->expertcount) {
                 foreach ($this->content['navigation']['main'] as $key => $nav) {
                     if ($nav['url'] == qa_path_html(qa_opt('expert_question_page_url'))) {
                         $this->content['navigation']['main'][$key]['label'] .= ' (' . $this->expertcount . ')';
                     }
                 }
             }
         }
         global $qa_request;
         if ($qa_request == qa_opt('expert_question_page_url')) {
             $this->content['navigation']['sub'] = array('special' => 1);
         }
         if ($this->template == 'ask' && in_array(qa_opt('expert_question_type'), array(0, 2)) && !qa_user_permit_error('permit_post_q') && !qa_permit_value_error(qa_opt('expert_question_ask'), qa_get_logged_in_userid(), qa_get_logged_in_level(), qa_get_logged_in_flags()) && !qa_opt('site_maintenance')) {
             $this->content['form']['fields'][] = array('tags' => 'NAME="is_expert_question" ID="is_expert_question"', 'value' => qa_get(qa_opt('expert_question_page_url')) == 'true' ? qa_opt('expert_question_yes') : qa_opt('expert_question_no'), 'type' => 'select-radio', 'options' => array('no' => qa_opt('expert_question_no'), 'yes' => qa_opt('expert_question_yes')));
         }
         if ($this->template == 'user' && qa_get_logged_in_handle() === $this->_user_handle()) {
             if (!isset($this->content['navigation']['sub'])) {
                 $this->content['navigation']['sub'] = array('profile' => array('url' => qa_path_html('user/' . $this->_user_handle(), null, qa_opt('site_url')), 'label' => $this->_user_handle(), 'selected' => !qa_get('tab') ? true : false), qa_opt('expert_question_page_url') => array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false));
             } else {
                 $this->content['navigation']['sub'][qa_opt('expert_question_page_url')] = array('url' => qa_path_html('user/' . $this->_user_handle(), array('tab' => qa_opt('expert_question_page_url')), qa_opt('site_url')), 'label' => qa_opt('expert_question_page_title'), 'selected' => qa_get('tab') == qa_opt('expert_question_page_url') ? true : false);
             }
         }
         if ($this->template == 'question') {
             $qid = $this->content['q_view']['raw']['postid'];
             $expert = qa_db_read_one_value(qa_db_query_sub("SELECT meta_value FROM ^postmeta WHERE meta_key='is_expert_question' AND post_id=#", $qid), true);
             if ($expert) {
                 // is expert question
                 $this->expert_question = 1;
                 // modify post elements
                 // title
                 $this->content['title'] .= ' ' . qa_opt('expert_question_title');
                 // css class
                 $this->content['q_view']['tags'] .= ' class="qa-expert-question"';
                 // remove hidden stuff
                 unset($this->content['q_view']['hidden']);
                 unset($this->content['hidden']);
             }
         }
     }
     qa_html_theme_base::doctype();
 }