admin-approve.php 4.12 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-approve.php
	Description: Controller for admin page showing new users 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.

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


Scott committed
32
// Check we're not using single-sign on integration
Scott committed
33

Scott committed
34 35
if (QA_FINAL_EXTERNAL_USERS)
	qa_fatal_error('User accounts are handled by external code');
Scott committed
36 37


Scott committed
38
// Find most flagged questions, answers, comments
Scott committed
39

Scott committed
40
$userid = qa_get_logged_in_userid();
Scott committed
41

Scott committed
42 43
$users = qa_db_get_unapproved_users(qa_opt('page_size_users'));
$userfields = qa_db_select_with_pending(qa_db_userfields_selectspec());
Scott committed
44 45


Scott committed
46
// Check admin privileges (do late to allow one DB query)
Scott committed
47

Scott committed
48 49 50 51 52
if (qa_get_logged_in_level() < QA_USER_LEVEL_MODERATOR) {
	$qa_content = qa_content_prepare();
	$qa_content['error'] = qa_lang_html('users/no_permission');
	return $qa_content;
}
Scott committed
53 54


Scott committed
55
// Check to see if any were approved or blocked here
Scott committed
56

Scott committed
57
$pageerror = qa_admin_check_clicks();
Scott committed
58 59


Scott committed
60
// Prepare content for theme
Scott committed
61

Scott committed
62
$qa_content = qa_content_prepare();
Scott committed
63

Scott committed
64 65
$qa_content['title'] = qa_lang_html('admin/approve_users_title');
$qa_content['error'] = isset($pageerror) ? $pageerror : qa_admin_page_error();
Scott committed
66

Scott committed
67 68 69
$qa_content['message_list'] = array(
	'form' => array(
		'tags' => 'method="post" action="' . qa_self_html() . '"',
Scott committed
70

Scott committed
71 72
		'hidden' => array(
			'code' => qa_get_form_security_code('admin/click'),
Scott committed
73
		),
Scott committed
74
	),
Scott committed
75

Scott committed
76 77
	'messages' => array(),
);
Scott committed
78 79


Scott committed
80 81 82
if (count($users)) {
	foreach ($users as $user) {
		$message = array();
Scott committed
83

Scott committed
84
		$message['tags'] = 'id="p' . qa_html($user['userid']) . '"'; // use p prefix for qa_admin_click() in qa-admin.js
Scott committed
85

Scott committed
86 87 88 89 90
		$message['content'] = qa_lang_html('users/registered_label') . ' ' .
			strtr(qa_lang_html('users/x_ago_from_y'), array(
				'^1' => qa_time_to_string(qa_opt('db_time') - $user['created']),
				'^2' => qa_ip_anchor_html(@inet_ntop($user['createip'])),
			)) . '<br/>';
Scott committed
91

Scott committed
92
		$htmlemail = qa_html($user['email']);
Scott committed
93

Scott committed
94
		$message['content'] .= qa_lang_html('users/email_label') . ' <a href="mailto:' . $htmlemail . '">' . $htmlemail . '</a>';
Scott committed
95

Scott committed
96 97 98
		if (qa_opt('confirm_user_emails')) {
			$message['content'] .= '<small> - ' . qa_lang_html(($user['flags'] & QA_USER_FLAGS_EMAIL_CONFIRMED) ? 'users/email_confirmed' : 'users/email_not_confirmed') . '</small>';
		}
Scott committed
99

Scott committed
100 101 102 103
		foreach ($userfields as $userfield) {
			if (strlen(@$user['profile'][$userfield['title']]))
				$message['content'] .= '<br/>' . qa_html($userfield['content'] . ': ' . $user['profile'][$userfield['title']]);
		}
Scott committed
104

Scott committed
105 106
		$message['meta_order'] = qa_lang_html('main/meta_order');
		$message['who']['data'] = qa_get_one_user_html($user['handle']);
Scott committed
107

Scott committed
108 109
		$message['form'] = array(
			'style' => 'light',
Scott committed
110

Scott committed
111 112 113 114 115
			'buttons' => array(
				'approve' => array(
					'tags' => 'name="admin_' . $user['userid'] . '_userapprove" onclick="return qa_admin_click(this);"',
					'label' => qa_lang_html('question/approve_button'),
					'popup' => qa_lang_html('admin/approve_user_popup'),
Scott committed
116 117
				),

Scott committed
118 119 120 121 122 123 124
				'block' => array(
					'tags' => 'name="admin_' . $user['userid'] . '_userblock" onclick="return qa_admin_click(this);"',
					'label' => qa_lang_html('admin/block_button'),
					'popup' => qa_lang_html('admin/block_user_popup'),
				),
			),
		);
Scott committed
125

Scott committed
126 127
		$qa_content['message_list']['messages'][] = $message;
	}
Scott committed
128

Scott committed
129 130
} else
	$qa_content['title'] = qa_lang_html('admin/no_unapproved_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;