admin-hidden.php 5.56 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 hidden questions, answers and comments


	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 30
require_once QA_INCLUDE_DIR . 'app/admin.php';
require_once QA_INCLUDE_DIR . 'db/admin.php';
require_once QA_INCLUDE_DIR . 'db/selects.php';
require_once QA_INCLUDE_DIR . 'app/format.php';
Scott committed
31 32


Scott committed
33
// Find recently hidden questions, answers, comments
Scott committed
34

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

Scott committed
37 38 39 40 41
list($hiddenquestions, $hiddenanswers, $hiddencomments) = qa_db_select_with_pending(
	qa_db_qs_selectspec($userid, 'created', 0, null, null, 'Q_HIDDEN', true),
	qa_db_recent_a_qs_selectspec($userid, 0, null, null, 'A_HIDDEN', true),
	qa_db_recent_c_qs_selectspec($userid, 0, null, null, 'C_HIDDEN', true)
);
Scott committed
42 43


Scott committed
44
// Check admin privileges (do late to allow one DB query)
Scott committed
45

Scott committed
46 47 48 49 50
if (qa_user_maximum_permit_error('permit_hide_show') && qa_user_maximum_permit_error('permit_delete_hidden')) {
	$qa_content = qa_content_prepare();
	$qa_content['error'] = qa_lang_html('users/no_permission');
	return $qa_content;
}
Scott committed
51 52


Scott committed
53
// Check to see if any have been reshown or deleted
Scott committed
54

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


Scott committed
58
// Combine sets of questions and remove those this user has no permissions for
Scott committed
59

Scott committed
60
$questions = qa_any_sort_by_date(array_merge($hiddenquestions, $hiddenanswers, $hiddencomments));
Scott committed
61

Scott committed
62 63 64 65 66 67 68
if (qa_user_permit_error('permit_hide_show') && qa_user_permit_error('permit_delete_hidden')) { // not allowed to see all hidden posts
	foreach ($questions as $index => $question) {
		if (qa_user_post_permit_error('permit_hide_show', $question) && qa_user_post_permit_error('permit_delete_hidden', $question)) {
			unset($questions[$index]);
		}
	}
}
Scott committed
69 70


Scott committed
71
// Get information for users
Scott committed
72

Scott committed
73
$usershtml = qa_userids_handles_html(qa_any_get_userids_handles($questions));
Scott committed
74 75


Scott committed
76
// Create list of actual hidden postids and see which ones have dependents
Scott committed
77

Scott committed
78 79 80
$qhiddenpostid = array();
foreach ($questions as $key => $question)
	$qhiddenpostid[$key] = isset($question['opostid']) ? $question['opostid'] : $question['postid'];
Scott committed
81

Scott committed
82
$dependcounts = qa_db_postids_count_dependents($qhiddenpostid);
Scott committed
83 84


Scott committed
85
// Prepare content for theme
Scott committed
86

Scott committed
87
$qa_content = qa_content_prepare();
Scott committed
88

Scott committed
89 90
$qa_content['title'] = qa_lang_html('admin/recent_hidden_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
Scott committed
91

Scott committed
92 93 94
$qa_content['q_list'] = array(
	'form' => array(
		'tags' => 'method="post" action="' . qa_self_html() . '"',
Scott committed
95

Scott committed
96 97
		'hidden' => array(
			'code' => qa_get_form_security_code('admin/click'),
Scott committed
98
		),
Scott committed
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	),

	'qs' => array(),
);

if (count($questions)) {
	foreach ($questions as $key => $question) {
		$elementid = 'p' . $qhiddenpostid[$key];

		$htmloptions = qa_post_html_options($question);
		$htmloptions['voteview'] = false;
		$htmloptions['tagsview'] = !isset($question['opostid']);
		$htmloptions['answersview'] = false;
		$htmloptions['viewsview'] = false;
		$htmloptions['updateview'] = false;
		$htmloptions['contentview'] = true;
		$htmloptions['flagsview'] = true;
		$htmloptions['elementid'] = $elementid;

		$htmlfields = qa_any_to_q_html_fields($question, $userid, qa_cookie_get(), $usershtml, null, $htmloptions);

		if (isset($htmlfields['what_url'])) // link directly to relevant content
			$htmlfields['url'] = $htmlfields['what_url'];

		$htmlfields['what_2'] = qa_lang_html('main/hidden');
Scott committed
124

Scott committed
125 126 127 128
		if (@$htmloptions['whenview']) {
			$updated = @$question[isset($question['opostid']) ? 'oupdated' : 'updated'];
			if (isset($updated))
				$htmlfields['when_2'] = qa_when_to_html($updated, @$htmloptions['fulldatedays']);
Scott committed
129 130
		}

Scott committed
131
		$buttons = array();
Scott committed
132

Scott committed
133
		$posttype = qa_strtolower(isset($question['obasetype']) ? $question['obasetype'] : $question['basetype']);
Scott committed
134

Scott committed
135 136 137 138 139 140 141 142
		if (!qa_user_post_permit_error('permit_hide_show', $question)) {
			// Possible values for popup: reshow_q_popup, reshow_a_popup, reshow_c_popup
			$buttons['reshow'] = array(
				'tags' => 'name="admin_' . qa_html($qhiddenpostid[$key]) . '_reshow" onclick="return qa_admin_click(this);"',
				'label' => qa_lang_html('question/reshow_button'),
				'popup' => qa_lang_html(sprintf('question/reshow_%s_popup', $posttype)),
			);
		}
Scott committed
143

Scott committed
144
		if (!qa_user_post_permit_error('permit_delete_hidden', $question) && !$dependcounts[$qhiddenpostid[$key]]) {
Scott committed
145 146 147 148 149 150 151
			// Possible values for popup: delete_q_popup, delete_a_popup, delete_c_popup
			$buttons['delete'] = array(
				'tags' => 'name="admin_' . qa_html($qhiddenpostid[$key]) . '_delete" onclick="return qa_admin_click(this);"',
				'label' => qa_lang_html('question/delete_button'),
				'popup' => qa_lang_html(sprintf('question/delete_%s_popup', $posttype)),
			);
		}
Scott committed
152

Scott committed
153 154 155 156 157 158 159 160 161
		if (count($buttons)) {
			$htmlfields['form'] = array(
				'style' => 'light',
				'buttons' => $buttons,
			);
		}

		$qa_content['q_list']['qs'][] = $htmlfields;
	}
Scott committed
162

Scott committed
163 164
} else
	$qa_content['title'] = qa_lang_html('admin/no_hidden_found');
Scott committed
165

Scott committed
166 167 168 169 170 171

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


return $qa_content;