admin-flagged.php 3.79 KB
Newer Older
Scott committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	Description: Controller for admin page showing posts with the most flags


	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.

	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
*/

Scott committed
22
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
23
	header('Location: ../../../');
Scott committed
24 25
	exit;
}
Scott committed
26

Scott committed
27 28 29
require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
Scott committed
30 31


Scott committed
32
// Find most flagged questions, answers, comments
Scott committed
33

Scott committed
34
$userid = qa_get_logged_in_userid();
Scott committed
35

Scott committed
36 37 38
$questions = qa_db_select_with_pending(
	qa_db_flagged_post_qs_selectspec($userid, 0, true)
);
Scott committed
39 40


Scott committed
41
// Check admin privileges (do late to allow one DB query)
Scott committed
42

Scott committed
43 44 45 46 47
if (qa_user_maximum_permit_error('permit_hide_show')) {
	$qa_content = qa_content_prepare();
	$qa_content['error'] = qa_lang_html('users/no_permission');
	return $qa_content;
}
Scott committed
48 49


Scott committed
50
// Check to see if any were cleared or hidden here
Scott committed
51

Scott committed
52
$pageerror = qa_admin_check_clicks();
Scott committed
53 54


Scott committed
55
// Remove questions the user has no permission to hide/show
Scott committed
56

Scott committed
57 58 59 60 61 62 63
if (qa_user_permit_error('permit_hide_show')) { // if user not allowed to show/hide all posts
	foreach ($questions as $index => $question) {
		if (qa_user_post_permit_error('permit_hide_show', $question)) {
			unset($questions[$index]);
		}
	}
}
Scott committed
64 65


Scott committed
66
// Get information for users
Scott committed
67

Scott committed
68
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
Scott committed
69 70


Scott committed
71
// Prepare content for theme
Scott committed
72

Scott committed
73
$qa_content = qa_content_prepare();
Scott committed
74

Scott committed
75 76
$qa_content['title'] = qa_lang_html('admin/most_flagged_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
Scott committed
77

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

Scott committed
82 83
		'hidden' => array(
			'code' => qa_get_form_security_code('admin/click'),
Scott committed
84
		),
Scott committed
85
	),
Scott committed
86

Scott committed
87 88
	'qs' => array(),
);
Scott committed
89 90


Scott committed
91 92 93 94
if (count($questions)) {
	foreach ($questions as $question) {
		$postid = qa_html(isset($question['opostid']) ? $question['opostid'] : $question['postid']);
		$elementid = 'p' . $postid;
Scott committed
95

Scott committed
96 97 98 99 100 101 102 103
		$htmloptions = qa_post_html_options($question);
		$htmloptions['voteview'] = false;
		$htmloptions['tagsview'] = ($question['obasetype'] == 'Q');
		$htmloptions['answersview'] = false;
		$htmloptions['viewsview'] = false;
		$htmloptions['contentview'] = true;
		$htmloptions['flagsview'] = true;
		$htmloptions['elementid'] = $elementid;
Scott committed
104

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

Scott committed
107 108
		if (isset($htmlfields['what_url'])) // link directly to relevant content
			$htmlfields['url'] = $htmlfields['what_url'];
Scott committed
109

Scott committed
110 111
		$htmlfields['form'] = array(
			'style' => 'light',
Scott committed
112

Scott committed
113 114 115 116
			'buttons' => array(
				'clearflags' => array(
					'tags' => 'name="admin_' . $postid . '_clearflags" onclick="return qa_admin_click(this);"',
					'label' => qa_lang_html('question/clear_flags_button'),
Scott committed
117 118
				),

Scott committed
119 120 121 122 123 124
				'hide' => array(
					'tags' => 'name="admin_' . $postid . '_hide" onclick="return qa_admin_click(this);"',
					'label' => qa_lang_html('question/hide_button'),
				),
			),
		);
Scott committed
125

Scott committed
126 127
		$qa_content['q_list']['qs'][] = $htmlfields;
	}
Scott committed
128

Scott committed
129 130
} else
	$qa_content['title'] = qa_lang_html('admin/no_flagged_found');
Scott committed
131 132


Scott committed
133 134
$qa_content['navigation']['sub'] = qa_admin_sub_navigation();
$qa_content['script_rel'][] = 'qa-content/qa-admin.js?' . QA_VERSION;
Scott committed
135 136


Scott committed
137
return $qa_content;