qa-page-admin-approve.php 4.33 KB
Newer Older
Gideon Greenspan committed
1
<?php
Scott Vivian committed
2

Gideon Greenspan committed
3
/*
Gideon Greenspan committed
4
	Question2Answer by Gideon Greenspan and contributors
Gideon Greenspan committed
5 6 7

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

Gideon Greenspan committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
	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';

Scott Vivian committed
35

Gideon Greenspan committed
36
//	Check we're not using single-sign on integration
Scott Vivian committed
37

Gideon Greenspan committed
38 39 40 41 42 43 44
	if (QA_FINAL_EXTERNAL_USERS)
		qa_fatal_error('User accounts are handled by external code');


//	Find most flagged questions, answers, comments

	$userid=qa_get_logged_in_userid();
Scott Vivian committed
45

Gideon Greenspan committed
46 47 48 49 50 51 52 53 54 55 56
	$users=qa_db_get_unapproved_users(qa_opt('page_size_users'));
	$userfields=qa_db_select_with_pending(qa_db_userfields_selectspec());


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

	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 Vivian committed
57 58


Gideon Greenspan committed
59 60 61
//	Check to see if any were approved or blocked here

	$pageerror=qa_admin_check_clicks();
Scott Vivian committed
62

Gideon Greenspan committed
63 64

//	Prepare content for theme
Scott Vivian committed
65

Gideon Greenspan committed
66 67 68 69
	$qa_content=qa_content_prepare();

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

Gideon Greenspan committed
71 72
	$qa_content['message_list']=array(
		'form' => array(
Gideon Greenspan committed
73
			'tags' => 'method="post" action="'.qa_self_html().'"',
Gideon Greenspan committed
74 75 76 77 78

			'hidden' => array(
				'code' => qa_get_form_security_code('admin/click'),
			),
		),
Scott Vivian committed
79

Gideon Greenspan committed
80 81
		'messages' => array(),
	);
Scott Vivian committed
82 83


Gideon Greenspan committed
84 85 86
	if (count($users)) {
		foreach ($users as $user) {
			$message=array();
Scott Vivian committed
87

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

Gideon Greenspan committed
90 91 92 93 94
			$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($user['createip']),
				)).'<br/>';
Scott Vivian committed
95

Gideon Greenspan committed
96
			$htmlemail=qa_html($user['email']);
Scott Vivian committed
97

Gideon Greenspan committed
98
			$message['content'].=qa_lang_html('users/email_label').' <a href="mailto:'.$htmlemail.'">'.$htmlemail.'</a>';
Scott Vivian committed
99

Gideon Greenspan committed
100 101
			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 Vivian committed
102

Gideon Greenspan committed
103 104 105
			foreach ($userfields as $userfield)
				if (strlen(@$user['profile'][$userfield['title']]))
					$message['content'].='<br/>'.qa_html($userfield['content'].': '.$user['profile'][$userfield['title']]);
Scott Vivian committed
106

Gideon Greenspan committed
107 108
			$message['meta_order']=qa_lang_html('main/meta_order');
			$message['who']['data']=qa_get_one_user_html($user['handle']);
Scott Vivian committed
109

Gideon Greenspan committed
110 111 112 113 114
			$message['form']=array(
				'style' => 'light',

				'buttons' => array(
					'approve' => array(
Gideon Greenspan committed
115
						'tags' => 'name="admin_'.$user['userid'].'_userapprove" onclick="return qa_admin_click(this);"',
Gideon Greenspan committed
116
						'label' => qa_lang_html('question/approve_button'),
117
						'popup' => qa_lang_html('admin/approve_user_popup'),
Gideon Greenspan committed
118 119 120
					),

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

Gideon Greenspan committed
128 129
			$qa_content['message_list']['messages'][]=$message;
		}
Scott Vivian committed
130

Gideon Greenspan committed
131 132 133 134 135 136 137
	} else
		$qa_content['title']=qa_lang_html('admin/no_unapproved_found');


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

Scott Vivian committed
138

Gideon Greenspan committed
139
	return $qa_content;
Scott Vivian committed
140

Gideon Greenspan committed
141 142 143

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