qa-page-user-questions.php 3.33 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3 4 5 6 7
/*
	Question2Answer (c) Gideon Greenspan

	http://www.question2answer.org/

Scott Vivian committed
8

Gideon Greenspan committed
9 10
	File: qa-include/qa-page-user-questions.php
	Version: See define()s at top of qa-include/qa-base.php
Gideon Greenspan committed
11
	Description: Controller for user page showing all user's questions
Gideon Greenspan committed
12 13 14 15 16 17


	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	More about this license: http://www.question2answer.org/license.php
*/

	if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
		header('Location: ../');
		exit;
	}

	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';
Scott Vivian committed
34

Gideon Greenspan committed
35 36 37

//	$handle, $userhtml are already set by qa-page-user.php - also $userid if using external user integration

Scott committed
38
	$start = qa_get_start();
Scott Vivian committed
39 40


Gideon Greenspan committed
41
//	Find the questions for this user
Scott Vivian committed
42

Scott committed
43 44
	$loginuserid = qa_get_logged_in_userid();
	$identifier = QA_FINAL_EXTERNAL_USERS ? $userid : $handle;
Gideon Greenspan committed
45

Scott committed
46
	list($useraccount, $userpoints, $questions) = qa_db_select_with_pending(
Gideon Greenspan committed
47 48 49 50
		QA_FINAL_EXTERNAL_USERS ? null : qa_db_user_account_selectspec($handle, false),
		qa_db_user_points_selectspec($identifier),
		qa_db_user_recent_qs_selectspec($loginuserid, $identifier, qa_opt_if_loaded('page_size_qs'), $start)
	);
Scott Vivian committed
51

Gideon Greenspan committed
52 53 54 55 56 57
	if ((!QA_FINAL_EXTERNAL_USERS) && !is_array($useraccount)) // check the user exists
		return include QA_INCLUDE_DIR.'qa-page-not-found.php';


//	Get information on user questions

Scott committed
58 59 60 61
	$pagesize = qa_opt('page_size_qs');
	$count = (int)@$userpoints['qposts'];
	$questions = array_slice($questions, 0, $pagesize);
	$usershtml = qa_userids_handles_html($questions, false);
Gideon Greenspan committed
62

Scott Vivian committed
63

Gideon Greenspan committed
64
//	Prepare content for theme
Scott Vivian committed
65

Scott committed
66
	$qa_content = qa_content_prepare(true);
Scott Vivian committed
67

Gideon Greenspan committed
68
	if (count($questions))
Scott committed
69
		$qa_content['title'] = qa_lang_html_sub('profile/questions_by_x', $userhtml);
Gideon Greenspan committed
70
	else
Scott committed
71
		$qa_content['title'] = qa_lang_html_sub('profile/no_questions_by_x', $userhtml);
Gideon Greenspan committed
72 73 74 75


//	Recent questions by this user

Scott committed
76
	$qa_content['q_list']['form'] = array(
Gideon Greenspan committed
77
		'tags' => 'method="post" action="'.qa_self_html().'"',
Gideon Greenspan committed
78 79 80 81 82

		'hidden' => array(
			'code' => qa_get_form_security_code('vote'),
		),
	);
Scott Vivian committed
83

Scott committed
84
	$qa_content['q_list']['qs'] = array();
Scott Vivian committed
85

Scott committed
86 87 88
	$htmldefaults = qa_post_html_defaults('Q');
	$htmldefaults['whoview'] = false;
	$htmldefaults['avatarsize'] = 0;
Scott Vivian committed
89

90
	foreach ($questions as $question) {
Scott committed
91
		$qa_content['q_list']['qs'][] = qa_post_html_fields($question, $loginuserid, qa_cookie_get(),
Gideon Greenspan committed
92
			$usershtml, null, qa_post_html_options($question, $htmldefaults));
93
	}
Gideon Greenspan committed
94

Scott committed
95
	$qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $count, qa_opt('pages_prev_next'));
Gideon Greenspan committed
96 97 98 99


//	Sub menu for navigation in user pages

Scott committed
100 101
	$ismyuser = isset($loginuserid) && $loginuserid == (QA_FINAL_EXTERNAL_USERS ? $userid : $useraccount['userid']);
	$qa_content['navigation']['sub'] = qa_user_sub_navigation($handle, 'questions', $ismyuser);
Gideon Greenspan committed
102 103 104 105 106 107 108 109


	return $qa_content;


/*
	Omit PHP closing tag to help avoid accidental output
*/