qa-page-admin-moderate.php 4.36 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 11 12 13 14 15 16 17
	File: qa-include/qa-page-admin-moderate.php
	Version: See define()s at top of qa-include/qa-base.php
	Description: Controller for admin page showing questions, answers and comments waiting for approval


	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 34 35
	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-app-admin.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';

Scott Vivian committed
36

Gideon Greenspan committed
37 38 39
//	Find queued questions, answers, comments

	$userid=qa_get_logged_in_userid();
Scott Vivian committed
40

Gideon Greenspan committed
41 42 43 44 45
	list($queuedquestions, $queuedanswers, $queuedcomments)=qa_db_select_with_pending(
		qa_db_qs_selectspec($userid, 'created', 0, null, null, 'Q_QUEUED', true),
		qa_db_recent_a_qs_selectspec($userid, 0, null, null, 'A_QUEUED', true),
		qa_db_recent_c_qs_selectspec($userid, 0, null, null, 'C_QUEUED', true)
	);
Scott Vivian committed
46 47


Gideon Greenspan committed
48 49
//	Check admin privileges (do late to allow one DB query)

Gideon Greenspan committed
50
	if (qa_user_maximum_permit_error('permit_moderate')) {
Gideon Greenspan committed
51 52 53 54
		$qa_content=qa_content_prepare();
		$qa_content['error']=qa_lang_html('users/no_permission');
		return $qa_content;
	}
Scott Vivian committed
55

Gideon Greenspan committed
56

Gideon Greenspan committed
57 58
//	Check to see if any were approved/rejected here

Gideon Greenspan committed
59
	$pageerror=qa_admin_check_clicks();
Scott Vivian committed
60

Gideon Greenspan committed
61

Gideon Greenspan committed
62
//	Combine sets of questions and remove those this user has no permission to moderate
Gideon Greenspan committed
63 64

	$questions=qa_any_sort_by_date(array_merge($queuedquestions, $queuedanswers, $queuedcomments));
Scott Vivian committed
65

Gideon Greenspan committed
66 67 68 69
	if (qa_user_permit_error('permit_moderate')) // if user not allowed to moderate all posts
		foreach ($questions as $index => $question)
			if (qa_user_post_permit_error('permit_moderate', $question))
				unset($questions[$index]);
Scott Vivian committed
70

Gideon Greenspan committed
71 72 73 74 75 76 77

//	Get information for users

	$usershtml=qa_userids_handles_html(qa_any_get_userids_handles($questions));


//	Prepare content for theme
Scott Vivian committed
78

Gideon Greenspan committed
79 80 81
	$qa_content=qa_content_prepare();

	$qa_content['title']=qa_lang_html('admin/recent_approve_title');
Gideon Greenspan committed
82
	$qa_content['error']=isset($pageerror) ? $pageerror : qa_admin_page_error();
Scott Vivian committed
83

Gideon Greenspan committed
84 85
	$qa_content['q_list']=array(
		'form' => array(
Gideon Greenspan committed
86
			'tags' => 'method="post" action="'.qa_self_html().'"',
Gideon Greenspan committed
87 88 89 90

			'hidden' => array(
				'code' => qa_get_form_security_code('admin/click'),
			),
Gideon Greenspan committed
91
		),
Scott Vivian committed
92

Gideon Greenspan committed
93 94
		'qs' => array(),
	);
Scott Vivian committed
95

Gideon Greenspan committed
96 97 98 99
	if (count($questions)) {
		foreach ($questions as $question) {
			$postid=qa_html(isset($question['opostid']) ? $question['opostid'] : $question['postid']);
			$elementid='p'.$postid;
Scott Vivian committed
100

Gideon Greenspan committed
101
			$htmloptions=qa_post_html_options($question);
Gideon Greenspan committed
102 103 104
			$htmloptions['voteview']=false;
			$htmloptions['tagsview']=!isset($question['opostid']);
			$htmloptions['answersview']=false;
Gideon Greenspan committed
105
			$htmloptions['viewsview']=false;
Gideon Greenspan committed
106 107 108 109
			$htmloptions['contentview']=true;
			$htmloptions['elementid']=$elementid;

			$htmlfields=qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, $htmloptions);
Scott Vivian committed
110

Gideon Greenspan committed
111 112
			if (isset($htmlfields['what_url'])) // link directly to relevant content
				$htmlfields['url']=$htmlfields['what_url'];
Scott Vivian committed
113

Gideon Greenspan committed
114 115 116 117 118
			$htmlfields['form']=array(
				'style' => 'light',

				'buttons' => array(
					'approve' => array(
Gideon Greenspan committed
119
						'tags' => 'name="admin_'.$postid.'_approve" onclick="return qa_admin_click(this);"',
Gideon Greenspan committed
120 121
						'label' => qa_lang_html('question/approve_button'),
					),
Scott Vivian committed
122

Gideon Greenspan committed
123
					'reject' => array(
Gideon Greenspan committed
124
						'tags' => 'name="admin_'.$postid.'_reject" onclick="return qa_admin_click(this);"',
Gideon Greenspan committed
125 126 127 128 129 130 131 132 133 134
						'label' => qa_lang_html('question/reject_button'),
					),
				),
			);

			$qa_content['q_list']['qs'][]=$htmlfields;
		}

	} else
		$qa_content['title']=qa_lang_html('admin/no_approve_found');
Scott Vivian committed
135

Gideon Greenspan committed
136 137 138

	$qa_content['navigation']['sub']=qa_admin_sub_navigation();
	$qa_content['script_rel'][]='qa-content/qa-admin.js?'.QA_VERSION;
Scott Vivian committed
139 140


Gideon Greenspan committed
141
	return $qa_content;
Scott Vivian committed
142

Gideon Greenspan committed
143 144 145 146

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