qa-page-admin-hidden.php 5.42 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-hidden.php
	Version: See define()s at top of qa-include/qa-base.php
	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.
Scott Vivian committed
18

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
	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-admin.php';
	require_once QA_INCLUDE_DIR.'qa-db-selects.php';
	require_once QA_INCLUDE_DIR.'qa-app-format.php';

Scott Vivian committed
37

Gideon Greenspan committed
38 39 40
//	Find recently hidden questions, answers, comments

	$userid=qa_get_logged_in_userid();
Scott Vivian committed
41

Gideon Greenspan committed
42 43 44 45 46
	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 Vivian committed
47 48


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

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


Gideon Greenspan committed
58 59
//	Check to see if any have been reshown or deleted

Gideon Greenspan committed
60
	$pageerror=qa_admin_check_clicks();
Gideon Greenspan committed
61 62


Gideon Greenspan committed
63
//	Combine sets of questions and remove those this user has no permissions for
Gideon Greenspan committed
64 65 66

	$questions=qa_any_sort_by_date(array_merge($hiddenquestions, $hiddenanswers, $hiddencomments));

Gideon Greenspan committed
67 68 69 70 71 72 73 74
	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]);


//	Get information for users

Gideon Greenspan committed
75 76 77 78 79 80 81 82
	$usershtml=qa_userids_handles_html(qa_any_get_userids_handles($questions));


//	Create list of actual hidden postids and see which ones have dependents

	$qhiddenpostid=array();
	foreach ($questions as $key => $question)
		$qhiddenpostid[$key]=isset($question['opostid']) ? $question['opostid'] : $question['postid'];
Scott Vivian committed
83

Gideon Greenspan committed
84
	$dependcounts=qa_db_postids_count_dependents($qhiddenpostid);
Scott Vivian committed
85

Gideon Greenspan committed
86 87

//	Prepare content for theme
Scott Vivian committed
88

Gideon Greenspan committed
89 90 91
	$qa_content=qa_content_prepare();

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

Gideon Greenspan committed
94 95
	$qa_content['q_list']=array(
		'form' => array(
Gideon Greenspan committed
96
			'tags' => 'method="post" action="'.qa_self_html().'"',
Gideon Greenspan committed
97 98 99 100

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

Gideon Greenspan committed
103 104
		'qs' => array(),
	);
Scott Vivian committed
105

Gideon Greenspan committed
106 107 108 109
	if (count($questions)) {
		foreach ($questions as $key => $question) {
			$elementid='p'.$qhiddenpostid[$key];

Gideon Greenspan committed
110
			$htmloptions=qa_post_html_options($question);
Gideon Greenspan committed
111 112 113
			$htmloptions['voteview']=false;
			$htmloptions['tagsview']=!isset($question['opostid']);
			$htmloptions['answersview']=false;
Gideon Greenspan committed
114
			$htmloptions['viewsview']=false;
Gideon Greenspan committed
115 116 117 118 119 120
			$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);
Scott Vivian committed
121

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

Gideon Greenspan committed
125 126
			$htmlfields['what_2']=qa_lang_html('main/hidden');

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

Gideon Greenspan committed
133
			$buttons=array();
Scott Vivian committed
134

Gideon Greenspan committed
135
			if (!qa_user_post_permit_error('permit_hide_show', $question))
Gideon Greenspan committed
136
				$buttons['reshow']=array(
Gideon Greenspan committed
137
					'tags' => 'name="admin_'.qa_html($qhiddenpostid[$key]).'_reshow" onclick="return qa_admin_click(this);"',
Gideon Greenspan committed
138 139
					'label' => qa_lang_html('question/reshow_button'),
				);
Scott Vivian committed
140

Gideon Greenspan committed
141
			if ((!qa_user_post_permit_error('permit_delete_hidden', $question)) && !$dependcounts[$qhiddenpostid[$key]])
Gideon Greenspan committed
142
				$buttons['delete']=array(
Gideon Greenspan committed
143
					'tags' => 'name="admin_'.qa_html($qhiddenpostid[$key]).'_delete" onclick="return qa_admin_click(this);"',
Gideon Greenspan committed
144 145
					'label' => qa_lang_html('question/delete_button'),
				);
Scott Vivian committed
146

Gideon Greenspan committed
147 148 149 150 151 152 153 154 155 156 157
			if (count($buttons))
				$htmlfields['form']=array(
					'style' => 'light',
					'buttons' => $buttons,
				);

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

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

Gideon Greenspan committed
159 160 161 162

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

Scott Vivian committed
163

Gideon Greenspan committed
164
	return $qa_content;
Scott Vivian committed
165

Gideon Greenspan committed
166 167 168 169

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