admin-flagged.php 3.82 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 22
<?php
/*
	Question2Answer by Gideon Greenspan and contributors
	http://www.question2answer.org/

	File: qa-include/qa-page-admin-flagged.php
	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
23 24 25 26
if (!defined('QA_VERSION')) { // don't allow this page to be requested directly from browser
	header('Location: ../');
	exit;
}
Scott committed
27

Scott committed
28 29 30
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
31 32 33 34


//	Find most flagged questions, answers, comments

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

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


//	Check admin privileges (do late to allow one DB query)

Scott committed
44 45 46 47 48
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
49 50 51 52


//	Check to see if any were cleared or hidden here

Scott committed
53
$pageerror = qa_admin_check_clicks();
Scott committed
54 55 56 57


//	Remove questions the user has no permission to hide/show

Scott committed
58 59 60 61 62 63 64
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
65 66 67 68


//	Get information for users

Scott committed
69
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
Scott committed
70 71 72 73


//	Prepare content for theme

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

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

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

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

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


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

Scott committed
97 98 99 100 101 102 103 104
		$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
105

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

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

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

Scott committed
114 115 116 117
			'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
118 119
				),

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

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

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


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


Scott committed
138
return $qa_content;